@servicetitan/dte-unlayer 0.91.0 → 0.93.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 +2 -2
- package/dist/editor-core-source.d.ts.map +1 -1
- package/dist/editor-core-source.js +2 -2
- package/dist/editor-core-source.js.map +1 -1
- package/dist/editor.js.map +1 -1
- package/dist/shared/schema.d.ts +6 -2
- package/dist/shared/schema.d.ts.map +1 -1
- package/dist/shared/schema.js +10 -6
- package/dist/shared/schema.js.map +1 -1
- package/dist/unlayer.d.ts.map +1 -1
- package/dist/unlayer.js +33 -3
- package/dist/unlayer.js.map +1 -1
- package/package.json +1 -1
- package/src/editor-core-source.ts +2 -2
- package/src/editor.tsx +1 -1
- package/src/shared/schema.ts +21 -13
- package/src/unlayer.tsx +61 -24
package/src/editor.tsx
CHANGED
package/src/shared/schema.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type SchemaNodeAvailableTypes = 'object' | 'array' | 'string';
|
|
2
|
-
export const schemaNodeAvailableTypes = ['object', 'array', 'string'];
|
|
1
|
+
export type SchemaNodeAvailableTypes = 'object' | 'array' | 'string' | 'number';
|
|
2
|
+
export const schemaNodeAvailableTypes = ['object', 'array', 'string', 'number'];
|
|
3
3
|
|
|
4
4
|
export type SchemaNodeStringSubTypes = 'string' | 'text' | 'html' | 'image';
|
|
5
5
|
export const schemaNodeStringSubTypes = ['string', 'text', 'html', 'image'];
|
|
@@ -35,7 +35,11 @@ export interface SchemaSimpleString extends SchemaNodeProps {
|
|
|
35
35
|
subType?: SchemaNodeStringSubTypes;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export
|
|
38
|
+
export interface SchemaSimpleNumber extends SchemaNodeProps {
|
|
39
|
+
type: 'number';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type SchemaSimple = SchemaSimpleString | SchemaSimpleNumber;
|
|
39
43
|
|
|
40
44
|
export const schemaArrayRootKey = '[]';
|
|
41
45
|
export type SchemaNode = SchemaObject | SchemaArray | SchemaSimple;
|
|
@@ -46,6 +50,8 @@ export const schemaIsArrayOfObjects = (node?: SchemaNode): node is SchemaArray =
|
|
|
46
50
|
export const schemaIsArray = (node?: SchemaNode): node is SchemaArray => node?.type === 'array';
|
|
47
51
|
export const schemaIsString = (node?: SchemaNode): node is SchemaSimpleString =>
|
|
48
52
|
node?.type === 'string';
|
|
53
|
+
export const schemaIsNumber = (node?: SchemaNode): node is SchemaSimpleNumber =>
|
|
54
|
+
node?.type === 'number';
|
|
49
55
|
export const schemaIsStringHtml = (node?: SchemaNode): node is SchemaSimpleString =>
|
|
50
56
|
node?.type === 'string' && node?.subType === 'html';
|
|
51
57
|
|
|
@@ -94,15 +100,15 @@ export const schemaFindParentNode = (schema: SchemaNode, key: string): SchemaNod
|
|
|
94
100
|
return keys.length
|
|
95
101
|
? schemaFindNode(schema, keys.join('.'))
|
|
96
102
|
: schemaIsObject(schema) && schema.properties[key]
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
? schema
|
|
104
|
+
: undefined;
|
|
99
105
|
};
|
|
100
106
|
|
|
101
107
|
export const schemaGetFieldKey = (fullKey: string): string => fullKey.split('.').pop() ?? '';
|
|
102
108
|
|
|
103
109
|
export const schemaBuildNode = (
|
|
104
110
|
type: SchemaNodeAvailableTypes,
|
|
105
|
-
arrayItemType?: SchemaNodeAvailableTypes
|
|
111
|
+
arrayItemType?: SchemaNodeAvailableTypes,
|
|
106
112
|
): SchemaNode => {
|
|
107
113
|
if (type === 'object') {
|
|
108
114
|
return { type: 'object', properties: {}, options: {} };
|
|
@@ -135,7 +141,7 @@ export const schemaBuildMap = (schema: SchemaObject): { map: SchemaMap; dummyDat
|
|
|
135
141
|
nodeKey: string,
|
|
136
142
|
parentNodes: { key: string; title: string }[],
|
|
137
143
|
isArrayed: boolean,
|
|
138
|
-
dummyDataNode: any
|
|
144
|
+
dummyDataNode: any,
|
|
139
145
|
) => {
|
|
140
146
|
const nodeLabel = node.title ?? nodeKey;
|
|
141
147
|
const isArrayRoot = nodeKey === schemaArrayRootKey;
|
|
@@ -148,7 +154,7 @@ export const schemaBuildMap = (schema: SchemaObject): { map: SchemaMap; dummyDat
|
|
|
148
154
|
fieldKey: nodeKey,
|
|
149
155
|
fullKey,
|
|
150
156
|
fullTitle,
|
|
151
|
-
title: node.title ?? isArrayed ? nodeLabel : fullTitle,
|
|
157
|
+
title: (node.title ?? isArrayed) ? nodeLabel : fullTitle,
|
|
152
158
|
node,
|
|
153
159
|
isArrayed,
|
|
154
160
|
isValue: !schemaIsObject(node) && !schemaIsArray(node),
|
|
@@ -174,7 +180,7 @@ export const schemaBuildMap = (schema: SchemaObject): { map: SchemaMap; dummyDat
|
|
|
174
180
|
key,
|
|
175
181
|
nodeKey ? [...parentNodes, { key: nodeKey, title: nodeLabel }] : [],
|
|
176
182
|
isArrayed,
|
|
177
|
-
dummyDataObject
|
|
183
|
+
dummyDataObject,
|
|
178
184
|
);
|
|
179
185
|
}
|
|
180
186
|
} else if (schemaIsArray(node)) {
|
|
@@ -186,16 +192,18 @@ export const schemaBuildMap = (schema: SchemaObject): { map: SchemaMap; dummyDat
|
|
|
186
192
|
schemaArrayRootKey,
|
|
187
193
|
nodeKey ? [...parentNodes, { key: nodeKey, title: nodeLabel }] : [],
|
|
188
194
|
true,
|
|
189
|
-
dummyDataNode[nodeKey]
|
|
195
|
+
dummyDataNode[nodeKey],
|
|
190
196
|
);
|
|
191
197
|
} else if (nodeKey) {
|
|
198
|
+
const sampleData = node?.options?.sampleData;
|
|
192
199
|
const placeholder = node?.options?.placeholder;
|
|
200
|
+
const value = sampleData !== undefined ? sampleData : placeholder;
|
|
193
201
|
|
|
194
|
-
if (
|
|
202
|
+
if (value !== undefined) {
|
|
195
203
|
if (isArrayRoot) {
|
|
196
|
-
dummyDataNode.push?.(
|
|
204
|
+
dummyDataNode.push?.(value);
|
|
197
205
|
} else {
|
|
198
|
-
dummyDataNode[nodeKey] =
|
|
206
|
+
dummyDataNode[nodeKey] = value;
|
|
199
207
|
}
|
|
200
208
|
}
|
|
201
209
|
}
|
package/src/unlayer.tsx
CHANGED
|
@@ -61,8 +61,8 @@ export interface EventDesignUpdated {
|
|
|
61
61
|
* to know correct schema version, open unlayer editor and check output design ('schema' property)
|
|
62
62
|
*/
|
|
63
63
|
export const versions = {
|
|
64
|
-
unlayer: '1.
|
|
65
|
-
schema:
|
|
64
|
+
unlayer: '1.339.0',
|
|
65
|
+
schema: 22,
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
export const handlePreselectTool = (preselectToolSlug: string) => {
|
|
@@ -94,6 +94,29 @@ export const hideUnlayerBodyMenuItem = () => {
|
|
|
94
94
|
`;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
const injectEditorCoreStyles = () => {
|
|
98
|
+
const cssText = editorCoreStyles?.trim();
|
|
99
|
+
|
|
100
|
+
if (!cssText) {
|
|
101
|
+
return '';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return `
|
|
105
|
+
(function () {
|
|
106
|
+
var css = ${JSON.stringify(cssText)};
|
|
107
|
+
var id = 'dte-unlayer-core-styles';
|
|
108
|
+
if (document.getElementById(id)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
var style = document.createElement('style');
|
|
112
|
+
style.id = id;
|
|
113
|
+
style.type = 'text/css';
|
|
114
|
+
style.appendChild(document.createTextNode(css));
|
|
115
|
+
document.head.appendChild(style);
|
|
116
|
+
})();
|
|
117
|
+
`;
|
|
118
|
+
};
|
|
119
|
+
|
|
97
120
|
export const hideMobileTabletPreview = () => `
|
|
98
121
|
[data-key="preview-tablet"],
|
|
99
122
|
[data-key="resolution"],
|
|
@@ -155,11 +178,12 @@ export const createUnlayerEditor = (
|
|
|
155
178
|
noCoreTools,
|
|
156
179
|
tools,
|
|
157
180
|
units,
|
|
158
|
-
}: CreateUnlayerEditorProps
|
|
181
|
+
}: CreateUnlayerEditorProps,
|
|
159
182
|
): Unlayer => {
|
|
160
183
|
const customScripts = [
|
|
161
184
|
editorCoreScript,
|
|
162
185
|
editorCoreTools,
|
|
186
|
+
injectEditorCoreStyles(),
|
|
163
187
|
'window.dteStore.sendData("--core-loaded")',
|
|
164
188
|
...unlayerCustomToolsGetRegisterUrls(tools),
|
|
165
189
|
unlayerCustomToolMetaData(tools),
|
|
@@ -202,26 +226,29 @@ export const createUnlayerEditor = (
|
|
|
202
226
|
value: key.charAt(0).toLowerCase() + key.replace(/ /g, '').slice(1),
|
|
203
227
|
}));
|
|
204
228
|
|
|
205
|
-
const unitsConfig = (units ?? []).reduce(
|
|
206
|
-
out
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
properties: {
|
|
211
|
-
[constGenericsEditor.userConfigProperty]: {
|
|
212
|
-
editor: {
|
|
213
|
-
data: { [acv]: unit.values[acv] },
|
|
214
|
-
},
|
|
229
|
+
const unitsConfig = (units ?? []).reduce(
|
|
230
|
+
(out, unit) => {
|
|
231
|
+
out[`custom#${unit.generic}:unit:${unit.id}`] = {
|
|
232
|
+
data: {
|
|
233
|
+
[acv]: unit.values[acv],
|
|
215
234
|
},
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
235
|
+
properties: {
|
|
236
|
+
[constGenericsEditor.userConfigProperty]: {
|
|
237
|
+
editor: {
|
|
238
|
+
data: { [acv]: unit.values[acv] },
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
[constGenericsEditor.infoDataProperty]: {
|
|
242
|
+
editor: {
|
|
243
|
+
data: { title: unit.title },
|
|
244
|
+
},
|
|
219
245
|
},
|
|
220
246
|
},
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
247
|
+
};
|
|
248
|
+
return out;
|
|
249
|
+
},
|
|
250
|
+
{} as Record<string, any>,
|
|
251
|
+
);
|
|
225
252
|
|
|
226
253
|
const eSignComponentRecipients = {
|
|
227
254
|
properties: {
|
|
@@ -252,18 +279,25 @@ export const createUnlayerEditor = (
|
|
|
252
279
|
preview: true,
|
|
253
280
|
userUploads: false,
|
|
254
281
|
stockImages: false,
|
|
282
|
+
textEditor: {
|
|
283
|
+
tables: true,
|
|
284
|
+
},
|
|
255
285
|
},
|
|
256
|
-
mergeTags: mergeTags?.reduce(
|
|
257
|
-
out
|
|
286
|
+
mergeTags: mergeTags?.reduce(
|
|
287
|
+
(out, tag) => {
|
|
288
|
+
out[tag.id] = { name: tag.name, value: tag.propertyPath };
|
|
258
289
|
|
|
259
|
-
|
|
260
|
-
|
|
290
|
+
return out;
|
|
291
|
+
},
|
|
292
|
+
{} as Record<string, { name: string; value: string }>,
|
|
293
|
+
),
|
|
261
294
|
projectId: 5713,
|
|
262
295
|
version: latest ? undefined : versions.unlayer,
|
|
263
296
|
appearance: {
|
|
264
297
|
theme: 'classic_light',
|
|
265
298
|
},
|
|
266
299
|
tools: {
|
|
300
|
+
'carousel': { enabled: false },
|
|
267
301
|
'button': { enabled: false },
|
|
268
302
|
'html': {
|
|
269
303
|
enabled: enableHTMLEditing,
|
|
@@ -279,6 +313,9 @@ export const createUnlayerEditor = (
|
|
|
279
313
|
},
|
|
280
314
|
},
|
|
281
315
|
},
|
|
316
|
+
'table': {
|
|
317
|
+
enabled: true,
|
|
318
|
+
},
|
|
282
319
|
'menu': { enabled: false },
|
|
283
320
|
'form': { enabled: false },
|
|
284
321
|
...(noCoreTools
|