@chat-leo/chatleo 0.0.0-stage → 2.0.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.
Files changed (144) hide show
  1. package/LICENSE +21 -0
  2. package/dist/chatleo/chatleo.esm.js +1 -0
  3. package/dist/chatleo/index.esm.js +1 -0
  4. package/dist/chatleo/p-43ada232.entry.js +1 -0
  5. package/dist/chatleo/p-4485e141.entry.js +1 -0
  6. package/dist/chatleo/p-BnCPdbII.js +1 -0
  7. package/dist/chatleo/p-C-l90Wre.js +1 -0
  8. package/dist/chatleo/p-DQuL1Twl.js +1 -0
  9. package/dist/chatleo/p-DmL518NK.js +3 -0
  10. package/dist/chatleo/p-aed60255.entry.js +1 -0
  11. package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
  12. package/dist/cjs/chatleo-avatar_13.cjs.entry.js +2986 -0
  13. package/dist/cjs/chatleo-call-adapter-B2OfC0VZ.js +35 -0
  14. package/dist/cjs/chatleo-chat-input.cjs.entry.js +67 -0
  15. package/dist/cjs/chatleo.cjs.js +25 -0
  16. package/dist/cjs/index-DkSDLR0y.js +56 -0
  17. package/dist/cjs/index-Dxw4YCA_.js +1741 -0
  18. package/dist/cjs/index.cjs.js +7 -0
  19. package/dist/cjs/loader.cjs.js +13 -0
  20. package/dist/cjs/my-component.cjs.entry.js +33 -0
  21. package/dist/collection/__mocks__/stencil-core.js +26 -0
  22. package/dist/collection/collection-manifest.json +27 -0
  23. package/dist/collection/components/chatleo-avatar/chatleo-avatar.css +40 -0
  24. package/dist/collection/components/chatleo-avatar/chatleo-avatar.js +116 -0
  25. package/dist/collection/components/chatleo-chat/chatleo-chat.css +108 -0
  26. package/dist/collection/components/chatleo-chat/chatleo-chat.js +459 -0
  27. package/dist/collection/components/chatleo-chat-header/chatleo-chat-header.css +22 -0
  28. package/dist/collection/components/chatleo-chat-header/chatleo-chat-header.js +105 -0
  29. package/dist/collection/components/chatleo-chat-input/chatleo-chat-input.css +84 -0
  30. package/dist/collection/components/chatleo-chat-input/chatleo-chat-input.js +141 -0
  31. package/dist/collection/components/chatleo-chat-message/chatleo-chat-message.css +149 -0
  32. package/dist/collection/components/chatleo-chat-message/chatleo-chat-message.js +259 -0
  33. package/dist/collection/components/chatleo-component/chatleo-component.css +271 -0
  34. package/dist/collection/components/chatleo-component/chatleo-component.js +1366 -0
  35. package/dist/collection/components/chatleo-new-message-selector/chatleo-new-message-selector.css +96 -0
  36. package/dist/collection/components/chatleo-new-message-selector/chatleo-new-message-selector.js +231 -0
  37. package/dist/collection/components/chatleo-rich-input/chatleo-rich-input.css +352 -0
  38. package/dist/collection/components/chatleo-rich-input/chatleo-rich-input.js +976 -0
  39. package/dist/collection/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.css +169 -0
  40. package/dist/collection/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.js +400 -0
  41. package/dist/collection/components/chatleo-room-list/chatleo-room-list.css +111 -0
  42. package/dist/collection/components/chatleo-room-list/chatleo-room-list.js +180 -0
  43. package/dist/collection/components/chatleo-room-tile-component/chatleo-room-tile-component.css +110 -0
  44. package/dist/collection/components/chatleo-room-tile-component/chatleo-room-tile-component.js +241 -0
  45. package/dist/collection/components/chatleo-room-view/chatleo-room-view.css +93 -0
  46. package/dist/collection/components/chatleo-room-view/chatleo-room-view.js +593 -0
  47. package/dist/collection/components/chatleo-tray-component/chatleo-tray-component.css +284 -0
  48. package/dist/collection/components/chatleo-tray-component/chatleo-tray-component.js +391 -0
  49. package/dist/collection/components/chatleo-user-tile/chatleo-user-tile.css +56 -0
  50. package/dist/collection/components/chatleo-user-tile/chatleo-user-tile.js +149 -0
  51. package/dist/collection/components/my-component/my-component.css +4 -0
  52. package/dist/collection/components/my-component/my-component.js +95 -0
  53. package/dist/collection/index.js +10 -0
  54. package/dist/collection/utils/call-entry.js +34 -0
  55. package/dist/collection/utils/delivery.js +7 -0
  56. package/dist/collection/utils/utils.js +51 -0
  57. package/dist/components/chatleo-avatar.d.ts +11 -0
  58. package/dist/components/chatleo-avatar.js +1 -0
  59. package/dist/components/chatleo-chat-header.d.ts +11 -0
  60. package/dist/components/chatleo-chat-header.js +1 -0
  61. package/dist/components/chatleo-chat-input.d.ts +11 -0
  62. package/dist/components/chatleo-chat-input.js +1 -0
  63. package/dist/components/chatleo-chat-message.d.ts +11 -0
  64. package/dist/components/chatleo-chat-message.js +1 -0
  65. package/dist/components/chatleo-chat.d.ts +11 -0
  66. package/dist/components/chatleo-chat.js +1 -0
  67. package/dist/components/chatleo-component.d.ts +11 -0
  68. package/dist/components/chatleo-component.js +1 -0
  69. package/dist/components/chatleo-new-message-selector.d.ts +11 -0
  70. package/dist/components/chatleo-new-message-selector.js +1 -0
  71. package/dist/components/chatleo-rich-input.d.ts +11 -0
  72. package/dist/components/chatleo-rich-input.js +1 -0
  73. package/dist/components/chatleo-rich-message-renderer.d.ts +11 -0
  74. package/dist/components/chatleo-rich-message-renderer.js +1 -0
  75. package/dist/components/chatleo-room-list.d.ts +11 -0
  76. package/dist/components/chatleo-room-list.js +1 -0
  77. package/dist/components/chatleo-room-tile-component.d.ts +11 -0
  78. package/dist/components/chatleo-room-tile-component.js +1 -0
  79. package/dist/components/chatleo-room-view.d.ts +11 -0
  80. package/dist/components/chatleo-room-view.js +1 -0
  81. package/dist/components/chatleo-tray-component.d.ts +11 -0
  82. package/dist/components/chatleo-tray-component.js +1 -0
  83. package/dist/components/chatleo-user-tile.d.ts +11 -0
  84. package/dist/components/chatleo-user-tile.js +1 -0
  85. package/dist/components/index.d.ts +35 -0
  86. package/dist/components/index.js +1 -0
  87. package/dist/components/my-component.d.ts +11 -0
  88. package/dist/components/my-component.js +1 -0
  89. package/dist/components/p-8kvQ-Uh-.js +1 -0
  90. package/dist/components/p-B7cdqAgv.js +1 -0
  91. package/dist/components/p-BdiOcOYZ.js +1 -0
  92. package/dist/components/p-BlbDSb7D.js +1 -0
  93. package/dist/components/p-BnCPdbII.js +1 -0
  94. package/dist/components/p-C-v19aUJ.js +1 -0
  95. package/dist/components/p-C1mF0s8g.js +1 -0
  96. package/dist/components/p-CRtBdzP3.js +1 -0
  97. package/dist/components/p-CfayCm9O.js +1 -0
  98. package/dist/components/p-DGjAxoQy.js +1 -0
  99. package/dist/components/p-Exj_2-yI.js +1 -0
  100. package/dist/components/p-XlwGxsqT.js +1 -0
  101. package/dist/components/p-fjMaTJam.js +1 -0
  102. package/dist/components/p-xt4kzz3B.js +1 -0
  103. package/dist/esm/app-globals-DQuL1Twl.js +3 -0
  104. package/dist/esm/chatleo-avatar_13.entry.js +2972 -0
  105. package/dist/esm/chatleo-call-adapter-BnCPdbII.js +33 -0
  106. package/dist/esm/chatleo-chat-input.entry.js +65 -0
  107. package/dist/esm/chatleo.js +21 -0
  108. package/dist/esm/index-C-l90Wre.js +53 -0
  109. package/dist/esm/index-DmL518NK.js +1733 -0
  110. package/dist/esm/index.js +1 -0
  111. package/dist/esm/loader.js +11 -0
  112. package/dist/esm/my-component.entry.js +31 -0
  113. package/dist/index.cjs.js +1 -0
  114. package/dist/index.js +1 -0
  115. package/dist/types/__mocks__/stencil-core.d.ts +24 -0
  116. package/dist/types/components/chatleo-avatar/chatleo-avatar.d.ts +27 -0
  117. package/dist/types/components/chatleo-chat/chatleo-chat.d.ts +75 -0
  118. package/dist/types/components/chatleo-chat-header/chatleo-chat-header.d.ts +27 -0
  119. package/dist/types/components/chatleo-chat-input/chatleo-chat-input.d.ts +31 -0
  120. package/dist/types/components/chatleo-chat-message/chatleo-chat-message.d.ts +22 -0
  121. package/dist/types/components/chatleo-component/chatleo-component.d.ts +278 -0
  122. package/dist/types/components/chatleo-new-message-selector/chatleo-new-message-selector.d.ts +68 -0
  123. package/dist/types/components/chatleo-rich-input/chatleo-rich-input.d.ts +216 -0
  124. package/dist/types/components/chatleo-rich-message-renderer/chatleo-rich-message-renderer.d.ts +77 -0
  125. package/dist/types/components/chatleo-room-list/chatleo-room-list.d.ts +52 -0
  126. package/dist/types/components/chatleo-room-tile-component/chatleo-room-tile-component.d.ts +59 -0
  127. package/dist/types/components/chatleo-room-view/chatleo-room-view.d.ts +91 -0
  128. package/dist/types/components/chatleo-tray-component/chatleo-tray-component.d.ts +112 -0
  129. package/dist/types/components/chatleo-user-tile/chatleo-user-tile.d.ts +36 -0
  130. package/dist/types/components/my-component/my-component.d.ts +16 -0
  131. package/dist/types/components.d.ts +1593 -0
  132. package/dist/types/index.d.ts +12 -0
  133. package/dist/types/stencil-public-runtime.d.ts +1879 -0
  134. package/dist/types/utils/call-entry.d.ts +9 -0
  135. package/dist/types/utils/delivery.d.ts +7 -0
  136. package/dist/types/utils/utils.d.ts +24 -0
  137. package/loader/cdn.js +1 -0
  138. package/loader/index.cjs.js +1 -0
  139. package/loader/index.d.ts +24 -0
  140. package/loader/index.es2017.js +1 -0
  141. package/loader/index.js +2 -0
  142. package/package.json +70 -3
  143. package/readme.md +111 -0
  144. package/README.md +0 -3
