@servicetitan/dte-unlayer 0.34.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/editor.tsx CHANGED
@@ -71,6 +71,12 @@ export const UnlayerEditor = forwardRef<UnlayerRef, UnlayerEditorProps>((props,
71
71
  return () => store.setOnSnapshotSave();
72
72
  }, [props.onSnapshotSave, store]);
73
73
 
74
+ useEffect(() => {
75
+ if (props.opts.newSnapshot) {
76
+ store.addTwin(props.opts.newSnapshot);
77
+ }
78
+ }, [props.opts.newSnapshot, store]);
79
+
74
80
  useEffect(() => {
75
81
  store.setOnReady(props.onReady);
76
82
 
@@ -12,12 +12,12 @@ export const unlayerToolsParseUnitKey = (
12
12
  };
13
13
 
14
14
  export const unlayerToolsGenerateTwinKey = (toolType: string, toolSlug?: string) =>
15
- `:twin:${toolType}:${toolSlug ?? ''}:${Date.now()}${Math.round(Math.random() * 10000)}`;
15
+ `|twin|${toolType}|${toolSlug ?? ''}|${Date.now()}${Math.round(Math.random() * 10000)}`;
16
16
 
17
17
  export const unlayerToolsParseTwinKey = (
18
18
  toolKey: string
19
19
  ): { type: string; slug?: string } | undefined => {
20
- const [, twin, type, slug] = (toolKey ?? '').split(':');
20
+ const [, twin, type, slug] = (toolKey ?? '').split('|');
21
21
 
22
22
  if (twin === 'twin' && type) {
23
23
  return { type, slug: slug || undefined };
package/src/store.ts CHANGED
@@ -94,6 +94,11 @@ export class UnlayerStore {
94
94
  }
95
95
  };
96
96
 
97
+ addTwin = (twin: UnlayerEditorTwin) => {
98
+ this.props.toolTwins?.push(twin);
99
+ this.sendMessage('--add-twin', JSON.parse(JSON.stringify(twin)));
100
+ };
101
+
97
102
  setDesign = (design?: UnlayerDesignFormat) => {
98
103
  if (!this.editor) {
99
104
  return;
@@ -53,6 +53,7 @@ export interface UnlayerEditorCustomTool {
53
53
 
54
54
  export interface CreateUnlayerEditorProps {
55
55
  tools: UnlayerEditorCustomTool[];
56
+ newSnapshot?: UnlayerEditorTwin;
56
57
  toolTwins?: UnlayerEditorTwin[];
57
58
  dummyData?: any;
58
59
  schema?: SchemaObject;
package/src/unlayer.tsx CHANGED
@@ -1,7 +1,6 @@
1
1
  import { editorCoreScript, editorCoreStyles, editorCoreTools } from './editor-core';
2
- import { constGenericsEditor, UnlayerEditorUnit } from './shared/const';
2
+ import { constGenericsEditor } from './shared/const';
3
3
  import { unlayerSupportedFonts } from './shared/fonts';
4
- import { unlayerToolsParseUnitKey } from './shared/tools';
5
4
  import { unlayerCustomToolsGetRegisterUrls } from './tools';
6
5
  import { CreateUnlayerEditorProps } from './unlayer-interface';
7
6
 
@@ -64,16 +63,7 @@ export const versions = {
64
63
 
65
64
  export const createUnlayerEditor = (
66
65
  container: HTMLDivElement,
67
- {
68
- customCSS,
69
- customJS,
70
- latest,
71
- mergeTags,
72
- noCoreTools,
73
- toolTwins,
74
- tools,
75
- units,
76
- }: CreateUnlayerEditorProps
66
+ { customCSS, customJS, latest, mergeTags, noCoreTools, tools, units }: CreateUnlayerEditorProps
77
67
  ): Unlayer => {
78
68
  const customScripts = [
79
69
  editorCoreScript,
@@ -105,28 +95,7 @@ export const createUnlayerEditor = (
105
95
 
106
96
  const acv = constGenericsEditor.adminConfigProperty;
107
97
 
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
+ const unitsConfig = (units ?? []).reduce((out, unit) => {
130
99
  out[`custom#${unit.generic}:unit:${unit.id}`] = {
131
100
  data: {
132
101
  [acv]: unit.values[acv],