@postalsys/ee-client 1.4.0 → 1.5.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.
package/README.md CHANGED
@@ -115,15 +115,17 @@ EmailEngine can also mint short-lived, session-bound tokens whose value starts w
115
115
  new EmailEngineClient(options);
116
116
  ```
117
117
 
118
- | Option | Type | Default | Description |
119
- | --------------- | ------------- | ----------------------- | ------------------------------------------------------------------------------------------------------- |
120
- | `account` | `string` | (required) | EmailEngine account identifier. |
121
- | `apiUrl` | `string` | `http://127.0.0.1:3000` | Base URL of your EmailEngine instance. |
122
- | `accessToken` | `string` | - | Bearer token for API authentication. |
123
- | `container` | `HTMLElement` | - | DOM element to render the webmail UI into. Omit for API-only use. |
124
- | `pageSize` | `number` | `20` | Messages per page. A saved value in `localStorage` takes precedence. |
125
- | `confirmMethod` | `function` | browser `confirm()` | Custom confirm dialog, `(message, title, cancelText, okText)`. May be sync or async; returns a boolean. |
126
- | `alertMethod` | `function` | browser `alert()` | Custom alert dialog, `(message, title, cancelText, okText)` where `cancelText` is `null`. |
118
+ | Option | Type | Default | Description |
119
+ | -------------------- | ------------- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
120
+ | `account` | `string` | (required) | EmailEngine account identifier. |
121
+ | `apiUrl` | `string` | `http://127.0.0.1:3000` | Base URL of your EmailEngine instance. |
122
+ | `accessToken` | `string` | - | Bearer token for API authentication. |
123
+ | `container` | `HTMLElement` | - | DOM element to render the webmail UI into. Omit for API-only use. |
124
+ | `pageSize` | `number` | `20` | Messages per page. A saved value in `localStorage` takes precedence. |
125
+ | `confirmMethod` | `function` | browser `confirm()` | Custom confirm dialog, `(message, title, cancelText, okText)`. May be sync or async; returns a boolean. |
126
+ | `alertMethod` | `function` | browser `alert()` | Custom alert dialog, `(message, title, cancelText, okText)` where `cancelText` is `null`. |
127
+ | `darkMode` | `boolean` | stored preference | Initial dark mode. Overrides the preference stored by the builtin toggle. |
128
+ | `showDarkModeToggle` | `boolean` | `true` | Render the builtin dark mode toggle. Set `false` when the host application drives the mode through `client.setDarkMode(enabled)` (for example in sync with its own theme switch). |
127
129
 
128
130
  UI rendering, the compose modal, and dark mode only activate when a `container` is supplied. In a non-browser environment the UI is skipped and the instance behaves as a plain API client.
129
131
 
@@ -187,6 +189,10 @@ Browser only. Fetch an attachment and trigger a download, using the filename fro
187
189
 
188
190
  Browser only. Download the raw message source as an `.eml` file.
189
191
 
192
+ ### `setDarkMode(enabled: boolean): void`
193
+
194
+ Set dark mode from the host application without touching the preference stored by the builtin toggle. Combine with `showDarkModeToggle: false` to keep the rendered UI in sync with the host page's own theme switch.
195
+
190
196
  ### `destroy(): void`
191
197
 
192
198
  Clean up the instance and clear the `sess_` token keep-alive interval. Always call this when you are finished with a client (for example when unmounting the UI) to avoid a leaked timer.
package/index.d.ts CHANGED
@@ -80,6 +80,10 @@ export interface EmailEngineClientOptions {
80
80
  pageSize?: number;
81
81
  confirmMethod?: DialogMethod;
82
82
  alertMethod?: DialogMethod;
83
+ /** Initial dark mode; overrides the preference stored by the builtin toggle */
84
+ darkMode?: boolean;
85
+ /** Render the builtin dark mode toggle button (default true); set false when the host drives the mode through setDarkMode() */
86
+ showDarkModeToggle?: boolean;
83
87
  }
84
88
 
