LogstashUI 0.5.5.dev0__py3-none-any.whl

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.
Files changed (762) hide show
  1. AI/__init__.py +0 -0
  2. AI/integration_factory.py +1392 -0
  3. AI/migrations/0001_initial.py +58 -0
  4. AI/migrations/0002_draftdefinition_normalizers.py +23 -0
  5. AI/migrations/0003_delete_aisettings_delete_draftdefinition.py +19 -0
  6. AI/migrations/__init__.py +0 -0
  7. AI/models.py +5 -0
  8. AI/static/js/integration_factory.js +1102 -0
  9. AI/system_prompts/dashboard_generator.md +367 -0
  10. AI/system_prompts/grok_patterns.txt +95 -0
  11. AI/system_prompts/ingest_pipeline_generator.md +331 -0
  12. AI/system_prompts/ingest_pipeline_processors.json +2851 -0
  13. AI/system_prompts/ingest_verifier.md +84 -0
  14. AI/system_prompts/integrations_list.json +2690 -0
  15. AI/system_prompts/log_classifier.md +134 -0
  16. AI/system_prompts/template_creator.md +123 -0
  17. AI/templates/integration_factory.html +200 -0
  18. AI/urls.py +16 -0
  19. AI/views.py +20 -0
  20. API/__init__.py +0 -0
  21. API/admin.py +7 -0
  22. API/api.http +784 -0
  23. API/apps.py +9 -0
  24. API/auth.py +101 -0
  25. API/connections_views.py +312 -0
  26. API/guides.py +88 -0
  27. API/mcp/__init__.py +5 -0
  28. API/mcp/dispatch.py +179 -0
  29. API/mcp/tools.py +890 -0
  30. API/mcp/views.py +215 -0
  31. API/migrations/__init__.py +0 -0
  32. API/models.py +7 -0
  33. API/pipelines_views.py +1224 -0
  34. API/policies_views.py +1015 -0
  35. API/security_views.py +488 -0
  36. API/simulation_detail.py +219 -0
  37. API/snmp_views.py +1539 -0
  38. API/urls.py +81 -0
  39. Common/__init__.py +0 -0
  40. Common/ai/agent_builder.py +690 -0
  41. Common/context_processors.py +49 -0
  42. Common/decorators.py +68 -0
  43. Common/elastic_utils.py +1154 -0
  44. Common/encryption.py +271 -0
  45. Common/error_handlers.py +65 -0
  46. Common/formatters.py +106 -0
  47. Common/logstash_config_parse.py +1469 -0
  48. Common/logstash_utils.py +34 -0
  49. Common/middleware.py +216 -0
  50. Common/product_ca.py +1124 -0
  51. Common/validators.py +66 -0
  52. Documentation/__init__.py +0 -0
  53. Documentation/admin.py +7 -0
  54. Documentation/apps.py +9 -0
  55. Documentation/content/CHANGELOG.md +890 -0
  56. Documentation/content/docs/getting_started.md +92 -0
  57. Documentation/content/docs/index.md +124 -0
  58. Documentation/content/docs/logstashagent/configuration/index.md +60 -0
  59. Documentation/content/docs/logstashagent/configuration/logstashagent.yml.md +141 -0
  60. Documentation/content/docs/logstashagent/general/build.md +217 -0
  61. Documentation/content/docs/logstashagent/general/index.md +38 -0
  62. Documentation/content/docs/logstashagent/general/roles.md +267 -0
  63. Documentation/content/docs/logstashagent/index.md +264 -0
  64. Documentation/content/docs/logstashui/SNMP/Quickstart.md +94 -0
  65. Documentation/content/docs/logstashui/SNMP/architecture.md +64 -0
  66. Documentation/content/docs/logstashui/SNMP/configuration.md +147 -0
  67. Documentation/content/docs/logstashui/SNMP/data_overview.md +59 -0
  68. Documentation/content/docs/logstashui/SNMP/deploying_changes.md +71 -0
  69. Documentation/content/docs/logstashui/SNMP/device_support.md +39 -0
  70. Documentation/content/docs/logstashui/SNMP/discovery.md +48 -0
  71. Documentation/content/docs/logstashui/SNMP/index.md +58 -0
  72. Documentation/content/docs/logstashui/SNMP/pipeline_generation.md +63 -0
  73. Documentation/content/docs/logstashui/SNMP/schema.md +595 -0
  74. Documentation/content/docs/logstashui/SNMP/testing.md +47 -0
  75. Documentation/content/docs/logstashui/SNMP/traps.md +45 -0
  76. Documentation/content/docs/logstashui/SNMP/tsds_implementation.md +82 -0
  77. Documentation/content/docs/logstashui/agent_guides/concepts.md +25 -0
  78. Documentation/content/docs/logstashui/agent_guides/deploy.md +30 -0
  79. Documentation/content/docs/logstashui/agent_guides/pipeline-review.md +24 -0
  80. Documentation/content/docs/logstashui/agent_guides/simulation.md +55 -0
  81. Documentation/content/docs/logstashui/agent_guides/snmp.md +57 -0
  82. Documentation/content/docs/logstashui/agent_guides/troubleshooting.md +21 -0
  83. Documentation/content/docs/logstashui/architecture.md +11 -0
  84. Documentation/content/docs/logstashui/compatibility.md +58 -0
  85. Documentation/content/docs/logstashui/configuration/environment.md +193 -0
  86. Documentation/content/docs/logstashui/configuration/host_mode.md +94 -0
  87. Documentation/content/docs/logstashui/configuration/index.md +72 -0
  88. Documentation/content/docs/logstashui/configuration/logstash_proxy.md +138 -0
  89. Documentation/content/docs/logstashui/configuration/logstashui.yml.md +16 -0
  90. Documentation/content/docs/logstashui/configuration/simulation.md +84 -0
  91. Documentation/content/docs/logstashui/database/examples/README.md +15 -0
  92. Documentation/content/docs/logstashui/database/examples/create-mariadb.sql +13 -0
  93. Documentation/content/docs/logstashui/database/examples/create-mysql.sql +12 -0
  94. Documentation/content/docs/logstashui/database/examples/create-postgresql.sql +13 -0
  95. Documentation/content/docs/logstashui/database/examples/schema-mysql.sql +502 -0
  96. Documentation/content/docs/logstashui/database/examples/schema-postgresql.sql +1709 -0
  97. Documentation/content/docs/logstashui/database/index.md +79 -0
  98. Documentation/content/docs/logstashui/database/migration.md +75 -0
  99. Documentation/content/docs/logstashui/general/build.md +154 -0
  100. Documentation/content/docs/logstashui/general/deploy.md +122 -0
  101. Documentation/content/docs/logstashui/general/deployment-recs.md +32 -0
  102. Documentation/content/docs/logstashui/general/index.md +62 -0
  103. Documentation/content/docs/logstashui/general/offline.md +68 -0
  104. Documentation/content/docs/logstashui/general/updating.md +50 -0
  105. Documentation/content/docs/logstashui/index.md +90 -0
  106. Documentation/content/docs/logstashui/kubernetes/cnpg.md +98 -0
  107. Documentation/content/docs/logstashui/kubernetes/envoy-gateway.md +112 -0
  108. Documentation/content/docs/logstashui/kubernetes/examples/README.md +46 -0
  109. Documentation/content/docs/logstashui/kubernetes/examples/embedded-agent.yaml +122 -0
  110. Documentation/content/docs/logstashui/kubernetes/examples/mysql/configmap.yaml +41 -0
  111. Documentation/content/docs/logstashui/kubernetes/examples/mysql/ingress.yaml +31 -0
  112. Documentation/content/docs/logstashui/kubernetes/examples/mysql/namespace.yaml +8 -0
  113. Documentation/content/docs/logstashui/kubernetes/examples/mysql/secret.yaml +19 -0
  114. Documentation/content/docs/logstashui/kubernetes/examples/mysql/statefulset.yaml +106 -0
  115. Documentation/content/docs/logstashui/kubernetes/examples/postgresql/cnpg.yaml +25 -0
  116. Documentation/content/docs/logstashui/kubernetes/examples/postgresql/configmap.yaml +42 -0
  117. Documentation/content/docs/logstashui/kubernetes/examples/postgresql/ingress.yaml +31 -0
  118. Documentation/content/docs/logstashui/kubernetes/examples/postgresql/namespace.yaml +8 -0
  119. Documentation/content/docs/logstashui/kubernetes/examples/postgresql/secret.yaml +19 -0
  120. Documentation/content/docs/logstashui/kubernetes/examples/postgresql/statefulset.yaml +106 -0
  121. Documentation/content/docs/logstashui/kubernetes/examples/sqlite/configmap.yaml +35 -0
  122. Documentation/content/docs/logstashui/kubernetes/examples/sqlite/ingress.yaml +31 -0
  123. Documentation/content/docs/logstashui/kubernetes/examples/sqlite/namespace.yaml +8 -0
  124. Documentation/content/docs/logstashui/kubernetes/examples/sqlite/secret.yaml +18 -0
  125. Documentation/content/docs/logstashui/kubernetes/examples/sqlite/statefulset.yaml +106 -0
  126. Documentation/content/docs/logstashui/kubernetes/index.md +121 -0
  127. Documentation/content/docs/logstashui/mcp.md +224 -0
  128. Documentation/content/docs/logstashui/mcp_scenarios.md +234 -0
  129. Documentation/content/docs/logstashui/rest_api.md +2783 -0
  130. Documentation/content/docs/logstashui/utilities/dissect_debugger.md +89 -0
  131. Documentation/content/docs/logstashui/utilities/grok_debugger.md +114 -0
  132. Documentation/content/docs/logstashui/utilities/index.md +40 -0
  133. Documentation/content/images/LogstashIcon.png +0 -0
  134. Documentation/content/images/architecture.png +0 -0
  135. Documentation/content/images/connection_manager.png +0 -0
  136. Documentation/content/images/control_plane.png +0 -0
  137. Documentation/content/images/graph.gif +0 -0
  138. Documentation/content/images/login.png +0 -0
  139. Documentation/content/images/monitoring.png +0 -0
  140. Documentation/content/images/new_connection.gif +0 -0
  141. Documentation/content/images/simulate.gif +0 -0
  142. Documentation/content/images/simulate.png +0 -0
  143. Documentation/content/images/snmp.gif +0 -0
  144. Documentation/content/images/snmp.png +0 -0
  145. Documentation/content/images/snmp_architecture.png +0 -0
  146. Documentation/migrations/__init__.py +0 -0
  147. Documentation/models.py +9 -0
  148. Documentation/static/css/markdown.css +250 -0
  149. Documentation/templates/documentation.html +225 -0
  150. Documentation/templates/nav_item.html +41 -0
  151. Documentation/urls.py +11 -0
  152. Documentation/views.py +442 -0
  153. LogstashUI/__init__.py +0 -0
  154. LogstashUI/__main__.py +10 -0
  155. LogstashUI/asgi.py +16 -0
  156. LogstashUI/cli.py +626 -0
  157. LogstashUI/config.py +116 -0
  158. LogstashUI/database.py +263 -0
  159. LogstashUI/insecure_http.py +117 -0
  160. LogstashUI/logging_config.py +99 -0
  161. LogstashUI/migrate_engine.py +282 -0
  162. LogstashUI/packaging/__init__.py +3 -0
  163. LogstashUI/packaging/logstashui.default +68 -0
  164. LogstashUI/packaging/logstashui.service.in +22 -0
  165. LogstashUI/paths.py +181 -0
  166. LogstashUI/settings.py +437 -0
  167. LogstashUI/telemetry.py +159 -0
  168. LogstashUI/urls.py +56 -0
  169. LogstashUI/wsgi.py +77 -0
  170. Management/__init__.py +0 -0
  171. Management/apps.py +10 -0
  172. Management/migrations/0001_initial.py +29 -0
  173. Management/migrations/0002_settings.py +25 -0
  174. Management/migrations/0003_settings_agent_ui_url.py +29 -0
  175. Management/migrations/0004_settings_logstash_artifact_base_url.py +29 -0
  176. Management/migrations/__init__.py +0 -0
  177. Management/models.py +92 -0
  178. Management/templates/api_tokens.html +214 -0
  179. Management/templates/components/api_token_created.html +38 -0
  180. Management/templates/components/api_token_row.html +84 -0
  181. Management/templates/components/logstash_artifact_row.html +100 -0
  182. Management/templates/components/logstash_artifact_tbody.html +26 -0
  183. Management/templates/components/user_row.html +67 -0
  184. Management/templates/logs.html +98 -0
  185. Management/templates/logstash_artifacts.html +172 -0
  186. Management/templates/management.html +80 -0
  187. Management/templates/management_settings.html +320 -0
  188. Management/templates/registration/login.html +404 -0
  189. Management/templates/users.html +304 -0
  190. Management/urls.py +23 -0
  191. Management/views.py +804 -0
  192. Monitoring/__init__.py +0 -0
  193. Monitoring/apps.py +9 -0
  194. Monitoring/migrations/__init__.py +0 -0
  195. Monitoring/static/js/monitoring.js +463 -0
  196. Monitoring/templates/components/node_metrics.html +161 -0
  197. Monitoring/templates/components/pipeline_metrics.html +189 -0
  198. Monitoring/templates/monitoring.html +271 -0
  199. Monitoring/urls.py +16 -0
  200. Monitoring/views.py +724 -0
  201. PipelineManager/__init__.py +0 -0
  202. PipelineManager/agent_api.py +1173 -0
  203. PipelineManager/agent_client.py +59 -0
  204. PipelineManager/agent_modes.py +880 -0
  205. PipelineManager/agent_policies.py +689 -0
  206. PipelineManager/agent_versions.py +151 -0
  207. PipelineManager/apps.py +10 -0
  208. PipelineManager/artifact_metrics.py +171 -0
  209. PipelineManager/artifacts.py +820 -0
  210. PipelineManager/connections_crud.py +722 -0
  211. PipelineManager/data/default_jvm.options +76 -0
  212. PipelineManager/data/default_log4j2.properties +165 -0
  213. PipelineManager/data/default_logstash.yml +405 -0
  214. PipelineManager/data/plugins.json +29109 -0
  215. PipelineManager/editor_views.py +608 -0
  216. PipelineManager/forms.py +284 -0
  217. PipelineManager/manager_views.py +490 -0
  218. PipelineManager/migrations/0001_initial.py +38 -0
  219. PipelineManager/migrations/0002_alter_connection_connection_type_and_more.py +38 -0
  220. PipelineManager/migrations/0003_policy_connection_policy.py +38 -0
  221. PipelineManager/migrations/0004_policy_current_revision_number_and_more.py +75 -0
  222. PipelineManager/migrations/0005_apikey_enrollmenttoken.py +38 -0
  223. PipelineManager/migrations/0006_enrollmenttoken_name.py +18 -0
  224. PipelineManager/migrations/0007_alter_enrollmenttoken_options_and_more.py +21 -0
  225. PipelineManager/migrations/0008_connection_agent_id.py +18 -0
  226. PipelineManager/migrations/0009_connection_last_check_in_policy_jvm_options_hash_and_more.py +33 -0
  227. PipelineManager/migrations/0010_keystore_revision_number_pipeline_revision_number.py +23 -0
  228. PipelineManager/migrations/0011_keystore_kv_hash.py +18 -0
  229. PipelineManager/migrations/0012_policy_binary_path.py +18 -0
  230. PipelineManager/migrations/0013_connection_status_blob.py +18 -0
  231. PipelineManager/migrations/0014_pipeline_pipeline_batch_delay_and_more.py +43 -0
  232. PipelineManager/migrations/0015_add_pipeline_hash.py +18 -0
  233. PipelineManager/migrations/0016_backfill_pipeline_hash.py +32 -0
  234. PipelineManager/migrations/0017_policy_keystore_password.py +31 -0
  235. PipelineManager/migrations/0018_policy_last_deployed_at.py +18 -0
  236. PipelineManager/migrations/0019_connection_restart_on_next_checkin.py +18 -0
  237. PipelineManager/migrations/0020_pipeline_no_input_pipeline_non_reloadable.py +23 -0
  238. PipelineManager/migrations/0021_connection_desired_agent_version.py +18 -0
  239. PipelineManager/migrations/0022_keystore_managed_by_pipeline_managed_by.py +23 -0
  240. PipelineManager/migrations/0023_agent_modes_policy_connection.py +89 -0
  241. PipelineManager/migrations/0024_seed_system_policies.py +173 -0
  242. PipelineManager/migrations/0025_packaged_managed_policy_types.py +166 -0
  243. PipelineManager/migrations/0026_normalize_opt_logstash_agent_paths.py +63 -0
  244. PipelineManager/migrations/0027_packaged_managed_default_ports.py +49 -0
  245. PipelineManager/migrations/0028_apikey_admin_tokens.py +80 -0
  246. PipelineManager/migrations/0029_logstash_artifacts.py +45 -0
  247. PipelineManager/migrations/0030_connection_allow_self_signed_certs.py +33 -0
  248. PipelineManager/migrations/0031_deploy_system_policies.py +93 -0
  249. PipelineManager/migrations/0032_connection_agent_inbound_key.py +30 -0
  250. PipelineManager/migrations/0033_simulation_result.py +26 -0
  251. PipelineManager/migrations/__init__.py +0 -0
  252. PipelineManager/models.py +1300 -0
  253. PipelineManager/pipelines_crud.py +738 -0
  254. PipelineManager/policies_crud.py +772 -0
  255. PipelineManager/sim_keystore.py +319 -0
  256. PipelineManager/simulation.py +1581 -0
  257. PipelineManager/static/css/codemirror.min.css +1 -0
  258. PipelineManager/static/css/graph_move.css +79 -0
  259. PipelineManager/static/css/monokai.min.css +1 -0
  260. PipelineManager/static/css/move_mode.css +144 -0
  261. PipelineManager/static/css/show-hint.min.css +1 -0
  262. PipelineManager/static/images/age.png +0 -0
  263. PipelineManager/static/images/aggregate.png +0 -0
  264. PipelineManager/static/images/alter.png +0 -0
  265. PipelineManager/static/images/azure_event_hubs.png +0 -0
  266. PipelineManager/static/images/beats.png +0 -0
  267. PipelineManager/static/images/boundary.png +0 -0
  268. PipelineManager/static/images/bytes.png +0 -0
  269. PipelineManager/static/images/cidr.png +0 -0
  270. PipelineManager/static/images/cipher.png +0 -0
  271. PipelineManager/static/images/circonus.png +0 -0
  272. PipelineManager/static/images/clone.png +0 -0
  273. PipelineManager/static/images/cloudwatch.png +0 -0
  274. PipelineManager/static/images/comment.png +0 -0
  275. PipelineManager/static/images/continue.png +0 -0
  276. PipelineManager/static/images/couchdb_changes.png +0 -0
  277. PipelineManager/static/images/csv.png +0 -0
  278. PipelineManager/static/images/datadog.png +0 -0
  279. PipelineManager/static/images/datadog_metrics.png +0 -0
  280. PipelineManager/static/images/date.png +0 -0
  281. PipelineManager/static/images/de_dot.png +0 -0
  282. PipelineManager/static/images/dead_letter_queue.png +0 -0
  283. PipelineManager/static/images/dissect.png +0 -0
  284. PipelineManager/static/images/dns.png +0 -0
  285. PipelineManager/static/images/drop.png +0 -0
  286. PipelineManager/static/images/dynatrace.png +0 -0
  287. PipelineManager/static/images/elapsed.png +0 -0
  288. PipelineManager/static/images/elastic_agent.png +0 -0
  289. PipelineManager/static/images/elastic_integration.png +0 -0
  290. PipelineManager/static/images/elastic_serverless_forwarder.png +0 -0
  291. PipelineManager/static/images/elastic_workplace_search.png +0 -0
  292. PipelineManager/static/images/elasticsearch.png +0 -0
  293. PipelineManager/static/images/else.png +0 -0
  294. PipelineManager/static/images/else_if.png +0 -0
  295. PipelineManager/static/images/email.png +0 -0
  296. PipelineManager/static/images/environment.png +0 -0
  297. PipelineManager/static/images/exec.png +0 -0
  298. PipelineManager/static/images/extractnumbers.png +0 -0
  299. PipelineManager/static/images/file.png +0 -0
  300. PipelineManager/static/images/fingerprint.png +0 -0
  301. PipelineManager/static/images/ganglia.png +0 -0
  302. PipelineManager/static/images/gelf.png +0 -0
  303. PipelineManager/static/images/generator.png +0 -0
  304. PipelineManager/static/images/geoip.png +0 -0
  305. PipelineManager/static/images/github.png +0 -0
  306. PipelineManager/static/images/google_bigquery.png +0 -0
  307. PipelineManager/static/images/google_cloud_storage.png +0 -0
  308. PipelineManager/static/images/google_pubsub.png +0 -0
  309. PipelineManager/static/images/graphite.png +0 -0
  310. PipelineManager/static/images/graphtastic.png +0 -0
  311. PipelineManager/static/images/grok.png +0 -0
  312. PipelineManager/static/images/heartbeat.png +0 -0
  313. PipelineManager/static/images/http.png +0 -0
  314. PipelineManager/static/images/http_poller.png +0 -0
  315. PipelineManager/static/images/i18n.png +0 -0
  316. PipelineManager/static/images/if.png +0 -0
  317. PipelineManager/static/images/imap.png +0 -0
  318. PipelineManager/static/images/influxdb.png +0 -0
  319. PipelineManager/static/images/irc.png +0 -0
  320. PipelineManager/static/images/java_generator.png +0 -0
  321. PipelineManager/static/images/java_stdin.png +0 -0
  322. PipelineManager/static/images/java_stdout.png +0 -0
  323. PipelineManager/static/images/java_uuid.png +0 -0
  324. PipelineManager/static/images/jdbc.png +0 -0
  325. PipelineManager/static/images/jdbc_static.png +0 -0
  326. PipelineManager/static/images/jdbc_streaming.png +0 -0
  327. PipelineManager/static/images/jms.png +0 -0
  328. PipelineManager/static/images/jmx.png +0 -0
  329. PipelineManager/static/images/json.png +0 -0
  330. PipelineManager/static/images/json_encode.png +0 -0
  331. PipelineManager/static/images/juggernaut.png +0 -0
  332. PipelineManager/static/images/kafka.png +0 -0
  333. PipelineManager/static/images/kinesis.png +0 -0
  334. PipelineManager/static/images/kv.png +0 -0
  335. PipelineManager/static/images/librato.png +0 -0
  336. PipelineManager/static/images/log4j.png +0 -0
  337. PipelineManager/static/images/loggly.png +0 -0
  338. PipelineManager/static/images/logstash.png +0 -0
  339. PipelineManager/static/images/lumberjack.png +0 -0
  340. PipelineManager/static/images/meetup.png +0 -0
  341. PipelineManager/static/images/memcached.png +0 -0
  342. PipelineManager/static/images/metriccatcher.png +0 -0
  343. PipelineManager/static/images/metricize.png +0 -0
  344. PipelineManager/static/images/metrics.png +0 -0
  345. PipelineManager/static/images/mongodb.png +0 -0
  346. PipelineManager/static/images/mutate.png +0 -0
  347. PipelineManager/static/images/nagios.png +0 -0
  348. PipelineManager/static/images/nagios_nsca.png +0 -0
  349. PipelineManager/static/images/opentsdb.png +0 -0
  350. PipelineManager/static/images/pagerduty.png +0 -0
  351. PipelineManager/static/images/pipe.png +0 -0
  352. PipelineManager/static/images/pipeline.png +0 -0
  353. PipelineManager/static/images/prune.png +0 -0
  354. PipelineManager/static/images/puppet_facter.png +0 -0
  355. PipelineManager/static/images/rabbitmq.png +0 -0
  356. PipelineManager/static/images/range.png +0 -0
  357. PipelineManager/static/images/redis.png +0 -0
  358. PipelineManager/static/images/redmine.png +0 -0
  359. PipelineManager/static/images/relp.png +0 -0
  360. PipelineManager/static/images/riak.png +0 -0
  361. PipelineManager/static/images/riemann.png +0 -0
  362. PipelineManager/static/images/rss.png +0 -0
  363. PipelineManager/static/images/ruby.png +0 -0
  364. PipelineManager/static/images/s3-sns-sqs.png +0 -0
  365. PipelineManager/static/images/s3.png +0 -0
  366. PipelineManager/static/images/salesforce.png +0 -0
  367. PipelineManager/static/images/sink.png +0 -0
  368. PipelineManager/static/images/sleep.png +0 -0
  369. PipelineManager/static/images/snmp.png +0 -0
  370. PipelineManager/static/images/snmptrap.png +0 -0
  371. PipelineManager/static/images/sns.png +0 -0
  372. PipelineManager/static/images/solr_http.png +0 -0
  373. PipelineManager/static/images/split.png +0 -0
  374. PipelineManager/static/images/sqlite.png +0 -0
  375. PipelineManager/static/images/sqs.png +0 -0
  376. PipelineManager/static/images/statsd.png +0 -0
  377. PipelineManager/static/images/stdin.png +0 -0
  378. PipelineManager/static/images/stdout.png +0 -0
  379. PipelineManager/static/images/stomp.png +0 -0
  380. PipelineManager/static/images/syslog.png +0 -0
  381. PipelineManager/static/images/syslog_pri.png +0 -0
  382. PipelineManager/static/images/tcp.png +0 -0
  383. PipelineManager/static/images/threats_classifier.png +0 -0
  384. PipelineManager/static/images/throttle.png +0 -0
  385. PipelineManager/static/images/timber.png +0 -0
  386. PipelineManager/static/images/tld.png +0 -0
  387. PipelineManager/static/images/translate.png +0 -0
  388. PipelineManager/static/images/truncate.png +0 -0
  389. PipelineManager/static/images/twitter.png +0 -0
  390. PipelineManager/static/images/udp.png +0 -0
  391. PipelineManager/static/images/unix.png +0 -0
  392. PipelineManager/static/images/urldecode.png +0 -0
  393. PipelineManager/static/images/useragent.png +0 -0
  394. PipelineManager/static/images/uuid.png +0 -0
  395. PipelineManager/static/images/varnishlog.png +0 -0
  396. PipelineManager/static/images/webhdfs.png +0 -0
  397. PipelineManager/static/images/websocket.png +0 -0
  398. PipelineManager/static/images/wmi.png +0 -0
  399. PipelineManager/static/images/wurfl_device_detection.png +0 -0
  400. PipelineManager/static/images/xml.png +0 -0
  401. PipelineManager/static/images/xmpp.png +0 -0
  402. PipelineManager/static/images/zabbix.png +0 -0
  403. PipelineManager/static/js/agent_inspect_modal.js +141 -0
  404. PipelineManager/static/js/agent_policies.js +3746 -0
  405. PipelineManager/static/js/agent_status_sse.js +166 -0
  406. PipelineManager/static/js/codemirror.min.js +1 -0
  407. PipelineManager/static/js/connections_table.js +551 -0
  408. PipelineManager/static/js/d3.v7.js +20625 -0
  409. PipelineManager/static/js/diff_modal.js +995 -0
  410. PipelineManager/static/js/expression_editor.js +291 -0
  411. PipelineManager/static/js/js-yaml.min.js +1 -0
  412. PipelineManager/static/js/logstashyml_guides.js +1063 -0
  413. PipelineManager/static/js/move_graph.js +577 -0
  414. PipelineManager/static/js/move_mode.js +559 -0
  415. PipelineManager/static/js/pipeline_editor.js +4102 -0
  416. PipelineManager/static/js/pipeline_graph_editor.js +3542 -0
  417. PipelineManager/static/js/pipeline_list.js +274 -0
  418. PipelineManager/static/js/pipeline_settings.js +121 -0
  419. PipelineManager/static/js/pipeline_text_editor.js +2088 -0
  420. PipelineManager/static/js/plugin_config_modal.js +2827 -0
  421. PipelineManager/static/js/policy_deploy_modal.js +1066 -0
  422. PipelineManager/static/js/show-hint.min.js +1 -0
  423. PipelineManager/static/js/sim_targets.js +380 -0
  424. PipelineManager/static/js/simple-comment-mode.js +56 -0
  425. PipelineManager/static/js/simulation_modal.js +1135 -0
  426. PipelineManager/static/js/simulation_results.js +2778 -0
  427. PipelineManager/static/js/stats_strip.js +231 -0
  428. PipelineManager/static/js/yaml.js +120 -0
  429. PipelineManager/system_policy_defaults.py +279 -0
  430. PipelineManager/templates/components/pipeline_editor/diff_modal.html +127 -0
  431. PipelineManager/templates/components/pipeline_editor/expression_editor.html +160 -0
  432. PipelineManager/templates/components/pipeline_editor/plugin_config_modal.html +119 -0
  433. PipelineManager/templates/components/pipeline_editor/plugin_modal.html +1016 -0
  434. PipelineManager/templates/components/pipeline_editor/simulation_modal.html +394 -0
  435. PipelineManager/templates/components/pipeline_editor/simulation_results.html +123 -0
  436. PipelineManager/templates/components/pipeline_editor/stats_strip.html +123 -0
  437. PipelineManager/templates/components/pipeline_editor/view_code_modal.html +133 -0
  438. PipelineManager/templates/components/pipeline_manager/agent_inspect_content.html +805 -0
  439. PipelineManager/templates/components/pipeline_manager/agent_inspect_modal.html +40 -0
  440. PipelineManager/templates/components/pipeline_manager/agent_policies.html +2421 -0
  441. PipelineManager/templates/components/pipeline_manager/change_policy_modal.html +210 -0
  442. PipelineManager/templates/components/pipeline_manager/collapsible_row.html +11 -0
  443. PipelineManager/templates/components/pipeline_manager/connection_modal.html +1361 -0
  444. PipelineManager/templates/components/pipeline_manager/keystore_modal.html +269 -0
  445. PipelineManager/templates/components/pipeline_manager/logstashyml_guides/centralized_pipeline_management.html +291 -0
  446. PipelineManager/templates/components/pipeline_manager/logstashyml_guides/default.html +166 -0
  447. PipelineManager/templates/components/pipeline_manager/mcp_modal.html +241 -0
  448. PipelineManager/templates/components/pipeline_manager/pipeline_list_content.html +586 -0
  449. PipelineManager/templates/components/pipeline_manager/policy_deploy_modal.html +238 -0
  450. PipelineManager/templates/pipeline_editor.html +1738 -0
  451. PipelineManager/templates/pipeline_graph_editor.html +99 -0
  452. PipelineManager/templates/pipeline_manager.html +584 -0
  453. PipelineManager/templates/pipeline_text_editor.html +350 -0
  454. PipelineManager/urls.py +99 -0
  455. SNMP/__init__.py +0 -0
  456. SNMP/ai_template_generation.py +232 -0
  457. SNMP/apps.py +9 -0
  458. SNMP/assets/device_template_generation/agents/snmp-profile-author.json +15 -0
  459. SNMP/assets/device_template_generation/skills/snmp-catalog.json +9 -0
  460. SNMP/data/authoring_instructions.md +65 -0
  461. SNMP/data/grounding/.gitignore +4 -0
  462. SNMP/data/grounding/build_grounding.py +35 -0
  463. SNMP/data/grounding/grounding.json +1 -0
  464. SNMP/data/grounding/sample_agent_payload.cisco2960x.json +2184 -0
  465. SNMP/data/mib_reference/std_bgp4_mib.json +43 -0
  466. SNMP/data/mib_reference/std_entity_sensors.json +28 -0
  467. SNMP/data/mib_reference/std_host_resources.json +32 -0
  468. SNMP/data/mib_reference/std_ospf_mib.json +55 -0
  469. SNMP/data/mib_reference/std_ucd_linux.json +27 -0
  470. SNMP/data/normalizers.json +103 -0
  471. SNMP/data/official_device_templates/arista_eos.json +24 -0
  472. SNMP/data/official_device_templates/aruba_wireless_controller.json +23 -0
  473. SNMP/data/official_device_templates/brocade_fc_switch.json +20 -0
  474. SNMP/data/official_device_templates/cisco_ios.json +21 -0
  475. SNMP/data/official_device_templates/default.json +13 -0
  476. SNMP/data/official_device_templates/dell_idrac.json +22 -0
  477. SNMP/data/official_device_templates/dell_x1026.json +16 -0
  478. SNMP/data/official_device_templates/dlink_dgs1210_switch.json +19 -0
  479. SNMP/data/official_device_templates/eastpower_ups.json +20 -0
  480. SNMP/data/official_device_templates/eaton_ups.json +22 -0
  481. SNMP/data/official_device_templates/epson_printer.json +18 -0
  482. SNMP/data/official_device_templates/geist_watchdog.json +20 -0
  483. SNMP/data/official_device_templates/generic_linux.json +18 -0
  484. SNMP/data/official_device_templates/generic_ont.json +18 -0
  485. SNMP/data/official_device_templates/generic_ups.json +16 -0
  486. SNMP/data/official_device_templates/hp_laserjet_mfp_m281cdw.json +18 -0
  487. SNMP/data/official_device_templates/hpe_nimble.json +17 -0
  488. SNMP/data/official_device_templates/huawei_ups.json +19 -0
  489. SNMP/data/official_device_templates/ingrasys_ups.json +19 -0
  490. SNMP/data/official_device_templates/isilon_onefs.json +22 -0
  491. SNMP/data/official_device_templates/mellanox_sx6036.json +20 -0
  492. SNMP/data/official_device_templates/netapp_7mode.json +22 -0
  493. SNMP/data/official_device_templates/palo_alto_firewall.json +21 -0
  494. SNMP/data/official_device_templates/phoenixtec_ups.json +18 -0
  495. SNMP/data/official_device_templates/ubiquiti_unifi_ap.json +19 -0
  496. SNMP/data/official_device_templates/ubiquiti_unifi_switch.json +18 -0
  497. SNMP/data/official_device_templates/ubiquiti_unifi_udm.json +19 -0
  498. SNMP/data/official_device_templates/versa_flexvnf_appliance.json +19 -0
  499. SNMP/data/official_profiles/arista_eos.json +16 -0
  500. SNMP/data/official_profiles/aruba_wireless_controller.json +145 -0
  501. SNMP/data/official_profiles/brocade_fibre_channel_switch_fibre_channel_ports.json +35 -0
  502. SNMP/data/official_profiles/brocade_fibre_channel_switch_name_server.json +23 -0
  503. SNMP/data/official_profiles/brocade_fibre_channel_switch_system_metrics.json +36 -0
  504. SNMP/data/official_profiles/cisco_cdp.json +26 -0
  505. SNMP/data/official_profiles/cisco_fans.json +18 -0
  506. SNMP/data/official_profiles/cisco_sensors.json +21 -0
  507. SNMP/data/official_profiles/cisco_system_metrics.json +40 -0
  508. SNMP/data/official_profiles/dell_idrac_cpu.json +19 -0
  509. SNMP/data/official_profiles/dell_idrac_fans.json +20 -0
  510. SNMP/data/official_profiles/dell_idrac_global_status.json +13 -0
  511. SNMP/data/official_profiles/dell_idrac_memory.json +20 -0
  512. SNMP/data/official_profiles/dell_idrac_power_supply.json +19 -0
  513. SNMP/data/official_profiles/dell_idrac_raid_controller.json +19 -0
  514. SNMP/data/official_profiles/dlink_dgs1210.json +15 -0
  515. SNMP/data/official_profiles/dlink_dgs1210_system_metrics.json +38 -0
  516. SNMP/data/official_profiles/eaton_ups.json +40 -0
  517. SNMP/data/official_profiles/geist_environment.json +50 -0
  518. SNMP/data/official_profiles/generic_arp.json +19 -0
  519. SNMP/data/official_profiles/generic_bgp.json +24 -0
  520. SNMP/data/official_profiles/generic_entity_psu.json +26 -0
  521. SNMP/data/official_profiles/generic_entity_sensor.json +22 -0
  522. SNMP/data/official_profiles/generic_host_system_metrics.json +68 -0
  523. SNMP/data/official_profiles/generic_interfaces.json +86 -0
  524. SNMP/data/official_profiles/generic_ip_addr.json +19 -0
  525. SNMP/data/official_profiles/generic_lldp.json +54 -0
  526. SNMP/data/official_profiles/generic_lm_sensors.json +37 -0
  527. SNMP/data/official_profiles/generic_mac_table.json +19 -0
  528. SNMP/data/official_profiles/generic_ont.json +88 -0
  529. SNMP/data/official_profiles/generic_ospf.json +21 -0
  530. SNMP/data/official_profiles/generic_printer_mib.json +48 -0
  531. SNMP/data/official_profiles/generic_rmon.json +38 -0
  532. SNMP/data/official_profiles/generic_system.json +17 -0
  533. SNMP/data/official_profiles/generic_ucd_system_metrics.json +63 -0
  534. SNMP/data/official_profiles/generic_ups_mib.json +154 -0
  535. SNMP/data/official_profiles/hpe_nimble_volumes.json +59 -0
  536. SNMP/data/official_profiles/huawei_ups.json +111 -0
  537. SNMP/data/official_profiles/isilon_performance.json +92 -0
  538. SNMP/data/official_profiles/isilon_protocols.json +77 -0
  539. SNMP/data/official_profiles/isilon_system.json +86 -0
  540. SNMP/data/official_profiles/mellanox_mlnx_os.json +15 -0
  541. SNMP/data/official_profiles/netapp_7mode_data_protection.json +106 -0
  542. SNMP/data/official_profiles/netapp_7mode_disks.json +51 -0
  543. SNMP/data/official_profiles/netapp_7mode_protocols.json +66 -0
  544. SNMP/data/official_profiles/netapp_7mode_system.json +92 -0
  545. SNMP/data/official_profiles/netapp_7mode_volumes.json +166 -0
  546. SNMP/data/official_profiles/paloalto_components.json +36 -0
  547. SNMP/data/official_profiles/paloalto_system.json +15 -0
  548. SNMP/data/official_profiles/traps.json +16 -0
  549. SNMP/data/official_profiles/ubiquiti_unifi_switch.json +18 -0
  550. SNMP/data/official_profiles/ubiquiti_unifi_switch_system.json +14 -0
  551. SNMP/data/official_profiles/ubiquiti_unifi_wireless.json +60 -0
  552. SNMP/data/official_profiles/versa_flexvnf.json +14 -0
  553. SNMP/data/schema.md +650 -0
  554. SNMP/data/schema_reference/snmp_field_schema.md +747 -0
  555. SNMP/data/snmp_template.json +629 -0
  556. SNMP/data/template_profile_context.md +3986 -0
  557. SNMP/inline_grounding.py +77 -0
  558. SNMP/management/__init__.py +1 -0
  559. SNMP/management/commands/__init__.py +1 -0
  560. SNMP/management/commands/generate_template_profile_context.py +272 -0
  561. SNMP/management/commands/load_test_snmp_data.py +240 -0
  562. SNMP/management/commands/sync_snmp_official_data.py +263 -0
  563. SNMP/management/commands/unload_test_snmp_data.py +77 -0
  564. SNMP/migrations/0001_initial.py +101 -0
  565. SNMP/migrations/0002_devicetemplate.py +34 -0
  566. SNMP/migrations/0003_remove_devicetemplate_type_remove_profile_type_and_more.py +31 -0
  567. SNMP/migrations/0004_device_device_template.py +19 -0
  568. SNMP/migrations/0005_devicetemplate_product_profile_product.py +23 -0
  569. SNMP/migrations/0006_alter_devicetemplate_model_and_more.py +28 -0
  570. SNMP/migrations/0007_remove_device_profiles.py +17 -0
  571. SNMP/migrations/0008_devicetemplate_type.py +18 -0
  572. SNMP/migrations/0009_alter_device_device_template.py +19 -0
  573. SNMP/migrations/0010_alter_device_device_template.py +19 -0
  574. SNMP/migrations/0011_network_namespace.py +18 -0
  575. SNMP/migrations/0012_profile_normalizers.py +18 -0
  576. SNMP/migrations/0013_snmpdeploymentstate.py +26 -0
  577. SNMP/migrations/0014_alter_snmpdeploymentstate_last_config_change.py +18 -0
  578. SNMP/migrations/0015_alter_snmpdeploymentstate_last_config_change.py +20 -0
  579. SNMP/migrations/0016_alter_snmpdeploymentstate_last_config_change.py +18 -0
  580. SNMP/migrations/0017_remove_network_logstash_name.py +17 -0
  581. SNMP/migrations/0018_add_official_key.py +39 -0
  582. SNMP/migrations/0019_network_namespace_from_device_template.py +18 -0
  583. SNMP/migrations/0020_device_hostname_alter_device_ip_address_and_more.py +27 -0
  584. SNMP/migrations/0021_device_building_device_latitude_device_longitude_and_more.py +43 -0
  585. SNMP/migrations/0022_alter_device_latitude_alter_device_longitude.py +23 -0
  586. SNMP/migrations/0023_network_agent_connection_network_deployment_mode_and_more.py +30 -0
  587. SNMP/migrations/0024_network_credential_mode.py +18 -0
  588. SNMP/migrations/0025_network_ssl_certificate_authorities.py +18 -0
  589. SNMP/migrations/__init__.py +0 -0
  590. SNMP/models.py +892 -0
  591. SNMP/network_map.py +660 -0
  592. SNMP/overview.py +394 -0
  593. SNMP/snmp_crud.py +6082 -0
  594. SNMP/snmp_grounding.py +146 -0
  595. SNMP/snmp_normalizers.py +594 -0
  596. SNMP/snmp_pipeline_generator.py +1658 -0
  597. SNMP/snmp_test.py +962 -0
  598. SNMP/static/css/snmp.css +33 -0
  599. SNMP/static/images/apc.png +0 -0
  600. SNMP/static/images/arista.png +0 -0
  601. SNMP/static/images/aruba.png +0 -0
  602. SNMP/static/images/brocade.png +0 -0
  603. SNMP/static/images/cisco.png +0 -0
  604. SNMP/static/images/dell.png +0 -0
  605. SNMP/static/images/dlink.png +0 -0
  606. SNMP/static/images/east.png +0 -0
  607. SNMP/static/images/eaton.png +0 -0
  608. SNMP/static/images/epson.png +0 -0
  609. SNMP/static/images/hauwei.png +0 -0
  610. SNMP/static/images/hp.png +0 -0
  611. SNMP/static/images/hpe.png +0 -0
  612. SNMP/static/images/ingrasys.png +0 -0
  613. SNMP/static/images/linux.png +0 -0
  614. SNMP/static/images/mellanox.png +0 -0
  615. SNMP/static/images/netapp.png +0 -0
  616. SNMP/static/images/paloalto.png +0 -0
  617. SNMP/static/images/phoenixtec.png +0 -0
  618. SNMP/static/images/ubiquiti.png +0 -0
  619. SNMP/static/images/unknown.png +0 -0
  620. SNMP/static/images/versa.png +0 -0
  621. SNMP/static/images/vertiv.png +0 -0
  622. SNMP/static/js/ai_device_template_modal.js +1116 -0
  623. SNMP/static/js/credentials_table.js +291 -0
  624. SNMP/static/js/devices_table.js +588 -0
  625. SNMP/static/js/discovered_devices.js +291 -0
  626. SNMP/static/js/network_map.js +1657 -0
  627. SNMP/static/js/networks_table.js +360 -0
  628. SNMP/static/js/onboarding.js +866 -0
  629. SNMP/static/js/overview.js +416 -0
  630. SNMP/static/js/snmp_changes_indicator.js +76 -0
  631. SNMP/static/js/snmp_commit_modal.js +39 -0
  632. SNMP/static/js/snmp_credentials_modal.js +217 -0
  633. SNMP/static/js/snmp_device_template_modal.js +669 -0
  634. SNMP/static/js/snmp_device_visual_preview.js +1707 -0
  635. SNMP/static/js/snmp_devices_modal.js +912 -0
  636. SNMP/static/js/snmp_diff_modal.js +1559 -0
  637. SNMP/static/js/snmp_network_modal.js +940 -0
  638. SNMP/static/js/snmp_profile_modal.js +1212 -0
  639. SNMP/static/js/snmp_profile_modal_helpers.js +17 -0
  640. SNMP/static/js/snmp_test.js +538 -0
  641. SNMP/templates/Credentials.html +325 -0
  642. SNMP/templates/DeviceTemplates.html +1059 -0
  643. SNMP/templates/Devices.html +274 -0
  644. SNMP/templates/Networks.html +469 -0
  645. SNMP/templates/Onboarding.html +521 -0
  646. SNMP/templates/Overview.html +227 -0
  647. SNMP/templates/components/ai_device_template_modal.html +46 -0
  648. SNMP/templates/components/ai_generate_template_content.html +224 -0
  649. SNMP/templates/components/device_template_profile_modal.html +60 -0
  650. SNMP/templates/components/discovered_devices_content.html +86 -0
  651. SNMP/templates/components/discovered_devices_modal.html +43 -0
  652. SNMP/templates/components/gmaps_latlon_modal.html +93 -0
  653. SNMP/templates/components/network_map.html +110 -0
  654. SNMP/templates/components/snmp_commit_modal.html +53 -0
  655. SNMP/templates/components/snmp_credentials_modal.html +189 -0
  656. SNMP/templates/components/snmp_device_modal.html +6 -0
  657. SNMP/templates/components/snmp_device_template_modal.html +129 -0
  658. SNMP/templates/components/snmp_device_visual_preview.html +347 -0
  659. SNMP/templates/components/snmp_devices_modal.html +330 -0
  660. SNMP/templates/components/snmp_diff_modal.html +148 -0
  661. SNMP/templates/components/snmp_network_modal.html +380 -0
  662. SNMP/templates/components/snmp_profile_modal.html +147 -0
  663. SNMP/templates/components/snmp_test_modal.html +398 -0
  664. SNMP/templatetags/__init__.py +0 -0
  665. SNMP/templatetags/snmp_extras.py +17 -0
  666. SNMP/urls.py +94 -0
  667. SNMP/views.py +913 -0
  668. Site/__init__.py +0 -0
  669. Site/apps.py +9 -0
  670. Site/migrations/__init__.py +0 -0
  671. Site/product_ca_views.py +41 -0
  672. Site/static/images/ElasticIcon.png +0 -0
  673. Site/static/images/LoggyIcon.png +0 -0
  674. Site/static/images/LoggyWizardIcon.png +0 -0
  675. Site/static/images/LogstashAgentIcon.png +0 -0
  676. Site/static/images/LogstashIcon.png +0 -0
  677. Site/static/js/base.js +192 -0
  678. Site/static/js/marked.min.js +69 -0
  679. Site/templates/base.html +52 -0
  680. Site/templates/error.html +65 -0
  681. Site/templates/home.html +148 -0
  682. Site/templates/navigation.html +530 -0
  683. Site/templates/popup.html +251 -0
  684. Site/templatetags/__init__.py +0 -0
  685. Site/templatetags/custom_filters.py +36 -0
  686. Site/urls.py +21 -0
  687. Site/views.py +200 -0
  688. Utilities/__init__.py +0 -0
  689. Utilities/apps.py +9 -0
  690. Utilities/data/grok-patterns/LICENSE +202 -0
  691. Utilities/data/grok-patterns/ecs-v1/aws +33 -0
  692. Utilities/data/grok-patterns/ecs-v1/bacula +53 -0
  693. Utilities/data/grok-patterns/ecs-v1/bind +13 -0
  694. Utilities/data/grok-patterns/ecs-v1/bro +30 -0
  695. Utilities/data/grok-patterns/ecs-v1/exim +26 -0
  696. Utilities/data/grok-patterns/ecs-v1/firewalls +111 -0
  697. Utilities/data/grok-patterns/ecs-v1/grok-patterns +95 -0
  698. Utilities/data/grok-patterns/ecs-v1/haproxy +40 -0
  699. Utilities/data/grok-patterns/ecs-v1/httpd +17 -0
  700. Utilities/data/grok-patterns/ecs-v1/java +34 -0
  701. Utilities/data/grok-patterns/ecs-v1/junos +13 -0
  702. Utilities/data/grok-patterns/ecs-v1/linux-syslog +16 -0
  703. Utilities/data/grok-patterns/ecs-v1/maven +1 -0
  704. Utilities/data/grok-patterns/ecs-v1/mcollective +4 -0
  705. Utilities/data/grok-patterns/ecs-v1/mongodb +7 -0
  706. Utilities/data/grok-patterns/ecs-v1/nagios +124 -0
  707. Utilities/data/grok-patterns/ecs-v1/postgresql +2 -0
  708. Utilities/data/grok-patterns/ecs-v1/rails +13 -0
  709. Utilities/data/grok-patterns/ecs-v1/redis +3 -0
  710. Utilities/data/grok-patterns/ecs-v1/ruby +2 -0
  711. Utilities/data/grok-patterns/ecs-v1/squid +6 -0
  712. Utilities/data/grok-patterns/ecs-v1/zeek +33 -0
  713. Utilities/data/grok-patterns/legacy/aws +14 -0
  714. Utilities/data/grok-patterns/legacy/bacula +50 -0
  715. Utilities/data/grok-patterns/legacy/bind +3 -0
  716. Utilities/data/grok-patterns/legacy/bro +13 -0
  717. Utilities/data/grok-patterns/legacy/exim +19 -0
  718. Utilities/data/grok-patterns/legacy/firewalls +91 -0
  719. Utilities/data/grok-patterns/legacy/grok-patterns +95 -0
  720. Utilities/data/grok-patterns/legacy/haproxy +39 -0
  721. Utilities/data/grok-patterns/legacy/httpd +15 -0
  722. Utilities/data/grok-patterns/legacy/java +17 -0
  723. Utilities/data/grok-patterns/legacy/junos +9 -0
  724. Utilities/data/grok-patterns/legacy/linux-syslog +16 -0
  725. Utilities/data/grok-patterns/legacy/maven +1 -0
  726. Utilities/data/grok-patterns/legacy/mcollective +1 -0
  727. Utilities/data/grok-patterns/legacy/mcollective-patterns +4 -0
  728. Utilities/data/grok-patterns/legacy/mongodb +7 -0
  729. Utilities/data/grok-patterns/legacy/nagios +124 -0
  730. Utilities/data/grok-patterns/legacy/postgresql +3 -0
  731. Utilities/data/grok-patterns/legacy/rails +13 -0
  732. Utilities/data/grok-patterns/legacy/redis +3 -0
  733. Utilities/data/grok-patterns/legacy/ruby +2 -0
  734. Utilities/data/grok-patterns/legacy/squid +4 -0
  735. Utilities/dissect.py +302 -0
  736. Utilities/grok.py +412 -0
  737. Utilities/migrations/__init__.py +0 -0
  738. Utilities/static/css/debugger_editor.css +88 -0
  739. Utilities/static/js/debugger_editor.js +93 -0
  740. Utilities/static/js/grok_debugger.js +131 -0
  741. Utilities/templates/dissect_debugger.html +95 -0
  742. Utilities/templates/grok_debugger.html +99 -0
  743. Utilities/urls.py +14 -0
  744. Utilities/views.py +363 -0
  745. logstashui-0.5.5.dev0.dist-info/METADATA +333 -0
  746. logstashui-0.5.5.dev0.dist-info/RECORD +762 -0
  747. logstashui-0.5.5.dev0.dist-info/WHEEL +4 -0
  748. logstashui-0.5.5.dev0.dist-info/entry_points.txt +2 -0
  749. logstashui-0.5.5.dev0.dist-info/licenses/LICENSE.txt +93 -0
  750. logstashui-0.5.5.dev0.dist-info/licenses/NOTICE.txt +2772 -0
  751. theme/__init__.py +0 -0
  752. theme/apps.py +9 -0
  753. theme/package-lock.json +6 -0
  754. theme/static/css/dist/styles.css +2 -0
  755. theme/static/images/favicon.ico +0 -0
  756. theme/static_src/.gitignore +1 -0
  757. theme/static_src/package-lock.json +1930 -0
  758. theme/static_src/package.json +26 -0
  759. theme/static_src/postcss.config.js +7 -0
  760. theme/static_src/src/styles.css +38 -0
  761. theme/static_src/tailwind.config.js +43 -0
  762. theme/templates/base.html +32 -0
