@postalsys/ee-client 1.2.1 → 1.3.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 (3) hide show
  1. package/README.md +11 -0
  2. package/index.js +265 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -111,6 +111,7 @@ When used in a browser with a container element, the client automatically create
111
111
  - Message list with pagination
112
112
  - Message viewer with actions (mark as read/unread, delete, move)
113
113
  - Responsive design
114
+ - Dark mode support with persistent preference
114
115
 
115
116
  ```html
116
117
  <div id="email-client" style="height: 600px;"></div>
@@ -184,6 +185,16 @@ The library uses contextually appropriate titles and button texts:
184
185
 
185
186
  Both methods can be synchronous or asynchronous and should return a boolean for confirm dialogs.
186
187
 
188
+ ### Dark Mode
189
+
190
+ The email client includes built-in dark mode support with automatic persistence of user preference:
191
+
192
+ - **Toggle Button**: A moon/sun icon in the top-right corner toggles between light and dark modes
193
+ - **Persistent Preference**: Dark mode preference is saved to localStorage and restored on page reload
194
+ - **Complete Theme**: All UI components are styled for optimal readability in both light and dark modes
195
+
196
+ Dark mode is automatically initialized based on the saved preference when the client is created.
197
+
187
198
  ## License
188
199
 
189
200
  MIT © Postal Systems OÜ
package/index.js CHANGED
@@ -21,6 +21,12 @@ export class EmailEngineClient {
21
21
  this.keepAliveTimer = null;
22
22
  this.lastActivity = Date.now();
23
23
 
24
+ // Dark mode state
25
+ this.darkMode = false;
26
+ if (typeof window !== 'undefined' && window.localStorage) {
27
+ this.darkMode = localStorage.getItem('ee-client-dark-mode') === 'true';
28
+ }
29
+
24
30
  // Get page size from localStorage or options or default
25
31
  const savedPageSize =
26
32
  typeof window !== 'undefined' && window.localStorage ? localStorage.getItem('ee-client-page-size') : null;
@@ -177,6 +183,15 @@ export class EmailEngineClient {
177
183
 
178
184
  if (this.container) {
179
185
  this.renderMessage();
186
+
187
+ // Scroll to top of the email client container
188
+ this.container.scrollIntoView({ behavior: 'smooth', block: 'start' });
189
+
190
+ // Also scroll the window to ensure visibility
191
+ if (typeof window !== 'undefined') {
192
+ const containerTop = this.container.getBoundingClientRect().top + window.pageYOffset;
193
+ window.scrollTo({ top: containerTop, behavior: 'smooth' });
194
+ }
180
195
  }
181
196
 
182
197
  return this.currentMessage;
@@ -1035,6 +1050,219 @@ export class EmailEngineClient {
1035
1050
  .ee-compose-cancel:hover {
1036
1051
  background: #545b62;
1037
1052
  }
1053
+
1054
+ /* Dark mode toggle button */
1055
+ .ee-dark-mode-toggle {
1056
+ position: absolute;
1057
+ top: 8px;
1058
+ right: 16px;
1059
+ background: #f8f9fa;
1060
+ border: 1px solid #dee2e6;
1061
+ border-radius: 3px;
1062
+ padding: 6px 10px;
1063
+ font-size: 12px;
1064
+ cursor: pointer;
1065
+ z-index: 100;
1066
+ transition: all 0.2s ease;
1067
+ display: flex;
1068
+ align-items: center;
1069
+ justify-content: center;
1070
+ color: #495057;
1071
+ font-weight: 500;
1072
+ }
1073
+
1074
+ .ee-dark-mode-toggle:hover {
1075
+ background: #e9ecef;
1076
+ border-color: #adb5bd;
1077
+ }
1078
+
1079
+ .ee-dark-mode-icon {
1080
+ font-size: 14px;
1081
+ line-height: 1;
1082
+ }
1083
+
1084
+ /* Dark mode styles */
1085
+ .ee-dark-mode {
1086
+ background: #1a1a1a;
1087
+ color: #e0e0e0;
1088
+ }
1089
+
1090
+ .ee-dark-mode .ee-dark-mode-toggle {
1091
+ background: #333;
1092
+ border-color: #444;
1093
+ color: #e0e0e0;
1094
+ }
1095
+
1096
+ .ee-dark-mode .ee-dark-mode-toggle:hover {
1097
+ background: #444;
1098
+ border-color: #555;
1099
+ }
1100
+
1101
+ .ee-dark-mode .ee-sidebar {
1102
+ background: #202020;
1103
+ border-color: #333;
1104
+ }
1105
+
1106
+ .ee-dark-mode .ee-folder-item {
1107
+ border-color: #333;
1108
+ }
1109
+
1110
+ .ee-dark-mode .ee-folder-item:hover {
1111
+ background: #2a2a2a;
1112
+ }
1113
+
1114
+ .ee-dark-mode .ee-folder-item.active {
1115
+ background: #0056b3;
1116
+ }
1117
+
1118
+ .ee-dark-mode .ee-message-list {
1119
+ background: #202020;
1120
+ border-color: #333;
1121
+ }
1122
+
1123
+ .ee-dark-mode .ee-message-item {
1124
+ border-color: #333;
1125
+ }
1126
+
1127
+ .ee-dark-mode .ee-message-item:hover {
1128
+ background: #2a2a2a;
1129
+ }
1130
+
1131
+ .ee-dark-mode .ee-message-item.active {
1132
+ background: #1a3d5c;
1133
+ }
1134
+
1135
+ .ee-dark-mode .ee-message-date,
1136
+ .ee-dark-mode .ee-message-preview,
1137
+ .ee-dark-mode .ee-attachment-indicator {
1138
+ color: #999;
1139
+ }
1140
+
1141
+ .ee-dark-mode .ee-pane-header {
1142
+ background: linear-gradient(to bottom, #2a2a2a, #252525);
1143
+ border-color: #333;
1144
+ color: #e0e0e0;
1145
+ }
1146
+
1147
+ .ee-dark-mode .ee-pane-title {
1148
+ color: #e0e0e0;
1149
+ }
1150
+
1151
+ .ee-dark-mode .ee-page-size-label {
1152
+ color: #e0e0e0;
1153
+ }
1154
+
1155
+ .ee-dark-mode .ee-message-viewer {
1156
+ background: #1a1a1a;
1157
+ }
1158
+
1159
+ .ee-dark-mode .ee-message-actions {
1160
+ background: linear-gradient(to bottom, #2a2a2a, #252525);
1161
+ border-color: #333;
1162
+ }
1163
+
1164
+ .ee-dark-mode .ee-button {
1165
+ background: #333;
1166
+ border-color: #444;
1167
+ color: #e0e0e0;
1168
+ }
1169
+
1170
+ .ee-dark-mode .ee-button:hover {
1171
+ background: #444;
1172
+ border-color: #555;
1173
+ }
1174
+
1175
+ .ee-dark-mode .ee-button:disabled {
1176
+ background: #222;
1177
+ color: #666;
1178
+ }
1179
+
1180
+ .ee-dark-mode select {
1181
+ background: #2a2a2a;
1182
+ border-color: #444;
1183
+ color: #e0e0e0;
1184
+ }
1185
+
1186
+ .ee-dark-mode .ee-message-content {
1187
+ background: #1a1a1a;
1188
+ color: #e0e0e0;
1189
+ }
1190
+
1191
+ .ee-dark-mode .ee-attachments {
1192
+ background: #252525;
1193
+ border-color: #333;
1194
+ }
1195
+
1196
+ .ee-dark-mode .ee-attachment-item {
1197
+ background: #2a2a2a;
1198
+ border-color: #333;
1199
+ }
1200
+
1201
+ .ee-dark-mode .ee-attachment-item:hover {
1202
+ background: #333;
1203
+ }
1204
+
1205
+ .ee-dark-mode .ee-loading,
1206
+ .ee-dark-mode .ee-empty-state,
1207
+ .ee-dark-mode .ee-error {
1208
+ color: #999;
1209
+ }
1210
+
1211
+ .ee-dark-mode .ee-pagination {
1212
+ background: #252525;
1213
+ border-color: #333;
1214
+ }
1215
+
1216
+ .ee-dark-mode .ee-compose-button {
1217
+ background: #0056b3;
1218
+ }
1219
+
1220
+ .ee-dark-mode .ee-compose-modal {
1221
+ background: rgba(0, 0, 0, 0.7);
1222
+ }
1223
+
1224
+ .ee-dark-mode .ee-compose-content {
1225
+ background: #202020;
1226
+ color: #e0e0e0;
1227
+ }
1228
+
1229
+ .ee-dark-mode .ee-compose-header {
1230
+ background: linear-gradient(to bottom, #2a2a2a, #252525);
1231
+ border-color: #333;
1232
+ }
1233
+
1234
+ .ee-dark-mode .ee-compose-close {
1235
+ color: #999;
1236
+ }
1237
+
1238
+ .ee-dark-mode .ee-compose-close:hover {
1239
+ color: #fff;
1240
+ }
1241
+
1242
+ .ee-dark-mode .ee-compose-input,
1243
+ .ee-dark-mode .ee-compose-textarea {
1244
+ background: #1a1a1a;
1245
+ border-color: #444;
1246
+ color: #e0e0e0;
1247
+ }
1248
+
1249
+ .ee-dark-mode .ee-compose-input:focus,
1250
+ .ee-dark-mode .ee-compose-textarea:focus {
1251
+ border-color: #0056b3;
1252
+ box-shadow: 0 0 0 2px rgba(0,86,179,0.2);
1253
+ }
1254
+
1255
+ .ee-dark-mode .ee-compose-actions {
1256
+ border-color: #333;
1257
+ }
1258
+
1259
+ .ee-dark-mode .ee-compose-cancel {
1260
+ background: #444;
1261
+ }
1262
+
1263
+ .ee-dark-mode .ee-compose-cancel:hover {
1264
+ background: #555;
1265
+ }
1038
1266
  `;
