@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.
@@ -1 +1 @@
1
- {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/editor.tsx"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EAOhB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAgB,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAE3E,MAAM,WAAW,kBAAkB;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,IAAI,EAAE,wBAAwB,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;IAEtB,OAAO,CAAC,IAAI,IAAI,CAAC;IAEjB,QAAQ,CAAC,CAAC,IAAI,EAAE,uBAAuB,GAAG,IAAI,CAAC;IAE/C,cAAc,CAAC,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAE/C,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAE/C,OAAO,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpD,SAAS,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC;CAC7C;AAED,eAAO,MAAM,aAAa,2DAAwC,CAAC;AAEnE,eAAO,MAAM,aAAa,2GAuGxB,CAAC"}
1
+ {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/editor.tsx"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EAOhB,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAgB,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAE3E,MAAM,WAAW,kBAAkB;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,IAAI,EAAE,wBAAwB,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;IAEtB,OAAO,CAAC,IAAI,IAAI,CAAC;IAEjB,QAAQ,CAAC,CAAC,IAAI,EAAE,uBAAuB,GAAG,IAAI,CAAC;IAE/C,cAAc,CAAC,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAE/C,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAE/C,OAAO,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpD,SAAS,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC;CAC7C;AAED,eAAO,MAAM,aAAa,2DAAwC,CAAC;AAEnE,eAAO,MAAM,aAAa,2GAiHxB,CAAC"}
package/dist/editor.js CHANGED
@@ -1,19 +1,38 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
3
3
  import { DisplayConditionModal } from './display-conditions/DisplayConditionModal';
4
+ import { getErrorMessage } from './log';
4
5
  import { UnlayerStore } from './store';
5
6
  export const useUnlayerRef = ()=>useRef(null);
6
7
  export const UnlayerEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
7
8
  var _props_id;
8
9
  const [isReady, setIsReady] = useState(false);
10
+ const [loadError, setLoadError] = useState();
9
11
  const containerRef = useRef(null);
10
12
  const store = useMemo(()=>new UnlayerStore(props.opts), // eslint-disable-next-line react-hooks/exhaustive-deps
11
13
  []);
14
+ useEffect(()=>{
15
+ store.setOnError(props.onError);
16
+ return ()=>store.setOnError();
17
+ }, [
18
+ props.onError,
19
+ store
20
+ ]);
12
21
  useEffect(()=>{
13
22
  if (containerRef.current) {
14
- store.init(containerRef.current).then(()=>setIsReady(true)).catch(()=>setIsReady(false));
23
+ store.init(containerRef.current).then(()=>{
24
+ setLoadError(undefined);
25
+ setIsReady(true);
26
+ }).catch((error)=>{
27
+ var _props_onError;
28
+ const description = getErrorMessage(error);
29
+ setIsReady(false);
30
+ setLoadError(description);
31
+ (_props_onError = props.onError) === null || _props_onError === void 0 ? void 0 : _props_onError.call(props, 'Editor failed to load', description);
32
+ });
15
33
  }
16
34
  return ()=>store.destroy();
35
+ // eslint-disable-next-line react-hooks/exhaustive-deps
17
36
  }, [
18
37
  store
19
38
  ]);
@@ -65,13 +84,6 @@ export const UnlayerEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
65
84
  props.onImage,
66
85
  store
67
86
  ]);
