@servicetitan/dte-unlayer 0.152.0 → 0.154.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/editor.d.ts.map +1 -1
- package/dist/editor.js +25 -10
- package/dist/editor.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/loadScript.d.ts.map +1 -1
- package/dist/loadScript.js +8 -1
- package/dist/loadScript.js.map +1 -1
- package/dist/log.d.ts +3 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +21 -0
- package/dist/log.js.map +1 -0
- package/dist/merge-tags.d.ts +15 -2
- package/dist/merge-tags.d.ts.map +1 -1
- package/dist/merge-tags.js +40 -22
- package/dist/merge-tags.js.map +1 -1
- package/dist/shared/instance-id.d.ts +13 -0
- package/dist/shared/instance-id.d.ts.map +1 -0
- package/dist/shared/instance-id.js +22 -0
- package/dist/shared/instance-id.js.map +1 -0
- package/dist/store.d.ts +19 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +109 -11
- package/dist/store.js.map +1 -1
- package/dist/tools.d.ts +12 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +47 -0
- package/dist/tools.js.map +1 -1
- package/dist/unlayer-interface.d.ts +11 -1
- package/dist/unlayer-interface.d.ts.map +1 -1
- package/dist/unlayer-interface.js.map +1 -1
- package/dist/unlayer.d.ts.map +1 -1
- package/dist/unlayer.js +90 -73
- package/dist/unlayer.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/load-script.test.ts +41 -0
- package/src/__tests__/log.test.ts +44 -0
- package/src/__tests__/merge-tags.test.ts +133 -18
- package/src/__tests__/store.merge-tags.test.ts +186 -0
- package/src/editor.tsx +20 -9
- package/src/index.ts +7 -1
- package/src/loadScript.ts +9 -1
- package/src/log.ts +24 -0
- package/src/merge-tags.ts +59 -25
- package/src/shared/instance-id.ts +23 -0
- package/src/store.ts +128 -10
- package/src/tools.ts +51 -0
- package/src/unlayer-interface.tsx +11 -1
- package/src/unlayer.tsx +81 -61
package/dist/editor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/editor.tsx"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EAOhB,MAAM,OAAO,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(()=>
|
|
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
|
-
|
|
122
|
+
loadError && /*#__PURE__*/ _jsxs("p", {
|
|
111
123
|
className: "c-red-500",
|
|
112
|
-
children:
|
|
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',
|
package/dist/editor.js.map
CHANGED
|
@@ -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.
|
|
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","displayConditionModalP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C,GAAG;QAACpC,MAAMQ,IAAI,CAAC6B,eAAe;QAAE9B;KAAM;IAEtCjB,UAAU;QACNiB,MAAM+B,oBAAoB,CAACtC,MAAMQ,IAAI,CAAC+B,iBAAiB;QAEvD,OAAO,IAAMhC,MAAM+B,oBAAoB;IAC3C,GAAG;QAACtC,MAAMQ,IAAI,CAAC+B,iBAAiB;QAAEhC;KAAM;IAExC,MAAM,EAAEiC,YAAY,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE,GAAGzC;IAExC,qBACI,MAAC0C;QAAID,OAAO;YAAED;YAAWG,SAAS;QAAO;;YACpCvC,2BAAa,MAACwC;gBAAEC,WAAU;;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,7 +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
|
|
6
|
+
export { isUnlayerMergeTagGroup, toUnlayerMergeTags } from './merge-tags';
|
|
7
|
+
export type { ToUnlayerMergeTagsOptions, UnlayerMergeTagGroup, UnlayerMergeTagLeaf, UnlayerMergeTagsConfig, } from './merge-tags';
|
|
7
8
|
export * from './loadScript';
|
|
8
9
|
export * from './shared/const';
|
|
9
10
|
export * from './shared/forms';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC1E,YAAY,EACR,yBAAyB,EACzB,oBAAoB,EACpB,mBAAmB,EACnB,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,7 +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
|
|
6
|
+
export { isUnlayerMergeTagGroup, toUnlayerMergeTags } from './merge-tags';
|
|
7
7
|
export * from './loadScript';
|
|
8
8
|
export * from './shared/const';
|
|
9
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
|
|
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, toUnlayerMergeTags } from './merge-tags';\nexport type {\n ToUnlayerMergeTagsOptions,\n UnlayerMergeTagGroup,\n UnlayerMergeTagLeaf,\n UnlayerMergeTagsConfig,\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","toUnlayerMergeTags","versions","emptyArrayIfNull"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,UAAU;AACxB,cAAc,aAAa;AAC3B,cAAc,qBAAqB;AACnC,cAAc,sBAAsB;AACpC,SAASA,sBAAsB,EAAEC,kBAAkB,QAAQ,eAAe;AAO1E,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"}
|
package/dist/loadScript.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../src/loadScript.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/loadScript.js
CHANGED
|
@@ -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
|
};
|
package/dist/loadScript.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/loadScript.ts"],"sourcesContent":["
|
|
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 @@
|
|
|
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
|
package/dist/log.js.map
ADDED
|
@@ -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"}
|
package/dist/merge-tags.d.ts
CHANGED
|
@@ -5,9 +5,22 @@ export interface UnlayerMergeTagLeaf {
|
|
|
5
5
|
}
|
|
6
6
|
export interface UnlayerMergeTagGroup {
|
|
7
7
|
name: string;
|
|
8
|
-
|
|
8
|
+
/** Nested submenu: leaves and/or further groups (Unlayer supports arbitrary depth). */
|
|
9
|
+
mergeTags: UnlayerMergeTagsConfig;
|
|
9
10
|
}
|
|
10
11
|
export type UnlayerMergeTagsConfig = Record<string, UnlayerMergeTagLeaf | UnlayerMergeTagGroup>;
|
|
12
|
+
export interface ToUnlayerMergeTagsOptions {
|
|
13
|
+
/**
|
|
14
|
+
* When false, ignore `group` and emit the flat 0.151 shape. Unlayer custom
|
|
15
|
+
* tools fail to register if nested groups are present during createEditor.
|
|
16
|
+
*/
|
|
17
|
+
groups?: boolean;
|
|
18
|
+
}
|
|
11
19
|
export declare function isUnlayerMergeTagGroup(entry: UnlayerMergeTagLeaf | UnlayerMergeTagGroup): entry is UnlayerMergeTagGroup;
|
|
12
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Builds Unlayer's `mergeTags` config. With `groups` enabled (default) tags nest under the
|
|
22
|
+
* submenu path in `group`; `UnlayerStore` applies that shape once the editor is ready, since
|
|
23
|
+
* nested groups at `createEditor` time prevent DTE custom tools from loading.
|
|
24
|
+
*/
|
|
25
|
+
export declare const toUnlayerMergeTags: (tags: UnlayerEditorMergeTagInfo[] | undefined, options?: ToUnlayerMergeTagsOptions) => UnlayerMergeTagsConfig | undefined;
|
|
13
26
|
//# sourceMappingURL=merge-tags.d.ts.map
|
package/dist/merge-tags.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-tags.d.ts","sourceRoot":"","sources":["../src/merge-tags.ts"],"names":[],"mappings":"AAAA,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,
|
|
1
|
+
{"version":3,"file":"merge-tags.d.ts","sourceRoot":"","sources":["../src/merge-tags.ts"],"names":[],"mappings":"AAAA,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,uFAAuF;IACvF,SAAS,EAAE,sBAAsB,CAAC;CACrC;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,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,mBAAmB,GAAG,oBAAoB,GAClD,KAAK,IAAI,oBAAoB,CAE/B;AA4CD;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC3B,MAAM,yBAAyB,EAAE,GAAG,SAAS,EAC7C,UAAU,yBAAyB,uCAoBtC,CAAC"}
|
package/dist/merge-tags.js
CHANGED
|
@@ -1,37 +1,55 @@
|
|
|
1
1
|
export function isUnlayerMergeTagGroup(entry) {
|
|
2
2
|
return 'mergeTags' in entry;
|
|
3
3
|
}
|
|
4
|
-
const
|
|
5
|
-
const key =
|
|
6
|
-
return key ||
|
|
4
|
+
const toMergeTagKey = (value)=>{
|
|
5
|
+
const key = value.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).join('_');
|
|
6
|
+
return key || value;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes the host `group` into the submenu path the tag belongs to:
|
|
10
|
+
* `'Custom Fields'` → `['Custom Fields']`, `['Forms', 'Intake']` → `['Forms', 'Intake']`.
|
|
11
|
+
* Blank segments are dropped; an empty result means the tag stays at the top level.
|
|
12
|
+
*/ const toGroupPath = (group)=>{
|
|
13
|
+
const segments = Array.isArray(group) ? group : group === undefined ? [] : [
|
|
14
|
+
group
|
|
15
|
+
];
|
|
16
|
+
return segments.map((segment)=>segment.trim()).filter(Boolean);
|
|
17
|
+
};
|
|
18
|
+
/** Returns the `mergeTags` record of the (possibly nested) group at `path`, creating groups on the way. */ const ensureGroup = (root, path)=>{
|
|
19
|
+
let current = root;
|
|
20
|
+
for (const groupName of path){
|
|
21
|
+
const groupKey = toMergeTagKey(groupName);
|
|
22
|
+
const existing = current[groupKey];
|
|
23
|
+
if (existing && isUnlayerMergeTagGroup(existing)) {
|
|
24
|
+
current = existing.mergeTags;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const created = {
|
|
28
|
+
name: groupName,
|
|
29
|
+
mergeTags: {}
|
|
30
|
+
};
|
|
31
|
+
current[groupKey] = created;
|
|
32
|
+
current = created.mergeTags;
|
|
33
|
+
}
|
|
34
|
+
return current;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Builds Unlayer's `mergeTags` config. With `groups` enabled (default) tags nest under the
|
|
38
|
+
* submenu path in `group`; `UnlayerStore` applies that shape once the editor is ready, since
|
|
39
|
+
* nested groups at `createEditor` time prevent DTE custom tools from loading.
|
|
40
|
+
*/ export const toUnlayerMergeTags = (tags, options)=>{
|
|
9
41
|
if (!(tags === null || tags === void 0 ? void 0 : tags.length)) {
|
|
10
42
|
return undefined;
|
|
11
43
|
}
|
|
44
|
+
const groupsEnabled = (options === null || options === void 0 ? void 0 : options.groups) !== false;
|
|
12
45
|
return tags.reduce((out, tag)=>{
|
|
13
|
-
var _tag_group;
|
|
14
46
|
const mergeTag = {
|
|
15
47
|
name: tag.name,
|
|
16
48
|
value: tag.propertyPath
|
|
17
49
|
};
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return out;
|
|
22
|
-
}
|
|
23
|
-
const groupKey = toMergeTagGroupKey(groupName);
|
|
24
|
-
const existing = out[groupKey];
|
|
25
|
-
if (existing && isUnlayerMergeTagGroup(existing)) {
|
|
26
|
-
existing.mergeTags[tag.id] = mergeTag;
|
|
27
|
-
return out;
|
|
28
|
-
}
|
|
29
|
-
out[groupKey] = {
|
|
30
|
-
name: groupName,
|
|
31
|
-
mergeTags: {
|
|
32
|
-
[tag.id]: mergeTag
|
|
33
|
-
}
|
|
34
|
-
};
|
|
50
|
+
const tagKey = toMergeTagKey(tag.id);
|
|
51
|
+
const groupPath = groupsEnabled ? toGroupPath(tag.group) : [];
|
|
52
|
+
ensureGroup(out, groupPath)[tagKey] = mergeTag;
|
|
35
53
|
return out;
|
|
36
54
|
}, {});
|
|
37
55
|
};
|
package/dist/merge-tags.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/merge-tags.ts"],"sourcesContent":["import { UnlayerEditorMergeTagInfo } from './unlayer-interface';\n\nexport interface UnlayerMergeTagLeaf {\n name: string;\n value: string;\n}\n\nexport interface UnlayerMergeTagGroup {\n name: string;\n
|
|
1
|
+
{"version":3,"sources":["../src/merge-tags.ts"],"sourcesContent":["import { UnlayerEditorMergeTagInfo } from './unlayer-interface';\n\nexport interface UnlayerMergeTagLeaf {\n name: string;\n value: string;\n}\n\nexport interface UnlayerMergeTagGroup {\n name: string;\n /** Nested submenu: leaves and/or further groups (Unlayer supports arbitrary depth). */\n mergeTags: UnlayerMergeTagsConfig;\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 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\n/**\n * Normalizes the host `group` into the submenu path the tag belongs to:\n * `'Custom Fields'` → `['Custom Fields']`, `['Forms', 'Intake']` → `['Forms', 'Intake']`.\n * Blank segments are dropped; an empty result means the tag stays at the top level.\n */\nconst toGroupPath = (group: UnlayerEditorMergeTagInfo['group']): string[] => {\n const segments = Array.isArray(group) ? group : group === undefined ? [] : [group];\n\n return segments.map(segment => segment.trim()).filter(Boolean);\n};\n\n/** Returns the `mergeTags` record of the (possibly nested) group at `path`, creating groups on the way. */\nconst ensureGroup = (root: UnlayerMergeTagsConfig, path: string[]) => {\n let current = root;\n\n for (const groupName of path) {\n const groupKey = toMergeTagKey(groupName);\n const existing = current[groupKey];\n\n if (existing && isUnlayerMergeTagGroup(existing)) {\n current = existing.mergeTags;\n continue;\n }\n\n const created: UnlayerMergeTagGroup = { name: groupName, mergeTags: {} };\n current[groupKey] = created;\n current = created.mergeTags;\n }\n\n return current;\n};\n\n/**\n * Builds Unlayer's `mergeTags` config. With `groups` enabled (default) tags nest under the\n * submenu path in `group`; `UnlayerStore` applies that shape once the editor is ready, since\n * nested groups at `createEditor` time prevent DTE custom tools from loading.\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 groupPath = groupsEnabled ? toGroupPath(tag.group) : [];\n\n ensureGroup(out, groupPath)[tagKey] = mergeTag;\n\n return out;\n }, {});\n};\n"],"names":["isUnlayerMergeTagGroup","entry","toMergeTagKey","value","key","toLowerCase","split","filter","Boolean","join","toGroupPath","group","segments","Array","isArray","undefined","map","segment","trim","ensureGroup","root","path","current","groupName","groupKey","existing","mergeTags","created","name","toUnlayerMergeTags","tags","options","length","groupsEnabled","groups","reduce","out","tag","mergeTag","propertyPath","tagKey","id","groupPath"],"mappings":"AAuBA,OAAO,SAASA,uBACZC,KAAiD;IAEjD,OAAO,eAAeA;AAC1B;AAEA,MAAMC,gBAAgB,CAACC;IACnB,MAAMC,MAAMD,MACPE,WAAW,GACXC,KAAK,CAAC,cACNC,MAAM,CAACC,SACPC,IAAI,CAAC;IAEV,OAAOL,OAAOD;AAClB;AAEA;;;;CAIC,GACD,MAAMO,cAAc,CAACC;IACjB,MAAMC,WAAWC,MAAMC,OAAO,CAACH,SAASA,QAAQA,UAAUI,YAAY,EAAE,GAAG;QAACJ;KAAM;IAElF,OAAOC,SAASI,GAAG,CAACC,CAAAA,UAAWA,QAAQC,IAAI,IAAIX,MAAM,CAACC;AAC1D;AAEA,yGAAyG,GACzG,MAAMW,cAAc,CAACC,MAA8BC;IAC/C,IAAIC,UAAUF;IAEd,KAAK,MAAMG,aAAaF,KAAM;QAC1B,MAAMG,WAAWtB,cAAcqB;QAC/B,MAAME,WAAWH,OAAO,CAACE,SAAS;QAElC,IAAIC,YAAYzB,uBAAuByB,WAAW;YAC9CH,UAAUG,SAASC,SAAS;YAC5B;QACJ;QAEA,MAAMC,UAAgC;YAAEC,MAAML;YAAWG,WAAW,CAAC;QAAE;QACvEJ,OAAO,CAACE,SAAS,GAAGG;QACpBL,UAAUK,QAAQD,SAAS;IAC/B;IAEA,OAAOJ;AACX;AAEA;;;;CAIC,GACD,OAAO,MAAMO,qBAAqB,CAC9BC,MACAC;IAEA,IAAI,EAACD,iBAAAA,2BAAAA,KAAME,MAAM,GAAE;QACf,OAAOjB;IACX;IAEA,MAAMkB,gBAAgBF,CAAAA,oBAAAA,8BAAAA,QAASG,MAAM,MAAK;IAE1C,OAAOJ,KAAKK,MAAM,CAAyB,CAACC,KAAKC;QAC7C,MAAMC,WAAgC;YAClCV,MAAMS,IAAIT,IAAI;YACdzB,OAAOkC,IAAIE,YAAY;QAC3B;QACA,MAAMC,SAAStC,cAAcmC,IAAII,EAAE;QACnC,MAAMC,YAAYT,gBAAgBvB,YAAY2B,IAAI1B,KAAK,IAAI,EAAE;QAE7DQ,YAAYiB,KAAKM,UAAU,CAACF,OAAO,GAAGF;QAEtC,OAAOF;IACX,GAAG,CAAC;AACR,EAAE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom tools whose `values.id` is a per-instance GUID that must stay unique
|
|
3
|
+
* within a design. When such a tool is duplicated (content or row duplicate),
|
|
4
|
+
* Unlayer copies the values as-is, so the host regenerates the id of the copy.
|
|
5
|
+
*/
|
|
6
|
+
export declare const INSTANCE_ID_TOOL_SLUGS: string[];
|
|
7
|
+
/**
|
|
8
|
+
* Generates an RFC 4122 v4 GUID (`3fa85f64-5717-4562-b3fc-2c963f66afa6`) with the
|
|
9
|
+
* platform `crypto.randomUUID()`. It is only exposed in secure contexts (https /
|
|
10
|
+
* localhost); when missing the error is logged and no id is produced.
|
|
11
|
+
*/
|
|
12
|
+
export declare const generateInstanceId: () => string | undefined;
|
|
13
|
+
//# sourceMappingURL=instance-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-id.d.ts","sourceRoot":"","sources":["../../src/shared/instance-id.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,UAAqB,CAAC;AAEzD;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,QAAO,MAAM,GAAG,SAU9C,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom tools whose `values.id` is a per-instance GUID that must stay unique
|
|
3
|
+
* within a design. When such a tool is duplicated (content or row duplicate),
|
|
4
|
+
* Unlayer copies the values as-is, so the host regenerates the id of the copy.
|
|
5
|
+
*/ export const INSTANCE_ID_TOOL_SLUGS = [
|
|
6
|
+
'embedded-image'
|
|
7
|
+
];
|
|
8
|
+
/**
|
|
9
|
+
* Generates an RFC 4122 v4 GUID (`3fa85f64-5717-4562-b3fc-2c963f66afa6`) with the
|
|
10
|
+
* platform `crypto.randomUUID()`. It is only exposed in secure contexts (https /
|
|
11
|
+
* localhost); when missing the error is logged and no id is produced.
|
|
12
|
+
*/ export const generateInstanceId = ()=>{
|
|
13
|
+
var _globalThis_crypto;
|
|
14
|
+
if (typeof ((_globalThis_crypto = globalThis.crypto) === null || _globalThis_crypto === void 0 ? void 0 : _globalThis_crypto.randomUUID) !== 'function') {
|
|
15
|
+
// eslint-disable-next-line no-console
|
|
16
|
+
console.error('crypto.randomUUID is not available (insecure context?), cannot generate an instance id');
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return globalThis.crypto.randomUUID();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=instance-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shared/instance-id.ts"],"sourcesContent":["/**\n * Custom tools whose `values.id` is a per-instance GUID that must stay unique\n * within a design. When such a tool is duplicated (content or row duplicate),\n * Unlayer copies the values as-is, so the host regenerates the id of the copy.\n */\nexport const INSTANCE_ID_TOOL_SLUGS = ['embedded-image'];\n\n/**\n * Generates an RFC 4122 v4 GUID (`3fa85f64-5717-4562-b3fc-2c963f66afa6`) with the\n * platform `crypto.randomUUID()`. It is only exposed in secure contexts (https /\n * localhost); when missing the error is logged and no id is produced.\n */\nexport const generateInstanceId = (): string | undefined => {\n if (typeof globalThis.crypto?.randomUUID !== 'function') {\n // eslint-disable-next-line no-console\n console.error(\n 'crypto.randomUUID is not available (insecure context?), cannot generate an instance id',\n );\n return undefined;\n }\n\n return globalThis.crypto.randomUUID();\n};\n"],"names":["INSTANCE_ID_TOOL_SLUGS","generateInstanceId","globalThis","crypto","randomUUID","console","error","undefined"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,MAAMA,yBAAyB;IAAC;CAAiB,CAAC;AAEzD;;;;CAIC,GACD,OAAO,MAAMC,qBAAqB;QACnBC;IAAX,IAAI,SAAOA,qBAAAA,WAAWC,MAAM,cAAjBD,yCAAAA,mBAAmBE,UAAU,MAAK,YAAY;QACrD,sCAAsC;QACtCC,QAAQC,KAAK,CACT;QAEJ,OAAOC;IACX;IAEA,OAAOL,WAAWC,MAAM,CAACC,UAAU;AACvC,EAAE"}
|
package/dist/store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UnlayerEditorTwin } from './shared/const';
|
|
2
2
|
import { FormFieldInfo, FormInfo } from './shared/forms';
|
|
3
|
-
import { CreateUnlayerEditorProps, UnlayerDesignFormat, UnlayerRef } from './unlayer-interface';
|
|
3
|
+
import { CreateUnlayerEditorProps, UnlayerDesignFormat, UnlayerEditorMergeTagInfo, UnlayerRef } from './unlayer-interface';
|
|
4
4
|
export interface UnlayerDesignChangeInfo {
|
|
5
5
|
isToolsListChanged: boolean;
|
|
6
6
|
}
|
|
@@ -13,8 +13,14 @@ 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;
|
|
21
|
+
private isEditorReady;
|
|
22
|
+
private isMergeTagsApplied;
|
|
23
|
+
private mergeTagsConfig?;
|
|
18
24
|
private onMessageCB?;
|
|
19
25
|
private onChangeCB?;
|
|
20
26
|
private onSnapshotSaveCB?;
|
|
@@ -41,6 +47,16 @@ export declare class UnlayerStore {
|
|
|
41
47
|
sendFormList: (forms: FormInfo[]) => void;
|
|
42
48
|
sendFormFields: (formId: number, fields: FormFieldInfo[]) => void;
|
|
43
49
|
sendCalcFieldLabels: (labels: Record<string, string>) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Replaces the editor's merge tag menu. Nested groups passed to `createEditor` stop DTE
|
|
52
|
+
* custom tools from registering, so init only carries the flat shape and the grouped
|
|
53
|
+
* config is applied here once the editor is ready. A call before that (including the
|
|
54
|
+
* initial props) is parked; a later call replaces it. A failed apply is retried on the
|
|
55
|
+
* next `design:loaded`.
|
|
56
|
+
*/
|
|
57
|
+
setMergeTags: (tags: UnlayerEditorMergeTagInfo[] | undefined) => void;
|
|
58
|
+
private applyMergeTags;
|
|
59
|
+
private onEditorReady;
|
|
44
60
|
private onDesignLoaded;
|
|
45
61
|
private onDesignUpdated;
|
|
46
62
|
private onPostMessage;
|
|
@@ -50,6 +66,8 @@ export declare class UnlayerStore {
|
|
|
50
66
|
private buildCalculatedFieldDemoData;
|
|
51
67
|
private sendMessage;
|
|
52
68
|
private uploadImage;
|
|
69
|
+
private startToolsReadyWatchdog;
|
|
70
|
+
private clearToolsReadyWatchdog;
|
|
53
71
|
private validateImage;
|
|
54
72
|
}
|
|
55
73
|
//# sourceMappingURL=store.d.ts.map
|
package/dist/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAA4C,MAAM,gBAAgB,CAAC;AAElG,OAAO,EACH,aAAa,EACb,QAAQ,EAGX,MAAM,gBAAgB,CAAC;AAUxB,OAAO,EACH,wBAAwB,EACxB,mBAAmB,EACnB,yBAAyB,EACzB,UAAU,EACb,MAAM,qBAAqB,CAAC;AA0I7B,MAAM,WAAW,uBAAuB;IACpC,kBAAkB,EAAE,OAAO,CAAC;CAC/B;AAmBD,qBAAa,YAAY;IA4BT,QAAQ,CAAC,KAAK,EAAE,wBAAwB;IA3BpD,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,aAAa,CAAS;IAC9B,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,oBAAoB,CAAC,CAAS;IACtC,OAAO,CAAC,kBAAkB,CAAuC;IACjE,OAAO,CAAC,gBAAgB,CAA+B;IACvD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,eAAe,CAAC,CAAyB;IAEjD,OAAO,CAAC,WAAW,CAAC,CAAoC;IACxD,O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