|
| 1 | +interface BaseStylingProps { |
| 2 | + grow?: number; |
| 3 | +} |
| 4 | + |
| 5 | +interface BlockStylingProps extends BaseStylingProps { |
| 6 | + borders?: boolean; |
| 7 | + borderRadius?: number; |
| 8 | + borderWidth?: number; |
| 9 | + backgroundColor?: string; |
| 10 | + padding?: number; |
| 11 | +} |
| 12 | + |
| 13 | +interface TextStylingProps extends BaseStylingProps { |
| 14 | + fontSize?: number; |
| 15 | + fontColor?: string; |
| 16 | + bold?: boolean; |
| 17 | + italic?: boolean; |
| 18 | +} |
| 19 | + |
| 20 | +export interface ImageProps extends BaseStylingProps { |
| 21 | + type: "Image"; |
| 22 | + document?: string; // svg image |
| 23 | + data?: string; // base64 image. Will only be read if no svg image is passed |
| 24 | + width?: number; // sets a fixed maximum width |
| 25 | + height?: number; // sets a fixed maximum height |
| 26 | +} |
| 27 | + |
| 28 | +export function svgImage(svgTextData: string, width?: number, height?: number): ImageProps { |
| 29 | + return { |
| 30 | + type: "Image", |
| 31 | + document: svgTextData, |
| 32 | + width, |
| 33 | + height |
| 34 | + }; |
| 35 | +} |
| 36 | + |
| 37 | +export function image(base64Data: string, width?: number, height?: number): ImageProps { |
| 38 | + return { |
| 39 | + type: "Image", |
| 40 | + data: base64Data, |
| 41 | + width, |
| 42 | + height |
| 43 | + }; |
| 44 | +} |
| 45 | + |
| 46 | +export interface ContainerProps extends BlockStylingProps { |
| 47 | + type: "Container"; |
| 48 | + children?: StructurePreviewProps[]; |
| 49 | +} |
| 50 | + |
| 51 | +export function container(styleProps?: BlockStylingProps): (...children: StructurePreviewProps[]) => ContainerProps { |
| 52 | + return (...children: StructurePreviewProps[]) => { |
| 53 | + return { |
| 54 | + type: "Container", |
| 55 | + ...styleProps, |
| 56 | + children |
| 57 | + }; |
| 58 | + }; |
| 59 | +} |
| 60 | + |
| 61 | +export interface RowLayoutStyling extends BlockStylingProps { |
| 62 | + columnSize?: "fixed" | "grow"; |
| 63 | +} |
| 64 | + |
| 65 | +export interface RowLayoutProps extends RowLayoutStyling { |
| 66 | + type: "RowLayout"; |
| 67 | + children: StructurePreviewProps[]; |
| 68 | +} |
| 69 | + |
| 70 | +export function rowLayout(styleProps?: RowLayoutStyling): (...children: StructurePreviewProps[]) => RowLayoutProps { |
| 71 | + return (...children: StructurePreviewProps[]) => { |
| 72 | + return { |
| 73 | + type: "RowLayout", |
| 74 | + ...styleProps, |
| 75 | + children |
| 76 | + }; |
| 77 | + }; |
| 78 | +} |
| 79 | + |
| 80 | +export interface TextProps extends TextStylingProps { |
| 81 | + type: "Text"; |
| 82 | + content: string; |
| 83 | +} |
| 84 | + |
| 85 | +export function text(style?: TextStylingProps): (content: string) => TextProps { |
| 86 | + return (content: string) => { |
| 87 | + return { |
| 88 | + type: "Text", |
| 89 | + ...style, |
| 90 | + content |
| 91 | + }; |
| 92 | + }; |
| 93 | +} |
| 94 | + |
| 95 | +export interface DropZoneProps extends BaseStylingProps { |
| 96 | + type: "DropZone"; |
| 97 | + property: object; |
| 98 | + placeholder?: string; |
| 99 | +} |
| 100 | + |
| 101 | +export function dropzone(property: object, placeholder?: string): DropZoneProps { |
| 102 | + return { |
| 103 | + type: "DropZone", |
| 104 | + placeholder, |
| 105 | + property |
| 106 | + }; |
| 107 | +} |
| 108 | + |
| 109 | +export interface SelectableProps extends BaseStylingProps { |
| 110 | + type: "Selectable"; |
| 111 | + object: object; |
| 112 | + child: StructurePreviewProps; |
| 113 | +} |
| 114 | + |
| 115 | +export function selectable(object: object): (child: StructurePreviewProps) => SelectableProps { |
| 116 | + return (child: StructurePreviewProps) => { |
| 117 | + return { |
| 118 | + type: "Selectable", |
| 119 | + object, |
| 120 | + child |
| 121 | + }; |
| 122 | + }; |
| 123 | +} |
| 124 | + |
| 125 | +export interface DatasourceProps extends BaseStylingProps { |
| 126 | + type: "Datasource"; |
| 127 | + property: object | null; // datasource property object from Values API |
| 128 | + child?: StructurePreviewProps; // any type of preview property component (optional) |
| 129 | +} |
| 130 | + |
| 131 | +export function datasource(property: object | null): (child?: StructurePreviewProps) => DatasourceProps { |
| 132 | + return (child: StructurePreviewProps) => { |
| 133 | + return { |
| 134 | + type: "Datasource", |
| 135 | + property, |
| 136 | + child |
| 137 | + }; |
| 138 | + }; |
| 139 | +} |
| 140 | + |
| 141 | +export type StructurePreviewProps = |
| 142 | + | ImageProps |
| 143 | + | ContainerProps |
| 144 | + | RowLayoutProps |
| 145 | + | TextProps |
| 146 | + | DropZoneProps |
| 147 | + | SelectableProps |
| 148 | + | DatasourceProps; |
0 commit comments