@unlayer/react-elements 0.1.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/README.md +432 -0
- package/dist/index.cjs +1621 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +852 -0
- package/dist/index.d.ts +852 -0
- package/dist/index.js +1588 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,852 @@
|
|
|
1
|
+
import * as React$1 from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import { ButtonValues } from '@unlayer/types/tools/button';
|
|
4
|
+
export { ButtonValues } from '@unlayer/types/tools/button';
|
|
5
|
+
import { DividerValues } from '@unlayer/types/tools/divider';
|
|
6
|
+
export { DividerValues } from '@unlayer/types/tools/divider';
|
|
7
|
+
import { HeadingValues } from '@unlayer/types/tools/heading';
|
|
8
|
+
export { HeadingValues } from '@unlayer/types/tools/heading';
|
|
9
|
+
import { HtmlValues } from '@unlayer/types/tools/html';
|
|
10
|
+
export { HtmlValues } from '@unlayer/types/tools/html';
|
|
11
|
+
import { ImageValues } from '@unlayer/types/tools/image';
|
|
12
|
+
export { ImageValues } from '@unlayer/types/tools/image';
|
|
13
|
+
import { MenuValues } from '@unlayer/types/tools/menu';
|
|
14
|
+
export { MenuValues } from '@unlayer/types/tools/menu';
|
|
15
|
+
import { ParagraphValues } from '@unlayer/types/tools/paragraph';
|
|
16
|
+
export { ParagraphValues } from '@unlayer/types/tools/paragraph';
|
|
17
|
+
import { SocialValues } from '@unlayer/types/tools/social';
|
|
18
|
+
export { SocialValues } from '@unlayer/types/tools/social';
|
|
19
|
+
import { TableValues } from '@unlayer/types/tools/table';
|
|
20
|
+
export { TableValues } from '@unlayer/types/tools/table';
|
|
21
|
+
import { VideoValues } from '@unlayer/types/tools/video';
|
|
22
|
+
export { VideoValues } from '@unlayer/types/tools/video';
|
|
23
|
+
import { RowValues } from '@unlayer/types/containers/row';
|
|
24
|
+
export { RowValues } from '@unlayer/types/containers/row';
|
|
25
|
+
import { ColumnValues } from '@unlayer/types/containers/column';
|
|
26
|
+
export { ColumnValues } from '@unlayer/types/containers/column';
|
|
27
|
+
import { BodyValues } from '@unlayer/types/containers/body';
|
|
28
|
+
export { BodyValues } from '@unlayer/types/containers/body';
|
|
29
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
30
|
+
export { ContentValues } from '@unlayer/types/containers/content';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Shared Type Definitions
|
|
34
|
+
*
|
|
35
|
+
* Framework-agnostic types used across all Unlayer Elements packages.
|
|
36
|
+
* Value types use Record<string, any> since the runtime semantic-props mapper
|
|
37
|
+
* determines nesting from default-values objects, not from static types.
|
|
38
|
+
* Shared sub-types (Href, Icons, etc.) are inlined here.
|
|
39
|
+
*/
|
|
40
|
+
interface Href {
|
|
41
|
+
name: string;
|
|
42
|
+
attrs?: {
|
|
43
|
+
href?: string;
|
|
44
|
+
target?: string;
|
|
45
|
+
onClick?: unknown;
|
|
46
|
+
class?: string;
|
|
47
|
+
download?: boolean;
|
|
48
|
+
[k: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
values?: {
|
|
51
|
+
[k: string]: string | number | {
|
|
52
|
+
label?: string;
|
|
53
|
+
value: string | number;
|
|
54
|
+
}[];
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
interface Icons {
|
|
58
|
+
iconType: string;
|
|
59
|
+
icons: {
|
|
60
|
+
name: string;
|
|
61
|
+
url: string;
|
|
62
|
+
imgUrl?: string;
|
|
63
|
+
}[];
|
|
64
|
+
editor?: {
|
|
65
|
+
data?: {
|
|
66
|
+
customIcons?: {
|
|
67
|
+
name: string;
|
|
68
|
+
url: string;
|
|
69
|
+
icons: {
|
|
70
|
+
[k: string]: string;
|
|
71
|
+
};
|
|
72
|
+
}[];
|
|
73
|
+
customOptions?: {
|
|
74
|
+
value: string;
|
|
75
|
+
label: string;
|
|
76
|
+
}[];
|
|
77
|
+
showDefaultIcons?: boolean;
|
|
78
|
+
showDefaultOptions?: boolean;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
interface VideoSource {
|
|
83
|
+
loading?: boolean;
|
|
84
|
+
playIconColor?: string;
|
|
85
|
+
playIconSize?: number;
|
|
86
|
+
playIconType?: string;
|
|
87
|
+
thumbnail?: string | null;
|
|
88
|
+
type?: "youtube" | "vimeo";
|
|
89
|
+
url?: string;
|
|
90
|
+
videoId?: string;
|
|
91
|
+
}
|
|
92
|
+
type TextAlign = "left" | "center" | "right" | "justify";
|
|
93
|
+
interface LinkStyle {
|
|
94
|
+
body?: boolean;
|
|
95
|
+
inherit?: boolean;
|
|
96
|
+
linkColor?: string;
|
|
97
|
+
linkHoverColor?: string;
|
|
98
|
+
linkUnderline?: boolean;
|
|
99
|
+
linkHoverUnderline?: boolean;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** A social-media icon entry for the `icons` shorthand prop. */
|
|
103
|
+
interface SocialIcon {
|
|
104
|
+
/** Platform name (e.g., "Facebook", "X", "Instagram") */
|
|
105
|
+
name: string;
|
|
106
|
+
/** Profile or share URL */
|
|
107
|
+
url: string;
|
|
108
|
+
}
|
|
109
|
+
/** A menu item entry for the `items` shorthand prop. */
|
|
110
|
+
interface MenuItem {
|
|
111
|
+
/** Display text */
|
|
112
|
+
text: string;
|
|
113
|
+
/** Link URL */
|
|
114
|
+
href: string;
|
|
115
|
+
/** Link target (default: "_blank") */
|
|
116
|
+
target?: string;
|
|
117
|
+
}
|
|
118
|
+
type RenderMode = "web" | "email" | "document";
|
|
119
|
+
interface DesignContent {
|
|
120
|
+
type: string;
|
|
121
|
+
values: Record<string, any>;
|
|
122
|
+
}
|
|
123
|
+
interface DesignColumn {
|
|
124
|
+
contents: DesignContent[];
|
|
125
|
+
values: Record<string, any>;
|
|
126
|
+
}
|
|
127
|
+
interface DesignRow {
|
|
128
|
+
cells: number[];
|
|
129
|
+
columns: DesignColumn[];
|
|
130
|
+
values: Record<string, any>;
|
|
131
|
+
}
|
|
132
|
+
interface DesignBody {
|
|
133
|
+
rows: DesignRow[];
|
|
134
|
+
values: Record<string, any>;
|
|
135
|
+
}
|
|
136
|
+
interface DesignJSON {
|
|
137
|
+
counters: Record<string, number>;
|
|
138
|
+
body: DesignBody;
|
|
139
|
+
schemaVersion: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
interface HeadConfig {
|
|
143
|
+
hasFeature?: (featureName: string) => boolean;
|
|
144
|
+
getInitialValues?: (containerType: string) => Record<string, any>;
|
|
145
|
+
}
|
|
146
|
+
interface UnlayerConfig {
|
|
147
|
+
cdnBaseUrl: string;
|
|
148
|
+
toSafeHtml?: (text: string, options?: any) => string;
|
|
149
|
+
textDirection?: string;
|
|
150
|
+
mergeTagState?: Record<string, any>;
|
|
151
|
+
mode?: RenderMode;
|
|
152
|
+
headConfig?: HeadConfig;
|
|
153
|
+
}
|
|
154
|
+
declare const DEFAULT_CONFIG: UnlayerConfig;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Column Layouts - All 8 supported column combinations from Unlayer Editor
|
|
158
|
+
*
|
|
159
|
+
* These layouts provide a structured and type-safe way to specify column
|
|
160
|
+
* configurations that match exactly what the Unlayer editor supports.
|
|
161
|
+
*
|
|
162
|
+
* Usage:
|
|
163
|
+
* import { ColumnLayouts } from '@unlayer-internal/shared-elements';
|
|
164
|
+
* <Row layout={ColumnLayouts.TwoEqual}>
|
|
165
|
+
* <Column>...</Column>
|
|
166
|
+
* <Column>...</Column>
|
|
167
|
+
* </Row>
|
|
168
|
+
*/
|
|
169
|
+
interface ColumnLayout {
|
|
170
|
+
name: string;
|
|
171
|
+
description: string;
|
|
172
|
+
cells: number[];
|
|
173
|
+
expectedColumns: number;
|
|
174
|
+
widths: string[];
|
|
175
|
+
}
|
|
176
|
+
declare const ColumnLayouts: {
|
|
177
|
+
OneColumn: ColumnLayout;
|
|
178
|
+
TwoEqual: ColumnLayout;
|
|
179
|
+
TwoWideNarrow: ColumnLayout;
|
|
180
|
+
TwoNarrowWide: ColumnLayout;
|
|
181
|
+
ThreeEqual: ColumnLayout;
|
|
182
|
+
ThreeNarrowWideNarrow: ColumnLayout;
|
|
183
|
+
FourEqual: ColumnLayout;
|
|
184
|
+
FiveEqual: ColumnLayout;
|
|
185
|
+
};
|
|
186
|
+
type ValidColumnLayout = (typeof ColumnLayouts)[keyof typeof ColumnLayouts];
|
|
187
|
+
/**
|
|
188
|
+
* Validates that a layout has the correct number of Column components
|
|
189
|
+
*/
|
|
190
|
+
declare function validateColumnLayout(layout: ColumnLayout, childrenCount: number): void;
|
|
191
|
+
/**
|
|
192
|
+
* Convert an HTML string to a textJson-compatible value.
|
|
193
|
+
*
|
|
194
|
+
* Wraps the HTML in a passthrough format that `generateHtmlFromTextJson`
|
|
195
|
+
* detects and returns directly — avoiding the Lexical headless editor
|
|
196
|
+
* round-trip (HTML → Lexical JSON → HTML) which doesn't work reliably
|
|
197
|
+
* in browser environments.
|
|
198
|
+
*
|
|
199
|
+
* Supports any HTML formatting: bold, italic, underline, strikethrough,
|
|
200
|
+
* code, links, lists, etc.
|
|
201
|
+
*
|
|
202
|
+
* @param html - HTML string with formatting (e.g. `"Hello <b>bold</b>"`)
|
|
203
|
+
* @returns JSON string compatible with Paragraph's `textJson` prop
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* const json = htmlToTextJson('Hello <b>world</b> and <a href="https://example.com">link</a>');
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
declare function htmlToTextJson(html: string): string;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Universal Semantic Props System
|
|
214
|
+
*
|
|
215
|
+
* Automatically flattens nested properties for ALL components
|
|
216
|
+
* No build-time generation needed - pure TypeScript + runtime detection
|
|
217
|
+
*
|
|
218
|
+
* Example:
|
|
219
|
+
* - ButtonValues has: { buttonColors: { color, backgroundColor }, fontSize }
|
|
220
|
+
* - Users can pass: { color: "red", backgroundColor: "blue" } OR { buttonColors: { color: "red" } }
|
|
221
|
+
* - TypeScript provides autocomplete for ALL properties (flat and nested)
|
|
222
|
+
*/
|
|
223
|
+
/**
|
|
224
|
+
* Type utility: Extracts all properties from nested objects
|
|
225
|
+
* This provides TypeScript autocomplete for flat props!
|
|
226
|
+
*/
|
|
227
|
+
type FlattenObjectProps<T> = T extends object ? {
|
|
228
|
+
[K in keyof T]?: T[K] extends object ? T[K] | FlattenObjectProps<T[K]> : T[K];
|
|
229
|
+
} & {
|
|
230
|
+
[K in keyof T as T[K] extends object ? keyof T[K] extends string ? keyof T[K] : never : never]?: any;
|
|
231
|
+
} : T;
|
|
232
|
+
/**
|
|
233
|
+
* Semantic props type for any component.
|
|
234
|
+
* Generic TChildren parameter allows each framework to supply its own child type.
|
|
235
|
+
*/
|
|
236
|
+
type SemanticProps$1<T, TChildren = any> = FlattenObjectProps<T> & {
|
|
237
|
+
children?: TChildren;
|
|
238
|
+
values?: T;
|
|
239
|
+
/** HTML string with inline formatting for Paragraph (e.g. `'Hello <b>bold</b>'`) */
|
|
240
|
+
html?: string;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Type Definitions
|
|
245
|
+
*
|
|
246
|
+
* Re-exports shared types from @unlayer-internal/shared-elements
|
|
247
|
+
* and defines React-specific component prop types.
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Public props for item components.
|
|
252
|
+
* Includes semantic flat props, children, values escape hatch,
|
|
253
|
+
* className, style, and mode. Excludes internal threading props.
|
|
254
|
+
*/
|
|
255
|
+
type ItemProps<TValues> = SemanticProps$1<TValues, React.ReactNode> & {
|
|
256
|
+
className?: string;
|
|
257
|
+
style?: React.CSSProperties;
|
|
258
|
+
mode?: "web" | "email" | "document";
|
|
259
|
+
};
|
|
260
|
+
/** Button component props */
|
|
261
|
+
type ButtonProps = ItemProps<ButtonValues>;
|
|
262
|
+
/** Heading component props */
|
|
263
|
+
type HeadingProps = ItemProps<HeadingValues>;
|
|
264
|
+
/** Divider component props */
|
|
265
|
+
type DividerProps = ItemProps<DividerValues>;
|
|
266
|
+
/** HTML component props */
|
|
267
|
+
type HtmlProps = ItemProps<HtmlValues>;
|
|
268
|
+
/** Paragraph component props */
|
|
269
|
+
type ParagraphProps = ItemProps<ParagraphValues>;
|
|
270
|
+
/** Image component props — supports `alt` shorthand for `altText`. */
|
|
271
|
+
type ImageProps = ItemProps<ImageValues> & {
|
|
272
|
+
/** Alt text (alias for altText) */
|
|
273
|
+
alt?: string;
|
|
274
|
+
};
|
|
275
|
+
/** Social component props — supports `icons` shorthand array. */
|
|
276
|
+
type SocialProps = ItemProps<SocialValues> & {
|
|
277
|
+
/** Social icons shorthand */
|
|
278
|
+
icons?: SocialIcon[];
|
|
279
|
+
/** Icon shape */
|
|
280
|
+
iconType?: "circle" | "rounded" | "squared";
|
|
281
|
+
};
|
|
282
|
+
/** Menu component props — supports `items` shorthand array. */
|
|
283
|
+
type MenuProps = ItemProps<MenuValues> & {
|
|
284
|
+
/** Menu items shorthand */
|
|
285
|
+
items?: MenuItem[];
|
|
286
|
+
};
|
|
287
|
+
/** Table component props — supports `headers` + `data` shorthands. */
|
|
288
|
+
type TableProps = ItemProps<TableValues> & {
|
|
289
|
+
/** Column headers */
|
|
290
|
+
headers?: string[];
|
|
291
|
+
/** Row data as 2D array */
|
|
292
|
+
data?: string[][];
|
|
293
|
+
};
|
|
294
|
+
/** Video component props — supports `videoUrl` shorthand. */
|
|
295
|
+
type VideoProps = ItemProps<VideoValues> & {
|
|
296
|
+
/** YouTube/Vimeo URL (auto-parsed) */
|
|
297
|
+
videoUrl?: string;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Universal Component Factory
|
|
302
|
+
*
|
|
303
|
+
* Eliminates boilerplate by creating components from configuration.
|
|
304
|
+
* This factory handles all the repetitive logic that was duplicated
|
|
305
|
+
* across Button, Heading, Paragraph, etc.
|
|
306
|
+
*/
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Base props that all item components support
|
|
310
|
+
*/
|
|
311
|
+
interface BaseItemComponentProps {
|
|
312
|
+
children?: React__default.ReactNode;
|
|
313
|
+
className?: string;
|
|
314
|
+
style?: React__default.CSSProperties;
|
|
315
|
+
mode?: RenderMode;
|
|
316
|
+
index?: number;
|
|
317
|
+
colIndex?: number;
|
|
318
|
+
cells?: any[];
|
|
319
|
+
bodyValues?: any;
|
|
320
|
+
rowValues?: any;
|
|
321
|
+
/** @internal - Unlayer config threaded from UnlayerProvider */
|
|
322
|
+
_config?: UnlayerConfig;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Props type that combines base props with semantic props
|
|
326
|
+
*/
|
|
327
|
+
type ItemComponentProps<TSemanticProps> = BaseItemComponentProps & TSemanticProps;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* React Semantic Props
|
|
331
|
+
*
|
|
332
|
+
* Re-exports the shared semantic props system with React.ReactNode
|
|
333
|
+
* as the default children type.
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* React-specific SemanticProps — pins TChildren to React.ReactNode
|
|
338
|
+
*/
|
|
339
|
+
type SemanticProps<T> = SemanticProps$1<T, React.ReactNode>;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Button - Universal SSR/Client Component with Automatic Semantic Props
|
|
343
|
+
*
|
|
344
|
+
* ✅ TypeScript provides autocomplete for ALL props (flat and nested)
|
|
345
|
+
* ✅ Works for any nested structure - no configuration needed
|
|
346
|
+
* ✅ Escape hatch: values prop for full control
|
|
347
|
+
* ✅ Works on both server and client
|
|
348
|
+
*
|
|
349
|
+
* @example Flat Props (Simple - most common)
|
|
350
|
+
* ```tsx
|
|
351
|
+
* <Button color="white" backgroundColor="#3b82f6" fontSize="16px">
|
|
352
|
+
* Click me
|
|
353
|
+
* </Button>
|
|
354
|
+
* ```
|
|
355
|
+
*
|
|
356
|
+
* @example Advanced (per-side borders)
|
|
357
|
+
* ```tsx
|
|
358
|
+
* <Button
|
|
359
|
+
* backgroundColor="blue"
|
|
360
|
+
* borderTopColor="red"
|
|
361
|
+
* borderTopWidth="2px"
|
|
362
|
+
* borderBottomWidth="0px"
|
|
363
|
+
* >
|
|
364
|
+
* Click me
|
|
365
|
+
* </Button>
|
|
366
|
+
* ```
|
|
367
|
+
*
|
|
368
|
+
* @example Nested Objects (full control)
|
|
369
|
+
* ```tsx
|
|
370
|
+
* <Button
|
|
371
|
+
* buttonColors={{ backgroundColor: "#3b82f6", hoverBackgroundColor: "#2563eb" }}
|
|
372
|
+
* border={{ borderTopWidth: "2px" }}
|
|
373
|
+
* >
|
|
374
|
+
* Click me
|
|
375
|
+
* </Button>
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
declare const Button: React$1.FC<ItemComponentProps<SemanticProps<ButtonValues>>>;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Divider - Universal SSR/Client Component with Automatic Semantic Props
|
|
382
|
+
*
|
|
383
|
+
* @example Flat Props
|
|
384
|
+
* ```tsx
|
|
385
|
+
* <Divider borderTopWidth="2px" borderTopColor="#ccc" width="80%" />
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* @example Full Control
|
|
389
|
+
* ```tsx
|
|
390
|
+
* <Divider values={{
|
|
391
|
+
* border: { borderTopWidth: "2px", borderTopColor: "#ccc" },
|
|
392
|
+
* width: "80%"
|
|
393
|
+
* }} />
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
declare const Divider: React$1.FC<ItemComponentProps<SemanticProps<DividerValues>>>;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Heading - Universal SSR/Client Component with Semantic Props API
|
|
400
|
+
*
|
|
401
|
+
* ✅ Semantic flat props (level, color, fontSize, etc.)
|
|
402
|
+
* ✅ Escape hatch: values prop for full control
|
|
403
|
+
* ✅ Works on both server and client
|
|
404
|
+
* ✅ Minimal boilerplate using component factory
|
|
405
|
+
*
|
|
406
|
+
* @example Semantic Props (Recommended)
|
|
407
|
+
* ```tsx
|
|
408
|
+
* <Heading level="h1" color="#222" fontSize="32px">
|
|
409
|
+
* Welcome
|
|
410
|
+
* </Heading>
|
|
411
|
+
* ```
|
|
412
|
+
*
|
|
413
|
+
* @example Full Control via Values
|
|
414
|
+
* ```tsx
|
|
415
|
+
* <Heading values={{ headingType: "h1", color: "#222" }}>Welcome</Heading>
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
declare const Heading: React$1.FC<ItemComponentProps<SemanticProps<HeadingValues>>>;
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Html - Universal SSR/Client Component for custom HTML with Automatic Semantic Props
|
|
422
|
+
*
|
|
423
|
+
* @example Flat Props
|
|
424
|
+
* ```tsx
|
|
425
|
+
* <Html html="<div>Custom HTML</div>" />
|
|
426
|
+
* ```
|
|
427
|
+
*
|
|
428
|
+
* @example Full Control
|
|
429
|
+
* ```tsx
|
|
430
|
+
* <Html values={{ html: "<div>Custom HTML</div>" }} />
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
declare const Html: React$1.FC<ItemComponentProps<SemanticProps<HtmlValues>>>;
|
|
434
|
+
|
|
435
|
+
type ImageSemanticProps = SemanticProps<ImageValues> & {
|
|
436
|
+
/** Alt text (alias for altText) */
|
|
437
|
+
alt?: string;
|
|
438
|
+
};
|
|
439
|
+
/**
|
|
440
|
+
* Image - Renders an image element.
|
|
441
|
+
*
|
|
442
|
+
* @example Shorthand
|
|
443
|
+
* ```tsx
|
|
444
|
+
* <Image src="https://example.com/photo.jpg" alt="A photo" />
|
|
445
|
+
* ```
|
|
446
|
+
*
|
|
447
|
+
* @example Full Control
|
|
448
|
+
* ```tsx
|
|
449
|
+
* <Image values={{
|
|
450
|
+
* src: { url: "https://example.com/image.jpg", width: 600 },
|
|
451
|
+
* altText: "Description"
|
|
452
|
+
* }} />
|
|
453
|
+
* ```
|
|
454
|
+
*/
|
|
455
|
+
declare const Image: React$1.FC<ItemComponentProps<ImageSemanticProps>>;
|
|
456
|
+
|
|
457
|
+
type MenuSemanticProps = SemanticProps<MenuValues> & {
|
|
458
|
+
/** Menu items shorthand */
|
|
459
|
+
items?: MenuItem[];
|
|
460
|
+
};
|
|
461
|
+
/**
|
|
462
|
+
* Menu - Renders a navigation menu.
|
|
463
|
+
*
|
|
464
|
+
* @example Shorthand
|
|
465
|
+
* ```tsx
|
|
466
|
+
* <Menu items={[{ text: "Home", href: "/" }, { text: "About", href: "/about" }]} />
|
|
467
|
+
* ```
|
|
468
|
+
*
|
|
469
|
+
* @example Full Control
|
|
470
|
+
* ```tsx
|
|
471
|
+
* <Menu values={{
|
|
472
|
+
* menu: {
|
|
473
|
+
* items: [
|
|
474
|
+
* { key: "home", text: "Home", link: { name: "web", values: { href: "/" } } }
|
|
475
|
+
* ]
|
|
476
|
+
* }
|
|
477
|
+
* }} />
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
declare const Menu: React$1.FC<ItemComponentProps<MenuSemanticProps>>;
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Paragraph - Universal SSR/Client Component with Semantic Props API
|
|
484
|
+
*
|
|
485
|
+
* ✅ Semantic flat props (color, fontSize, textAlign, etc.)
|
|
486
|
+
* ✅ Escape hatch: values prop for full control
|
|
487
|
+
* ✅ Works on both server and client
|
|
488
|
+
* ✅ Minimal boilerplate using component factory
|
|
489
|
+
*
|
|
490
|
+
* @example Semantic Props (Recommended)
|
|
491
|
+
* ```tsx
|
|
492
|
+
* <Paragraph color="#555" fontSize="14px" lineHeight="1.6">
|
|
493
|
+
* Your paragraph content here with <strong>rich text</strong> support
|
|
494
|
+
* </Paragraph>
|
|
495
|
+
* ```
|
|
496
|
+
*
|
|
497
|
+
* @example Full Control via Values
|
|
498
|
+
* ```tsx
|
|
499
|
+
* <Paragraph values={{ textJson: "...", color: "#555" }} />
|
|
500
|
+
* ```
|
|
501
|
+
*/
|
|
502
|
+
declare const Paragraph: React$1.FC<ItemComponentProps<SemanticProps<ParagraphValues>>>;
|
|
503
|
+
|
|
504
|
+
type SocialSemanticProps = SemanticProps<SocialValues> & {
|
|
505
|
+
/** Social icons shorthand (array of {name, url}) */
|
|
506
|
+
icons?: SocialIcon[];
|
|
507
|
+
/** Icon shape */
|
|
508
|
+
iconType?: "circle" | "rounded" | "squared";
|
|
509
|
+
};
|
|
510
|
+
/**
|
|
511
|
+
* Social - Renders social-media icon links.
|
|
512
|
+
*
|
|
513
|
+
* @example Shorthand
|
|
514
|
+
* ```tsx
|
|
515
|
+
* <Social icons={[{ name: "Facebook", url: "https://facebook.com" }]} iconType="rounded" />
|
|
516
|
+
* ```
|
|
517
|
+
*
|
|
518
|
+
* @example Full Control
|
|
519
|
+
* ```tsx
|
|
520
|
+
* <Social values={{
|
|
521
|
+
* icons: { icons: [
|
|
522
|
+
* { name: "Facebook", url: "https://facebook.com/..." },
|
|
523
|
+
* { name: "Twitter", url: "https://twitter.com/..." }
|
|
524
|
+
* ]}
|
|
525
|
+
* }} />
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
declare const Social: React$1.FC<ItemComponentProps<SocialSemanticProps>>;
|
|
529
|
+
|
|
530
|
+
type TableSemanticProps = SemanticProps<TableValues> & {
|
|
531
|
+
/** Column headers as string[] */
|
|
532
|
+
headers?: string[];
|
|
533
|
+
/** Row data as 2D string array */
|
|
534
|
+
data?: string[][];
|
|
535
|
+
};
|
|
536
|
+
/**
|
|
537
|
+
* Table - Renders a data table.
|
|
538
|
+
*
|
|
539
|
+
* @example Shorthand
|
|
540
|
+
* ```tsx
|
|
541
|
+
* <Table
|
|
542
|
+
* headers={["Name", "Email", "Role"]}
|
|
543
|
+
* data={[["Alice", "alice@co.com", "Admin"], ["Bob", "bob@co.com", "User"]]}
|
|
544
|
+
* />
|
|
545
|
+
* ```
|
|
546
|
+
*
|
|
547
|
+
* @example Full Control
|
|
548
|
+
* ```tsx
|
|
549
|
+
* <Table values={{
|
|
550
|
+
* table: {
|
|
551
|
+
* headers: [{ cells: [{ text: "Name" }, { text: "Email" }] }],
|
|
552
|
+
* rows: [{ cells: [{ text: "John" }, { text: "john@example.com" }] }]
|
|
553
|
+
* },
|
|
554
|
+
* enableHeader: true
|
|
555
|
+
* }} />
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
declare const Table: React$1.FC<ItemComponentProps<TableSemanticProps>>;
|
|
559
|
+
|
|
560
|
+
type VideoSemanticProps = SemanticProps<VideoValues> & {
|
|
561
|
+
/** YouTube/Vimeo URL (auto-parsed) */
|
|
562
|
+
videoUrl?: string;
|
|
563
|
+
};
|
|
564
|
+
/**
|
|
565
|
+
* Video - Renders an embedded video player (YouTube/Vimeo).
|
|
566
|
+
*
|
|
567
|
+
* @example Shorthand
|
|
568
|
+
* ```tsx
|
|
569
|
+
* <Video videoUrl="https://www.youtube.com/watch?v=dQw4w9WgXcQ" />
|
|
570
|
+
* ```
|
|
571
|
+
*
|
|
572
|
+
* @example Full Control
|
|
573
|
+
* ```tsx
|
|
574
|
+
* <Video values={{
|
|
575
|
+
* video: { type: "youtube", videoId: "dQw4w9WgXcQ", thumbnail: "..." }
|
|
576
|
+
* }} />
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
declare const Video: React$1.FC<ItemComponentProps<VideoSemanticProps>>;
|
|
580
|
+
|
|
581
|
+
interface RowProps extends SemanticProps<RowValues> {
|
|
582
|
+
children?: React__default.ReactNode;
|
|
583
|
+
layout?: ColumnLayout;
|
|
584
|
+
cells?: number[];
|
|
585
|
+
mode?: RenderMode;
|
|
586
|
+
className?: string;
|
|
587
|
+
style?: React__default.CSSProperties;
|
|
588
|
+
index?: number;
|
|
589
|
+
bodyValues?: any;
|
|
590
|
+
collection?: string;
|
|
591
|
+
/** @internal - Unlayer config threaded from UnlayerProvider via Body */
|
|
592
|
+
_config?: UnlayerConfig;
|
|
593
|
+
}
|
|
594
|
+
declare const Row: React__default.FC<RowProps>;
|
|
595
|
+
|
|
596
|
+
interface ColumnProps extends SemanticProps<ColumnValues> {
|
|
597
|
+
children?: React__default.ReactNode;
|
|
598
|
+
index?: number;
|
|
599
|
+
cells?: number[];
|
|
600
|
+
bodyValues?: any;
|
|
601
|
+
rowValues?: any;
|
|
602
|
+
mode?: RenderMode;
|
|
603
|
+
className?: string;
|
|
604
|
+
style?: React__default.CSSProperties;
|
|
605
|
+
/** @internal - Unlayer config threaded from UnlayerProvider via Body/Row */
|
|
606
|
+
_config?: UnlayerConfig;
|
|
607
|
+
}
|
|
608
|
+
declare const Column: React__default.FC<ColumnProps>;
|
|
609
|
+
|
|
610
|
+
interface BodyProps extends SemanticProps<BodyValues> {
|
|
611
|
+
children?: React__default.ReactNode;
|
|
612
|
+
mode?: RenderMode;
|
|
613
|
+
className?: string;
|
|
614
|
+
style?: React__default.CSSProperties;
|
|
615
|
+
index?: number;
|
|
616
|
+
/** Optional config (replaces context-based config for Server Component usage) */
|
|
617
|
+
config?: Partial<UnlayerConfig>;
|
|
618
|
+
/** Preview text shown in email client inboxes (email mode only) */
|
|
619
|
+
previewText?: string;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Body - Universal Server/Client Component
|
|
623
|
+
*
|
|
624
|
+
* Works in both Server Components and Client Components.
|
|
625
|
+
* In Server Components, pass config as a prop.
|
|
626
|
+
* In Client Components, config can come from UnlayerProvider context or props.
|
|
627
|
+
*
|
|
628
|
+
* @example Server Component
|
|
629
|
+
* ```tsx
|
|
630
|
+
* <Body backgroundColor="#F7F8F9" contentWidth="600px" mode="web">
|
|
631
|
+
* <Row><Column><Paragraph values={{...}} mode="web" /></Column></Row>
|
|
632
|
+
* </Body>
|
|
633
|
+
* ```
|
|
634
|
+
*
|
|
635
|
+
* @example Client Component with Provider
|
|
636
|
+
* ```tsx
|
|
637
|
+
* <UnlayerProvider config={{ mode: "email" }}>
|
|
638
|
+
* <Body>...</Body>
|
|
639
|
+
* </UnlayerProvider>
|
|
640
|
+
* ```
|
|
641
|
+
*/
|
|
642
|
+
declare const Body: React__default.FC<BodyProps>;
|
|
643
|
+
|
|
644
|
+
type EmailProps = Omit<BodyProps, "mode">;
|
|
645
|
+
/**
|
|
646
|
+
* Email - Renders email-client safe HTML (tables for Outlook, Gmail, Yahoo).
|
|
647
|
+
*
|
|
648
|
+
* Thin wrapper around Body with mode locked to "email".
|
|
649
|
+
*
|
|
650
|
+
* @example
|
|
651
|
+
* ```tsx
|
|
652
|
+
* <Email backgroundColor="#f4f4f5" contentWidth="560px" previewText="Welcome!">
|
|
653
|
+
* <Row><Column><Paragraph text="Hello" /></Column></Row>
|
|
654
|
+
* </Email>
|
|
655
|
+
* ```
|
|
656
|
+
*/
|
|
657
|
+
declare function Email(props: EmailProps): react_jsx_runtime.JSX.Element;
|
|
658
|
+
declare namespace Email {
|
|
659
|
+
var displayName: string;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
type PageProps = Omit<BodyProps, "mode">;
|
|
663
|
+
/**
|
|
664
|
+
* Page - Renders with div/flexbox for responsive web display.
|
|
665
|
+
*
|
|
666
|
+
* Thin wrapper around Body with mode locked to "web".
|
|
667
|
+
*
|
|
668
|
+
* @example
|
|
669
|
+
* ```tsx
|
|
670
|
+
* <Page backgroundColor="#ffffff" contentWidth="960px">
|
|
671
|
+
* <Row><Column><Paragraph text="Hello" /></Column></Row>
|
|
672
|
+
* </Page>
|
|
673
|
+
* ```
|
|
674
|
+
*/
|
|
675
|
+
declare function Page(props: PageProps): react_jsx_runtime.JSX.Element;
|
|
676
|
+
declare namespace Page {
|
|
677
|
+
var displayName: string;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
type DocumentProps = Omit<BodyProps, "mode">;
|
|
681
|
+
/**
|
|
682
|
+
* Document - Print-optimized rendering for PDF generation.
|
|
683
|
+
*
|
|
684
|
+
* Thin wrapper around Body with mode locked to "document".
|
|
685
|
+
*
|
|
686
|
+
* @example
|
|
687
|
+
* ```tsx
|
|
688
|
+
* <Document backgroundColor="#ffffff" contentWidth="700px">
|
|
689
|
+
* <Row><Column><Paragraph text="Hello" /></Column></Row>
|
|
690
|
+
* </Document>
|
|
691
|
+
* ```
|
|
692
|
+
*/
|
|
693
|
+
declare function Document(props: DocumentProps): react_jsx_runtime.JSX.Element;
|
|
694
|
+
declare namespace Document {
|
|
695
|
+
var displayName: string;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
interface UnlayerProviderProps {
|
|
699
|
+
config: Partial<UnlayerConfig>;
|
|
700
|
+
children: React__default.ReactNode;
|
|
701
|
+
}
|
|
702
|
+
declare const UnlayerProvider: React__default.FC<UnlayerProviderProps>;
|
|
703
|
+
declare function useUnlayerConfig(): UnlayerConfig;
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Renders an Unlayer element tree to an HTML string.
|
|
707
|
+
*
|
|
708
|
+
* - Passes merged config via the `config` prop (no React context — works in Server Components)
|
|
709
|
+
* - Uses `renderToStaticMarkup` — no React hydration markers, clean HTML for email/PDF
|
|
710
|
+
* - Synchronous
|
|
711
|
+
*
|
|
712
|
+
* @param element - A React element tree (e.g. `<Body><Row>...</Row></Body>`)
|
|
713
|
+
* @param config - Optional config overrides (mode, cdnBaseUrl, etc.)
|
|
714
|
+
* @returns Clean HTML string
|
|
715
|
+
* @throws {Error} If rendering fails, with a helpful message
|
|
716
|
+
*
|
|
717
|
+
* @example
|
|
718
|
+
* ```tsx
|
|
719
|
+
* import { renderToHtml, Body, Row, Column, Paragraph } from "@unlayer/react-elements";
|
|
720
|
+
*
|
|
721
|
+
* const html = renderToHtml(
|
|
722
|
+
* <Body><Row><Column><Paragraph>Hello</Paragraph></Column></Row></Body>,
|
|
723
|
+
* { mode: "email", cdnBaseUrl: "https://my-cdn.com" }
|
|
724
|
+
* );
|
|
725
|
+
* ```
|
|
726
|
+
*/
|
|
727
|
+
declare function renderToHtml(element: React__default.ReactElement, config?: Partial<UnlayerConfig>): string;
|
|
728
|
+
/**
|
|
729
|
+
* Renders an Unlayer element tree to a plain text string.
|
|
730
|
+
*
|
|
731
|
+
* Internally calls `renderToHtml` then converts to plain text using
|
|
732
|
+
* `htmlToPlainText`. Useful for generating the text/plain MIME part
|
|
733
|
+
* of multipart emails (critical for deliverability).
|
|
734
|
+
*
|
|
735
|
+
* @param element - A React element tree (e.g. `<Body><Row>...</Row></Body>`)
|
|
736
|
+
* @param config - Optional config overrides (mode, cdnBaseUrl, etc.)
|
|
737
|
+
* @returns Plain text representation of the email
|
|
738
|
+
*
|
|
739
|
+
* @example
|
|
740
|
+
* ```tsx
|
|
741
|
+
* import { renderToPlainText, Body, Row, Column, Paragraph } from "@unlayer/react-elements";
|
|
742
|
+
*
|
|
743
|
+
* const text = renderToPlainText(
|
|
744
|
+
* <Body mode="email"><Row><Column><Paragraph>Hello World</Paragraph></Column></Row></Body>
|
|
745
|
+
* );
|
|
746
|
+
* // "Hello World"
|
|
747
|
+
* ```
|
|
748
|
+
*/
|
|
749
|
+
declare function renderToPlainText(element: React__default.ReactElement, config?: Partial<UnlayerConfig>): string;
|
|
750
|
+
/**
|
|
751
|
+
* Result of renderToHtmlParts — head and body as separate strings.
|
|
752
|
+
*/
|
|
753
|
+
interface HtmlParts {
|
|
754
|
+
/** `<head>` content: `<style>` blocks with component CSS, optional `<script>` tags */
|
|
755
|
+
head: string;
|
|
756
|
+
/** `<body>` content: the rendered HTML (same output as `renderToHtml`) */
|
|
757
|
+
body: string;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Renders an Unlayer element tree to separate head and body HTML strings.
|
|
761
|
+
*
|
|
762
|
+
* This is the recommended API for sending emails, because email clients need
|
|
763
|
+
* the `<style>` block in `<head>` for hover effects, responsive breakpoints,
|
|
764
|
+
* and font declarations that cannot be expressed as inline styles.
|
|
765
|
+
*
|
|
766
|
+
* - `head` contains `<style>` tags with CSS generated by each component's
|
|
767
|
+
* head function (button hover colors, body fonts, link styles, etc.)
|
|
768
|
+
* - `body` is identical to what `renderToHtml()` returns
|
|
769
|
+
*
|
|
770
|
+
* @param element - A React element tree (e.g. `<Email><Row>...</Row></Email>`)
|
|
771
|
+
* @param config - Optional config overrides (mode, cdnBaseUrl, etc.)
|
|
772
|
+
* @returns `{ head, body }` — drop these into your HTML document template
|
|
773
|
+
*
|
|
774
|
+
* @example
|
|
775
|
+
* ```tsx
|
|
776
|
+
* import { renderToHtmlParts, Email, Row, Column, Button } from "@unlayer/react-elements";
|
|
777
|
+
*
|
|
778
|
+
* const { head, body } = renderToHtmlParts(
|
|
779
|
+
* <Email>
|
|
780
|
+
* <Row><Column><Button>Click</Button></Column></Row>
|
|
781
|
+
* </Email>
|
|
782
|
+
* );
|
|
783
|
+
*
|
|
784
|
+
* const html = `<!DOCTYPE html>
|
|
785
|
+
* <html><head>${head}</head>${body}</html>`;
|
|
786
|
+
* ```
|
|
787
|
+
*/
|
|
788
|
+
declare function renderToHtmlParts(element: React__default.ReactElement, config?: Partial<UnlayerConfig>): HtmlParts;
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* renderToJson — Convert a React element tree to Unlayer's DesignJSON format.
|
|
792
|
+
*
|
|
793
|
+
* Walks the React element tree statically via React.Children and extracts
|
|
794
|
+
* values at each level. No HTML rendering is performed.
|
|
795
|
+
*
|
|
796
|
+
* Produces the { body: { rows, values }, counters, schemaVersion } structure
|
|
797
|
+
* that the Unlayer editor uses, enabling round-tripping: build with React
|
|
798
|
+
* components → export as JSON → load into the Unlayer editor.
|
|
799
|
+
*/
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Convert a React element tree to Unlayer's DesignJSON format.
|
|
803
|
+
*
|
|
804
|
+
* The root element must be a `<Body>`, `<Email>`, `<Page>`, or `<Document>`.
|
|
805
|
+
* The tree is walked statically — no HTML rendering is performed.
|
|
806
|
+
*
|
|
807
|
+
* @param element - A React element tree with Body > Row > Column > Item structure
|
|
808
|
+
* @returns DesignJSON object compatible with the Unlayer editor
|
|
809
|
+
* @throws {Error} If the root element is not a recognized container component
|
|
810
|
+
*
|
|
811
|
+
* @example
|
|
812
|
+
* ```tsx
|
|
813
|
+
* import { renderToJson, Body, Row, Column, Paragraph } from "@unlayer/react-elements";
|
|
814
|
+
*
|
|
815
|
+
* const design = renderToJson(
|
|
816
|
+
* <Body backgroundColor="#ffffff" contentWidth="600px">
|
|
817
|
+
* <Row>
|
|
818
|
+
* <Column>
|
|
819
|
+
* <Paragraph>Hello World</Paragraph>
|
|
820
|
+
* </Column>
|
|
821
|
+
* </Row>
|
|
822
|
+
* </Body>
|
|
823
|
+
* );
|
|
824
|
+
* ```
|
|
825
|
+
*/
|
|
826
|
+
/**
|
|
827
|
+
* Convert a single `<Row>` element to Unlayer's row JSON format.
|
|
828
|
+
*
|
|
829
|
+
* Use this when targeting a Block Editor, which works with individual rows
|
|
830
|
+
* rather than full design JSON. For full designs, use `renderToJson` instead.
|
|
831
|
+
*
|
|
832
|
+
* @param element - A React element tree with Row > Column > Item structure
|
|
833
|
+
* @returns A DesignRow object compatible with the Unlayer block editor
|
|
834
|
+
* @throws {Error} If the element is not a `<Row>`
|
|
835
|
+
*
|
|
836
|
+
* @example
|
|
837
|
+
* ```tsx
|
|
838
|
+
* import { renderRowToJson, Row, Column, Paragraph } from "@unlayer/react-elements";
|
|
839
|
+
*
|
|
840
|
+
* const row = renderRowToJson(
|
|
841
|
+
* <Row>
|
|
842
|
+
* <Column>
|
|
843
|
+
* <Paragraph>Hello World</Paragraph>
|
|
844
|
+
* </Column>
|
|
845
|
+
* </Row>
|
|
846
|
+
* );
|
|
847
|
+
* ```
|
|
848
|
+
*/
|
|
849
|
+
declare function renderRowToJson(element: React__default.ReactElement): DesignRow;
|
|
850
|
+
declare function renderToJson(element: React__default.ReactElement): DesignJSON;
|
|
851
|
+
|
|
852
|
+
export { Body, Button, type ButtonProps, Column, type ColumnLayout, ColumnLayouts, DEFAULT_CONFIG, type DesignBody, type DesignColumn, type DesignContent, type DesignJSON, type DesignRow, Divider, type DividerProps, Document, type DocumentProps, Email, type EmailProps, Heading, type HeadingProps, type Href, Html, type HtmlParts, type HtmlProps, type Icons, Image, type ImageProps, type LinkStyle, Menu, type MenuItem, type MenuProps, Page, type PageProps, Paragraph, type ParagraphProps, Row, type RowProps, Social, type SocialIcon, type SocialProps, Table, type TableProps, type TextAlign, type UnlayerConfig, UnlayerProvider, type UnlayerProviderProps, type ValidColumnLayout, Video, type VideoProps, type VideoSource, htmlToTextJson, renderRowToJson, renderToHtml, renderToHtmlParts, renderToJson, renderToPlainText, useUnlayerConfig, validateColumnLayout };
|