@file-viewer/renderer-email 2.4.0 → 3.0.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/dist/email.js CHANGED
@@ -265,6 +265,9 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
265
265
  const darkMode = resolveFileViewerColorScheme((_d = context === null || context === void 0 ? void 0 : context.options) === null || _d === void 0 ? void 0 : _d.theme, systemDark) === 'dark';
266
266
  const cleanups = [];
267
267
  let nestedRendered;
268
+ let attachmentPreviewVersion = 0;
269
+ let attachmentAbortController;
270
+ let disposed = false;
268
271
  let overlay = null;
269
272
  let errorElement = null;
270
273
  const root = createElement('section', 'email-viewer');
@@ -395,6 +398,18 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
395
398
  });
396
399
  };
397
400
  const previewAttachment = async (attachment) => {
401
+ var _a, _b, _c;
402
+ const previewVersion = ++attachmentPreviewVersion;
403
+ attachmentAbortController === null || attachmentAbortController === void 0 ? void 0 : attachmentAbortController.abort();
404
+ const previewAbortController = new AbortController();
405
+ attachmentAbortController = previewAbortController;
406
+ const abortFromParent = () => { var _a; return previewAbortController.abort((_a = context === null || context === void 0 ? void 0 : context.signal) === null || _a === void 0 ? void 0 : _a.reason); };
407
+ if ((_a = context === null || context === void 0 ? void 0 : context.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
408
+ abortFromParent();
409
+ }
410
+ else {
411
+ (_b = context === null || context === void 0 ? void 0 : context.signal) === null || _b === void 0 ? void 0 : _b.addEventListener('abort', abortFromParent, { once: true });
412
+ }
398
413
  activeAttachment = attachment;
399
414
  syncAttachmentState();
400
415
  attachmentPreview.hidden = false;
@@ -408,22 +423,37 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
408
423
  attachmentTarget.append(child);
409
424
  const extension = getAttachmentExtension(attachment.name);
410
425
  if (context === null || context === void 0 ? void 0 : context.renderNestedBuffer) {
411
- nestedRendered = await context.renderNestedBuffer(attachmentBuffer, extension, child, {
426
+ const nextRendered = await context.renderNestedBuffer(attachmentBuffer, extension, child, {
412
427
  ...context,
413
428
  filename: attachment.name,
414
429
  options: context.options,
430
+ signal: previewAbortController.signal,
415
431
  });
432
+ if (disposed || previewVersion !== attachmentPreviewVersion || previewAbortController.signal.aborted) {
433
+ await disposeFileViewerRendered(nextRendered);
434
+ return;
435
+ }
436
+ nestedRendered = nextRendered;
416
437
  }
417
438
  else {
418
439
  child.append(createElement('div', undefined, t('email.attachments.nestedUnavailable', { name: attachment.name })));
419
440
  }
420
441
  }
421
442
  catch (nextError) {
443
+ if (disposed || previewVersion !== attachmentPreviewVersion || previewAbortController.signal.aborted) {
444
+ return;
445
+ }
422
446
  console.error(nextError);
423
447
  showError(nextError instanceof Error ? nextError.message : String(nextError));
424
448
  }
425
449
  finally {
426
- hideLoading();
450
+ (_c = context === null || context === void 0 ? void 0 : context.signal) === null || _c === void 0 ? void 0 : _c.removeEventListener('abort', abortFromParent);
451
+ if (attachmentAbortController === previewAbortController) {
452
+ attachmentAbortController = undefined;
453
+ }
454
+ if (!disposed && previewVersion === attachmentPreviewVersion) {
455
+ hideLoading();
456
+ }
427
457
  }
428
458
  };
429
459
  parsed.attachments.forEach(attachment => {
@@ -466,6 +496,10 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
466
496
  return {
467
497
  $el: root,
468
498
  async unmount() {
499
+ disposed = true;
500
+ attachmentPreviewVersion += 1;
501
+ attachmentAbortController === null || attachmentAbortController === void 0 ? void 0 : attachmentAbortController.abort();
502
+ attachmentAbortController = undefined;
469
503
  await clearAttachmentPreview();
470
504
  cleanups.splice(0).forEach(cleanup => cleanup());
471
505
  objectUrls.forEach(url => URL.revokeObjectURL(url));
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "../../../ecosystem/capability-manifest.schema.json",
3
+ "schemaVersion": 1,
4
+ "id": "email",
5
+ "packageName": "@file-viewer/renderer-email",
6
+ "rendererIds": ["email"],
7
+ "formats": ["eml", "msg", "mbox"],
8
+ "assets": { "rendererIds": [] },
9
+ "license": { "spdx": "Apache-2.0", "policy": "permissive" },
10
+ "weight": "light",
11
+ "profiles": ["standard", "all"]
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-email",
3
- "version": "2.4.0",
3
+ "version": "3.0.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Standalone email renderer plugin for File Viewer with EML, MSG, MBOX, attachments, and nested previews.",
@@ -50,18 +50,23 @@
50
50
  },
51
51
  "files": [
52
52
  "dist",
53
+ "file-viewer.capability.json",
53
54
  "README.md",
54
55
  "README.en.md",
55
56
  "LICENSE"
56
57
  ],
57
58
  "dependencies": {
58
- "@file-viewer/core": "2.4.0",
59
+ "@file-viewer/core": "3.0.0",
59
60
  "@kenjiuno/msgreader": "^1.28.0",
61
+ "buffer": "^6.0.3",
60
62
  "postal-mime": "^2.7.4"
61
63
  },
62
64
  "devDependencies": {
63
65
  "typescript": "^6.0.3"
64
66
  },
67
+ "fileViewer": {
68
+ "capabilityManifest": "./file-viewer.capability.json"
69
+ },
65
70
  "license": "Apache-2.0",
66
71
  "scripts": {
67
72
  "build": "tsc -b tsconfig.json",