bi-sdk-react 0.0.54 → 0.0.56

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 (38) 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/example.d.ts +8 -4
  5. package/dist/types/components/hooks/datasource.d.ts +2 -1
  6. package/dist/types/components/hooks/method.d.ts +1 -0
  7. package/dist/types/components/panel/GlobalDatasetPanel.d.ts +2 -0
  8. package/dist/types/components/plugins/@antd/item-props/TableProps.d.ts +9 -0
  9. package/dist/types/components/plugins/@antd/item-props/TextProps.d.ts +1 -0
  10. package/dist/types/components/plugins/@antd/items/TableRender.d.ts +9 -1
  11. package/dist/types/components/plugins/@antd/items/TextRender.d.ts +3 -4
  12. package/dist/types/components/typing.d.ts +9 -1
  13. package/dist/umd/js/bi-sdk.umd.min.js +55 -41
  14. package/package.json +1 -1
  15. package/src/components/PageDesigner.tsx +8 -0
  16. package/src/components/context/GlobalDatasetContext.tsx +52 -0
  17. package/src/components/context/PageContext.tsx +31 -8
  18. package/src/components/example.ts +9 -10
  19. package/src/components/hooks/datasource.ts +5 -4
  20. package/src/components/hooks/event.ts +6 -1
  21. package/src/components/hooks/method.ts +2 -2
  22. package/src/components/icon/IconFont.tsx +1 -1
  23. package/src/components/panel/EventPanel.tsx +1 -0
  24. package/src/components/panel/GlobalDatasetPanel.tsx +165 -0
  25. package/src/components/panel/VariablesPanel.tsx +4 -1
  26. package/src/components/plugins/@antd/index.ts +15 -7
  27. package/src/components/plugins/@antd/item-props/EchartsProps.tsx +20 -2
  28. package/src/components/plugins/@antd/item-props/HtmlProps.tsx +19 -2
  29. package/src/components/plugins/@antd/item-props/TableProps.tsx +86 -0
  30. package/src/components/plugins/@antd/item-props/TextProps.tsx +12 -0
  31. package/src/components/plugins/@antd/items/DrawerRender.tsx +8 -0
  32. package/src/components/plugins/@antd/items/EchartsRender.tsx +6 -2
  33. package/src/components/plugins/@antd/items/HtmlRender.tsx +13 -4
  34. package/src/components/plugins/@antd/items/ModalRender.tsx +7 -0
  35. package/src/components/plugins/@antd/items/TableRender.tsx +95 -21
  36. package/src/components/plugins/@antd/items/TextRender.tsx +21 -6
  37. package/src/components/typing.ts +9 -1
  38. package/src/example.tsx +9 -0
@@ -11,6 +11,7 @@ import {
11
11
  Modal,
12
12
  Input,
13
13
  type TableProps as AntTableProps,
14
+ Select,
14
15
  } from "antd";
15
16
  import type { PropEditorProps } from "./types";
