@nyaruka/temba-components 0.113.0 → 0.114.1

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 (130) hide show
  1. package/CHANGELOG.md +27 -2
  2. package/demo/index.html +1 -1
  3. package/dist/temba-components.js +793 -966
  4. package/dist/temba-components.js.map +1 -1
  5. package/out-tsc/src/aliaseditor/AliasEditor.js.map +1 -1
  6. package/out-tsc/src/button/Button.js +6 -2
  7. package/out-tsc/src/button/Button.js.map +1 -1
  8. package/out-tsc/src/chat/Chat.js +29 -7
  9. package/out-tsc/src/chat/Chat.js.map +1 -1
  10. package/out-tsc/src/compose/Compose.js +10 -5
  11. package/out-tsc/src/compose/Compose.js.map +1 -1
  12. package/out-tsc/src/contacts/ContactChat.js +240 -114
  13. package/out-tsc/src/contacts/ContactChat.js.map +1 -1
  14. package/out-tsc/src/contacts/ContactFieldEditor.js.map +1 -1
  15. package/out-tsc/src/contacts/events.js.map +1 -1
  16. package/out-tsc/src/contacts/helpers.js +5 -1
  17. package/out-tsc/src/contacts/helpers.js.map +1 -1
  18. package/out-tsc/src/contactsearch/ContactSearch.js +1 -1
  19. package/out-tsc/src/contactsearch/ContactSearch.js.map +1 -1
  20. package/out-tsc/src/dropdown/Dropdown.js +121 -108
  21. package/out-tsc/src/dropdown/Dropdown.js.map +1 -1
  22. package/out-tsc/src/interfaces.js +2 -0
  23. package/out-tsc/src/interfaces.js.map +1 -1
  24. package/out-tsc/src/list/ContentMenu.js +11 -8
  25. package/out-tsc/src/list/ContentMenu.js.map +1 -1
  26. package/out-tsc/src/list/RunList.js.map +1 -1
  27. package/out-tsc/src/list/TembaList.js +21 -14
  28. package/out-tsc/src/list/TembaList.js.map +1 -1
  29. package/out-tsc/src/list/TembaMenu.js +11 -12
  30. package/out-tsc/src/list/TembaMenu.js.map +1 -1
  31. package/out-tsc/src/list/TicketList.js +10 -0
  32. package/out-tsc/src/list/TicketList.js.map +1 -1
  33. package/out-tsc/src/omnibox/Omnibox.js +33 -90
  34. package/out-tsc/src/omnibox/Omnibox.js.map +1 -1
  35. package/out-tsc/src/options/Options.js +49 -47
  36. package/out-tsc/src/options/Options.js.map +1 -1
  37. package/out-tsc/src/select/PopupSelect.js +57 -0
  38. package/out-tsc/src/select/PopupSelect.js.map +1 -0
  39. package/out-tsc/src/select/Select.js +194 -144
  40. package/out-tsc/src/select/Select.js.map +1 -1
  41. package/out-tsc/src/select/UserSelect.js +67 -0
  42. package/out-tsc/src/select/UserSelect.js.map +1 -0
  43. package/out-tsc/src/store/Store.js +65 -14
  44. package/out-tsc/src/store/Store.js.map +1 -1
  45. package/out-tsc/src/tabpane/TabPane.js +72 -115
  46. package/out-tsc/src/tabpane/TabPane.js.map +1 -1
  47. package/out-tsc/src/textinput/TextInput.js +1 -0
  48. package/out-tsc/src/textinput/TextInput.js.map +1 -1
  49. package/out-tsc/src/user/TembaUser.js +24 -37
  50. package/out-tsc/src/user/TembaUser.js.map +1 -1
  51. package/out-tsc/src/utils/index.js +13 -6
  52. package/out-tsc/src/utils/index.js.map +1 -1
  53. package/out-tsc/temba-modules.js +4 -2
  54. package/out-tsc/temba-modules.js.map +1 -1
  55. package/out-tsc/test/temba-omnibox.test.js +43 -4
  56. package/out-tsc/test/temba-omnibox.test.js.map +1 -1
  57. package/out-tsc/test/temba-select.test.js +121 -65
  58. package/out-tsc/test/temba-select.test.js.map +1 -1
  59. package/out-tsc/test/utils.test.js +4 -0
  60. package/out-tsc/test/utils.test.js.map +1 -1
  61. package/package.json +1 -1
  62. package/screenshots/truth/compose/attachments-tab.png +0 -0
  63. package/screenshots/truth/compose/attachments-with-files-focused.png +0 -0
  64. package/screenshots/truth/compose/attachments-with-files.png +0 -0
  65. package/screenshots/truth/compose/intial-text.png +0 -0
  66. package/screenshots/truth/compose/no-counter.png +0 -0
  67. package/screenshots/truth/compose/wraps-text-and-spaces.png +0 -0
  68. package/screenshots/truth/compose/wraps-text-and-url.png +0 -0
  69. package/screenshots/truth/compose/wraps-text-no-spaces.png +0 -0
  70. package/screenshots/truth/contacts/chat-failure.png +0 -0
  71. package/screenshots/truth/contacts/chat-for-active-contact.png +0 -0
  72. package/screenshots/truth/contacts/chat-for-archived-contact.png +0 -0
  73. package/screenshots/truth/contacts/chat-for-blocked-contact.png +0 -0
  74. package/screenshots/truth/contacts/chat-for-stopped-contact.png +0 -0
  75. package/screenshots/truth/contacts/chat-sends-attachments-only.png +0 -0
  76. package/screenshots/truth/contacts/chat-sends-text-and-attachments.png +0 -0
  77. package/screenshots/truth/contacts/chat-sends-text-only.png +0 -0
  78. package/screenshots/truth/content-menu/item-no-buttons.png +0 -0
  79. package/screenshots/truth/content-menu/items-and-buttons.png +0 -0
  80. package/screenshots/truth/omnibox/selected.png +0 -0
  81. package/screenshots/truth/select/enabled-multi-selection.png +0 -0
  82. package/screenshots/truth/select/endpoint-initial-value-updated.png +0 -0
  83. package/screenshots/truth/select/endpoint-initial-value.png +0 -0
  84. package/screenshots/truth/select/expressions.png +0 -0
  85. package/screenshots/truth/select/functions.png +0 -0
  86. package/screenshots/truth/select/initial-value.png +0 -0
  87. package/screenshots/truth/select/multi-with-endpoint.png +0 -0
  88. package/screenshots/truth/select/multiple-initial-values.png +0 -0
  89. package/screenshots/truth/select/selected-multi-test.png +0 -0
  90. package/screenshots/truth/select/static-initial-value.png +0 -0
  91. package/screenshots/truth/select/static-initial-via-selected.png +0 -0
  92. package/screenshots/truth/select/value-initial.png +0 -0
  93. package/src/aliaseditor/AliasEditor.ts +1 -1
  94. package/src/button/Button.ts +6 -2
  95. package/src/chat/Chat.ts +28 -6
  96. package/src/compose/Compose.ts +11 -6
  97. package/src/contacts/ContactChat.ts +260 -118
  98. package/src/contacts/ContactFieldEditor.ts +1 -1
  99. package/src/contacts/events.ts +1 -0
  100. package/src/contacts/helpers.ts +8 -1
  101. package/src/contactsearch/ContactSearch.ts +3 -3
  102. package/src/dropdown/Dropdown.ts +142 -103
  103. package/src/interfaces.ts +4 -1
  104. package/src/list/ContentMenu.ts +11 -9
  105. package/src/list/RunList.ts +3 -1
  106. package/src/list/TembaList.ts +24 -14
  107. package/src/list/TembaMenu.ts +14 -15
  108. package/src/list/TicketList.ts +11 -0
  109. package/src/omnibox/Omnibox.ts +34 -95
  110. package/src/options/Options.ts +57 -60
  111. package/src/select/PopupSelect.ts +53 -0
  112. package/src/select/Select.ts +182 -112
  113. package/src/select/UserSelect.ts +71 -0
  114. package/src/store/Store.ts +72 -21
  115. package/src/tabpane/TabPane.ts +79 -113
  116. package/src/textinput/TextInput.ts +1 -0
  117. package/src/user/TembaUser.ts +30 -41
  118. package/src/utils/index.ts +12 -8
  119. package/temba-modules.ts +4 -2
  120. package/test/temba-omnibox.test.ts +56 -4
  121. package/test/temba-select.test.ts +170 -56
  122. package/test/utils.test.ts +5 -0
  123. package/test-assets/select/omnibox.json +55 -0
  124. package/web-test-runner.config.mjs +16 -4
  125. package/out-tsc/src/contacts/ContactTickets.js +0 -462
  126. package/out-tsc/src/contacts/ContactTickets.js.map +0 -1
  127. package/out-tsc/test/temba-contact-tickets.test.js +0 -36
  128. package/out-tsc/test/temba-contact-tickets.test.js.map +0 -1
  129. package/src/contacts/ContactTickets.ts +0 -490
  130. package/test/temba-contact-tickets.test.ts +0 -52
