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
@@ -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";
@@ -57,16 +61,16 @@ export const HtmlRender: React.FC<HtmlRenderProps> = ({
57
61
  const html = useMemo(
58
62
  () =>
59
63
  (template || "").replace(
60
- /{\s*{\s*([^#]+)\s*}\s*}/g,
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,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
  }}