bi-sdk-react 0.0.53 → 0.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/es/js/bi-sdk.es.js +55 -41
  2. package/dist/types/components/context/GlobalDatasetContext.d.ts +7 -0
  3. package/dist/types/components/context/PageContext.d.ts +6 -3
  4. package/dist/types/components/hooks/method.d.ts +1 -0
  5. package/dist/types/components/panel/GlobalDatasetPanel.d.ts +2 -0
  6. package/dist/types/components/plugins/@antd/item-props/TextProps.d.ts +1 -0
  7. package/dist/types/components/plugins/@antd/items/TextRender.d.ts +3 -4
  8. package/dist/types/components/typing.d.ts +9 -1
  9. package/dist/umd/js/bi-sdk.umd.min.js +55 -41
  10. package/package.json +1 -1
  11. package/src/components/PageDesigner.tsx +8 -0
  12. package/src/components/context/GlobalDatasetContext.tsx +52 -0
  13. package/src/components/context/PageContext.tsx +31 -8
  14. package/src/components/hooks/event.ts +6 -1
  15. package/src/components/hooks/method.ts +2 -2
  16. package/src/components/icon/IconFont.tsx +1 -1
  17. package/src/components/panel/EventPanel.tsx +1 -0
  18. package/src/components/panel/GlobalDatasetPanel.tsx +165 -0
  19. package/src/components/panel/VariablesPanel.tsx +4 -1
  20. package/src/components/plugins/@antd/index.ts +10 -0
  21. package/src/components/plugins/@antd/item-props/EchartsProps.tsx +20 -2
  22. package/src/components/plugins/@antd/item-props/HtmlProps.tsx +19 -2
  23. package/src/components/plugins/@antd/item-props/TextProps.tsx +12 -0
  24. package/src/components/plugins/@antd/items/DrawerRender.tsx +8 -0
  25. package/src/components/plugins/@antd/items/EchartsRender.tsx +6 -2
  26. package/src/components/plugins/@antd/items/HtmlRender.tsx +14 -5
  27. package/src/components/plugins/@antd/items/ModalRender.tsx +7 -0
  28. package/src/components/plugins/@antd/items/TextRender.tsx +21 -6
  29. package/src/components/typing.ts +9 -1
  30. package/src/example.tsx +9 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bi-sdk-react",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/umd/js/bi-sdk.umd.min.js",
@@ -45,6 +45,7 @@ import {
45
45
  } from "./typing";
46
46
  import { uuid } from "./utils";
47
47
  import { EventPanel } from "./panel/EventPanel";
48
+ import { GlobalDatasetPanel } from "./panel/GlobalDatasetPanel";
48
49
 
