vanilla-agent 1.28.0 → 1.30.0

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.
@@ -0,0 +1,36 @@
1
+ import { Idiomorph } from "idiomorph";
2
+
3
+ export type MorphOptions = {
4
+ preserveTypingAnimation?: boolean;
5
+ };
6
+
7
+ /**
8
+ * Morph a container's contents using idiomorph with chat-widget-specific
9
+ * preservation rules for typing indicators.
10
+ *
11
+ * Action buttons are matched by their `id` attribute (set to `actions-{messageId}`)
12
+ * so idiomorph updates them in place rather than recreating them.
13
+ */
14
+ export const morphMessages = (
15
+ container: HTMLElement,
16
+ newContent: HTMLElement,
17
+ options: MorphOptions = {}
18
+ ): void => {
19
+ const { preserveTypingAnimation = true } = options;
20
+
21
+ Idiomorph.morph(container, newContent.innerHTML, {
22
+ morphStyle: "innerHTML",
23
+ callbacks: {
24
+ beforeNodeMorphed(oldNode: Node, newNode: Node): boolean | void {
25
+ if (!(oldNode instanceof HTMLElement)) return;
26
+
27
+ // Preserve typing indicator dots to maintain animation continuity
28
+ if (preserveTypingAnimation) {
29
+ if (oldNode.classList.contains("tvw-animate-typing")) {
30
+ return false;
31
+ }
32
+ }
33
+ },
34
+ },
35
+ });
36
+ };