emailengine-app 2.76.0 → 2.77.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 (102) hide show
  1. package/.github/workflows/release.yaml +24 -19
  2. package/.ncurc.js +14 -2
  3. package/.release-please-manifest.json +3 -0
  4. package/CHANGELOG.md +23 -0
  5. package/README.md +1 -1
  6. package/data/google-crawlers.json +1 -1
  7. package/encrypt.js +71 -4
  8. package/lib/address-strategies.js +18 -0
  9. package/lib/api-reference/code-samples.js +194 -0
  10. package/lib/api-reference/format.js +179 -0
  11. package/lib/api-reference/index.js +205 -0
  12. package/lib/api-reference/model.js +336 -0
  13. package/lib/api-reference/schema-tree.js +366 -0
  14. package/lib/api-routes/account-routes.js +117 -37
  15. package/lib/api-routes/behavior-notes.js +54 -0
  16. package/lib/api-routes/blocklist-routes.js +9 -9
  17. package/lib/api-routes/changes-routes.js +6 -4
  18. package/lib/api-routes/chat-routes.js +3 -3
  19. package/lib/api-routes/delivery-test-routes.js +24 -6
  20. package/lib/api-routes/export-routes.js +14 -12
  21. package/lib/api-routes/gateway-routes.js +11 -11
  22. package/lib/api-routes/license-routes.js +7 -7
  23. package/lib/api-routes/mailbox-routes.js +18 -9
  24. package/lib/api-routes/message-routes.js +55 -35
  25. package/lib/api-routes/oauth2-app-routes.js +22 -16
  26. package/lib/api-routes/outbox-routes.js +7 -7
  27. package/lib/api-routes/pubsub-routes.js +3 -3
  28. package/lib/api-routes/settings-routes.js +10 -9
  29. package/lib/api-routes/stats-routes.js +3 -3
  30. package/lib/api-routes/submit-routes.js +58 -8
  31. package/lib/api-routes/template-routes.js +13 -13
  32. package/lib/api-routes/token-routes.js +15 -10
  33. package/lib/api-routes/webhook-route-routes.js +5 -5
  34. package/lib/consts.js +7 -0
  35. package/lib/email-client/base-client.js +66 -12
  36. package/lib/enum-descriptions.js +130 -0
  37. package/lib/imapproxy/imap-server.js +30 -26
  38. package/lib/imapproxy/upstream-client.js +38 -0
  39. package/lib/oauth2-apps.js +9 -3
  40. package/lib/openapi/build-document.js +318 -0
  41. package/lib/openapi/index.js +95 -0
  42. package/lib/openapi/joi-schema.js +523 -0
  43. package/lib/routes-ui.js +5 -1
  44. package/lib/schemas.js +76 -17
  45. package/lib/swagger-options.js +173 -0
  46. package/lib/tokens.js +69 -5
  47. package/lib/ui-routes/admin-entities-routes.js +3 -0
  48. package/lib/ui-routes/dashboard-routes.js +2 -26
  49. package/lib/ui-routes/reference-routes.js +195 -0
  50. package/lib/ui-routes/route-helpers.js +11 -0
  51. package/package.json +9 -11
  52. package/prepare-bundle-deps.sh +28 -0
  53. package/release-please-config.json +11 -0
  54. package/sbom.json +0 -1
  55. package/server.js +10 -2
  56. package/static/css/flyonui.css +1 -1
  57. package/static/css/src/app.tailwind.css +90 -0
  58. package/static/js/ee-client.js +238 -8
  59. package/static/js/reference.js +736 -0
  60. package/static/js/ui.js +61 -33
  61. package/static/licenses.html +4 -4
  62. package/translations/messages.pot +27 -27
  63. package/views/config/ai.hbs +1 -1
  64. package/views/config/document-store/chat.hbs +5 -5
  65. package/views/config/document-store/index.hbs +2 -2
  66. package/views/config/document-store/pre-processing/index.hbs +1 -1
  67. package/views/config/email-processing.hbs +1 -1
  68. package/views/config/imap-proxy.hbs +1 -1
  69. package/views/config/license.hbs +1 -1
  70. package/views/config/oauth/index.hbs +3 -3
  71. package/views/config/security.hbs +1 -1
  72. package/views/config/smtp.hbs +2 -2
  73. package/views/dashboard.hbs +1 -1
  74. package/views/layout/app.hbs +18 -7
  75. package/views/partials/oauth_form.hbs +4 -4
  76. package/views/partials/reference/anchor-link.hbs +20 -0
  77. package/views/partials/reference/disclosure.hbs +37 -0
  78. package/views/partials/reference/nav.hbs +93 -0
  79. package/views/partials/reference/operation.hbs +127 -0
  80. package/views/partials/reference/params.hbs +20 -0
  81. package/views/partials/reference/schema-node.hbs +99 -0
  82. package/views/partials/reference/schema.hbs +19 -0
  83. package/views/partials/reference/section-heading.hbs +16 -0
  84. package/views/partials/reference/token-alert.hbs +24 -0
  85. package/views/partials/reference/try-field.hbs +31 -0
  86. package/views/partials/reference/try-it.hbs +78 -0
  87. package/views/partials/side_menu.hbs +1 -1
  88. package/views/partials/ui/badge.hbs +4 -2
  89. package/views/partials/ui/page-header.hbs +1 -1
  90. package/views/partials/ui/search-input.hbs +31 -0
  91. package/views/partials/ui/setting-ref.hbs +1 -1
  92. package/views/partials/ui/stat-card.hbs +4 -2
  93. package/views/partials/ui/tab.hbs +6 -1
  94. package/views/partials/ui/tabs.hbs +2 -2
  95. package/views/reference/index.hbs +76 -0
  96. package/views/reference/redirect.hbs +49 -0
  97. package/views/reference/tag.hbs +28 -0
  98. package/views/reference/token.hbs +49 -0
  99. package/views/tokens/index.hbs +9 -1
  100. package/views/webhooks/index.hbs +3 -3
  101. package/workers/api.js +37 -215
  102. package/views/swagger/index.hbs +0 -82
