| 92 | } |
| 93 | |
| 94 | export function attachStreamActions(root: HTMLElement | null): () => void { |
| 95 | if (!root) { |
| 96 | return () => {}; |
| 97 | } |
| 98 | |
| 99 | const onClick = (event: MouseEvent) => { |
| 100 | const target = event.target; |
| 101 | if (!(target instanceof Element)) { |
| 102 | return; |
| 103 | } |
| 104 | const actionEl = target.closest<HTMLElement>("[data-stream-action]"); |
| 105 | if (!actionEl || !root.contains(actionEl)) { |
| 106 | return; |
| 107 | } |
| 108 | event.preventDefault(); |
| 109 | void runAction(actionEl.dataset.streamAction ?? "", actionEl); |
| 110 | }; |
| 111 | |
| 112 | root.addEventListener("click", onClick); |
| 113 | return () => root.removeEventListener("click", onClick); |
| 114 | } |