bi-sdk-react 0.0.49 → 0.0.51
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.
- package/dist/es/js/bi-sdk.es.js +55 -31
- package/dist/types/components/context/PageContext.d.ts +1 -2
- package/dist/types/components/layout/PageItem.d.ts +1 -0
- package/dist/types/components/plugins/@antd/index.d.ts +2 -0
- package/dist/types/components/plugins/@antd/item-props/DrawerProps.d.ts +20 -0
- package/dist/types/components/plugins/@antd/item-props/ModalProps.d.ts +18 -0
- package/dist/types/components/plugins/@antd/item-props/index.d.ts +2 -0
- package/dist/types/components/plugins/@antd/items/DrawerRender.d.ts +19 -0
- package/dist/types/components/plugins/@antd/items/ModalRender.d.ts +17 -0
- package/dist/types/components/plugins/@antd/items/index.d.ts +2 -0
- package/dist/umd/js/bi-sdk.umd.min.js +55 -31
- package/package.json +1 -1
- package/src/components/context/PageContext.tsx +2 -12
- package/src/components/dnd/DropContainer.tsx +34 -0
- package/src/components/hooks/datasource.ts +6 -6
- package/src/components/icon/IconFont.tsx +1 -1
- package/src/components/layout/PageItem.tsx +17 -2
- package/src/components/panel/LayerPanel.tsx +7 -6
- package/src/components/plugins/@antd/index.ts +56 -0
- package/src/components/plugins/@antd/item-props/DrawerProps.tsx +157 -0
- package/src/components/plugins/@antd/item-props/ModalProps.tsx +136 -0
- package/src/components/plugins/@antd/item-props/index.ts +2 -0
- package/src/components/plugins/@antd/items/DrawerRender.tsx +166 -0
- package/src/components/plugins/@antd/items/ModalRender.tsx +146 -0
- package/src/components/plugins/@antd/items/index.ts +2 -1
- package/src/example.tsx +2 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { Button, Drawer, Modal, Space } from "antd";
|
|
2
|
+
import React, { useContext, useEffect, useState } from "react";
|
|
3
|
+
import styled from "styled-components";
|
|
4
|
+
import { PageContext } from "../../../context/PageContext";
|
|
5
|
+
import { DropContainer } from "../../../dnd/DropContainer";
|
|
6
|
+
import { CallbackType, HtmlBaseProps, SchemaItemType } from "../../../typing";
|
|
7
|
+
|
|
8
|
+
const Placeholder = styled.div`
|
|
9
|
+
text-align: center;
|
|
10
|
+
color: #a7a7a7;
|
|
11
|
+
background: #f5f5f5;
|
|
12
|
+
border: dotted 1px #ccc;
|
|
13
|
+
user-select: none;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
font-size: 12px;
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export type DrawerRenderProps = {
|
|
20
|
+
item: any;
|
|
21
|
+
title?: string;
|
|
22
|
+
size?: number;
|
|
23
|
+
placement?: "top" | "bottom" | "left" | "right";
|
|
24
|
+
okType?: "primary" | "link" | "text" | "dashed" | "default";
|
|
25
|
+
okText?: string;
|
|
26
|
+
cancelText?: string;
|
|
27
|
+
closable?: boolean;
|
|
28
|
+
keyboard?: boolean;
|
|
29
|
+
mask?: boolean;
|
|
30
|
+
maskClosable?: boolean;
|
|
31
|
+
resizable?: boolean;
|
|
32
|
+
footer?: boolean;
|
|
33
|
+
ancestors: SchemaItemType[];
|
|
34
|
+
} & HtmlBaseProps;
|
|
35
|
+
|
|
36
|
+
export const DrawerRender: React.FC<DrawerRenderProps> = ({
|
|
37
|
+
id,
|
|
38
|
+
item,
|
|
39
|
+
ancestors,
|
|
40
|
+
style = {},
|
|
41
|
+
className,
|
|
42
|
+
footer = true,
|
|
43
|
+
okType = "primary",
|
|
44
|
+
okText = "确定",
|
|
45
|
+
cancelText = "取消",
|
|
46
|
+
resizable = true,
|
|
47
|
+
...rest
|
|
48
|
+
}) => {
|
|
49
|
+
const { designable, selectedItem, setSelectedItem, initCallback } =
|
|
50
|
+
useContext(PageContext);
|
|
51
|
+
const [open, setOpen] = useState(false);
|
|
52
|
+
const [localChildren, setLocalChildren] = useState(item.children || []);
|
|
53
|
+
const [size, setSize] = useState(rest.size || 400);
|
|
54
|
+
|
|
55
|
+
const onLocalChildrenChange = (list: any[]) => {
|
|
56
|
+
item.children = list;
|
|
57
|
+
setLocalChildren(list);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const callback: CallbackType = () => {
|
|
61
|
+
setOpen(true);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const updateToolbarPosition = () => {
|
|
65
|
+
const toolbarEl = document.getElementById("page-item-toolbar");
|
|
66
|
+
if (!toolbarEl) return;
|
|
67
|
+
const target = document.getElementById(`page-item-${item.id}`);
|
|
68
|
+
if (!target) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const rect = target.getBoundingClientRect();
|
|
72
|
+
if (rect.width === 0 && rect.height === 0) {
|
|
73
|
+
toolbarEl.style.display = "none";
|
|
74
|
+
return;
|
|
75
|
+
} else {
|
|
76
|
+
toolbarEl.style.display = "flex";
|
|
77
|
+
}
|
|
78
|
+
const scrollTop =
|
|
79
|
+
window.pageYOffset ||
|
|
80
|
+
document.documentElement.scrollTop ||
|
|
81
|
+
document.body.scrollTop ||
|
|
82
|
+
0;
|
|
83
|
+
const scrollLeft =
|
|
84
|
+
window.pageXOffset ||
|
|
85
|
+
document.documentElement.scrollLeft ||
|
|
86
|
+
document.body.scrollLeft ||
|
|
87
|
+
0;
|
|
88
|
+
toolbarEl.style.top = `${rect.top + scrollTop - 22}px`;
|
|
89
|
+
toolbarEl.style.left = `${rect.left + scrollLeft - 1}px`;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
setSize(rest.size || 400);
|
|
94
|
+
}, [rest.size]);
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
setLocalChildren(item.children || []);
|
|
98
|
+
}, [item.children]);
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
updateToolbarPosition();
|
|
103
|
+
}, 0);
|
|
104
|
+
}, [open]);
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
initCallback({ id: item.id, callback });
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
const classes = [
|
|
111
|
+
className,
|
|
112
|
+
"drag-container",
|
|
113
|
+
"page-item-component",
|
|
114
|
+
selectedItem === item ? "selected" : "",
|
|
115
|
+
designable ? "designable" : "",
|
|
116
|
+
]
|
|
117
|
+
.filter(Boolean)
|
|
118
|
+
.join(" ");
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<>
|
|
122
|
+
{designable && (
|
|
123
|
+
<Placeholder
|
|
124
|
+
id={open ? undefined : id || item.id}
|
|
125
|
+
onDoubleClick={() => setOpen(true)}
|
|
126
|
+
className={classes}
|
|
127
|
+
>
|
|
128
|
+
抽屉:{item.name}({item.id})
|
|
129
|
+
</Placeholder>
|
|
130
|
+
)}
|
|
131
|
+
<Drawer
|
|
132
|
+
{...rest}
|
|
133
|
+
id={id || item.id}
|
|
134
|
+
open={open}
|
|
135
|
+
size={size}
|
|
136
|
+
onClose={() => setOpen(false)}
|
|
137
|
+
getContainer={() =>
|
|
138
|
+
designable ? document.querySelector(".page-canvas")! : document.body
|
|
139
|
+
}
|
|
140
|
+
push={{ distance: 0 }}
|
|
141
|
+
style={{ ...(item.style || {}), ...style, paddingBottom: 0 }}
|
|
142
|
+
className={className}
|
|
143
|
+
onClick={() => setSelectedItem(item)}
|
|
144
|
+
footer={
|
|
145
|
+
footer ? (
|
|
146
|
+
<Space>
|
|
147
|
+
<Button onClick={() => setOpen(false)}>{cancelText}</Button>
|
|
148
|
+
<Button type={okType}>
|
|
149
|
+
{okText}
|
|
150
|
+
</Button>
|
|
151
|
+
</Space>
|
|
152
|
+
) : null
|
|
153
|
+
}
|
|
154
|
+
resizable={{
|
|
155
|
+
onResize: setSize,
|
|
156
|
+
}}
|
|
157
|
+
>
|
|
158
|
+
<DropContainer
|
|
159
|
+
ancestors={[...ancestors, item]}
|
|
160
|
+
list={localChildren}
|
|
161
|
+
onListChange={onLocalChildrenChange}
|
|
162
|
+
/>
|
|
163
|
+
</Drawer>
|
|
164
|
+
</>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Modal } from "antd";
|
|
2
|
+
import React, { useContext, useEffect, useState } from "react";
|
|
3
|
+
import styled from "styled-components";
|
|
4
|
+
import { PageContext } from "../../../context/PageContext";
|
|
5
|
+
import { DropContainer } from "../../../dnd/DropContainer";
|
|
6
|
+
import { CallbackType, HtmlBaseProps, SchemaItemType } from "../../../typing";
|
|
7
|
+
|
|
8
|
+
const Placeholder = styled.div`
|
|
9
|
+
text-align: center;
|
|
10
|
+
color: #a7a7a7;
|
|
11
|
+
background: #f5f5f5;
|
|
12
|
+
border: dotted 1px #ccc;
|
|
13
|
+
user-select: none;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
font-size: 12px;
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
export type ModalRenderProps = {
|
|
19
|
+
item: any;
|
|
20
|
+
title?: string;
|
|
21
|
+
width?: number;
|
|
22
|
+
okType?: "primary" | "link" | "text" | "dashed" | "default";
|
|
23
|
+
okText?: string;
|
|
24
|
+
cancelText?: string;
|
|
25
|
+
closable?: boolean;
|
|
26
|
+
keyboard?: boolean;
|
|
27
|
+
mask?: boolean;
|
|
28
|
+
maskClosable?: boolean;
|
|
29
|
+
footer?: boolean;
|
|
30
|
+
ancestors: SchemaItemType[];
|
|
31
|
+
} & HtmlBaseProps;
|
|
32
|
+
|
|
33
|
+
export const ModalRender: React.FC<ModalRenderProps> = ({
|
|
34
|
+
id,
|
|
35
|
+
item,
|
|
36
|
+
ancestors,
|
|
37
|
+
style = {},
|
|
38
|
+
className,
|
|
39
|
+
footer = true,
|
|
40
|
+
...rest
|
|
41
|
+
}) => {
|
|
42
|
+
const { designable, selectedItem, setSelectedItem, initCallback } =
|
|
43
|
+
useContext(PageContext);
|
|
44
|
+
const [open, setOpen] = useState(false);
|
|
45
|
+
const [localChildren, setLocalChildren] = useState(item.children || []);
|
|
46
|
+
|
|
47
|
+
const onLocalChildrenChange = (list: any[]) => {
|
|
48
|
+
item.children = list;
|
|
49
|
+
setLocalChildren(list);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const callback: CallbackType = () => {
|
|
53
|
+
setOpen(true);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const updateToolbarPosition = () => {
|
|
57
|
+
const toolbarEl = document.getElementById("page-item-toolbar");
|
|
58
|
+
if (!toolbarEl) return;
|
|
59
|
+
const target = document.getElementById(`page-item-${item.id}`);
|
|
60
|
+
if (!target) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const rect = target.getBoundingClientRect();
|
|
64
|
+
if (rect.width === 0 && rect.height === 0) {
|
|
65
|
+
toolbarEl.style.display = "none";
|
|
66
|
+
return;
|
|
67
|
+
} else {
|
|
68
|
+
toolbarEl.style.display = "flex";
|
|
69
|
+
}
|
|
70
|
+
const scrollTop =
|
|
71
|
+
window.pageYOffset ||
|
|
72
|
+
document.documentElement.scrollTop ||
|
|
73
|
+
document.body.scrollTop ||
|
|
74
|
+
0;
|
|
75
|
+
const scrollLeft =
|
|
76
|
+
window.pageXOffset ||
|
|
77
|
+
document.documentElement.scrollLeft ||
|
|
78
|
+
document.body.scrollLeft ||
|
|
79
|
+
0;
|
|
80
|
+
toolbarEl.style.top = `${rect.top + scrollTop - 22}px`;
|
|
81
|
+
toolbarEl.style.left = `${rect.left + scrollLeft - 1}px`;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
setLocalChildren(item.children || []);
|
|
86
|
+
}, [item.children]);
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
setTimeout(() => {
|
|
90
|
+
updateToolbarPosition();
|
|
91
|
+
}, 0);
|
|
92
|
+
}, [open]);
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
initCallback({ id: item.id, callback });
|
|
96
|
+
}, []);
|
|
97
|
+
|
|
98
|
+
const classes = [
|
|
99
|
+
className,
|
|
100
|
+
"drag-container",
|
|
101
|
+
"page-item-component",
|
|
102
|
+
selectedItem === item ? "selected" : "",
|
|
103
|
+
designable ? "designable" : "",
|
|
104
|
+
]
|
|
105
|
+
.filter(Boolean)
|
|
106
|
+
.join(" ");
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<>
|
|
110
|
+
{designable && (
|
|
111
|
+
<Placeholder
|
|
112
|
+
id={open ? undefined : id || item.id}
|
|
113
|
+
onDoubleClick={() => setOpen(true)}
|
|
114
|
+
className={classes}
|
|
115
|
+
>
|
|
116
|
+
弹窗:{item.name}({item.id})
|
|
117
|
+
</Placeholder>
|
|
118
|
+
)}
|
|
119
|
+
<Modal
|
|
120
|
+
{...rest}
|
|
121
|
+
open={open}
|
|
122
|
+
onCancel={() => setOpen(false)}
|
|
123
|
+
getContainer={() =>
|
|
124
|
+
designable ? document.querySelector(".page-canvas")! : document.body
|
|
125
|
+
}
|
|
126
|
+
style={{ ...(item.style || {}), ...style, paddingBottom: 0 }}
|
|
127
|
+
className={className}
|
|
128
|
+
modalRender={(modal) => (
|
|
129
|
+
<div
|
|
130
|
+
id={open ? id || item.id : undefined}
|
|
131
|
+
onClick={() => setSelectedItem(item)}
|
|
132
|
+
>
|
|
133
|
+
{modal}
|
|
134
|
+
</div>
|
|
135
|
+
)}
|
|
136
|
+
footer={footer ? undefined : null}
|
|
137
|
+
>
|
|
138
|
+
<DropContainer
|
|
139
|
+
ancestors={[...ancestors, item]}
|
|
140
|
+
list={localChildren}
|
|
141
|
+
onListChange={onLocalChildrenChange}
|
|
142
|
+
/>
|
|
143
|
+
</Modal>
|
|
144
|
+
</>
|
|
145
|
+
);
|
|
146
|
+
};
|
|
@@ -17,4 +17,5 @@ export { CapsuleRender } from './CapsuleRender'
|
|
|
17
17
|
export { CheckboxRender } from './CheckboxRender'
|
|
18
18
|
export { DatePickerRender } from './DatePickerRender'
|
|
19
19
|
export { SwitchRender } from './SwitchRender'
|
|
20
|
-
|
|
20
|
+
export { ModalRender } from './ModalRender'
|
|
21
|
+
export { DrawerRender } from './DrawerRender'
|
package/src/example.tsx
CHANGED
|
@@ -25,6 +25,7 @@ const EditDrawer = styled(Drawer)`
|
|
|
25
25
|
|
|
26
26
|
.ant-drawer-content-wrapper {
|
|
27
27
|
width: 100%;
|
|
28
|
+
transform: none !important;
|
|
28
29
|
|
|
29
30
|
.ant-drawer-section {
|
|
30
31
|
width: 100%;
|
|
@@ -122,7 +123,7 @@ export const Example: React.FC = () => {
|
|
|
122
123
|
open={editVisible}
|
|
123
124
|
onClose={() => setEditVisible(false)}
|
|
124
125
|
styles={{
|
|
125
|
-
wrapper: { width: "100%" },
|
|
126
|
+
wrapper: { width: "100%", transform: "none !important" },
|
|
126
127
|
header: { display: "none" },
|
|
127
128
|
body: {
|
|
128
129
|
padding: 0,
|