Skip to content

Commit 35cd4b1

Browse files
authored
[WC-1301]: refactor structure preview typings (#14)
2 parents 2085645 + 7895d33 commit 35cd4b1

File tree

5 files changed

+150
-68
lines changed

5 files changed

+150
-68
lines changed

packages/shared/pluggable-widgets-commons/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"precompile": "rimraf ./dist",
2222
"compile": "tsc",
2323
"lint": "eslint --config ../../../.eslintrc.js --ext .jsx,.js,.ts,.tsx src/",
24-
"prepare": "npm run compile",
24+
"prepare": "pnpm run compile",
2525
"test": "pluggable-widgets-tools test:unit:web"
2626
},
2727
"devDependencies": {

packages/shared/pluggable-widgets-commons/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ export * from "./assets";
22
export * from "./functions";
33
export * from "./builders";
44
export * from "./utils";
5-
export * from "./typings";
5+
export * from "./structure-preview-api";
66
export * from "./hooks/useEventCallback";
77
import "./module-defs";
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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;

packages/shared/pluggable-widgets-commons/src/typings/PageEditor.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.

packages/shared/pluggable-widgets-commons/src/typings/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)