49
50
  export type PageDesignerProps = {
50
51
  pageId: string;
@@ -266,6 +267,7 @@ export const PageDesigner = React.forwardRef<any, PageDesignerProps>(
266
267
  | "env"
267
268
  | "code"
268
269
  | "dataset"
270
+ | "global-dataset"
269
271
  >("component");
270
272
  const [rightPanelActiveKey, setRightPanelActiveKey] = useState<
271
273
  "ai" | "props" | "cascade" | "events"
@@ -635,6 +637,11 @@ export const PageDesigner = React.forwardRef<any, PageDesignerProps>(
635
637
  <IconFont type="icon-variable" />
636
638
  </Radio.Button>
637
639
  </Tooltip>
640
+ <Tooltip title="全局数据集" placement="right">
641
+ <Radio.Button value="global-dataset">
642
+ <IconFont type="icon-datasource-g" />
643
+ </Radio.Button>
644
+ </Tooltip>
638
645
  <Tooltip title="源码" placement="right">
639
646
  <Radio.Button value="code">
640
647
  <IconFont type="icon-json" />
@@ -666,6 +673,7 @@ export const PageDesigner = React.forwardRef<any, PageDesignerProps>(
666
673
  renderNode={datasetPanel}
667
674
  />
668
675
  )}
676
+ {leftPanelActiveKey === "global-dataset" && <GlobalDatasetPanel />}
669
677
  </div>
670
678
  </div>
671
679
  <div className="center" style={{ flex: "1 1 auto" }}>
@@ -0,0 +1,52 @@
1
+ import { useContext, useEffect, useMemo } from "react";
2
+ import { PageContext } from "./PageContext";
3
+
4
+ type GlobalDatasetContextType = {
5
+ datasetId: string;
6
+ var: string;
7
+ dependencies: string[];
8
+ };
9
+
10
+ const GlobalDatasetContext: React.FC<GlobalDatasetContextType> = ({
11
+ datasetId,
12
+ var: varName,
13
+ dependencies,
14
+ }) => {
15
+ const { schema, getGlobalEnv, fetch, env, updateGlobalVar } = useContext(PageContext);
16
+ const dataset = schema?.datasets?.find((item) => item.id === datasetId);
17
+ if (!dataset || !fetch?.dataset) {
18
+ return <></>;
19
+ }
20
+
21
+ const params = useMemo(() => {
22
+ return dependencies.reduce(
23
+ (prev, cur) => {
24
+ const value = env.global[cur];
25
+ return [...prev, value];
26
+ },
27
+ [] as any[],
28
+ );
29
+ }, [dependencies, env.global]);
30
+
31
+ const handleFetch = async () => {
32
+ const queryParams = dependencies.reduce(
33
+ (prev, cur) => {
34
+ const value = getGlobalEnv(cur);
35
+ return { ...prev, [cur]: value };
36
+ },
37
+ {} as Record<string, any>,
38
+ );
39
+ const { code, data } = await fetch?.dataset?.(datasetId, queryParams, dataset.aiPrompt);
40
+ if (code === "OK") {
41
+ updateGlobalVar(varName, data);
42
+ }
43
+ };
44
+
45
+ useEffect(() => {
46
+ handleFetch();
47
+ }, [datasetId, fetch, ...params]);
48
+
49
+ return <></>;
50
+ };
51
+
52
+ export default GlobalDatasetContext;
@@ -10,6 +10,7 @@ import {
10
10
  PluginType,
11
11
  SchemaItemType,
12
12
  } from "../typing";
13
+ import GlobalDatasetContext from "./GlobalDatasetContext";
13
14
 
14
15
  type InitCallbackParams = {
15
16
  id: string;
@@ -60,9 +61,12 @@ type PageContextType = {
60
61
  ) => any;
61
62
  getVars: (id: string) => Record<string, any>;
62
63
  setVar: (item: SchemaItemType, key: string, value: any) => void;
63
- getGlobalVar: (key: string) => string | undefined | null;
64
- setGlobalVar: (key: string, value: any) => void;
64
+ env: EnvType;
65
+ getGlobalEnv: (key: string) => string | undefined | null;
66
+ setGlobalEnv: (key: string, value: any) => void;
65
67
  setItemData?: (id: string, data: any) => void;
68
+ globalVars: Record<string, any>;
69
+ updateGlobalVar: (key: string, value: any) => void;
66
70
  };
67
71
 
68
72
  export const PageContext = createContext<PageContextType>({
@@ -97,9 +101,12 @@ export const PageContext = createContext<PageContextType>({
97
101
  handleMethod: () => {},
98
102
  getVars: () => ({}),
99
103
  setVar: () => {},
100
- getGlobalVar: () => undefined,
101
- setGlobalVar: () => {},
104
+ env: { global: {}, local: {} },
105
+ getGlobalEnv: () => undefined,
106
+ setGlobalEnv: () => {},
102
107
  setItemData: () => {},
108
+ globalVars: {},
109
+ updateGlobalVar: () => {},
103
110
  });
104
111
 
105
112
  type PageProviderProps = React.PropsWithChildren<
@@ -133,6 +140,7 @@ export const PageProvider: React.FC<PageProviderProps> = ({
133
140
  setItemData,
134
141
  }) => {
135
142
  const [deviceWidth, setDeviceWidth] = useState<number>(0);
143
+ const [globalVars, setGlobalVars] = useState<Record<string, any>>({});
136
144
  const updateSelectedItem = (props?: Partial<SchemaItemType> | null) => {
137
145
  setSelectedItem?.(Object.assign(selectedItem!, props || {}));
138
146
  setSchema?.({ ...schema });
@@ -218,10 +226,14 @@ export const PageProvider: React.FC<PageProviderProps> = ({
218
226
  next.local[id][key] = value;
219
227
  });
220
228
  };
221
- const getGlobalVar = (key: string) => env.global[key];
222
- const setGlobalVar = (key: string, value: any) => {
229
+ const getGlobalEnv = (key: string) => env.global[key];
230
+ const setGlobalEnv = (key: string, value: any) => {
223
231
  setEnv((e: EnvType) => ({ ...e, global: { ...e.global, [key]: value } }));
224
232
  };
233
+ const updateGlobalVar = (key: string, value: any) => {
234
+ // console.log("updateGlobalVar", key, value);
235
+ setGlobalVars((c) => ({ ...c, [key]: value }));
236
+ };
225
237
 
226
238
  useEffect(() => {
227
239
  const nextGlobal: Record<string, any> = {};
@@ -260,12 +272,23 @@ export const PageProvider: React.FC<PageProviderProps> = ({
260
272
  handleMethod,
261
273
  getVars,
262
274
  setVar,
263
- getGlobalVar,
264
- setGlobalVar,
275
+ env,
276
+ getGlobalEnv,
277
+ setGlobalEnv,
265
278
  setItemData,
279
+ globalVars,
280
+ updateGlobalVar,
266
281
  }}
267
282
  >
268
283
  {children}
284
+ {schema.datasets?.map((item, index) => (
285
+ <GlobalDatasetContext
286
+ key={index}
287
+ datasetId={item.id}
288
+ var={item.key!}
289
+ dependencies={item.dependencies || []}
290
+ />
291
+ ))}
269
292
  </PageContext.Provider>
270
293
  );
271
294
  };
@@ -10,7 +10,7 @@ export const useEvent = (item: SchemaItemType) => {
10
10
  {} as Record<string, string>,
11
11
  );
12
12
 
13
- const { callMethod } = useMethods(item);
13
+ const { callMethod, updateEnv } = useMethods(item);
14
14
 
15
15
  const handleEvent = (eventName: string, arg?: any) => {
16
16
  const script = events[eventName];
@@ -27,6 +27,7 @@ export const useEvent = (item: SchemaItemType) => {
27
27
  "Number",
28
28
  "Boolean",
29
29
  "callMethod",
30
+ "updateEnv",
30
31
  "param",
31
32
  `
32
33
  "use strict";
@@ -37,6 +38,9 @@ export const useEvent = (item: SchemaItemType) => {
37
38
  const require = undefined;
38
39
  const module = undefined;
39
40
  const exports = undefined;
41
+ const cookie = undefined;
42
+ const localStorage = undefined;
43
+ const sessionStorage = undefined;
40
44
  ${script}
41
45
  `,
42
46
  );
@@ -50,6 +54,7 @@ export const useEvent = (item: SchemaItemType) => {
50
54
  Number,
51
55
  Boolean,
52
56
  callMethod,
57
+ updateEnv,
53
58
  {
54
59
  item,
55
60
  sourceId: item.id,
@@ -3,11 +3,11 @@ import { PageContext } from "../context/PageContext";
3
3
  import { SchemaItemType } from "../typing";
4
4
 
5
5
  export const useMethods = (item: SchemaItemType) => {
6
- const { handleMethod } = useContext(PageContext);
6
+ const { handleMethod, setGlobalEnv: updateEnv } = useContext(PageContext);
7
7
 
8
8
  const callMethod = (targetId: string, methodName: string, arg?: any) => {
9
9
  return handleMethod(item, targetId, methodName, arg);
10
10
  };
11
11
 
12
- return { callMethod };
12
+ return { callMethod, updateEnv };
13
13
  };
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import { createFromIconfontCN } from "@ant-design/icons";
3
3
 
4
4
  const IconFontCN = createFromIconfontCN({
5
- scriptUrl: "https://at.alicdn.com/t/c/font_5072483_8ex0em5yn29.js",
5
+ scriptUrl: "https://at.alicdn.com/t/c/font_5072483_30lly4gkmhf.js",
6
6
  });
7
7
 
8
8
  export type IconFontProps = {
@@ -178,6 +178,7 @@ export const EventPanel: React.FC = ({}) => {
178
178
  module, exports, cookie, localStorage, sessionStorage。
179
179
  </li>
180
180
  <li>组件方法调用:callMethod(targetId, methodName, arg)。</li>
181
+ <li>环境变量设置:updateEnv(key, value)。</li>
181
182
  </ul>
182
183
  </div>
183
184
  </div>
@@ -0,0 +1,165 @@
1
+ import { DeleteOutlined } from "@ant-design/icons";
2
+ import { Card, Drawer, Form, Input, Popconfirm, Select, Space } from "antd";
3
+ import React, { useContext, useMemo, useState } from "react";
4
+ import styled from "styled-components";
5
+ import { PageContext } from "../context/PageContext";
6
+ import { PaneHeader } from "./PaneHeader";
7
+
8
+ const Root = styled.div`
9
+ display: flex;
10
+ flex-direction: column;
11
+ height: 100%;
12
+ .body {
13
+ flex: 1 1 auto;
14
+ display: flex;
15
+ flex-direction: column;
16
+ gap: 12px;
17
+ padding: 12px;
18
+ }
19
+ `;
20
+
21
+ export const GlobalDatasetPanel: React.FC = () => {
22
+ const [visible, setVisible] = useState(false);
23
+ const [form] = Form.useForm();
24
+
25
+ const { schema, datasetSelector, setSchema } = useContext(PageContext);
26
+
27
+ const datasets = useMemo(() => schema?.datasets || [], [schema]);
28
+ const variables = useMemo(() => schema.variables || [], [schema.variables]);
29
+
30
+ return (
31
+ <Root>
32
+ <PaneHeader
33
+ title="全局数据集"
34
+ extra={
35
+ <Space>
36
+ <a
37
+ className="toolbar"
38
+ onClick={() => {
39
+ form.resetFields();
40
+ setVisible(true);
41
+ }}
42
+ >
43
+ +
44
+ </a>
45
+ </Space>
46
+ }
47
+ />
48
+ <div className="body beautified_scrollbar">
49
+ {datasets.map((dataset, index) => (
50
+ <Card
51
+ key={index}
52
+ title={dataset.name}
53
+ size="small"
54
+ variant="outlined"
55
+ extra={
56
+ <Popconfirm
57
+ title="确认删除吗?"
58
+ onConfirm={() => {
59
+ setSchema((schema) => ({
60
+ ...schema,
61
+ datasets: datasets.filter((d) => d.id !== dataset.id),
62
+ }));
63
+ }}
64
+ >
65
+ <a className="toolbar">
66
+ <DeleteOutlined />
67
+ </a>
68
+ </Popconfirm>
69
+ }
70
+ styles={{
71
+ header: {minHeight: 0}
72
+ }}
73
+ >
74
+ <Form
75
+ layout="vertical"
76
+ size="small"
77
+ styles={{
78
+ label: { fontSize: 12, color: "var(--ant-color-text-label)" },
79
+ }}
80
+ >
81
+ <Form.Item label="变量名" style={{ marginBottom: 10 }}>
82
+ <Input
83
+ name="key"
84
+ size="small"
85
+ value={dataset.key}
86
+ placeholder="请输入变量名"
87
+ onChange={(e) => {
88
+ datasets[index].key = e.target.value;
89
+ setSchema((schema) => ({
90
+ ...schema,
91
+ datasets: [...datasets],
92
+ }));
93
+ }}
94
+ style={{ width: "100%" }}
95
+ />
96
+ </Form.Item>
97
+ <Form.Item label="依赖环境变量" style={{ marginBottom: 10 }}>
98
+ <Select
99
+ size="small"
100
+ mode="multiple"
101
+ options={variables.map((variable) => ({
102
+ label: variable.name,
103
+ value: variable.name,
104
+ }))}
105
+ placeholder="请选择依赖环境变量"
106
+ style={{ width: "100%" }}
107
+ value={dataset.dependencies}
108
+ notFoundContent={"暂无依赖环境变量"}
109
+ onChange={(values) => {
110
+ datasets[index].dependencies = values;
111
+ setSchema((schema) => ({
112
+ ...schema,
113
+ datasets: [...datasets],
114
+ }));
115
+ }}
116
+ />
117
+ </Form.Item>
118
+ <Form.Item label="AI解读提示词" tooltip="用于AI解读数据集,为空时不进行解读" style={{ marginBottom: 0 }}>
119
+ <Input.TextArea
120
+ size="small"
121
+ value={dataset.aiPrompt}
122
+ onChange={(e) => {
123
+ datasets[index].aiPrompt = e.target.value;
124
+ setSchema((schema) => ({
125
+ ...schema,
126
+ datasets: [...datasets],
127
+ }));
128
+ }}
129
+ rows={4}
130
+ />
131
+ </Form.Item>
132
+ </Form>
133
+ </Card>
134
+ ))}
135
+ </div>
136
+ {!!datasetSelector && (
137
+ <Drawer
138
+ title="选择数据集"
139
+ size={800}
140
+ open={visible}
141
+ onClose={() => {
142
+ setVisible(false);
143
+ }}
144
+ >
145
+ {datasetSelector((dataset) => {
146
+ setVisible(false);
147
+ setSchema((schema) => ({
148
+ ...schema,
149
+ datasets: [
150
+ ...datasets,
151
+ {
152
+ id: dataset.id,
153
+ name: dataset.name,
154
+ key: dataset.id,
155
+ output: dataset.output,
156
+ dependencies: [],
157
+ },
158
+ ],
159
+ }));
160
+ })}
161
+ </Drawer>
162
+ )}
163
+ </Root>
164
+ );
165
+ };
@@ -22,13 +22,16 @@ const Root = styled.div`
22
22
  `;
23
23
 
24
24
  export const VariablesPanel: React.FC = () => {
25
- const {schema, setSchema} = useContext(PageContext);
25
+ const {schema, setSchema, setGlobalEnv} = useContext(PageContext);
26
26
  const [visible, setVisible] = React.useState(false);
27
27
  const [editIndex, setEditIndex] = React.useState(-1);
28
28
  const [form] = Form.useForm<VariableItem>();
29
29
  const list = useMemo(() => schema.variables || [], [schema.variables]);
30
30
  const onUpdateVariables = (data: VariableItem[]) => {
31
31
  setSchema({ ...schema, variables: data });
32
+ data.forEach((item) => {
33
+ setGlobalEnv(item.name, item.value);
34
+ });
32
35
  };
33
36
  const columns = [
34
37
  {
@@ -71,6 +71,7 @@ export const TextPlugin: PluginType = {
71
71
  },
72
72
  },
73
73
  },
74
+ events: [{ name: "点击", handler: "click" }],
74
75
  };
75
76
 
76
77
  export const ImagePlugin: PluginType = {
@@ -197,6 +198,7 @@ export const HtmlPlugin: PluginType = {
197
198
  template: `<div>{{name}}, welcome to the world of programming.</div>`,
198
199
  },
199
200
  },
201
+ events: [{ name: "点击", handler: "click" }],
200
202
  };
201
203
 
202
204
  export const EchartsPlugin: PluginType = {
@@ -459,6 +461,10 @@ export const ModalPlugin: PluginType = {
459
461
  },
460
462
  children: [],
461
463
  },
464
+ events: [
465
+ { name: "打开", handler: "open" },
466
+ { name: "关闭", handler: "close" },
467
+ ]
462
468
  };
463
469
 
464
470
  export const DrawerPlugin: PluginType = {
@@ -485,6 +491,10 @@ export const DrawerPlugin: PluginType = {
485
491
  },
486
492
  children: [],
487
493
  },
494
+ events: [
495
+ { name: "打开", handler: "open" },
496
+ { name: "关闭", handler: "close" },
497
+ ]
488
498
  };
489
499
 
490
500
  export const plugins: PluginType[] = [
@@ -1,8 +1,9 @@
1
1
  import React, { useRef } from "react";
2
- import { Form, InputNumber } from "antd";
2
+ import { Form, InputNumber, Space, Tooltip } from "antd";
3
3
  import Editor from "@monaco-editor/react";
4
4
  import type { PropEditorProps } from "./types";
5
5
  import { IconFont } from "../../../icon/IconFont";
6
+ import { InfoCircleOutlined } from "@ant-design/icons";
6
7
 
7
8
  export type EchartsModel = { script: string; height?: number };
8
9
 
@@ -40,7 +41,24 @@ export const EchartsProps: React.FC<PropEditorProps<EchartsModel>> = ({
40
41
  layout="vertical"
41
42
  label={
42
43
  <>
43
- Echarts 渲染脚本{" "}
44
+ <Space>
45
+ Echarts 渲染脚本{" "}
46
+ <Tooltip
47
+ title={
48
+ <>
49
+ 模板语法参考
50
+ <ul style={{padding: 0, listStyle: "none"}}>
51
+ <li>变量调用:{ `{{变量名}}` }</li>
52
+ <li>环境变量:{ `{{$e.变量名}}` }</li>
53
+ <li>全局变量:{ `{{$g.变量名}}` }</li>
54
+ <li>函数参数:{ `{{data}}` }</li>
55
+ </ul>
56
+ </>
57
+ }
58
+ >
59
+ <InfoCircleOutlined />
60
+ </Tooltip>
61
+ </Space>
44
62
  <a onClick={format}>
45
63
  <IconFont type="icon-formate" /> 格式化
46
64
  </a>
@@ -1,8 +1,9 @@
1
1
  import React, { useRef } from "react";
2
- import { Form, Select } from "antd";
2
+ import { Form, Select, Space, Tooltip } from "antd";
3
3
  import Editor from "@monaco-editor/react";
4
4
  import type { PropEditorProps } from "./types";
5
5
  import { IconFont } from "../../../icon/IconFont";
6
+ import { InfoCircleOutlined } from "@ant-design/icons";
6
7
 
7
8
  export type HtmlModel = { template: string; classNames?: string[] };
8
9
 
@@ -31,7 +32,23 @@ export const HtmlProps: React.FC<PropEditorProps<HtmlModel>> = ({
31
32
  <Form.Item
32
33
  label={
33
34
  <>
34
- 模板
35
+ <Space>
36
+ 模板
37
+ <Tooltip
38
+ title={
39
+ <>
40
+ 模板语法参考
41
+ <ul style={{padding: 0, listStyle: "none"}}>
42
+ <li>变量调用:{ `{{变量名}}` }</li>
43
+ <li>环境变量:{ `{{$e.变量名}}` }</li>
44
+ <li>全局变量:{ `{{$g.变量名}}` }</li>
45
+ </ul>
46
+ </>
47
+ }
48
+ >
49
+ <InfoCircleOutlined />
50
+ </Tooltip>
51
+ </Space>
35
52
  <a onClick={format}>
36
53
  <IconFont type="icon-formate" /> 格式化
37
54
  </a>
@@ -4,6 +4,7 @@ import type { PropEditorProps } from "./types";
4
4
 
5
5
  export type TextModel = {
6
6
  text?: string;
7
+ tag?: string;
7
8
  customStyle?: React.CSSProperties;
8
9
  classNames?: string[];
9
10
  };
@@ -27,6 +28,17 @@ export const TextProps: React.FC<PropEditorProps<TextModel>> = ({
27
28
  onChange={(e) => triggerModel("text", e.target.value)}
28
29
  />
29
30
  </Form.Item>
31
+ <Form.Item label="HTML标签">
32
+ <Select
33
+ size="small"
34
+ value={model.tag}
35
+ onChange={(v) => triggerModel("tag", v)}
36
+ options={[
37
+ { value: "span", label: "span" },
38
+ { value: "a", label: "a" },
39
+ ]}
40
+ />
41
+ </Form.Item>
30
42
  <Form.Item label="类名">
31
43
  <Select
32
44
  size="small"
@@ -4,6 +4,7 @@ import styled from "styled-components";
4
4
  import { PageContext } from "../../../context/PageContext";
5
5
  import { DropContainer } from "../../../dnd/DropContainer";
6
6
  import { CallbackType, HtmlBaseProps, SchemaItemType } from "../../../typing";
7
+ import { useEvent } from "../../../hooks/event";
7
8
 
8
9
  const Placeholder = styled.div`
9
10
  text-align: center;
@@ -56,6 +57,8 @@ export const DrawerRender: React.FC<DrawerRenderProps> = ({
56
57
  const [localChildren, setLocalChildren] = useState(item.children || []);
57
58
  const [size, setSize] = useState(rest.size || 400);
58
59
 
60
+ const { handleEvent } = useEvent(item);
61
+
59
62
  const onLocalChildrenChange = (list: any[]) => {
60
63
  item.children = list;
61
64
  setLocalChildren(list);
@@ -93,6 +96,10 @@ export const DrawerRender: React.FC<DrawerRenderProps> = ({
93
96
  toolbarEl.style.left = `${rect.left + scrollLeft - 1}px`;
94
97
  };
95
98
 
99
+ const handleOpenChange = (open: boolean) => {
100
+ handleEvent(open ? "open" : "close");
101
+ };
102
+
96
103
  useEffect(() => {
97
104
  setSize(rest.size || 400);
98
105
  }, [rest.size]);
@@ -145,6 +152,7 @@ export const DrawerRender: React.FC<DrawerRenderProps> = ({
145
152
  open={open}
146
153
  size={size}
147
154
  onClose={() => setOpen(false)}
155
+ afterOpenChange={handleOpenChange}
148
156
  getContainer={() =>
149
157
  designable ? document.querySelector(".page-canvas")! : document.body
150
158
  }
@@ -32,7 +32,7 @@ export const EchartsRender: React.FC<EchartsRenderProps> = ({
32
32
  style,
33
33
  className,
34
34
  }) => {
35
- const { initCallback } = useContext(PageContext);
35
+ const { initCallback, globalVars, env } = useContext(PageContext);
36
36
  const chartRef = useRef<HTMLDivElement | null>(null);
37
37
  const [chart, setChart] = useState<echarts.ECharts | null>(null);
38
38
  const [signal, setSignal] = useState<number>(0);
@@ -59,6 +59,8 @@ export const EchartsRender: React.FC<EchartsRenderProps> = ({
59
59
  "String",
60
60
  "Number",
61
61
  "Boolean",
62
+ "$g",
63
+ "$e",
62
64
  "data",
63
65
  `
64
66
  "use strict";
@@ -82,6 +84,8 @@ export const EchartsRender: React.FC<EchartsRenderProps> = ({
82
84
  String,
83
85
  Number,
84
86
  Boolean,
87
+ globalVars,
88
+ env.global,
85
89
  datasource,
86
90
  );
87
91
  } catch (evalError) {
@@ -127,7 +131,7 @@ export const EchartsRender: React.FC<EchartsRenderProps> = ({
127
131
  }
128
132
  setTimeout(() => chart.resize(), 50);
129
133
  }
130
- }, [chart, script, datasource]);
134
+ }, [chart, script, datasource, globalVars, env]);
131
135
 
132
136
  useEffect(() => {
133
137
  if (!chart) return;