68
- useEffect(()=>{
69
- store.setOnError(props.onError);
70
- return ()=>store.setOnError();
71
- }, [
72
- props.onError,
73
- store
74
- ]);
75
87
  useEffect(()=>{
76
88
  store.setOnMessage(props.onMessage);
77
89
  return ()=>store.setOnMessage();
@@ -107,9 +119,12 @@ export const UnlayerEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
107
119
  display: 'flex'
108
120
  },
109
121
  children: [
110
- !isReady && /*#__PURE__*/ _jsx("p", {
122
+ loadError && /*#__PURE__*/ _jsxs("p", {
111
123
  className: "c-red-500",
112
- children: "error loading editor"
124
+ children: [
125
+ "error loading editor: ",
126
+ loadError
127
+ ]
113
128
  }),
114
129
  /*#__PURE__*/ _jsx("div", {
115
130
  id: (_props_id = props.id) !== null && _props_id !== void 0 ? _props_id : 'editor',
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/editor.tsx"],"sourcesContent":["import {\n CSSProperties,\n forwardRef,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { DisplayConditionModal } from './display-conditions/DisplayConditionModal';\nimport { UnlayerEditorTwin } from './shared/const';\nimport { UnlayerStore, UnlayerDesignChangeInfo } from './store';\nimport { UnlayerRef, CreateUnlayerEditorProps } from './unlayer-interface';\n\nexport interface UnlayerEditorProps {\n id?: string;\n design?: any;\n opts: CreateUnlayerEditorProps;\n minHeight?: number;\n style?: CSSProperties;\n\n onReady?(): void;\n\n onChange?(info: UnlayerDesignChangeInfo): void;\n\n onSnapshotSave?(tool: UnlayerEditorTwin): void;\n\n onImage?(file: File): Promise<{ url: string }>;\n\n onError?(title: string, description?: string): void;\n\n onMessage?(type: string, data: any): void;\n}\n\nexport const useUnlayerRef = () => useRef<UnlayerRef | null>(null);\n\nexport const UnlayerEditor = forwardRef<UnlayerRef, UnlayerEditorProps>((props, ref) => {\n const [isReady, setIsReady] = useState(false);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const store = useMemo(\n () => new UnlayerStore(props.opts),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n useEffect(() => {\n if (containerRef.current) {\n store\n .init(containerRef.current)\n .then(() => setIsReady(true))\n .catch(() => setIsReady(false));\n }\n\n return () => store.destroy();\n }, [store]);\n useImperativeHandle(ref, () => store.unlayerRef, [store]);\n\n useEffect(() => {\n if (isReady) {\n store.setDesign(props.design);\n }\n }, [isReady, props.design, store]);\n\n useEffect(() => {\n store.setOnChange(props.onChange);\n\n return () => store.setOnChange();\n }, [props.onChange, store]);\n\n useEffect(() => {\n store.setOnSnapshotSave(props.onSnapshotSave);\n\n return () => store.setOnSnapshotSave();\n }, [props.onSnapshotSave, store]);\n\n useEffect(() => {\n if (props.opts.newSnapshot) {\n store.addTwin(props.opts.newSnapshot);\n }\n }, [props.opts.newSnapshot, store]);\n\n useEffect(() => {\n store.setOnReady(props.onReady);\n\n return () => store.setOnReady();\n }, [props.onReady, store]);\n\n useEffect(() => {\n store.setOnImage(props.onImage);\n\n return () => store.setOnImage();\n }, [props.onImage, store]);\n\n useEffect(() => {\n store.setOnError(props.onError);\n\n return () => store.setOnError();\n }, [props.onError, store]);\n\n useEffect(() => {\n store.setOnMessage(props.onMessage);\n\n return () => store.setOnMessage();\n }, [props.onMessage, store]);\n\n useEffect(() => {\n store.setOnFormSelect(props.opts.onFormSelect);\n\n return () => store.setOnFormSelect();\n }, [props.opts.onFormSelect, store]);\n\n useEffect(() => {\n store.setOnCalcFieldOpen(props.opts.onCalcFieldOpen);\n\n return () => store.setOnCalcFieldOpen();\n }, [props.opts.onCalcFieldOpen, store]);\n\n useEffect(() => {\n store.setOnCalcFieldSelect(props.opts.onCalcFieldSelect);\n\n return () => store.setOnCalcFieldSelect();\n }, [props.opts.onCalcFieldSelect, store]);\n\n const { minHeight = 800, style = {} } = props;\n\n return (\n <div style={{ minHeight, display: 'flex' }}>\n {!isReady && <p className=\"c-red-500\">error loading editor</p>}\n <div id={props.id ?? 'editor'} style={style} ref={containerRef} />\n {props.opts.displayConditions && (\n <DisplayConditionModal\n portalContainer={props.opts.displayConditionModalPortalContainer}\n schema={props.opts.schema}\n onConditionalsOpen={props.opts.onConditionalsOpen}\n onConditionFormSelect={props.opts.onConditionFormSelect}\n />\n )}\n </div>\n );\n});\n"],"names":["forwardRef","useEffect","useImperativeHandle","useMemo","useRef","useState","DisplayConditionModal","UnlayerStore","useUnlayerRef","UnlayerEditor","props","ref","isReady","setIsReady","containerRef","store","opts","current","init","then","catch","destroy","unlayerRef","setDesign","design","setOnChange","onChange","setOnSnapshotSave","onSnapshotSave","newSnapshot","addTwin","setOnReady","onReady","setOnImage","onImage","setOnError","onError","setOnMessage","onMessage","setOnFormSelect","onFormSelect","setOnCalcFieldOpen","onCalcFieldOpen","setOnCalcFieldSelect","onCalcFieldSelect","minHeight","style","div","display","p","className","id","displayConditions","portalContainer","displayConditionModalPortalContainer","schema","onConditionalsOpen","onConditionFormSelect"],"mappings":";AAAA,SAEIA,UAAU,EACVC,SAAS,EACTC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,QAAQ;AACf,SAASC,qBAAqB,QAAQ,6CAA6C;AAEnF,SAASC,YAAY,QAAiC,UAAU;AAuBhE,OAAO,MAAMC,gBAAgB,IAAMJ,OAA0B,MAAM;AAEnE,OAAO,MAAMK,8BAAgBT,WAA2C,CAACU,OAAOC;QA4F3DD;IA3FjB,MAAM,CAACE,SAASC,WAAW,GAAGR,SAAS;IACvC,MAAMS,eAAeV,OAA8B;IACnD,MAAMW,QAAQZ,QACV,IAAM,IAAII,aAAaG,MAAMM,IAAI,GACjC,uDAAuD;IACvD,EAAE;IAGNf,UAAU;QACN,IAAIa,aAAaG,OAAO,EAAE;YACtBF,MACKG,IAAI,CAACJ,aAAaG,OAAO,EACzBE,IAAI,CAAC,IAAMN,WAAW,OACtBO,KAAK,CAAC,IAAMP,WAAW;QAChC;QAEA,OAAO,IAAME,MAAMM,OAAO;IAC9B,GAAG;QAACN;KAAM;IACVb,oBAAoBS,KAAK,IAAMI,MAAMO,UAAU,EAAE;QAACP;KAAM;IAExDd,UAAU;QACN,IAAIW,SAAS;YACTG,MAAMQ,SAAS,CAACb,MAAMc,MAAM;QAChC;IACJ,GAAG;QAACZ;QAASF,MAAMc,MAAM;QAAET;KAAM;IAEjCd,UAAU;QACNc,MAAMU,WAAW,CAACf,MAAMgB,QAAQ;QAEhC,OAAO,IAAMX,MAAMU,WAAW;IAClC,GAAG;QAACf,MAAMgB,QAAQ;QAAEX;KAAM;IAE1Bd,UAAU;QACNc,MAAMY,iBAAiB,CAACjB,MAAMkB,cAAc;QAE5C,OAAO,IAAMb,MAAMY,iBAAiB;IACxC,GAAG;QAACjB,MAA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ACjC,MAAMM,IAAI,CAAC4B,iBAAiB;QAAE7B;KAAM;IAExC,MAAM,EAAE8B,YAAY,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE,GAAGpC;IAExC,qBACI,MAACqC;QAAID,OAAO;YAAED;YAAWG,SAAS;QAAO;;YACpC,CAACpC,yBAAW,KAACqC;gBAAEC,WAAU;0BAAY;;0BACtC,KAACH;gBAAII,EAAE,GAAEzC,YAAAA,MAAMyC,EAAE,cAARzC,uBAAAA,YAAY;gBAAUoC,OAAOA;gBAAOnC,KAAKG;;YACjDJ,MAAMM,IAAI,CAACoC,iBAAiB,kBACzB,KAAC9C;gBACG+C,iBAAiB3C,MAAMM,IAAI,CAACsC,oCAAoC;gBAChEC,QAAQ7C,MAAMM,IAAI,CAACuC,MAAM;gBACzBC,oBAAoB9C,MAAMM,IAAI,CAACwC,kBAAkB;gBACjDC,uBAAuB/C,MAAMM,IAAI,CAACyC,qBAAqB;;;;AAK3E,GAAG"}
1
+ {"version":3,"sources":["../src/editor.tsx"],"sourcesContent":["import {\n CSSProperties,\n forwardRef,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { DisplayConditionModal } from './display-conditions/DisplayConditionModal';\nimport { getErrorMessage } from './log';\nimport { UnlayerEditorTwin } from './shared/const';\nimport { UnlayerStore, UnlayerDesignChangeInfo } from './store';\nimport { UnlayerRef, CreateUnlayerEditorProps } from './unlayer-interface';\n\nexport interface UnlayerEditorProps {\n id?: string;\n design?: any;\n opts: CreateUnlayerEditorProps;\n minHeight?: number;\n style?: CSSProperties;\n\n onReady?(): void;\n\n onChange?(info: UnlayerDesignChangeInfo): void;\n\n onSnapshotSave?(tool: UnlayerEditorTwin): void;\n\n onImage?(file: File): Promise<{ url: string }>;\n\n onError?(title: string, description?: string): void;\n\n onMessage?(type: string, data: any): void;\n}\n\nexport const useUnlayerRef = () => useRef<UnlayerRef | null>(null);\n\nexport const UnlayerEditor = forwardRef<UnlayerRef, UnlayerEditorProps>((props, ref) => {\n const [isReady, setIsReady] = useState(false);\n const [loadError, setLoadError] = useState<string>();\n const containerRef = useRef<HTMLDivElement | null>(null);\n const store = useMemo(\n () => new UnlayerStore(props.opts),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n useEffect(() => {\n store.setOnError(props.onError);\n\n return () => store.setOnError();\n }, [props.onError, store]);\n\n useEffect(() => {\n if (containerRef.current) {\n store\n .init(containerRef.current)\n .then(() => {\n setLoadError(undefined);\n setIsReady(true);\n })\n .catch((error: unknown) => {\n const description = getErrorMessage(error);\n setIsReady(false);\n setLoadError(description);\n props.onError?.('Editor failed to load', description);\n });\n }\n\n return () => store.destroy();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [store]);\n useImperativeHandle(ref, () => store.unlayerRef, [store]);\n\n useEffect(() => {\n if (isReady) {\n store.setDesign(props.design);\n }\n }, [isReady, props.design, store]);\n\n useEffect(() => {\n store.setOnChange(props.onChange);\n\n return () => store.setOnChange();\n }, [props.onChange, store]);\n\n useEffect(() => {\n store.setOnSnapshotSave(props.onSnapshotSave);\n\n return () => store.setOnSnapshotSave();\n }, [props.onSnapshotSave, store]);\n\n useEffect(() => {\n if (props.opts.newSnapshot) {\n store.addTwin(props.opts.newSnapshot);\n }\n }, [props.opts.newSnapshot, store]);\n\n useEffect(() => {\n store.setOnReady(props.onReady);\n\n return () => store.setOnReady();\n }, [props.onReady, store]);\n\n useEffect(() => {\n store.setOnImage(props.onImage);\n\n return () => store.setOnImage();\n }, [props.onImage, store]);\n\n useEffect(() => {\n store.setOnMessage(props.onMessage);\n\n return () => store.setOnMessage();\n }, [props.onMessage, store]);\n\n useEffect(() => {\n store.setOnFormSelect(props.opts.onFormSelect);\n\n return () => store.setOnFormSelect();\n }, [props.opts.onFormSelect, store]);\n\n useEffect(() => {\n store.setOnCalcFieldOpen(props.opts.onCalcFieldOpen);\n\n return () => store.setOnCalcFieldOpen();\n }, [props.opts.onCalcFieldOpen, store]);\n\n useEffect(() => {\n store.setOnCalcFieldSelect(props.opts.onCalcFieldSelect);\n\n return () => store.setOnCalcFieldSelect();\n }, [props.opts.onCalcFieldSelect, store]);\n\n const { minHeight = 800, style = {} } = props;\n\n return (\n <div style={{ minHeight, display: 'flex' }}>\n {loadError && <p className=\"c-red-500\">error loading editor: {loadError}</p>}\n <div id={props.id ?? 'editor'} style={style} ref={containerRef} />\n {props.opts.displayConditions && (\n <DisplayConditionModal\n portalContainer={props.opts.displayConditionModalPortalContainer}\n schema={props.opts.schema}\n onConditionalsOpen={props.opts.onConditionalsOpen}\n onConditionFormSelect={props.opts.onConditionFormSelect}\n />\n )}\n </div>\n );\n});\n"],"names":["forwardRef","useEffect","useImperativeHandle","useMemo","useRef","useState","DisplayConditionModal","getErrorMessage","UnlayerStore","useUnlayerRef","UnlayerEditor","props","ref","isReady","setIsReady","loadError","setLoadError","containerRef","store","opts","setOnError","onError","current","init","then","undefined","catch","error","description","destroy","unlayerRef","setDesign","design","setOnChange","onChange","setOnSnapshotSave","onSnapshotSave","newSnapshot","addTwin","setOnReady","onReady","setOnImage","onImage","setOnMessage","onMessage","setOnFormSelect","onFormSelect","setOnCalcFieldOpen","onCalcFieldOpen","setOnCalcFieldSelect","onCalcFieldSelect","minHeight","style","div","display","p","className","id","displayConditions","portalContainer","displayConditionModalPortalContainer","schema","onConditionalsOpen","onConditionFormSelect"],"mappings":";AAAA,SAEIA,UAAU,EACVC,SAAS,EACTC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,QAAQ;AACf,SAASC,qBAAqB,QAAQ,6CAA6C;AACnF,SAASC,eAAe,QAAQ,QAAQ;AAExC,SAASC,YAAY,QAAiC,UAAU;AAuBhE,OAAO,MAAMC,gBAAgB,IAAML,OAA0B,MAAM;AAEnE,OAAO,MAAMM,8BAAgBV,WAA2C,CAACW,OAAOC;QAsG3DD;IArGjB,MAAM,CAACE,SAASC,WAAW,GAAGT,SAAS;IACvC,MAAM,CAACU,W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;oBAAY;oBAAuBzC;;;0BAC9D,KAACsC;gBAAII,EAAE,GAAE9C,YAAAA,MAAM8C,EAAE,cAAR9C,uBAAAA,YAAY;gBAAUyC,OAAOA;gBAAOxC,KAAKK;;YACjDN,MAAMQ,IAAI,CAACuC,iBAAiB,kBACzB,KAACpD;gBACGqD,iBAAiBhD,MAAMQ,IAAI,CAACyC,oCAAoC;gBAChEC,QAAQlD,MAAMQ,IAAI,CAAC0C,MAAM;gBACzBC,oBAAoBnD,MAAMQ,IAAI,CAAC2C,kBAAkB;gBACjDC,uBAAuBpD,MAAMQ,IAAI,CAAC4C,qBAAqB;;;;AAK3E,GAAG"}
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export * from './tools';
3
3
  export * from './api-core';
4
4
  export * from './api-custom-tools';
5
5
  export * from './unlayer-interface';
6
+ export { isUnlayerMergeTagGroup, scheduleUnlayerMergeTags, toUnlayerMergeTags } from './merge-tags';
7
+ export type { ToUnlayerMergeTagsOptions, UnlayerMergeTagGroup, UnlayerMergeTagLeaf, UnlayerMergeTagsConfig, UnlayerMergeTagsEditor, } from './merge-tags';
6
8
  export * from './loadScript';
7
9
  export * from './shared/const';
8
10
  export * from './shared/forms';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,YAAY,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,cAAc,8CAA8C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACpG,YAAY,EACR,yBAAyB,EACzB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,GACzB,MAAM,cAAc,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,YAAY,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,cAAc,8CAA8C,CAAC"}
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ export * from './tools';
3
3
  export * from './api-core';
4
4
  export * from './api-custom-tools';
5
5
  export * from './unlayer-interface';
6
+ export { isUnlayerMergeTagGroup, scheduleUnlayerMergeTags, toUnlayerMergeTags } from './merge-tags';
6
7
  export * from './loadScript';
7
8
  export * from './shared/const';
8
9
  export * from './shared/forms';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './editor';\nexport * from './tools';\nexport * from './api-core';\nexport * from './api-custom-tools';\nexport * from './unlayer-interface';\nexport * from './loadScript';\nexport * from './shared/const';\nexport * from './shared/forms';\nexport * from './shared/schema';\nexport * from './shared/tools';\nexport type { UnlayerDesignChangeInfo } from './store';\nexport { versions } from './unlayer';\nexport * from './shared/date-calc';\nexport { emptyArrayIfNull } from './shared/nunjucks-helpers';\nexport * from './display-conditions/lookupOptionsController';\n"],"names":["versions","emptyArrayIfNull"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,UAAU;AACxB,cAAc,aAAa;AAC3B,cAAc,qBAAqB;AACnC,cAAc,sBAAsB;AACpC,cAAc,eAAe;AAC7B,cAAc,iBAAiB;AAC/B,cAAc,iBAAiB;AAC/B,cAAc,kBAAkB;AAChC,cAAc,iBAAiB;AAE/B,SAASA,QAAQ,QAAQ,YAAY;AACrC,cAAc,qBAAqB;AACnC,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,cAAc,+CAA+C"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './editor';\nexport * from './tools';\nexport * from './api-core';\nexport * from './api-custom-tools';\nexport * from './unlayer-interface';\nexport { isUnlayerMergeTagGroup, scheduleUnlayerMergeTags, toUnlayerMergeTags } from './merge-tags';\nexport type {\n ToUnlayerMergeTagsOptions,\n UnlayerMergeTagGroup,\n UnlayerMergeTagLeaf,\n UnlayerMergeTagsConfig,\n UnlayerMergeTagsEditor,\n} from './merge-tags';\nexport * from './loadScript';\nexport * from './shared/const';\nexport * from './shared/forms';\nexport * from './shared/schema';\nexport * from './shared/tools';\nexport type { UnlayerDesignChangeInfo } from './store';\nexport { versions } from './unlayer';\nexport * from './shared/date-calc';\nexport { emptyArrayIfNull } from './shared/nunjucks-helpers';\nexport * from './display-conditions/lookupOptionsController';\n"],"names":["isUnlayerMergeTagGroup","scheduleUnlayerMergeTags","toUnlayerMergeTags","versions","emptyArrayIfNull"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,UAAU;AACxB,cAAc,aAAa;AAC3B,cAAc,qBAAqB;AACnC,cAAc,sBAAsB;AACpC,SAASA,sBAAsB,EAAEC,wBAAwB,EAAEC,kBAAkB,QAAQ,eAAe;AAQpG,cAAc,eAAe;AAC7B,cAAc,iBAAiB;AAC/B,cAAc,iBAAiB;AAC/B,cAAc,kBAAkB;AAChC,cAAc,iBAAiB;AAE/B,SAASC,QAAQ,QAAQ,YAAY;AACrC,cAAc,qBAAqB;AACnC,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,cAAc,+CAA+C"}
@@ -1 +1 @@
1
- {"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../src/loadScript.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,UAAU,GAAI,WAAW,MAAM,KAAG,OAAO,CAAC,IAAI,CAa1D,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,SAI9C,CAAC"}
1
+ {"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../src/loadScript.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,UAAU,GAAI,WAAW,MAAM,KAAG,OAAO,CAAC,IAAI,CAmB1D,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,SAI9C,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { logUnlayerError } from './log';
1
2
  const isScriptInjected = (scriptUrl)=>{
2
3
  const scripts = document.querySelectorAll('script');
3
4
  let injected = false;
@@ -9,15 +10,21 @@ const isScriptInjected = (scriptUrl)=>{
9
10
  return injected;
10
11
  };
11
12
  export const loadScript = (scriptUrl)=>{
12
- return new Promise((resolve)=>{
13
+ return new Promise((resolve, reject)=>{
13
14
  if (isScriptInjected(scriptUrl)) {
14
15
  resolve();
16
+ return;
15
17
  }
16
18
  const embedScript = document.createElement('script');
17
19
  embedScript.setAttribute('src', scriptUrl);
18
20
  embedScript.onload = ()=>{
19
21
  resolve();
20
22
  };
23
+ embedScript.onerror = ()=>{
24
+ const error = new Error(`Failed to load Unlayer script: ${scriptUrl}`);
25
+ logUnlayerError('Unlayer embed script failed to load', error);
26
+ reject(error);
27
+ };
21
28
  document.head.appendChild(embedScript);
22
29
  });
23
30
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/loadScript.ts"],"sourcesContent":["const isScriptInjected = (scriptUrl: string) => {\n const scripts = document.querySelectorAll('script');\n let injected = false;\n\n scripts.forEach(script => {\n if (script.src.includes(scriptUrl)) {\n injected = true;\n }\n });\n\n return injected;\n};\n\nexport const loadScript = (scriptUrl: string): Promise<void> => {\n return new Promise<void>(resolve => {\n if (isScriptInjected(scriptUrl)) {\n resolve();\n }\n\n const embedScript = document.createElement('script');\n embedScript.setAttribute('src', scriptUrl);\n embedScript.onload = () => {\n resolve();\n };\n document.head.appendChild(embedScript);\n });\n};\n\nexport const loadScriptSource = (source: string) => {\n const embedScript = document.createElement('script');\n embedScript.textContent = source;\n document.head.appendChild(embedScript);\n};\n"],"names":["isScriptInjected","scriptUrl","scripts","document","querySelectorAll","injected","forEach","script","src","includes","loadScript","Promise","resolve","embedScript","createElement","setAttribute","onload","head","appendChild","loadScriptSource","source","textContent"],"mappings":"AAAA,MAAMA,mBAAmB,CAACC;IACtB,MAAMC,UAAUC,SAASC,gBAAgB,CAAC;IAC1C,IAAIC,WAAW;IAEfH,QAAQI,OAAO,CAACC,CAAAA;QACZ,IAAIA,OAAOC,GAAG,CAACC,QAAQ,CAACR,YAAY;YAChCI,WAAW;QACf;IACJ;IAEA,OAAOA;AACX;AAEA,OAAO,MAAMK,aAAa,CAACT;IACvB,OAAO,IAAIU,QAAcC,CAAAA;QACrB,IAAIZ,iBAAiBC,YAAY;YAC7BW;QACJ;QAEA,MAAMC,cAAcV,SAASW,aAAa,CAAC;QAC3CD,YAAYE,YAAY,CAAC,OAAOd;QAChCY,YAAYG,MAAM,GAAG;YACjBJ;QACJ;QACAT,SAASc,IAAI,CAACC,WAAW,CAACL;IAC9B;AACJ,EAAE;AAEF,OAAO,MAAMM,mBAAmB,CAACC;IAC7B,MAAMP,cAAcV,SAASW,aAAa,CAAC;IAC3CD,YAAYQ,WAAW,GAAGD;IAC1BjB,SAASc,IAAI,CAACC,WAAW,CAACL;AAC9B,EAAE"}
1
+ {"version":3,"sources":["../src/loadScript.ts"],"sourcesContent":["import { logUnlayerError } from './log';\n\nconst isScriptInjected = (scriptUrl: string) => {\n const scripts = document.querySelectorAll('script');\n let injected = false;\n\n scripts.forEach(script => {\n if (script.src.includes(scriptUrl)) {\n injected = true;\n }\n });\n\n return injected;\n};\n\nexport const loadScript = (scriptUrl: string): Promise<void> => {\n return new Promise<void>((resolve, reject) => {\n if (isScriptInjected(scriptUrl)) {\n resolve();\n return;\n }\n\n const embedScript = document.createElement('script');\n embedScript.setAttribute('src', scriptUrl);\n embedScript.onload = () => {\n resolve();\n };\n embedScript.onerror = () => {\n const error = new Error(`Failed to load Unlayer script: ${scriptUrl}`);\n logUnlayerError('Unlayer embed script failed to load', error);\n reject(error);\n };\n document.head.appendChild(embedScript);\n });\n};\n\nexport const loadScriptSource = (source: string) => {\n const embedScript = document.createElement('script');\n embedScript.textContent = source;\n document.head.appendChild(embedScript);\n};\n"],"names":["logUnlayerError","isScriptInjected","scriptUrl","scripts","document","querySelectorAll","injected","forEach","script","src","includes","loadScript","Promise","resolve","reject","embedScript","createElement","setAttribute","onload","onerror","error","Error","head","appendChild","loadScriptSource","source","textContent"],"mappings":"AAAA,SAASA,eAAe,QAAQ,QAAQ;AAExC,MAAMC,mBAAmB,CAACC;IACtB,MAAMC,UAAUC,SAASC,gBAAgB,CAAC;IAC1C,IAAIC,WAAW;IAEfH,QAAQI,OAAO,CAACC,CAAAA;QACZ,IAAIA,OAAOC,GAAG,CAACC,QAAQ,CAACR,YAAY;YAChCI,WAAW;QACf;IACJ;IAEA,OAAOA;AACX;AAEA,OAAO,MAAMK,aAAa,CAACT;IACvB,OAAO,IAAIU,QAAc,CAACC,SAASC;QAC/B,IAAIb,iBAAiBC,YAAY;YAC7BW;YACA;QACJ;QAEA,MAAME,cAAcX,SAASY,aAAa,CAAC;QAC3CD,YAAYE,YAAY,CAAC,OAAOf;QAChCa,YAAYG,MAAM,GAAG;YACjBL;QACJ;QACAE,YAAYI,OAAO,GAAG;YAClB,MAAMC,QAAQ,IAAIC,MAAM,CAAC,+BAA+B,EAAEnB,WAAW;YACrEF,gBAAgB,uCAAuCoB;YACvDN,OAAOM;QACX;QACAhB,SAASkB,IAAI,CAACC,WAAW,CAACR;IAC9B;AACJ,EAAE;AAEF,OAAO,MAAMS,mBAAmB,CAACC;IAC7B,MAAMV,cAAcX,SAASY,aAAa,CAAC;IAC3CD,YAAYW,WAAW,GAAGD;IAC1BrB,SAASkB,IAAI,CAACC,WAAW,CAACR;AAC9B,EAAE"}
package/dist/log.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare const getErrorMessage: (error: unknown) => string;
2
+ export declare const logUnlayerError: (message: string, error?: unknown) => void;
3
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,WAU7C,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,EAAE,QAAQ,OAAO,SAS/D,CAAC"}
package/dist/log.js ADDED
@@ -0,0 +1,21 @@
1
+ const LOG_PREFIX = '[dte-unlayer]';
2
+ export const getErrorMessage = (error)=>{
3
+ if (error instanceof Error && error.message) {
4
+ return error.message;
5
+ }
6
+ if (typeof error === 'string' && error) {
7
+ return error;
8
+ }
9
+ return 'Unknown Unlayer error';
10
+ };
11
+ export const logUnlayerError = (message, error)=>{
12
+ if (error === undefined) {
13
+ // eslint-disable-next-line no-console
14
+ console.error(LOG_PREFIX, message);
15
+ return;
16
+ }
17
+ // eslint-disable-next-line no-console
18
+ console.error(LOG_PREFIX, message, error);
19
+ };
20
+
21
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/log.ts"],"sourcesContent":["const LOG_PREFIX = '[dte-unlayer]';\n\nexport const getErrorMessage = (error: unknown) => {\n if (error instanceof Error && error.message) {\n return error.message;\n }\n\n if (typeof error === 'string' && error) {\n return error;\n }\n\n return 'Unknown Unlayer error';\n};\n\nexport const logUnlayerError = (message: string, error?: unknown) => {\n if (error === undefined) {\n // eslint-disable-next-line no-console\n console.error(LOG_PREFIX, message);\n return;\n }\n\n // eslint-disable-next-line no-console\n console.error(LOG_PREFIX, message, error);\n};\n"],"names":["LOG_PREFIX","getErrorMessage","error","Error","message","logUnlayerError","undefined","console"],"mappings":"AAAA,MAAMA,aAAa;AAEnB,OAAO,MAAMC,kBAAkB,CAACC;IAC5B,IAAIA,iBAAiBC,SAASD,MAAME,OAAO,EAAE;QACzC,OAAOF,MAAME,OAAO;IACxB;IAEA,IAAI,OAAOF,UAAU,YAAYA,OAAO;QACpC,OAAOA;IACX;IAEA,OAAO;AACX,EAAE;AAEF,OAAO,MAAMG,kBAAkB,CAACD,SAAiBF;IAC7C,IAAIA,UAAUI,WAAW;QACrB,sCAAsC;QACtCC,QAAQL,KAAK,CAACF,YAAYI;QAC1B;IACJ;IAEA,sCAAsC;IACtCG,QAAQL,KAAK,CAACF,YAAYI,SAASF;AACvC,EAAE"}
@@ -0,0 +1,30 @@
1
+ import { UnlayerEditorMergeTagInfo } from './unlayer-interface';
2
+ export interface UnlayerMergeTagLeaf {
3
+ name: string;
4
+ value: string;
5
+ }
6
+ export interface UnlayerMergeTagGroup {
7
+ name: string;
8
+ mergeTags: Record<string, UnlayerMergeTagLeaf>;
9
+ }
10
+ export type UnlayerMergeTagsConfig = Record<string, UnlayerMergeTagLeaf | UnlayerMergeTagGroup>;
11
+ export interface ToUnlayerMergeTagsOptions {
12
+ /**
13
+ * When false, ignore `group` and emit the flat 0.151 shape. Unlayer custom
14
+ * tools fail to register if nested groups are present during createEditor.
15
+ */
16
+ groups?: boolean;
17
+ }
18
+ export interface UnlayerMergeTagsEditor {
19
+ addEventListener(event: string, cb: (arg: any) => void): void;
20
+ setMergeTags(tags: UnlayerMergeTagsConfig): void;
21
+ }
22
+ export declare function isUnlayerMergeTagGroup(entry: UnlayerMergeTagLeaf | UnlayerMergeTagGroup): entry is UnlayerMergeTagGroup;
23
+ export declare const toUnlayerMergeTags: (tags: UnlayerEditorMergeTagInfo[] | undefined, options?: ToUnlayerMergeTagsOptions) => UnlayerMergeTagsConfig | undefined;
24
+ /**
25
+ * Nested Unlayer groups passed to createEditor prevent DTE custom tools from
26
+ * loading in the host app. Apply the 0.151 flat shape at init, then upgrade to
27
+ * grouped submenus once the editor (and customJS tools) are ready.
28
+ */
29
+ export declare const scheduleUnlayerMergeTags: (editor: UnlayerMergeTagsEditor, tags: UnlayerEditorMergeTagInfo[] | undefined) => void;
30
+ //# sourceMappingURL=merge-tags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-tags.d.ts","sourceRoot":"","sources":["../src/merge-tags.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;CAClD;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,oBAAoB,CAAC,CAAC;AAEhG,MAAM,WAAW,yBAAyB;IACtC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,sBAAsB;IACnC,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI,CAAC;IAC9D,YAAY,CAAC,IAAI,EAAE,sBAAsB,GAAG,IAAI,CAAC;CACpD;AAED,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,mBAAmB,GAAG,oBAAoB,GAClD,KAAK,IAAI,oBAAoB,CAE/B;AAYD,eAAO,MAAM,kBAAkB,GAC3B,MAAM,yBAAyB,EAAE,GAAG,SAAS,EAC7C,UAAU,yBAAyB,uCAsCtC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GACjC,QAAQ,sBAAsB,EAC9B,MAAM,yBAAyB,EAAE,GAAG,SAAS,SAwBhD,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { logUnlayerError } from './log';
2
+ export function isUnlayerMergeTagGroup(entry) {
3
+ return 'mergeTags' in entry;
4
+ }
5
+ const toMergeTagKey = (value)=>{
6
+ const key = value.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).join('_');
7
+ return key || value;
8
+ };
9
+ export const toUnlayerMergeTags = (tags, options)=>{
10
+ if (!(tags === null || tags === void 0 ? void 0 : tags.length)) {
11
+ return undefined;
12
+ }
13
+ const groupsEnabled = (options === null || options === void 0 ? void 0 : options.groups) !== false;
14
+ return tags.reduce((out, tag)=>{
15
+ var _tag_group;
16
+ const mergeTag = {
17
+ name: tag.name,
18
+ value: tag.propertyPath
19
+ };
20
+ const tagKey = toMergeTagKey(tag.id);
21
+ const groupName = groupsEnabled ? (_tag_group = tag.group) === null || _tag_group === void 0 ? void 0 : _tag_group.trim() : undefined;
22
+ if (!groupName) {
23
+ out[tagKey] = mergeTag;
24
+ return out;
25
+ }
26
+ const groupKey = toMergeTagKey(groupName);
27
+ const existing = out[groupKey];
28
+ if (existing && isUnlayerMergeTagGroup(existing)) {
29
+ existing.mergeTags[tagKey] = mergeTag;
30
+ return out;
31
+ }
32
+ out[groupKey] = {
33
+ name: groupName,
34
+ mergeTags: {
35
+ [tagKey]: mergeTag
36
+ }
37
+ };
38
+ return out;
39
+ }, {});
40
+ };
41
+ /**
42
+ * Nested Unlayer groups passed to createEditor prevent DTE custom tools from
43
+ * loading in the host app. Apply the 0.151 flat shape at init, then upgrade to
44
+ * grouped submenus once the editor (and customJS tools) are ready.
45
+ */ export const scheduleUnlayerMergeTags = (editor, tags)=>{
46
+ const grouped = toUnlayerMergeTags(tags);
47
+ if (!grouped) {
48
+ return;
49
+ }
50
+ let isApplied = false;
51
+ const apply = ()=>{
52
+ if (isApplied) {
53
+ return;
54
+ }
55
+ try {
56
+ editor.setMergeTags(grouped);
57
+ isApplied = true;
58
+ } catch (error) {
59
+ logUnlayerError('Failed to apply grouped merge tags', error);
60
+ }
61
+ };
62
+ editor.addEventListener('editor:ready', apply);
63
+ editor.addEventListener('design:loaded', apply);
64
+ };
65
+
66
+ //# sourceMappingURL=merge-tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/merge-tags.ts"],"sourcesContent":["import { logUnlayerError } from './log';\nimport { UnlayerEditorMergeTagInfo } from './unlayer-interface';\n\nexport interface UnlayerMergeTagLeaf {\n name: string;\n value: string;\n}\n\nexport interface UnlayerMergeTagGroup {\n name: string;\n mergeTags: Record<string, UnlayerMergeTagLeaf>;\n}\n\nexport type UnlayerMergeTagsConfig = Record<string, UnlayerMergeTagLeaf | UnlayerMergeTagGroup>;\n\nexport interface ToUnlayerMergeTagsOptions {\n /**\n * When false, ignore `group` and emit the flat 0.151 shape. Unlayer custom\n * tools fail to register if nested groups are present during createEditor.\n */\n groups?: boolean;\n}\n\nexport interface UnlayerMergeTagsEditor {\n addEventListener(event: string, cb: (arg: any) => void): void;\n setMergeTags(tags: UnlayerMergeTagsConfig): void;\n}\n\nexport function isUnlayerMergeTagGroup(\n entry: UnlayerMergeTagLeaf | UnlayerMergeTagGroup,\n): entry is UnlayerMergeTagGroup {\n return 'mergeTags' in entry;\n}\n\nconst toMergeTagKey = (value: string) => {\n const key = value\n .toLowerCase()\n .split(/[^a-z0-9]+/)\n .filter(Boolean)\n .join('_');\n\n return key || value;\n};\n\nexport const toUnlayerMergeTags = (\n tags: UnlayerEditorMergeTagInfo[] | undefined,\n options?: ToUnlayerMergeTagsOptions,\n) => {\n if (!tags?.length) {\n return undefined;\n }\n\n const groupsEnabled = options?.groups !== false;\n\n return tags.reduce<UnlayerMergeTagsConfig>((out, tag) => {\n const mergeTag: UnlayerMergeTagLeaf = {\n name: tag.name,\n value: tag.propertyPath,\n };\n const tagKey = toMergeTagKey(tag.id);\n const groupName = groupsEnabled ? tag.group?.trim() : undefined;\n\n if (!groupName) {\n out[tagKey] = mergeTag;\n return out;\n }\n\n const groupKey = toMergeTagKey(groupName);\n const existing = out[groupKey];\n\n if (existing && isUnlayerMergeTagGroup(existing)) {\n existing.mergeTags[tagKey] = mergeTag;\n return out;\n }\n\n out[groupKey] = {\n name: groupName,\n mergeTags: {\n [tagKey]: mergeTag,\n },\n };\n\n return out;\n }, {});\n};\n\n/**\n * Nested Unlayer groups passed to createEditor prevent DTE custom tools from\n * loading in the host app. Apply the 0.151 flat shape at init, then upgrade to\n * grouped submenus once the editor (and customJS tools) are ready.\n */\nexport const scheduleUnlayerMergeTags = (\n editor: UnlayerMergeTagsEditor,\n tags: UnlayerEditorMergeTagInfo[] | undefined,\n) => {\n const grouped = toUnlayerMergeTags(tags);\n\n if (!grouped) {\n return;\n }\n\n let isApplied = false;\n const apply = () => {\n if (isApplied) {\n return;\n }\n\n try {\n editor.setMergeTags(grouped);\n isApplied = true;\n } catch (error: unknown) {\n logUnlayerError('Failed to apply grouped merge tags', error);\n }\n };\n\n editor.addEventListener('editor:ready', apply);\n editor.addEventListener('design:loaded', apply);\n};\n"],"names":["logUnlayerError","isUnlayerMergeTagGroup","entry","toMergeTagKey","value","key","toLowerCase","split","filter","Boolean","join","toUnlayerMergeTags","tags","options","length","undefined","groupsEnabled","groups","reduce","out","tag","mergeTag","name","propertyPath","tagKey","id","groupName","group","trim","groupKey","existing","mergeTags","scheduleUnlayerMergeTags","editor","grouped","isApplied","apply","setMergeTags","error","addEventListener"],"mappings":"AAAA,SAASA,eAAe,QAAQ,QAAQ;AA4BxC,OAAO,SAASC,uBACZC,KAAiD;IAEjD,OAAO,eAAeA;AAC1B;AAEA,MAAMC,gBAAgB,CAACC;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1D;IACJ;IAEAL,OAAOM,gBAAgB,CAAC,gBAAgBH;IACxCH,OAAOM,gBAAgB,CAAC,iBAAiBH;AAC7C,EAAE"}
package/dist/store.d.ts CHANGED
@@ -13,6 +13,9 @@ export declare class UnlayerStore {
13
13
  private isInit;
14
14
  private iframe?;
15
15
  private hasDesign;
16
+ private hasCoreLoaded;
17
+ private hasToolsRegistered;
18
+ private toolsReadyWatchdogId?;
16
19
  private formFieldsByFormId;
17
20
  private formFieldSamples;
18
21
  private onMessageCB?;
@@ -50,6 +53,8 @@ export declare class UnlayerStore {
50
53
  private buildCalculatedFieldDemoData;
51
54
  private sendMessage;
52
55
  private uploadImage;
56
+ private startToolsReadyWatchdog;
57
+ private clearToolsReadyWatchdog;
53
58
  private validateImage;
54
59
  }
55
60
  //# sourceMappingURL=store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAA4C,MAAM,gBAAgB,CAAC;AAElG,OAAO,EACH,aAAa,EACb,QAAQ,EAGX,MAAM,gBAAgB,CAAC;AAUxB,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAyIhG,MAAM,WAAW,uBAAuB;IACpC,kBAAkB,EAAE,OAAO,CAAC;CAC/B;AAmBD,qBAAa,YAAY;IAsBT,QAAQ,CAAC,KAAK,EAAE,wBAAwB;IArBpD,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA0B;IAC1D,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAc;IAElD,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAC,CAAoB;IACnC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,kBAAkB,CAAuC;IACjE,OAA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,OAAO,CAAC,aAAa,CA0EnB;IAEF,OAAO,CAAC,sBAAsB,CAgB5B;IAEF,OAAO,CAAC,0BAA0B,CAyBhC;IAEF,OAAO,CAAC,gBAAgB,CAqCtB;IAEF,OAAO,CAAC,4BAA4B,CAiBlC;IAEF,OAAO,CAAC,WAAW,CAUjB;IAEF,OAAO,CAAC,WAAW,CAuCjB;IAEF,OAAO,CAAC,uBAAuB,CAmB7B;IAEF,OAAO,CAAC,uBAAuB,CAO7B;IAEF,OAAO,CAAC,aAAa,CA+CnB;CACL"}
package/dist/store.js CHANGED
@@ -12,6 +12,7 @@ function _define_property(obj, key, value) {
12
12
  return obj;
13
13
  }
14
14
  import { loadScript } from './loadScript';
15
+ import { logUnlayerError } from './log';
15
16
  import { defaultImageValidation } from './shared/configs';
16
17
  import { unlayerSupportedFonts } from './shared/fonts';
17
18
  import { getFormFieldSampleValue, parseFormFieldKey } from './shared/forms';
@@ -20,6 +21,7 @@ import { unlayerToolsParseTwinKey } from './shared/tools';
20
21
  import { unlayerToolsIterate } from './tools';
21
22
  import { createUnlayerEditor, DesignUpdatedEventType } from './unlayer';
22
23
  const defaultScriptUrl = 'https://editor.unlayer.com/embed.js?2';
24
+ const UNLAYER_TOOLS_READY_TIMEOUT_MS = 30000;
23
25
  const normalizeFontToken = (font)=>font.replace(/["']/g, '').split(',')[0].trim().toLowerCase();
24
26
  const getDesignFontTokens = (value, out)=>{
25
27
  if (!value || typeof value !== 'object') {
@@ -152,6 +154,9 @@ export class UnlayerStore {
152
154
  _define_property(this, "isInit", void 0);
153
155
  _define_property(this, "iframe", void 0);
154
156
  _define_property(this, "hasDesign", void 0);
157
+ _define_property(this, "hasCoreLoaded", void 0);
158
+ _define_property(this, "hasToolsRegistered", void 0);
159
+ _define_property(this, "toolsReadyWatchdogId", void 0);
155
160
  _define_property(this, "formFieldsByFormId", void 0);
156
161
  _define_property(this, "formFieldSamples", void 0);
157
162
  _define_property(this, "onMessageCB", void 0);
@@ -188,27 +193,46 @@ export class UnlayerStore {
188
193
  _define_property(this, "buildCalculatedFieldDemoData", void 0);
189
194
  _define_property(this, "sendMessage", void 0);
190
195
  _define_property(this, "uploadImage", void 0);
196
+ _define_property(this, "startToolsReadyWatchdog", void 0);
197
+ _define_property(this, "clearToolsReadyWatchdog", void 0);
191
198
  _define_property(this, "validateImage", void 0);
192
199
  this.props = props;
193
200
  this.isInit = false;
194
201
  this.hasDesign = false;
202
+ this.hasCoreLoaded = false;
203
+ this.hasToolsRegistered = false;
195
204
  this.formFieldsByFormId = {};
196
205
  this.formFieldSamples = {};
197
206
  this.init = async (container)=>{
198
- var _container_querySelector;
199
207
  if (this.isInit) {
200
208
  return;
201
209
  }
202
210
  this.isInit = true;
203
- setTimeout(()=>window.addEventListener('message', this.onPostMessage));
204
- await loadScript(defaultScriptUrl);
205
- this.editor = createUnlayerEditor(container, this.props);
206
- this.editor.addEventListener('design:loaded', this.onDesignLoaded);
207
- this.editor.addEventListener('design:updated', this.onDesignUpdated);
208
- this.editor.registerCallback('image', this.uploadImage);
209
- this.iframe = (_container_querySelector = container.querySelector(`iframe`)) !== null && _container_querySelector !== void 0 ? _container_querySelector : undefined;
211
+ try {
212
+ var _container_querySelector;
213
+ setTimeout(()=>window.addEventListener('message', this.onPostMessage));
214
+ await loadScript(defaultScriptUrl);
215
+ if (!window.unlayer) {
216
+ throw new Error('Unlayer embed script loaded but window.unlayer is missing');
217
+ }
218
+ this.editor = createUnlayerEditor(container, this.props);
219
+ this.editor.addEventListener('design:loaded', this.onDesignLoaded);
220
+ this.editor.addEventListener('design:updated', this.onDesignUpdated);
221
+ this.editor.registerCallback('image', this.uploadImage);
222
+ this.iframe = (_container_querySelector = container.querySelector(`iframe`)) !== null && _container_querySelector !== void 0 ? _container_querySelector : undefined;
223
+ if (!this.iframe) {
224
+ logUnlayerError('Unlayer iframe was not created after createEditor');
225
+ }
226
+ this.startToolsReadyWatchdog();
227
+ } catch (error) {
228
+ this.isInit = false;
229
+ this.clearToolsReadyWatchdog();
230
+ logUnlayerError('Failed to initialize Unlayer editor', error);
231
+ throw error;
232
+ }
210
233
  };
211
234
  this.destroy = ()=>{
235
+ this.clearToolsReadyWatchdog();
212
236
  window.removeEventListener('message', this.onPostMessage);
213
237
  if (this.editor) {
214
238
  this.editor.removeEventListener('design:loaded', this.onDesignLoaded);
@@ -333,8 +357,11 @@ export class UnlayerStore {
333
357
  }
334
358
  if (type === '--ready' || type === '--registered') {
335
359
  var _this_onReadyCB, _this1;
360
+ this.hasToolsRegistered = true;
361
+ this.clearToolsReadyWatchdog();
336
362
  (_this_onReadyCB = (_this1 = this).onReadyCB) === null || _this_onReadyCB === void 0 ? void 0 : _this_onReadyCB.call(_this1);
337
363
  } else if (type === '--core-loaded') {
364
+ this.hasCoreLoaded = true;
338
365
  const configData = {
339
366
  dummyData: this.props.dummyData,
340
367
  schema: this.props.schema,
@@ -496,6 +523,7 @@ export class UnlayerStore {
496
523
  });
497
524
  if (!res.isValid) {
498
525
  var _this_onErrorCB, _this;
526
+ logUnlayerError(`Image validation failed: ${res.title}`, res.description);
499
527
  (_this_onErrorCB = (_this = this).onErrorCB) === null || _this_onErrorCB === void 0 ? void 0 : _this_onErrorCB.call(_this, res.title, res.description);
500
528
  return;
501
529
  }
@@ -508,14 +536,36 @@ export class UnlayerStore {
508
536
  progress: 100,
509
537
  url
510
538
  });
511
- } catch (unused) {
539
+ } catch (error) {
512
540
  var _this_onErrorCB1, _this1;
541
+ logUnlayerError('Image upload failed', error);
513
542
  (_this_onErrorCB1 = (_this1 = this).onErrorCB) === null || _this_onErrorCB1 === void 0 ? void 0 : _this_onErrorCB1.call(_this1, 'Image upload failed', 'Something went wrong while uploading the image. Please try again or select another image.');
514
543
  done({
515
544
  progress: 100
516
545
  });
517
546
  }
518
547
  };
548
+ this.startToolsReadyWatchdog = ()=>{
549
+ this.clearToolsReadyWatchdog();
550
+ this.toolsReadyWatchdogId = window.setTimeout(()=>{
551
+ var _this_onErrorCB, _this;
552
+ if (this.hasToolsRegistered) {
553
+ return;
554
+ }
555
+ logUnlayerError('Unlayer custom tools did not finish loading. customJS may not have run, or tool registration stalled.', {
556
+ hasCoreLoaded: this.hasCoreLoaded,
557
+ hasToolsRegistered: this.hasToolsRegistered
558
+ });
559
+ (_this_onErrorCB = (_this = this).onErrorCB) === null || _this_onErrorCB === void 0 ? void 0 : _this_onErrorCB.call(_this, 'Editor failed to load custom tools', 'Unlayer custom tools did not finish loading. Check the browser console for [dte-unlayer] details.');
560
+ }, UNLAYER_TOOLS_READY_TIMEOUT_MS);
561
+ };
562
+ this.clearToolsReadyWatchdog = ()=>{
563
+ if (this.toolsReadyWatchdogId === undefined) {
564
+ return;
565
+ }
566
+ window.clearTimeout(this.toolsReadyWatchdogId);
567
+ this.toolsReadyWatchdogId = undefined;
568
+ };
519
569
  this.validateImage = async (file, imageValidation)=>{
520
570
  const { maxFileSize, maxHeight, maxWidth } = imageValidation;
521
571
  if (file.size > maxFileSize) {