@unlayer/types 1.386.1 → 1.386.2
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/README.md +17 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,37 +25,34 @@ const options: UnlayerOptions = {
|
|
|
25
25
|
projectId: 12345,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
//
|
|
29
|
-
function handleDesign(design: JSONTemplate) {
|
|
30
|
-
for (const row of design.body.rows) {
|
|
31
|
-
for (const column of row.columns) {
|
|
32
|
-
for (const content of column.contents) {
|
|
33
|
-
if (content.type === 'button') {
|
|
34
|
-
// content.values type is narrowed to ButtonValues
|
|
35
|
-
console.info(content.values.buttonColors);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Display mode generics
|
|
44
|
-
|
|
45
|
-
Export methods accept a display mode generic that narrows the design types:
|
|
46
|
-
|
|
47
|
-
```ts
|
|
28
|
+
// JSONTemplate types for each Display Mode
|
|
48
29
|
type EmailDesign = JSONTemplate<'email'>; // body.values has preheaderText
|
|
49
30
|
type PopupDesign = JSONTemplate<'popup'>; // body.values has popupPosition
|
|
50
31
|
|
|
32
|
+
// Container and Tool types, e.g. BodyValues, RowValues, ButtonValues, etc
|
|
51
33
|
type EmailBody = BodyValues<'email'>; // has preheaderText, lacks popupPosition
|
|
52
34
|
type PopupBody = BodyValues<'popup'>; // has popupPosition, lacks preheaderText
|
|
53
35
|
|
|
36
|
+
// Export methods accept a display mode generic that narrows the design types:
|
|
54
37
|
declare const unlayer: UnlayerEditor;
|
|
55
38
|
unlayer.exportHtml<'email'>((result) => {
|
|
56
39
|
const html = result.html;
|
|
57
40
|
const preheaderText = result.design.body.values.preheaderText; // typed, email-only field
|
|
58
41
|
});
|
|
42
|
+
|
|
43
|
+
// Example of fully typed json manipulation
|
|
44
|
+
function handleDesign(design: JSONTemplate) {
|
|
45
|
+
for (const row of design.body.rows) {
|
|
46
|
+
for (const column of row.columns) {
|
|
47
|
+
for (const content of column.contents) {
|
|
48
|
+
if (content.type === 'button') {
|
|
49
|
+
// content.values type is narrowed to ButtonValues
|
|
50
|
+
console.info('Button found', content.id, content.values.buttonColors);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
59
56
|
```
|
|
60
57
|
|
|
61
58
|
## License
|