16
17
  import {
@@ -31,6 +32,15 @@ export type TableColumnModel = {
31
32
  export type TableModel = {
32
33
  pageSize?: number;
33
34
  columns: TableColumnModel[];
35
+ dataKey?: string;
36
+ showSizeChanger?: boolean;
37
+ showQuickJumper?: boolean;
38
+ hideOnSinglePage?: boolean;
39
+ showTotal?: boolean;
40
+ headerCellClassNames?: string[];
41
+ bodyCellClassNames?: string[];
42
+ paginationRootClassNames?: string[];
43
+ paginationItemClassNames?: string[];
34
44
  } & Pick<AntTableProps, "bordered" | "showHeader" | "size">;
35
45
 
36
46
  export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
@@ -88,6 +98,13 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
88
98
  return (
89
99
  <div>
90
100
  <Form labelCol={{ span: 12 }} wrapperCol={{ span: 12 }}>
101
+ <Form.Item label="数据键" tooltip="数据键用于指定数据来源中的数据项,例如:'data.items'">
102
+ <Input
103
+ size="small"
104
+ value={model.dataKey}
105
+ onChange={(e) => trigger("dataKey", e.target.value)}
106
+ />
107
+ </Form.Item>
91
108
  <Form.Item label="大小">
92
109
  <Radio.Group
93
110
  size="small"
@@ -113,6 +130,34 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
113
130
  onChange={(v) => trigger("showHeader", v)}
114
131
  />
115
132
  </Form.Item>
133
+ <Form.Item label="显示分页大小选择器">
134
+ <Switch
135
+ size="small"
136
+ checked={!!model.showSizeChanger}
137
+ onChange={(v) => trigger("showSizeChanger", v)}
138
+ />
139
+ </Form.Item>
140
+ <Form.Item label="显示快速跳转">
141
+ <Switch
142
+ size="small"
143
+ checked={!!model.showQuickJumper}
144
+ onChange={(v) => trigger("showQuickJumper", v)}
145
+ />
146
+ </Form.Item>
147
+ <Form.Item label="隐藏单页分页">
148
+ <Switch
149
+ size="small"
150
+ checked={!!model.hideOnSinglePage}
151
+ onChange={(v) => trigger("hideOnSinglePage", v)}
152
+ />
153
+ </Form.Item>
154
+ <Form.Item label="显示分页总数">
155
+ <Switch
156
+ size="small"
157
+ checked={!!model.showTotal}
158
+ onChange={(v) => trigger("showTotal", v)}
159
+ />
160
+ </Form.Item>
116
161
  <Form.Item label="分页大小">
117
162
  <InputNumber
118
163
  size="small"
@@ -133,6 +178,47 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
133
178
  <Button size="small" onClick={addColumn} block>
134
179
  添加列
135
180
  </Button>
181
+ <Divider style={{marginTop: 10}}>样式设置</Divider>
182
+ <Form.Item label="表头单元格类名" layout="vertical">
183
+ <Select
184
+ mode="tags"
185
+ size="small"
186
+ value={(model.headerCellClassNames || [])}
187
+ onChange={(e) =>
188
+ trigger("headerCellClassNames", e)
189
+ }
190
+ />
191
+ </Form.Item>
192
+ <Form.Item label="表格单元格类名" layout="vertical">
193
+ <Select
194
+ mode="tags"
195
+ size="small"
196
+ value={(model.bodyCellClassNames || [])}
197
+ onChange={(e) =>
198
+ trigger("bodyCellClassNames", e)
199
+ }
200
+ />
201
+ </Form.Item>
202
+ <Form.Item label="分页根类名" layout="vertical">
203
+ <Select
204
+ mode="tags"
205
+ size="small"
206
+ value={(model.paginationRootClassNames || [])}
207
+ onChange={(e) =>
208
+ trigger("paginationRootClassNames", e)
209
+ }
210
+ />
211
+ </Form.Item>
212
+ <Form.Item label="分页项类名" layout="vertical">
213
+ <Select
214
+ mode="tags"
215
+ size="small"
216
+ value={(model.paginationItemClassNames || [])}
217
+ onChange={(e) =>
218
+ trigger("paginationItemClassNames", e)
219
+ }
220
+ />
221
+ </Form.Item>
136
222
  <Modal
137
223
  title="编辑列"
138
224
  open={editVisible}
@@ -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;
@@ -1,7 +1,8 @@
1
- import React, { useContext, useEffect, useMemo, useRef, useState } from "react";
1
+ import React, { MouseEventHandler, useContext, useEffect, useMemo, useRef, useState } from "react";
2
2
  import { PageContext } from "../../../context/PageContext";
3
3
  import { useDatasource } from "../../../hooks/datasource";
4
4
  import { CallbackType, HtmlBaseProps } from "../../../typing";
5
+ import { useEvent } from "../../../hooks/event";
5
6
 
6
7
  export type HtmlRenderProps = {
7
8
  dataSource?: Record<string, any>;
@@ -30,13 +31,16 @@ export const HtmlRender: React.FC<HtmlRenderProps> = ({
30
31
  className,
31
32
  classNames = [],
32
33
  }) => {
33
- const { initCallback } = useContext(PageContext);
34
+ const { initCallback, globalVars, env } = useContext(PageContext);
35
+ const { handleEvent } = useEvent(item);
34
36
  const [signal, setSignal] = useState<number>(0);
35
37
  const datasource = useDatasource({ item, signal });
36
38
 
37
39
  const keys = useMemo(() => Object.keys(datasource || {}), [datasource]);
38
40
  const func = (path: string) =>
39
41
  new Function(
42
+ "$g",
43
+ "$e",
40
44
  ...keys,
41
45
  `
42
46
  "use strict";
@@ -60,13 +64,13 @@ export const HtmlRender: React.FC<HtmlRenderProps> = ({
60
64
  /{\s*{\s*([^}]+)\s*}\s*}/g,
61
65
  (_match: any, p1: string) => {
62
66
  try {
63
- return (func(p1) as any)(...args);
67
+ return (func(p1) as any)(globalVars, env.global, ...args);
64
68
  } catch {
65
69
  return "";
66
70
  }
67
71
  },
68
72
  ),
69
- [template, args],
73
+ [template, args, globalVars, env],
70
74
  );
71
75
 
72
76
  const callback: CallbackType = (refresh = true) => {
@@ -77,6 +81,10 @@ export const HtmlRender: React.FC<HtmlRenderProps> = ({
77
81
  };
78
82
  };
79
83
 
84
+ const click: MouseEventHandler = () => {
85
+ handleEvent("click");
86
+ };
87
+
80
88
  useEffect(() => {
81
89
  initCallback({ id: item.id, callback });
82
90
  }, []);
@@ -87,6 +95,7 @@ export const HtmlRender: React.FC<HtmlRenderProps> = ({
87
95
  style={style}
88
96
  className={(classNames || []).join(" ") + (" " + className || "")}
89
97
  dangerouslySetInnerHTML={{ __html: html }}
98
+ onClick={click}
90
99
  />
91
100
  );
92
101
  };
@@ -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;
@@ -48,6 +49,7 @@ export const ModalRender: React.FC<ModalRenderProps> = ({
48
49
  } = useContext(PageContext);
49
50
  const [open, setOpen] = useState(false);
50
51
  const [localChildren, setLocalChildren] = useState(item.children || []);
52
+ const { handleEvent } = useEvent(item);
51
53
 
52
54
  const onLocalChildrenChange = (list: any[]) => {
53
55
  item.children = list;
@@ -86,6 +88,10 @@ export const ModalRender: React.FC<ModalRenderProps> = ({
86
88
  toolbarEl.style.left = `${rect.left + scrollLeft - 1}px`;
87
89
  };
88
90
 
91
+ const handleOpenChange = (open: boolean) => {
92
+ handleEvent(open ? "open" : "close");
93
+ };
94
+
89
95
  useEffect(() => {
90
96
  setLocalChildren(item.children || []);
91
97
  }, [item.children]);
@@ -132,6 +138,7 @@ export const ModalRender: React.FC<ModalRenderProps> = ({
132
138
  {...rest}
133
139
  open={open}
134
140
  onCancel={() => setOpen(false)}
141
+ afterOpenChange={handleOpenChange}
135
142
  getContainer={() =>
136
143
  designable ? document.querySelector(".page-canvas")! : document.body
137
144
  }
@@ -1,45 +1,54 @@
1
- import { Table, type TableProps } from "antd";
2
- import React, { useContext, useEffect } from "react";
1
+ import { PaginationProps, Table, type TableProps } from "antd";
2
+ import React, { useContext, useEffect, useMemo, useState } from "react";
3
3
  import { PageContext } from "../../../context/PageContext";
4
4
  import { HtmlBaseProps } from "../../../typing";
5
+ import { useDatasource } from "../../../hooks/datasource";
5
6
 
6
7
  export type TableRenderProps = {
7
- dataSource?: any[];
8
8
  columns?: any[];
9
+ dataKey?: string;
9
10
  pageSize?: number;
10
11
  bordered?: boolean;
11
12
  size?: TableProps["size"];
12
13
  showHeader?: boolean;
13
14
  item: any;
15
+ showSizeChanger?: boolean;
16
+ showQuickJumper?: boolean;
17
+ hideOnSinglePage?: boolean;
18
+ showTotal?: boolean;
19
+ headerCellClassNames?: string[];
20
+ bodyCellClassNames?: string[];
21
+ paginationRootClassNames?: string[];
22
+ paginationItemClassNames?: string[];
14
23
  } & HtmlBaseProps;
15
24
 
16
25
  export const TableRender: React.FC<TableRenderProps> = ({
17
26
  id,
18
27
  item,
19
- dataSource = [],
20
28
  columns = [],
29
+ dataKey = "",
21
30
  pageSize = 10,
22
31
  bordered = true,
23
32
  size,
24
33
  showHeader = true,
34
+ showSizeChanger = true,
35
+ showQuickJumper = true,
36
+ hideOnSinglePage = true,
37
+ showTotal = true,
25
38
  style = {},
26
39
  className,
40
+ headerCellClassNames = [],
41
+ bodyCellClassNames = [],
42
+ paginationRootClassNames = [],
43
+ paginationItemClassNames = [],
27
44
  }) => {
28
45
  const { initCallback } = useContext(PageContext);
29
- const pagination =
30
- !pageSize || pageSize <= dataSource.length
31
- ? false
32
- : {
33
- total: dataSource.length,
34
- pageSize,
35
- size,
36
- showSizeChanger: true,
37
- showQuickJumper: true,
38
- hideOnSinglePage: true,
39
- pageSizeOptions: ["10", "20", "30", "40"],
40
- showTotal: (total: number, range: [number, number]) =>
41
- `共 ${total} 条记录,显示第 ${range[0]}-${range[1]} 条`,
42
- };
46
+ const [page, setPage] = useState<{
47
+ current: number;
48
+ pageSize: number;
49
+ }>({ current: 1, pageSize });
50
+
51
+ const dataSource = useDatasource({ item, query: page });
43
52
  const realColumns = columns.map((item: any) => ({
44
53
  ...item,
45
54
  render:
@@ -69,7 +78,7 @@ export const TableRender: React.FC<TableRenderProps> = ({
69
78
  const module = undefined;
70
79
  const exports = undefined;
71
80
  ${item.customRender}
72
- `
81
+ `,
73
82
  );
74
83
  return (safeEval as any)(
75
84
  console,
@@ -82,15 +91,68 @@ export const TableRender: React.FC<TableRenderProps> = ({
82
91
  Boolean,
83
92
  text,
84
93
  record,
85
- index
94
+ index,
86
95
  );
87
96
  },
88
97
  }));
89
98
 
99
+ const data = useMemo(() => {
100
+ if (!dataKey || dataKey.trim() === "") {
101
+ return dataSource || [];
102
+ }
103
+ const keys = dataKey.split(".");
104
+ let result = dataSource || [];
105
+ for (const key of keys) {
106
+ if (result[key]) {
107
+ result = result[key];
108
+ } else {
109
+ result = [];
110
+ break;
111
+ }
112
+ }
113
+ return result || [];
114
+ }, [dataKey, dataSource]);
115
+
116
+ const pagination = useMemo(
117
+ () =>
118
+ !pageSize || pageSize >= (data || []).length
119
+ ? false
120
+ : ({
121
+ total: (data || []).length,
122
+ current: page.current,
123
+ pageSize: page.pageSize,
124
+ size,
125
+ showSizeChanger,
126
+ showQuickJumper,
127
+ hideOnSinglePage,
128
+ pageSizeOptions: ["10", "20", "30", "40"],
129
+ showTotal: showTotal
130
+ ? (total: number, range: [number, number]) =>
131
+ `共 ${total} 条记录,显示第 ${range[0]}-${range[1]} 条`
132
+ : undefined,
133
+ locale: {
134
+ items_per_page: "/ 页",
135
+ jump_to: "跳转至第",
136
+ page: "页",
137
+ },
138
+ onChange: (page: number, pageSize: number) => {
139
+ setPage({ current: page, pageSize });
140
+ },
141
+ onShowSizeChange: (current: number, size: number) => {
142
+ setPage({ current, pageSize: size });
143
+ },
144
+ } as PaginationProps),
145
+ [data, page, pageSize, size, showSizeChanger, showQuickJumper, hideOnSinglePage, showTotal],
146
+ );
147
+
90
148
  const callback = () => {
91
149
  console.log("callback table");
92
150
  };
93
151
 
152
+ useEffect(() => {
153
+ setPage({ current: 1, pageSize });
154
+ }, [pageSize]);
155
+
94
156
  useEffect(() => {
95
157
  initCallback({ id: item.id, callback });
96
158
  }, []);
@@ -98,7 +160,7 @@ export const TableRender: React.FC<TableRenderProps> = ({
98
160
  return (
99
161
  <Table
100
162
  id={id}
101
- dataSource={dataSource}
163
+ dataSource={data || []}
102
164
  columns={realColumns as any}
103
165
  pagination={pagination as any}
104
166
  bordered={bordered}
@@ -107,6 +169,18 @@ export const TableRender: React.FC<TableRenderProps> = ({
107
169
  rowKey={(_, index) => String(index)}
108
170
  style={{ padding: 1, ...style }}
109
171
  className={className}
172
+ classNames={{
173
+ header: {
174
+ cell: (headerCellClassNames || []).join(" "),
175
+ },
176
+ body: {
177
+ cell: (bodyCellClassNames || []).join(" "),
178
+ },
179
+ pagination: {
180
+ root: (paginationRootClassNames || []).join(" "),
181
+ item: (paginationItemClassNames || []).join(" "),
182
+ },
183
+ }}
110
184
  />
111
185
  );
112
186
  };
@@ -1,33 +1,48 @@
1
- import React, { useMemo } from "react";
2
- import { HtmlBaseProps } from "../../../typing";
1
+ import React, { ComponentType, MouseEventHandler, useMemo } from "react";
2
+ import { HtmlBaseProps, SchemaItemType } from "../../../typing";
3
+ import { useEvent } from "../../../hooks/event";
3
4
 
4
5
  export type TextRenderProps = {
5
6
  text?: string;
7
+ tag?: "span" | "a";
6
8
  customStyle?: React.CSSProperties;
7
- item?: { style?: React.CSSProperties };
9
+ item: SchemaItemType;
8
10
  classNames?: string[];
9
11
  } & HtmlBaseProps;
10
12
 
11
13
  export const TextRender: React.FC<TextRenderProps> = ({
12
14
  id,
13
15
  text,
16
+ tag = "span",
14
17
  item,
15
18
  style = {},
16
19
  customStyle = {},
17
20
  className,
18
21
  classNames = [],
19
22
  }) => {
23
+ const { handleEvent } = useEvent(item);
20
24
  const actualStyle = useMemo(
21
25
  () => ({
22
26
  ...(item?.style || {}),
23
27
  ...(customStyle || {}),
24
28
  ...(style || {}),
25
29
  }),
26
- [item, customStyle, style]
30
+ [item, customStyle, style],
27
31
  );
32
+
33
+ const Tag = tag || "span";
34
+
35
+ const click: MouseEventHandler = () => {
36
+ handleEvent("click");
37
+ };
28
38
  return (
29
- <span id={id} style={actualStyle} className={(classNames || []).join(" ") + (" " + className || "")}>
39
+ <Tag
40
+ id={id}
41
+ style={actualStyle}
42
+ className={(classNames || []).join(" ") + (" " + className || "")}
43
+ onClick={click}
44
+ >
30
45
  {text}
31
- </span>
46
+ </Tag>
32
47
  );
33
48
  };
@@ -79,7 +79,7 @@ export type FetchType = {
79
79
  removeConversation: (conversationId: string) => Promise<boolean>;
80
80
  removeMessage: (messageId: string) => Promise<boolean>;
81
81
  };
82
- dataset?: (dataSetId: string, params: Record<string, any>) => Promise<any>;
82
+ dataset?: (dataSetId: string, params: Record<string, any>, aiPrompt?: string) => Promise<any>;
83
83
  };
84
84
 
85
85
  export type HtmlBaseProps = {
@@ -190,6 +190,14 @@ export type PageSchema = {
190
190
  scripts: ScriptItem[];
191
191
  variables: VariableItem[];
192
192
  items: SchemaItemType[];
193
+ datasets?: {
194
+ id: string;
195
+ name: string;
196
+ key: string;
197
+ aiPrompt?: string;
198
+ output: DataSetOutput;
199
+ dependencies?: string[];
200
+ }[]
193
201
  };
194
202
 
195
203
  export type EnvType = {
package/src/example.tsx CHANGED
@@ -197,6 +197,15 @@ export const Example: React.FC = () => {
197
197
  removeMessage: async (messageId) =>
198
198
  Promise.resolve(true),
199
199
  },
200
+ dataset: async (dataSetId, params, aiPrompt) => {
201
+ console.log("dataset", dataSetId, params, aiPrompt);
202
+ return Promise.resolve({
203
+ code: "OK",
204
+ data: {
205
+ ...params,
206
+ }
207
+ });
208
+ },
200
209
  upload: async (file) =>
201
210
  Promise.resolve({ id: uuid(), name: file.name }),
202
211
  }}