bi-sdk-react 0.0.1

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 (146) hide show
  1. package/dist/es/css/bi-sdk.css +1 -0
  2. package/dist/es/js/bi-sdk.es.js +795 -0
  3. package/dist/es/js/bi-sdk.es.js.LICENSE.txt +9 -0
  4. package/dist/types/components/PageDesigner.d.ts +10 -0
  5. package/dist/types/components/context/DesignerContext.d.ts +15 -0
  6. package/dist/types/components/context/EnvContext.d.ts +15 -0
  7. package/dist/types/components/dnd/DropContainer.d.ts +21 -0
  8. package/dist/types/components/example.d.ts +225 -0
  9. package/dist/types/components/hooks/datasource.d.ts +1 -0
  10. package/dist/types/components/hooks/useDeepCompareEffect.d.ts +1 -0
  11. package/dist/types/components/icon/IconFont.d.ts +6 -0
  12. package/dist/types/components/index.d.ts +10 -0
  13. package/dist/types/components/layout/PageCanvas.d.ts +6 -0
  14. package/dist/types/components/layout/PageItem.d.ts +27 -0
  15. package/dist/types/components/panel/AiPanel.d.ts +8 -0
  16. package/dist/types/components/panel/CascadePanel.d.ts +2 -0
  17. package/dist/types/components/panel/ChatInput.d.ts +28 -0
  18. package/dist/types/components/panel/CodePanel.d.ts +2 -0
  19. package/dist/types/components/panel/ComponentPanel.d.ts +2 -0
  20. package/dist/types/components/panel/DatasourcePanel.d.ts +2 -0
  21. package/dist/types/components/panel/LayerPanel.d.ts +2 -0
  22. package/dist/types/components/panel/PaneHeader.d.ts +6 -0
  23. package/dist/types/components/panel/PropertiesPanel.d.ts +2 -0
  24. package/dist/types/components/panel/ScriptPanel.d.ts +2 -0
  25. package/dist/types/components/panel/VariablesPanel.d.ts +2 -0
  26. package/dist/types/components/panel/index.d.ts +9 -0
  27. package/dist/types/components/plugins/@antd/index.d.ts +22 -0
  28. package/dist/types/components/plugins/@antd/item-props/ButtonProps.d.ts +8 -0
  29. package/dist/types/components/plugins/@antd/item-props/CapsuleProps.d.ts +13 -0
  30. package/dist/types/components/plugins/@antd/item-props/CardProps.d.ts +8 -0
  31. package/dist/types/components/plugins/@antd/item-props/CheckboxProps.d.ts +13 -0
  32. package/dist/types/components/plugins/@antd/item-props/ColProps.d.ts +12 -0
  33. package/dist/types/components/plugins/@antd/item-props/DatePickerProps.d.ts +8 -0
  34. package/dist/types/components/plugins/@antd/item-props/EchartsProps.d.ts +6 -0
  35. package/dist/types/components/plugins/@antd/item-props/HtmlProps.d.ts +6 -0
  36. package/dist/types/components/plugins/@antd/item-props/ImageProps.d.ts +10 -0
  37. package/dist/types/components/plugins/@antd/item-props/InputNumberProps.d.ts +9 -0
  38. package/dist/types/components/plugins/@antd/item-props/InputProps.d.ts +10 -0
  39. package/dist/types/components/plugins/@antd/item-props/ListProps.d.ts +10 -0
  40. package/dist/types/components/plugins/@antd/item-props/PageHeaderProps.d.ts +7 -0
  41. package/dist/types/components/plugins/@antd/item-props/RowProps.d.ts +6 -0
  42. package/dist/types/components/plugins/@antd/item-props/SelectProps.d.ts +16 -0
  43. package/dist/types/components/plugins/@antd/item-props/SpaceProps.d.ts +7 -0
  44. package/dist/types/components/plugins/@antd/item-props/SwitchProps.d.ts +6 -0
  45. package/dist/types/components/plugins/@antd/item-props/TableProps.d.ts +15 -0
  46. package/dist/types/components/plugins/@antd/item-props/TextProps.d.ts +6 -0
  47. package/dist/types/components/plugins/@antd/item-props/index.d.ts +19 -0
  48. package/dist/types/components/plugins/@antd/item-props/types.d.ts +5 -0
  49. package/dist/types/components/plugins/@antd/items/ButtonRender.d.ts +14 -0
  50. package/dist/types/components/plugins/@antd/items/CapsuleRender.d.ts +14 -0
  51. package/dist/types/components/plugins/@antd/items/CardRender.d.ts +12 -0
  52. package/dist/types/components/plugins/@antd/items/CheckboxRender.d.ts +14 -0
  53. package/dist/types/components/plugins/@antd/items/ColRender.d.ts +13 -0
  54. package/dist/types/components/plugins/@antd/items/DatePickerRender.d.ts +14 -0
  55. package/dist/types/components/plugins/@antd/items/EchartsRender.d.ts +10 -0
  56. package/dist/types/components/plugins/@antd/items/HtmlRender.d.ts +20 -0
  57. package/dist/types/components/plugins/@antd/items/ImageRender.d.ts +10 -0
  58. package/dist/types/components/plugins/@antd/items/InputNumberRender.d.ts +17 -0
  59. package/dist/types/components/plugins/@antd/items/InputRender.d.ts +17 -0
  60. package/dist/types/components/plugins/@antd/items/ListRender.d.ts +11 -0
  61. package/dist/types/components/plugins/@antd/items/PageHeaderRender.d.ts +8 -0
  62. package/dist/types/components/plugins/@antd/items/RowRender.d.ts +13 -0
  63. package/dist/types/components/plugins/@antd/items/SelectRender.d.ts +18 -0
  64. package/dist/types/components/plugins/@antd/items/SpaceRender.d.ts +10 -0
  65. package/dist/types/components/plugins/@antd/items/SwitchRender.d.ts +14 -0
  66. package/dist/types/components/plugins/@antd/items/TableRender.d.ts +12 -0
  67. package/dist/types/components/plugins/@antd/items/TextRender.d.ts +9 -0
  68. package/dist/types/components/plugins/@antd/items/index.d.ts +19 -0
  69. package/dist/types/components/typing.d.ts +80 -0
  70. package/dist/types/components/utils.d.ts +9 -0
  71. package/dist/types/example.d.ts +2 -0
  72. package/dist/types/index.d.ts +1 -0
  73. package/dist/umd/css/bi-sdk.css +1 -0
  74. package/dist/umd/js/bi-sdk.umd.min.js +795 -0
  75. package/dist/umd/js/bi-sdk.umd.min.js.LICENSE.txt +9 -0
  76. package/package.json +52 -0
  77. package/src/components/PageDesigner.tsx +509 -0
  78. package/src/components/context/DesignerContext.tsx +71 -0
  79. package/src/components/context/EnvContext.tsx +42 -0
  80. package/src/components/dnd/DropContainer.tsx +474 -0
  81. package/src/components/example.ts +577 -0
  82. package/src/components/hooks/datasource.ts +23 -0
  83. package/src/components/hooks/useDeepCompareEffect.ts +12 -0
  84. package/src/components/icon/IconFont.tsx +16 -0
  85. package/src/components/index.ts +29 -0
  86. package/src/components/layout/PageCanvas.tsx +145 -0
  87. package/src/components/layout/PageItem.tsx +182 -0
  88. package/src/components/panel/AiPanel.tsx +116 -0
  89. package/src/components/panel/CascadePanel.tsx +163 -0
  90. package/src/components/panel/ChatInput.tsx +550 -0
  91. package/src/components/panel/CodePanel.tsx +48 -0
  92. package/src/components/panel/ComponentPanel.tsx +119 -0
  93. package/src/components/panel/DatasourcePanel.tsx +419 -0
  94. package/src/components/panel/LayerPanel.tsx +238 -0
  95. package/src/components/panel/PaneHeader.tsx +34 -0
  96. package/src/components/panel/PropertiesPanel.tsx +394 -0
  97. package/src/components/panel/ScriptPanel.tsx +175 -0
  98. package/src/components/panel/VariablesPanel.tsx +153 -0
  99. package/src/components/panel/index.ts +9 -0
  100. package/src/components/plugins/@antd/index.ts +445 -0
  101. package/src/components/plugins/@antd/item-props/ButtonProps.tsx +91 -0
  102. package/src/components/plugins/@antd/item-props/CapsuleProps.tsx +102 -0
  103. package/src/components/plugins/@antd/item-props/CardProps.tsx +58 -0
  104. package/src/components/plugins/@antd/item-props/CheckboxProps.tsx +75 -0
  105. package/src/components/plugins/@antd/item-props/ColProps.tsx +43 -0
  106. package/src/components/plugins/@antd/item-props/DatePickerProps.tsx +72 -0
  107. package/src/components/plugins/@antd/item-props/EchartsProps.tsx +35 -0
  108. package/src/components/plugins/@antd/item-props/HtmlProps.tsx +61 -0
  109. package/src/components/plugins/@antd/item-props/ImageProps.tsx +43 -0
  110. package/src/components/plugins/@antd/item-props/InputNumberProps.tsx +18 -0
  111. package/src/components/plugins/@antd/item-props/InputProps.tsx +89 -0
  112. package/src/components/plugins/@antd/item-props/ListProps.tsx +69 -0
  113. package/src/components/plugins/@antd/item-props/PageHeaderProps.tsx +20 -0
  114. package/src/components/plugins/@antd/item-props/RowProps.tsx +21 -0
  115. package/src/components/plugins/@antd/item-props/SelectProps.tsx +136 -0
  116. package/src/components/plugins/@antd/item-props/SpaceProps.tsx +52 -0
  117. package/src/components/plugins/@antd/item-props/SwitchProps.tsx +17 -0
  118. package/src/components/plugins/@antd/item-props/TableProps.tsx +200 -0
  119. package/src/components/plugins/@antd/item-props/TextProps.tsx +41 -0
  120. package/src/components/plugins/@antd/item-props/index.ts +20 -0
  121. package/src/components/plugins/@antd/item-props/types.ts +6 -0
  122. package/src/components/plugins/@antd/items/ButtonRender.tsx +63 -0
  123. package/src/components/plugins/@antd/items/CapsuleRender.tsx +49 -0
  124. package/src/components/plugins/@antd/items/CardRender.tsx +119 -0
  125. package/src/components/plugins/@antd/items/CheckboxRender.tsx +56 -0
  126. package/src/components/plugins/@antd/items/ColRender.tsx +78 -0
  127. package/src/components/plugins/@antd/items/DatePickerRender.tsx +117 -0
  128. package/src/components/plugins/@antd/items/EchartsRender.tsx +98 -0
  129. package/src/components/plugins/@antd/items/HtmlRender.tsx +74 -0
  130. package/src/components/plugins/@antd/items/ImageRender.tsx +37 -0
  131. package/src/components/plugins/@antd/items/InputNumberRender.tsx +57 -0
  132. package/src/components/plugins/@antd/items/InputRender.tsx +75 -0
  133. package/src/components/plugins/@antd/items/ListRender.tsx +227 -0
  134. package/src/components/plugins/@antd/items/PageHeaderRender.tsx +74 -0
  135. package/src/components/plugins/@antd/items/RowRender.tsx +47 -0
  136. package/src/components/plugins/@antd/items/SelectRender.tsx +53 -0
  137. package/src/components/plugins/@antd/items/SpaceRender.tsx +54 -0
  138. package/src/components/plugins/@antd/items/SwitchRender.tsx +52 -0
  139. package/src/components/plugins/@antd/items/TableRender.tsx +99 -0
  140. package/src/components/plugins/@antd/items/TextRender.tsx +25 -0
  141. package/src/components/plugins/@antd/items/index.ts +20 -0
  142. package/src/components/styles.css +12 -0
  143. package/src/components/typing.ts +80 -0
  144. package/src/components/utils.ts +37 -0
  145. package/src/example.tsx +136 -0
  146. package/src/index.tsx +17 -0