85
89
  export declare class EmailEngineClient {
@@ -91,6 +95,7 @@ export declare class EmailEngineClient {
91
95
  alertMethod: DialogMethod;
92
96
  pageSize: number;
93
97
  darkMode: boolean;
98
+ showDarkModeToggle: boolean;
94
99
  currentFolder: string | null;
95
100
  currentMessage: Message | null;
96
101
  folders: Folder[];
@@ -120,6 +125,7 @@ export declare class EmailEngineClient {
120
125
  renderMessage(): void;
121
126
  createLayout(): void;
122
127
  init(): void;
128
+ setDarkMode(enabled: boolean): void;
123
129
  toggleDarkMode(): void;
124
130
  destroy(): void;
125
131
  }
package/index.js CHANGED
@@ -39,11 +39,18 @@ export class EmailEngineClient {
39
39
  this.keepAliveTimer = null;
40
40
  this.lastActivity = Date.now();
41
41
 
42
- // Dark mode state
42
+ // Dark mode state. An explicit darkMode option overrides the stored
43
+ // preference - for hosts that manage the theme themselves (usually
44
+ // together with showDarkModeToggle: false to hide the builtin button
45
+ // and drive the mode through setDarkMode()).
43
46
  this.darkMode = false;
44
47
  if (typeof window !== 'undefined' && window.localStorage) {
45
48
  this.darkMode = localStorage.getItem('ee-client-dark-mode') === 'true';
46
49
  }
50
+ if (typeof options.darkMode === 'boolean') {
51
+ this.darkMode = options.darkMode;
52
+ }
53
+ this.showDarkModeToggle = options.showDarkModeToggle !== false;
47
54
 
48
55
  // Get page size from localStorage or options or default
49
56
  const savedPageSize =
@@ -1650,9 +1657,13 @@ export class EmailEngineClient {
1650
1657
 
1651
1658
  this.container.innerHTML = `
1652
1659
  <div class="ee-client${this.darkMode ? ' ee-dark-mode' : ''}">
1653
- <button class="ee-dark-mode-toggle" title="Toggle dark mode">
1660
+ ${
1661
+ this.showDarkModeToggle
1662
+ ? `<button class="ee-dark-mode-toggle" title="Toggle dark mode">
1654
1663
  <span class="ee-dark-mode-icon">${this.darkMode ? '☀️' : '🌙'}</span>
1655
- </button>
1664
+ </button>`
1665
+ : ''
1666
+ }
1656
1667
  <div class="ee-sidebar">
1657
1668
  <div class="ee-pane-header">
1658
1669
  <span class="ee-pane-title">Folders</span>
@@ -1944,13 +1955,10 @@ export class EmailEngineClient {
1944
1955
  }
1945
1956
  }
1946
1957
 
1947
- toggleDarkMode() {
1948
- this.darkMode = !this.darkMode;
1949
-
1950
- // Save preference
1951
- if (typeof window !== 'undefined' && window.localStorage) {
1952
- localStorage.setItem('ee-client-dark-mode', this.darkMode.toString());
1953
- }
1958
+ // Set dark mode from the host application (does not touch the stored
1959
+ // preference - the builtin toggle owns that)
1960
+ setDarkMode(enabled) {
1961
+ this.darkMode = !!enabled;
1954
1962
 
1955
1963
  // DOM updates only apply to the rendered UI; skip without a container
1956
1964
  if (!this.container) {
@@ -1974,6 +1982,15 @@ export class EmailEngineClient {
1974
1982
  }
1975
1983
  }
1976
1984
 
1985
+ toggleDarkMode() {
1986
+ this.setDarkMode(!this.darkMode);
1987
+
1988
+ // Save preference
1989
+ if (typeof window !== 'undefined' && window.localStorage) {
1990
+ localStorage.setItem('ee-client-dark-mode', this.darkMode.toString());
1991
+ }
1992
+ }
1993
+
1977
1994
  destroy() {
1978
1995
  // Mark destroyed first so any in-flight async completion skips
1979
1996
  // re-rendering into a torn-down or recreated container.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postalsys/ee-client",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "EmailEngine client library for browser and Node.js applications",
5
5
  "main": "index.js",
6
6
  "module": "index.js",