@nyaruka/temba-components 0.129.7 → 0.129.9

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 (269) hide show
  1. package/.devcontainer/Dockerfile +11 -4
  2. package/.devcontainer/devcontainer.json +3 -2
  3. package/.github/workflows/build.yml +4 -14
  4. package/CHANGELOG.md +29 -0
  5. package/demo/components/flow/example.html +1 -1
  6. package/demo/components/message-editor/example.html +125 -0
  7. package/demo/components/textinput/completion.html +1 -0
  8. package/demo/data/flows/food-order.json +12 -21
  9. package/demo/data/flows/sample-flow.json +210 -104
  10. package/dist/temba-components.js +715 -364
  11. package/dist/temba-components.js.map +1 -1
  12. package/out-tsc/src/display/Thumbnail.js +2 -1
  13. package/out-tsc/src/display/Thumbnail.js.map +1 -1
  14. package/out-tsc/src/events.js.map +1 -1
  15. package/out-tsc/src/excellent/helpers.js +2 -2
  16. package/out-tsc/src/excellent/helpers.js.map +1 -1
  17. package/out-tsc/src/flow/CanvasNode.js +25 -7
  18. package/out-tsc/src/flow/CanvasNode.js.map +1 -1
  19. package/out-tsc/src/flow/Editor.js +11 -1
  20. package/out-tsc/src/flow/Editor.js.map +1 -1
  21. package/out-tsc/src/flow/NodeEditor.js +342 -276
  22. package/out-tsc/src/flow/NodeEditor.js.map +1 -1
  23. package/out-tsc/src/flow/actions/add_input_labels.js +40 -0
  24. package/out-tsc/src/flow/actions/add_input_labels.js.map +1 -1
  25. package/out-tsc/src/flow/actions/call_llm.js +56 -3
  26. package/out-tsc/src/flow/actions/call_llm.js.map +1 -1
  27. package/out-tsc/src/flow/actions/call_webhook.js +26 -17
  28. package/out-tsc/src/flow/actions/call_webhook.js.map +1 -1
  29. package/out-tsc/src/flow/actions/open_ticket.js +65 -3
  30. package/out-tsc/src/flow/actions/open_ticket.js.map +1 -1
  31. package/out-tsc/src/flow/actions/send_msg.js +147 -6
  32. package/out-tsc/src/flow/actions/send_msg.js.map +1 -1
  33. package/out-tsc/src/flow/actions/set_run_result.js +75 -0
  34. package/out-tsc/src/flow/actions/set_run_result.js.map +1 -1
  35. package/out-tsc/src/flow/config.js +4 -0
  36. package/out-tsc/src/flow/config.js.map +1 -1
  37. package/out-tsc/src/flow/nodes/split_by_llm_categorize.js +227 -0
  38. package/out-tsc/src/flow/nodes/split_by_llm_categorize.js.map +1 -0
  39. package/out-tsc/src/flow/nodes/split_by_ticket.js +18 -0
  40. package/out-tsc/src/flow/nodes/split_by_ticket.js.map +1 -0
  41. package/out-tsc/src/flow/nodes/wait_for_response.js +27 -1
  42. package/out-tsc/src/flow/nodes/wait_for_response.js.map +1 -1
  43. package/out-tsc/src/flow/types.js +0 -65
  44. package/out-tsc/src/flow/types.js.map +1 -1
  45. package/out-tsc/src/form/ArrayEditor.js +87 -57
  46. package/out-tsc/src/form/ArrayEditor.js.map +1 -1
  47. package/out-tsc/src/form/BaseListEditor.js +19 -4
  48. package/out-tsc/src/form/BaseListEditor.js.map +1 -1
  49. package/out-tsc/src/form/FieldRenderer.js +305 -0
  50. package/out-tsc/src/form/FieldRenderer.js.map +1 -0
  51. package/out-tsc/src/form/FormField.js +4 -4
  52. package/out-tsc/src/form/FormField.js.map +1 -1
  53. package/out-tsc/src/form/KeyValueEditor.js +1 -1
  54. package/out-tsc/src/form/KeyValueEditor.js.map +1 -1
  55. package/out-tsc/src/form/MediaPicker.js +13 -1
  56. package/out-tsc/src/form/MediaPicker.js.map +1 -1
  57. package/out-tsc/src/form/MessageEditor.js +422 -0
  58. package/out-tsc/src/form/MessageEditor.js.map +1 -0
  59. package/out-tsc/src/form/TextInput.js +13 -6
  60. package/out-tsc/src/form/TextInput.js.map +1 -1
  61. package/out-tsc/src/form/select/Select.js +52 -24
  62. package/out-tsc/src/form/select/Select.js.map +1 -1
  63. package/out-tsc/src/live/ContactChat.js +66 -15
  64. package/out-tsc/src/live/ContactChat.js.map +1 -1
  65. package/out-tsc/src/markdown.js +13 -11
  66. package/out-tsc/src/markdown.js.map +1 -1
  67. package/out-tsc/temba-modules.js +2 -0
  68. package/out-tsc/temba-modules.js.map +1 -1
  69. package/out-tsc/test/ActionHelper.js +2 -0
  70. package/out-tsc/test/ActionHelper.js.map +1 -1
  71. package/out-tsc/test/NodeHelper.js +148 -0
  72. package/out-tsc/test/NodeHelper.js.map +1 -0
  73. package/out-tsc/test/actions/call_llm.test.js +103 -0
  74. package/out-tsc/test/actions/call_llm.test.js.map +1 -0
  75. package/out-tsc/test/nodes/split_by_llm_categorize.test.js +532 -0
  76. package/out-tsc/test/nodes/split_by_llm_categorize.test.js.map +1 -0
  77. package/out-tsc/test/nodes/split_by_random.test.js +150 -0
  78. package/out-tsc/test/nodes/split_by_random.test.js.map +1 -0
  79. package/out-tsc/test/nodes/wait_for_digits.test.js +150 -0
  80. package/out-tsc/test/nodes/wait_for_digits.test.js.map +1 -0
  81. package/out-tsc/test/nodes/wait_for_response.test.js +171 -0
  82. package/out-tsc/test/nodes/wait_for_response.test.js.map +1 -0
  83. package/out-tsc/test/temba-add-input-labels.test.js +70 -0
  84. package/out-tsc/test/temba-add-input-labels.test.js.map +1 -0
  85. package/out-tsc/test/temba-field-config.test.js +4 -2
  86. package/out-tsc/test/temba-field-config.test.js.map +1 -1
  87. package/out-tsc/test/temba-field-renderer.test.js +296 -0
  88. package/out-tsc/test/temba-field-renderer.test.js.map +1 -0
  89. package/out-tsc/test/temba-markdown.test.js +1 -1
  90. package/out-tsc/test/temba-markdown.test.js.map +1 -1
  91. package/out-tsc/test/temba-message-editor.test.js +194 -0
  92. package/out-tsc/test/temba-message-editor.test.js.map +1 -0
  93. package/out-tsc/test/temba-node-editor.test.js +471 -0
  94. package/out-tsc/test/temba-node-editor.test.js.map +1 -1
  95. package/out-tsc/test/temba-select.test.js +7 -4
  96. package/out-tsc/test/temba-select.test.js.map +1 -1
  97. package/out-tsc/test/temba-textinput.test.js +16 -0
  98. package/out-tsc/test/temba-textinput.test.js.map +1 -1
  99. package/out-tsc/test/temba-webchat.test.js +5 -1
  100. package/out-tsc/test/temba-webchat.test.js.map +1 -1
  101. package/out-tsc/test/utils.test.js +2 -8
  102. package/out-tsc/test/utils.test.js.map +1 -1
  103. package/package.json +7 -4
  104. package/screenshots/truth/actions/add_contact_groups/editor/descriptive-group-names.png +0 -0
  105. package/screenshots/truth/actions/add_contact_groups/editor/long-group-names.png +0 -0
  106. package/screenshots/truth/actions/add_contact_groups/editor/many-groups.png +0 -0
  107. package/screenshots/truth/actions/add_contact_groups/editor/multiple-groups.png +0 -0
  108. package/screenshots/truth/actions/add_contact_groups/editor/single-group.png +0 -0
  109. package/screenshots/truth/actions/call_llm/editor/information-extraction.png +0 -0
  110. package/screenshots/truth/actions/call_llm/editor/sentiment-analysis.png +0 -0
  111. package/screenshots/truth/actions/call_llm/editor/summarization.png +0 -0
  112. package/screenshots/truth/actions/call_llm/editor/translation-task.png +0 -0
  113. package/screenshots/truth/actions/call_llm/render/information-extraction.png +0 -0
  114. package/screenshots/truth/actions/call_llm/render/sentiment-analysis.png +0 -0
  115. package/screenshots/truth/actions/call_llm/render/summarization.png +0 -0
  116. package/screenshots/truth/actions/call_llm/render/translation-task.png +0 -0
  117. package/screenshots/truth/actions/remove_contact_groups/editor/cleanup-groups.png +0 -0
  118. package/screenshots/truth/actions/remove_contact_groups/editor/long-descriptive-group-names.png +0 -0
  119. package/screenshots/truth/actions/remove_contact_groups/editor/many-groups.png +0 -0
  120. package/screenshots/truth/actions/remove_contact_groups/editor/multiple-groups.png +0 -0
  121. package/screenshots/truth/actions/remove_contact_groups/editor/remove-from-all-groups.png +0 -0
  122. package/screenshots/truth/actions/remove_contact_groups/editor/single-group.png +0 -0
  123. package/screenshots/truth/actions/send_email/editor/complex-business-email.png +0 -0
  124. package/screenshots/truth/actions/send_email/editor/empty-body.png +0 -0
  125. package/screenshots/truth/actions/send_email/editor/empty-subject.png +0 -0
  126. package/screenshots/truth/actions/send_email/editor/long-subject.png +0 -0
  127. package/screenshots/truth/actions/send_email/editor/multiline-body.png +0 -0
  128. package/screenshots/truth/actions/send_email/editor/multiple-recipients.png +0 -0
  129. package/screenshots/truth/actions/send_email/editor/simple-email.png +0 -0
  130. package/screenshots/truth/actions/send_email/editor/with-expressions.png +0 -0
  131. package/screenshots/truth/actions/send_msg/editor/long-quick-replies.png +0 -0
  132. package/screenshots/truth/actions/send_msg/editor/multiline-text-with-replies.png +0 -0
  133. package/screenshots/truth/actions/send_msg/editor/simple-text.png +0 -0
  134. package/screenshots/truth/actions/send_msg/editor/text-with-linebreaks.png +0 -0
  135. package/screenshots/truth/actions/send_msg/editor/text-with-many-quick-replies.png +0 -0
  136. package/screenshots/truth/actions/send_msg/editor/text-with-quick-replies.png +0 -0
  137. package/screenshots/truth/actions/send_msg/editor/text-without-quick-replies.png +0 -0
  138. package/screenshots/truth/editor/router.png +0 -0
  139. package/screenshots/truth/editor/send_msg.png +0 -0
  140. package/screenshots/truth/editor/set_contact_language.png +0 -0
  141. package/screenshots/truth/editor/set_contact_name.png +0 -0
  142. package/screenshots/truth/editor/set_run_result.png +0 -0
  143. package/screenshots/truth/editor/wait.png +0 -0
  144. package/screenshots/truth/field-renderer/checkbox-checked.png +0 -0
  145. package/screenshots/truth/field-renderer/checkbox-unchecked.png +0 -0
  146. package/screenshots/truth/field-renderer/checkbox-with-errors.png +0 -0
  147. package/screenshots/truth/field-renderer/context-comparison.png +0 -0
  148. package/screenshots/truth/field-renderer/key-value-with-label.png +0 -0
  149. package/screenshots/truth/field-renderer/message-editor-with-label.png +0 -0
  150. package/screenshots/truth/field-renderer/select-multi.png +0 -0
  151. package/screenshots/truth/field-renderer/select-no-label.png +0 -0
  152. package/screenshots/truth/field-renderer/select-with-label.png +0 -0
  153. package/screenshots/truth/field-renderer/text-evaluated.png +0 -0
  154. package/screenshots/truth/field-renderer/text-no-label.png +0 -0
  155. package/screenshots/truth/field-renderer/text-with-errors.png +0 -0
  156. package/screenshots/truth/field-renderer/text-with-label.png +0 -0
  157. package/screenshots/truth/field-renderer/textarea-evaluated.png +0 -0
  158. package/screenshots/truth/field-renderer/textarea-with-label.png +0 -0
  159. package/screenshots/truth/formfield/markdown-errors.png +0 -0
  160. package/screenshots/truth/formfield/no-errors.png +0 -0
  161. package/screenshots/truth/formfield/plain-text-errors.png +0 -0
  162. package/screenshots/truth/message-editor/autogrow-initial-content.png +0 -0
  163. package/screenshots/truth/message-editor/default.png +0 -0
  164. package/screenshots/truth/message-editor/drag-highlight.png +0 -0
  165. package/screenshots/truth/message-editor/filtered-attachments.png +0 -0
  166. package/screenshots/truth/message-editor/with-completion.png +0 -0
  167. package/screenshots/truth/message-editor/with-properties.png +0 -0
  168. package/screenshots/truth/nodes/split_by_llm_categorize/editor/basic-categorization.png +0 -0
  169. package/screenshots/truth/nodes/split_by_llm_categorize/editor/custom-input-and-result-name.png +0 -0
  170. package/screenshots/truth/nodes/split_by_llm_categorize/editor/feedback-categorization.png +0 -0
  171. package/screenshots/truth/nodes/split_by_llm_categorize/editor/many-categories.png +0 -0
  172. package/screenshots/truth/nodes/split_by_llm_categorize/editor/minimal-categories.png +0 -0
  173. package/screenshots/truth/nodes/split_by_llm_categorize/render/basic-categorization.png +0 -0
  174. package/screenshots/truth/nodes/split_by_llm_categorize/render/custom-input-and-result-name.png +0 -0
  175. package/screenshots/truth/nodes/split_by_llm_categorize/render/feedback-categorization.png +0 -0
  176. package/screenshots/truth/nodes/split_by_llm_categorize/render/many-categories.png +0 -0
  177. package/screenshots/truth/nodes/split_by_llm_categorize/render/minimal-categories.png +0 -0
  178. package/screenshots/truth/nodes/split_by_random/editor/ab-test-multiple-variants.png +0 -0
  179. package/screenshots/truth/nodes/split_by_random/editor/sampling-split.png +0 -0
  180. package/screenshots/truth/nodes/split_by_random/editor/three-way-split.png +0 -0
  181. package/screenshots/truth/nodes/split_by_random/editor/two-bucket-split.png +0 -0
  182. package/screenshots/truth/nodes/split_by_random/render/ab-test-multiple-variants.png +0 -0
  183. package/screenshots/truth/nodes/split_by_random/render/sampling-split.png +0 -0
  184. package/screenshots/truth/nodes/split_by_random/render/three-way-split.png +0 -0
  185. package/screenshots/truth/nodes/split_by_random/render/two-bucket-split.png +0 -0
  186. package/screenshots/truth/nodes/wait_for_digits/editor/basic-digits-wait.png +0 -0
  187. package/screenshots/truth/nodes/wait_for_digits/editor/phone-number-collection.png +0 -0
  188. package/screenshots/truth/nodes/wait_for_digits/editor/single-digit-with-timeout.png +0 -0
  189. package/screenshots/truth/nodes/wait_for_digits/editor/verification-code.png +0 -0
  190. package/screenshots/truth/nodes/wait_for_digits/render/basic-digits-wait.png +0 -0
  191. package/screenshots/truth/nodes/wait_for_digits/render/phone-number-collection.png +0 -0
  192. package/screenshots/truth/nodes/wait_for_digits/render/single-digit-with-timeout.png +0 -0
  193. package/screenshots/truth/nodes/wait_for_digits/render/verification-code.png +0 -0
  194. package/screenshots/truth/nodes/wait_for_response/editor/basic-wait.png +0 -0
  195. package/screenshots/truth/nodes/wait_for_response/editor/custom-result-name.png +0 -0
  196. package/screenshots/truth/nodes/wait_for_response/editor/no-timeout.png +0 -0
  197. package/screenshots/truth/nodes/wait_for_response/editor/short-timeout.png +0 -0
  198. package/screenshots/truth/nodes/wait_for_response/render/basic-wait.png +0 -0
  199. package/screenshots/truth/nodes/wait_for_response/render/custom-result-name.png +0 -0
  200. package/screenshots/truth/nodes/wait_for_response/render/no-timeout.png +0 -0
  201. package/screenshots/truth/nodes/wait_for_response/render/short-timeout.png +0 -0
  202. package/screenshots/truth/omnibox/selected.png +0 -0
  203. package/screenshots/truth/select/functions.png +0 -0
  204. package/screenshots/truth/select/multi-with-endpoint.png +0 -0
  205. package/screenshots/truth/select/search-enabled.png +0 -0
  206. package/screenshots/truth/textinput/autogrow-initial.png +0 -0
  207. package/screenshots/truth/textinput/input-form.png +0 -0
  208. package/src/display/Thumbnail.ts +2 -1
  209. package/src/events.ts +13 -1
  210. package/src/excellent/helpers.ts +2 -2
  211. package/src/flow/CanvasNode.ts +22 -1
  212. package/src/flow/Editor.ts +12 -1
  213. package/src/flow/NodeEditor.ts +412 -354
  214. package/src/flow/actions/add_input_labels.ts +45 -0
  215. package/src/flow/actions/call_llm.ts +57 -3
  216. package/src/flow/actions/call_webhook.ts +28 -18
  217. package/src/flow/actions/open_ticket.ts +74 -3
  218. package/src/flow/actions/send_msg.ts +170 -6
  219. package/src/flow/actions/set_run_result.ts +83 -0
  220. package/src/flow/config.ts +4 -0
  221. package/src/flow/nodes/split_by_llm_categorize.ts +277 -0
  222. package/src/flow/nodes/split_by_ticket.ts +19 -0
  223. package/src/flow/nodes/wait_for_response.ts +28 -1
  224. package/src/flow/types.ts +46 -128
  225. package/src/form/ArrayEditor.ts +96 -66
  226. package/src/form/BaseListEditor.ts +22 -6
  227. package/src/form/FieldRenderer.ts +465 -0
  228. package/src/form/FormField.ts +4 -4
  229. package/src/form/KeyValueEditor.ts +1 -1
  230. package/src/form/MediaPicker.ts +13 -1
  231. package/src/form/MessageEditor.ts +449 -0
  232. package/src/form/TextInput.ts +16 -8
  233. package/src/form/select/Select.ts +55 -24
  234. package/src/live/ContactChat.ts +69 -19
  235. package/src/markdown.ts +19 -11
  236. package/src/store/flow-definition.d.ts +5 -2
  237. package/static/api/labels.json +31 -0
  238. package/static/api/topics.json +24 -9
  239. package/static/api/users.json +35 -16
  240. package/static/css/temba-components.css +5 -3
  241. package/static/mr/docs/en-us/editor.json +2588 -0
  242. package/stress-test.js +143 -0
  243. package/temba-modules.ts +2 -0
  244. package/test/ActionHelper.ts +2 -0
  245. package/test/NodeHelper.ts +184 -0
  246. package/test/actions/call_llm.test.ts +137 -0
  247. package/test/nodes/README.md +78 -0
  248. package/test/nodes/split_by_llm_categorize.test.ts +698 -0
  249. package/test/nodes/split_by_random.test.ts +177 -0
  250. package/test/nodes/wait_for_digits.test.ts +176 -0
  251. package/test/nodes/wait_for_response.test.ts +206 -0
  252. package/test/temba-add-input-labels.test.ts +87 -0
  253. package/test/temba-field-config.test.ts +4 -2
  254. package/test/temba-field-renderer.test.ts +482 -0
  255. package/test/temba-markdown.test.ts +1 -1
  256. package/test/temba-message-editor.test.ts +300 -0
  257. package/test/temba-node-editor.test.ts +590 -0
  258. package/test/temba-select.test.ts +7 -7
  259. package/test/temba-textinput.test.ts +26 -0
  260. package/test/temba-webchat.test.ts +6 -1
  261. package/test/utils.test.ts +2 -13
  262. package/test-assets/contacts/history.json +19 -0
  263. package/test-assets/select/llms.json +18 -0
  264. package/test-assets/style.css +2 -0
  265. package/web-dev-mock.mjs +523 -0
  266. package/web-dev-server.config.mjs +74 -6
  267. package/web-test-runner.config.mjs +9 -4
  268. package/test/temba-flow-editor.test.ts.backup +0 -563
  269. package/test/temba-utils-index.test.ts.backup +0 -1737