@@ -516,6 +516,18 @@ export class Stubbable {
516
516
 
517
517
  export const stubbable = new Stubbable();
518
518
 
519
+ export const spreadAttributes = (obj): TemplateResult[] => {
520
+ return Object.entries(obj).map(([key, value]) => {
521
+ if (key.startsWith('@')) {
522
+ return html`@${key.slice(1)}=${value}`;
523
+ } else if (key.startsWith('.')) {
524
+ return html`.${key.slice(1)}=${value}`;
525
+ } else {
526
+ return html`${key}=${value}`;
527
+ }
528
+ });
529
+ };
530
+
519
531
  export const timeSince = (
520
532
  date: Date,
521
533
  options: { compareDate?: Date; hideRecentText?: boolean; suffix?: string } = {
@@ -730,14 +742,6 @@ export const stopEvent = (event: Event) => {
730
742
  }
731
743
  };
732
744
 
733
- export const getFullName = (user: User) => {
734
- if (user.first_name && user.last_name) {
735
- return `${user.first_name} ${user.last_name}`;
736
- }
737
-
738
- return user.email;
739
- };
740
-
741
745
  /**
742
746
  * Extracts 2-letter initials from text like a workspace or user name
743
747
  * @param text the input text
package/temba-modules.ts CHANGED
@@ -32,7 +32,6 @@ import { ContactFieldEditor } from './src/contacts/ContactFieldEditor';
32
32
 
33
33
  import { ContactBadges } from './src/contacts/ContactBadges';
34
34
  import { ContactPending } from './src/contacts/ContactPending';
35
- import { ContactTickets } from './src/contacts/ContactTickets';
36
35
  import { TembaSlider } from './src/slider/TembaSlider';
37
36
  import { RunList } from './src/list/RunList';
38
37
  import { FlowStoreElement } from './src/flow/FlowStoreElement';
@@ -62,6 +61,8 @@ import { OutboxMonitor } from './src/outboxmonitor/OutboxMonitor';
62
61
  import { ProgressBar } from './src/progress/ProgressBar';
63
62
  import { StartProgress } from './src/progress/StartProgress';
64
63
  import { ShortcutList } from './src/list/ShortcutList';
64
+ import { PopupSelect } from './src/select/PopupSelect';
65
+ import { UserSelect } from './src/select/UserSelect';
65
66
 
66
67
  export function addCustomElement(name: string, comp: any) {
67
68
  if (!window.customElements.get(name)) {
@@ -114,7 +115,6 @@ addCustomElement('temba-tabs', TabPane);
114
115
  addCustomElement('temba-tab', Tab);
115
116
  addCustomElement('temba-contact-badges', ContactBadges);
116
117
  addCustomElement('temba-contact-pending', ContactPending);
117
- addCustomElement('temba-contact-tickets', ContactTickets);
118
118
  addCustomElement('temba-slider', TembaSlider);
119
119
  addCustomElement('temba-content-menu', ContentMenu);
120
120
  addCustomElement('temba-compose', Compose);
@@ -134,3 +134,5 @@ addCustomElement('temba-outbox-monitor', OutboxMonitor);
134
134
  addCustomElement('temba-progress', ProgressBar);
135
135
  addCustomElement('temba-start-progress', StartProgress);
136
136
  addCustomElement('temba-shortcuts', ShortcutList);
137
+ addCustomElement('temba-popup-select', PopupSelect);
138
+ addCustomElement('temba-user-select', UserSelect);
@@ -1,14 +1,66 @@
1
1
  import { fixture, assert } from '@open-wc/testing';
2
2
  import { Omnibox } from '../src/omnibox/Omnibox';
3
- import './utils.test';
3
+ import { assertScreenshot, getClip } from './utils.test';
4
+ import { openAndClick } from './temba-select.test';
5
+ import { useFakeTimers, spy } from 'sinon';
4
6
 
5
- export const getHTML = () => {
6
- return `<temba-omnibox></temba-omnibox>`;
7
+ export const getHTML = (attrs: any = { name: 'recipients' }): string => {
8
+ const selectHTML = `
9
+ <temba-omnibox${Object.keys(attrs)
10
+ .map((name: string) => {
11
+ // check if it's a string attribute
12
+ if (typeof attrs[name] === 'string') {
13
+ return ` ${name}="${attrs[name].replace(/"/g, '&quot;')}"`;
14
+ }
15
+ return ` ${name}="${attrs[name]}"`;
16
+ })
17
+ .join(' ')}>
18
+ </temba-select>`;
19
+ return selectHTML;
20
+ };
21
+
22
+ export const createOmnibox = async (
23
+ clock: any,
24
+ attrs: any = {}
25
+ ): Promise<Omnibox> => {
26
+ const parentNode = document.createElement('div');
27
+ parentNode.setAttribute('style', 'width: 250px;');
28
+
29
+ const omnibox: Omnibox = await fixture(getHTML(attrs), { parentNode });
30
+ clock.runAll();
31
+ await omnibox.updateComplete;
32
+ return omnibox;
7
33
  };
8
34
 
9
35
  describe('temba-omnibox', () => {
36
+ let clock: any;
37
+ beforeEach(function () {
38
+ clock = useFakeTimers();
39
+ setViewport({ width: 500, height: 1000, deviceScaleFactor: 2 });
40
+ });
41
+
42
+ afterEach(function () {
43
+ clock.restore();
44
+ });
45
+
10
46
  it('can be created', async () => {
11
- const omnibox: Omnibox = await fixture(getHTML());
47
+ const omnibox: Omnibox = await fixture(
48
+ getHTML({ endpoint: '/test-assets/select/omnibox.json' })
49
+ );
12
50
  assert.instanceOf(omnibox, Omnibox);
13
51
  });
52
+
53
+ it('fires change events on selection', async () => {
54
+ const omnibox: Omnibox = await createOmnibox(clock, {
55
+ endpoint: '/test-assets/select/omnibox.json'
56
+ });
57
+
58
+ const changeEvent = spy();
59
+ omnibox.addEventListener('change', changeEvent);
60
+
61
+ await openAndClick(clock, omnibox, 0);
62
+ assert(changeEvent.called, 'change event not fired');
63
+
64
+ await assertScreenshot('omnibox/selected', getClip(omnibox));
65
+ });
14
66
  });