@@ -55,6 +55,7 @@
55
55
  @source '../../js/ui.js';
56
56
  @source '../../js/passkey-register.js';
57
57
  @source '../../js/login-passkey.js';
58
+ @source '../../js/reference.js';
58
59
  @source '../../../node_modules/flyonui/flyonui.js';
59
60
 
60
61
  /* Safelist for classes assembled dynamically - in JS (badge-${type} etc.) and
@@ -84,6 +85,14 @@
84
85
  /* single source for the sidebar width: w-sidebar on the aside,
85
86
  * lg:ps-sidebar on the content column */
86
87
  --spacing-sidebar: 18rem;
88
+ /* height of the sticky topbar: the secondary nav column sticks directly
89
+ * below it (lg:top-topbar) and sizes its scroll region against it, so the
90
+ * two must agree */
91
+ --spacing-topbar: 2.9375rem;
92
+ /* one step below text-xs, for the dense metadata labels in the API
93
+ * reference (required markers, constraint chips, nav method labels) */
94
+ --text-2xs: 0.6875rem;
95
+ --text-2xs--line-height: calc(1 / 0.6875);
87
96
  }
88
97
 
89
98
  @layer base {
@@ -199,6 +208,87 @@
199
208
  line-height: 1.4286;
200
209
  }
201
210
 
