MCPcopy Create free account
hub / github.com/Alphanimble/htmlstream / attachStreamActions

Function attachStreamActions

demo/chat/stream-actions.ts:94–114  ·  view source on GitHub ↗
(root: HTMLElement | null)

Source from the content-addressed store, hash-verified

92}
93
94export 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}

Callers 1

ChatAppFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected