@servicetitan/dte-unlayer 0.32.0 → 0.34.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-core-source.d.ts +3 -3
- package/dist/editor-core-source.d.ts.map +1 -1
- package/dist/editor-core-source.js +3 -3
- package/dist/editor-core-source.js.map +1 -1
- package/dist/editor.d.ts +2 -0
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +4 -0
- package/dist/editor.js.map +1 -1
- package/dist/store.d.ts +2 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +34 -2
- package/dist/store.js.map +1 -1
- package/dist/unlayer.d.ts +1 -1
- package/dist/unlayer.d.ts.map +1 -1
- package/dist/unlayer.js +21 -2
- package/dist/unlayer.js.map +1 -1
- package/package.json +1 -1
- package/src/editor-core-source.ts +3 -3
- package/src/editor.tsx +13 -0
- package/src/store.ts +23 -1
- package/src/unlayer.tsx +35 -3
package/src/editor.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
useRef,
|
|
8
8
|
useState,
|
|
9
9
|
} from 'react';
|
|
10
|
+
import { UnlayerEditorTwin } from './shared/const';
|
|
10
11
|
import { UnlayerStore, UnlayerDesignChangeInfo } from './store';
|
|
11
12
|
import { UnlayerRef, CreateUnlayerEditorProps } from './unlayer-interface';
|
|
12
13
|
|
|
@@ -16,9 +17,15 @@ export interface UnlayerEditorProps {
|
|
|
16
17
|
opts: CreateUnlayerEditorProps;
|
|
17
18
|
minHeight?: number;
|
|
18
19
|
style?: CSSProperties;
|
|
20
|
+
|
|
19
21
|
onReady?(): void;
|
|
22
|
+
|
|
20
23
|
onChange?(info: UnlayerDesignChangeInfo): void;
|
|
24
|
+
|
|
25
|
+
onSnapshotSave?(tool: UnlayerEditorTwin): void;
|
|
26
|
+
|
|
21
27
|
onImage?(file: File): Promise<{ url: string }>;
|
|
28
|
+
|
|
22
29
|
onMessage?(type: string, data: any): void;
|
|
23
30
|
}
|
|
24
31
|
|
|
@@ -58,6 +65,12 @@ export const UnlayerEditor = forwardRef<UnlayerRef, UnlayerEditorProps>((props,
|
|
|
58
65
|
return () => store.setOnChange();
|
|
59
66
|
}, [props.onChange, store]);
|
|
60
67
|
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
store.setOnSnapshotSave(props.onSnapshotSave);
|
|
70
|
+
|
|
71
|
+
return () => store.setOnSnapshotSave();
|
|
72
|
+
}, [props.onSnapshotSave, store]);
|
|
73
|
+
|
|
61
74
|
useEffect(() => {
|
|
62
75
|
store.setOnReady(props.onReady);
|
|
63
76
|
|
package/src/store.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { loadScript } from './loadScript';
|
|
2
|
-
import { UnlayerEventConfig, UnlayerEventRegister } from './shared/const';
|
|
2
|
+
import { UnlayerEditorTwin, UnlayerEventConfig, UnlayerEventRegister } from './shared/const';
|
|
3
3
|
import { unlayerToolsParseTwinKey } from './shared/tools';
|
|
4
4
|
import { unlayerToolsIterate } from './tools';
|
|
5
5
|
import {
|
|
@@ -43,6 +43,7 @@ export class UnlayerStore {
|
|
|
43
43
|
|
|
44
44
|
private onMessageCB?: (type: string, data: any) => void;
|
|
45
45
|
private onChangeCB?: (info: UnlayerDesignChangeInfo) => void;
|
|
46
|
+
private onSnapshotSaveCB?: (snapshot: UnlayerEditorTwin) => void;
|
|
46
47
|
private onReadyCB?: () => void;
|
|
47
48
|
private onImageCB?: (file: File) => Promise<{ url: string }>;
|
|
48
49
|
|
|
@@ -109,6 +110,10 @@ export class UnlayerStore {
|
|
|
109
110
|
this.onChangeCB = onChange;
|
|
110
111
|
};
|
|
111
112
|
|
|
113
|
+
setOnSnapshotSave = (onSnapshotSave?: UnlayerStore['onSnapshotSaveCB']) => {
|
|
114
|
+
this.onSnapshotSaveCB = onSnapshotSave;
|
|
115
|
+
};
|
|
116
|
+
|
|
112
117
|
setOnReady = (onReady?: UnlayerStore['onReadyCB']) => {
|
|
113
118
|
this.onReadyCB = onReady;
|
|
114
119
|
};
|
|
@@ -205,6 +210,23 @@ export class UnlayerStore {
|
|
|
205
210
|
};
|
|
206
211
|
|
|
207
212
|
this.sendMessage('--register', JSON.parse(JSON.stringify(data)));
|
|
213
|
+
} else if (type === '--save-snapshot') {
|
|
214
|
+
this.editor?.exportHtml(template => {
|
|
215
|
+
unlayerToolsIterate(template.design, tool => {
|
|
216
|
+
if (tool.values?.snapshot?.id === data.id) {
|
|
217
|
+
if (!tool.slug) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
this.onSnapshotSaveCB?.({
|
|
222
|
+
title: '',
|
|
223
|
+
tool: tool.slug,
|
|
224
|
+
values: tool.values,
|
|
225
|
+
});
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
});
|
|
208
230
|
}
|
|
209
231
|
|
|
210
232
|
this.onMessageCB?.(type, data);
|
package/src/unlayer.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { editorCoreScript, editorCoreStyles, editorCoreTools } from './editor-core';
|
|
2
|
-
import { constGenericsEditor } from './shared/const';
|
|
2
|
+
import { constGenericsEditor, UnlayerEditorUnit } from './shared/const';
|
|
3
3
|
import { unlayerSupportedFonts } from './shared/fonts';
|
|
4
|
+
import { unlayerToolsParseUnitKey } from './shared/tools';
|
|
4
5
|
import { unlayerCustomToolsGetRegisterUrls } from './tools';
|
|
5
6
|
import { CreateUnlayerEditorProps } from './unlayer-interface';
|
|
6
7
|
|
|
@@ -63,7 +64,16 @@ export const versions = {
|
|
|
63
64
|
|
|
64
65
|
export const createUnlayerEditor = (
|
|
65
66
|
container: HTMLDivElement,
|
|
66
|
-
{
|
|
67
|
+
{
|
|
68
|
+
customCSS,
|
|
69
|
+
customJS,
|
|
70
|
+
latest,
|
|
71
|
+
mergeTags,
|
|
72
|
+
noCoreTools,
|
|
73
|
+
toolTwins,
|
|
74
|
+
tools,
|
|
75
|
+
units,
|
|
76
|
+
}: CreateUnlayerEditorProps
|
|
67
77
|
): Unlayer => {
|
|
68
78
|
const customScripts = [
|
|
69
79
|
editorCoreScript,
|
|
@@ -94,7 +104,29 @@ export const createUnlayerEditor = (
|
|
|
94
104
|
};
|
|
95
105
|
|
|
96
106
|
const acv = constGenericsEditor.adminConfigProperty;
|
|
97
|
-
|
|
107
|
+
|
|
108
|
+
const unitTwins = toolTwins?.reduce((out, twin) => {
|
|
109
|
+
const isUnit = unlayerToolsParseUnitKey(twin.tool);
|
|
110
|
+
if (isUnit && twin.values.snapshot.id) {
|
|
111
|
+
const originalUnit = units?.find(unit => unit.id === isUnit.id);
|
|
112
|
+
if (!originalUnit) {
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const values = JSON.parse(JSON.stringify(twin.values));
|
|
117
|
+
values.adminConfig = originalUnit.values.adminConfig;
|
|
118
|
+
|
|
119
|
+
out.push({
|
|
120
|
+
id: twin.values.snapshot.id,
|
|
121
|
+
generic: isUnit.generic,
|
|
122
|
+
title: twin.title,
|
|
123
|
+
values,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}, [] as UnlayerEditorUnit[]);
|
|
128
|
+
|
|
129
|
+
const unitsConfig = [...(units ?? []), ...(unitTwins ?? [])].reduce((out, unit) => {
|
|
98
130
|
out[`custom#${unit.generic}:unit:${unit.id}`] = {
|
|
99
131
|
data: {
|
|
100
132
|
[acv]: unit.values[acv],
|