@postalsys/ee-client 1.9.0 → 1.10.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 (2) hide show
  1. package/index.js +432 -134
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -65,6 +65,31 @@ const MESSAGE_BODY_STYLES = `
65
65
  }
66
66
  `;
67
67
 
68
+ // Inline SVG icons (24x24 grid, stroked with currentColor so they follow the button's text
69
+ // colour in both themes). Static markup only, nothing here is built from message data.
70
+ const ICON_PATHS = {
71
+ back: '<path d="m15 18-6-6 6-6"/>',
72
+ next: '<path d="m9 18 6-6-6-6"/>',
73
+ chevronDown: '<path d="m6 9 6 6 6-6"/>',
74
+ mail: '<rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/>',
75
+ mailOpen:
76
+ '<path d="M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z"/><path d="m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10"/>',
77
+ trash: '<path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/>',
78
+ move: '<path d="M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1"/><path d="M2 13h10"/><path d="m9 16 3-3-3-3"/>',
79
+ download: '<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/><path d="M12 15V3"/>',
80
+ send: '<path d="m22 2-7 20-4-9-9-4Z"/><path d="M22 2 11 13"/>',
81
+ compose: '<path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/>'
82
+ };
83
+
84
+ // Below this container width the UI shows one pane at a time and the compose button
85
+ // drops its label. Shared by the stylesheet's container query and the compose button
86
+ // sizing, which cannot use the query because the button is not inside .ee-client.
87
+ const NARROW_WIDTH = 700;
88
+
89
+ function icon(name, size = 16) {
90
+ return `<svg class="ee-icon" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${ICON_PATHS[name]}</svg>`;
91
+ }
92
+
68
93
  export class EmailEngineClient {
69
94
  constructor(options = {}) {
70
95
  this.apiUrl = options.apiUrl || 'http://127.0.0.1:3000';
@@ -242,7 +267,8 @@ export class EmailEngineClient {
242
267
  }
243
268
 
244
269
  async loadMessages(path, cursor = null) {
245
- this._setPaneHtml('.ee-message-list', '<div class="ee-loading">Loading messages...</div>');
270
+ this._setView('list');
271
+ this._setPaneHtml('.ee-message-list', `${this._messageListHeader(path)}<div class="ee-loading">Loading messages...</div>`);
246
272
 
247
273
  try {
248
274
  const params = new URLSearchParams({ path, pageSize: this.pageSize });
@@ -272,13 +298,20 @@ export class EmailEngineClient {
272
298
  };
273
299
  } catch (error) {
274
300
  console.error('Failed to load messages:', error);
275
- this._renderPaneError('.ee-message-list', 'Messages unavailable', error, () => this._fireAndForget(this.loadMessages(path, cursor)));
301
+ this._renderPaneError(
302
+ '.ee-message-list',
303
+ 'Messages unavailable',
304
+ error,
305
+ () => this._fireAndForget(this.loadMessages(path, cursor)),
306
+ this._messageListHeader(path)
307
+ );
276
308
  throw error;
277
309
  }
278
310
  }
279
311
 
280
312
  async loadMessage(messageId) {
281
- this._setPaneHtml('.ee-message-viewer', '<div class="ee-loading">Loading message...</div>');
313
+ this._setView('message');
314
+ this._setPaneHtml('.ee-message-viewer', `${this._messageToolbar()}<div class="ee-loading">Loading message...</div>`);
282
315
 
283
316
  try {
284
317
  const params = new URLSearchParams({
@@ -314,7 +347,13 @@ export class EmailEngineClient {
314
347
  return this.currentMessage;
315
348
  } catch (error) {
316
349
  console.error('Failed to load message:', error);
317
- this._renderPaneError('.ee-message-viewer', 'Message unavailable', error, () => this._fireAndForget(this.loadMessage(messageId)));
350
+ this._renderPaneError(
351
+ '.ee-message-viewer',
352
+ 'Message unavailable',
353
+ error,
354
+ () => this._fireAndForget(this.loadMessage(messageId)),
355
+ this._messageToolbar()
356
+ );
318
357
  throw error;
319
358
  }
320
359
  }
@@ -556,11 +595,12 @@ export class EmailEngineClient {
556
595
  // missing, optionally with a Retry button. Without this a failed request
557
596
  // leaves the pane stuck on its "Loading..." placeholder forever, with the
558
597
  // only trace of the failure in the developer console.
559
- _renderPaneError(selector, title, error, retry = null) {
598
+ _renderPaneError(selector, title, error, retry = null, header = '') {
560
599
  const detail = this._errorMessage(error, '');
561
600
  const pane = this._setPaneHtml(
562
601
  selector,
563
602
  `
603
+ ${header}
564
604
  <div class="ee-error">
565
605
  <div class="ee-error-title">${this.escapeHtml(title)}</div>
566
606
  ${detail ? `<div class="ee-error-detail">${this.escapeHtml(detail)}</div>` : ''}
@@ -604,14 +644,54 @@ export class EmailEngineClient {
604
644
  // The message list before any folder is opened. Shared with createLayout so the
605
645
  // pane header markup lives in one place.
606
646
  _messageListPlaceholder() {
647
+ return `${this._messageListHeader(null)}<div class="ee-empty-state">Select a folder</div>`;
648
+ }
649
+
650
+ // Header for every state of the message list pane, titled with the folder
651
+ // being shown. In the single-pane layout its back button leads to the folders.
652
+ _messageListHeader(path, controls = '') {
653
+ const folder = path && this.folders.find(f => f.path === path);
607
654
  return `
608
655
  <div class="ee-pane-header">
609
- <span class="ee-pane-title">Messages</span>
656
+ <div class="ee-pane-heading">
657
+ ${this._iconButton('show-folders', 'back', 'Folders', 'ee-nav-button')}
658
+ <span class="ee-pane-title">${this.escapeHtml(folder ? folder.name : 'Messages')}</span>
659
+ </div>
660
+ ${controls}
610
661
  </div>
611
- <div class="ee-empty-state">Select a folder</div>
612
662
  `;
613
663
  }
614
664
 
665
+ // The viewer's toolbar row. It stays up in the loading, empty and error states
666
+ // too, so the header band runs unbroken across the panes and the single-pane
667
+ // layout always has its way back to the list.
668
+ _messageToolbar(actions = '') {
669
+ return `
670
+ <div class="ee-message-actions">
671
+ ${this._iconButton('back-to-list', 'back', 'Back to messages', 'ee-nav-button')}
672
+ ${actions}
673
+ </div>
674
+ `;
675
+ }
676
+
677
+ _messageViewerPlaceholder() {
678
+ return `${this._messageToolbar()}<div class="ee-empty-state">Select a message to view</div>`;
679
+ }
680
+
681
+ // Which pane the single-pane (narrow) layout shows: folders, list or message.
682
+ // Wider layouts show all three and ignore it.
683
+ _getView() {
684
+ const client = this.container && this.container.querySelector('.ee-client');
685
+ return client ? client.dataset.view : null;
686
+ }
687
+
688
+ _setView(view) {
689
+ const client = this.container && this.container.querySelector('.ee-client');
690
+ if (client) {
691
+ client.dataset.view = view;
692
+ }
693
+ }
694
+
615
695
  formatDate(dateStr) {
616
696
  const date = new Date(dateStr);
617
697
  const now = new Date();
@@ -830,6 +910,9 @@ export class EmailEngineClient {
830
910
  background: #fff;
831
911
  border: 1px solid #ddd;
832
912
  position: relative;
913
+ /* Layout breakpoints follow the widget's own width, not the viewport:
914
+ hosts embed it in pages of any shape */
915
+ container: ee-client / inline-size;
833
916
  }
834
917
 
835
918
  .ee-client * {
@@ -837,7 +920,8 @@ export class EmailEngineClient {
837
920
  }
838
921
 
839
922
  .ee-sidebar {
840
- width: 200px;
923
+ width: clamp(160px, 18%, 220px);
924
+ flex-shrink: 0;
841
925
  background: #ffffff;
842
926
  border-right: 1px solid #ddd;
843
927
  display: flex;
@@ -917,7 +1001,8 @@ export class EmailEngineClient {
917
1001
  }
918
1002
 
919
1003
  .ee-message-list {
920
- width: 350px;
1004
+ width: clamp(260px, 32%, 380px);
1005
+ flex-shrink: 0;
921
1006
  border-right: 1px solid #ddd;
922
1007
  background: #ffffff;
923
1008
  display: flex;
@@ -998,45 +1083,117 @@ export class EmailEngineClient {
998
1083
 
999
1084
  .ee-message-viewer {
1000
1085
  flex: 1;
1086
+ min-width: 0;
1001
1087
  display: flex;
1002
1088
  flex-direction: column;
1003
1089
  overflow: hidden;
1090
+ container: ee-viewer / inline-size;
1004
1091
  }
1005
1092
 
1006
1093
  .ee-message-actions {
1007
- padding: 10px 16px;
1094
+ padding: 0 12px;
1008
1095
  background: #e9ecef;
1009
1096
  background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
1010
1097
  border-bottom: 2px solid #dee2e6;
1011
1098
  display: flex;
1012
- gap: 8px;
1099
+ gap: 6px;
1013
1100
  height: 44px;
1014
1101
  align-items: center;
1015
1102
  flex-shrink: 0;
1016
1103
  box-sizing: border-box;
1017
1104
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
1105
+ overflow-x: auto;
1106
+ scrollbar-width: none;
1018
1107
  }
1019
1108
 
1020
1109
  .ee-button {
1021
- padding: 4px 10px;
1022
- border: 1px solid #ddd;
1110
+ display: inline-flex;
1111
+ align-items: center;
1112
+ justify-content: center;
1113
+ gap: 6px;
1114
+ flex-shrink: 0;
1115
+ padding: 0 10px;
1116
+ border: 1px solid #d0d4d9;
1023
1117
  background: white;
1024
- border-radius: 4px;
1118
+ color: #333;
1119
+ border-radius: 6px;
1025
1120
  cursor: pointer;
1026
- font-size: 12px;
1027
- height: 24px;
1121
+ font-family: inherit;
1122
+ font-size: 13px;
1123
+ font-weight: 500;
1124
+ height: 30px;
1028
1125
  line-height: 1;
1126
+ white-space: nowrap;
1029
1127
  box-sizing: border-box;
1030
1128
  }
1031
1129
 
1032
- select.ee-button {
1033
- padding: 3px 10px;
1034
- height: 24px;
1035
- }
1036
-
1037
1130
  .ee-button:hover:not(:disabled) {
1038
1131
  background: #f0f0f0;
1039
1132
  }
1133
+
1134
+ .ee-button:focus-visible,
1135
+ .ee-move-button:focus-within,
1136
+ .ee-compose-button:focus-visible {
1137
+ outline: 2px solid #4d9fff;
1138
+ outline-offset: 1px;
1139
+ }
1140
+
1141
+ .ee-icon {
1142
+ flex-shrink: 0;
1143
+ }
1144
+
1145
+ .ee-icon-button {
1146
+ width: 30px;
1147
+ padding: 0;
1148
+ }
1149
+
1150
+ .ee-nav-button {
1151
+ display: none;
1152
+ }
1153
+
1154
+ /* Borderless, so a back arrow beside the title does not read as one
1155
+ of the pagination arrows */
1156
+ .ee-client .ee-button.ee-nav-button {
1157
+ background: transparent;
1158
+ border-color: transparent;
1159
+ margin-left: -6px;
1160
+ }
1161
+
1162
+ .ee-toolbar-spacer {
1163
+ flex: 1;
1164
+ }
1165
+
1166
+ .ee-button-primary {
1167
+ background: #007bff;
1168
+ border-color: #007bff;
1169
+ color: white;
1170
+ }
1171
+
1172
+ .ee-button-primary:hover:not(:disabled) {
1173
+ background: #0069d9;
1174
+ }
1175
+
1176
+ .ee-button-danger:hover:not(:disabled) {
1177
+ background: #fdecea;
1178
+ border-color: #f1b0ab;
1179
+ color: #c62828;
1180
+ }
1181
+
1182
+ .ee-move-button {
1183
+ position: relative;
1184
+ }
1185
+
1186
+ /* The native select covers the whole button, invisibly, so a click
1187
+ anywhere on it opens the platform folder picker */
1188
+ .ee-move-select {
1189
+ position: absolute;
1190
+ inset: 0;
1191
+ width: 100%;
1192
+ height: 100%;
1193
+ opacity: 0;
1194
+ cursor: pointer;
1195
+ font-size: 14px;
1196
+ }
1040
1197
 
1041
1198
  .ee-button:disabled {
1042
1199
  background: #e9ecef;
@@ -1047,18 +1204,35 @@ export class EmailEngineClient {
1047
1204
 
1048
1205
  .ee-message-content {
1049
1206
  flex: 1;
1050
- padding: 16px;
1207
+ /* The bottom padding lets the end of the message scroll clear of
1208
+ the floating compose button */
1209
+ padding: 20px 20px 88px;
1051
1210
  overflow-y: auto;
1052
1211
  }
1212
+
1213
+ .ee-message-title {
1214
+ margin: 0 0 12px;
1215
+ font-size: 20px;
1216
+ font-weight: 600;
1217
+ line-height: 1.3;
1218
+ overflow-wrap: anywhere;
1219
+ }
1053
1220
 
1054
1221
  .ee-message-meta {
1222
+ display: grid;
1223
+ grid-template-columns: auto minmax(0, 1fr);
1224
+ gap: 2px 12px;
1055
1225
  margin-bottom: 16px;
1056
1226
  padding-bottom: 16px;
1057
1227
  border-bottom: 1px solid #e0e0e0;
1058
1228
  }
1059
1229
 
1060
1230
  .ee-message-meta-row {
1061
- margin-bottom: 4px;
1231
+ display: contents;
1232
+ }
1233
+
1234
+ .ee-message-meta-value {
1235
+ overflow-wrap: anywhere;
1062
1236
  }
1063
1237
 
1064
1238
  .ee-otp {
@@ -1138,8 +1312,6 @@ export class EmailEngineClient {
1138
1312
  }
1139
1313
 
1140
1314
  .ee-message-meta-label {
1141
- display: inline-block;
1142
- width: 60px;
1143
1315
  color: #666;
1144
1316
  font-weight: 500;
1145
1317
  }
@@ -1249,7 +1421,8 @@ export class EmailEngineClient {
1249
1421
  }
1250
1422
 
1251
1423
  .ee-pane-header {
1252
- padding: 10px 16px;
1424
+ gap: 8px;
1425
+ padding: 0 12px 0 16px;
1253
1426
  background: #e9ecef;
1254
1427
  background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
1255
1428
  border-bottom: 2px solid #dee2e6;
@@ -1262,10 +1435,20 @@ export class EmailEngineClient {
1262
1435
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
1263
1436
  }
1264
1437
 
1438
+ .ee-pane-heading {
1439
+ display: flex;
1440
+ align-items: center;
1441
+ gap: 6px;
1442
+ min-width: 0;
1443
+ }
1444
+
1265
1445
  .ee-pane-title {
1266
- font-weight: 500;
1446
+ font-weight: 600;
1267
1447
  font-size: 14px;
1268
1448
  color: #333;
1449
+ overflow: hidden;
1450
+ text-overflow: ellipsis;
1451
+ white-space: nowrap;
1269
1452
  }
1270
1453
 
1271
1454
  .ee-folder-tree {
@@ -1275,15 +1458,16 @@ export class EmailEngineClient {
1275
1458
 
1276
1459
  .ee-pagination-controls {
1277
1460
  display: flex;
1278
- gap: 8px;
1461
+ gap: 6px;
1279
1462
  align-items: center;
1463
+ flex-shrink: 0;
1280
1464
  }
1281
1465
 
1282
1466
  .ee-page-size-selector {
1283
1467
  display: flex;
1284
- gap: 4px;
1468
+ gap: 6px;
1285
1469
  align-items: center;
1286
- margin-left: auto;
1470
+ margin-left: 4px;
1287
1471
  }
1288
1472
 
1289
1473
  .ee-page-size-label {
@@ -1292,49 +1476,100 @@ export class EmailEngineClient {
1292
1476
  }
1293
1477
 
1294
1478
  .ee-page-size-select {
1295
- font-size: 11px;
1296
- padding: 2px 4px;
1297
- border: 1px solid #ddd;
1298
- border-radius: 3px;
1299
- background: white;
1300
- cursor: pointer;
1301
- height: 22px;
1302
- }
1303
-
1304
- .ee-pagination-btn {
1305
- font-size: 11px;
1306
- padding: 3px 8px;
1307
- height: 22px;
1308
- line-height: 1;
1479
+ padding: 0 4px;
1309
1480
  }
1310
1481
 
1311
1482
  .ee-message-items {
1312
1483
  flex: 1;
1313
1484
  overflow-y: auto;
1485
+ padding-bottom: 88px;
1314
1486
  }
1315
1487
 
1316
1488
  .ee-compose-button {
1317
1489
  position: fixed;
1318
1490
  bottom: 20px;
1319
1491
  right: 20px;
1320
- width: 56px;
1321
- height: 56px;
1492
+ display: inline-flex;
1493
+ align-items: center;
1494
+ gap: 10px;
1495
+ height: 52px;
1496
+ padding: 0 22px 0 18px;
1322
1497
  background: #007bff;
1323
1498
  border: none;
1324
- border-radius: 50%;
1499
+ border-radius: 16px;
1325
1500
  color: white;
1326
- font-size: 24px;
1501
+ font-family: var(--ee-font, inherit);
1502
+ font-size: 15px;
1503
+ font-weight: 600;
1327
1504
  cursor: pointer;
1328
1505
  box-shadow: 0 4px 12px rgba(0,123,255,0.3);
1329
1506
  z-index: 1000;
1330
- transition: all 0.2s ease;
1507
+ transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
1331
1508
  }
1332
1509
 
1333
1510
  .ee-compose-button:hover {
1334
1511
  background: #0056b3;
1335
- transform: scale(1.05);
1512
+ transform: translateY(-1px);
1336
1513
  box-shadow: 0 6px 16px rgba(0,123,255,0.4);
1337
1514
  }
1515
+
1516
+ .ee-compose-button.ee-compose-compact {
1517
+ width: 56px;
1518
+ height: 56px;
1519
+ padding: 0;
1520
+ justify-content: center;
1521
+ border-radius: 50%;
1522
+ }
1523
+
1524
+ .ee-compose-compact .ee-compose-button-label {
1525
+ display: none;
1526
+ }
1527
+
1528
+ /* Medium widths: the viewer is too narrow for labelled buttons, so the
1529
+ toolbar goes icon-only, as webmail toolbars usually are */
1530
+ @container ee-viewer (max-width: 559px) {
1531
+ .ee-message-actions .ee-button:not(.ee-keep-label) .ee-button-label {
1532
+ display: none;
1533
+ }
1534
+
1535
+ .ee-message-actions .ee-button:not(.ee-keep-label) {
1536
+ width: 30px;
1537
+ padding: 0;
1538
+ }
1539
+
1540
+ .ee-message-actions .ee-move-button {
1541
+ width: 44px;
1542
+ gap: 2px;
1543
+ }
1544
+ }
1545
+
1546
+ /* Narrow widths: one pane at a time, in the order a phone mail app uses
1547
+ (folders, list, message), with back buttons in the pane headers. The
1548
+ shown pane follows data-view on .ee-client. */
1549
+ @container ee-client (max-width: ${NARROW_WIDTH - 1}px) {
1550
+ .ee-sidebar,
1551
+ .ee-message-list,
1552
+ .ee-message-viewer {
1553
+ display: none;
1554
+ width: 100%;
1555
+ flex: 1;
1556
+ border-right: 0;
1557
+ }
1558
+
1559
+ .ee-client[data-view="folders"] .ee-sidebar,
1560
+ .ee-client[data-view="list"] .ee-message-list,
1561
+ .ee-client[data-view="message"] .ee-message-viewer {
1562
+ display: flex;
1563
+ }
1564
+
1565
+ .ee-nav-button {
1566
+ display: inline-flex;
1567
+ }
1568
+
1569
+ .ee-message-content {
1570
+ padding: 16px 16px 88px;
1571
+ }
1572
+ }
1338
1573
 
1339
1574
  .ee-compose-modal {
1340
1575
  display: none;
@@ -1515,24 +1750,21 @@ export class EmailEngineClient {
1515
1750
  opacity: 0.6;
1516
1751
  }
1517
1752
 
1518
- /* Dark mode toggle button */
1753
+ /* Dark mode toggle button, in the Folders pane header */
1519
1754
  .ee-dark-mode-toggle {
1520
- position: absolute;
1521
- top: 8px;
1522
- right: 16px;
1523
1755
  background: #f8f9fa;
1524
1756
  border: 1px solid #dee2e6;
1525
- border-radius: 3px;
1526
- padding: 6px 10px;
1527
- font-size: 12px;
1757
+ border-radius: 6px;
1758
+ padding: 0;
1759
+ width: 30px;
1760
+ height: 30px;
1761
+ flex-shrink: 0;
1528
1762
  cursor: pointer;
1529
- z-index: 100;
1530
1763
  transition: all 0.2s ease;
1531
1764
  display: flex;
1532
1765
  align-items: center;
1533
1766
  justify-content: center;
1534
1767
  color: #495057;
1535
- font-weight: 500;
1536
1768
  }
1537
1769
 
1538
1770
  .ee-dark-mode-toggle:hover {
@@ -1645,6 +1877,27 @@ export class EmailEngineClient {
1645
1877
  border-color: #555;
1646
1878
  }
1647
1879
 
1880
+ .ee-dark-mode .ee-button-primary,
1881
+ .ee-dark-mode .ee-button-primary:hover:not(:disabled) {
1882
+ background: #0056b3;
1883
+ border-color: #0056b3;
1884
+ color: white;
1885
+ }
1886
+
1887
+ .ee-dark-mode .ee-button-danger:hover:not(:disabled) {
1888
+ background: #4a2323;
1889
+ border-color: #7a3434;
1890
+ color: #f0a5a5;
1891
+ }
1892
+
1893
+ .ee-dark-mode .ee-message-meta {
1894
+ border-color: #333;
1895
+ }
1896
+
1897
+ .ee-dark-mode .ee-message-meta-label {
1898
+ color: #999;
1899
+ }
1900
+
1648
1901
  .ee-dark-mode .ee-button:disabled {
1649
1902
  background: #222;
1650
1903
  color: #666;
@@ -1662,10 +1915,18 @@ export class EmailEngineClient {
1662
1915
  }
1663
1916
 
1664
1917
  .ee-dark-mode .ee-attachments {
1665
- background: #252525;
1666
1918
  border-color: #333;
1667
1919
  }
1668
1920
 
1921
+ .ee-dark-mode .ee-attachments-title,
1922
+ .ee-dark-mode .ee-attachment-name {
1923
+ color: #e0e0e0;
1924
+ }
1925
+
1926
+ .ee-dark-mode .ee-attachment-size {
1927
+ color: #999;
1928
+ }
1929
+
1669
1930
  .ee-dark-mode .ee-attachment-item {
1670
1931
  background: #2a2a2a;
1671
1932
  border-color: #333;
@@ -1716,19 +1977,30 @@ export class EmailEngineClient {
1716
1977
  border-color: #333;
1717
1978
  }
1718
1979
 
1719
- .ee-dark-mode .ee-compose-button {
1980
+ /* The compose button and modal sit beside .ee-client, not inside it, so
1981
+ setDarkMode puts the ee-dark-mode class on them directly */
1982
+ .ee-compose-button.ee-dark-mode {
1720
1983
  background: #0056b3;
1984
+ color: white;
1721
1985
  }
1722
1986
 
1723
- .ee-dark-mode .ee-compose-modal {
1987
+ .ee-compose-button.ee-dark-mode:hover {
1988
+ background: #004a99;
1989
+ }
1990
+
1991
+ .ee-compose-modal.ee-dark-mode {
1724
1992
  background: rgba(0, 0, 0, 0.7);
1725
1993
  }
1726
1994
 
1727
- .ee-dark-mode .ee-compose-content {
1995
+ .ee-dark-mode .ee-compose-dialog {
1728
1996
  background: #202020;
1729
1997
  color: #e0e0e0;
1730
1998
  }
1731
1999
 
2000
+ .ee-dark-mode .ee-compose-label {
2001
+ color: #ccc;
2002
+ }
2003
+
1732
2004
  .ee-dark-mode .ee-compose-header {
1733
2005
  background: linear-gradient(to bottom, #2a2a2a, #252525);
1734
2006
  border-color: #333;
@@ -1920,41 +2192,39 @@ export class EmailEngineClient {
1920
2192
  }
1921
2193
 
1922
2194
  if (!this.messages.length) {
1923
- messageList.innerHTML = `
1924
- <div class="ee-pane-header">
1925
- <span class="ee-pane-title">Messages</span>
1926
- </div>
1927
- <div class="ee-empty-state">No messages</div>
1928
- `;
2195
+ messageList.innerHTML = `${this._messageListHeader(this.currentFolder)}<div class="ee-empty-state">No messages</div>`;
1929
2196
  return;
1930
2197
  }
1931
2198
 
1932
2199
  const hasPagination = this.nextPageCursor || this.prevPageCursor;
1933
2200
 
1934
- const html = `
1935
- <div class="ee-pane-header">
1936
- <span class="ee-pane-title">Messages</span>
2201
+ // Both arrows stay in place once there is more than one page, the unavailable
2202
+ // one disabled, so the controls do not shift under the pointer between pages
2203
+ const controls = `
1937
2204
  <div class="ee-pagination-controls">
1938
2205
  ${
1939
2206
  hasPagination
1940
2207
  ? `
1941
- ${this.prevPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="prev-page">← Previous</button>` : ''}
1942
- ${this.nextPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="next-page">Next →</button>` : ''}
2208
+ ${this._iconButton('prev-page', 'back', 'Previous page', '', !this.prevPageCursor)}
2209
+ ${this._iconButton('next-page', 'next', 'Next page', '', !this.nextPageCursor)}
1943
2210
  `
1944
2211
  : ''
1945
2212
  }
1946
- <div class="ee-page-size-selector">
1947
- <span class="ee-page-size-label">Show:</span>
1948
- <select class="ee-page-size-select" data-action="page-size">
2213
+ <label class="ee-page-size-selector" title="Messages per page">
2214
+ <span class="ee-page-size-label">Show</span>
2215
+ <select class="ee-button ee-page-size-select" data-action="page-size">
1949
2216
  <option value="10" ${this.pageSize === 10 ? 'selected' : ''}>10</option>
1950
2217
  <option value="20" ${this.pageSize === 20 ? 'selected' : ''}>20</option>
1951
2218
  <option value="30" ${this.pageSize === 30 ? 'selected' : ''}>30</option>
1952
2219
  <option value="50" ${this.pageSize === 50 ? 'selected' : ''}>50</option>
1953
2220
  <option value="100" ${this.pageSize === 100 ? 'selected' : ''}>100</option>
1954
2221
  </select>
1955
- </div>
2222
+ </label>
1956
2223
  </div>
1957
- </div>
2224
+ `;
2225
+
2226
+ const html = `
2227
+ ${this._messageListHeader(this.currentFolder, controls)}
1958
2228
  <div class="ee-message-items">
1959
2229
  ${this.messages
1960
2230
  .map(
@@ -2020,57 +2290,68 @@ export class EmailEngineClient {
2020
2290
  }
2021
2291
 
2022
2292
  if (!this.currentMessage) {
2023
- viewer.innerHTML = '<div class="ee-empty-state">Select a message to view</div>';
2293
+ viewer.innerHTML = this._messageViewerPlaceholder();
2294
+ // Nothing left to show in the single-pane layout (the message was deleted
2295
+ // or moved), so return to the list it came from
2296
+ if (this._getView() === 'message') {
2297
+ this._setView('list');
2298
+ }
2024
2299
  return;
2025
2300
  }
2026
2301
 
2027
2302
  const msg = this.currentMessage;
2028
2303
  const isUnseen = msg.unseen;
2029
2304
  const isDraft = this._isDraftMessage(msg);
2305
+ // Labels drop to icons when the viewer is narrow (see the ee-viewer container
2306
+ // query); aria-label and title carry the full name either way. The move control
2307
+ // is a native select laid invisibly over a button so it looks like the rest of
2308
+ // the toolbar while keeping the platform's own folder picker.
2309
+ const actions = `
2310
+ ${isDraft ? this._toolbarButton('send-draft', 'send', 'Send draft', 'Send this draft now', 'ee-button-primary ee-keep-label') : ''}
2311
+ ${this._toolbarButton('toggle-read', isUnseen ? 'mailOpen' : 'mail', isUnseen ? 'Mark read' : 'Mark unread', isUnseen ? 'Mark as read' : 'Mark as unread')}
2312
+ <span class="ee-button ee-move-button" title="Move to folder">
2313
+ ${icon('move')}<span class="ee-button-label">Move</span>${icon('chevronDown', 12)}
2314
+ <select class="ee-move-select" data-action="move" aria-label="Move to folder">
2315
+ <option value="">Move to...</option>
2316
+ ${this.buildFolderTree()
2317
+ .map(({ folder, depth }) => {
2318
+ const indent = ' '.repeat(depth);
2319
+ const prefix = depth > 0 ? '└ ' : '';
2320
+ return `<option value="${this.escapeHtml(folder.path)}" ${folder.path === this.currentFolder ? 'disabled' : ''}>${indent}${prefix}${this.escapeHtml(folder.name)}</option>`;
2321
+ })
2322
+ .join('')}
2323
+ </select>
2324
+ </span>
2325
+ ${this._toolbarButton('delete', 'trash', 'Delete', 'Delete', 'ee-button-danger')}
2326
+ <span class="ee-toolbar-spacer"></span>
2327
+ ${this._toolbarButton('download-original', 'download', 'Download', 'Download the original message (.eml)')}
2328
+ `;
2030
2329
  const html = `
2031
- <div class="ee-message-actions">
2032
- ${isDraft ? '<button class="ee-button" data-action="send-draft">Send Draft</button>' : ''}
2033
- <button class="ee-button" data-action="toggle-read">Mark as ${isUnseen ? 'seen' : 'unseen'}</button>
2034
- <button class="ee-button" data-action="delete">Delete</button>
2035
- <button class="ee-button" data-action="download-original">Download Original</button>
2036
- <select class="ee-button" data-action="move">
2037
- <option value="">Move to...</option>
2038
- ${this.buildFolderTree()
2039
- .map(({ folder, depth }) => {
2040
- const indent = ' '.repeat(depth);
2041
- const prefix = depth > 0 ? '└ ' : '';
2042
- return `<option value="${this.escapeHtml(folder.path)}" ${folder.path === this.currentFolder ? 'disabled' : ''}>${indent}${prefix}${this.escapeHtml(folder.name)}</option>`;
2043
- })
2044
- .join('')}
2045
- </select>
2046
- </div>
2330
+ ${this._messageToolbar(actions)}
2047
2331
  <div class="ee-message-content">
2332
+ <h2 class="ee-message-title">${this.escapeHtml(msg.subject || '(no subject)')}</h2>
2048
2333
  <div class="ee-message-meta">
2049
2334
  <div class="ee-message-meta-row">
2050
- <span class="ee-message-meta-label">From:</span>
2051
- ${msg.from ? `${this.escapeHtml(msg.from.name || '')} &lt;${this.escapeHtml(msg.from.address)}&gt;` : 'Unknown'}
2335
+ <span class="ee-message-meta-label">From</span>
2336
+ <span class="ee-message-meta-value">${msg.from ? `${this.escapeHtml(msg.from.name || '')} &lt;${this.escapeHtml(msg.from.address)}&gt;` : 'Unknown'}</span>
2052
2337
  </div>
2053
2338
  <div class="ee-message-meta-row">
2054
- <span class="ee-message-meta-label">To:</span>
2055
- ${msg.to ? msg.to.map(t => `${this.escapeHtml(t.name || '')} &lt;${this.escapeHtml(t.address)}&gt;`).join(', ') : ''}
2339
+ <span class="ee-message-meta-label">To</span>
2340
+ <span class="ee-message-meta-value">${msg.to ? msg.to.map(t => `${this.escapeHtml(t.name || '')} &lt;${this.escapeHtml(t.address)}&gt;`).join(', ') : ''}</span>
2056
2341
  </div>
2057
2342
  ${
2058
2343
  msg.cc && msg.cc.length
2059
2344
  ? `
2060
2345
  <div class="ee-message-meta-row">
2061
- <span class="ee-message-meta-label">Cc:</span>
2062
- ${msg.cc.map(c => `${this.escapeHtml(c.name || '')} &lt;${this.escapeHtml(c.address)}&gt;`).join(', ')}
2346
+ <span class="ee-message-meta-label">Cc</span>
2347
+ <span class="ee-message-meta-value">${msg.cc.map(c => `${this.escapeHtml(c.name || '')} &lt;${this.escapeHtml(c.address)}&gt;`).join(', ')}</span>
2063
2348
  </div>
2064
2349
  `
2065
2350
  : ''
2066
2351
  }
2067
2352
  <div class="ee-message-meta-row">
2068
- <span class="ee-message-meta-label">Date:</span>
2069
- ${new Date(msg.date).toLocaleString()}
2070
- </div>
2071
- <div class="ee-message-meta-row">
2072
- <span class="ee-message-meta-label">Subject:</span>
2073
- ${this.escapeHtml(msg.subject || '(no subject)')}
2353
+ <span class="ee-message-meta-label">Date</span>
2354
+ <span class="ee-message-meta-value">${this.escapeHtml(new Date(msg.date).toLocaleString())}</span>
2074
2355
  </div>
2075
2356
  </div>
2076
2357
  ${this.renderOtpBox(msg.otp)}
@@ -2117,9 +2398,11 @@ export class EmailEngineClient {
2117
2398
  return;
2118
2399
  }
2119
2400
 
2120
- const originalText = sendDraftButton.textContent;
2401
+ // Only the label changes, the icon stays
2402
+ const label = sendDraftButton.querySelector('.ee-button-label');
2403
+ const originalText = label.textContent;
2121
2404
  sendDraftButton.disabled = true;
2122
- sendDraftButton.textContent = 'Sending...';
2405
+ label.textContent = 'Sending...';
2123
2406
 
2124
2407
  try {
2125
2408
  await this.submitDraft(msg.id);
@@ -2134,7 +2417,7 @@ export class EmailEngineClient {
2134
2417
  const errorMessage = this._formatSendError(error);
2135
2418
  await this.alertMethod(errorMessage, 'Send Error', null, 'OK');
2136
2419
  sendDraftButton.disabled = false;
2137
- sendDraftButton.textContent = originalText;
2420
+ label.textContent = originalText;
2138
2421
  }
2139
2422
  });
2140
2423
  }
@@ -2199,6 +2482,16 @@ export class EmailEngineClient {
2199
2482
  // Message content scrolling is now handled in loadMessage method
2200
2483
  }
2201
2484
 
2485
+ // An icon-only button. Static arguments only, never message data.
2486
+ _iconButton(action, iconName, label, extraClass = '', disabled = false) {
2487
+ return `<button type="button" class="ee-button ee-icon-button ${extraClass}" data-action="${action}" aria-label="${label}" title="${label}"${disabled ? ' disabled' : ''}>${icon(iconName)}</button>`;
2488
+ }
2489
+
2490
+ // A message toolbar button. Static arguments only, never message data.
2491
+ _toolbarButton(action, iconName, label, title, extraClass = '') {
2492
+ return `<button type="button" class="ee-button ${extraClass}" data-action="${action}" aria-label="${label}" title="${title}">${icon(iconName)}<span class="ee-button-label">${label}</span></button>`;
2493
+ }
2494
+
2202
2495
  // The message body goes into a shadow root on its container. Sanitised message HTML still
2203
2496
  // carries class and id attributes, and in the host document those would pick up the host's
2204
2497
  // own stylesheet (a utility class like "fixed inset-0" could cover the whole page) or collide
@@ -2248,27 +2541,25 @@ export class EmailEngineClient {
2248
2541
  }
2249
2542
 
2250
2543
  this.container.innerHTML = `
2251
- <div class="ee-client${this.darkMode ? ' ee-dark-mode' : ''}">
2252
- ${
2253
- this.showDarkModeToggle
2254
- ? `<button class="ee-dark-mode-toggle" title="Toggle dark mode">
2255
- <span class="ee-dark-mode-icon">${this.darkMode ? '☀️' : '🌙'}</span>
2256
- </button>`
2257
- : ''
2258
- }
2544
+ <div class="ee-client${this.darkMode ? ' ee-dark-mode' : ''}" data-view="list">
2259
2545
  <div class="ee-sidebar">
2260
2546
  <div class="ee-pane-header">
2261
2547
  <span class="ee-pane-title">Folders</span>
2548
+ ${
2549
+ this.showDarkModeToggle
2550
+ ? `<button type="button" class="ee-dark-mode-toggle" title="Toggle dark mode" aria-label="Toggle dark mode">
2551
+ <span class="ee-dark-mode-icon">${this.darkMode ? '☀️' : '🌙'}</span>
2552
+ </button>`
2553
+ : ''
2554
+ }
2262
2555
  </div>
2263
2556
  <div class="ee-folder-tree"></div>
2264
2557
  </div>
2265
2558
  <div class="ee-message-list">${this._messageListPlaceholder()}</div>
2266
- <div class="ee-message-viewer">
2267
- <div class="ee-empty-state">Select a message to view</div>
2268
- </div>
2559
+ <div class="ee-message-viewer">${this._messageViewerPlaceholder()}</div>
2269
2560
  </div>
2270
- <button class="ee-compose-button" title="Compose Email">✉</button>
2271
- <div class="ee-compose-modal">
2561
+ <button type="button" class="ee-compose-button${this.darkMode ? ' ee-dark-mode' : ''}" title="Compose email" aria-label="Compose">${icon('compose', 22)}<span class="ee-compose-button-label">Compose</span></button>
2562
+ <div class="ee-compose-modal${this.darkMode ? ' ee-dark-mode' : ''}">
2272
2563
  <div class="ee-compose-dialog">
2273
2564
  <div class="ee-compose-header">
2274
2565
  <h3 class="ee-compose-title">Compose Email</h3>
@@ -2297,6 +2588,15 @@ export class EmailEngineClient {
2297
2588
  </div>
2298
2589
  `;
2299
2590
 
2591
+ // Pane navigation in the single-pane layout, delegated because the panes
2592
+ // re-render their headers on every load
2593
+ this.container.querySelector('.ee-client').addEventListener('click', e => {
2594
+ const nav = e.target.closest('[data-action="show-folders"], [data-action="back-to-list"]');
2595
+ if (nav) {
2596
+ this._setView(nav.dataset.action === 'show-folders' ? 'folders' : 'list');
2597
+ }
2598
+ });
2599
+
2300
2600
  // Wire up compose modal events
2301
2601
  this.setupComposeModal();
2302
2602
 
@@ -2458,7 +2758,6 @@ export class EmailEngineClient {
2458
2758
 
2459
2759
  const updateButtonPosition = () => {
2460
2760
  const containerRect = this.container.getBoundingClientRect();
2461
- const buttonSize = 56; // Button width/height
2462
2761
  const margin = 20; // Desired margin from edges
2463
2762
 
2464
2763
  // A hidden container (display: none) reports a zero-size rect; positioning
@@ -2472,6 +2771,11 @@ export class EmailEngineClient {
2472
2771
  }
2473
2772
  composeButton.style.display = '';
2474
2773
 
2774
+ // A labelled pill on roomy layouts, a round icon button where width is
2775
+ // short and the button would cover too much of the single pane
2776
+ composeButton.classList.toggle('ee-compose-compact', containerRect.width < NARROW_WIDTH);
2777
+ const buttonSize = composeButton.offsetWidth || 56;
2778
+
2475
2779
  // Calculate the ideal position (bottom-right of container with margin)
2476
2780
  const idealBottom = window.innerHeight - containerRect.bottom + margin;
2477
2781
  const idealRight = window.innerWidth - containerRect.right + margin;
@@ -2634,15 +2938,9 @@ export class EmailEngineClient {
2634
2938
  return;
2635
2939
  }
2636
2940
 
2637
- // Update UI
2638
- const client = this.container.querySelector('.ee-client');
2639
- if (client) {
2640
- if (this.darkMode) {
2641
- client.classList.add('ee-dark-mode');
2642
- } else {
2643
- client.classList.remove('ee-dark-mode');
2644
- }
2645
- }
2941
+ // Update UI. The compose button and modal are siblings of .ee-client, so
2942
+ // they carry the class themselves.
2943
+ this.container.querySelectorAll('.ee-client, .ee-compose-button, .ee-compose-modal').forEach(el => el.classList.toggle('ee-dark-mode', this.darkMode));
2646
2944
 
2647
2945
  // Update toggle button icon
2648
2946
  const icon = this.container.querySelector('.ee-dark-mode-icon');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postalsys/ee-client",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "EmailEngine client library for browser and Node.js applications",
5
5
  "main": "index.js",
6
6
  "module": "index.js",