1039
1267
  document.head.appendChild(style);
1040
1268
  }
@@ -1381,11 +1609,7 @@ export class EmailEngineClient {
1381
1609
  });
1382
1610
  });
1383
1611
 
1384
- // Scroll message viewer back to top when new email is displayed
1385
- const messageContent = viewer.querySelector('.ee-message-content');
1386
- if (messageContent) {
1387
- messageContent.scrollTop = 0;
1388
- }
1612
+ // Message content scrolling is now handled in loadMessage method
1389
1613
  }
1390
1614
 
1391
1615
  createLayout() {
@@ -1394,7 +1618,10 @@ export class EmailEngineClient {
1394
1618
  }
1395
1619
 
1396
1620
  this.container.innerHTML = `
1397
- <div class="ee-client">
1621
+ <div class="ee-client${this.darkMode ? ' ee-dark-mode' : ''}">
1622
+ <button class="ee-dark-mode-toggle" title="Toggle dark mode">
1623
+ <span class="ee-dark-mode-icon">${this.darkMode ? '☀️' : '🌙'}</span>
1624
+ </button>
1398
1625
  <div class="ee-sidebar">
1399
1626
  <div class="ee-pane-header">
1400
1627
  <span class="ee-pane-title">Folders</span>
@@ -1626,6 +1853,13 @@ export class EmailEngineClient {
1626
1853
 
1627
1854
  this.createStyles();
1628
1855
  this.createLayout();
1856
+
1857
+ // Set up dark mode toggle
1858
+ const toggleBtn = this.container.querySelector('.ee-dark-mode-toggle');
1859
+ if (toggleBtn) {
1860
+ toggleBtn.addEventListener('click', () => this.toggleDarkMode());
1861
+ }
1862
+
1629
1863
  this.loadFolders()
1630
1864
  .then(() => {
1631
1865
  const inbox =
@@ -1678,6 +1912,31 @@ export class EmailEngineClient {
1678
1912
  }
1679
1913
  }
1680
1914
 
1915
+ toggleDarkMode() {
1916
+ this.darkMode = !this.darkMode;
1917
+
1918
+ // Save preference
1919
+ if (typeof window !== 'undefined' && window.localStorage) {
1920
+ localStorage.setItem('ee-client-dark-mode', this.darkMode.toString());
1921
+ }
1922
+
1923
+ // Update UI
1924
+ const client = this.container.querySelector('.ee-client');
1925
+ if (client) {
1926
+ if (this.darkMode) {
1927
+ client.classList.add('ee-dark-mode');
1928
+ } else {
1929
+ client.classList.remove('ee-dark-mode');
1930
+ }
1931
+ }
1932
+
1933
+ // Update toggle button icon
1934
+ const icon = this.container.querySelector('.ee-dark-mode-icon');
1935
+ if (icon) {
1936
+ icon.textContent = this.darkMode ? '☀️' : '🌙';
1937
+ }
1938
+ }
1939
+
1681
1940
  destroy() {
1682
1941
  // Clean up keep-alive timer
1683
1942
  if (this.keepAliveTimer) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postalsys/ee-client",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "EmailEngine client library for browser and Node.js applications",
5
5
  "main": "index.js",
6
6
  "module": "index.js",