@@ -0,0 +1,141 @@
1
+ import { h } from "@stencil/core";
2
+ /**
3
+ * @component ChatleoChatInput
4
+ * @description This component provides a simple text input for sending chat messages. It includes a text field, an emoji button, and action buttons for attaching files and sending the message. It can be configured to send messages on `Enter` or `Cmd/Ctrl+Enter`.
5
+ * @property {boolean} disabled - When `true`, the input field and all buttons are disabled, preventing user interaction.
6
+ * @property {boolean} sendOnModifierEnter - If `true`, the message will be sent when the user presses `Cmd+Enter` (on Mac) or `Ctrl+Enter` (on other systems). If `false`, the message is sent on `Enter` alone.
7
+ * @fires messageInputSent - This event is emitted when the user sends a message. The event detail contains the trimmed text of the message.
8
+ */
9
+ export class ChatleoChatInput {
10
+ /**
11
+ * When `true`, the input field and all buttons are disabled, preventing user interaction.
12
+ */
13
+ disabled = false;
14
+ /**
15
+ * If `true`, the message will be sent when the user presses `Cmd+Enter` (on Mac) or `Ctrl+Enter` (on other systems). If `false`, the message is sent on `Enter` alone.
16
+ */
17
+ sendOnModifierEnter = false;
18
+ inputValue = '';
19
+ messageInputSent;
20
+ inputRef;
21
+ isMac = () => {
22
+ return typeof navigator !== 'undefined' && navigator.platform.toUpperCase().indexOf('MAC') >= 0;
23
+ };
24
+ handleSubmit = (e) => {
25
+ e.preventDefault();
26
+ if (this.disabled)
27
+ return;
28
+ const value = this.inputValue.trim();
29
+ if (value) {
30
+ this.messageInputSent.emit(value);
31
+ this.inputValue = '';
32
+ this.inputRef.value = ''; // TODO: why both?
33
+ }
34
+ };
35
+ handleKeyPress = (e) => {
36
+ if (e.key === 'Enter') {
37
+ if (this.sendOnModifierEnter) {
38
+ // Check for Cmd on Mac or Ctrl on Windows/Linux
39
+ const modifierPressed = this.isMac() ? e.metaKey : e.ctrlKey;
40
+ if (modifierPressed) {
41
+ this.handleSubmit(e);
42
+ }
43
+ }
44
+ else {
45
+ // Default behavior: send on Enter
46
+ this.handleSubmit(e);
47
+ }
48
+ }
49
+ };
50
+ handleInput = (e) => {
51
+ const target = e.target;
52
+ this.inputValue = target.value;
53
+ };
54
+ /**
55
+ * @function render
56
+ * @description The render method for the `ChatleoChatInput` component. It creates the layout for the input area, including the text input, emoji button, and action buttons. The `disabled` state of the input and buttons is controlled by the `disabled` prop.
57
+ * @returns {any} A VNode representing the component's UI.
58
+ */
59
+ render() {
60
+ return (h("div", { key: 'd4696c7c5c3a24901303a7ad4ccb5caa46e5a76c', class: "chat-input-container" }, h("div", { key: 'bda9a1218853fa285da618b59da61b7e42c872fa', class: "input-wrapper" }, h("input", { key: '96d1683a63cdfd3129a895a3dbe583a2d7e19618', ref: el => this.inputRef = el, type: "text", placeholder: "Write a comment...", class: "chat-input", onKeyPress: this.handleKeyPress, onInput: this.handleInput, disabled: this.disabled }), h("button", { key: '7de82bd11d42e77cf43d49691c1ce1a5cafa31ab', class: "emoji-button" }, "\uD83D\uDE0A")), h("div", { key: '63d136df55745b6f5c99a17e670fcff32c28a02f', class: "action-buttons" }, h("button", { key: '884b6bb075e46fe72d334720ea18b579c9fd37c0', class: "action-button" }, h("svg", { key: 'ffbcc860666136d91ae0e7833a22f5ecafb9a83e', xmlns: "http://www.w3.org/2000/svg", width: "17", height: "16", viewBox: "0 0 17 16", fill: "none" }, h("path", { key: '8e1f60338db9d48dff0293c120b17b44ea97eba4', d: "M11.9286 3.42858L11.9286 10.5714C11.9286 12.6286 10.2714 14.2857 8.21429 14.2857C6.15714 14.2857 4.5 12.6286 4.5 10.5714L4.5 4.28572C4.5 2.85715 5.64286 1.71429 7.07143 1.71429C8.5 1.71429 9.64286 2.85715 9.64286 4.28572L9.64286 10C9.64286 10.8 9.01429 11.4286 8.21429 11.4286C7.41429 11.4286 6.78571 10.8 6.78571 10L6.78571 5.14287", stroke: "#4A86E8", "stroke-width": "1.5", "stroke-miterlimit": "10", "stroke-linecap": "square" }))), h("button", { key: '1abac7331daae09f49faacaab62eb620dcc138b7', class: "action-button" }, h("svg", { key: '51ad70231d80fb7ca5543904b530697c528e8490', xmlns: "http://www.w3.org/2000/svg", width: "33", height: "32", viewBox: "0 0 33 32", fill: "none" }, h("path", { key: 'd606dad20a4ce3b88d6924a3ca9bd035a40fe894', d: "M10.5 18.5312L14.3226 14.7683C14.6047 14.4907 15.062 14.4907 15.344 14.7683L18.4444 17.8203M18.4444 17.8203L17.3611 18.8867M18.4444 17.8203L19.7393 16.5457C20.0214 16.268 20.4786 16.268 20.7607 16.5457L23.5 19.2422M11.9444 21.375H22.0556C22.8533 21.375 23.5 20.7384 23.5 19.9531V11.4219C23.5 10.6366 22.8533 10 22.0556 10H11.9444C11.1467 10 10.5 10.6366 10.5 11.4219V19.9531C10.5 20.7384 11.1467 21.375 11.9444 21.375ZM21.6944 13.1992C21.6944 13.9845 21.0477 14.6211 20.25 14.6211C19.4523 14.6211 18.8056 13.9845 18.8056 13.1992C18.8056 12.4139 19.4523 11.7773 20.25 11.7773C21.0477 11.7773 21.6944 12.4139 21.6944 13.1992Z", stroke: "#4A86E8", "stroke-width": "1.5", "stroke-linecap": "round", "stroke-linejoin": "round" }))), h("button", { key: '7e90543be4744853a917661f7ee9ad7d7792ea1c', class: "action-button", onClick: this.handleSubmit }, h("svg", { key: '9ca013889d4fec8d45543c54695a6335685b6802', xmlns: "http://www.w3.org/2000/svg", width: "17", height: "16", viewBox: "0 0 17 16", fill: "none" }, h("path", { key: '078800be3b4eef96e6801cd3b9b4036f5ac6c4e0', d: "M14.214 2.28564L5.64258 9.14279L5.64258 13.1428L7.69972 10.6856", stroke: "#4A86E8", "stroke-width": "1.5", "stroke-miterlimit": "10" }), h("path", { key: '10da5167e57bf2f5784a8e0b42c12aedcbb4f2e4', d: "M2.78613 6.85707L14.2147 2.28564L11.929 13.7142L2.78613 6.85707Z", stroke: "#4A86E8", "stroke-width": "1.5", "stroke-miterlimit": "10", "stroke-linecap": "square" }))))));
61
+ }
62
+ static get is() { return "chatleo-chat-input"; }
63
+ static get encapsulation() { return "shadow"; }
64
+ static get originalStyleUrls() {
65
+ return {
66
+ "$": ["chatleo-chat-input.css"]
67
+ };
68
+ }
69
+ static get styleUrls() {
70
+ return {
71
+ "$": ["chatleo-chat-input.css"]
72
+ };
73
+ }
74
+ static get properties() {
75
+ return {
76
+ "disabled": {
77
+ "type": "boolean",
78
+ "mutable": false,
79
+ "complexType": {
80
+ "original": "boolean",
81
+ "resolved": "boolean",
82
+ "references": {}
83
+ },
84
+ "required": false,
85
+ "optional": false,
86
+ "docs": {
87
+ "tags": [],
88
+ "text": "When `true`, the input field and all buttons are disabled, preventing user interaction."
89
+ },
90
+ "getter": false,
91
+ "setter": false,
92
+ "reflect": false,
93
+ "attribute": "disabled",
94
+ "defaultValue": "false"
95
+ },
96
+ "sendOnModifierEnter": {
97
+ "type": "boolean",
98
+ "mutable": false,
99
+ "complexType": {
100
+ "original": "boolean",
101
+ "resolved": "boolean",
102
+ "references": {}
103
+ },
104
+ "required": false,
105
+ "optional": false,
106
+ "docs": {
107
+ "tags": [],
108
+ "text": "If `true`, the message will be sent when the user presses `Cmd+Enter` (on Mac) or `Ctrl+Enter` (on other systems). If `false`, the message is sent on `Enter` alone."
109
+ },
110
+ "getter": false,
111
+ "setter": false,
112
+ "reflect": false,
113
+ "attribute": "send-on-modifier-enter",
114
+ "defaultValue": "false"
115
+ }
116
+ };
117
+ }
118
+ static get states() {
119
+ return {
120
+ "inputValue": {}
121
+ };
122
+ }
123
+ static get events() {
124
+ return [{
125
+ "method": "messageInputSent",
126
+ "name": "messageInputSent",
127
+ "bubbles": true,
128
+ "cancelable": true,
129
+ "composed": true,
130
+ "docs": {
131
+ "tags": [],
132
+ "text": ""
133
+ },
134
+ "complexType": {
135
+ "original": "string",
136
+ "resolved": "string",
137
+ "references": {}
138
+ }
139
+ }];
140
+ }
141
+ }
@@ -0,0 +1,149 @@
1
+ :host {
2
+ /* Component-specific variables */
3
+ --status-size: 9px;
4
+ --status-border: 1.5px;
5
+ }
6
+
7
+ .message-row {
8
+ display: flex;
9
+ gap: 16px;
10
+ padding-left: 16px;
11
+ }
12
+
13
+ .message-avatar-container {
14
+ position: relative;
15
+ width: var(--avatar-size);
16
+ height: var(--avatar-size);
17
+ flex-shrink: 0;
18
+ }
19
+
20
+ .message-avatar {
21
+ width: 100%;
22
+ height: 100%;
23
+ border-radius: 50%;
24
+ object-fit: cover;
25
+ background: var(--bg-light);
26
+ }
27
+
28
+ .message-status-indicator {
29
+ position: absolute;
30
+ bottom: 0;
31
+ right: 0;
32
+ width: var(--status-size);
33
+ height: var(--status-size);
34
+ border-radius: 50%;
35
+ border: var(--status-border) solid var(--bg-primary);
36
+ }
37
+
38
+ .message-status-indicator.online {
39
+ background: var(--status-online);
40
+ }
41
+
42
+ .message-status-indicator.offline {
43
+ background: var(--border-color);
44
+ }
45
+
46
+ .message-content {
47
+ flex: 1;
48
+ display: flex;
49
+ flex-direction: column;
50
+ gap: 4px;
51
+ }
52
+
53
+ .message-header {
54
+ display: flex;
55
+ align-items: center;
56
+ /*justify-content: end;*/
57
+ gap: 8px;
58
+ }
59
+
60
+ .message-author {
61
+ font-family: var(--font-primary);
62
+ font-weight: 700;
63
+ font-size: 14px;
64
+ line-height: 1.6;
65
+ color: var(--text-primary);
66
+ }
67
+
68
+ .message-timestamp {
69
+ font-family: var(--font-primary);
70
+ font-weight: 400;
71
+ font-size: 12px;
72
+ line-height: 1.65;
73
+ color: var(--text-secondary);
74
+ }
75
+
76
+ .message-timestamp::before {
77
+ content: '•';
78
+ margin-right: 8px;
79
+ }
80
+
81
+ .message-text {
82
+ font-family: var(--font-primary);
83
+ font-weight: 400;
84
+ font-size: 14px;
85
+ line-height: 1.6;
86
+ color: var(--text-primary);
87
+ word-wrap: break-word;
88
+ /*text-align: right;*/
89
+ }
90
+
91
+ .message-status {
92
+ display: flex;
93
+ align-items: center;
94
+ gap: 8px;
95
+ font-family: var(--font-primary);
96
+ font-size: 12px;
97
+ line-height: 1.5;
98
+ }
99
+
100
+ .message-status.pending {
101
+ color: var(--text-secondary);
102
+ font-style: italic;
103
+ }
104
+
105
+ .message-status.failed {
106
+ color: #c62828;
107
+ flex-wrap: wrap;
108
+ }
109
+
110
+ .message-status-actions {
111
+ display: inline-flex;
112
+ gap: 6px;
113
+ }
114
+
115
+ .status-action {
116
+ border: 1px solid currentColor;
117
+ background: transparent;
118
+ color: inherit;
119
+ border-radius: 4px;
120
+ padding: 1px 8px;
121
+ font: inherit;
122
+ cursor: pointer;
123
+ }
124
+
125
+ .status-action:hover {
126
+ background: rgba(198, 40, 40, 0.08);
127
+ }
128
+
129
+ .status-action.discard {
130
+ opacity: 0.8;
131
+ }
132
+
133
+ .call-message {
134
+ display: inline-flex;
135
+ align-items: center;
136
+ gap: 6px;
137
+ padding: 6px 10px;
138
+ border: 1px solid var(--border-light, #ddd);
139
+ border-radius: 8px;
140
+ font-family: var(--font-primary);
141
+ font-size: 13px;
142
+ color: var(--text-secondary, #667);
143
+ background: var(--bg-secondary, transparent);
144
+ }
145
+
146
+ .call-message::before {
147
+ content: '☎';
148
+ font-size: 15px;
149
+ }
@@ -0,0 +1,259 @@
1
+ import { h } from "@stencil/core";
2
+ import { callEntryText } from "../../utils/call-entry";
3
+ import { deliveryView } from "../../utils/delivery";
4
+ export class ChatleoChatMessageComponent {
5
+ message;
6
+ sender = undefined;
7
+ senderIsOnline = false;
8
+ isOwnMessage = false;
9
+ locale = 'en-US';
10
+ translations = {};
11
+ /** Emitted when the user asks to resend a failed message (detail: `client_id`). */
12
+ messageRetry;
13
+ /** Emitted when the user discards a failed/pending message (detail: `client_id`). */
14
+ messageDiscard;
15
+ isStructuredContent(content) {
16
+ try {
17
+ const parsed = JSON.parse(content);
18
+ if (parsed && parsed.blocks && Array.isArray(parsed.blocks) && parsed.version) {
19
+ return parsed;
20
+ }
21
+ }
22
+ catch (e) {
23
+ // Not JSON or invalid structure
24
+ }
25
+ return null;
26
+ }
27
+ formatTimestamp(isoDate) {
28
+ try {
29
+ return new Intl.DateTimeFormat(this.locale, {
30
+ hour: 'numeric',
31
+ minute: 'numeric',
32
+ }).format(new Date(isoDate));
33
+ }
34
+ catch (e) {
35
+ return isoDate;
36
+ }
37
+ }
38
+ defaultTranslations = {
39
+ you: 'You',
40
+ sending: 'Sending…',
41
+ failed: 'Not sent',
42
+ retry: 'Retry',
43
+ discard: 'Discard',
44
+ };
45
+ t(key) {
46
+ console.log(`Translating key: ${key}`, this.translations, this.defaultTranslations);
47
+ // Use the provided translation, fallback to default, finally fallback to the key itself.
48
+ return this.translations[key] || this.defaultTranslations[key] || key;
49
+ }
50
+ callEntry() {
51
+ return callEntryText(this.message.content_body);
52
+ }
53
+ renderMessageContent() {
54
+ const callEntry = this.callEntry();
55
+ if (callEntry)
56
+ return h("div", { class: "call-message" }, callEntry);
57
+ const structuredContent = this.isStructuredContent(this.message.content_body);
58
+ if (structuredContent) {
59
+ return (h(h.Fragment, null, h("chatleo-rich-message-renderer", { content: structuredContent, downloadUrls: this.message.attachment_details, alignment: this.isOwnMessage ? 'right' : 'left' })));
60
+ }
61
+ // Fallback to plain text
62
+ return (h("div", { class: "message-text", style: { textAlign: this.isOwnMessage ? 'right' : 'left' } }, this.message.content_body));
63
+ }
64
+ renderDeliveryStatus() {
65
+ const view = deliveryView(this.message, this.isOwnMessage);
66
+ if (view.status === 'none')
67
+ return null;
68
+ const clientId = this.message.client_id;
69
+ if (view.status === 'pending') {
70
+ return (h("div", { class: "message-status pending", "aria-live": "polite" }, this.t('sending')));
71
+ }
72
+ return (h("div", { class: "message-status failed" }, h("span", { class: "message-status-text" }, this.t('failed'), view.error ? `: ${view.error}` : ''), view.canRetry && clientId && (h("span", { class: "message-status-actions" }, h("button", { type: "button", class: "status-action", onClick: () => this.messageRetry.emit(clientId) }, this.t('retry')), h("button", { type: "button", class: "status-action discard", onClick: () => this.messageDiscard.emit(clientId) }, this.t('discard'))))));
73
+ }
74
+ render() {
75
+ const authorName = this.isOwnMessage ? this.t('you') : (this.sender?.display_name ?? '');
76
+ return (h("div", { key: 'c91f01cbf694c79d4e68b8445a99ffbc5b0b9790', class: "message-row" }, !this.isOwnMessage && h("chatleo-avatar", { key: '6f05c378fd18203d9917f1edbc61b20bf94b81b9', name: authorName, url: this.sender?.profile_picture_url ?? null, isOnline: this.senderIsOnline }), h("div", { key: 'b1f4df458b587cace3423637b5bad8350a5c3a14', class: "message-content" }, h("div", { key: 'f7c565319462013dac380d21a813e21861544833', class: "message-header", style: { justifyContent: this.isOwnMessage ? 'end' : 'start' } }, h("span", { key: '4d30b5eb0c55abb854b6192f0fe9c78bb54aff33', class: "message-author" }, authorName), h("span", { key: '13867dc122764cbdbdd7fa60f5ff7e6916ed49e7', class: "message-timestamp" }, this.formatTimestamp(this.message.created_at))), this.renderMessageContent(), this.renderDeliveryStatus()), this.isOwnMessage && h("chatleo-avatar", { key: 'c818e945cb494c07356fae74c00719e32a2c6b23', name: authorName, url: this.sender?.profile_picture_url ?? null, isOnline: this.senderIsOnline })));
77
+ }
78
+ static get is() { return "chatleo-chat-message"; }
79
+ static get encapsulation() { return "shadow"; }
80
+ static get originalStyleUrls() {
81
+ return {
82
+ "$": ["chatleo-chat-message.css"]
83
+ };
84
+ }
85
+ static get styleUrls() {
86
+ return {
87
+ "$": ["chatleo-chat-message.css"]
88
+ };
89
+ }
90
+ static get properties() {
91
+ return {
92
+ "message": {
93
+ "type": "unknown",
94
+ "mutable": false,
95
+ "complexType": {
96
+ "original": "ChatLeoMessage",
97
+ "resolved": "ChatLeoMessage",
98
+ "references": {
99
+ "ChatLeoMessage": {
100
+ "location": "import",
101
+ "path": "@chat-leo/chatleolib",
102
+ "id": "../chatleolib/dist/index.d.ts::ChatLeoMessage",
103
+ "referenceLocation": "ChatLeoMessage"
104
+ }
105
+ }
106
+ },
107
+ "required": false,
108
+ "optional": false,
109
+ "docs": {
110
+ "tags": [],
111
+ "text": ""
112
+ },
113
+ "getter": false,
114
+ "setter": false
115
+ },
116
+ "sender": {
117
+ "type": "unknown",
118
+ "mutable": false,
119
+ "complexType": {
120
+ "original": "UserProfile | undefined",
121
+ "resolved": "{ id: string; display_name: string; profile_picture_url: string; }",
122
+ "references": {
123
+ "UserProfile": {
124
+ "location": "import",
125
+ "path": "@chat-leo/chatleolib",
126
+ "id": "../chatleolib/dist/index.d.ts::UserProfile",
127
+ "referenceLocation": "UserProfile"
128
+ }
129
+ }
130
+ },
131
+ "required": false,
132
+ "optional": false,
133
+ "docs": {
134
+ "tags": [],
135
+ "text": ""
136
+ },
137
+ "getter": false,
138
+ "setter": false,
139
+ "defaultValue": "undefined"
140
+ },
141
+ "senderIsOnline": {
142
+ "type": "boolean",
143
+ "mutable": false,
144
+ "complexType": {
145
+ "original": "boolean",
146
+ "resolved": "boolean",
147
+ "references": {}
148
+ },
149
+ "required": false,
150
+ "optional": false,
151
+ "docs": {
152
+ "tags": [],
153
+ "text": ""
154
+ },
155
+ "getter": false,
156
+ "setter": false,
157
+ "reflect": false,
158
+ "attribute": "sender-is-online",
159
+ "defaultValue": "false"
160
+ },
161
+ "isOwnMessage": {
162
+ "type": "boolean",
163
+ "mutable": false,
164
+ "complexType": {
165
+ "original": "boolean",
166
+ "resolved": "boolean",
167
+ "references": {}
168
+ },
169
+ "required": false,
170
+ "optional": false,
171
+ "docs": {
172
+ "tags": [],
173
+ "text": ""
174
+ },
175
+ "getter": false,
176
+ "setter": false,
177
+ "reflect": false,
178
+ "attribute": "is-own-message",
179
+ "defaultValue": "false"
180
+ },
181
+ "locale": {
182
+ "type": "string",
183
+ "mutable": false,
184
+ "complexType": {
185
+ "original": "string",
186
+ "resolved": "string",
187
+ "references": {}
188
+ },
189
+ "required": false,
190
+ "optional": false,
191
+ "docs": {
192
+ "tags": [],
193
+ "text": ""
194
+ },
195
+ "getter": false,
196
+ "setter": false,
197
+ "reflect": false,
198
+ "attribute": "locale",
199
+ "defaultValue": "'en-US'"
200
+ },
201
+ "translations": {
202
+ "type": "unknown",
203
+ "mutable": false,
204
+ "complexType": {
205
+ "original": "Record<string, string>",
206
+ "resolved": "string",
207
+ "references": {
208
+ "Record": {
209
+ "location": "global",
210
+ "id": "global::Record"
211
+ }
212
+ }
213
+ },
214
+ "required": false,
215
+ "optional": false,
216
+ "docs": {
217
+ "tags": [],
218
+ "text": ""
219
+ },
220
+ "getter": false,
221
+ "setter": false,
222
+ "defaultValue": "{}"
223
+ }
224
+ };
225
+ }
226
+ static get events() {
227
+ return [{
228
+ "method": "messageRetry",
229
+ "name": "messageRetry",
230
+ "bubbles": true,
231
+ "cancelable": true,
232
+ "composed": true,
233
+ "docs": {
234
+ "tags": [],
235
+ "text": "Emitted when the user asks to resend a failed message (detail: `client_id`)."
236
+ },
237
+ "complexType": {
238
+ "original": "string",
239
+ "resolved": "string",
240
+ "references": {}
241
+ }
242
+ }, {
243
+ "method": "messageDiscard",
244
+ "name": "messageDiscard",
245
+ "bubbles": true,
246
+ "cancelable": true,
247
+ "composed": true,
248
+ "docs": {
249
+ "tags": [],
250
+ "text": "Emitted when the user discards a failed/pending message (detail: `client_id`)."
251
+ },
252
+ "complexType": {
253
+ "original": "string",
254
+ "resolved": "string",
255
+ "references": {}
256
+ }
257
+ }];
258
+ }
259
+ }