PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
tableberg / src / elements / index.ts

index.ts in Tableberg – Simple Gutenberg Table Block 1.1.5, at src/elements/index.ts

64 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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