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 / extensions.tsx

extensions.tsx in Tableberg – Simple Gutenberg Table Block 1.1.5, at src/extensions.tsx

62 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { ReactNode } from "react";
2 import { applyFilters } from "@wordpress/hooks";
3
4 import { CellElement, CellKey } from "./attributes";
5 import { BindableAttribute } from "./dynamic-data";
6
7 export interface ExtendedElementRendererProps {
8 element: CellElement;
9 cellCoords: CellKey;
10 elementIndex: number;
11 }
12
13 export interface ExtendedElementDefinition {
14 name: string;
15 title: string;
16 icon: ReactNode;
17 blockName: string;
18 create: () => CellElement;
19 render: (props: ExtendedElementRendererProps) => ReactNode;
20 bindableAttributes?: BindableAttribute[];
21 autocompleteLabel?: string;
22 }
23
24 export function getExtendedElementDefinitions(): ExtendedElementDefinition[] {
25 return applyFilters(
26 "tableberg.extendedElementDefinitions",
27 [] as ExtendedElementDefinition[]
28 ) as ExtendedElementDefinition[];
29 }
30
31 export function getExtendedElementDefinition(
32 name: string
33 ): ExtendedElementDefinition | undefined {
34 return getExtendedElementDefinitions().find(
35 definition => definition.name === name
36 );
37 }
38
39 export function createExtendedElement(name: string): CellElement | null {
40 return getExtendedElementDefinition(name)?.create() ?? null;
41 }
42
43 export function renderExtendedElement(
44 element: CellElement,
45 cellCoords: CellKey,
46 elementIndex: number
47 ): ReactNode | null {
48 return (
49 getExtendedElementDefinition(element.name)?.render({
50 element,
51 cellCoords,
52 elementIndex,
53 }) ?? null
54 );
55 }
56
57 export function getExtendedElementBlockName(
58 element: CellElement
59 ): string | undefined {
60 return getExtendedElementDefinition(element.name)?.blockName;
61 }
62