Skip to content

Commit 3cfd977

Browse files
author
FalkWolsky
committed
Update Demo Plugin Sources
1 parent 031bc86 commit 3cfd977

File tree

20 files changed

+555
-107
lines changed

20 files changed

+555
-107
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*.tgz
2-
/node_modules
2+
.DS_Store
3+
node_modules
4+
*.zip
Lines changed: 17 additions & 0 deletions
Loading

client/packages/lowcoder-cli-template-typescript/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Lowcoder Comp Playground</title>
7+
<title>Lowcoder Component Plugin Preview</title>
88
<style>
99
#root {
1010
height: 100vh;
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { createRoot } from "react-dom/client";
1+
import { createRoot } from 'react-dom/client';
22
import { CompIDE } from "lowcoder-sdk";
33
import { name, version, lowcoder } from "./package.json";
44
import compMap from "./src/index";
5-
65
import "lowcoder-sdk/dist/style.css";
76

87
function CompDevApp() {
@@ -15,7 +14,6 @@ function CompDevApp() {
1514
/>
1615
);
1716
}
18-
19-
const container = document.querySelector("#root");
20-
const root = createRoot(container!);
17+
const container = document.querySelector("#root") as Element | DocumentFragment;
18+
const root = createRoot(container);
2119
root.render(<CompDevApp />);

client/packages/lowcoder-cli-template-typescript/locales/en.json

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