@@ -0,0 +1,449 @@
1
+ import { TemplateResult, css, html } from 'lit';
2
+ import { property } from 'lit/decorators.js';
3
+ import { ifDefined } from 'lit-html/directives/if-defined.js';
4
+ import { FormElement } from './FormElement';
5
+ import { Completion } from './Completion';
6
+ import { MediaPicker } from './MediaPicker';
7
+ import { Attachment } from '../interfaces';
8
+ import { getClasses } from '../utils';
9
+ import { Icon } from '../Icons';
10
+
11
+ /**
12
+ * MessageEditor is a composed component that combines temba-completion and temba-media-picker
13
+ * for editing messages with text completion and file attachments
14
+ */
15
+ export class MessageEditor extends FormElement {
16
+ static get styles() {
17
+ return css`
18
+ :host {
19
+ display: block;
20
+ }
21
+
22
+ .message-editor-container {
23
+ border: 1px solid var(--color-widget-border);
24
+ border-radius: var(--curvature-widget);
25
+ background: #fff;
26
+ position: relative;
27
+ transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
28
+ }
29
+
30
+ .message-editor-container:focus-within {
31
+ border-color: var(--color-focus);
32
+ box-shadow: var(--widget-box-shadow-focused);
33
+ }
34
+
35
+ .message-editor-container.highlight {
36
+ border-color: rgba(156, 222, 106, 0.88);
37
+ }
38
+
39
+ /* Hide the completion field border since we draw our own */
40
+ .message-editor-container temba-completion::part(field) {
41
+ border: none;
42
+ box-shadow: none;
43
+ border-radius: 0;
44
+ }
45
+
46
+ .message-editor-container temba-completion {
47
+ --widget-box-shadow: none;
48
+ --widget-box-shadow-focused: none;
49
+ --widget-box-shadow-focused: none;
50
+ --color-widget-border: transparent;
51
+ --color-focus: transparent;
52
+ }
53
+
54
+ .completion-wrapper {
55
+ }
56
+
57
+ .media-wrapper {
58
+ padding: 4px 8px;
59
+ background: rgba(0, 0, 0, 0.03);
60
+ border-top: 1px solid var(--color-widget-border);
61
+ border-radius: 0 0 var(--curvature-widget) var(--curvature-widget);
62
+ box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.05);
63
+ margin-top: 3px;
64
+ display: none;
65
+ }
66
+ .has-attachments .media-wrapper {
67
+ display: flex;
68
+ }
69
+
70
+ /* Override media picker styles to integrate better */
71
+ .media-wrapper temba-media-picker {
72
+ --color-widget-border: transparent;
73
+ }
74
+
75
+ .media-wrapper .attachments-list {
76
+ padding: 0.2em 0;
77
+ }
78
+
79
+ .drop-overlay {
80
+ position: absolute;
81
+ top: 0;
82
+ left: 0;
83
+ right: 0;
84
+ bottom: 0;
85
+ background: rgba(210, 243, 184, 0.5);
86
+ border-radius: var(--curvature-widget);
87
+ display: flex;
88
+ align-items: center;
89
+ justify-content: center;
90
+ opacity: 0;
91
+ pointer-events: none;
92
+ transition: opacity 0.2s ease-in-out;
93
+ z-index: 10;
94
+ }
95
+
96
+ .message-editor-container.highlight .drop-overlay {
97
+ opacity: 1;
98
+ }
99
+
100
+ .drop-message {
101
+ background: rgba(0, 0, 0, 0.8);
102
+ color: white;
103
+ padding: 12px 24px;
104
+ border-radius: var(--curvature);
105
+ font-weight: 500;
106
+ }
107
+
108
+ .attachment-icon {
109
+ position: absolute;
110
+ bottom: 4px;
111
+ right: 4px;
112
+ color: var(--color-text-dark);
113
+ cursor: pointer;
114
+ padding: 6px;
115
+ border-radius: var(--curvature);
116
+ transition: background-color 0.2s ease-in-out;
117
+ display: block;
118
+ }
119
+
120
+ .has-attachments .attachment-icon {
121
+ display: none;
122
+ }
123
+
124
+ .attachment-icon:hover {
125
+ background-color: rgba(0, 0, 0, 0.05);
126
+ }
127
+ `;
128
+ }
129
+
130
+ @property({ type: String })
131
+ name = '';
132
+
133
+ @property({ type: String })
134
+ value = '';
135
+
136
+ @property({ type: String })
137
+ placeholder = '';
138
+
139
+ @property({ type: Boolean })
140
+ textarea = true;
141
+
142
+ @property({ type: Boolean })
143
+ autogrow = true;
144
+
145
+ @property({ type: Number })
146
+ minHeight = 60;
147
+
148
+ @property({ type: Number })
149
+ maxLength: number;
150
+
151
+ @property({ type: Boolean })
152
+ session: boolean;
153
+
154
+ @property({ type: Boolean })
155
+ submitOnEnter = false;
156
+
157
+ @property({ type: Boolean })
158
+ gsm: boolean;
159
+
160
+ @property({ type: Boolean })
161
+ disableCompletion: boolean;
162
+
163
+ @property({ type: String })
164
+ counter: string;
165
+
166
+ @property({ type: Array })
167
+ attachments: (Attachment | string)[] = [];
168
+
169
+ @property({ type: String })
170
+ accept = '';
171
+
172
+ @property({ type: Number, attribute: 'max-attachments' })
173
+ maxAttachments = 3;
174
+
175
+ @property({ type: String })
176
+ endpoint = '';
177
+
178
+ @property({ type: Boolean, attribute: false })
179
+ pendingDrop = false;
180
+
181
+ @property({ type: Boolean, attribute: false })
182
+ uploading = false;
183
+
184
+ private completionElement: Completion;
185
+ private mediaPickerElement: MediaPicker;
186
+
187
+ public firstUpdated(changes: Map<string, any>) {
188
+ super.firstUpdated(changes);
189
+
190
+ this.completionElement = this.shadowRoot.querySelector(
191
+ 'temba-completion'
192
+ ) as Completion;
193
+
194
+ // Get the visible media picker (either in media-wrapper or the hidden one)
195
+ this.mediaPickerElement = this.shadowRoot.querySelector(
196
+ 'temba-media-picker'
197
+ ) as MediaPicker;
198
+
199
+ // Set up proper attachment filtering and parsing
200
+ this.parseAndFilterAttachments();
201
+ }
202
+
203
+ /**
204
+ * Parse attachments and filter out runtime attachments for media picker
205
+ */
206
+ private parseAndFilterAttachments() {
207
+ if (!this.attachments) return;
208
+
209
+ // Filter out runtime attachments (those without '/' in content type)
210
+ const staticAttachments = this.attachments.filter((attachment) => {
211
+ if (typeof attachment === 'string') {
212
+ const [contentType] = attachment.split(':');
213
+ return contentType.includes('/');
214
+ }
215
+ return true;
216
+ });
217
+
218
+ // Convert string attachments to Attachment objects for media picker
219
+ const mediaAttachments = staticAttachments.map((attachment) => {
220
+ if (typeof attachment === 'string') {
221
+ // split into content type and URL
222
+ // e.g. "image/jpeg:http://example.com/image.jpg"
223
+ const colonIndex = attachment.indexOf(':');
224
+ const contentType = attachment.substring(0, colonIndex);
225
+ const url = attachment.substring(colonIndex + 1);
226
+ return {
227
+ content_type: contentType,
228
+ url: url,
229
+ filename: this.getFilenameFromUrl(url),
230
+ size: 0
231
+ } as Attachment;
232
+ }
233
+ return attachment;
234
+ });
235
+
236
+ if (this.mediaPickerElement) {
237
+ this.mediaPickerElement.attachments = mediaAttachments;
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Check if there are any static attachments (excluding runtime attachments)
243
+ */
244
+ private hasStaticAttachments(): boolean {
245
+ if (!this.attachments || this.attachments.length === 0) return false;
246
+
247
+ return this.attachments.some((attachment) => {
248
+ if (typeof attachment === 'string') {
249
+ const [contentType] = attachment.split(':');
250
+ return contentType.includes('/');
251
+ }
252
+ return true;
253
+ });
254
+ }
255
+
256
+ private getFilenameFromUrl(url: string): string {
257
+ try {
258
+ const urlObj = new URL(url);
259
+ const pathname = urlObj.pathname;
260
+ return pathname.substring(pathname.lastIndexOf('/') + 1) || 'attachment';
261
+ } catch {
262
+ return 'attachment';
263
+ }
264
+ }
265
+
266
+ private handleCompletionChange(event: Event) {
267
+ event.stopPropagation();
268
+ const completion = event.target as Completion;
269
+ this.value = completion.value;
270
+ this.fireEvent('change');
271
+ }
272
+
273
+ private handleMediaChange(event: Event) {
274
+ event.stopPropagation();
275
+ const mediaPicker = event.target as MediaPicker;
276
+ // Convert media picker attachments back to the format expected by the form
277
+ const formattedAttachments = mediaPicker.attachments.map((attachment) => {
278
+ return `${attachment.content_type}:${attachment.url}`;
279
+ });
280
+
281
+ // Merge with any runtime attachments that were filtered out
282
+ const runtimeAttachments = (this.attachments || []).filter((attachment) => {
283
+ if (typeof attachment === 'string') {
284
+ const [contentType] = attachment.split(':');
285
+ return !contentType.includes('/');
286
+ }
287
+ return false;
288
+ }) as string[];
289
+
290
+ this.attachments = [...runtimeAttachments, ...formattedAttachments];
291
+ this.fireEvent('change');
292
+ }
293
+
294
+ private handleDragEnter(evt: DragEvent): void {
295
+ this.highlight(evt);
296
+ }
297
+
298
+ private handleDragOver(evt: DragEvent): void {
299
+ this.highlight(evt);
300
+ }
301
+
302
+ private handleDragLeave(evt: DragEvent): void {
303
+ this.unhighlight(evt);
304
+ }
305
+
306
+ private handleDrop(evt: DragEvent): void {
307
+ this.unhighlight(evt);
308
+
309
+ // Forward to media picker
310
+ if (this.mediaPickerElement) {
311
+ const files = [...evt.dataTransfer.files];
312
+ this.mediaPickerElement.uploadFiles(files);
313
+ }
314
+ }
315
+
316
+ private handleAttachmentIconClick(): void {
317
+ // Trigger the file picker on the media picker
318
+ if (this.mediaPickerElement) {
319
+ const uploadInput = this.mediaPickerElement.shadowRoot.querySelector(
320
+ '#upload-input'
321
+ ) as HTMLInputElement;
322
+ if (uploadInput) {
323
+ uploadInput.click();
324
+ }
325
+ }
326
+ }
327
+
328
+ private highlight(evt: DragEvent): void {
329
+ evt.preventDefault();
330
+ evt.stopPropagation();
331
+
332
+ // Always allow highlight for testing purposes, but in real usage check media picker
333
+ this.pendingDrop = true;
334
+ }
335
+
336
+ private unhighlight(evt: DragEvent): void {
337
+ evt.preventDefault();
338
+ evt.stopPropagation();
339
+ this.pendingDrop = false;
340
+ }
341
+
342
+ public updated(changedProperties: Map<string, any>) {
343
+ super.updated(changedProperties);
344
+
345
+ if (changedProperties.has('attachments')) {
346
+ // Re-query media picker since the DOM structure may have changed
347
+ this.mediaPickerElement = this.shadowRoot.querySelector(
348
+ 'temba-media-picker'
349
+ ) as MediaPicker;
350
+ }
351
+
352
+ if (changedProperties.has('uploading')) {
353
+ this.dispatchEvent(
354
+ new CustomEvent('loading', {
355
+ detail: { loading: this.uploading }
356
+ })
357
+ );
358
+ }
359
+ }
360
+
361
+ public focus() {
362
+ super.focus();
363
+ if (this.completionElement) {
364
+ this.completionElement.focus();
365
+ }
366
+ }
367
+
368
+ public click() {
369
+ super.click();
370
+ if (this.completionElement) {
371
+ this.completionElement.click();
372
+ }
373
+ }
374
+
375
+ public render(): TemplateResult {
376
+ const hasAttachments = this.hasStaticAttachments();
377
+
378
+ return html`
379
+ <temba-field
380
+ name=${this.name}
381
+ .label=${this.label}
382
+ .helpText=${this.helpText}
383
+ .errors=${this.errors}
384
+ .widgetOnly=${this.widgetOnly}
385
+ >
386
+ <div
387
+ class=${getClasses({
388
+ 'message-editor-container': true,
389
+ highlight: this.pendingDrop,
390
+ 'has-attachments': hasAttachments
391
+ })}
392
+ @dragenter=${this.handleDragEnter}
393
+ @dragover=${this.handleDragOver}
394
+ @dragleave=${this.handleDragLeave}
395
+ @drop=${this.handleDrop}
396
+ >
397
+ <div class="completion-wrapper">
398
+ <temba-completion
399
+ name=${this.name}
400
+ .value=${this.value}
401
+ placeholder=${this.placeholder}
402
+ ?textarea=${this.textarea}
403
+ ?autogrow=${this.autogrow}
404
+ ?session=${this.session}
405
+ ?submitOnEnter=${this.submitOnEnter}
406
+ ?gsm=${this.gsm}
407
+ ?disableCompletion=${this.disableCompletion}
408
+ maxlength=${ifDefined(this.maxLength)}
409
+ counter=${ifDefined(this.counter)}
410
+ minHeight=${ifDefined(this.minHeight)}
411
+ widgetOnly
412
+ @change=${this.handleCompletionChange}
413
+ ></temba-completion>
414
+ </div>
415
+
416
+ <div class="media-wrapper ">
417
+ <temba-media-picker
418
+ .accept=${this.accept}
419
+ .max=${this.maxAttachments}
420
+ .endpoint=${this.endpoint}
421
+ @change=${this.handleMediaChange}
422
+ ignoreDrops
423
+ ></temba-media-picker>
424
+ </div>
425
+ <temba-icon
426
+ class="attachment-icon"
427
+ name=${Icon.attachment}
428
+ size="1.2"
429
+ @click=${this.handleAttachmentIconClick}
430
+ ></temba-icon>
431
+
432
+ <div class="drop-overlay"></div>
433
+
434
+ <!-- Hidden media picker for handling uploads when no attachments are shown -->
435
+ ${!hasAttachments
436
+ ? html`<temba-media-picker
437
+ style="display: none;"
438
+ .accept=${this.accept}
439
+ .max=${this.maxAttachments}
440
+ .endpoint=${this.endpoint}
441
+ @change=${this.handleMediaChange}
442
+ ignoreDrops
443
+ ></temba-media-picker>`
444
+ : ''}
445
+ </div>
446
+ </temba-field>
447
+ `;
448
+ }
449
+ }
@@ -193,7 +193,7 @@ export class TextInput extends FormElement {
193
193
 
194
194
  this.inputElement = this.shadowRoot.querySelector('.textinput');
195
195
 
196
- if (changes.has('counter')) {
196
+ if (changes.has('counter') && this.counter && this.counter.trim()) {
197
197
  let root = this.getParentModax() as any;
198
198
  if (root) {
199
199
  root = root.shadowRoot;
@@ -202,7 +202,20 @@ export class TextInput extends FormElement {
202
202
  root = document;
203
203
  }
204
204
  this.counterElement = root.querySelector(this.counter);
205
- this.counterElement.text = this.value;
205
+ if (this.counterElement) {
206
+ this.counterElement.text = this.value;
207
+ }
208
+ }
209
+ }
210
+
211
+ private updateAutogrowSize(): void {
212
+ if (this.textarea && this.autogrow) {
213
+ const autogrow = this.shadowRoot.querySelector(
214
+ '.grow-wrap > div'
215
+ ) as HTMLDivElement;
216
+ if (autogrow) {
217
+ autogrow.innerText = this.value + String.fromCharCode(10);
218
+ }
206
219
  }
207
220
  }
208
221
 
@@ -214,12 +227,7 @@ export class TextInput extends FormElement {
214
227
  this.fireEvent('change');
215
228
  }
216
229
 
217
- if (this.textarea && this.autogrow) {
218
- const autogrow = this.shadowRoot.querySelector(
219
- '.grow-wrap > div'
220
- ) as HTMLDivElement;
221
- autogrow.innerText = this.value + String.fromCharCode(10);
222
- }
230
+ this.updateAutogrowSize();
223
231
 
224
232
  if (this.cursorStart > -1 && this.cursorEnd > -1) {
225
233
  this.inputElement.setSelectionRange(this.cursorStart, this.cursorEnd);
@@ -81,7 +81,7 @@ export class Select<T extends SelectOption> extends FormElement {
81
81
  background: rgba(100, 100, 100, 0.05);
82
82
  }
83
83
 
84
- . selected-item.multi .remove-item {
84
+ .selected-item.multi .remove-item {
85
85
  display: none;
86
86
  }
87
87
 
@@ -222,6 +222,7 @@ export class Select<T extends SelectOption> extends FormElement {
222
222
 
223
223
  .multi temba-sortable-list {
224
224
  margin: 0 !important;
225
+ flex-grow: 1;
225
226
  }
226
227
 
227
228
  input {
@@ -255,6 +256,12 @@ export class Select<T extends SelectOption> extends FormElement {
255
256
 
256
257
  .multi .input-wrapper {
257
258
  margin-left: 2px !important;
259
+ margin-right: 2px !important;
260
+ margin-top: 2px;
261
+ margin-bottom: 2px;
262
+ flex-shrink: 0;
263
+ min-width: 100px;
264
+ align-self: center;
258
265
  }
259
266
 
260
267
  .input-wrapper:focus-within .placeholder {
@@ -290,11 +297,6 @@ export class Select<T extends SelectOption> extends FormElement {
290
297
  box-shadow: none !important;
291
298
  }
292
299
 
293
- .multi .input-wrapper {
294
- flex-shrink: 0;
295
- min-width: 100px;
296
- }
297
-
298
300
  .input-wrapper .searchbox {
299
301
  }
300
302
 
@@ -310,6 +312,17 @@ export class Select<T extends SelectOption> extends FormElement {
310
312
  margin-left: 6px;
311
313
  }
312
314
 
315
+ .empty .placeholder {
316
+ display: block;
317
+ }
318
+
319
+ .multi .placeholder {
320
+ display: block;
321
+ margin: 2px 2px;
322
+ padding: 2px 8px;
323
+ align-self: center;
324
+ }
325
+
313
326
  .footer {
314
327
  padding: 5px 10px;
315
328
  background: var(--color-primary-light);
@@ -320,10 +333,10 @@ export class Select<T extends SelectOption> extends FormElement {
320
333
  }
321
334
 
322
335
  .small {
323
- --temba-select-selected-padding: 7px;
324
- --temba-select-selected-line-height: 13px;
325
- --temba-select-selected-font-size: 12px;
326
- --search-input-height: 7px !important;
336
+ --temba-select-selected-padding: 6px;
337
+ --temba-select-selected-line-height: 12px;
338
+ --temba-select-selected-font-size: 14px;
339
+ --temba-select-min-height: 2.28em;
327
340
  }
328
341
 
329
342
  .info-text {
@@ -476,15 +489,26 @@ export class Select<T extends SelectOption> extends FormElement {
476
489
  @property({ type: String, attribute: 'info_text' })
477
490
  infoText = '';
478
491
 
492
+ // Override the setter to ensure values is always an array
479
493
  @property({ type: Array })
480
- values: T[] = [];
494
+ set values(newValues: any) {
495
+ this._values = Array.isArray(newValues) ? newValues : [];
496
+ this.requestUpdate('values');
497
+ }
498
+
499
+ get values(): T[] {
500
+ return this._values || [];
501
+ }
502
+
503
+ private _values: T[] = [];
481
504
 
482
505
  @property({ type: Object })
483
506
  selection: any;
484
507
 
485
508
  @property({ attribute: false })
486
- getName: (option: any) => string = (option: any) =>
487
- option[this.nameKey || 'name'];
509
+ getName: (option: any) => string = (option: any) => {
510
+ return option[this.nameKey || 'name'];
511
+ };
488
512
 
489
513
  @property({ attribute: false })
490
514
  isMatch: (option: any, q: string) => boolean = this.isMatchDefault;
@@ -545,7 +569,7 @@ export class Select<T extends SelectOption> extends FormElement {
545
569
  private alphaSort = (a: any, b: any) => {
546
570
  // by default, all endpoint values are sorted by name
547
571
  if (this.endpoint) {
548
- return this.getName(a).localeCompare(this.getName(b));
572
+ return this.getNameInternal(a).localeCompare(this.getNameInternal(b));
549
573
  }
550
574
  return 0;
551
575
  };
@@ -573,7 +597,7 @@ export class Select<T extends SelectOption> extends FormElement {
573
597
  }
574
598
 
575
599
  public isMatchDefault(option: T, q: string) {
576
- const name = this.getName(option) || '';
600
+ const name = this.getNameInternal(option) || '';
577
601
  return name.toLowerCase().indexOf(q) > -1;
578
602
  }
579
603
 
@@ -963,7 +987,9 @@ export class Select<T extends SelectOption> extends FormElement {
963
987
  }
964
988
 
965
989
  protected getNameInternal: (option: T) => string = (option: T) => {
966
- return this.getName(option);
990
+ return this.getName
991
+ ? this.getName(option)
992
+ : option[this.nameKey || 'name'] || '';
967
993
  };
968
994
 
969
995
  private getOptionsDefault(response: WebResponse): any[] {
@@ -1493,7 +1519,7 @@ export class Select<T extends SelectOption> extends FormElement {
1493
1519
  name="${icon}"
1494
1520
  style="margin-right:0.5em;"
1495
1521
  ></temba-icon>`
1496
- : null}<span>${this.getName(option)}</span>
1522
+ : null}<span>${this.getNameInternal(option)}</span>
1497
1523
  </div>
1498
1524
  `;
1499
1525
  }
@@ -1636,9 +1662,13 @@ export class Select<T extends SelectOption> extends FormElement {
1636
1662
 
1637
1663
  public render(): TemplateResult {
1638
1664
  const placeholder = this.values.length === 0 ? this.placeholder : '';
1639
- const placeholderDiv = html`
1640
- <div class="placeholder">${placeholder}</div>
1641
- `;
1665
+
1666
+ // Single unified placeholder - shows when empty and (not focused OR not searchable)
1667
+ const shouldShowPlaceholder =
1668
+ this.values.length === 0 && (!this.focused || !this.searchable);
1669
+ const placeholderElement = shouldShowPlaceholder
1670
+ ? html`<div class="placeholder">${placeholder}</div>`
1671
+ : null;
1642
1672
 
1643
1673
  const clear =
1644
1674
  this.clearable && this.values.length > 0 && !this.isMultiMode
@@ -1683,10 +1713,9 @@ export class Select<T extends SelectOption> extends FormElement {
1683
1713
  .value=${this.input}
1684
1714
  />
1685
1715
  <div id="anchor" style=${styleMap(anchorStyles)}></div>
1686
- ${placeholderDiv}
1687
1716
  </div>
1688
1717
  `
1689
- : placeholderDiv;
1718
+ : null;
1690
1719
 
1691
1720
  const items = html`${!this.isMultiMode && !this.resolving ? input : null}
1692
1721
  ${this.isMultiMode && this.values.length > 1
@@ -1760,9 +1789,10 @@ export class Select<T extends SelectOption> extends FormElement {
1760
1789
  </div>
1761
1790
  `
1762
1791
  )}
1792
+ ${this.searchable && this.focused ? input : null}
1763
1793
  </temba-sortable-list>
1764
1794
  `
1765
- : this.values.map(
1795
+ : html`${this.values.map(
1766
1796
  (selected: any, index: number) => html`
1767
1797
  <div
1768
1798
  class="selected-item ${index === this.selectedIndex
@@ -1811,7 +1841,8 @@ export class Select<T extends SelectOption> extends FormElement {
1811
1841
  </div>
1812
1842
  `
1813
1843
  )}
1814
- ${this.isMultiMode ? input : null}`;
1844
+ ${this.isMultiMode && this.searchable && this.focused ? input : null}
1845
+ ${placeholderElement}`}`;
1815
1846
 
1816
1847
  return html`
1817
1848