@@ -0,0 +1,20 @@
1
+ export { CardRender } from './CardRender'
2
+ export { RowRender } from './RowRender'
3
+ export { ColRender } from './ColRender'
4
+ export { PageHeaderRender } from './PageHeaderRender'
5
+ export { TableRender } from './TableRender'
6
+ export { ListRender } from './ListRender'
7
+ export { HtmlRender } from './HtmlRender'
8
+ export { EchartsRender } from './EchartsRender'
9
+ export { TextRender } from './TextRender'
10
+ export { ImageRender } from './ImageRender'
11
+ export { ButtonRender } from './ButtonRender'
12
+ export { SpaceRender } from './SpaceRender'
13
+ export { InputRender } from './InputRender'
14
+ export { InputNumberRender } from './InputNumberRender'
15
+ export { SelectRender } from './SelectRender'
16
+ export { CapsuleRender } from './CapsuleRender'
17
+ export { CheckboxRender } from './CheckboxRender'
18
+ export { DatePickerRender } from './DatePickerRender'
19
+ export { SwitchRender } from './SwitchRender'
20
+
@@ -0,0 +1,12 @@
1
+ .ant-dropdown-menu-vertical {
2
+ max-height: 70vh;
3
+ overflow: auto;
4
+ }
5
+
6
+ a.toolbar {
7
+ color: var(--ant-color-text-secondary);
8
+
9
+ &.active {
10
+ color: var(--ant-color-primary);
11
+ }
12
+ }
@@ -0,0 +1,80 @@
1
+ import { MouseEventHandler } from "react";
2
+
3
+ export type HtmlBaseProps = {
4
+ id?: string;
5
+ style?: React.CSSProperties;
6
+ className?: string;
7
+ onClick?: MouseEventHandler;
8
+ };
9
+
10
+ export type SchemaItemType = {
11
+ id?: string;
12
+ type: string;
13
+ name?: string;
14
+ description?: string;
15
+ style?: React.CSSProperties;
16
+ props?: Record<string, any>;
17
+ cascadeIds?: string[];
18
+ children?: SchemaItemType[] | Record<string, SchemaItemType[]>;
19
+ datasource?: {
20
+ source?: "custom" | "define";
21
+ datasourceId?: string | null;
22
+ scriptId?: string | null;
23
+ custom?: string | null;
24
+ };
25
+ };
26
+
27
+ export type PluginType = {
28
+ group: string;
29
+ key: string;
30
+ label: string;
31
+ icon: string;
32
+ component: React.FC<any>;
33
+ formComponent?: React.FC<any>;
34
+ defaultOptions?: Pick<
35
+ SchemaItemType,
36
+ "props" | "children" | "cascadeIds" | "datasource" | "style"
37
+ >;
38
+ };
39
+ type NameValue = { name?: string; value?: string };
40
+ export type ScriptItem = { id?: string; name: string; script: string };
41
+ export type VariableItem = { name: string; value: string; id?: string };
42
+
43
+ export type ApiType = {
44
+ id: string;
45
+ type: "api";
46
+ name: string;
47
+ url: string;
48
+ method: "GET" | "POST" | "PUT" | "DELETE";
49
+ headers: NameValue[];
50
+ formData: NameValue[];
51
+ body: string;
52
+ };
53
+
54
+ export type SqlType = {
55
+ id: string;
56
+ type: "sql";
57
+ name: string;
58
+ query: string;
59
+ };
60
+
61
+ export type PageInfo = {
62
+ name?: string;
63
+ description?: string;
64
+ cover?: string;
65
+ };
66
+
67
+ export type PageSchema = {
68
+ info: PageInfo;
69
+ datasources: (ApiType | SqlType)[];
70
+ scripts: ScriptItem[];
71
+ variables: VariableItem[];
72
+ items: SchemaItemType[];
73
+ };
74
+
75
+ export type EnvType = {
76
+ global: Record<string, any>;
77
+ local: Record<string, Record<string, any>>;
78
+ };
79
+
80
+ export type CallbacksType = Record<string, (v: any) => void>;
@@ -0,0 +1,37 @@
1
+ import { useId } from "react";
2
+ import { CallbacksType, EnvType, SchemaItemType } from "./typing";
3
+ import { v4 } from "uuid";
4
+
5
+ type Env = EnvType;
6
+
7
+ export const getVars = (env: Env, item: SchemaItemType) => {
8
+ return { ...env.global, ...(env.local[item.id || ""] || {}) };
9
+ };
10
+
11
+ export const setVar = (
12
+ env: Env,
13
+ item: SchemaItemType,
14
+ key: string,
15
+ value: any
16
+ ) => {
17
+ (item.cascadeIds || []).forEach((id) => {
18
+ env.local[id] = env.local[id] || {};
19
+ env.local[id][key] = value;
20
+ });
21
+ };
22
+
23
+ export const handleCallback = (
24
+ env: Env,
25
+ item: SchemaItemType,
26
+ callbacks: CallbacksType
27
+ ) => {
28
+ const vars = getVars(env, item);
29
+ (item.cascadeIds || []).forEach((id) => {
30
+ const cb = callbacks[id];
31
+ if (typeof cb === "function") {
32
+ cb(vars);
33
+ }
34
+ });
35
+ };
36
+
37
+ export const uuid = () => v4();
@@ -0,0 +1,136 @@
1
+ import { CloseOutlined, EditOutlined, PlusOutlined } from "@ant-design/icons";
2
+ import { Button, Col, Divider, Drawer, Form, Input, Row, Table } from "antd";
3
+ import React, { useEffect, useRef, useState } from "react";
4
+ import styled from "styled-components";
5
+ import { PageDesigner } from "./components";
6
+ import { schema } from "./components/example";
7
+ import { plugins } from "./components/plugins/@antd";
8
+
9
+ type Agent = { id: string | number; name: string };
10
+
11
+ const EditDrawer = styled(Drawer)`
12
+ width: 80%;
13
+
14
+ .ant-drawer-content-wrapper {
15
+ width: 100%;
16
+
17
+ .ant-drawer-section {
18
+ width: 100%;
19
+
20
+ .ant-drawer-header {
21
+ padding: 8px 24px;
22
+ }
23
+ .ant-drawer-body {
24
+ padding: 0;
25
+ height: "calc(100vh - 41px)";
26
+ overflow: "hidden";
27
+ }
28
+ }
29
+ }
30
+ `;
31
+
32
+ export const Example: React.FC = () => {
33
+ const editDrawerRef = useRef<any>(null);
34
+ const [editVisible, setEditVisible] = useState(false);
35
+ const [agentList, setAgentList] = useState<Agent[]>([]);
36
+ const [params, setParams] = useState<{ name: string }>({ name: "" });
37
+ const columns = [
38
+ { title: "名称", dataIndex: "name", key: "name" },
39
+ {
40
+ title: "操作",
41
+ dataIndex: "operation",
42
+ key: "operation",
43
+ render: (_: any, record: any) => (
44
+ <a onClick={() => handleEditClick(record)}>
45
+ <EditOutlined />
46
+ </a>
47
+ ),
48
+ },
49
+ ];
50
+ const dataSource = [{ name: "数据报表1" }, { name: "数据报表2" }];
51
+ const handleEditClick = (record: any) => {
52
+ setEditVisible(true);
53
+ setTimeout(() => {
54
+ editDrawerRef.current?.handleOpen(JSON.parse(JSON.stringify(schema)));
55
+ }, 0);
56
+ };
57
+ const handleAdd = () => {
58
+ setEditVisible(true);
59
+ setTimeout(() => {
60
+ editDrawerRef.current?.handleOpen(JSON.parse(JSON.stringify(schema)));
61
+ }, 0);
62
+ };
63
+
64
+ useEffect(() => {
65
+ const initAgentList = async () => {
66
+ try {
67
+ setAgentList([]);
68
+ } catch {
69
+ setAgentList([]);
70
+ }
71
+ };
72
+ initAgentList();
73
+ }, []);
74
+ return (
75
+ <div style={{ padding: 20 }}>
76
+ <Row justify="space-around">
77
+ <Col flex="auto">
78
+ <Form layout="inline">
79
+ <Form.Item label="名称">
80
+ <Input
81
+ value={params.name}
82
+ onChange={(e) => setParams({ name: e.target.value })}
83
+ placeholder="请输入数据报表名称"
84
+ />
85
+ </Form.Item>
86
+ <Form.Item>
87
+ <Button>查询</Button>
88
+ </Form.Item>
89
+ </Form>
90
+ </Col>
91
+ <Col flex="100px">
92
+ <Button type="primary" onClick={handleAdd} icon={<PlusOutlined />}>
93
+ 创建数据报表
94
+ </Button>
95
+ </Col>
96
+ </Row>
97
+ <Table
98
+ size="small"
99
+ columns={columns as any}
100
+ dataSource={dataSource}
101
+ bordered
102
+ style={{ marginTop: 20 }}
103
+ rowKey={(_, i) => String(i)}
104
+ />
105
+ {editVisible && (
106
+ <EditDrawer
107
+ open={editVisible}
108
+ onClose={() => setEditVisible(false)}
109
+ styles={{
110
+ wrapper: { width: "100%" },
111
+ header: { display: "none" },
112
+ body: {
113
+ padding: 0,
114
+ height: "calc(100vh - 41px)",
115
+ overflow: "hidden",
116
+ },
117
+ }}
118
+ >
119
+ <PageDesigner
120
+ ref={editDrawerRef}
121
+ agentList={agentList}
122
+ plugins={plugins}
123
+ headerExtra={
124
+ <>
125
+ <Divider type="vertical" />
126
+ <a className="toolbar" onClick={() => setEditVisible(false)}>
127
+ <CloseOutlined />
128
+ </a>
129
+ </>
130
+ }
131
+ />
132
+ </EditDrawer>
133
+ )}
134
+ </div>
135
+ );
136
+ };
package/src/index.tsx ADDED
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom/client';
3
+ import { Example } from './example';
4
+
5
+ // export * from './components'
6
+
7
+
8
+ const rootElement = document.getElementById('root');
9
+
10
+ if (rootElement) {
11
+ const root = ReactDOM.createRoot(rootElement);
12
+ root.render(
13
+ <React.StrictMode>
14
+ <Example />
15
+ </React.StrictMode>
16
+ );
17
+ }