211
+ /* Inline code / metadata pill. The block-level counterpart is
212
+ * .ee-code-block above; there was no inline equivalent before. .ee-code is
213
+ * emitted from lib/api-reference/format.js for every backtick span in a
214
+ * schema description, which the Tailwind scanner never sees - so this has
215
+ * to be a class, not utilities. */
216
+ .ee-code,
217
+ .ee-chip {
218
+ background-color: color-mix(in oklab, var(--color-base-content) 8%, transparent);
219
+ border-radius: var(--radius-field, 0.375rem);
220
+ padding: 0.0625rem 0.375rem;
221
+ font-family: var(--font-mono, ui-monospace, monospace);
222
+ font-size: 0.75rem;
223
+ white-space: nowrap;
224
+ }
225
+ /* .ee-chip is the muted variant, for constraint and default markers */
226
+ .ee-chip {
227
+ color: color-mix(in oklab, var(--color-base-content) 65%, transparent);
228
+ }
229
+
230
+ /* --- API reference (/admin/reference) ---------------------------------
231
+ * The schema trees are deeply nested lists rendered by a recursive
232
+ * partial, so their look comes from a class rather than utilities. These
233
+ * class names double as the e2e selectors in test/e2e/reference.spec.js. */
234
+ .ee-ref-props {
235
+ display: flex;
236
+ flex-direction: column;
237
+ gap: 0.625rem;
238
+ }
239
+ .ee-ref-nest {
240
+ border-inline-start: 1px solid color-mix(in oklab, var(--color-base-content) 12%, transparent);
241
+ padding-inline-start: 0.75rem;
242
+ }
243
+
244
+ /* Deep-link icons (reference/anchor-link), on operation headings and on every
245
+ * property row. One definition instead of the utility string repeated at every
246
+ * call site - a tag page renders up to 434 of these. */
247
+ .ee-ref-anchor {
248
+ color: color-mix(in oklab, var(--color-base-content) 40%, transparent);
249
+ flex-shrink: 0;
250
+ }
251
+ .ee-ref-anchor:hover {
252
+ color: var(--color-primary);
253
+ }
254
+
255
+ /* Property links stay hidden until their row is hovered. The rule hangs off the
256
+ * header row rather than the list item because the item CONTAINS the nested rows,
257
+ * so hovering a leaf would reveal the link on every one of its ancestors too. The
258
+ * header row has no rows inside it, which makes it exact at every depth (same
259
+ * reasoning as the disclosure chevron below). */
260
+ .ee-ref-prop-anchor {
261
+ opacity: 0;
262
+ transition: opacity 0.15s;
263
+ }
264
+ .ee-ref-prop-head:hover .ee-ref-prop-anchor,
265
+ .ee-ref-prop-anchor:focus-visible {
266
+ opacity: 1;
267
+ }
268
+
269
+ /* Arriving on a linked property. :target needs no script, so the row is marked
270
+ * even if the deep link lands on an already-expanded group. */
271
+ .ee-ref-prop:target > .ee-ref-prop-head {
272
+ background: color-mix(in oklab, var(--color-primary) 12%, transparent);
273
+ border-radius: var(--radius-field);
274
+ box-shadow: 0 0 0 0.25rem color-mix(in oklab, var(--color-primary) 12%, transparent);
275
+ }
276
+ .ee-ref-prop:target > .ee-ref-prop-head .ee-ref-prop-anchor {
277
+ opacity: 1;
278
+ }
279
+
280
+ /* Collapsible section (reference/disclosure). The chevron rotation is here
281
+ * rather than on Tailwind's group-open variant because these disclosures
282
+ * nest: a named group matches ANY open ancestor, so an inner collapsed
283
+ * group's chevron would rotate whenever an outer one was open. The child
284
+ * combinator below is exact at every depth. */
285
+ .ee-ref-disclosure > summary .ee-ref-chevron {
286
+ transition: transform 0.2s;
287
+ }
288
+ .ee-ref-disclosure[open] > summary .ee-ref-chevron {
289
+ transform: rotate(90deg);
290
+ }
291
+
202
292
  /* Typography island for server-rendered markdown (marked output: the EULA
203
293
  * on /license.html and the branding preview page). Preflight strips all
204
294
  * default heading sizes, margins and list bullets, so restore a minimal
@@ -310,14 +310,25 @@ export class EmailEngineClient {
310
310
  }
311
311
  }
312
312
 
313
+ _normalizeRecipients(to) {
314
+ return Array.isArray(to)
315
+ ? to.map(addr => (typeof addr === 'string' ? { address: addr } : addr))
316
+ : [typeof to === 'string' ? { address: to } : to];
317
+ }
318
+
319
+ // Account details (name, email address) fetched once and cached for the lifetime
320
+ // of the instance; used as the From identity of saved drafts.
321
+ async _getAccountInfo() {
322
+ if (!this._accountInfo) {
323
+ this._accountInfo = await this.apiRequest('GET', `/v1/account/${this.account}`);
324
+ }
325
+ return this._accountInfo;
326
+ }
327
+
313
328
  async sendMessage(to, subject, text) {
314
329
  try {
315
- const toAddresses = Array.isArray(to)
316
- ? to.map(addr => (typeof addr === 'string' ? { address: addr } : addr))
317
- : [typeof to === 'string' ? { address: to } : to];
318
-
319
330
  const messageData = {
320
- to: toAddresses,
331
+ to: this._normalizeRecipients(to),
321
332
  subject: subject,
322
333
  text: text
323
334
  };
@@ -332,6 +343,77 @@ export class EmailEngineClient {
332
343
  }
333
344
  }
334
345
 
346
+ async saveDraft(to, subject, text) {
347
+ try {
348
+ if (!this.folders.length) {
349
+ await this.loadFolders();
350
+ }
351
+ const draftsFolder = this.folders.find(f => f.specialUse === '\\Drafts');
352
+ if (!draftsFolder) {
353
+ throw new Error('No Drafts folder found for this account');
354
+ }
355
+
356
+ const messageData = {
357
+ path: draftsFolder.path,
358
+ flags: ['\\Draft'],
359
+ subject: subject,
360
+ text: text
361
+ };
362
+
363
+ const recipients = to ? this._normalizeRecipients(to) : [];
364
+ if (recipients.length) {
365
+ messageData.to = recipients;
366
+ }
367
+
368
+ // The upload endpoint does not add a From header on its own, but the draft
369
+ // needs one to be deliverable later - use the account's own identity.
370
+ try {
371
+ const accountInfo = await this._getAccountInfo();
372
+ if (accountInfo && accountInfo.email) {
373
+ messageData.from = { name: accountInfo.name || '', address: accountInfo.email };
374
+ }
375
+ } catch (err) {
376
+ // Non-fatal: the draft is saved without a From header
377
+ }
378
+
379
+ const response = await this.apiRequest('POST', `/v1/account/${this.account}/message`, messageData);
380
+ return response;
381
+ } catch (error) {
382
+ console.error('Failed to save draft:', error);
383
+ this._parseApiError(error);
384
+ throw error;
385
+ }
386
+ }
387
+
388
+ async submitDraft(messageId, options = null) {
389
+ try {
390
+ const response = await this.apiRequest(
391
+ 'POST',
392
+ `/v1/account/${this.account}/message/${messageId}/submit`,
393
+ options
394
+ );
395
+ return response;
396
+ } catch (error) {
397
+ console.error('Failed to submit draft:', error);
398
+ this._parseApiError(error);
399
+ throw error;
400
+ }
401
+ }
402
+
403
+ // A message counts as a draft when the server marks it as one (the \Draft flag on IMAP,
404
+ // the DRAFT label on Gmail, a draft message on MS Graph) or when it sits in the Drafts
405
+ // special-use folder.
406
+ _isDraftMessage(msg) {
407
+ if (!msg) {
408
+ return false;
409
+ }
410
+ if (msg.draft || msg.messageSpecialUse === '\\Drafts') {
411
+ return true;
412
+ }
413
+ const folder = this.folders.find(f => f.path === this.currentFolder);
414
+ return !!(folder && folder.specialUse === '\\Drafts');
415
+ }
416
+
335
417
  _parseApiError(error) {
336
418
  try {
337
419
  // If error has response text, try to parse it
@@ -368,7 +450,10 @@ export class EmailEngineClient {
368
450
  return mainMessage;
369
451
  }
370
452
 
371
- // Fallback to generic error message
453
+ // No field-level details - fall back to the API-provided message, then to a generic one
454
+ if (error.details && typeof error.details.message === 'string' && error.details.message) {
455
+ return error.details.message;
456
+ }
372
457
  return 'Failed to send email. Please check your input and try again.';
373
458
  }
374
459
 
@@ -1095,11 +1180,34 @@ export class EmailEngineClient {
1095
1180
  font-size: 14px;
1096
1181
  cursor: pointer;
1097
1182
  }
1098
-
1183
+
1099
1184
  .ee-compose-cancel:hover {
1100
1185
  background: #545b62;
1101
1186
  }
1102
1187
 
1188
+ .ee-compose-save-draft {
1189
+ background: transparent;
1190
+ color: #007bff;
1191
+ border: 1px solid #007bff;
1192
+ padding: 10px 20px;
1193
+ border-radius: 4px;
1194
+ font-size: 14px;
1195
+ font-weight: 500;
1196
+ cursor: pointer;
1197
+ }
1198
+
1199
+ .ee-compose-save-draft:hover:not(:disabled) {
1200
+ background: #007bff;
1201
+ color: white;
1202
+ }
1203
+
1204
+ .ee-compose-save-draft:disabled {
1205
+ color: #6c757d;
1206
+ border-color: #6c757d;
1207
+ cursor: not-allowed;
1208
+ opacity: 0.6;
1209
+ }
1210
+
1103
1211
  /* Dark mode toggle button */
