@servicetitan/dte-unlayer 0.155.0 → 0.157.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.
@@ -0,0 +1,7 @@
1
+ /** Reject `onImage` with this error to show its message to the user instead of the generic upload failure text. */
2
+ export class ImageUploadError extends Error {
3
+ constructor(message: string, options?: ErrorOptions) {
4
+ super(message, options);
5
+ this.name = 'ImageUploadError';
6
+ }
7
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './editor';
2
+ export { ImageUploadError } from './image-upload-error';
2
3
  export * from './tools';
3
4
  export * from './api-core';
4
5
  export * from './api-custom-tools';
@@ -1,6 +1,6 @@
1
1
  export const unlayerSupportedFonts = [
2
2
  {
3
- label: 'Arial',
3
+ label: 'Liberation Sans',
4
4
  value: 'arial,helvetica,sans-serif',
5
5
  },
6
6
  {
package/src/store.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { emitESignOffsetRequest } from './e-sign-offset/eSignOffsetController';
2
+ import { ImageUploadError } from './image-upload-error';
2
3
  import { loadScript } from './loadScript';
3
4
  import { logUnlayerError } from './log';
4
5
  import { toUnlayerMergeTags, type UnlayerMergeTagsConfig } from './merge-tags';
@@ -720,8 +721,10 @@ export class UnlayerStore {
720
721
  return;
721
722
  }
722
723
 
723
- done({ progress: 0 });
724
-
724
+ /*
725
+ * Unlayer only leaves its "uploading" state when `done` receives a url, so `done` must not be
726
+ * called before the upload succeeds or after it fails, otherwise the image widget gets stuck.
727
+ */
725
728
  try {
726
729
  const { url } = await this.onImageCB(file);
727
730
  done({ progress: 100, url });
@@ -729,9 +732,10 @@ export class UnlayerStore {
729
732
  logUnlayerError('Image upload failed', error);
730
733
  this.onErrorCB?.(
731
734
  'Image upload failed',
732
- 'Something went wrong while uploading the image. Please try again or select another image.',
735
+ error instanceof ImageUploadError
736
+ ? error.message
737
+ : 'Something went wrong while uploading the image. Please try again or select another image.',
733
738
  );
734
- done({ progress: 100 });
735
739
  }
736
740
  };
737
741
 
package/src/tools.ts CHANGED
@@ -82,7 +82,7 @@ export const unlayerGetDefaultDesign = (): UnlayerDesignFormat => ({
82
82
  contentWidth: '100%',
83
83
  contentAlign: 'center',
84
84
  fontFamily: {
85
- label: 'Arial',
85
+ label: 'Liberation Sans',
86
86
  value: 'arial,helvetica,sans-serif',
87
87
  },
88
88
  preheaderText: '',