@@ -0,0 +1,3542 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License;
4
+ * you may not use this file except in compliance with the Elastic License.
5
+ */
6
+
7
+ // Track fullscreen state
8
+ let isGraphFullscreen = false;
9
+
10
+ // Store node original positions for snap-back
11
+ let nodeOriginalPositions = new Map();
12
+
13
+ // D3 zoom behavior
14
+ let zoomBehavior = null;
15
+
16
+ // Track newly added component for animation
17
+ let newlyAddedComponentId = null;
18
+ window.newlyAddedComponentId = null;
19
+
20
+ // Track if this is the initial render for centering and animations
21
+ let isInitialRender = true;
22
+ let nodeRenderIndex = 0;
23
+ let currentTransform = null; // Store current transform to preserve position
24
+ let animationDelayPerNode = 100; // Dynamic delay per node (ms), calculated based on total nodes
25
+
26
+ /**
27
+ * Toggle fullscreen mode for graph editor
28
+ */
29
+ function toggleGraphFullscreen() {
30
+ const container = document.getElementById('graphEditorContainer');
31
+ const btn = document.getElementById('graphFullscreenBtn');
32
+
33
+ if (!container || !btn) return;
34
+
35
+ isGraphFullscreen = !isGraphFullscreen;
36
+
37
+ if (isGraphFullscreen) {
38
+ // Enter fullscreen
39
+ container.style.position = 'fixed';
40
+ container.style.top = '0';
41
+ container.style.left = '0';
42
+ container.style.right = '0';
43
+ container.style.bottom = '0';
44
+ container.style.zIndex = '9999';
45
+ container.style.backgroundColor = '#1a1d23';
46
+
47
+ // Change icon to minimize
48
+ btn.innerHTML = `
49
+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
50
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
51
+ </svg>
52
+ `;
53
+ btn.title = 'Exit fullscreen';
54
+ } else {
55
+ // Exit fullscreen
56
+ container.style.position = '';
57
+ container.style.top = '';
58
+ container.style.left = '';
59
+ container.style.right = '';
60
+ container.style.bottom = '';
61
+ container.style.zIndex = '';
62
+ container.style.backgroundColor = '';
63
+
64
+ // Change icon back to expand
65
+ btn.innerHTML = `
66
+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
67
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"></path>
68
+ </svg>
69
+ `;
70
+ btn.title = 'Toggle fullscreen';
71
+ }
72
+
73
+ // Re-render to adjust to new size
74
+ setTimeout(() => renderGraphEditor(), 100);
75
+ }
76
+
77
+ /**
78
+ * Initialize d3 zoom and pan behavior
79
+ */
80
+ function initializeZoomPan(svg) {
81
+ const svgElement = d3.select(svg);
82
+
83
+ // Create zoom behavior
84
+ zoomBehavior = d3.zoom()
85
+ .scaleExtent([0.1, 3]) // Allow zoom from 10% to 300%
86
+ .on('zoom', (event) => {
87
+ // Apply transform to the main group
88
+ svgElement.select('g').attr('transform', event.transform);
89
+ // Store current transform
90
+ currentTransform = event.transform;
91
+ });
92
+
93
+ // Apply zoom behavior to SVG
94
+ svgElement.call(zoomBehavior);
95
+
96
+ // Apply transform: use stored transform if available, otherwise center on initial load
97
+ if (currentTransform) {
98
+ // Reapply the stored transform to maintain position
99
+ svgElement.call(zoomBehavior.transform, currentTransform);
100
+ } else if (isInitialRender) {
101
+ // First time loading - center the canvas
102
+ const svgRect = svg.getBoundingClientRect();
103
+ const svgWidth = svgRect.width;
104
+
105
+ // Calculate center position - aim for the "Add Input" button area
106
+ const targetX = 300; // Approximate center of input section
107
+ const targetY = 50; // Position of Add Input button
108
+
109
+ // Calculate transform to center horizontally and position at top
110
+ const translateX = (svgWidth / 2) - targetX;
111
+ const translateY = 50; // Position near top of viewport with small margin
112
+
113
+ // Apply initial transform
114
+ const initialTransform = d3.zoomIdentity.translate(translateX, translateY);
115
+ svgElement.call(zoomBehavior.transform, initialTransform);
116
+ currentTransform = initialTransform;
117
+ }
118
+
119
+ // Reset zoom on double-click
120
+ svgElement.on('dblclick.zoom', () => {
121
+ svgElement.transition()
122
+ .duration(750)
123
+ .call(zoomBehavior.transform, d3.zoomIdentity);
124
+ });
125
+ }
126
+
127
+ /**
128
+ * Pan viewport to center on a specific node while preserving zoom level
129
+ */
130
+ function panToNode(nodeId) {
131
+ console.log('[panToNode] Looking for node:', nodeId);
132
+
133
+ const svg = document.querySelector('#graphSvg');
134
+ if (!svg || !zoomBehavior) {
135
+ console.warn('[panToNode] SVG or zoomBehavior not available');
136
+ return;
137
+ }
138
+
139
+ // Find the node element
140
+ const nodeElement = svg.querySelector(`[data-component-id="${nodeId}"]`);
141
+ if (!nodeElement) {
142
+ console.warn('[panToNode] Node not found for panning:', nodeId);
143
+ // Debug: list all nodes with data-component-id
144
+ const allNodes = svg.querySelectorAll('[data-component-id]');
145
+ console.log('[panToNode] Available nodes:', Array.from(allNodes).map(n => n.getAttribute('data-component-id')));
146
+ return;
147
+ }
148
+
149
+ console.log('[panToNode] Node found:', nodeElement);
150
+
151
+ // Get the node's bounding box in SVG coordinates
152
+ const bbox = nodeElement.getBBox();
153
+ const nodeCenterX = bbox.x + bbox.width / 2;
154
+ const nodeCenterY = bbox.y + bbox.height / 2;
155
+
156
+ console.log('[panToNode] Node center:', nodeCenterX, nodeCenterY);
157
+
158
+ // Get SVG viewport dimensions
159
+ const svgRect = svg.getBoundingClientRect();
160
+ const svgWidth = svgRect.width;
161
+ const svgHeight = svgRect.height;
162
+
163
+ // Get current zoom transform to preserve the zoom level
164
+ const svgElement = d3.select(svg);
165
+ const currentZoomTransform = d3.zoomTransform(svg);
166
+ const scale = currentZoomTransform.k;
167
+
168
+ console.log('[panToNode] Current zoom scale:', scale);
169
+
170
+ // Calculate the transform needed to center the node while preserving zoom
171
+ const translateX = (svgWidth / 2) - (nodeCenterX * scale);
172
+ const translateY = (svgHeight / 2) - (nodeCenterY * scale);
173
+
174
+ console.log('[panToNode] New transform:', translateX, translateY, scale);
175
+
176
+ // Create new transform by modifying only the translation, keeping the same scale
177
+ // This prevents D3 from interpolating through different zoom levels
178
+ const newTransform = d3.zoomIdentity
179
+ .scale(scale)
180
+ .translate(translateX / scale, translateY / scale);
181
+
182
+ // Apply smooth transition to the new position
183
+ svgElement.transition()
184
+ .duration(750)
185
+ .call(zoomBehavior.transform, newTransform);
186
+ }
187
+
188
+ /**
189
+ * Navigate to the Input section
190
+ */
191
+ function goToInput() {
192
+ const svg = document.querySelector('#graphSvg');
193
+ if (!svg || !zoomBehavior) {
194
+ console.warn('[goToInput] SVG or zoomBehavior not available');
195
+ return;
196
+ }
197
+
198
+ // Find the INPUT section label
199
+ const inputLabel = Array.from(svg.querySelectorAll('text')).find(text => text.textContent === 'INPUT');
200
+ if (!inputLabel) {
201
+ console.warn('[goToInput] INPUT section label not found');
202
+ return;
203
+ }
204
+
205
+ // Get the label's position
206
+ const labelX = parseFloat(inputLabel.getAttribute('x'));
207
+ const labelY = parseFloat(inputLabel.getAttribute('y'));
208
+
209
+ // Get SVG viewport dimensions
210
+ const svgRect = svg.getBoundingClientRect();
211
+ const svgWidth = svgRect.width;
212
+ const svgHeight = svgRect.height;
213
+
214
+ // Get current zoom transform to preserve the zoom level
215
+ const svgElement = d3.select(svg);
216
+ const currentZoomTransform = d3.zoomTransform(svg);
217
+ const scale = currentZoomTransform.k;
218
+
219
+ // Calculate the transform needed to center the section horizontally and position it near the top
220
+ // Position the section about 100px from the top of the viewport
221
+ const targetY = 100;
222
+ const translateX = (svgWidth / 2) - (labelX * scale);
223
+ const translateY = targetY - (labelY * scale);
224
+
225
+ // Create new transform
226
+ const newTransform = d3.zoomIdentity
227
+ .scale(scale)
228
+ .translate(translateX / scale, translateY / scale);
229
+
230
+ // Apply smooth transition to the new position
231
+ svgElement.transition()
232
+ .duration(750)
233
+ .call(zoomBehavior.transform, newTransform);
234
+ }
235
+
236
+ /**
237
+ * Navigate to the Output section
238
+ */
239
+ function goToOutput() {
240
+ const svg = document.querySelector('#graphSvg');
241
+ if (!svg || !zoomBehavior) {
242
+ console.warn('[goToOutput] SVG or zoomBehavior not available');
243
+ return;
244
+ }
245
+
246
+ // Find the OUTPUT section label
247
+ const outputLabel = Array.from(svg.querySelectorAll('text')).find(text => text.textContent === 'OUTPUT');
248
+ if (!outputLabel) {
249
+ console.warn('[goToOutput] OUTPUT section label not found');
250
+ return;
251
+ }
252
+
253
+ // Get the label's position
254
+ const labelX = parseFloat(outputLabel.getAttribute('x'));
255
+ const labelY = parseFloat(outputLabel.getAttribute('y'));
256
+
257
+ // Get SVG viewport dimensions
258
+ const svgRect = svg.getBoundingClientRect();
259
+ const svgWidth = svgRect.width;
260
+ const svgHeight = svgRect.height;
261
+
262
+ // Get current zoom transform to preserve the zoom level
263
+ const svgElement = d3.select(svg);
264
+ const currentZoomTransform = d3.zoomTransform(svg);
265
+ const scale = currentZoomTransform.k;
266
+
267
+ // Calculate the transform needed to center the section horizontally and position it near the top
268
+ // Position the section about 100px from the top of the viewport
269
+ const targetY = 100;
270
+ const translateX = (svgWidth / 2) - (labelX * scale);
271
+ const translateY = targetY - (labelY * scale);
272
+
273
+ // Create new transform
274
+ const newTransform = d3.zoomIdentity
275
+ .scale(scale)
276
+ .translate(translateX / scale, translateY / scale);
277
+
278
+ // Apply smooth transition to the new position
279
+ svgElement.transition()
280
+ .duration(750)
281
+ .call(zoomBehavior.transform, newTransform);
282
+ }
283
+
284
+ /**
285
+ * Make a node draggable with snap-back physics
286
+ * Note: Individual node dragging is disabled - use canvas pan/zoom instead
287
+ */
288
+ function makeDraggable(nodeGroup, originalX, originalY, componentId) {
289
+ // Dragging is now handled at the canvas level via zoom/pan
290
+ // Nodes can still be clicked to open config
291
+ return;
292
+ }
293
+
294
+ /**
295
+ * Initialize and render the graph editor
296
+ */
297
+ function renderGraphEditor() {
298
+ if (!components) {
299
+ console.error('Components not available');
300
+ return;
301
+ }
302
+
303
+ const svg = document.getElementById('graphSvg');
304
+ if (!svg) {
305
+ console.error('Graph SVG not found');
306
+ return;
307
+ }
308
+
309
+ // Reset node render index for staggered animations
310
+ nodeRenderIndex = 0;
311
+
312
+ // Calculate dynamic animation timing based on total node count
313
+ // Target: all nodes rendered within ~3 seconds
314
+ const targetTotalTime = 3000; // 3 seconds in milliseconds
315
+ const fadeInDuration = 500; // Fixed fade-in duration
316
+
317
+ // Count total nodes (including conditionals and nested plugins)
318
+ let totalNodes = 0;
319
+ if (typeof countTotalPlugins === 'function') {
320
+ totalNodes = countTotalPlugins(components);
321
+ }
322
+ // Also count conditional nodes themselves
323
+ if (typeof countTotalConditions === 'function') {
324
+ totalNodes += countTotalConditions(components);
325
+ }
326
+
327
+ // Calculate delay per node to fit within target time
328
+ // Formula: (targetTime - fadeInDuration) / totalNodes
329
+ // Min delay: 10ms (for very large pipelines), Max delay: 150ms (for small pipelines)
330
+ if (totalNodes > 0) {
331
+ const calculatedDelay = Math.max(10, Math.min(150, (targetTotalTime - fadeInDuration) / totalNodes));
332
+ animationDelayPerNode = calculatedDelay;
333
+ } else {
334
+ animationDelayPerNode = 100; // Default for empty pipelines
335
+ }
336
+
337
+ console.log(`[Animation] Total nodes: ${totalNodes}, Delay per node: ${animationDelayPerNode.toFixed(1)}ms`);
338
+
339
+ // Clear existing content
340
+ svg.innerHTML = '';
341
+
342
+ // Collect all components
343
+ const allComponents = {
344
+ input: components.input || [],
345
+ filter: components.filter || [],
346
+ output: components.output || []
347
+ };
348
+
349
+ // Check if we have any components
350
+ const hasComponents = allComponents.input.length > 0 ||
351
+ allComponents.filter.length > 0 ||
352
+ allComponents.output.length > 0;
353
+
354
+ // Always render using branch layout (supports empty sections now)
355
+ renderBranchLayout(svg, allComponents);
356
+
357
+ // Initialize zoom and pan behavior
358
+ initializeZoomPan(svg);
359
+
360
+ console.log('[renderGraphEditor] Checking for newly added component...');
361
+ console.log('[renderGraphEditor] newlyAddedComponentId:', newlyAddedComponentId);
362
+ console.log('[renderGraphEditor] window.newlyAddedComponentId:', window.newlyAddedComponentId);
363
+
364
+ // Pan to newly added node if one exists
365
+ if (newlyAddedComponentId || window.newlyAddedComponentId) {
366
+ const nodeId = newlyAddedComponentId || window.newlyAddedComponentId;
367
+ console.log('[renderGraphEditor] Will pan to node:', nodeId);
368
+ // Wait for DOM to update before panning
369
+ setTimeout(() => {
370
+ panToNode(nodeId);
371
+ }, 100);
372
+ } else {
373
+ console.log('[renderGraphEditor] No newly added component to pan to');
374
+ }
375
+
376
+ // After first render, disable initial render flag
377
+ setTimeout(() => {
378
+ isInitialRender = false;
379
+ }, 100);
380
+
381
+ // Restore graph move-mode drop zones if a move is in progress (see move_graph.js)
382
+ if (window.graphMove && typeof window.graphMove.onRender === 'function') {
383
+ window.graphMove.onRender();
384
+ }
385
+ }
386
+
387
+ /**
388
+ * Create an "Add" button for empty sections
389
+ */
390
+ function createAddButton(type) {
391
+ const button = document.createElement('button');
392
+ button.className = 'graph-add-button';
393
+ button.onclick = () => {
394
+ // Reuse existing plugin modal
395
+ if (typeof PluginModal !== 'undefined') {
396
+ PluginModal.show(type);
397
+ }
398
+ };
399
+
400
+ const typeLabel = type.charAt(0).toUpperCase() + type.slice(1);
401
+ button.innerHTML = `
402
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
403
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
404
+ </svg>
405
+ <span>Add ${typeLabel}</span>
406
+ `;
407
+
408
+ return button;
409
+ }
410
+
411
+ /**
412
+ * Render empty state with add buttons
413
+ */
414
+ function renderEmptyState(svg) {
415
+ const foreignObject = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
416
+ foreignObject.setAttribute('x', '50%');
417
+ foreignObject.setAttribute('y', '50%');
418
+ foreignObject.setAttribute('width', '400');
419
+ foreignObject.setAttribute('height', '300');
420
+ foreignObject.setAttribute('transform', 'translate(-200, -150)');
421
+
422
+ const div = document.createElement('div');
423
+ div.className = 'flex flex-col gap-4 items-center justify-center';
424
+ div.innerHTML = `
425
+ <p class="text-gray-400 text-center mb-4">No components in pipeline</p>
426
+ <button class="graph-add-button" onclick="if(typeof PluginModal !== 'undefined') PluginModal.show('input')">
427
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
428
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
429
+ </svg>
430
+ <span>Add Input</span>
431
+ </button>
432
+ <button class="graph-add-button" onclick="if(typeof PluginModal !== 'undefined') PluginModal.show('filter')">
433
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
434
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
435
+ </svg>
436
+ <span>Add Filter</span>
437
+ </button>
438
+ <button class="graph-add-button" onclick="if(typeof PluginModal !== 'undefined') PluginModal.show('output')">
439
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
440
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
441
+ </svg>
442
+ <span>Add Output</span>
443
+ </button>
444
+ `;
445
+
446
+ foreignObject.appendChild(div);
447
+ svg.appendChild(foreignObject);
448
+ }
449
+
450
+ /**
451
+ * Process components to identify conditionals for branch rendering
452
+ * Returns an array where conditionals are kept as objects with their branches
453
+ */
454
+ function processComponentsForBranching(components) {
455
+ const processed = {
456
+ input: [],
457
+ filter: [],
458
+ output: []
459
+ };
460
+
461
+ ['input', 'filter', 'output'].forEach(type => {
462
+ if (components[type] && Array.isArray(components[type])) {
463
+ components[type].forEach((component, index) => {
464
+ if (component.plugin === 'if') {
465
+ // Keep conditional as a special branching structure
466
+ processed[type].push({
467
+ ...component,
468
+ isBranchPoint: true,
469
+ branches: extractBranches(component)
470
+ });
471
+ } else {
472
+ // Regular plugin
473
+ processed[type].push(component);
474
+ }
475
+ });
476
+ }
477
+ });
478
+
479
+ return processed;
480
+ }
481
+
482
+ /**
483
+ * Process plugins array to convert nested conditionals to branch points
484
+ */
485
+ function processPluginsForBranches(plugins) {
486
+ if (!plugins || !Array.isArray(plugins)) return [];
487
+
488
+ return plugins.map(plugin => {
489
+ if (plugin.plugin === 'if') {
490
+ // Convert nested conditional to branch point
491
+ return {
492
+ ...plugin,
493
+ isBranchPoint: true,
494
+ branches: extractBranches(plugin)
495
+ };
496
+ }
497
+ return plugin;
498
+ });
499
+ }
500
+
501
+ /**
502
+ * Extract all branches from a conditional (if, else_ifs, else)
503
+ * Recursively processes nested conditionals within each branch
504
+ */
505
+ function extractBranches(conditional) {
506
+ const branches = [];
507
+
508
+ // Main if branch
509
+ branches.push({
510
+ type: 'if',
511
+ condition: conditional.config.condition,
512
+ plugins: processPluginsForBranches(conditional.config.plugins || []),
513
+ id: conditional.id
514
+ });
515
+
516
+ // else_if branches
517
+ if (conditional.config.else_ifs && Array.isArray(conditional.config.else_ifs)) {
518
+ conditional.config.else_ifs.forEach((elseIf, index) => {
519
+ branches.push({
520
+ type: 'else_if',
521
+ condition: elseIf.condition,
522
+ plugins: processPluginsForBranches(elseIf.plugins || []),
523
+ id: conditional.id + '_elseif_' + index
524
+ });
525
+ });
526
+ }
527
+
528
+ // else branch
529
+ if (conditional.config.else && conditional.config.else.plugins) {
530
+ branches.push({
531
+ type: 'else',
532
+ condition: 'else',
533
+ plugins: processPluginsForBranches(conditional.config.else.plugins || []),
534
+ id: conditional.id + '_else'
535
+ });
536
+ } else {
537
+ // Add "Continue - No matching condition" branch when there's no else block
538
+ branches.push({
539
+ type: 'continue',
540
+ condition: 'Continue - No matching condition',
541
+ plugins: [], // No plugins in continue branch
542
+ id: conditional.id + '_continue',
543
+ isContinue: true // Flag to identify this as a continue branch
544
+ });
545
+ }
546
+
547
+ return branches;
548
+ }
549
+
550
+ /**
551
+ * Helper function to recursively calculate the width needed for a branch with nested conditionals
552
+ */
553
+ function calculateBranchWidth(branch, nodeWidth, branchHorizontalSpacing) {
554
+ if (!branch.plugins || branch.plugins.length === 0) {
555
+ return nodeWidth;
556
+ }
557
+
558
+ let maxNestedWidth = nodeWidth;
559
+
560
+ branch.plugins.forEach(plugin => {
561
+ if (plugin.isBranchPoint && plugin.branches) {
562
+ // Recursively calculate width for each nested branch
563
+ const nestedBranchWidths = plugin.branches.map(nestedBranch =>
564
+ calculateBranchWidth(nestedBranch, nodeWidth, branchHorizontalSpacing)
565
+ );
566
+
567
+ const nestedTotalWidth = nestedBranchWidths.reduce((sum, w) => sum + w, 0) +
568
+ ((plugin.branches.length - 1) * branchHorizontalSpacing);
569
+
570
+ // Parent needs to be at least as wide as its nested content plus padding
571
+ maxNestedWidth = Math.max(maxNestedWidth, nestedTotalWidth + 24);
572
+ }
573
+ });
574
+
575
+ return maxNestedWidth;
576
+ }
577
+
578
+ /**
579
+ * Recursively render a nested conditional as a full branch layout
580
+ * This handles conditionals at any depth of nesting
581
+ */
582
+ function renderNestedConditional(g, nestedConditional, parentX, startY, parentWidth, nodeWidth, nodeHeight, verticalSpacing, branchHorizontalSpacing, filterIndex, parentComponentId) {
583
+ const nestedBranches = nestedConditional.branches;
584
+ const branchCount = nestedBranches.length;
585
+
586
+ let currentY = startY;
587
+
588
+ // Calculate dynamic widths for nested branches using recursive calculation
589
+ const branchWidths = nestedBranches.map(branch =>
590
+ calculateBranchWidth(branch, nodeWidth, branchHorizontalSpacing)
591
+ );
592
+
593
+ const totalBranchWidth = branchWidths.reduce((sum, w) => sum + w, 0) +
594
+ ((branchCount - 1) * branchHorizontalSpacing);
595
+ const branchStartX = parentX + (parentWidth / 2) - (totalBranchWidth / 2);
596
+
597
+ let maxBranchEndY = currentY;
598
+ const branchEndPositions = [];
599
+ const buttonElements = [];
600
+
601
+ // Add spacing before nested conditional branches (similar to base-level conditionals)
602
+ const beforeBranchY = currentY;
603
+ const isMultiBranch = branchCount > 1;
604
+ const conditionalSpacing = isMultiBranch ? verticalSpacing : 0;
605
+ currentY += conditionalSpacing;
606
+
607
+ // Draw forking connection lines from parent to each nested branch
608
+ // This creates the visual pattern: line down from parent, split horizontally, then down to each condition
609
+ if (isMultiBranch) {
610
+ // For multi-branch: draw vertical line down, then horizontal lines to each branch, then vertical down to each condition
611
+ const parentCenterX = parentX + (parentWidth / 2);
612
+ const forkY = beforeBranchY + (conditionalSpacing / 2);
613
+
614
+ // Draw vertical line from parent to fork point
615
+ const verticalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
616
+ verticalLine.setAttribute('x1', parentCenterX);
617
+ verticalLine.setAttribute('y1', beforeBranchY);
618
+ verticalLine.setAttribute('x2', parentCenterX);
619
+ verticalLine.setAttribute('y2', forkY);
620
+ verticalLine.setAttribute('stroke', '#6b7280');
621
+ verticalLine.setAttribute('stroke-width', 2);
622
+ verticalLine.setAttribute('stroke-dasharray', '5,5');
623
+ g.appendChild(verticalLine);
624
+
625
+ // Draw horizontal line spanning all branches
626
+ let cumulativeX = branchStartX;
627
+ const leftmostBranchCenterX = branchStartX + (branchWidths[0] / 2);
628
+ const rightmostBranchCenterX = branchStartX + branchWidths.reduce((sum, w, idx) => {
629
+ if (idx < branchCount - 1) {
630
+ return sum + w + branchHorizontalSpacing;
631
+ }
632
+ return sum + w;
633
+ }, 0) - branchWidths[branchCount - 1] + (branchWidths[branchCount - 1] / 2);
634
+
635
+ const horizontalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
636
+ horizontalLine.setAttribute('x1', leftmostBranchCenterX);
637
+ horizontalLine.setAttribute('y1', forkY);
638
+ horizontalLine.setAttribute('x2', rightmostBranchCenterX);
639
+ horizontalLine.setAttribute('y2', forkY);
640
+ horizontalLine.setAttribute('stroke', '#6b7280');
641
+ horizontalLine.setAttribute('stroke-width', 2);
642
+ horizontalLine.setAttribute('stroke-dasharray', '5,5');
643
+ g.appendChild(horizontalLine);
644
+
645
+ // Draw vertical lines from fork point down to each condition node
646
+ cumulativeX = branchStartX;
647
+ nestedBranches.forEach((branch, branchIndex) => {
648
+ const branchWidth = branchWidths[branchIndex];
649
+ const branchCenterX = cumulativeX + (branchWidth / 2);
650
+
651
+ const branchVerticalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
652
+ branchVerticalLine.setAttribute('x1', branchCenterX);
653
+ branchVerticalLine.setAttribute('y1', forkY);
654
+ branchVerticalLine.setAttribute('x2', branchCenterX);
655
+ branchVerticalLine.setAttribute('y2', currentY);
656
+ branchVerticalLine.setAttribute('stroke', '#6b7280');
657
+ branchVerticalLine.setAttribute('stroke-width', 2);
658
+ branchVerticalLine.setAttribute('stroke-dasharray', '5,5');
659
+ g.appendChild(branchVerticalLine);
660
+
661
+ cumulativeX += branchWidth + branchHorizontalSpacing;
662
+ });
663
+ } else {
664
+ // For single-branch: draw simple vertical line from parent to condition
665
+ const parentCenterX = parentX + (parentWidth / 2);
666
+ const branchCenterX = branchStartX + (branchWidths[0] / 2);
667
+
668
+ const singleLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
669
+ singleLine.setAttribute('x1', parentCenterX);
670
+ singleLine.setAttribute('y1', beforeBranchY);
671
+ singleLine.setAttribute('x2', branchCenterX);
672
+ singleLine.setAttribute('y2', currentY);
673
+ singleLine.setAttribute('stroke', '#6b7280');
674
+ singleLine.setAttribute('stroke-width', 2);
675
+ singleLine.setAttribute('stroke-dasharray', '5,5');
676
+ g.appendChild(singleLine);
677
+ }
678
+
679
+ // Render each nested branch
680
+ let cumulativeX = branchStartX;
681
+ nestedBranches.forEach((branch, branchIndex) => {
682
+ const branchWidth = branchWidths[branchIndex];
683
+ const branchX = cumulativeX;
684
+ let branchY = currentY;
685
+ const branchStartY = branchY;
686
+
687
+ // Create condition node
688
+ // Check if the parent conditional has an else block
689
+ const hasElse = nestedConditional.branches.some(b => b.type === 'else');
690
+ const conditionNode = {
691
+ id: branch.id,
692
+ type: 'filter',
693
+ plugin: branch.type,
694
+ isConditional: true,
695
+ conditionText: branch.condition,
696
+ hasElse: hasElse,
697
+ isContinue: branch.isContinue || false,
698
+ config: {}
699
+ };
700
+ const conditionGroup = createNodeElement(conditionNode, branchX, branchY, branchWidth, nodeHeight, 'filter');
701
+ g.appendChild(conditionGroup);
702
+
703
+ branchY += nodeHeight + verticalSpacing;
704
+
705
+ // Render plugins in this nested branch
706
+ if (branch.plugins && branch.plugins.length > 0) {
707
+ branch.plugins.forEach((plugin, pluginIndex) => {
708
+ // Add hover area between plugins
709
+ if (pluginIndex > 0) {
710
+ const betweenY = branchY - verticalSpacing;
711
+ const betweenHeight = verticalSpacing;
712
+
713
+ const betweenHoverArea = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
714
+ betweenHoverArea.setAttribute('x', branchX - 12);
715
+ betweenHoverArea.setAttribute('y', betweenY);
716
+ betweenHoverArea.setAttribute('width', branchWidth + 24);
717
+ betweenHoverArea.setAttribute('height', betweenHeight);
718
+ betweenHoverArea.setAttribute('fill', 'transparent');
719
+ betweenHoverArea.style.cursor = 'pointer';
720
+ g.appendChild(betweenHoverArea);
721
+
722
+ const betweenButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
723
+ betweenButtonFO.setAttribute('x', branchX + (branchWidth / 2) - 95);
724
+ betweenButtonFO.setAttribute('y', betweenY + (betweenHeight / 2) - 15);
725
+ betweenButtonFO.setAttribute('width', '190');
726
+ betweenButtonFO.setAttribute('height', '30');
727
+ betweenButtonFO.setAttribute('overflow', 'visible');
728
+ betweenButtonFO.style.opacity = '0';
729
+ betweenButtonFO.style.pointerEvents = 'none';
730
+ betweenButtonFO.style.transition = 'opacity 0.15s ease';
731
+
732
+ const betweenButtonDiv = document.createElement('div');
733
+ betweenButtonDiv.style.display = 'flex';
734
+ betweenButtonDiv.style.gap = '6px';
735
+ betweenButtonDiv.style.justifyContent = 'center';
736
+ betweenButtonDiv.style.alignItems = 'center';
737
+
738
+ const blockType = branch.type === 'else_if' ? 'else_if' : (branch.type === 'else' ? 'else' : 'if');
739
+ const elseIfIndex = branch.type === 'else_if' ? branchIndex - 1 : null;
740
+
741
+ betweenButtonDiv.innerHTML = `
742
+ <button class="graph-add-plugin-to-branch-btn"
743
+ data-component-id="${nestedConditional.id}"
744
+ data-block-type="${blockType}"
745
+ data-elseif-index="${elseIfIndex}"
746
+ data-index="${pluginIndex}"
747
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #3b82f6; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
748
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
749
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
750
+ </svg>
751
+ <span>Add Plugin</span>
752
+ </button>
753
+ <button class="graph-add-condition-to-branch-btn"
754
+ data-component-id="${nestedConditional.id}"
755
+ data-block-type="${blockType}"
756
+ data-elseif-index="${elseIfIndex}"
757
+ data-index="${pluginIndex}"
758
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #d97706; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
759
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
760
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
761
+ </svg>
762
+ <span>Add Condition</span>
763
+ </button>
764
+ `;
765
+ betweenButtonFO.appendChild(betweenButtonDiv);
766
+
767
+ betweenHoverArea.addEventListener('mouseenter', () => {
768
+ betweenButtonFO.style.opacity = '1';
769
+ betweenButtonFO.style.pointerEvents = 'auto';
770
+ });
771
+ betweenHoverArea.addEventListener('mouseleave', () => {
772
+ betweenButtonFO.style.opacity = '0';
773
+ betweenButtonFO.style.pointerEvents = 'none';
774
+ });
775
+ betweenButtonFO.addEventListener('mouseenter', () => {
776
+ betweenButtonFO.style.opacity = '1';
777
+ betweenButtonFO.style.pointerEvents = 'auto';
778
+ });
779
+ betweenButtonFO.addEventListener('mouseleave', () => {
780
+ betweenButtonFO.style.opacity = '0';
781
+ betweenButtonFO.style.pointerEvents = 'none';
782
+ });
783
+
784
+ g.appendChild(betweenButtonFO);
785
+ }
786
+
787
+ // Draw connection line
788
+ if (pluginIndex === 0) {
789
+ const blockType = branch.type === 'else_if' ? 'else_if' : (branch.type === 'else' ? 'else' : 'if');
790
+ const elseIfIndex = branch.type === 'else_if' ? branchIndex - 1 : null;
791
+ const line = createConnectionLine(
792
+ branchX + branchWidth / 2, branchY - verticalSpacing,
793
+ branchX + branchWidth / 2, branchY,
794
+ false,
795
+ 'filter',
796
+ 0,
797
+ true,
798
+ nestedConditional.id,
799
+ blockType,
800
+ elseIfIndex
801
+ );
802
+ g.appendChild(line);
803
+ }
804
+
805
+ // Check if this plugin is itself a nested conditional (recursive case)
806
+ if (plugin.isBranchPoint) {
807
+ const deeperNestedResult = renderNestedConditional(
808
+ g, plugin, branchX, branchY, branchWidth,
809
+ nodeWidth, nodeHeight, verticalSpacing, branchHorizontalSpacing,
810
+ filterIndex, nestedConditional.id
811
+ );
812
+ branchY = deeperNestedResult.endY;
813
+
814
+ if (pluginIndex < branch.plugins.length - 1) {
815
+ const blockType = branch.type === 'else_if' ? 'else_if' : (branch.type === 'else' ? 'else' : 'if');
816
+ const elseIfIndex = branch.type === 'else_if' ? branchIndex - 1 : null;
817
+ const line = createConnectionLine(
818
+ branchX + branchWidth / 2, deeperNestedResult.endY - verticalSpacing,
819
+ branchX + branchWidth / 2, branchY,
820
+ false,
821
+ 'filter',
822
+ pluginIndex + 1,
823
+ true,
824
+ nestedConditional.id,
825
+ blockType,
826
+ elseIfIndex
827
+ );
828
+ g.appendChild(line);
829
+ }
830
+ } else {
831
+ // Regular plugin
832
+ const pluginGroup = createNodeElement(plugin, branchX, branchY, branchWidth, nodeHeight, 'filter');
833
+ g.appendChild(pluginGroup);
834
+
835
+ if (pluginIndex < branch.plugins.length - 1) {
836
+ const nextY = branchY + nodeHeight + verticalSpacing;
837
+ const blockType = branch.type === 'else_if' ? 'else_if' : (branch.type === 'else' ? 'else' : 'if');
838
+ const elseIfIndex = branch.type === 'else_if' ? branchIndex - 1 : null;
839
+ const line = createConnectionLine(
840
+ branchX + branchWidth / 2, branchY + nodeHeight,
841
+ branchX + branchWidth / 2, nextY,
842
+ false,
843
+ 'filter',
844
+ pluginIndex + 1,
845
+ true,
846
+ nestedConditional.id,
847
+ blockType,
848
+ elseIfIndex
849
+ );
850
+ g.appendChild(line);
851
+ }
852
+
853
+ branchY += nodeHeight + verticalSpacing;
854
+ }
855
+ });
856
+ }
857
+
858
+ // Add hover area and buttons at bottom of branch (skip for continue branches)
859
+ const branchEndY = branchY - verticalSpacing;
860
+
861
+ if (!branch.isContinue) {
862
+ const blockType = branch.type === 'else_if' ? 'else_if' : (branch.type === 'else' ? 'else' : 'if');
863
+ const elseIfIndex = branch.type === 'else_if' ? branchIndex - 1 : null;
864
+ const pluginInsertIndex = branch.plugins ? branch.plugins.length : 0;
865
+
866
+ const branchButtonHoverArea = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
867
+ branchButtonHoverArea.setAttribute('x', branchX - 12);
868
+ branchButtonHoverArea.setAttribute('y', branchEndY);
869
+ branchButtonHoverArea.setAttribute('width', branchWidth + 24);
870
+ branchButtonHoverArea.setAttribute('height', 48);
871
+ branchButtonHoverArea.setAttribute('fill', 'transparent');
872
+ branchButtonHoverArea.style.cursor = 'pointer';
873
+ g.appendChild(branchButtonHoverArea);
874
+
875
+ const branchButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
876
+ branchButtonFO.setAttribute('x', branchX + (branchWidth / 2) - 95);
877
+ branchButtonFO.setAttribute('y', branchEndY + 10);
878
+ branchButtonFO.setAttribute('width', '190');
879
+ branchButtonFO.setAttribute('height', '30');
880
+ branchButtonFO.setAttribute('overflow', 'visible');
881
+ branchButtonFO.style.opacity = '0';
882
+ branchButtonFO.style.pointerEvents = 'none';
883
+ branchButtonFO.style.transition = 'opacity 0.15s ease';
884
+
885
+ const branchButtonDiv = document.createElement('div');
886
+ branchButtonDiv.style.display = 'flex';
887
+ branchButtonDiv.style.gap = '6px';
888
+ branchButtonDiv.style.justifyContent = 'center';
889
+ branchButtonDiv.style.alignItems = 'center';
890
+ branchButtonDiv.innerHTML = `
891
+ <button class="graph-add-plugin-to-branch-btn"
892
+ data-component-id="${nestedConditional.id}"
893
+ data-block-type="${blockType}"
894
+ data-elseif-index="${elseIfIndex}"
895
+ data-index="${pluginInsertIndex}"
896
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #2563eb; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
897
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
898
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
899
+ </svg>
900
+ <span>Add Plugin</span>
901
+ </button>
902
+ <button class="graph-add-condition-to-branch-btn"
903
+ data-component-id="${nestedConditional.id}"
904
+ data-block-type="${blockType}"
905
+ data-elseif-index="${elseIfIndex}"
906
+ data-index="${pluginInsertIndex}"
907
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #d97706; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
908
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
909
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
910
+ </svg>
911
+ <span>Add Condition</span>
912
+ </button>
913
+ `;
914
+ branchButtonFO.appendChild(branchButtonDiv);
915
+
916
+ branchButtonHoverArea.addEventListener('mouseenter', () => {
917
+ branchButtonFO.style.opacity = '1';
918
+ branchButtonFO.style.pointerEvents = 'auto';
919
+ });
920
+ branchButtonHoverArea.addEventListener('mouseleave', () => {
921
+ branchButtonFO.style.opacity = '0';
922
+ branchButtonFO.style.pointerEvents = 'none';
923
+ });
924
+ branchButtonFO.addEventListener('mouseenter', () => {
925
+ branchButtonFO.style.opacity = '1';
926
+ branchButtonFO.style.pointerEvents = 'auto';
927
+ });
928
+ branchButtonFO.addEventListener('mouseleave', () => {
929
+ branchButtonFO.style.opacity = '0';
930
+ branchButtonFO.style.pointerEvents = 'none';
931
+ });
932
+
933
+ buttonElements.push(branchButtonFO);
934
+ }
935
+
936
+ // Add branch container background
937
+ const branchHeight = branchY - branchStartY;
938
+ // Don't add extra height - branchY already includes button positioning
939
+ const containerHeight = branchHeight - verticalSpacing + 56;
940
+ const branchContainer = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
941
+ branchContainer.setAttribute('x', branchX - 12);
942
+ branchContainer.setAttribute('y', branchStartY - 8);
943
+ branchContainer.setAttribute('width', branchWidth + 24);
944
+ branchContainer.setAttribute('height', containerHeight);
945
+ branchContainer.setAttribute('rx', 8);
946
+ branchContainer.setAttribute('fill', 'rgba(0, 0, 0, 0.2)');
947
+ branchContainer.setAttribute('stroke', 'rgba(255, 255, 255, 0.08)');
948
+ branchContainer.setAttribute('stroke-width', 1);
949
+ branchContainer.setAttribute('data-branch-container', 'true');
950
+ branchContainer.setAttribute('data-branch-level', 'nested');
951
+ // Insert AFTER any existing parent containers to maintain proper z-order
952
+ const existingContainers = g.querySelectorAll('[data-branch-container="true"]');
953
+ if (existingContainers.length > 0) {
954
+ // Insert after the last container so nested appears on top of parent
955
+ const lastContainer = existingContainers[existingContainers.length - 1];
956
+ g.insertBefore(branchContainer, lastContainer.nextSibling);
957
+ } else {
958
+ g.insertBefore(branchContainer, g.firstChild);
959
+ }
960
+
961
+ // Add colored border stripe based on branch type
962
+ const stripeColors = {
963
+ 'if': '#22c55e', // Green
964
+ 'else_if': '#f59e0b', // Amber
965
+ 'else': '#a855f7' // Purple
966
+ };
967
+ const stripeColor = branch.isContinue ? '#3b82f6' : (stripeColors[branch.type] || '#22c55e');
968
+
969
+ const branchBorder = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
970
+ branchBorder.setAttribute('x', branchX - 12);
971
+ branchBorder.setAttribute('y', branchStartY - 8);
972
+ branchBorder.setAttribute('width', 4);
973
+ branchBorder.setAttribute('height', containerHeight);
974
+ branchBorder.setAttribute('rx', 2);
975
+ branchBorder.setAttribute('fill', stripeColor);
976
+ branchBorder.setAttribute('data-branch-border', 'true');
977
+ // Insert after the container to maintain z-order
978
+ g.insertBefore(branchBorder, branchContainer.nextSibling);
979
+
980
+ branchEndPositions[branchIndex] = branchY - verticalSpacing;
981
+ maxBranchEndY = Math.max(maxBranchEndY, branchY);
982
+ cumulativeX += branchWidth + branchHorizontalSpacing;
983
+ });
984
+
985
+ // Append button elements
986
+ buttonElements.forEach(buttonElement => {
987
+ g.appendChild(buttonElement);
988
+ });
989
+
990
+ // Draw rejoining fork pattern for multi-branch nested conditionals
991
+ const finalEndY = maxBranchEndY + 48;
992
+ if (isMultiBranch) {
993
+ // Calculate rejoin point (halfway between branch ends and final end)
994
+ const rejoinSpacing = 30;
995
+ const rejoinY = maxBranchEndY + (rejoinSpacing / 2);
996
+
997
+ // Draw vertical lines from each branch up to rejoin point
998
+ let convergenceCumulativeX = branchStartX;
999
+ nestedBranches.forEach((branch, branchIndex) => {
1000
+ const branchWidth = branchWidths[branchIndex];
1001
+ const branchX = convergenceCumulativeX;
1002
+ const branchEndY = branchEndPositions[branchIndex];
1003
+ const branchCenterX = branchX + (branchWidth / 2);
1004
+
1005
+ const verticalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
1006
+ verticalLine.setAttribute('x1', branchCenterX);
1007
+ verticalLine.setAttribute('y1', branchEndY);
1008
+ verticalLine.setAttribute('x2', branchCenterX);
1009
+ verticalLine.setAttribute('y2', rejoinY);
1010
+ verticalLine.setAttribute('stroke', '#6b7280');
1011
+ verticalLine.setAttribute('stroke-width', 2);
1012
+ verticalLine.setAttribute('stroke-dasharray', '5,5');
1013
+ g.appendChild(verticalLine);
1014
+
1015
+ convergenceCumulativeX += branchWidth + branchHorizontalSpacing;
1016
+ });
1017
+
1018
+ // Draw horizontal line connecting all branches at rejoin point
1019
+ const leftmostBranchCenterX = branchStartX + (branchWidths[0] / 2);
1020
+ const rightmostBranchCenterX = branchStartX + branchWidths.reduce((sum, w, idx) => {
1021
+ if (idx < branchCount - 1) {
1022
+ return sum + w + branchHorizontalSpacing;
1023
+ }
1024
+ return sum + w;
1025
+ }, 0) - branchWidths[branchCount - 1] + (branchWidths[branchCount - 1] / 2);
1026
+
1027
+ const horizontalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
1028
+ horizontalLine.setAttribute('x1', leftmostBranchCenterX);
1029
+ horizontalLine.setAttribute('y1', rejoinY);
1030
+ horizontalLine.setAttribute('x2', rightmostBranchCenterX);
1031
+ horizontalLine.setAttribute('y2', rejoinY);
1032
+ horizontalLine.setAttribute('stroke', '#6b7280');
1033
+ horizontalLine.setAttribute('stroke-width', 2);
1034
+ horizontalLine.setAttribute('stroke-dasharray', '5,5');
1035
+ g.appendChild(horizontalLine);
1036
+
1037
+ // Draw vertical line from rejoin point down to final end point
1038
+ const parentCenterX = parentX + (parentWidth / 2);
1039
+ const finalVerticalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
1040
+ finalVerticalLine.setAttribute('x1', parentCenterX);
1041
+ finalVerticalLine.setAttribute('y1', rejoinY);
1042
+ finalVerticalLine.setAttribute('x2', parentCenterX);
1043
+ finalVerticalLine.setAttribute('y2', finalEndY);
1044
+ finalVerticalLine.setAttribute('stroke', '#6b7280');
1045
+ finalVerticalLine.setAttribute('stroke-width', 2);
1046
+ finalVerticalLine.setAttribute('stroke-dasharray', '5,5');
1047
+ g.appendChild(finalVerticalLine);
1048
+ }
1049
+
1050
+ return {
1051
+ endY: finalEndY, // Add button area height to endY so parent knows total height
1052
+ branchEndPositions,
1053
+ totalWidth: totalBranchWidth,
1054
+ actualBranchWidths: branchWidths // Return actual widths used for each branch
1055
+ };
1056
+ }
1057
+
1058
+ /**
1059
+ * Render nodes in branch layout (tree-like structure)
1060
+ */
1061
+ function renderBranchLayout(svg, allComponents) {
1062
+ // Process components to identify branch points
1063
+ const processedComponents = processComponentsForBranching(allComponents);
1064
+
1065
+ // Create a group for all nodes
1066
+ const g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
1067
+ svg.appendChild(g);
1068
+
1069
+ const nodeWidth = 180;
1070
+ const nodeHeight = 150;
1071
+ const verticalSpacing = 60;
1072
+ const branchHorizontalSpacing = 110; // Spacing between branches horizontally (reduced from 220)
1073
+ const sectionSpacing = 200; // Increased spacing between sections
1074
+ const horizontalSpacing = 220;
1075
+ const filterStartX = 100;
1076
+ let currentY = 80;
1077
+
1078
+ // Track last conditional's branch metadata for filter-to-output connection
1079
+ let lastConditionalBranchData = null;
1080
+
1081
+ // Render Input section - always render, even if empty
1082
+ // Always horizontal, centered over first filter
1083
+ const hasInputs = processedComponents.input.length > 0;
1084
+ if (true) {
1085
+ const inputCount = processedComponents.input.length;
1086
+ const firstFilterX = filterStartX;
1087
+
1088
+ // If no inputs, show add button aligned left
1089
+ if (inputCount === 0) {
1090
+ const label = createSectionLabel('INPUT', firstFilterX, currentY, '#3b82f6');
1091
+ g.appendChild(label);
1092
+
1093
+ // Add "Add Input" button aligned left below the label
1094
+ const addButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
1095
+ addButtonFO.setAttribute('x', firstFilterX + (nodeWidth / 2) - 78);
1096
+ addButtonFO.setAttribute('y', currentY + 30);
1097
+ addButtonFO.setAttribute('width', '156');
1098
+ addButtonFO.setAttribute('height', '50');
1099
+
1100
+ const addButtonDiv = document.createElement('div');
1101
+ addButtonDiv.className = 'flex justify-center';
1102
+ addButtonDiv.innerHTML = `
1103
+ <button class="px-4 py-2 text-sm bg-blue-600 hover:bg-blue-700 text-white rounded flex items-center gap-2 transition-colors shadow-lg whitespace-nowrap"
1104
+ onclick="if(typeof PluginModal !== 'undefined') PluginModal.show('input')"
1105
+ title="Add Input">
1106
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1107
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1108
+ </svg>
1109
+ <span>Add Input</span>
1110
+ </button>
1111
+ `;
1112
+ addButtonFO.appendChild(addButtonDiv);
1113
+ g.appendChild(addButtonFO);
1114
+
1115
+ currentY += 180; // Space for empty INPUT section
1116
+
1117
+ // No connection line needed when input is empty
1118
+ } else {
1119
+ const totalInputWidth = (inputCount * nodeWidth) + ((inputCount - 1) * (horizontalSpacing - nodeWidth));
1120
+ const inputStartX = firstFilterX + (nodeWidth / 2) - (totalInputWidth / 2);
1121
+
1122
+ const label = createSectionLabel('INPUT', inputStartX, currentY - 30, '#3b82f6');
1123
+ g.appendChild(label);
1124
+
1125
+ // Calculate position for "Add Input" button
1126
+ // If odd number of inputs, center above middle node
1127
+ // If even number, center between the two middle nodes
1128
+ let addButtonX;
1129
+ if (inputCount % 2 === 1) {
1130
+ // Odd: center above middle node
1131
+ const middleIndex = Math.floor(inputCount / 2);
1132
+ addButtonX = inputStartX + (middleIndex * horizontalSpacing) + (nodeWidth / 2);
1133
+ } else {
1134
+ // Even: center between two middle nodes
1135
+ const leftMiddleIndex = (inputCount / 2) - 1;
1136
+ const leftMiddleX = inputStartX + (leftMiddleIndex * horizontalSpacing);
1137
+ const rightMiddleX = inputStartX + ((leftMiddleIndex + 1) * horizontalSpacing);
1138
+ addButtonX = (leftMiddleX + rightMiddleX + nodeWidth) / 2;
1139
+ }
1140
+
1141
+ // Add "Add Input" button using foreignObject
1142
+ const addButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
1143
+ addButtonFO.setAttribute('x', addButtonX - 50);
1144
+ addButtonFO.setAttribute('y', currentY - 30);
1145
+ addButtonFO.setAttribute('width', '100');
1146
+ addButtonFO.setAttribute('height', '30');
1147
+
1148
+ const addButtonDiv = document.createElement('div');
1149
+ addButtonDiv.className = 'flex justify-center';
1150
+ addButtonDiv.innerHTML = `
1151
+ <button class="px-3 py-1 text-xs bg-blue-600 hover:bg-blue-700 text-white rounded flex items-center gap-1 transition-colors"
1152
+ onclick="if(typeof PluginModal !== 'undefined') PluginModal.show('input')"
1153
+ title="Add Input">
1154
+ <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1155
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1156
+ </svg>
1157
+ <span>Add Input</span>
1158
+ </button>
1159
+ `;
1160
+ addButtonFO.appendChild(addButtonDiv);
1161
+ g.appendChild(addButtonFO);
1162
+
1163
+ // Calculate where the first filter will be positioned
1164
+ const filterY = currentY + nodeHeight + sectionSpacing;
1165
+
1166
+ processedComponents.input.forEach((component, index) => {
1167
+ const inputX = inputStartX + (index * horizontalSpacing);
1168
+ const nodeGroup = createNodeElement(component, inputX, currentY, nodeWidth, nodeHeight, 'input');
1169
+ g.appendChild(nodeGroup);
1170
+
1171
+ // Draw connection line from each input to the next section
1172
+ if (processedComponents.filter.length > 0) {
1173
+ // Draw to filter if it has components
1174
+ const isNewNode = component.id === newlyAddedComponentId;
1175
+ const line = createConnectionLine(
1176
+ inputX + nodeWidth / 2, currentY + nodeHeight,
1177
+ firstFilterX + nodeWidth / 2, filterY,
1178
+ isNewNode,
1179
+ 'filter',
1180
+ 0,
1181
+ false // Don't show buttons on input-to-filter lines
1182
+ );
1183
+ g.insertBefore(line, nodeGroup);
1184
+ } else if (processedComponents.output.length > 0) {
1185
+ // Draw to output if filter is empty but output has components
1186
+ const outputY = filterY + sectionSpacing;
1187
+ const isNewNode = component.id === newlyAddedComponentId;
1188
+ const line = createConnectionLine(
1189
+ inputX + nodeWidth / 2, currentY + nodeHeight,
1190
+ firstFilterX + nodeWidth / 2, outputY,
1191
+ isNewNode,
1192
+ 'output',
1193
+ 0,
1194
+ false
1195
+ );
1196
+ g.insertBefore(line, nodeGroup);
1197
+ }
1198
+ });
1199
+
1200
+ currentY = filterY;
1201
+ }
1202
+ }
1203
+
1204
+ // Render Filter section - always render, even if empty
1205
+ const hasFilters = processedComponents.filter.length > 0;
1206
+ if (true) {
1207
+ const label = createSectionLabel('FILTER', filterStartX, currentY - 45, '#22c55e');
1208
+ g.appendChild(label);
1209
+
1210
+ // If no filters, show add button aligned left below label
1211
+ if (!hasFilters) {
1212
+ const addButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
1213
+ addButtonFO.setAttribute('x', filterStartX + (nodeWidth / 2) - 78);
1214
+ addButtonFO.setAttribute('y', currentY - 15);
1215
+ addButtonFO.setAttribute('width', '156');
1216
+ addButtonFO.setAttribute('height', '50');
1217
+
1218
+ const addButtonDiv = document.createElement('div');
1219
+ addButtonDiv.className = 'flex justify-center gap-2';
1220
+ addButtonDiv.innerHTML = `
1221
+ <button class="px-4 py-2 text-sm bg-green-600 hover:bg-green-700 text-white rounded flex items-center gap-2 transition-colors shadow-lg whitespace-nowrap"
1222
+ onclick="if(typeof PluginModal !== 'undefined') PluginModal.show('filter')"
1223
+ title="Add Filter">
1224
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1225
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1226
+ </svg>
1227
+ <span>Add Filter</span>
1228
+ </button>
1229
+ `;
1230
+ addButtonFO.appendChild(addButtonDiv);
1231
+ g.appendChild(addButtonFO);
1232
+
1233
+ currentY += 150; // Space for empty FILTER section
1234
+ } else {
1235
+
1236
+ // Add hover area and buttons before the first filter component
1237
+ const beforeFirstFilterY = currentY - (verticalSpacing / 2);
1238
+ const beforeFirstFilterHeight = verticalSpacing / 2;
1239
+
1240
+ const beforeFirstFilterHoverArea = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
1241
+ beforeFirstFilterHoverArea.setAttribute('x', filterStartX - 20);
1242
+ beforeFirstFilterHoverArea.setAttribute('y', beforeFirstFilterY);
1243
+ beforeFirstFilterHoverArea.setAttribute('width', nodeWidth + 40);
1244
+ beforeFirstFilterHoverArea.setAttribute('height', beforeFirstFilterHeight);
1245
+ beforeFirstFilterHoverArea.setAttribute('fill', 'transparent');
1246
+ beforeFirstFilterHoverArea.style.cursor = 'pointer';
1247
+ g.appendChild(beforeFirstFilterHoverArea);
1248
+
1249
+ const beforeFirstFilterButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
1250
+ beforeFirstFilterButtonFO.setAttribute('x', filterStartX + (nodeWidth / 2) - 95);
1251
+ beforeFirstFilterButtonFO.setAttribute('y', beforeFirstFilterY + (beforeFirstFilterHeight / 2) - 15);
1252
+ beforeFirstFilterButtonFO.setAttribute('width', '190');
1253
+ beforeFirstFilterButtonFO.setAttribute('height', '30');
1254
+ beforeFirstFilterButtonFO.setAttribute('overflow', 'visible');
1255
+ beforeFirstFilterButtonFO.style.opacity = '0';
1256
+ beforeFirstFilterButtonFO.style.pointerEvents = 'none';
1257
+ beforeFirstFilterButtonFO.style.transition = 'opacity 0.15s ease';
1258
+
1259
+ const beforeFirstFilterButtonDiv = document.createElement('div');
1260
+ beforeFirstFilterButtonDiv.style.display = 'flex';
1261
+ beforeFirstFilterButtonDiv.style.gap = '6px';
1262
+ beforeFirstFilterButtonDiv.style.justifyContent = 'center';
1263
+ beforeFirstFilterButtonDiv.style.alignItems = 'center';
1264
+ beforeFirstFilterButtonDiv.innerHTML = `
1265
+ <button class="graph-add-plugin-btn"
1266
+ data-type="filter"
1267
+ data-index="0"
1268
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #3b82f6; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
1269
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1270
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1271
+ </svg>
1272
+ <span>Add Plugin</span>
1273
+ </button>
1274
+ <button class="graph-add-condition-btn"
1275
+ data-type="filter"
1276
+ data-index="0"
1277
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #d97706; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
1278
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1279
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1280
+ </svg>
1281
+ <span>Add Condition</span>
1282
+ </button>
1283
+ `;
1284
+ beforeFirstFilterButtonFO.appendChild(beforeFirstFilterButtonDiv);
1285
+
1286
+ beforeFirstFilterHoverArea.addEventListener('mouseenter', () => {
1287
+ beforeFirstFilterButtonFO.style.opacity = '1';
1288
+ beforeFirstFilterButtonFO.style.pointerEvents = 'auto';
1289
+ });
1290
+
1291
+ beforeFirstFilterHoverArea.addEventListener('mouseleave', () => {
1292
+ beforeFirstFilterButtonFO.style.opacity = '0';
1293
+ beforeFirstFilterButtonFO.style.pointerEvents = 'none';
1294
+ });
1295
+
1296
+ beforeFirstFilterButtonFO.addEventListener('mouseenter', () => {
1297
+ beforeFirstFilterButtonFO.style.opacity = '1';
1298
+ beforeFirstFilterButtonFO.style.pointerEvents = 'auto';
1299
+ });
1300
+
1301
+ beforeFirstFilterButtonFO.addEventListener('mouseleave', () => {
1302
+ beforeFirstFilterButtonFO.style.opacity = '0';
1303
+ beforeFirstFilterButtonFO.style.pointerEvents = 'none';
1304
+ });
1305
+
1306
+ g.appendChild(beforeFirstFilterButtonFO);
1307
+
1308
+ processedComponents.filter.forEach((component, index) => {
1309
+ // Add hover area between this component and the previous one (if not first)
1310
+ if (index > 0) {
1311
+ const betweenY = currentY - verticalSpacing;
1312
+ const betweenHeight = verticalSpacing;
1313
+
1314
+ const betweenHoverArea = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
1315
+ betweenHoverArea.setAttribute('x', filterStartX - 20);
1316
+ betweenHoverArea.setAttribute('y', betweenY);
1317
+ betweenHoverArea.setAttribute('width', nodeWidth + 40);
1318
+ betweenHoverArea.setAttribute('height', betweenHeight);
1319
+ betweenHoverArea.setAttribute('fill', 'transparent');
1320
+ betweenHoverArea.style.cursor = 'pointer';
1321
+ g.appendChild(betweenHoverArea);
1322
+
1323
+ const betweenButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
1324
+ betweenButtonFO.setAttribute('x', filterStartX + (nodeWidth / 2) - 95);
1325
+ betweenButtonFO.setAttribute('y', betweenY + (betweenHeight / 2) - 15);
1326
+ betweenButtonFO.setAttribute('width', '190');
1327
+ betweenButtonFO.setAttribute('height', '30');
1328
+ betweenButtonFO.setAttribute('overflow', 'visible');
1329
+ betweenButtonFO.style.opacity = '0';
1330
+ betweenButtonFO.style.pointerEvents = 'none';
1331
+ betweenButtonFO.style.transition = 'opacity 0.15s ease';
1332
+
1333
+ const betweenButtonDiv = document.createElement('div');
1334
+ betweenButtonDiv.style.display = 'flex';
1335
+ betweenButtonDiv.style.gap = '6px';
1336
+ betweenButtonDiv.style.justifyContent = 'center';
1337
+ betweenButtonDiv.style.alignItems = 'center';
1338
+ betweenButtonDiv.innerHTML = `
1339
+ <button class="graph-add-plugin-between-btn"
1340
+ data-index="${index}"
1341
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #3b82f6; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
1342
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1343
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1344
+ </svg>
1345
+ <span>Add Plugin</span>
1346
+ </button>
1347
+ <button class="graph-add-condition-between-btn"
1348
+ data-index="${index}"
1349
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #d97706; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
1350
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1351
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1352
+ </svg>
1353
+ <span>Add Condition</span>
1354
+ </button>
1355
+ `;
1356
+ betweenButtonFO.appendChild(betweenButtonDiv);
1357
+
1358
+ betweenHoverArea.addEventListener('mouseenter', () => {
1359
+ betweenButtonFO.style.opacity = '1';
1360
+ betweenButtonFO.style.pointerEvents = 'auto';
1361
+ });
1362
+
1363
+ betweenHoverArea.addEventListener('mouseleave', () => {
1364
+ betweenButtonFO.style.opacity = '0';
1365
+ betweenButtonFO.style.pointerEvents = 'none';
1366
+ });
1367
+
1368
+ betweenButtonFO.addEventListener('mouseenter', () => {
1369
+ betweenButtonFO.style.opacity = '1';
1370
+ betweenButtonFO.style.pointerEvents = 'auto';
1371
+ });
1372
+
1373
+ betweenButtonFO.addEventListener('mouseleave', () => {
1374
+ betweenButtonFO.style.opacity = '0';
1375
+ betweenButtonFO.style.pointerEvents = 'none';
1376
+ });
1377
+
1378
+ g.appendChild(betweenButtonFO);
1379
+ }
1380
+
1381
+ if (component.isBranchPoint) {
1382
+ // This is a conditional - render as branches
1383
+ const branches = component.branches;
1384
+ const branchCount = branches.length;
1385
+
1386
+ // Store Y position before branches for connection lines
1387
+ const beforeBranchY = currentY;
1388
+
1389
+ // Check if this is a multi-branch conditional (has else-if or else)
1390
+ const isMultiBranch = branchCount > 1;
1391
+
1392
+ // Add extra spacing for multi-branch conditionals to account for branches spanning outward
1393
+ // Single-branch conditionals use normal spacing (same as two plugins)
1394
+ const conditionalSpacing = isMultiBranch ? verticalSpacing : 0;
1395
+ currentY += conditionalSpacing;
1396
+
1397
+ // Calculate dynamic widths for each branch using recursive calculation
1398
+ const branchWidths = branches.map(branch =>
1399
+ calculateBranchWidth(branch, nodeWidth, branchHorizontalSpacing)
1400
+ );
1401
+
1402
+ // Recalculate total width and starting positions based on dynamic widths
1403
+ const totalBranchWidth = branchWidths.reduce((sum, w) => sum + w, 0) +
1404
+ ((branchCount - 1) * branchHorizontalSpacing);
1405
+ const dynamicBranchStartX = filterStartX + (nodeWidth / 2) - (totalBranchWidth / 2);
1406
+
1407
+ // Track the maximum Y position across all branches
1408
+ let maxBranchEndY = currentY;
1409
+ const branchEndPositions = []; // Track end Y position of each branch
1410
+ const buttonElements = []; // Store button elements to append after lines
1411
+
1412
+ // Render each branch
1413
+ let cumulativeX = dynamicBranchStartX;
1414
+ branches.forEach((branch, branchIndex) => {
1415
+ const branchWidth = branchWidths[branchIndex];
1416
+ const branchX = cumulativeX;
1417
+ let branchY = currentY; // Start at currentY (with conditional spacing applied)
1418
+ const branchStartY = branchY; // Store start for background container
1419
+
1420
+ // Draw line from previous plugin to this branch's condition node
1421
+ if (index > 0 || processedComponents.input.length > 0) {
1422
+ const line = createConnectionLine(
1423
+ filterStartX + nodeWidth / 2, beforeBranchY,
1424
+ branchX + branchWidth / 2, branchY,
1425
+ false,
1426
+ 'filter',
1427
+ index,
1428
+ false
1429
+ );
1430
+ g.insertBefore(line, g.firstChild);
1431
+ }
1432
+
1433
+ // Create condition node (use dynamic branch width)
1434
+ // Check if this conditional has an else block
1435
+ const hasElse = branches.some(b => b.type === 'else');
1436
+ const conditionNode = {
1437
+ id: branch.id,
1438
+ type: 'filter',
1439
+ plugin: branch.type,
1440
+ isConditional: true,
1441
+ conditionText: branch.condition,
1442
+ hasElse: hasElse,
1443
+ isContinue: branch.isContinue || false,
1444
+ config: {}
1445
+ };
1446
+ const conditionGroup = createNodeElement(conditionNode, branchX, branchY, branchWidth, nodeHeight, 'filter');
1447
+ g.appendChild(conditionGroup);
1448
+
1449
+ branchY += nodeHeight + verticalSpacing;
1450
+ let branchYBeforeNested = branchY;
1451
+
1452
+ // Render plugins in this branch vertically
1453
+ branch.plugins.forEach((plugin, pluginIndex) => {
1454
+ // Add hover area between plugins (not before first plugin)
1455
+ if (pluginIndex > 0) {
1456
+ const betweenY = branchY - verticalSpacing;
1457
+ const betweenHeight = verticalSpacing;
1458
+
1459
+ const betweenHoverArea = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
1460
+ betweenHoverArea.setAttribute('x', branchX - 12);
1461
+ betweenHoverArea.setAttribute('y', betweenY);
1462
+ betweenHoverArea.setAttribute('width', branchWidth + 24);
1463
+ betweenHoverArea.setAttribute('height', betweenHeight);
1464
+ betweenHoverArea.setAttribute('fill', 'transparent');
1465
+ betweenHoverArea.style.cursor = 'pointer';
1466
+ g.appendChild(betweenHoverArea);
1467
+
1468
+ const betweenButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
1469
+ betweenButtonFO.setAttribute('x', branchX + (branchWidth / 2) - 95);
1470
+ betweenButtonFO.setAttribute('y', betweenY + (betweenHeight / 2) - 15);
1471
+ betweenButtonFO.setAttribute('width', '190');
1472
+ betweenButtonFO.setAttribute('height', '30');
1473
+ betweenButtonFO.setAttribute('overflow', 'visible');
1474
+ betweenButtonFO.style.opacity = '0';
1475
+ betweenButtonFO.style.pointerEvents = 'none';
1476
+ betweenButtonFO.style.transition = 'opacity 0.15s ease';
1477
+
1478
+ const betweenButtonDiv = document.createElement('div');
1479
+ betweenButtonDiv.style.display = 'flex';
1480
+ betweenButtonDiv.style.gap = '6px';
1481
+ betweenButtonDiv.style.justifyContent = 'center';
1482
+ betweenButtonDiv.style.alignItems = 'center';
1483
+
1484
+ const blockType = branch.type === 'else_if' ? 'else_if' : (branch.type === 'else' ? 'else' : 'if');
1485
+ const elseIfIndex = branch.type === 'else_if' ? branchIndex - 1 : null;
1486
+
1487
+ betweenButtonDiv.innerHTML = `
1488
+ <button class="graph-add-plugin-to-branch-btn"
1489
+ data-component-id="${component.id}"
1490
+ data-block-type="${blockType}"
1491
+ data-elseif-index="${elseIfIndex}"
1492
+ data-index="${pluginIndex}"
1493
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #3b82f6; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
1494
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1495
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1496
+ </svg>
1497
+ <span>Add Plugin</span>
1498
+ </button>
1499
+ <button class="graph-add-condition-to-branch-btn"
1500
+ data-component-id="${component.id}"
1501
+ data-block-type="${blockType}"
1502
+ data-elseif-index="${elseIfIndex}"
1503
+ data-index="${pluginIndex}"
1504
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #d97706; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
1505
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1506
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1507
+ </svg>
1508
+ <span>Add Condition</span>
1509
+ </button>
1510
+ `;
1511
+ betweenButtonFO.appendChild(betweenButtonDiv);
1512
+
1513
+ betweenHoverArea.addEventListener('mouseenter', () => {
1514
+ betweenButtonFO.style.opacity = '1';
1515
+ betweenButtonFO.style.pointerEvents = 'auto';
1516
+ });
1517
+
1518
+ betweenHoverArea.addEventListener('mouseleave', () => {
1519
+ betweenButtonFO.style.opacity = '0';
1520
+ betweenButtonFO.style.pointerEvents = 'none';
1521
+ });
1522
+
1523
+ betweenButtonFO.addEventListener('mouseenter', () => {
1524
+ betweenButtonFO.style.opacity = '1';
1525
+ betweenButtonFO.style.pointerEvents = 'auto';
1526
+ });
1527
+
1528
+ betweenButtonFO.addEventListener('mouseleave', () => {
1529
+ betweenButtonFO.style.opacity = '0';
1530
+ betweenButtonFO.style.pointerEvents = 'none';
1531
+ });
1532
+
1533
+ g.appendChild(betweenButtonFO);
1534
+ }
1535
+
1536
+ // Draw line from condition node to first plugin, or from previous plugin to next
1537
+ if (pluginIndex === 0) {
1538
+ // Line from condition node to first plugin
1539
+ const blockType = branch.type === 'else_if' ? 'else_if' : (branch.type === 'else' ? 'else' : 'if');
1540
+ const elseIfIndex = branch.type === 'else_if' ? branchIndex - 1 : null;
1541
+ const line = createConnectionLine(
1542
+ branchX + branchWidth / 2, branchY - verticalSpacing,
1543
+ branchX + branchWidth / 2, branchY,
1544
+ false,
1545
+ 'filter',
1546
+ pluginIndex, // Use pluginIndex for insertion at this position
1547
+ true, // Show buttons on connection lines within branches
1548
+ component.id, // Pass component ID for data-component-id
1549
+ blockType,
1550
+ elseIfIndex
1551
+ );
1552
+ g.appendChild(line);
1553
+ }
1554
+
1555
+ // Check if this plugin is itself a branch point (nested conditional)
1556
+ if (plugin.isBranchPoint) {
1557
+ // Recursively render nested conditional as full branch layout
1558
+ const nestedResult = renderNestedConditional(
1559
+ g, plugin, branchX, branchY, branchWidth,
1560
+ nodeWidth, nodeHeight, verticalSpacing, branchHorizontalSpacing,
1561
+ index, component.id
1562
+ );
1563
+ branchY = nestedResult.endY;
1564
+
1565
+ // Draw connection line to next plugin if there is one
1566
+ if (pluginIndex < branch.plugins.length - 1) {
1567
+ const nextY = branchY;
1568
+ const blockType = branch.type === 'else_if' ? 'else_if' : (branch.type === 'else' ? 'else' : 'if');
1569
+ const elseIfIndex = branch.type === 'else_if' ? branchIndex - 1 : null;
1570
+ const line = createConnectionLine(
1571
+ branchX + branchWidth / 2, nestedResult.endY - verticalSpacing,
1572
+ branchX + branchWidth / 2, nextY,
1573
+ false,
1574
+ 'filter',
1575
+ pluginIndex + 1, // Insert after the nested conditional
1576
+ true, // Show buttons on connection lines within branches
1577
+ component.id,
1578
+ blockType,
1579
+ elseIfIndex
1580
+ );
1581
+ g.appendChild(line);
1582
+ }
1583
+ } else {
1584
+ // Regular plugin (use branch width)
1585
+ const pluginGroup = createNodeElement(plugin, branchX, branchY, branchWidth, nodeHeight, 'filter');
1586
+ g.appendChild(pluginGroup);
1587
+
1588
+ // Draw line to next plugin in branch
1589
+ if (pluginIndex < branch.plugins.length - 1) {
1590
+ const nextY = branchY + nodeHeight + verticalSpacing;
1591
+ const blockType = branch.type === 'else_if' ? 'else_if' : (branch.type === 'else' ? 'else' : 'if');
1592
+ const elseIfIndex = branch.type === 'else_if' ? branchIndex - 1 : null;
1593
+ const line = createConnectionLine(
1594
+ branchX + branchWidth / 2, branchY + nodeHeight,
1595
+ branchX + branchWidth / 2, nextY,
1596
+ false,
1597
+ 'filter',
1598
+ pluginIndex + 1, // Insert after this plugin
1599
+ true, // Show buttons on connection lines within branches
1600
+ component.id,
1601
+ blockType,
1602
+ elseIfIndex
1603
+ );
1604
+ g.appendChild(line);
1605
+ }
1606
+
1607
+ branchY += nodeHeight + verticalSpacing;
1608
+ // Update branchYBeforeNested to include this regular plugin
1609
+ branchYBeforeNested = branchY;
1610
+ }
1611
+ });
1612
+
1613
+ // Track the end of this branch
1614
+ maxBranchEndY = Math.max(maxBranchEndY, branchY);
1615
+ branchEndPositions[branchIndex] = branchY - verticalSpacing; // Store actual end position (last element's bottom)
1616
+
1617
+ // Add subtle background container for this branch (use dynamic width)
1618
+ // Use branchY to include nested conditionals in the height calculation
1619
+ const branchHeight = branchY - branchStartY;
1620
+ const branchContainer = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
1621
+ branchContainer.setAttribute('x', branchX - 12);
1622
+ branchContainer.setAttribute('y', branchStartY - 8);
1623
+ branchContainer.setAttribute('width', branchWidth + 24);
1624
+ branchContainer.setAttribute('height', branchHeight - verticalSpacing + 56);
1625
+ branchContainer.setAttribute('rx', 8);
1626
+ branchContainer.setAttribute('fill', 'rgba(0, 0, 0, 0.15)');
1627
+ branchContainer.setAttribute('stroke', 'rgba(255, 255, 255, 0.05)');
1628
+ branchContainer.setAttribute('stroke-width', 1);
1629
+ branchContainer.setAttribute('data-branch-container', 'true');
1630
+ branchContainer.setAttribute('data-branch-level', 'parent');
1631
+ // Insert at beginning of group so it's behind everything
1632
+ g.insertBefore(branchContainer, g.firstChild);
1633
+
1634
+ // Add colored left border stripe based on branch type
1635
+ const stripeColors = {
1636
+ 'if': '#22c55e', // Green
1637
+ 'else_if': '#f59e0b', // Amber
1638
+ 'else': '#a855f7' // Purple
1639
+ };
1640
+ const stripeColor = branch.isContinue ? '#3b82f6' : (stripeColors[branch.type] || '#22c55e');
1641
+
1642
+ const branchBorder = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
1643
+ branchBorder.setAttribute('x', branchX - 12);
1644
+ branchBorder.setAttribute('y', branchStartY - 8);
1645
+ branchBorder.setAttribute('width', 4);
1646
+ branchBorder.setAttribute('height', branchHeight - verticalSpacing + 56);
1647
+ branchBorder.setAttribute('rx', 2);
1648
+ branchBorder.setAttribute('fill', stripeColor);
1649
+ branchBorder.setAttribute('data-branch-border', 'true');
1650
+ // Insert after the container to maintain z-order
1651
+ g.insertBefore(branchBorder, branchContainer.nextSibling);
1652
+
1653
+ // Add buttons at bottom of branch (skip for continue branches)
1654
+ const branchEndY = branchY - verticalSpacing;
1655
+
1656
+ if (!branch.isContinue) {
1657
+ // Determine the elseIfIndex based on branch type and index
1658
+ let elseIfIndex = null;
1659
+ let blockType = 'if';
1660
+
1661
+ if (branch.type === 'else_if') {
1662
+ blockType = 'else_if';
1663
+ elseIfIndex = branchIndex - 1;
1664
+ } else if (branch.type === 'else') {
1665
+ blockType = 'else';
1666
+ }
1667
+
1668
+ // Calculate the index where new plugins should be added (at the end of this branch's plugins)
1669
+ const pluginInsertIndex = branch.plugins ? branch.plugins.length : 0;
1670
+
1671
+ // Add hover area for buttons at bottom of branch
1672
+ const branchButtonHoverArea = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
1673
+ branchButtonHoverArea.setAttribute('x', branchX - 12);
1674
+ branchButtonHoverArea.setAttribute('y', branchEndY);
1675
+ branchButtonHoverArea.setAttribute('width', branchWidth + 24);
1676
+ branchButtonHoverArea.setAttribute('height', 48);
1677
+ branchButtonHoverArea.setAttribute('fill', 'transparent');
1678
+ branchButtonHoverArea.style.cursor = 'pointer';
1679
+ g.appendChild(branchButtonHoverArea);
1680
+
1681
+ // Create buttons in foreignObject (hover-based, centered in branch width)
1682
+ const branchButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
1683
+ branchButtonFO.setAttribute('x', branchX + (branchWidth / 2) - 95);
1684
+ branchButtonFO.setAttribute('y', branchEndY + 10);
1685
+ branchButtonFO.setAttribute('width', '190');
1686
+ branchButtonFO.setAttribute('height', '30');
1687
+ branchButtonFO.setAttribute('overflow', 'visible');
1688
+ branchButtonFO.style.opacity = '0';
1689
+ branchButtonFO.style.pointerEvents = 'none';
1690
+ branchButtonFO.style.transition = 'opacity 0.15s ease';
1691
+
1692
+ const branchButtonDiv = document.createElement('div');
1693
+ branchButtonDiv.style.display = 'flex';
1694
+ branchButtonDiv.style.gap = '6px';
1695
+ branchButtonDiv.style.justifyContent = 'center';
1696
+ branchButtonDiv.style.alignItems = 'center';
1697
+ branchButtonDiv.innerHTML = `
1698
+ <button class="graph-add-plugin-to-branch-btn"
1699
+ data-component-id="${component.id}"
1700
+ data-block-type="${blockType}"
1701
+ data-elseif-index="${elseIfIndex}"
1702
+ data-index="${pluginInsertIndex}"
1703
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #2563eb; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
1704
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1705
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1706
+ </svg>
1707
+ <span>Add Plugin</span>
1708
+ </button>
1709
+ <button class="graph-add-condition-to-branch-btn"
1710
+ data-component-id="${component.id}"
1711
+ data-block-type="${blockType}"
1712
+ data-elseif-index="${elseIfIndex}"
1713
+ data-index="${pluginInsertIndex}"
1714
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #d97706; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
1715
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1716
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1717
+ </svg>
1718
+ <span>Add Condition</span>
1719
+ </button>
1720
+ `;
1721
+ branchButtonFO.appendChild(branchButtonDiv);
1722
+
1723
+ // Show/hide buttons on hover
1724
+ branchButtonHoverArea.addEventListener('mouseenter', () => {
1725
+ branchButtonFO.style.opacity = '1';
1726
+ branchButtonFO.style.pointerEvents = 'auto';
1727
+ });
1728
+
1729
+ branchButtonHoverArea.addEventListener('mouseleave', () => {
1730
+ branchButtonFO.style.opacity = '0';
1731
+ branchButtonFO.style.pointerEvents = 'none';
1732
+ });
1733
+
1734
+ branchButtonFO.addEventListener('mouseenter', () => {
1735
+ branchButtonFO.style.opacity = '1';
1736
+ branchButtonFO.style.pointerEvents = 'auto';
1737
+ });
1738
+
1739
+ branchButtonFO.addEventListener('mouseleave', () => {
1740
+ branchButtonFO.style.opacity = '0';
1741
+ branchButtonFO.style.pointerEvents = 'none';
1742
+ });
1743
+
1744
+ // Store button element to append later (after lines are drawn)
1745
+ buttonElements.push(branchButtonFO);
1746
+ }
1747
+
1748
+ // Advance cumulativeX for next branch
1749
+ cumulativeX += branchWidth + branchHorizontalSpacing;
1750
+ });
1751
+
1752
+ // Move currentY to after all branches
1753
+ currentY = maxBranchEndY;
1754
+
1755
+ // Store branch metadata if this is the last filter component (for filter-to-output connection)
1756
+ if (index === processedComponents.filter.length - 1) {
1757
+ lastConditionalBranchData = {
1758
+ branchEndPositions: [...branchEndPositions],
1759
+ branchWidths: [...branchWidths],
1760
+ dynamicBranchStartX: dynamicBranchStartX,
1761
+ isMultiBranch: isMultiBranch,
1762
+ branchCount: branchCount
1763
+ };
1764
+ }
1765
+
1766
+ // Add extra spacing after conditionals for better visual separation
1767
+ const conditionalExtraSpacing = 20;
1768
+
1769
+ // If there's a next component, draw convergence lines from each branch to it
1770
+ if (index < processedComponents.filter.length - 1) {
1771
+ const nextY = currentY + verticalSpacing + conditionalExtraSpacing;
1772
+
1773
+ // For multi-branch conditionals, draw rejoining fork pattern
1774
+ if (isMultiBranch) {
1775
+ // Calculate the rejoin point (halfway between branches end and next component)
1776
+ const rejoinY = currentY + (conditionalExtraSpacing / 2);
1777
+
1778
+ // Recalculate branch positions for convergence lines
1779
+ let convergenceCumulativeX = dynamicBranchStartX;
1780
+
1781
+ // Draw vertical lines from each branch up to rejoin point
1782
+ branches.forEach((branch, branchIndex) => {
1783
+ const branchWidth = branchWidths[branchIndex];
1784
+ const branchX = convergenceCumulativeX;
1785
+ const branchEndY = branchEndPositions[branchIndex];
1786
+ const branchCenterX = branchX + (branchWidth / 2);
1787
+
1788
+ const verticalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
1789
+ verticalLine.setAttribute('x1', branchCenterX);
1790
+ verticalLine.setAttribute('y1', branchEndY);
1791
+ verticalLine.setAttribute('x2', branchCenterX);
1792
+ verticalLine.setAttribute('y2', rejoinY);
1793
+ verticalLine.setAttribute('stroke', '#6b7280');
1794
+ verticalLine.setAttribute('stroke-width', 2);
1795
+ verticalLine.setAttribute('stroke-dasharray', '5,5');
1796
+ g.appendChild(verticalLine);
1797
+
1798
+ convergenceCumulativeX += branchWidth + branchHorizontalSpacing;
1799
+ });
1800
+
1801
+ // Draw horizontal line connecting all branches at rejoin point
1802
+ const leftmostBranchCenterX = dynamicBranchStartX + (branchWidths[0] / 2);
1803
+ const rightmostBranchCenterX = dynamicBranchStartX + branchWidths.reduce((sum, w, idx) => {
1804
+ if (idx < branchCount - 1) {
1805
+ return sum + w + branchHorizontalSpacing;
1806
+ }
1807
+ return sum + w;
1808
+ }, 0) - branchWidths[branchCount - 1] + (branchWidths[branchCount - 1] / 2);
1809
+
1810
+ const horizontalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
1811
+ horizontalLine.setAttribute('x1', leftmostBranchCenterX);
1812
+ horizontalLine.setAttribute('y1', rejoinY);
1813
+ horizontalLine.setAttribute('x2', rightmostBranchCenterX);
1814
+ horizontalLine.setAttribute('y2', rejoinY);
1815
+ horizontalLine.setAttribute('stroke', '#6b7280');
1816
+ horizontalLine.setAttribute('stroke-width', 2);
1817
+ horizontalLine.setAttribute('stroke-dasharray', '5,5');
1818
+ g.appendChild(horizontalLine);
1819
+
1820
+ // Draw vertical line from rejoin point down to next component
1821
+ const targetX = filterStartX + (nodeWidth / 2);
1822
+ const finalVerticalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
1823
+ finalVerticalLine.setAttribute('x1', targetX);
1824
+ finalVerticalLine.setAttribute('y1', rejoinY);
1825
+ finalVerticalLine.setAttribute('x2', targetX);
1826
+ finalVerticalLine.setAttribute('y2', nextY);
1827
+ finalVerticalLine.setAttribute('stroke', '#6b7280');
1828
+ finalVerticalLine.setAttribute('stroke-width', 2);
1829
+ finalVerticalLine.setAttribute('stroke-dasharray', '5,5');
1830
+ g.appendChild(finalVerticalLine);
1831
+ } else {
1832
+ // Single branch: draw simple line from branch to next component
1833
+ const branchWidth = branchWidths[0];
1834
+ const branchX = dynamicBranchStartX;
1835
+ const branchEndY = branchEndPositions[0];
1836
+
1837
+ const line = createConnectionLine(
1838
+ branchX + branchWidth / 2, branchEndY,
1839
+ filterStartX + nodeWidth / 2, nextY,
1840
+ false,
1841
+ 'filter',
1842
+ index + 1,
1843
+ false
1844
+ );
1845
+ g.appendChild(line);
1846
+ }
1847
+
1848
+ currentY = nextY;
1849
+ }
1850
+
1851
+ // Append all button elements after lines are drawn (so buttons render on top)
1852
+ buttonElements.forEach(buttonElement => {
1853
+ g.appendChild(buttonElement);
1854
+ });
1855
+
1856
+ // Add hover area and buttons after the entire conditional for adding plugin/condition after it
1857
+ // Position buttons lower to rest on the convergence area
1858
+ const afterConditionalY = currentY + (conditionalExtraSpacing / 2);
1859
+ const afterConditionalHoverHeight = 40;
1860
+
1861
+ const afterConditionalHoverArea = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
1862
+ afterConditionalHoverArea.setAttribute('x', filterStartX - 20);
1863
+ afterConditionalHoverArea.setAttribute('y', afterConditionalY);
1864
+ afterConditionalHoverArea.setAttribute('width', nodeWidth + 40);
1865
+ afterConditionalHoverArea.setAttribute('height', afterConditionalHoverHeight);
1866
+ afterConditionalHoverArea.setAttribute('fill', 'transparent');
1867
+ afterConditionalHoverArea.style.cursor = 'pointer';
1868
+ g.appendChild(afterConditionalHoverArea);
1869
+
1870
+ const afterConditionalButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
1871
+ afterConditionalButtonFO.setAttribute('x', filterStartX + (nodeWidth / 2) - 95);
1872
+ afterConditionalButtonFO.setAttribute('y', afterConditionalY + 10);
1873
+ afterConditionalButtonFO.setAttribute('width', '190');
1874
+ afterConditionalButtonFO.setAttribute('height', '30');
1875
+ afterConditionalButtonFO.setAttribute('overflow', 'visible');
1876
+ afterConditionalButtonFO.style.opacity = '0';
1877
+ afterConditionalButtonFO.style.pointerEvents = 'none';
1878
+ afterConditionalButtonFO.style.transition = 'opacity 0.15s ease';
1879
+
1880
+ const afterConditionalButtonDiv = document.createElement('div');
1881
+ afterConditionalButtonDiv.style.display = 'flex';
1882
+ afterConditionalButtonDiv.style.gap = '6px';
1883
+ afterConditionalButtonDiv.style.justifyContent = 'center';
1884
+ afterConditionalButtonDiv.style.alignItems = 'center';
1885
+ afterConditionalButtonDiv.innerHTML = `
1886
+ <button class="graph-add-plugin-after-conditional-btn"
1887
+ data-component-id="${component.id}"
1888
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #3b82f6; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
1889
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1890
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1891
+ </svg>
1892
+ <span>Add Plugin</span>
1893
+ </button>
1894
+ <button class="graph-add-condition-after-conditional-btn"
1895
+ data-component-id="${component.id}"
1896
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #d97706; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
1897
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1898
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1899
+ </svg>
1900
+ <span>Add Condition</span>
1901
+ </button>
1902
+ `;
1903
+ afterConditionalButtonFO.appendChild(afterConditionalButtonDiv);
1904
+
1905
+ // Show/hide buttons on hover
1906
+ afterConditionalHoverArea.addEventListener('mouseenter', () => {
1907
+ afterConditionalButtonFO.style.opacity = '1';
1908
+ afterConditionalButtonFO.style.pointerEvents = 'auto';
1909
+ });
1910
+
1911
+ afterConditionalHoverArea.addEventListener('mouseleave', () => {
1912
+ afterConditionalButtonFO.style.opacity = '0';
1913
+ afterConditionalButtonFO.style.pointerEvents = 'none';
1914
+ });
1915
+
1916
+ afterConditionalButtonFO.addEventListener('mouseenter', () => {
1917
+ afterConditionalButtonFO.style.opacity = '1';
1918
+ afterConditionalButtonFO.style.pointerEvents = 'auto';
1919
+ });
1920
+
1921
+ afterConditionalButtonFO.addEventListener('mouseleave', () => {
1922
+ afterConditionalButtonFO.style.opacity = '0';
1923
+ afterConditionalButtonFO.style.pointerEvents = 'none';
1924
+ });
1925
+
1926
+ g.appendChild(afterConditionalButtonFO);
1927
+
1928
+ } else {
1929
+ // Regular plugin - render normally
1930
+ const nodeGroup = createNodeElement(component, filterStartX, currentY, nodeWidth, nodeHeight, 'filter');
1931
+ g.appendChild(nodeGroup);
1932
+
1933
+ // Draw connection line to next filter (if not the last one)
1934
+ if (index < processedComponents.filter.length - 1) {
1935
+ const isNewNode = component.id === newlyAddedComponentId;
1936
+ const nextY = currentY + nodeHeight + verticalSpacing;
1937
+ const line = createConnectionLine(
1938
+ filterStartX + nodeWidth / 2, currentY + nodeHeight,
1939
+ filterStartX + nodeWidth / 2, nextY,
1940
+ isNewNode,
1941
+ 'filter',
1942
+ index + 1
1943
+ );
1944
+ g.insertBefore(line, nodeGroup);
1945
+ }
1946
+ currentY += nodeHeight + verticalSpacing;
1947
+ }
1948
+ });
1949
+
1950
+ // Add hover area and buttons after the last filter plugin
1951
+ // Skip if last filter is a conditional (conditionals have their own "after conditional" buttons)
1952
+ const lastFilterComponent = processedComponents.filter[processedComponents.filter.length - 1];
1953
+ const shouldAddAfterFilterButtons = processedComponents.filter.length > 0 && !lastFilterComponent.isBranchPoint;
1954
+
1955
+ if (shouldAddAfterFilterButtons) {
1956
+ // Store the position right after the last filter for the connection line
1957
+ const lastFilterBottomY = currentY;
1958
+
1959
+ // Position buttons right at the bottom of the last filter
1960
+ const afterLastFilterY = currentY - verticalSpacing;
1961
+ const afterLastFilterHeight = 40; // Just enough height for the buttons
1962
+
1963
+ const afterLastFilterHoverArea = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
1964
+ afterLastFilterHoverArea.setAttribute('x', filterStartX - 20);
1965
+ afterLastFilterHoverArea.setAttribute('y', afterLastFilterY);
1966
+ afterLastFilterHoverArea.setAttribute('width', nodeWidth + 40);
1967
+ afterLastFilterHoverArea.setAttribute('height', afterLastFilterHeight);
1968
+ afterLastFilterHoverArea.setAttribute('fill', 'transparent');
1969
+ afterLastFilterHoverArea.style.cursor = 'pointer';
1970
+ g.appendChild(afterLastFilterHoverArea);
1971
+
1972
+ const afterLastFilterButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
1973
+ afterLastFilterButtonFO.setAttribute('x', filterStartX + (nodeWidth / 2) - 95);
1974
+ afterLastFilterButtonFO.setAttribute('y', afterLastFilterY + 5);
1975
+ afterLastFilterButtonFO.setAttribute('width', '190');
1976
+ afterLastFilterButtonFO.setAttribute('height', '30');
1977
+ afterLastFilterButtonFO.setAttribute('overflow', 'visible');
1978
+ afterLastFilterButtonFO.style.opacity = '0';
1979
+ afterLastFilterButtonFO.style.pointerEvents = 'none';
1980
+ afterLastFilterButtonFO.style.transition = 'opacity 0.15s ease';
1981
+
1982
+ const afterLastFilterButtonDiv = document.createElement('div');
1983
+ afterLastFilterButtonDiv.style.display = 'flex';
1984
+ afterLastFilterButtonDiv.style.gap = '6px';
1985
+ afterLastFilterButtonDiv.style.justifyContent = 'center';
1986
+ afterLastFilterButtonDiv.style.alignItems = 'center';
1987
+ afterLastFilterButtonDiv.innerHTML = `
1988
+ <button class="graph-add-plugin-btn"
1989
+ data-type="filter"
1990
+ data-index="${processedComponents.filter.length}"
1991
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #3b82f6; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
1992
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1993
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
1994
+ </svg>
1995
+ <span>Add Plugin</span>
1996
+ </button>
1997
+ <button class="graph-add-condition-btn"
1998
+ data-type="filter"
1999
+ data-index="${processedComponents.filter.length}"
2000
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #d97706; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
2001
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2002
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
2003
+ </svg>
2004
+ <span>Add Condition</span>
2005
+ </button>
2006
+ `;
2007
+ afterLastFilterButtonFO.appendChild(afterLastFilterButtonDiv);
2008
+
2009
+ afterLastFilterHoverArea.addEventListener('mouseenter', () => {
2010
+ afterLastFilterButtonFO.style.opacity = '1';
2011
+ afterLastFilterButtonFO.style.pointerEvents = 'auto';
2012
+ });
2013
+
2014
+ afterLastFilterHoverArea.addEventListener('mouseleave', () => {
2015
+ afterLastFilterButtonFO.style.opacity = '0';
2016
+ afterLastFilterButtonFO.style.pointerEvents = 'none';
2017
+ });
2018
+
2019
+ afterLastFilterButtonFO.addEventListener('mouseenter', () => {
2020
+ afterLastFilterButtonFO.style.opacity = '1';
2021
+ afterLastFilterButtonFO.style.pointerEvents = 'auto';
2022
+ });
2023
+
2024
+ afterLastFilterButtonFO.addEventListener('mouseleave', () => {
2025
+ afterLastFilterButtonFO.style.opacity = '0';
2026
+ afterLastFilterButtonFO.style.pointerEvents = 'none';
2027
+ });
2028
+
2029
+ g.appendChild(afterLastFilterButtonFO);
2030
+ }
2031
+
2032
+ // Don't add extra spacing here - currentY is already positioned after the last filter
2033
+ }
2034
+ }
2035
+
2036
+ // Render Output section - always render, even if empty
2037
+ const hasOutputs = processedComponents.output.length > 0;
2038
+ if (true) {
2039
+ // Draw connection line from filter to output (only if filter has components AND output has components)
2040
+ if (processedComponents.filter.length > 0 && processedComponents.output.length > 0) {
2041
+ // Check if the last filter component is a conditional (branch point)
2042
+ const lastFilterComponent = processedComponents.filter[processedComponents.filter.length - 1];
2043
+
2044
+ if (lastFilterComponent.isBranchPoint && lastConditionalBranchData) {
2045
+ // Last filter is a conditional - use stored branch metadata
2046
+ const { branchEndPositions, branchWidths, dynamicBranchStartX, isMultiBranch, branchCount } = lastConditionalBranchData;
2047
+
2048
+ // Add spacing for the connection line
2049
+ const connectionSpacing = 100;
2050
+ const rejoinY = currentY + (connectionSpacing / 2);
2051
+ currentY += connectionSpacing;
2052
+ const lineEndY = currentY;
2053
+
2054
+ if (isMultiBranch) {
2055
+ // Draw vertical lines from each branch up to rejoin point
2056
+ let convergenceCumulativeX = dynamicBranchStartX;
2057
+
2058
+ branchEndPositions.forEach((branchEndY, branchIndex) => {
2059
+ const branchWidth = branchWidths[branchIndex];
2060
+ const branchCenterX = convergenceCumulativeX + (branchWidth / 2);
2061
+
2062
+ const verticalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
2063
+ verticalLine.setAttribute('x1', branchCenterX);
2064
+ verticalLine.setAttribute('y1', branchEndY);
2065
+ verticalLine.setAttribute('x2', branchCenterX);
2066
+ verticalLine.setAttribute('y2', rejoinY);
2067
+ verticalLine.setAttribute('stroke', '#6b7280');
2068
+ verticalLine.setAttribute('stroke-width', 2);
2069
+ verticalLine.setAttribute('stroke-dasharray', '5,5');
2070
+ g.appendChild(verticalLine);
2071
+
2072
+ convergenceCumulativeX += branchWidth + branchHorizontalSpacing;
2073
+ });
2074
+
2075
+ // Draw horizontal line connecting all branches at rejoin point
2076
+ const leftmostBranchCenterX = dynamicBranchStartX + (branchWidths[0] / 2);
2077
+ const rightmostBranchCenterX = dynamicBranchStartX + branchWidths.reduce((sum, w, idx) => {
2078
+ if (idx < branchCount - 1) {
2079
+ return sum + w + branchHorizontalSpacing;
2080
+ }
2081
+ return sum + w;
2082
+ }, 0) - branchWidths[branchCount - 1] + (branchWidths[branchCount - 1] / 2);
2083
+
2084
+ const horizontalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
2085
+ horizontalLine.setAttribute('x1', leftmostBranchCenterX);
2086
+ horizontalLine.setAttribute('y1', rejoinY);
2087
+ horizontalLine.setAttribute('x2', rightmostBranchCenterX);
2088
+ horizontalLine.setAttribute('y2', rejoinY);
2089
+ horizontalLine.setAttribute('stroke', '#6b7280');
2090
+ horizontalLine.setAttribute('stroke-width', 2);
2091
+ horizontalLine.setAttribute('stroke-dasharray', '5,5');
2092
+ g.appendChild(horizontalLine);
2093
+
2094
+ // Draw vertical line from rejoin point down to output section
2095
+ // We'll extend this line later to connect to the first output component
2096
+ const targetX = filterStartX + (nodeWidth / 2);
2097
+ const finalVerticalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
2098
+ finalVerticalLine.setAttribute('x1', targetX);
2099
+ finalVerticalLine.setAttribute('y1', rejoinY);
2100
+ finalVerticalLine.setAttribute('x2', targetX);
2101
+ finalVerticalLine.setAttribute('y2', lineEndY);
2102
+ finalVerticalLine.setAttribute('stroke', '#6b7280');
2103
+ finalVerticalLine.setAttribute('stroke-width', 2);
2104
+ finalVerticalLine.setAttribute('stroke-dasharray', '5,5');
2105
+ finalVerticalLine.setAttribute('data-connection-line', 'filter-to-output');
2106
+ g.appendChild(finalVerticalLine);
2107
+ } else {
2108
+ // Single branch: draw simple line from branch to output
2109
+ const branchWidth = branchWidths[0];
2110
+ const branchCenterX = dynamicBranchStartX + (branchWidth / 2);
2111
+ const branchEndY = branchEndPositions[0];
2112
+
2113
+ const line = createConnectionLine(
2114
+ branchCenterX, branchEndY,
2115
+ filterStartX + nodeWidth / 2, lineEndY,
2116
+ false,
2117
+ 'output',
2118
+ 0,
2119
+ false
2120
+ );
2121
+ g.appendChild(line);
2122
+ }
2123
+ } else {
2124
+ // Last filter is a regular plugin - draw simple connection line
2125
+ const lineStartY = currentY - verticalSpacing;
2126
+ // Add spacing for the connection line
2127
+ currentY += 100;
2128
+ const lineEndY = currentY;
2129
+ const line = createConnectionLine(
2130
+ filterStartX + nodeWidth / 2, lineStartY,
2131
+ filterStartX + nodeWidth / 2, lineEndY,
2132
+ false,
2133
+ 'output',
2134
+ 0,
2135
+ false
2136
+ );
2137
+ line.setAttribute('data-connection-line', 'filter-to-output');
2138
+ g.appendChild(line);
2139
+ }
2140
+ }
2141
+
2142
+ // Add extra spacing before OUTPUT label to prevent collision with convergence lines
2143
+ currentY += 20;
2144
+
2145
+ // Store the Y position where the connection line should end (before the label)
2146
+ const connectionLineEndY = currentY - 20;
2147
+
2148
+ const label = createSectionLabel('OUTPUT', filterStartX, currentY - 45, '#a855f7');
2149
+ g.appendChild(label);
2150
+
2151
+ // If no outputs, show add button aligned left below label
2152
+ if (!hasOutputs) {
2153
+ const addButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
2154
+ addButtonFO.setAttribute('x', filterStartX + (nodeWidth / 2) - 78);
2155
+ addButtonFO.setAttribute('y', currentY - 15);
2156
+ addButtonFO.setAttribute('width', '156');
2157
+ addButtonFO.setAttribute('height', '50');
2158
+
2159
+ const addButtonDiv = document.createElement('div');
2160
+ addButtonDiv.className = 'flex justify-center gap-2';
2161
+ addButtonDiv.innerHTML = `
2162
+ <button class="px-4 py-2 text-sm bg-purple-600 hover:bg-purple-700 text-white rounded flex items-center gap-2 transition-colors shadow-lg whitespace-nowrap"
2163
+ onclick="if(typeof PluginModal !== 'undefined') PluginModal.show('output')"
2164
+ title="Add Output">
2165
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2166
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
2167
+ </svg>
2168
+ <span>Add Output</span>
2169
+ </button>
2170
+ `;
2171
+ addButtonFO.appendChild(addButtonDiv);
2172
+ g.appendChild(addButtonFO);
2173
+
2174
+ currentY += 150; // Space for empty OUTPUT section
2175
+ } else {
2176
+
2177
+ processedComponents.output.forEach((component, index) => {
2178
+ // For the first output component, extend the connection line to reach it
2179
+ if (index === 0 && processedComponents.filter.length > 0) {
2180
+ // Update the connection line to extend to the first output component
2181
+ const connectionLine = g.querySelector('[data-connection-line="filter-to-output"]');
2182
+ if (connectionLine) {
2183
+ // Check if it's a line element (from conditional) or group element (from regular plugin)
2184
+ if (connectionLine.tagName === 'line') {
2185
+ // Simple line element - just update y2
2186
+ connectionLine.setAttribute('y2', currentY);
2187
+ } else if (connectionLine.tagName === 'g') {
2188
+ // Group element from createConnectionLine - find the path inside
2189
+ const pathElement = connectionLine.querySelector('path');
2190
+ if (pathElement) {
2191
+ const d = pathElement.getAttribute('d');
2192
+ // Parse the path: M x1 y1 L x1 midY L x2 midY L x2 y2
2193
+ const parts = d.split(' ');
2194
+ if (parts.length >= 11) {
2195
+ const x1 = parseFloat(parts[1]);
2196
+ const y1 = parseFloat(parts[2]);
2197
+ const x2 = parseFloat(parts[7]);
2198
+ const newMidY = (y1 + currentY) / 2;
2199
+
2200
+ // Update the path with new coordinates
2201
+ const newPath = `M ${x1} ${y1} L ${x1} ${newMidY} L ${x2} ${newMidY} L ${x2} ${currentY}`;
2202
+ pathElement.setAttribute('d', newPath);
2203
+
2204
+ // Also update the hit area (second path element)
2205
+ const paths = connectionLine.querySelectorAll('path');
2206
+ if (paths[1]) {
2207
+ paths[1].setAttribute('d', newPath);
2208
+ }
2209
+ }
2210
+ }
2211
+ }
2212
+ }
2213
+ }
2214
+
2215
+ // Add hover area between components (including before first component for output)
2216
+ if (index > 0 || index === 0) {
2217
+ const betweenY = index === 0 ? currentY - (verticalSpacing / 2) : currentY - verticalSpacing;
2218
+ const betweenHeight = index === 0 ? verticalSpacing / 2 : verticalSpacing;
2219
+
2220
+ const betweenHoverArea = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
2221
+ betweenHoverArea.setAttribute('x', filterStartX - 20);
2222
+ betweenHoverArea.setAttribute('y', betweenY);
2223
+ betweenHoverArea.setAttribute('width', nodeWidth + 40);
2224
+ betweenHoverArea.setAttribute('height', betweenHeight);
2225
+ betweenHoverArea.setAttribute('fill', 'transparent');
2226
+ betweenHoverArea.style.cursor = 'pointer';
2227
+ g.appendChild(betweenHoverArea);
2228
+
2229
+ const betweenButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
2230
+ betweenButtonFO.setAttribute('x', filterStartX + (nodeWidth / 2) - 95);
2231
+ betweenButtonFO.setAttribute('y', betweenY + (betweenHeight / 2) - 15);
2232
+ betweenButtonFO.setAttribute('width', '190');
2233
+ betweenButtonFO.setAttribute('height', '30');
2234
+ betweenButtonFO.setAttribute('overflow', 'visible');
2235
+ betweenButtonFO.style.opacity = '0';
2236
+ betweenButtonFO.style.pointerEvents = 'none';
2237
+ betweenButtonFO.style.transition = 'opacity 0.15s ease';
2238
+
2239
+ const betweenButtonDiv = document.createElement('div');
2240
+ betweenButtonDiv.style.display = 'flex';
2241
+ betweenButtonDiv.style.gap = '6px';
2242
+ betweenButtonDiv.style.justifyContent = 'center';
2243
+ betweenButtonDiv.style.alignItems = 'center';
2244
+ betweenButtonDiv.innerHTML = `
2245
+ <button class="graph-add-plugin-btn"
2246
+ data-type="output"
2247
+ data-index="${index}"
2248
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #3b82f6; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
2249
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2250
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
2251
+ </svg>
2252
+ <span>Add Plugin</span>
2253
+ </button>
2254
+ <button class="graph-add-condition-btn"
2255
+ data-type="output"
2256
+ data-index="${index}"
2257
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #d97706; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
2258
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2259
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
2260
+ </svg>
2261
+ <span>Add Condition</span>
2262
+ </button>
2263
+ `;
2264
+ betweenButtonFO.appendChild(betweenButtonDiv);
2265
+
2266
+ betweenHoverArea.addEventListener('mouseenter', () => {
2267
+ betweenButtonFO.style.opacity = '1';
2268
+ betweenButtonFO.style.pointerEvents = 'auto';
2269
+ });
2270
+
2271
+ betweenHoverArea.addEventListener('mouseleave', () => {
2272
+ betweenButtonFO.style.opacity = '0';
2273
+ betweenButtonFO.style.pointerEvents = 'none';
2274
+ });
2275
+
2276
+ betweenButtonFO.addEventListener('mouseenter', () => {
2277
+ betweenButtonFO.style.opacity = '1';
2278
+ betweenButtonFO.style.pointerEvents = 'auto';
2279
+ });
2280
+
2281
+ betweenButtonFO.addEventListener('mouseleave', () => {
2282
+ betweenButtonFO.style.opacity = '0';
2283
+ betweenButtonFO.style.pointerEvents = 'none';
2284
+ });
2285
+
2286
+ g.appendChild(betweenButtonFO);
2287
+ }
2288
+
2289
+ if (component.isBranchPoint) {
2290
+ // This is a conditional - render as branches (same as filter section)
2291
+ const branches = component.branches;
2292
+ const branchCount = branches.length;
2293
+
2294
+ const beforeBranchY = currentY;
2295
+ const isMultiBranch = branchCount > 1;
2296
+ const conditionalSpacing = isMultiBranch ? verticalSpacing : 0;
2297
+ currentY += conditionalSpacing;
2298
+
2299
+ const branchWidths = branches.map(branch =>
2300
+ calculateBranchWidth(branch, nodeWidth, branchHorizontalSpacing)
2301
+ );
2302
+
2303
+ const totalBranchWidth = branchWidths.reduce((sum, w) => sum + w, 0) +
2304
+ ((branchCount - 1) * branchHorizontalSpacing);
2305
+ const dynamicBranchStartX = filterStartX + (nodeWidth / 2) - (totalBranchWidth / 2);
2306
+
2307
+ let maxBranchEndY = currentY;
2308
+ const branchEndPositions = [];
2309
+ const buttonElements = [];
2310
+
2311
+ // Render each branch
2312
+ let cumulativeX = dynamicBranchStartX;
2313
+ branches.forEach((branch, branchIndex) => {
2314
+ const branchWidth = branchWidths[branchIndex];
2315
+ const branchX = cumulativeX;
2316
+ let branchY = currentY;
2317
+ const branchStartY = branchY;
2318
+
2319
+ // Draw line from previous component to this branch's condition node
2320
+ // For first output component (index 0), draw from filter section if it exists
2321
+ // For subsequent components, draw from previous output
2322
+ if (index === 0 && (processedComponents.filter.length > 0 || processedComponents.input.length > 0)) {
2323
+ // First output component - draw from above (filter or input section)
2324
+ const line = createConnectionLine(
2325
+ filterStartX + nodeWidth / 2, beforeBranchY,
2326
+ branchX + branchWidth / 2, branchY,
2327
+ false,
2328
+ 'output',
2329
+ index,
2330
+ false
2331
+ );
2332
+ g.insertBefore(line, g.firstChild);
2333
+ } else if (index > 0) {
2334
+ // Subsequent output components - draw from previous output
2335
+ const line = createConnectionLine(
2336
+ filterStartX + nodeWidth / 2, beforeBranchY,
2337
+ branchX + branchWidth / 2, branchY,
2338
+ false,
2339
+ 'output',
2340
+ index,
2341
+ false
2342
+ );
2343
+ g.insertBefore(line, g.firstChild);
2344
+ }
2345
+
2346
+ // Create condition node
2347
+ const hasElse = branches.some(b => b.type === 'else');
2348
+ const conditionNode = {
2349
+ id: branch.id,
2350
+ type: 'output',
2351
+ plugin: branch.type,
2352
+ isConditional: true,
2353
+ conditionText: branch.condition,
2354
+ hasElse: hasElse,
2355
+ isContinue: branch.isContinue || false,
2356
+ config: {}
2357
+ };
2358
+ const conditionGroup = createNodeElement(conditionNode, branchX, branchY, branchWidth, nodeHeight, 'output');
2359
+ g.appendChild(conditionGroup);
2360
+
2361
+ branchY += nodeHeight + verticalSpacing;
2362
+ let branchYBeforeNested = branchY;
2363
+
2364
+ // Render plugins in this branch vertically (same pattern as filter section)
2365
+ branch.plugins.forEach((plugin, pluginIndex) => {
2366
+ // Add hover area between plugins
2367
+ if (pluginIndex > 0) {
2368
+ const betweenY = branchY - verticalSpacing;
2369
+ const betweenHeight = verticalSpacing;
2370
+
2371
+ const betweenHoverArea = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
2372
+ betweenHoverArea.setAttribute('x', branchX - 12);
2373
+ betweenHoverArea.setAttribute('y', betweenY);
2374
+ betweenHoverArea.setAttribute('width', branchWidth + 24);
2375
+ betweenHoverArea.setAttribute('height', betweenHeight);
2376
+ betweenHoverArea.setAttribute('fill', 'transparent');
2377
+ betweenHoverArea.style.cursor = 'pointer';
2378
+ g.appendChild(betweenHoverArea);
2379
+
2380
+ const betweenButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
2381
+ betweenButtonFO.setAttribute('x', branchX + (branchWidth / 2) - 95);
2382
+ betweenButtonFO.setAttribute('y', betweenY + (betweenHeight / 2) - 15);
2383
+ betweenButtonFO.setAttribute('width', '190');
2384
+ betweenButtonFO.setAttribute('height', '30');
2385
+ betweenButtonFO.setAttribute('overflow', 'visible');
2386
+ betweenButtonFO.style.opacity = '0';
2387
+ betweenButtonFO.style.pointerEvents = 'none';
2388
+ betweenButtonFO.style.transition = 'opacity 0.15s ease';
2389
+
2390
+ const betweenButtonDiv = document.createElement('div');
2391
+ betweenButtonDiv.style.display = 'flex';
2392
+ betweenButtonDiv.style.gap = '6px';
2393
+ betweenButtonDiv.style.justifyContent = 'center';
2394
+ betweenButtonDiv.style.alignItems = 'center';
2395
+
2396
+ const blockType = branch.type === 'else_if' ? 'else_if' : (branch.type === 'else' ? 'else' : 'if');
2397
+ const elseIfIndex = branch.type === 'else_if' ? branchIndex - 1 : null;
2398
+
2399
+ betweenButtonDiv.innerHTML = `
2400
+ <button class="graph-add-plugin-to-branch-btn"
2401
+ data-component-id="${component.id}"
2402
+ data-block-type="${blockType}"
2403
+ data-elseif-index="${elseIfIndex}"
2404
+ data-index="${pluginIndex}"
2405
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #3b82f6; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
2406
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2407
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
2408
+ </svg>
2409
+ <span>Add Plugin</span>
2410
+ </button>
2411
+ <button class="graph-add-condition-to-branch-btn"
2412
+ data-component-id="${component.id}"
2413
+ data-block-type="${blockType}"
2414
+ data-elseif-index="${elseIfIndex}"
2415
+ data-index="${pluginIndex}"
2416
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #d97706; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
2417
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2418
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
2419
+ </svg>
2420
+ <span>Add Condition</span>
2421
+ </button>
2422
+ `;
2423
+ betweenButtonFO.appendChild(betweenButtonDiv);
2424
+
2425
+ betweenHoverArea.addEventListener('mouseenter', () => {
2426
+ betweenButtonFO.style.opacity = '1';
2427
+ betweenButtonFO.style.pointerEvents = 'auto';
2428
+ });
2429
+
2430
+ betweenHoverArea.addEventListener('mouseleave', () => {
2431
+ betweenButtonFO.style.opacity = '0';
2432
+ betweenButtonFO.style.pointerEvents = 'none';
2433
+ });
2434
+
2435
+ betweenButtonFO.addEventListener('mouseenter', () => {
2436
+ betweenButtonFO.style.opacity = '1';
2437
+ betweenButtonFO.style.pointerEvents = 'auto';
2438
+ });
2439
+
2440
+ betweenButtonFO.addEventListener('mouseleave', () => {
2441
+ betweenButtonFO.style.opacity = '0';
2442
+ betweenButtonFO.style.pointerEvents = 'none';
2443
+ });
2444
+
2445
+ g.appendChild(betweenButtonFO);
2446
+ }
2447
+
2448
+ // Draw line from condition node to first plugin
2449
+ if (pluginIndex === 0) {
2450
+ const blockType = branch.type === 'else_if' ? 'else_if' : (branch.type === 'else' ? 'else' : 'if');
2451
+ const elseIfIndex = branch.type === 'else_if' ? branchIndex - 1 : null;
2452
+ const line = createConnectionLine(
2453
+ branchX + branchWidth / 2, branchY - verticalSpacing,
2454
+ branchX + branchWidth / 2, branchY,
2455
+ false,
2456
+ 'output',
2457
+ pluginIndex,
2458
+ true,
2459
+ component.id,
2460
+ blockType,
2461
+ elseIfIndex
2462
+ );
2463
+ g.appendChild(line);
2464
+ }
2465
+
2466
+ // Check if this plugin is itself a branch point (nested conditional)
2467
+ if (plugin.isBranchPoint) {
2468
+ const nestedResult = renderNestedConditional(
2469
+ g, plugin, branchX, branchY, branchWidth,
2470
+ nodeWidth, nodeHeight, verticalSpacing, branchHorizontalSpacing,
2471
+ index, component.id
2472
+ );
2473
+ branchY = nestedResult.endY;
2474
+ } else {
2475
+ const pluginGroup = createNodeElement(plugin, branchX, branchY, branchWidth, nodeHeight, 'output');
2476
+ g.appendChild(pluginGroup);
2477
+ branchY += nodeHeight + verticalSpacing;
2478
+ }
2479
+ });
2480
+
2481
+ // Add subtle background container for this branch (output section)
2482
+ const branchHeight = branchY - branchStartY;
2483
+ const branchContainer = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
2484
+ branchContainer.setAttribute('x', branchX - 12);
2485
+ branchContainer.setAttribute('y', branchStartY - 8);
2486
+ branchContainer.setAttribute('width', branchWidth + 24);
2487
+ branchContainer.setAttribute('height', branchHeight - verticalSpacing + 56);
2488
+ branchContainer.setAttribute('rx', 8);
2489
+ branchContainer.setAttribute('fill', 'rgba(0, 0, 0, 0.15)');
2490
+ branchContainer.setAttribute('stroke', 'rgba(255, 255, 255, 0.05)');
2491
+ branchContainer.setAttribute('stroke-width', 1);
2492
+ branchContainer.setAttribute('data-branch-container', 'true');
2493
+ branchContainer.setAttribute('data-branch-level', 'parent');
2494
+ // Insert at beginning of group so it's behind everything
2495
+ g.insertBefore(branchContainer, g.firstChild);
2496
+
2497
+ // Add purple left border accent line (for output section)
2498
+ const purpleBorder = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
2499
+ purpleBorder.setAttribute('x', branchX - 12);
2500
+ purpleBorder.setAttribute('y', branchStartY - 8);
2501
+ purpleBorder.setAttribute('width', 4);
2502
+ purpleBorder.setAttribute('height', branchHeight - verticalSpacing + 56);
2503
+ purpleBorder.setAttribute('rx', 2);
2504
+ purpleBorder.setAttribute('fill', '#a855f7'); // Purple-500
2505
+ purpleBorder.setAttribute('data-branch-border', 'true');
2506
+ // Insert after the container to maintain z-order
2507
+ g.insertBefore(purpleBorder, branchContainer.nextSibling);
2508
+
2509
+ // Add buttons at bottom of branch (skip for continue branches)
2510
+ const branchEndY = branchY - verticalSpacing;
2511
+
2512
+ if (!branch.isContinue) {
2513
+ const blockType = branch.type === 'else_if' ? 'else_if' : (branch.type === 'else' ? 'else' : 'if');
2514
+ const elseIfIndex = branch.type === 'else_if' ? branchIndex - 1 : null;
2515
+ const pluginInsertIndex = branch.plugins ? branch.plugins.length : 0;
2516
+
2517
+ const branchButtonHoverArea = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
2518
+ branchButtonHoverArea.setAttribute('x', branchX - 12);
2519
+ branchButtonHoverArea.setAttribute('y', branchEndY);
2520
+ branchButtonHoverArea.setAttribute('width', branchWidth + 24);
2521
+ branchButtonHoverArea.setAttribute('height', 48);
2522
+ branchButtonHoverArea.setAttribute('fill', 'transparent');
2523
+ branchButtonHoverArea.style.cursor = 'pointer';
2524
+ g.appendChild(branchButtonHoverArea);
2525
+
2526
+ const branchButtonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
2527
+ branchButtonFO.setAttribute('x', branchX + (branchWidth / 2) - 95);
2528
+ branchButtonFO.setAttribute('y', branchEndY + 10);
2529
+ branchButtonFO.setAttribute('width', '190');
2530
+ branchButtonFO.setAttribute('height', '30');
2531
+ branchButtonFO.setAttribute('overflow', 'visible');
2532
+ branchButtonFO.style.opacity = '0';
2533
+ branchButtonFO.style.pointerEvents = 'none';
2534
+ branchButtonFO.style.transition = 'opacity 0.15s ease';
2535
+
2536
+ const branchButtonDiv = document.createElement('div');
2537
+ branchButtonDiv.style.display = 'flex';
2538
+ branchButtonDiv.style.gap = '6px';
2539
+ branchButtonDiv.style.justifyContent = 'center';
2540
+ branchButtonDiv.style.alignItems = 'center';
2541
+ branchButtonDiv.innerHTML = `
2542
+ <button class="graph-add-plugin-to-branch-btn"
2543
+ data-component-id="${component.id}"
2544
+ data-block-type="${blockType}"
2545
+ data-elseif-index="${elseIfIndex}"
2546
+ data-index="${pluginInsertIndex}"
2547
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #2563eb; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
2548
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2549
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
2550
+ </svg>
2551
+ <span>Add Plugin</span>
2552
+ </button>
2553
+ <button class="graph-add-condition-to-branch-btn"
2554
+ data-component-id="${component.id}"
2555
+ data-block-type="${blockType}"
2556
+ data-elseif-index="${elseIfIndex}"
2557
+ data-index="${pluginInsertIndex}"
2558
+ style="pointer-events: auto; padding: 4px 8px; border: none; border-radius: 4px; font-size: 11px; cursor: pointer; white-space: nowrap; background-color: #d97706; color: white; display: flex; align-items: center; gap: 4px; font-weight: 500;">
2559
+ <svg style="width: 12px; height: 12px;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2560
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
2561
+ </svg>
2562
+ <span>Add Condition</span>
2563
+ </button>
2564
+ `;
2565
+ branchButtonFO.appendChild(branchButtonDiv);
2566
+
2567
+ branchButtonHoverArea.addEventListener('mouseenter', () => {
2568
+ branchButtonFO.style.opacity = '1';
2569
+ branchButtonFO.style.pointerEvents = 'auto';
2570
+ });
2571
+ branchButtonHoverArea.addEventListener('mouseleave', () => {
2572
+ branchButtonFO.style.opacity = '0';
2573
+ branchButtonFO.style.pointerEvents = 'none';
2574
+ });
2575
+ branchButtonFO.addEventListener('mouseenter', () => {
2576
+ branchButtonFO.style.opacity = '1';
2577
+ branchButtonFO.style.pointerEvents = 'auto';
2578
+ });
2579
+ branchButtonFO.addEventListener('mouseleave', () => {
2580
+ branchButtonFO.style.opacity = '0';
2581
+ branchButtonFO.style.pointerEvents = 'none';
2582
+ });
2583
+
2584
+ buttonElements.push(branchButtonFO);
2585
+ }
2586
+
2587
+ branchEndPositions.push(branchY);
2588
+ if (branchY > maxBranchEndY) {
2589
+ maxBranchEndY = branchY;
2590
+ }
2591
+
2592
+ cumulativeX += branchWidth + branchHorizontalSpacing;
2593
+ });
2594
+
2595
+ // Draw rejoining fork lines at the end of branches
2596
+ if (isMultiBranch) {
2597
+ const convergenceY = maxBranchEndY + verticalSpacing;
2598
+
2599
+ cumulativeX = dynamicBranchStartX;
2600
+ branches.forEach((branch, branchIndex) => {
2601
+ const branchWidth = branchWidths[branchIndex];
2602
+ const branchCenterX = cumulativeX + (branchWidth / 2);
2603
+ const branchEndY = branchEndPositions[branchIndex];
2604
+
2605
+ const verticalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
2606
+ verticalLine.setAttribute('x1', branchCenterX);
2607
+ verticalLine.setAttribute('y1', branchEndY);
2608
+ verticalLine.setAttribute('x2', branchCenterX);
2609
+ verticalLine.setAttribute('y2', convergenceY - (verticalSpacing / 2));
2610
+ verticalLine.setAttribute('stroke', '#6b7280');
2611
+ verticalLine.setAttribute('stroke-width', 2);
2612
+ verticalLine.setAttribute('stroke-dasharray', '5,5');
2613
+ g.appendChild(verticalLine);
2614
+
2615
+ cumulativeX += branchWidth + branchHorizontalSpacing;
2616
+ });
2617
+
2618
+ const leftmostBranchCenterX = dynamicBranchStartX + (branchWidths[0] / 2);
2619
+ const rightmostBranchCenterX = dynamicBranchStartX + branchWidths.reduce((sum, w, idx) => {
2620
+ if (idx < branchCount - 1) {
2621
+ return sum + w + branchHorizontalSpacing;
2622
+ }
2623
+ return sum + w;
2624
+ }, 0) - branchWidths[branchCount - 1] + (branchWidths[branchCount - 1] / 2);
2625
+
2626
+ const horizontalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
2627
+ horizontalLine.setAttribute('x1', leftmostBranchCenterX);
2628
+ horizontalLine.setAttribute('y1', convergenceY - (verticalSpacing / 2));
2629
+ horizontalLine.setAttribute('x2', rightmostBranchCenterX);
2630
+ horizontalLine.setAttribute('y2', convergenceY - (verticalSpacing / 2));
2631
+ horizontalLine.setAttribute('stroke', '#6b7280');
2632
+ horizontalLine.setAttribute('stroke-width', 2);
2633
+ horizontalLine.setAttribute('stroke-dasharray', '5,5');
2634
+ g.appendChild(horizontalLine);
2635
+
2636
+ const centerX = filterStartX + (nodeWidth / 2);
2637
+ const finalVerticalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
2638
+ finalVerticalLine.setAttribute('x1', centerX);
2639
+ finalVerticalLine.setAttribute('y1', convergenceY - (verticalSpacing / 2));
2640
+ finalVerticalLine.setAttribute('x2', centerX);
2641
+ finalVerticalLine.setAttribute('y2', convergenceY);
2642
+ finalVerticalLine.setAttribute('stroke', '#6b7280');
2643
+ finalVerticalLine.setAttribute('stroke-width', 2);
2644
+ finalVerticalLine.setAttribute('stroke-dasharray', '5,5');
2645
+ g.appendChild(finalVerticalLine);
2646
+
2647
+ currentY = convergenceY;
2648
+ } else {
2649
+ currentY = maxBranchEndY;
2650
+ }
2651
+
2652
+ buttonElements.forEach(btn => g.appendChild(btn));
2653
+
2654
+ } else {
2655
+ // Regular plugin (not a conditional)
2656
+ const nodeGroup = createNodeElement(component, filterStartX, currentY, nodeWidth, nodeHeight, 'output');
2657
+ g.appendChild(nodeGroup);
2658
+
2659
+ // Draw connection line to next component (if not the last one)
2660
+ if (index < processedComponents.output.length - 1) {
2661
+ const isNewNode = component.id === newlyAddedComponentId;
2662
+ const nextY = currentY + nodeHeight + verticalSpacing;
2663
+ const line = createConnectionLine(
2664
+ filterStartX + nodeWidth / 2, currentY + nodeHeight,
2665
+ filterStartX + nodeWidth / 2, nextY,
2666
+ isNewNode,
2667
+ 'output',
2668
+ index + 1
2669
+ );
2670
+ g.insertBefore(line, nodeGroup);
2671
+ }
2672
+ currentY += nodeHeight + verticalSpacing;
2673
+ }
2674
+ });
2675
+ }
2676
+ }
2677
+ }
2678
+
2679
+ /**
2680
+ * Create a section label
2681
+ */
2682
+ function createSectionLabel(text, x, y, color) {
2683
+ const label = document.createElementNS('http://www.w3.org/2000/svg', 'text');
2684
+ label.setAttribute('x', x);
2685
+ label.setAttribute('y', y);
2686
+ label.setAttribute('fill', color);
2687
+ label.setAttribute('font-size', '12');
2688
+ label.setAttribute('font-weight', '600');
2689
+ label.setAttribute('letter-spacing', '0.1em');
2690
+ label.textContent = text;
2691
+ return label;
2692
+ }
2693
+
2694
+ /**
2695
+ * Create a node element for a component
2696
+ */
2697
+ function createNodeElement(component, x, y, width, height, type) {
2698
+ const group = document.createElementNS('http://www.w3.org/2000/svg', 'g');
2699
+ group.setAttribute('class', 'graph-node');
2700
+ group.setAttribute('data-id', component.id);
2701
+ group.setAttribute('data-component-id', component.id);
2702
+
2703
+ // Determine color based on type - using dark gray bg with colored borders
2704
+ const colors = {
2705
+ input: { fill: '#374151', stroke: '#3b82f6', text: '#60a5fa' },
2706
+ filter: { fill: '#374151', stroke: '#22c55e', text: '#86efac' },
2707
+ output: { fill: '#374151', stroke: '#a855f7', text: '#c084fc' }
2708
+ };
2709
+
2710
+ // Special colors for conditional nodes
2711
+ const conditionalColors = {
2712
+ if: { fill: '#422006', stroke: '#f59e0b', text: '#fbbf24' }, // Amber/orange for if
2713
+ else_if: { fill: '#422006', stroke: '#f59e0b', text: '#fbbf24' }, // Same amber for else_if
2714
+ else: { fill: '#422006', stroke: '#f59e0b', text: '#fbbf24' }, // Same amber for else
2715
+ continue: { fill: '#1e3a8a', stroke: '#3b82f6', text: '#60a5fa' } // Blue for continue
2716
+ };
2717
+
2718
+ // Check if this is a conditional node or continue branch
2719
+ const isConditional = component.isConditional || component.plugin === 'if' || component.plugin === 'else_if' || component.plugin === 'else';
2720
+ const isContinue = component.isContinue || component.type === 'continue';
2721
+ const color = isContinue ? conditionalColors.continue : (isConditional ? conditionalColors[component.plugin] || conditionalColors.if : (colors[type] || colors.filter));
2722
+
2723
+ // Build config summary
2724
+ const configItems = [];
2725
+
2726
+ // For conditional nodes and continue branches, show the condition text
2727
+ if ((isConditional || isContinue) && component.conditionText) {
2728
+ configItems.push({ key: 'condition', value: component.conditionText });
2729
+ }
2730
+
2731
+ // Add other config items
2732
+ if (component.config && Object.keys(component.config).length > 0) {
2733
+ for (const [key, value] of Object.entries(component.config)) {
2734
+ if (value !== undefined && value !== null && value !== '' &&
2735
+ key !== 'plugins' && key !== 'else_ifs' && key !== 'else' && key !== 'condition') {
2736
+ const displayValue = formatConfigValueForGraph(value, key);
2737
+ configItems.push({ key, value: displayValue });
2738
+ }
2739
+ }
2740
+ }
2741
+
2742
+ // Use fixed node height of 150px
2743
+ const nodeHeight = 150;
2744
+ const baseHeight = 50; // Height for header section
2745
+ const configItemHeight = 24; // Height per config item
2746
+ const configPadding = 12; // Padding for config section
2747
+
2748
+ // Create node rectangle with dark background
2749
+ const rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
2750
+ rect.setAttribute('x', x);
2751
+ rect.setAttribute('y', y);
2752
+ rect.setAttribute('width', width);
2753
+ rect.setAttribute('height', nodeHeight);
2754
+ rect.setAttribute('rx', 8);
2755
+ rect.setAttribute('fill', color.fill);
2756
+ rect.setAttribute('stroke', color.stroke);
2757
+ rect.setAttribute('stroke-width', 2);
2758
+ rect.style.cursor = 'pointer';
2759
+
2760
+ // Apply blue glow animation if this is a newly added node
2761
+ if (component.id === newlyAddedComponentId) {
2762
+ group.setAttribute('class', 'graph-node graph-node-glow');
2763
+ // Clear the newlyAddedComponentId after applying the animation
2764
+ setTimeout(() => {
2765
+ newlyAddedComponentId = null;
2766
+ }, 6000);
2767
+ } else {
2768
+ group.setAttribute('class', 'graph-node');
2769
+ }
2770
+
2771
+ group.appendChild(rect);
2772
+
2773
+ // Add header section with icon, plugin name, and buttons using foreignObject
2774
+ const headerFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
2775
+ headerFO.setAttribute('x', x);
2776
+ headerFO.setAttribute('y', y);
2777
+ headerFO.setAttribute('width', width);
2778
+ headerFO.setAttribute('height', baseHeight);
2779
+
2780
+ // Move handle (see move_graph.js): not for inputs (no ordered slots in the graph),
2781
+ // not for pinned plugins, and for conditionals only on the "if" node, which moves
2782
+ // the whole conditional including all of its branches.
2783
+ const isIfNode = isConditional && !isContinue && component.plugin === 'if';
2784
+ const canMove = type !== 'input' &&
2785
+ !(window.isPinnedPipelineComponent && window.isPinnedPipelineComponent(component)) &&
2786
+ (!isConditional || isIfNode);
2787
+ const moveHandleHtml = canMove ? `
2788
+ <button class="text-gray-400 hover:text-white p-1 graph-move-handle"
2789
+ data-graph-move-id="${component.id}"
2790
+ title="${isIfNode ? 'Move this condition' : 'Move this component'}">
2791
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2792
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8h16M4 16h16" />
2793
+ </svg>
2794
+ </button>
2795
+ ` : '';
2796
+
2797
+ const headerDiv = document.createElement('div');
2798
+ headerDiv.className = 'flex items-center justify-between p-3 graph-node-header';
2799
+ headerDiv.innerHTML = `
2800
+ <div class="flex items-center gap-2 flex-1 min-w-0">
2801
+ <img src="/static/images/${component.plugin}.png"
2802
+ alt="${component.plugin}"
2803
+ class="w-5 h-5 object-contain flex-shrink-0"
2804
+ onerror="this.style.display='none';">
2805
+ <span class="font-medium text-white truncate" style="color: ${color.text}">${component.plugin || 'Unknown'}</span>
2806
+ </div>
2807
+ <div class="flex gap-1 flex-shrink-0 opacity-0 group-hover:opacity-100 transition-opacity graph-node-buttons">
2808
+ ${moveHandleHtml}
2809
+ ${(isConditional && !isContinue) ? `
2810
+ <button class="text-gray-400 hover:text-white p-1 graph-edit-condition-btn"
2811
+ data-component-id="${component.id}"
2812
+ data-plugin="${component.plugin}"
2813
+ title="Edit Condition">
2814
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2815
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
2816
+ </svg>
2817
+ </button>
2818
+ ` : ''}
2819
+ <button class="text-gray-400 hover:text-white p-1"
2820
+ onclick="event.stopPropagation(); if(typeof PluginConfigModal !== 'undefined') PluginConfigModal.show(${JSON.stringify(component).replace(/"/g, '&quot;')})"
2821
+ title="Configure">
2822
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2823
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543-.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
2824
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
2825
+ </svg>
2826
+ </button>
2827
+ <button class="text-gray-400 hover:text-red-400 p-1"
2828
+ onclick="event.stopPropagation(); if(typeof removeComponent === 'function') removeComponent('${component.id}')"
2829
+ title="Remove">
2830
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2831
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="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" />
2832
+ </svg>
2833
+ </button>
2834
+ </div>
2835
+ `;
2836
+
2837
+ headerFO.appendChild(headerDiv);
2838
+ group.appendChild(headerFO);
2839
+
2840
+ // Add config items using foreignObject for HTML rendering
2841
+ if (configItems.length > 0) {
2842
+ const maxConfigHeight = nodeHeight - baseHeight - 8; // Leave some padding at bottom
2843
+
2844
+ // Add shaded background area behind config pills
2845
+ const configBg = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
2846
+ configBg.setAttribute('x', x + 8);
2847
+ configBg.setAttribute('y', y + baseHeight);
2848
+ configBg.setAttribute('width', width - 16);
2849
+ configBg.setAttribute('height', maxConfigHeight);
2850
+ configBg.setAttribute('rx', 4);
2851
+ configBg.setAttribute('fill', 'rgba(0, 0, 0, 0.3)'); // Semi-transparent dark background
2852
+ group.appendChild(configBg);
2853
+
2854
+ const configFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
2855
+ configFO.setAttribute('x', x + 8);
2856
+ configFO.setAttribute('y', y + baseHeight);
2857
+ configFO.setAttribute('width', width - 16);
2858
+ configFO.setAttribute('height', maxConfigHeight);
2859
+
2860
+ const configDiv = document.createElement('div');
2861
+ configDiv.className = 'flex flex-wrap gap-1 p-1';
2862
+ configDiv.style.pointerEvents = 'auto'; // Enable pointer events for scrolling
2863
+ configDiv.style.maxHeight = maxConfigHeight + 'px';
2864
+ configDiv.style.overflowY = 'auto';
2865
+ configDiv.style.overflowX = 'hidden';
2866
+ // Subtle scrollbar styling
2867
+ configDiv.style.cssText += `
2868
+ scrollbar-width: thin;
2869
+ scrollbar-color: rgba(107, 114, 128, 0.5) transparent;
2870
+ `;
2871
+ // Webkit scrollbar styling
2872
+ const style = document.createElement('style');
2873
+ style.textContent = `
2874
+ .graph-node-config::-webkit-scrollbar {
2875
+ width: 4px;
2876
+ }
2877
+ .graph-node-config::-webkit-scrollbar-track {
2878
+ background: transparent;
2879
+ }
2880
+ .graph-node-config::-webkit-scrollbar-thumb {
2881
+ background: rgba(107, 114, 128, 0.5);
2882
+ border-radius: 2px;
2883
+ }
2884
+ .graph-node-config::-webkit-scrollbar-thumb:hover {
2885
+ background: rgba(107, 114, 128, 0.7);
2886
+ }
2887
+ `;
2888
+ if (!document.getElementById('graph-node-scrollbar-style')) {
2889
+ style.id = 'graph-node-scrollbar-style';
2890
+ document.head.appendChild(style);
2891
+ }
2892
+ configDiv.classList.add('graph-node-config');
2893
+
2894
+ // Prevent scroll events from bubbling to zoom handler
2895
+ configDiv.addEventListener('wheel', (e) => {
2896
+ e.stopPropagation();
2897
+ }, { passive: false });
2898
+
2899
+ // Prevent clicks on config area from opening modal
2900
+ configDiv.addEventListener('click', (e) => {
2901
+ e.stopPropagation();
2902
+ });
2903
+
2904
+ configItems.forEach(item => {
2905
+ const badge = document.createElement('span');
2906
+ badge.className = 'text-xs bg-gray-800/70 px-2 py-0.5 rounded text-gray-300';
2907
+ badge.textContent = `${item.key}: ${item.value}`;
2908
+ configDiv.appendChild(badge);
2909
+ });
2910
+
2911
+ configFO.appendChild(configDiv);
2912
+ group.appendChild(configFO);
2913
+ }
2914
+
2915
+ // Add + else if and + else buttons at the bottom for conditional nodes
2916
+ if (isConditional && !isContinue) {
2917
+ const bottomButtonsY = y + nodeHeight - 35; // Position near bottom of node
2918
+ const bottomButtonsFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
2919
+ bottomButtonsFO.setAttribute('x', x);
2920
+ bottomButtonsFO.setAttribute('y', bottomButtonsY);
2921
+ bottomButtonsFO.setAttribute('width', width);
2922
+ bottomButtonsFO.setAttribute('height', '30');
2923
+
2924
+ const bottomButtonsDiv = document.createElement('div');
2925
+ bottomButtonsDiv.className = 'flex gap-1 justify-center items-center px-2 opacity-0 transition-opacity graph-node-bottom-buttons';
2926
+ bottomButtonsDiv.style.pointerEvents = 'auto';
2927
+
2928
+ const baseComponentId = component.id.split('_elseif_')[0].split('_else')[0];
2929
+ bottomButtonsDiv.innerHTML = `
2930
+ <button class="px-2 py-1 text-xs bg-yellow-600/80 text-white rounded hover:bg-yellow-600"
2931
+ onclick="event.stopPropagation(); if(typeof addElseIfToConditional === 'function') addElseIfToConditional('${baseComponentId}')"
2932
+ title="Add else if"
2933
+ style="pointer-events: auto;">
2934
+ + else if
2935
+ </button>
2936
+ ${!component.hasElse ? `
2937
+ <button class="px-2 py-1 text-xs bg-yellow-600/80 text-white rounded hover:bg-yellow-600"
2938
+ onclick="event.stopPropagation(); if(typeof addElseToConditional === 'function') addElseToConditional('${baseComponentId}')"
2939
+ title="Add else"
2940
+ style="pointer-events: auto;">
2941
+ + else
2942
+ </button>
2943
+ ` : ''}
2944
+ `;
2945
+
2946
+ bottomButtonsFO.appendChild(bottomButtonsDiv);
2947
+ group.appendChild(bottomButtonsFO);
2948
+ }
2949
+
2950
+ // Add click handler to open config modal or condition prompt
2951
+ group.style.cursor = 'pointer';
2952
+ group.addEventListener('click', async (e) => {
2953
+ // Don't open modal if clicking on a button
2954
+ if (e.target.closest('button')) {
2955
+ return;
2956
+ }
2957
+
2958
+ // Handle continue nodes - do nothing
2959
+ if (isContinue) {
2960
+ return;
2961
+ }
2962
+
2963
+ // Handle if/else_if nodes - show condition prompt
2964
+ if (isConditional && (component.plugin === 'if' || component.plugin === 'else_if')) {
2965
+ if (typeof ConfirmationModal !== 'undefined' && typeof ConfirmationModal.prompt === 'function') {
2966
+ // Get the base component ID (remove _elseif_ or _else suffixes)
2967
+ const baseComponentId = component.id.split('_elseif_')[0].split('_else')[0];
2968
+ const baseComponent = findComponentById(baseComponentId);
2969
+
2970
+ if (!baseComponent) {
2971
+ console.error('Could not find base component:', baseComponentId);
2972
+ return;
2973
+ }
2974
+
2975
+ // Determine which condition we're editing
2976
+ let currentCondition = '';
2977
+ let elseIfIndex = null;
2978
+
2979
+ if (component.plugin === 'if') {
2980
+ currentCondition = baseComponent.config.condition || '';
2981
+ } else if (component.plugin === 'else_if') {
2982
+ // Extract the else_if index from the component ID
2983
+ const match = component.id.match(/_elseif_(\d+)$/);
2984
+ if (match) {
2985
+ elseIfIndex = parseInt(match[1]);
2986
+ currentCondition = baseComponent.config.else_ifs?.[elseIfIndex]?.condition || '';
2987
+ }
2988
+ }
2989
+
2990
+ // Show the prompt
2991
+ const title = component.plugin === 'if' ? 'Edit If Condition' : 'Edit Else-If Condition';
2992
+ const newCondition = await ConfirmationModal.prompt(
2993
+ `Enter the ${component.plugin === 'if' ? 'if' : 'else-if'} condition:`,
2994
+ currentCondition,
2995
+ title,
2996
+ 'e.g., [message] == "error"'
2997
+ );
2998
+
2999
+ if (newCondition !== null && newCondition !== currentCondition) {
3000
+ // Update the condition
3001
+ if (component.plugin === 'if') {
3002
+ baseComponent.config.condition = newCondition;
3003
+ } else if (component.plugin === 'else_if' && elseIfIndex !== null) {
3004
+ baseComponent.config.else_ifs[elseIfIndex].condition = newCondition;
3005
+ }
3006
+
3007
+ // Update the component and refresh UI
3008
+ if (typeof updateComponent === 'function') {
3009
+ updateComponent(baseComponent);
3010
+ }
3011
+ }
3012
+ }
3013
+ return;
3014
+ }
3015
+
3016
+ // Handle else nodes - show plugin config modal (no condition to edit)
3017
+ // Handle regular plugins - show plugin config modal
3018
+ if (typeof PluginConfigModal !== 'undefined') {
3019
+ PluginConfigModal.show(component);
3020
+ }
3021
+ });
3022
+
3023
+ // Add hover effect on the rect
3024
+ group.addEventListener('mouseenter', () => {
3025
+ rect.setAttribute('fill', '#4b5563');
3026
+ // Show buttons in header
3027
+ const buttons = headerDiv.querySelector('.graph-node-buttons');
3028
+ if (buttons) buttons.style.opacity = '1';
3029
+ // Show buttons at bottom for conditionals
3030
+ if (isConditional && !isContinue) {
3031
+ const bottomButtons = group.querySelector('.graph-node-bottom-buttons');
3032
+ if (bottomButtons) bottomButtons.style.opacity = '1';
3033
+ }
3034
+ });
3035
+ group.addEventListener('mouseleave', () => {
3036
+ rect.setAttribute('fill', color.fill);
3037
+ // Hide buttons in header
3038
+ const buttons = headerDiv.querySelector('.graph-node-buttons');
3039
+ if (buttons) buttons.style.opacity = '0';
3040
+ // Hide buttons at bottom for conditionals
3041
+ if (isConditional && !isContinue) {
3042
+ const bottomButtons = group.querySelector('.graph-node-bottom-buttons');
3043
+ if (bottomButtons) bottomButtons.style.opacity = '0';
3044
+ }
3045
+ });
3046
+
3047
+ // Make node draggable with snap-back physics
3048
+ makeDraggable(group, x, y, component.id);
3049
+
3050
+ // Add fade-in animation
3051
+ // Sync global and local newlyAddedComponentId
3052
+ if (window.newlyAddedComponentId) {
3053
+ newlyAddedComponentId = window.newlyAddedComponentId;
3054
+ }
3055
+
3056
+ const isNewNode = component.id === newlyAddedComponentId;
3057
+ const shouldAnimate = isNewNode || isInitialRender;
3058
+
3059
+ if (shouldAnimate) {
3060
+ // Start invisible
3061
+ group.style.opacity = '0';
3062
+
3063
+ // Calculate staggered delay for initial render using dynamic timing
3064
+ const delay = isInitialRender ? nodeRenderIndex * animationDelayPerNode : 0;
3065
+ nodeRenderIndex++;
3066
+
3067
+ // Fade in over 500ms using d3 transition
3068
+ d3.select(group)
3069
+ .transition()
3070
+ .delay(delay)
3071
+ .duration(500)
3072
+ .style('opacity', '1')
3073
+ .on('end', function() {
3074
+ // Clear the flag after animation completes (only for newly added nodes)
3075
+ if (isNewNode) {
3076
+ newlyAddedComponentId = null;
3077
+ window.newlyAddedComponentId = null;
3078
+ }
3079
+ });
3080
+ }
3081
+
3082
+ return group;
3083
+ }
3084
+
3085
+ /**
3086
+ * Format config value for graph display (simplified version)
3087
+ */
3088
+ function formatConfigValueForGraph(value, key) {
3089
+ // Handle arrays
3090
+ if (Array.isArray(value)) {
3091
+ if (value.length === 0) return '[]';
3092
+ if (value.length === 1) return `"${value[0]}"`;
3093
+ return `[${value.length} items]`;
3094
+ }
3095
+
3096
+ // Handle objects
3097
+ if (typeof value === 'object' && value !== null) {
3098
+ const entries = Object.entries(value);
3099
+ if (entries.length === 0) return '{}';
3100
+ if (key === 'codec') {
3101
+ const codecName = Object.keys(value)[0];
3102
+ return `"${codecName}"`;
3103
+ }
3104
+ return `{${entries.length} keys}`;
3105
+ }
3106
+
3107
+ // Handle strings and primitives
3108
+ const str = String(value).replace(/^"|"$/g, '');
3109
+ return str.length > 20 ? str.substring(0, 20) + '...' : str;
3110
+ }
3111
+
3112
+ /**
3113
+ * Create a connection line between nodes with orthogonal (right-angle) routing
3114
+ */
3115
+ function createConnectionLine(x1, y1, x2, y2, isAnimated = false, type = 'filter', index = 0, showButtons = true, componentId = null, blockType = null, elseIfIndex = null) {
3116
+ // Create a group to hold the line and interactive elements
3117
+ const group = document.createElementNS('http://www.w3.org/2000/svg', 'g');
3118
+ group.setAttribute('class', 'connection-line-group');
3119
+
3120
+ // Create orthogonal path: down from start, horizontal, then down to end
3121
+ const midY = (y1 + y2) / 2;
3122
+ const pathData = `M ${x1} ${y1} L ${x1} ${midY} L ${x2} ${midY} L ${x2} ${y2}`;
3123
+
3124
+ // Visible line
3125
+ const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
3126
+ path.setAttribute('d', pathData);
3127
+ path.setAttribute('stroke', '#6b7280');
3128
+ path.setAttribute('stroke-width', 2);
3129
+ path.setAttribute('fill', 'none');
3130
+ path.setAttribute('stroke-dasharray', '5,5');
3131
+
3132
+ // Invisible wider hit area for hover
3133
+ const hitArea = document.createElementNS('http://www.w3.org/2000/svg', 'path');
3134
+ hitArea.setAttribute('d', pathData);
3135
+ hitArea.setAttribute('stroke', 'transparent');
3136
+ hitArea.setAttribute('stroke-width', 20);
3137
+ hitArea.setAttribute('fill', 'none');
3138
+ hitArea.style.cursor = 'pointer';
3139
+
3140
+ // Animate if it's a newly added node OR if this is the initial render
3141
+ const shouldAnimate = isAnimated || isInitialRender;
3142
+
3143
+ if (shouldAnimate) {
3144
+ // Calculate total path length for animation
3145
+ const length = path.getTotalLength();
3146
+
3147
+ // Set up for drawing animation
3148
+ path.setAttribute('stroke-dasharray', length);
3149
+ path.setAttribute('stroke-dashoffset', length);
3150
+
3151
+ // Calculate delay based on current node index for staggered effect using dynamic timing
3152
+ const baseDelay = isInitialRender ? (nodeRenderIndex - 1) * animationDelayPerNode : 0;
3153
+ const animationDelay = baseDelay + 300; // Start after node fade-in begins
3154
+
3155
+ // Animate the line drawing
3156
+ d3.select(path)
3157
+ .transition()
3158
+ .duration(600)
3159
+ .delay(animationDelay)
3160
+ .attr('stroke-dashoffset', 0)
3161
+ .on('end', function() {
3162
+ // Reset to normal dashed line after animation
3163
+ d3.select(this)
3164
+ .attr('stroke-dasharray', '5,5')
3165
+ .attr('stroke-dashoffset', 0);
3166
+ });
3167
+ }
3168
+
3169
+ // Add the hit area and path to the group
3170
+ group.appendChild(hitArea);
3171
+ group.appendChild(path);
3172
+
3173
+ // Add hover buttons using foreignObject (only if showButtons is true)
3174
+ if (!showButtons) {
3175
+ return group;
3176
+ }
3177
+
3178
+ const buttonX = (x1 + x2) / 2;
3179
+ const buttonY = midY;
3180
+ const buttonFO = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
3181
+ buttonFO.setAttribute('x', buttonX - 100);
3182
+ buttonFO.setAttribute('y', buttonY - 12);
3183
+ buttonFO.setAttribute('width', '200');
3184
+ buttonFO.setAttribute('height', '24');
3185
+ buttonFO.style.opacity = '0';
3186
+ buttonFO.style.pointerEvents = 'none';
3187
+ buttonFO.style.transition = 'opacity 0.15s ease';
3188
+
3189
+ const buttonDiv = document.createElement('div');
3190
+ buttonDiv.className = 'flex gap-1 justify-center';
3191
+ buttonDiv.style.cssText = 'gap: 4px;';
3192
+ // If componentId is provided, create buttons for conditional branches with data-component-id
3193
+ // Otherwise, create buttons for top-level components with data-type/data-index
3194
+ if (componentId) {
3195
+ buttonDiv.innerHTML = `
3196
+ <button class="graph-add-plugin-to-branch-btn"
3197
+ data-component-id="${componentId}"
3198
+ data-block-type="${blockType}"
3199
+ data-elseif-index="${elseIfIndex}"
3200
+ data-index="${index}"
3201
+ style="pointer-events: auto; padding: 2px 6px; border: none; border-radius: 3px; font-size: 11px; cursor: pointer; display: flex; align-items: center; white-space: nowrap; height: 20px; background-color: #3b82f6; color: white;">
3202
+ <svg class="w-3 h-3 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width: 12px; height: 12px; margin-right: 4px;">
3203
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
3204
+ </svg>
3205
+ <span>Add Plugin</span>
3206
+ </button>
3207
+ <button class="graph-add-condition-to-branch-btn"
3208
+ data-component-id="${componentId}"
3209
+ data-block-type="${blockType}"
3210
+ data-elseif-index="${elseIfIndex}"
3211
+ data-index="${index}"
3212
+ style="pointer-events: auto; padding: 2px 6px; border: none; border-radius: 3px; font-size: 11px; cursor: pointer; display: flex; align-items: center; white-space: nowrap; height: 20px; background-color: #f59e0b; color: white;">
3213
+ <svg class="w-3 h-3 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width: 12px; height: 12px; margin-right: 4px;">
3214
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
3215
+ </svg>
3216
+ <span>Add Condition</span>
3217
+ </button>
3218
+ `;
3219
+ } else {
3220
+ buttonDiv.innerHTML = `
3221
+ <button class="graph-add-plugin-btn insertion-button add-plugin"
3222
+ data-type="${type}" data-index="${index}"
3223
+ style="pointer-events: auto; padding: 2px 6px; border: none; border-radius: 3px; font-size: 11px; cursor: pointer; display: flex; align-items: center; white-space: nowrap; height: 20px; background-color: #3b82f6; color: white;">
3224
+ <svg class="w-3 h-3 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width: 12px; height: 12px; margin-right: 4px;">
3225
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
3226
+ </svg>
3227
+ <span>Add Plugin</span>
3228
+ </button>
3229
+ ${type === 'filter' || type === 'output' ? `
3230
+ <button class="graph-add-condition-btn insertion-button add-condition"
3231
+ data-type="${type}" data-index="${index}"
3232
+ style="pointer-events: auto; padding: 2px 6px; border: none; border-radius: 3px; font-size: 11px; cursor: pointer; display: flex; align-items: center; white-space: nowrap; height: 20px; background-color: #f59e0b; color: white;">
3233
+ <svg class="w-3 h-3 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width: 12px; height: 12px; margin-right: 4px;">
3234
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
3235
+ </svg>
3236
+ <span>Add Condition</span>
3237
+ </button>
3238
+ ` : ''}
3239
+ `;
3240
+ }
3241
+ buttonFO.appendChild(buttonDiv);
3242
+
3243
+ // Show/hide buttons on hover
3244
+ hitArea.addEventListener('mouseenter', () => {
3245
+ buttonFO.style.opacity = '1';
3246
+ buttonFO.style.pointerEvents = 'auto';
3247
+ });
3248
+
3249
+ hitArea.addEventListener('mouseleave', () => {
3250
+ buttonFO.style.opacity = '0';
3251
+ buttonFO.style.pointerEvents = 'none';
3252
+ });
3253
+
3254
+ buttonFO.addEventListener('mouseenter', () => {
3255
+ buttonFO.style.opacity = '1';
3256
+ buttonFO.style.pointerEvents = 'auto';
3257
+ });
3258
+
3259
+ buttonFO.addEventListener('mouseleave', () => {
3260
+ buttonFO.style.opacity = '0';
3261
+ buttonFO.style.pointerEvents = 'none';
3262
+ });
3263
+
3264
+ // Add buttons to group
3265
+ group.appendChild(buttonFO);
3266
+
3267
+ return group;
3268
+ }
3269
+
3270
+ // Set up listener for component changes
3271
+ document.addEventListener('DOMContentLoaded', function() {
3272
+ // Listen for component additions to re-render graph
3273
+ document.body.addEventListener('componentAdded', function() {
3274
+ // Check both local and global currentEditorMode
3275
+ const editorMode = window.currentEditorMode || (typeof currentEditorMode !== 'undefined' ? currentEditorMode : null);
3276
+
3277
+ if (editorMode === 'graph') {
3278
+ // Use pendingAnimationPluginId if available (after modal save), otherwise use newlyAddedPluginId
3279
+ // pendingAnimationPluginId is set when a plugin is added via modal
3280
+ // newlyAddedPluginId is set for conditions and other direct additions
3281
+ if (typeof pendingAnimationPluginId !== 'undefined' && pendingAnimationPluginId) {
3282
+ newlyAddedComponentId = pendingAnimationPluginId;
3283
+ // Clear it after capturing
3284
+ window.pendingAnimationPluginId = null;
3285
+ } else if (typeof newlyAddedPluginId !== 'undefined' && newlyAddedPluginId) {
3286
+ newlyAddedComponentId = newlyAddedPluginId;
3287
+ // Clear it after capturing
3288
+ window.newlyAddedPluginId = null;
3289
+ }
3290
+ renderGraphEditor();
3291
+ }
3292
+ });
3293
+
3294
+ // Add event listeners for graph connection line buttons
3295
+ document.body.addEventListener('click', async function(e) {
3296
+ // Handle Edit Condition button on conditional nodes
3297
+ if (e.target.closest('.graph-edit-condition-btn')) {
3298
+ e.stopPropagation();
3299
+ const btn = e.target.closest('.graph-edit-condition-btn');
3300
+ const componentId = btn.dataset.componentId;
3301
+ const plugin = btn.dataset.plugin;
3302
+
3303
+ if (typeof ConfirmationModal !== 'undefined' && typeof ConfirmationModal.prompt === 'function') {
3304
+ // Get the base component ID (remove _elseif_ or _else suffixes)
3305
+ const baseComponentId = componentId.split('_elseif_')[0].split('_else')[0];
3306
+ const baseComponent = findComponentById(baseComponentId);
3307
+
3308
+ if (!baseComponent) {
3309
+ console.error('Could not find base component:', baseComponentId);
3310
+ return;
3311
+ }
3312
+
3313
+ // Determine which condition we're editing
3314
+ let currentCondition = '';
3315
+ let elseIfIndex = null;
3316
+
3317
+ if (plugin === 'if') {
3318
+ currentCondition = baseComponent.config.condition || '';
3319
+ } else if (plugin === 'else_if') {
3320
+ // Extract the else_if index from the component ID
3321
+ const match = componentId.match(/_elseif_(\d+)$/);
3322
+ if (match) {
3323
+ elseIfIndex = parseInt(match[1]);
3324
+ currentCondition = baseComponent.config.else_ifs?.[elseIfIndex]?.condition || '';
3325
+ }
3326
+ }
3327
+
3328
+ // Show the prompt
3329
+ const title = plugin === 'if' ? 'Edit If Condition' : 'Edit Else-If Condition';
3330
+ const newCondition = await ConfirmationModal.prompt(
3331
+ `Enter the ${plugin === 'if' ? 'if' : 'else-if'} condition:`,
3332
+ currentCondition,
3333
+ title,
3334
+ 'e.g., [message] == "error"'
3335
+ );
3336
+
3337
+ if (newCondition !== null && newCondition !== currentCondition) {
3338
+ // Update the condition
3339
+ if (plugin === 'if') {
3340
+ baseComponent.config.condition = newCondition;
3341
+ } else if (plugin === 'else_if' && elseIfIndex !== null) {
3342
+ if (!baseComponent.config.else_ifs) {
3343
+ baseComponent.config.else_ifs = [];
3344
+ }
3345
+ if (!baseComponent.config.else_ifs[elseIfIndex]) {
3346
+ baseComponent.config.else_ifs[elseIfIndex] = {};
3347
+ }
3348
+ baseComponent.config.else_ifs[elseIfIndex].condition = newCondition;
3349
+ }
3350
+
3351
+ // Mark as changed and re-render
3352
+ if (typeof markAsChanged === 'function') {
3353
+ markAsChanged();
3354
+ }
3355
+ renderGraphEditor();
3356
+ }
3357
+ }
3358
+ return;
3359
+ }
3360
+
3361
+ // Handle Add Plugin button between components
3362
+ if (e.target.closest('.graph-add-plugin-between-btn')) {
3363
+ const btn = e.target.closest('.graph-add-plugin-between-btn');
3364
+ const index = parseInt(btn.dataset.index);
3365
+
3366
+ if (typeof showPluginModal === 'function') {
3367
+ showPluginModal('filter', index);
3368
+ }
3369
+ }
3370
+
3371
+ // Handle Add Condition button between components
3372
+ if (e.target.closest('.graph-add-condition-between-btn')) {
3373
+ const btn = e.target.closest('.graph-add-condition-between-btn');
3374
+ const index = parseInt(btn.dataset.index);
3375
+
3376
+ if (typeof addConditionAtPosition === 'function') {
3377
+ addConditionAtPosition('filter', index);
3378
+ }
3379
+ }
3380
+
3381
+ // Handle Add Plugin button on connection lines
3382
+ if (e.target.closest('.graph-add-plugin-btn')) {
3383
+ const btn = e.target.closest('.graph-add-plugin-btn');
3384
+ const type = btn.dataset.type;
3385
+ const index = parseInt(btn.dataset.index);
3386
+
3387
+ // Use the existing showPluginModal function from pipeline_editor.js
3388
+ if (typeof showPluginModal === 'function') {
3389
+ showPluginModal(type, index);
3390
+ } else if (typeof PluginModal !== 'undefined') {
3391
+ PluginModal.show(type);
3392
+ }
3393
+ }
3394
+
3395
+ // Handle Add Condition button on connection lines
3396
+ if (e.target.closest('.graph-add-condition-btn')) {
3397
+ const btn = e.target.closest('.graph-add-condition-btn');
3398
+ const type = btn.dataset.type;
3399
+ const index = parseInt(btn.dataset.index);
3400
+
3401
+ // Use the existing addConditionAtPosition function from pipeline_editor.js
3402
+ if (typeof addConditionAtPosition === 'function') {
3403
+ addConditionAtPosition(type, index);
3404
+ }
3405
+ }
3406
+
3407
+ // Handle + else if button between branch columns
3408
+ if (e.target.closest('.graph-add-elseif-btn')) {
3409
+ const btn = e.target.closest('.graph-add-elseif-btn');
3410
+ const componentId = btn.dataset.componentId;
3411
+
3412
+ // Use the existing addElseIfToConditional function from pipeline_editor.js
3413
+ if (typeof addElseIfToConditional === 'function') {
3414
+ addElseIfToConditional(componentId);
3415
+ }
3416
+ }
3417
+
3418
+ // Handle + else button between branch columns
3419
+ if (e.target.closest('.graph-add-else-btn')) {
3420
+ const btn = e.target.closest('.graph-add-else-btn');
3421
+ const componentId = btn.dataset.componentId;
3422
+
3423
+ // Use the existing addElseToConditional function from pipeline_editor.js
3424
+ if (typeof addElseToConditional === 'function') {
3425
+ addElseToConditional(componentId);
3426
+ }
3427
+ }
3428
+
3429
+ // Handle Add Plugin button at bottom of branch
3430
+ if (e.target.closest('.graph-add-plugin-to-branch-btn')) {
3431
+ const btn = e.target.closest('.graph-add-plugin-to-branch-btn');
3432
+ const componentId = btn.dataset.componentId;
3433
+ const blockType = btn.dataset.blockType;
3434
+ const elseIfIndex = btn.dataset.elseifIndex !== 'null' ? parseInt(btn.dataset.elseifIndex) : null;
3435
+ const index = parseInt(btn.dataset.index);
3436
+
3437
+ console.log('[GRAPH] Add Plugin button clicked:', {componentId, blockType, elseIfIndex, index});
3438
+
3439
+ if (typeof addPluginToConditional === 'function') {
3440
+ addPluginToConditional(componentId, blockType, elseIfIndex, index);
3441
+ }
3442
+ }
3443
+
3444
+ // Handle Add Condition button at bottom of branch
3445
+ if (e.target.closest('.graph-add-condition-to-branch-btn')) {
3446
+ const btn = e.target.closest('.graph-add-condition-to-branch-btn');
3447
+ const componentId = btn.dataset.componentId;
3448
+ const blockType = btn.dataset.blockType;
3449
+ const elseIfIndex = btn.dataset.elseifIndex !== 'null' ? parseInt(btn.dataset.elseifIndex) : null;
3450
+ const index = btn.dataset.index !== undefined ? parseInt(btn.dataset.index) : null;
3451
+
3452
+ console.log('[GRAPH] Add Condition button clicked:', {componentId, blockType, elseIfIndex, index});
3453
+
3454
+ // Find the conditional component
3455
+ const component = findComponentById(componentId);
3456
+ if (component && typeof addConditionToConditional === 'function') {
3457
+ // If index is provided, use it; otherwise add at the end
3458
+ let insertIndex = index;
3459
+ if (insertIndex === null) {
3460
+ // Determine which plugin array to use to get the length
3461
+ let targetPlugins;
3462
+ switch (blockType) {
3463
+ case 'if':
3464
+ targetPlugins = component.config.plugins || [];
3465
+ break;
3466
+ case 'else_if':
3467
+ targetPlugins = component.config.else_ifs?.[elseIfIndex]?.plugins || [];
3468
+ break;
3469
+ case 'else':
3470
+ targetPlugins = component.config.else?.plugins || [];
3471
+ break;
3472
+ default:
3473
+ targetPlugins = [];
3474
+ }
3475
+ insertIndex = targetPlugins.length;
3476
+ }
3477
+
3478
+ addConditionToConditional('filter', componentId, blockType, insertIndex, elseIfIndex);
3479
+ }
3480
+ }
3481
+
3482
+ // Handle Add Plugin button below conditional (adds plugin after the entire conditional)
3483
+ if (e.target.closest('.graph-add-plugin-after-conditional-btn')) {
3484
+ const btn = e.target.closest('.graph-add-plugin-after-conditional-btn');
3485
+ const componentId = btn.dataset.componentId;
3486
+
3487
+ // Find the conditional component in the filter array
3488
+ // Use the global components variable, not window.components
3489
+ const filterComponents = (typeof components !== 'undefined' ? components.filter : window.components?.filter) || [];
3490
+ const conditionalIndex = filterComponents.findIndex(c => c.id === componentId);
3491
+
3492
+ if (conditionalIndex !== -1) {
3493
+ // Show plugin modal to add a plugin after this conditional
3494
+ if (typeof showPluginModal === 'function') {
3495
+ showPluginModal('filter', conditionalIndex + 1);
3496
+ }
3497
+ }
3498
+ }
3499
+
3500
+ // Handle Add Condition button below conditional (adds condition after the entire conditional)
3501
+ if (e.target.closest('.graph-add-condition-after-conditional-btn')) {
3502
+ const btn = e.target.closest('.graph-add-condition-after-conditional-btn');
3503
+ const componentId = btn.dataset.componentId;
3504
+
3505
+ // Find the conditional component in the filter array
3506
+ // Use the global components variable, not window.components
3507
+ const filterComponents = (typeof components !== 'undefined' ? components.filter : window.components?.filter) || [];
3508
+ const conditionalIndex = filterComponents.findIndex(c => c.id === componentId);
3509
+
3510
+ if (conditionalIndex !== -1) {
3511
+ // Add a condition after this conditional
3512
+ if (typeof addConditionAtPosition === 'function') {
3513
+ addConditionAtPosition('filter', conditionalIndex + 1);
3514
+ }
3515
+ }
3516
+ }
3517
+ });
3518
+ });
3519
+
3520
+ // Also listen to the global components variable changes as a fallback
3521
+ // This ensures the graph updates even if the event doesn't fire
3522
+ if (typeof MutationObserver !== 'undefined') {
3523
+ document.addEventListener('DOMContentLoaded', function() {
3524
+ // Set up a periodic check when in graph mode
3525
+ setInterval(function() {
3526
+ if (window.currentEditorMode === 'graph') {
3527
+ const graphContainer = document.getElementById('graphModeContainer');
3528
+ if (graphContainer && !graphContainer.classList.contains('hidden')) {
3529
+ // Check if we need to re-render (this is a safety net)
3530
+ const svg = document.getElementById('graphSvg');
3531
+ if (svg && svg.children.length === 0 && typeof components !== 'undefined') {
3532
+ renderGraphEditor();
3533
+ }
3534
+ }
3535
+ }
3536
+ }, 500); // Check every 500ms
3537
+ });
3538
+ }
3539
+
3540
+ // Make functions globally available
3541
+ window.renderGraphEditor = renderGraphEditor;
3542
+ window.toggleGraphFullscreen = toggleGraphFullscreen;