1104
1212
  .ee-dark-mode-toggle {
1105
1213
  position: absolute;
@@ -1314,6 +1422,16 @@ export class EmailEngineClient {
1314
1422
  .ee-dark-mode .ee-compose-cancel:hover {
1315
1423
  background: #555;
1316
1424
  }
1425
+
1426
+ .ee-dark-mode .ee-compose-save-draft {
1427
+ color: #66b2ff;
1428
+ border-color: #66b2ff;
1429
+ }
1430
+
1431
+ .ee-dark-mode .ee-compose-save-draft:hover:not(:disabled) {
1432
+ background: #66b2ff;
1433
+ color: #1a1a1a;
1434
+ }
1317
1435
  `;
1318
1436
  document.head.appendChild(style);
1319
1437
  this._styleElement = style;
@@ -1564,8 +1682,10 @@ export class EmailEngineClient {
1564
1682
 
1565
1683
  const msg = this.currentMessage;
1566
1684
  const isUnseen = msg.unseen;
1685
+ const isDraft = this._isDraftMessage(msg);
1567
1686
  const html = `
1568
1687
  <div class="ee-message-actions">
1688
+ ${isDraft ? '<button class="ee-button" data-action="send-draft">Send Draft</button>' : ''}
1569
1689
  <button class="ee-button" data-action="toggle-read">Mark as ${isUnseen ? 'seen' : 'unseen'}</button>
1570
1690
  <button class="ee-button" data-action="delete">Delete</button>
1571
1691
  <button class="ee-button" data-action="download-original">Download Original</button>
@@ -1640,6 +1760,41 @@ export class EmailEngineClient {
1640
1760
 
1641
1761
  this._labelCollapsedThreads(viewer);
1642
1762
 
1763
+ const sendDraftButton = viewer.querySelector('[data-action="send-draft"]');
1764
+ if (sendDraftButton) {
1765
+ sendDraftButton.addEventListener('click', async () => {
1766
+ const result = await this.confirmMethod(
1767
+ 'Send this draft to its recipients now? The draft is removed from the Drafts folder once it has been sent.',
1768
+ 'Send Draft',
1769
+ 'Cancel',
1770
+ 'Send'
1771
+ );
1772
+ if (!result) {
1773
+ return;
1774
+ }
1775
+
1776
+ const originalText = sendDraftButton.textContent;
1777
+ sendDraftButton.disabled = true;
1778
+ sendDraftButton.textContent = 'Sending...';
1779
+
1780
+ try {
1781
+ await this.submitDraft(msg.id);
1782
+ await this.alertMethod('Draft queued for delivery.', 'Success', null, 'OK');
1783
+ // Refresh the folder view - the provider removes the draft once it is sent,
1784
+ // immediately for Gmail and MS Graph, after SMTP delivery for IMAP accounts.
1785
+ if (!this._destroyed && this.currentFolder) {
1786
+ await this.loadMessages(this.currentFolder);
1787
+ }
1788
+ } catch (error) {
1789
+ console.error('Failed to send draft:', error);
1790
+ const errorMessage = this._formatSendError(error);
1791
+ await this.alertMethod(errorMessage, 'Send Error', null, 'OK');
1792
+ sendDraftButton.disabled = false;
1793
+ sendDraftButton.textContent = originalText;
1794
+ }
1795
+ });
1796
+ }
1797
+
1643
1798
  viewer.querySelector('[data-action="toggle-read"]').addEventListener('click', () => {
1644
1799
  const currentlyUnseen = msg.unseen;
1645
1800
  this.markAsRead(msg.id, currentlyUnseen);
@@ -1754,6 +1909,7 @@ export class EmailEngineClient {
1754
1909
  </form>
1755
1910
  <div class="ee-compose-actions">
1756
1911
  <button type="button" class="ee-compose-cancel">Cancel</button>
1912
+ <button type="button" class="ee-compose-save-draft">Save Draft</button>
1757
1913
  <button type="button" class="ee-compose-send">Send</button>
1758
1914
  </div>
1759
1915
  </div>
@@ -1776,6 +1932,7 @@ export class EmailEngineClient {
1776
1932
  const modal = this.container.querySelector('.ee-compose-modal');
1777
1933
  const closeButton = this.container.querySelector('.ee-compose-close');
1778
1934
  const cancelButton = this.container.querySelector('.ee-compose-cancel');
1935
+ const saveDraftButton = this.container.querySelector('.ee-compose-save-draft');
1779
1936
  const sendButton = this.container.querySelector('.ee-compose-send');
1780
1937
  const form = this.container.querySelector('.ee-compose-form');
1781
1938
 
@@ -1811,6 +1968,52 @@ export class EmailEngineClient {
1811
1968
  };
1812
1969
  document.addEventListener('keydown', this._composeKeydownHandler);
1813
1970
 
1971
+ // Save the composed message as a draft instead of sending it
1972
+ saveDraftButton.addEventListener('click', async () => {
1973
+ const formData = new FormData(form);
1974
+ const to = formData.get('to').trim();
1975
+ const subject = formData.get('subject').trim();
1976
+ const message = formData.get('message').trim();
1977
+
1978
+ if (!to && !subject && !message) {
1979
+ modal.classList.remove('show');
1980
+ await this.alertMethod(
1981
+ 'Nothing to save - fill in at least one field first.',
1982
+ 'Validation Error',
1983
+ null,
1984
+ 'OK'
1985
+ );
1986
+ modal.classList.add('show');
1987
+ setTimeout(() => form.querySelector('input[name="to"]').focus(), 100);
1988
+ return;
1989
+ }
1990
+
1991
+ const originalText = saveDraftButton.textContent;
1992
+ saveDraftButton.disabled = true;
1993
+ saveDraftButton.textContent = 'Saving...';
1994
+
1995
+ try {
1996
+ const response = await this.saveDraft(to || null, subject, message);
1997
+ closeModal();
1998
+ await this.alertMethod('Draft saved to the Drafts folder.', 'Success', null, 'OK');
1999
+ // Refresh the list when the user is looking at the Drafts folder
2000
+ if (!this._destroyed && response && response.path && this.currentFolder === response.path) {
2001
+ await this.loadMessages(this.currentFolder);
2002
+ }
2003
+ } catch (error) {
2004
+ console.error('Failed to save draft:', error);
2005
+ // Close modal before showing error alert, then reopen with preserved values
2006
+ modal.classList.remove('show');
2007
+ const errorMessage = this._formatSendError(error);
2008
+ await this.alertMethod(errorMessage, 'Save Error', null, 'OK');
2009
+ modal.classList.add('show');
2010
+ setTimeout(() => form.querySelector('input[name="to"]').focus(), 100);
2011
+ } finally {
2012
+ saveDraftButton.disabled = false;
2013
+ saveDraftButton.textContent = originalText;
2014
+ }
2015
+ });
2016
+
1814
2017
  // Send email
1815
2018
  sendButton.addEventListener('click', async () => {
1816
2019
  const formData = new FormData(form);
@@ -1889,6 +2092,17 @@ export class EmailEngineClient {
1889
2092
  const buttonSize = 56; // Button width/height
1890
2093
  const margin = 20; // Desired margin from edges
1891
2094
 
2095
+ // A hidden container (display: none) reports a zero-size rect; positioning
2096
+ // against it would push the fixed-position button off-screen. Hide the button
2097
+ // instead and let the ResizeObserver below restore it once the container is
2098
+ // shown - hosts often create the client inside a container that is only made
2099
+ // visible afterwards.
2100
+ if (!containerRect.width && !containerRect.height) {
2101
+ composeButton.style.display = 'none';
2102
+ return;
2103
+ }
2104
+ composeButton.style.display = '';
2105
+
1892
2106
  // Calculate the ideal position (bottom-right of container with margin)
1893
2107
  const idealBottom = window.innerHeight - containerRect.bottom + margin;
1894
2108
  const idealRight = window.innerWidth - containerRect.right + margin;
@@ -1917,10 +2131,26 @@ export class EmailEngineClient {
1917
2131
  window.addEventListener('scroll', updateWithThrottle);
1918
2132
  window.addEventListener('resize', updateWithThrottle);
1919
2133
 
1920
- // Store cleanup function for potential future use
2134
+ // Reposition when the container itself changes size or becomes visible - window
2135
+ // scroll/resize events never fire for those. Calls the update directly instead of
2136
+ // the throttled wrapper: the throttle drops trailing calls, which would leave the
2137
+ // button hidden when the observer fires twice in quick succession (initial
2138
+ // notification followed by the container being shown). Observer callbacks are
2139
+ // already batched per frame by the browser, so there is nothing to throttle.
2140
+ let resizeObserver = null;
2141
+ if (typeof ResizeObserver !== 'undefined') {
2142
+ resizeObserver = new ResizeObserver(updateButtonPosition);
2143
+ resizeObserver.observe(this.container);
2144
+ }
2145
+
2146
+ // Cleanup runs from destroy()
1921
2147
  this._composeButtonCleanup = () => {
1922
2148
  window.removeEventListener('scroll', updateWithThrottle);
1923
2149
  window.removeEventListener('resize', updateWithThrottle);
2150
+ if (resizeObserver) {
2151
+ resizeObserver.disconnect();
2152
+ resizeObserver = null;
2153
+ }
1924
2154
  };
1925
2155
  }
1926
2156