| 1 |
import { ElementBindings } from "../dynamic-data/types"; |
| 2 |
import { CellElement, CellKey, ElementTypes } from "../attributes"; |
| 3 |
import { textAttributeDefaults } from "../blocks/text/element"; |
| 4 |
import { buttonAttrDefaults } from "../blocks/button/element"; |
| 5 |
import { imageAttrDefaults } from "../blocks/image/element"; |
| 6 |
import { listAttrDefaults } from "../blocks/list/element"; |
| 7 |
import { createExtendedElement } from "../extensions"; |
| 8 |
|
| 9 |
export type { TextElementType, TextElementAttributes } from "../blocks/text/element"; |
| 10 |
export { TextElement, textAttributeDefaults } from "../blocks/text/element"; |
| 11 |
|
| 12 |
export type { ButtonElementType, ButtonElementAttributes } from "../blocks/button/element"; |
| 13 |
export { ButtonElement, buttonAttrDefaults } from "../blocks/button/element"; |
| 14 |
|
| 15 |
export type { ImageElementType, ImageElementAttributes } from "../blocks/image/element"; |
| 16 |
export { ImageElement, imageAttrDefaults } from "../blocks/image/element"; |
| 17 |
|
| 18 |
export type { ListElementType, ListElementAttributes } from "../blocks/list/element"; |
| 19 |
export { ListElement, listAttrDefaults } from "../blocks/list/element"; |
| 20 |
|
| 21 |
export interface ElementRendererProps<T> { |
| 22 |
attributes: T; |
| 23 |
bindings?: ElementBindings; |
| 24 |
cellCoords: CellKey; |
| 25 |
elementIndex: number; |
| 26 |
} |
| 27 |
|
| 28 |
export function getElementTextContent(element: CellElement): string { |
| 29 |
switch (element.name) { |
| 30 |
case "text": |
| 31 |
case "button": |
| 32 |
return element.attributes.content || ""; |
| 33 |
default: |
| 34 |
return ""; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
export function createElement(name: ElementTypes): CellElement | null { |
| 39 |
switch (name) { |
| 40 |
case "text": |
| 41 |
return { |
| 42 |
name: "text", |
| 43 |
attributes: { ...textAttributeDefaults }, |
| 44 |
}; |
| 45 |
case "button": |
| 46 |
return { |
| 47 |
name: "button", |
| 48 |
attributes: { ...buttonAttrDefaults }, |
| 49 |
}; |
| 50 |
case "image": |
| 51 |
return { |
| 52 |
name: "image", |
| 53 |
attributes: { ...imageAttrDefaults }, |
| 54 |
}; |
| 55 |
case "list": |
| 56 |
return { |
| 57 |
name: "list", |
| 58 |
attributes: { ...listAttrDefaults }, |
| 59 |
}; |
| 60 |
default: |
| 61 |
return createExtendedElement(name); |
| 62 |
} |
| 63 |
} |
| 64 |
|