@unlayer/types 1.386.0 → 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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +60 -0
  3. package/package.json +2 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Unlayer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @unlayer/types
2
+
3
+ TypeScript types for the [Unlayer](https://unlayer.com) email editor.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @unlayer/types
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import type {
15
+ UnlayerEditor,
16
+ UnlayerOptions,
17
+ JSONTemplate,
18
+ ButtonValues,
19
+ BodyValues,
20
+ } from '@unlayer/types';
21
+
22
+ // Editor options
23
+ const options: UnlayerOptions = {
24
+ displayMode: 'email',
25
+ projectId: 12345,
26
+ };
27
+
28
+ // JSONTemplate types for each Display Mode
29
+ type EmailDesign = JSONTemplate<'email'>; // body.values has preheaderText
30
+ type PopupDesign = JSONTemplate<'popup'>; // body.values has popupPosition
31
+
32
+ // Container and Tool types, e.g. BodyValues, RowValues, ButtonValues, etc
33
+ type EmailBody = BodyValues<'email'>; // has preheaderText, lacks popupPosition
34
+ type PopupBody = BodyValues<'popup'>; // has popupPosition, lacks preheaderText
35
+
36
+ // Export methods accept a display mode generic that narrows the design types:
37
+ declare const unlayer: UnlayerEditor;
38
+ unlayer.exportHtml<'email'>((result) => {
39
+ const html = result.html;
40
+ const preheaderText = result.design.body.values.preheaderText; // typed, email-only field
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
+ }
56
+ ```
57
+
58
+ ## License
59
+
60
+ MIT
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@unlayer/types",
3
- "version": "1.386.0",
3
+ "version": "1.386.2",
4
+ "license": "MIT",
4
5
  "private": false,
5
6
  "types": "./dist/index.d.ts",
6
7
  "files": [