client/packages/lowcoder-cli-template-typescript/locales/zh_CN.json

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
{
22
"name": "lowcoder-cli-template-typescript",
3-
"version": "0.0.14",
3+
"version": "0.0.15",
44
"type": "module",
55
"scripts": {
66
"start": "vite",
77
"build": "lowcoder-cli build",
88
"build_publish": "lowcoder-cli build --publish"
99
},
1010
"lowcoder": {
11-
"description": "",
11+
"description": "A Demo Hillchart Component Plugin",
1212
"comps": {
13-
"hello_world": {
14-
"name": "__i18n_helloWorldCompName__",
15-
"icon": "./icons/demo-icon.svg"
13+
"hillcharts": {
14+
"name": "Hillcharts Demo",
15+
"icon": "./icons/hills.svg",
16+
"description": "Hillchart Plugin Demo Component"
1617
}
1718
}
1819
},
1920
"devDependencies": {
20-
"lowcoder-cli": "workspace:^",
21-
"lowcoder-sdk": "workspace:^",
22-
"typescript": "^4.8.4",
21+
"lowcoder-cli": "^0.0.30",
22+
"lowcoder-sdk": "^2.1.10",
23+
"react": "^18.2.0",
24+
"react-dom": "^18.2.0",
25+
"react-resize-detector": "^7.0.0",
26+
"typescript": "5.3.3",
2327
"vite": "^4.3.9"
2428
},
2529
"keywords": [
26-
"Lowcoder, Component, Template, Plugin"
30+
"Lowcoder, Component, Template, Plugin, Demonstrator"
2731
],
2832
"license": "MIT"
2933
}

client/packages/lowcoder-cli-template-typescript/src/HelloWorldComp.tsx

Lines changed: 0 additions & 82 deletions
This file was deleted.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import {
2+
UICompBuilder,
3+
NameConfig,
4+
NumberControl,
5+
Section,
6+
withDefault,
7+
withExposingConfigs,
8+
eventHandlerControl,
9+
styleControl,
10+
toJSONObjectArray,
11+
jsonControl,
12+
AutoHeightControl,
13+
EditorContext,
14+
} from "lowcoder-sdk";
15+
16+
import styles from "./styles.module.css";
17+
18+
import { i18nObjs, trans } from "./i18n/comps";
19+
20+
import { Chart } from './vendors'
21+
import { useContext, useEffect, useRef, useState } from "react";
22+
23+
24+
export const CompStyles = [
25+
{
26+
name: "margin",
27+
label: trans("style.margin"),
28+
margin: "margin",
29+
},
30+
{
31+
name: "padding",
32+
label: trans("style.padding"),
33+
padding: "padding",
34+
},
35+
{
36+
name: "textSize",
37+
label: trans("style.textSize"),
38+
textSize: "textSize",
39+
},
40+
{
41+
name: "backgroundColor",
42+
label: trans("style.backgroundColor"),
43+
backgroundColor: "backgroundColor",
44+
},
45+
{
46+
name: "border",
47+
label: trans("style.border"),
48+
border: "border",
49+
},
50+
{
51+
name : "radius",
52+
label : trans("style.borderRadius"),
53+
radius : "radius",
54+
},
55+
{
56+
name : "borderWidth",
57+
label : trans("style.borderWidth"),
58+
borderWidth : "borderWidth",
59+
}
60+
] as const;
61+
62+
63+
64+
// const HillchartsCompBase = new UICompBuilder(childrenMap, (props: any) => {
65+
let HillchartsCompBase = (function () {
66+
67+
const childrenMap = {
68+
styles: styleControl(CompStyles),
69+
autoHeight: withDefault(AutoHeightControl, "auto"),
70+
data: jsonControl(toJSONObjectArray, i18nObjs.defaultData),
71+
onEvent: eventHandlerControl([
72+
{
73+
label: "onChange",
74+
value: "change",
75+
description: "Triggers when Chart data changes",
76+
},
77+
]),
78+
};
79+
80+
return new UICompBuilder(childrenMap, (props: { onEvent: (arg0: string) => void; styles: { backgroundColor: any; border: any; radius: any; borderWidth: any; margin: any; padding: any; textSize: any; }; data: any[] | null | undefined; }) => {
81+
const handleDataChange = () => {
82+
props.onEvent("change");
83+
};
84+
85+
const conRef = useRef<HTMLDivElement>(null);
86+
const [dimensions, setDimensions] = useState({ width: 400, height: 250 });
87+
88+
useEffect(() => {
89+
if (conRef.current) {
90+
setDimensions({
91+
width: conRef.current.clientWidth,
92+
height: conRef.current.clientHeight
93+
});
94+
}
95+
}, []);
96+
97+
return (
98+
<div ref={conRef} className={styles.wrapper} style={{
99+
display: "flex",
100+
justifyContent: "center",
101+
height: `100%`,
102+
width: `100%`,
103+
backgroundColor: `${props.styles.backgroundColor}`,
104+
borderColor: `${props.styles.border}`,
105+
borderRadius: `${props.styles.radius}`,
106+
borderWidth: `${props.styles.borderWidth}`,
107+
margin: `${props.styles.margin}`,
108+
padding: `${props.styles.padding}`,
109+
fontSize: `${props.styles.textSize}`,
110+
}}>
111+
<Chart data={props.data} height={dimensions.height} width={dimensions.width} onDataChange={handleDataChange}/>
112+
</div>
113+
);
114+
})
115+
.setPropertyViewFn((children: any) => {
116+
return (
117+
<>
118+
<Section name="Basic">
119+
{children.data.propertyView({ label: "Data" })}
120+
</Section>
121+
<Section name="Interaction">
122+
{children.onEvent.propertyView()}
123+
</Section>
124+
<Section name="Styles">
125+
{children.autoHeight.getPropertyView()}
126+
{children.styles.getPropertyView()}
127+
</Section>
128+
</>
129+
);
130+
})
131+
.build();
132+
})();
133+
134+
HillchartsCompBase = class extends HillchartsCompBase {
135+
autoHeight(): boolean {
136+
return this.children.autoHeight.getView();
137+
}
138+
};
139+
140+
export default withExposingConfigs(HillchartsCompBase, [
141+
new NameConfig("data", trans("component.data")),
142+
]);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Using Lowcoder Component Plugin
2+
3+
## Prerequisites
4+
Before you start, ensure you have a running Lowcoder installation. Alternatively, you can use it online at [https://app.lowcoder.cloud](https://app.lowcoder.cloud).
5+
6+
## Steps to Use the Plugin
7+
1. **Open the App Editor**: Navigate to the App Editor within your Lowcoder application.
8+
9+
<p align="center">
10+
<img src="https://raw.githubusercontent.com/lowcoder-org/lowcoder-media-assets/main/images/App%20Editor%20%7C%20Main%20Screeen%20clean.png" alt="Lowcoder App Editor">
11+
</p>
12+
13+
1. **Access Components Panel**: In the App Editor, locate the right panel where components are listed.
14+
15+
2. **Switch to Extensions**: Find and switch on the "Extensions" toggle. This option allows you to add additional components to your project.
16+
17+
<p align="center">
18+
<img src="https://raw.githubusercontent.com/lowcoder-org/lowcoder-media-assets/main/images/App%20Editor%20%7C%20Import%20Component%20Plugin%201.png" alt="Lowcoder App Editor">
19+
</p>
20+
21+
3. **Load the Plugin**: Here you have the option to load a Lowcoder Component Plugin from NPM. For example, to load the "hill charts" plugin, type `lowcoder-comp-hillcharts` in the provided field.
22+
23+
<p align="center">
24+
<img src="https://raw.githubusercontent.com/lowcoder-org/lowcoder-media-assets/main/images/App%20Editor%20%7C%20Import%20Component%20Plugin%202.png" alt="Lowcoder App Editor">
25+
</p>
26+
27+
4. **Start Using the Plugin**: After loading the plugin, it will be available for use within your Lowcoder project. You can now integrate and customize the component as per your application's needs.
28+
29+
<p align="center">
30+
<img src="https://raw.githubusercontent.com/lowcoder-org/lowcoder-media-assets/main/images/App%20Editor%20%7C%20Import%20Component%20Plugin%203.png" alt="Lowcoder App Editor">
31+
</p>
32+
33+
<p align="center">
34+
<img src="https://raw.githubusercontent.com/lowcoder-org/lowcoder-media-assets/main/images/App%20Editor%20%7C%20Import%20Component%20Plugin%204.png" alt="Lowcoder App Editor">
35+
</p>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { getI18nObjects, getValueByLocale, Translator } from "lowcoder-sdk";
2+
import * as localeData from "./locales";
3+
import { I18nObjects } from "./locales/types";
4+
5+
export const { trans, language } = new Translator<typeof localeData.en>(
6+
localeData,
7+
REACT_APP_LANGUAGES
8+
);
9+
10+
export const i18nObjs = getI18nObjects<I18nObjects>(localeData, REACT_APP_LANGUAGES);
11+
12+
export function getEchartsLocale() {
13+
return getValueByLocale("EN", (locale) => {
14+
switch (locale.language) {
15+
case "en":
16+
return "EN";
17+
case "zh":
18+
return "ZH";
19+
}
20+
});
21+
}
22+
23+
export function getCalendarLocale() {
24+
switch (language) {
25+
case "zh":
26+
return "zh-cn";
27+
default:
28+
return "en-gb";
29+
}
30+
}

0 commit comments

Comments
 (0)