@servicetitan/dte-unlayer 0.151.0 → 0.153.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/src/unlayer.tsx CHANGED
@@ -1,5 +1,7 @@
1
1
  import { emitDisplayCondition } from './display-conditions/displayConditionController';
2
2
  import { editorCoreScript, editorCoreStyles, editorCoreTools } from './editor-core';
3
+ import { logUnlayerError } from './log';
4
+ import { scheduleUnlayerMergeTags, toUnlayerMergeTags } from './merge-tags';
3
5
  import { constGenericsEditor } from './shared/const';
4
6
  import { unlayerSupportedFonts } from './shared/fonts';
5
7
  import {
@@ -275,82 +277,92 @@ export const createUnlayerEditor = (
275
277
  },
276
278
  };
277
279
 
278
- const result = (window as any).unlayer.createEditor({
279
- displayMode: 'web',
280
- devices: ['desktop'],
281
- features: {
282
- preview: true,
283
- userUploads: false,
284
- stockImages: false,
285
- textEditor: {
286
- tables: true,
287
- },
288
- },
289
- mergeTags: mergeTags?.reduce(
290
- (out, tag) => {
291
- out[tag.id] = { name: tag.name, value: tag.propertyPath };
280
+ let result: Unlayer;
281
+
282
+ try {
283
+ const unlayerApi = (window as any).unlayer;
284
+
285
+ if (!unlayerApi?.createEditor) {
286
+ throw new Error(
287
+ 'Unlayer embed is not available. window.unlayer.createEditor is missing.',
288
+ );
289
+ }
292
290
 
293
- return out;
291
+ result = unlayerApi.createEditor({
292
+ displayMode: 'web',
293
+ devices: ['desktop'],
294
+ features: {
295
+ preview: true,
296
+ userUploads: false,
297
+ stockImages: false,
298
+ textEditor: {
299
+ tables: true,
300
+ },
294
301
  },
295
- {} as Record<string, { name: string; value: string }>,
296
- ),
297
- projectId: 5713,
298
- version: latest ? undefined : versions.unlayer,
299
- appearance: {
300
- theme: 'classic_light',
301
- },
302
- tools: {
303
- 'carousel': { enabled: false },
304
- 'button': { enabled: false },
305
- 'html': {
306
- enabled: enableHTMLEditing,
307
- properties: {
308
- html: {
309
- editor: {
310
- widgetParams: {
311
- codeMirrorOptions: {
312
- readOnly: enableHTMLEditingReadonly,
302
+ mergeTags: toUnlayerMergeTags(mergeTags, { groups: false }),
303
+ projectId: 5713,
304
+ version: latest ? undefined : versions.unlayer,
305
+ appearance: {
306
+ theme: 'classic_light',
307
+ },
308
+ tools: {
309
+ 'carousel': { enabled: false },
310
+ 'button': { enabled: false },
311
+ 'html': {
312
+ enabled: enableHTMLEditing,
313
+ properties: {
314
+ html: {
315
+ editor: {
316
+ widgetParams: {
317
+ codeMirrorOptions: {
318
+ readOnly: enableHTMLEditingReadonly,
319
+ },
313
320
  },
314
321
  },
315
322
  },
316
323
  },
317
324
  },
325
+ 'table': {
326
+ enabled: true,
327
+ },
328
+ 'menu': { enabled: false },
329
+ 'form': { enabled: false },
330
+ ...(noCoreTools
331
+ ? {
332
+ columns: { enabled: false },
333
+ text: { enabled: false },
334
+ heading: { enabled: false },
335
+ divider: { enabled: false },
336
+ image: { enabled: false },
337
+ }
338
+ : {}),
339
+ ...unitsConfig,
340
+ 'custom#e-sign': eSignComponentRecipients,
318
341
  },
319
- 'table': {
320
- enabled: true,
342
+ editor: {
343
+ autoSelectOnDrop: true,
321
344
  },
322
- 'menu': { enabled: false },
323
- 'form': { enabled: false },
324
- ...(noCoreTools
325
- ? {
326
- columns: { enabled: false },
327
- text: { enabled: false },
328
- heading: { enabled: false },
329
- divider: { enabled: false },
330
- image: { enabled: false },
331
- }
332
- : {}),
333
- ...unitsConfig,
334
- 'custom#e-sign': eSignComponentRecipients,
335
- },
336
- editor: {
337
- autoSelectOnDrop: true,
338
- },
339
- customJS: customScripts,
340
- customCSS: customStyles,
341
- id,
342
- fonts: {
343
- showDefaultFonts: false,
344
- customFonts: unlayerSupportedFonts,
345
- },
346
- tabs: {
347
- content: {},
348
- body: {},
349
- blocks: { enabled: false },
350
- },
351
- });
345
+ customJS: customScripts,
346
+ customCSS: customStyles,
347
+ id,
348
+ fonts: {
349
+ showDefaultFonts: false,
350
+ customFonts: unlayerSupportedFonts,
351
+ },
352
+ tabs: {
353
+ content: {},
354
+ body: {},
355
+ blocks: { enabled: false },
356
+ },
357
+ });
358
+ } catch (error: unknown) {
359
+ logUnlayerError('unlayer.createEditor failed', error);
360
+ throw error;
361
+ } finally {
362
+ document.getElementById = currentFind;
363
+ }
352
364
 
353
- document.getElementById = currentFind;
365
+ scheduleUnlayerMergeTags(result, mergeTags);
354
366
 
355
367
  if (displayConditions) {
356
368
  result.registerCallback(