@raketa-builder/builder 0.27.0 → 0.29.0
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/.turbo/turbo-build.log +3 -3
- package/dist/index.js +559 -242
- package/package.json +1 -1
- package/src/Canvas.js +20 -2
- package/src/PageBuilder.js +74 -8
- package/src/dialogs/ReorderDialog.js +77 -22
- package/src/icons/IconCopy.js +33 -0
- package/src/icons/IconDelete.js +33 -0
- package/src/icons/index.js +4 -0
- package/src/lib/AdminWidget.js +42 -17
- package/src/lib/IconButton.js +0 -1
- package/src/lib/ModalSelectedWidgetsToolbar.js +51 -0
- package/src/lib/SelectedWidgetsToolbar.js +28 -0
- package/src/lists/index.js +7 -2
- package/src/styles.css +125 -3
package/package.json
CHANGED
package/src/Canvas.js
CHANGED
|
@@ -10,7 +10,15 @@ const EmptyCanvas = ({ className, ...rest }) => (
|
|
|
10
10
|
);
|
|
11
11
|
|
|
12
12
|
const Canvas = React.memo(
|
|
13
|
-
function Canvas({
|
|
13
|
+
function Canvas({
|
|
14
|
+
selectedWidgets,
|
|
15
|
+
widgets,
|
|
16
|
+
onReorder,
|
|
17
|
+
onEdit,
|
|
18
|
+
onRemove,
|
|
19
|
+
onCopy,
|
|
20
|
+
onSelectWidget,
|
|
21
|
+
}) {
|
|
14
22
|
const { library, adminLibrary } = React.useContext(LibraryContext);
|
|
15
23
|
|
|
16
24
|
if (widgets.length === 0) {
|
|
@@ -43,6 +51,8 @@ const Canvas = React.memo(
|
|
|
43
51
|
onEdit={onEdit}
|
|
44
52
|
onDelete={onRemove}
|
|
45
53
|
onCopy={onCopy}
|
|
54
|
+
onSelectWidget={onSelectWidget}
|
|
55
|
+
selectedWidgets={selectedWidgets}
|
|
46
56
|
/>
|
|
47
57
|
</ErrorBoundary>
|
|
48
58
|
))}
|
|
@@ -57,8 +67,16 @@ const Canvas = React.memo(
|
|
|
57
67
|
JSON.stringify(props.spacings) === JSON.stringify(nextProps.spacings);
|
|
58
68
|
const widgetsAreEqual =
|
|
59
69
|
JSON.stringify(props.widgets) === JSON.stringify(nextProps.widgets);
|
|
70
|
+
const selectedWidgetsAreEqual =
|
|
71
|
+
JSON.stringify(props.selectedWidgets) ===
|
|
72
|
+
JSON.stringify(nextProps.selectedWidgets);
|
|
60
73
|
|
|
61
|
-
return
|
|
74
|
+
return (
|
|
75
|
+
themesAreEqual &&
|
|
76
|
+
spacingsAreEqual &&
|
|
77
|
+
widgetsAreEqual &&
|
|
78
|
+
selectedWidgetsAreEqual
|
|
79
|
+
);
|
|
62
80
|
}
|
|
63
81
|
);
|
|
64
82
|
|
package/src/PageBuilder.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/* eslint-disable no-undef */
|
|
2
2
|
import React from "react";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
add,
|
|
5
|
+
removeById,
|
|
6
|
+
updateFieldById,
|
|
7
|
+
randomString,
|
|
8
|
+
removeMultipleById,
|
|
9
|
+
} from "./lists";
|
|
5
10
|
import HostContext from "./HostContext";
|
|
6
11
|
import LibraryContext from "./LibraryContext";
|
|
7
12
|
import Canvas from "./Canvas";
|
|
@@ -9,6 +14,7 @@ import AdminSidebar from "./lib/AdminSidebar";
|
|
|
9
14
|
import ReorderDialog from "./dialogs/ReorderDialog";
|
|
10
15
|
import SettingsDialog from "./dialogs/SettingsDialog";
|
|
11
16
|
import widgetData from "./helpers/widgetData";
|
|
17
|
+
import SelectedWidgetsToolbar from "./lib/SelectedWidgetsToolbar";
|
|
12
18
|
|
|
13
19
|
const usePreventWindowUnload = (preventDefault) => {
|
|
14
20
|
React.useEffect(() => {
|
|
@@ -24,6 +30,12 @@ const usePreventWindowUnload = (preventDefault) => {
|
|
|
24
30
|
}, [preventDefault]);
|
|
25
31
|
};
|
|
26
32
|
|
|
33
|
+
const saveToLocalStorage = (identifier, widgets) =>
|
|
34
|
+
window.localStorage.setItem(
|
|
35
|
+
`clipboard–${identifier}`,
|
|
36
|
+
JSON.stringify(widgets)
|
|
37
|
+
);
|
|
38
|
+
|
|
27
39
|
const PageBuilder = ({
|
|
28
40
|
page: initialPage,
|
|
29
41
|
library,
|
|
@@ -40,11 +52,24 @@ const PageBuilder = ({
|
|
|
40
52
|
const [dirty, setDirty] = React.useState(false);
|
|
41
53
|
const [selectedWidget, setSelectedWidget] = React.useState(null);
|
|
42
54
|
const [reorderOpen, setReorderOpen] = React.useState(false);
|
|
55
|
+
const [selectedWidgets, setSelectedWidgets] = React.useState([]);
|
|
56
|
+
|
|
57
|
+
const handleSelectWidget = (newWidget) => {
|
|
58
|
+
setSelectedWidgets((oldList) => {
|
|
59
|
+
const isUnique = oldList.filter((w) => w === newWidget).length <= 0;
|
|
60
|
+
|
|
61
|
+
if (isUnique) {
|
|
62
|
+
return [...oldList, newWidget];
|
|
63
|
+
} else {
|
|
64
|
+
return oldList.filter((w) => w !== newWidget);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
43
68
|
|
|
44
69
|
usePreventWindowUnload(dirty);
|
|
45
70
|
|
|
46
71
|
if (!adminLibrary) {
|
|
47
|
-
console.warn("No adminLibrary provided to AdminBuilder.
|
|
72
|
+
console.warn("No adminLibrary provided to AdminBuilder.");
|
|
48
73
|
}
|
|
49
74
|
|
|
50
75
|
const currentWidget = selectedWidget
|
|
@@ -62,6 +87,8 @@ const PageBuilder = ({
|
|
|
62
87
|
};
|
|
63
88
|
};
|
|
64
89
|
|
|
90
|
+
const handleSelectAll = (items) => setSelectedWidgets(items);
|
|
91
|
+
|
|
65
92
|
const handleAdd = (widgetName) => {
|
|
66
93
|
const widgets = add(page.widgets, factory(widgetName));
|
|
67
94
|
const newPage = {
|
|
@@ -106,6 +133,22 @@ const PageBuilder = ({
|
|
|
106
133
|
notifyChange(newPage);
|
|
107
134
|
};
|
|
108
135
|
|
|
136
|
+
const handleRemoveMultiple = () => {
|
|
137
|
+
if (!confirm("Are you sure?")) return;
|
|
138
|
+
|
|
139
|
+
const widgets = removeMultipleById(page.widgets, selectedWidgets);
|
|
140
|
+
const newPage = {
|
|
141
|
+
...page,
|
|
142
|
+
widgets,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
setPage(newPage);
|
|
146
|
+
setDirty(true);
|
|
147
|
+
setSelectedWidgets([]);
|
|
148
|
+
|
|
149
|
+
notifyChange(newPage);
|
|
150
|
+
};
|
|
151
|
+
|
|
109
152
|
const handleReorder = (widgets) => {
|
|
110
153
|
if (
|
|
111
154
|
page.widgets.map((w) => w.widgetId).join() !==
|
|
@@ -130,11 +173,19 @@ const PageBuilder = ({
|
|
|
130
173
|
setDirty(false);
|
|
131
174
|
};
|
|
132
175
|
|
|
133
|
-
const handleCopyWidgets = (widgets) => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
176
|
+
const handleCopyWidgets = (widgets, copyType) => {
|
|
177
|
+
if (copyType === "multiple") {
|
|
178
|
+
const filterSelected = page.widgets.filter((w) =>
|
|
179
|
+
widgets.some((c) => w.widgetId === c)
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
saveToLocalStorage(identifier, filterSelected);
|
|
183
|
+
setSelectedWidgets([]);
|
|
184
|
+
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
saveToLocalStorage(identifier, widgets);
|
|
138
189
|
};
|
|
139
190
|
|
|
140
191
|
const handlePasteWidget = () => {
|
|
@@ -192,6 +243,14 @@ const PageBuilder = ({
|
|
|
192
243
|
<HostContext.Provider value={{ host }}>
|
|
193
244
|
<LibraryContext.Provider value={{ library, adminLibrary }}>
|
|
194
245
|
<div style={{ paddingLeft: "64px" }}>
|
|
246
|
+
{!reorderOpen && selectedWidgets.length > 0 && (
|
|
247
|
+
<SelectedWidgetsToolbar
|
|
248
|
+
length={selectedWidgets.length}
|
|
249
|
+
onCopy={() => handleCopyWidgets(selectedWidgets, "multiple")}
|
|
250
|
+
onRemove={handleRemoveMultiple}
|
|
251
|
+
/>
|
|
252
|
+
)}
|
|
253
|
+
|
|
195
254
|
{reorderOpen && (
|
|
196
255
|
<ReorderDialog
|
|
197
256
|
widgets={sortableWidgets}
|
|
@@ -199,6 +258,11 @@ const PageBuilder = ({
|
|
|
199
258
|
onDelete={handleRemove}
|
|
200
259
|
onSelectWidget={setSelectedWidget}
|
|
201
260
|
onClose={() => setReorderOpen(false)}
|
|
261
|
+
selectedWidgets={selectedWidgets}
|
|
262
|
+
onSelectWidgets={handleSelectWidget}
|
|
263
|
+
onCopy={() => handleCopyWidgets(selectedWidgets, "multiple")}
|
|
264
|
+
onRemove={handleRemoveMultiple}
|
|
265
|
+
onSelectAll={handleSelectAll}
|
|
202
266
|
/>
|
|
203
267
|
)}
|
|
204
268
|
|
|
@@ -219,6 +283,8 @@ const PageBuilder = ({
|
|
|
219
283
|
onEdit={setSelectedWidget}
|
|
220
284
|
onRemove={handleRemove}
|
|
221
285
|
onCopy={handleCopyWidgets}
|
|
286
|
+
selectedWidgets={selectedWidgets}
|
|
287
|
+
onSelectWidget={handleSelectWidget}
|
|
222
288
|
/>
|
|
223
289
|
|
|
224
290
|
{selectedWidget && (
|
|
@@ -5,6 +5,7 @@ import { H, P, Button, cn } from "@raketa-builder/ui";
|
|
|
5
5
|
import Dialog from "./Dialog";
|
|
6
6
|
import LibraryContext from "../LibraryContext";
|
|
7
7
|
import widgetData from "../helpers/widgetData";
|
|
8
|
+
import ModalSelectedWidgetsToolbar from "../lib/ModalSelectedWidgetsToolbar";
|
|
8
9
|
|
|
9
10
|
const ReorderDialogItem = ({ className, ...props }) => (
|
|
10
11
|
<div className={cn("r-reorder-dialog-item", className)} {...props} />
|
|
@@ -32,7 +33,7 @@ const getWidgetTitle = (library, widget) => {
|
|
|
32
33
|
|
|
33
34
|
if (primaryField && typeof primaryField !== "string") {
|
|
34
35
|
throw new Error(
|
|
35
|
-
`The primaryField value of '${widget.component}' must be either a string or not present
|
|
36
|
+
`The primaryField value of '${widget.component}' must be either a string or not present!`
|
|
36
37
|
);
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -47,9 +48,26 @@ const ReorderDialog = ({
|
|
|
47
48
|
onChange,
|
|
48
49
|
onDelete,
|
|
49
50
|
onSelectWidget,
|
|
51
|
+
selectedWidgets,
|
|
52
|
+
onSelectWidgets,
|
|
53
|
+
onCopy,
|
|
54
|
+
onRemove,
|
|
55
|
+
onSelectAll,
|
|
50
56
|
}) => {
|
|
51
57
|
const { adminLibrary } = React.useContext(LibraryContext);
|
|
52
58
|
|
|
59
|
+
const isSelected = (id) => selectedWidgets.filter((w) => w === id).length > 0;
|
|
60
|
+
|
|
61
|
+
const areAllSelected = selectedWidgets.length === widgets.length;
|
|
62
|
+
|
|
63
|
+
const handleSelectWidget = (id) => onSelectWidgets(id);
|
|
64
|
+
|
|
65
|
+
const handleSelectAll = () => {
|
|
66
|
+
if (areAllSelected) return onSelectAll([]);
|
|
67
|
+
|
|
68
|
+
onSelectAll(widgets.map((w) => w.widgetId));
|
|
69
|
+
};
|
|
70
|
+
|
|
53
71
|
return (
|
|
54
72
|
<Dialog
|
|
55
73
|
open
|
|
@@ -58,7 +76,23 @@ const ReorderDialog = ({
|
|
|
58
76
|
primaryLabel=""
|
|
59
77
|
secondaryLabel="Close"
|
|
60
78
|
>
|
|
61
|
-
|
|
79
|
+
{widgets.length > 0 ? (
|
|
80
|
+
<>
|
|
81
|
+
<P>Drag and drop elements below to reorder the page layout.</P>
|
|
82
|
+
<ModalSelectedWidgetsToolbar
|
|
83
|
+
selectedWidgets={selectedWidgets}
|
|
84
|
+
onSelectAll={handleSelectAll}
|
|
85
|
+
areAllSelected={areAllSelected}
|
|
86
|
+
onCopy={onCopy}
|
|
87
|
+
onRemove={onRemove}
|
|
88
|
+
/>
|
|
89
|
+
</>
|
|
90
|
+
) : (
|
|
91
|
+
<P>
|
|
92
|
+
It's always good to start with a clean slate. Use the sidebar to add
|
|
93
|
+
content.
|
|
94
|
+
</P>
|
|
95
|
+
)}
|
|
62
96
|
|
|
63
97
|
<ReactSortable
|
|
64
98
|
list={widgets}
|
|
@@ -69,8 +103,22 @@ const ReorderDialog = ({
|
|
|
69
103
|
>
|
|
70
104
|
{widgets.map((widget) => (
|
|
71
105
|
<div key={widget.widgetId}>
|
|
72
|
-
<ReorderDialogItem
|
|
106
|
+
<ReorderDialogItem
|
|
107
|
+
data-drag
|
|
108
|
+
className={isSelected(widget.widgetId) ? "r-selected" : ""}
|
|
109
|
+
>
|
|
73
110
|
<div style={{ display: "flex", alignItems: "center" }}>
|
|
111
|
+
<input
|
|
112
|
+
type="checkbox"
|
|
113
|
+
style={{
|
|
114
|
+
width: "16px",
|
|
115
|
+
marginRight: "8px",
|
|
116
|
+
aspectRatio: 1,
|
|
117
|
+
}}
|
|
118
|
+
onChange={() => handleSelectWidget(widget.widgetId)}
|
|
119
|
+
checked={isSelected(widget.widgetId)}
|
|
120
|
+
/>
|
|
121
|
+
|
|
74
122
|
<H
|
|
75
123
|
size="base"
|
|
76
124
|
style={{
|
|
@@ -82,31 +130,38 @@ const ReorderDialog = ({
|
|
|
82
130
|
</H>
|
|
83
131
|
</div>
|
|
84
132
|
|
|
85
|
-
|
|
86
|
-
|
|
133
|
+
{!isSelected(widget.widgetId) && (
|
|
134
|
+
<div
|
|
135
|
+
style={{
|
|
136
|
+
display: "flex",
|
|
137
|
+
alignItems: "center",
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
{adminLibrary[widget.component] && (
|
|
141
|
+
<Button
|
|
142
|
+
type="button"
|
|
143
|
+
variant="primary"
|
|
144
|
+
onClick={() => {
|
|
145
|
+
onClose();
|
|
146
|
+
onSelectWidget(widget);
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
Edit
|
|
150
|
+
</Button>
|
|
151
|
+
)}
|
|
152
|
+
|
|
87
153
|
<Button
|
|
88
154
|
type="button"
|
|
89
|
-
variant="
|
|
155
|
+
variant="danger"
|
|
90
156
|
onClick={() => {
|
|
91
|
-
|
|
92
|
-
|
|
157
|
+
if (!confirm("Are you sure?")) return;
|
|
158
|
+
onDelete(widget.widgetId);
|
|
93
159
|
}}
|
|
94
160
|
>
|
|
95
|
-
|
|
161
|
+
×
|
|
96
162
|
</Button>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
<Button
|
|
100
|
-
type="button"
|
|
101
|
-
variant="danger"
|
|
102
|
-
onClick={() => {
|
|
103
|
-
if (!confirm("Are you sure?")) return;
|
|
104
|
-
onDelete(widget.widgetId);
|
|
105
|
-
}}
|
|
106
|
-
>
|
|
107
|
-
×
|
|
108
|
-
</Button>
|
|
109
|
-
</div>
|
|
163
|
+
</div>
|
|
164
|
+
)}
|
|
110
165
|
</ReorderDialogItem>
|
|
111
166
|
</div>
|
|
112
167
|
))}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const IconCopy = () => (
|
|
2
|
+
<svg
|
|
3
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
4
|
+
width="16"
|
|
5
|
+
height="16"
|
|
6
|
+
viewBox="0 0 16 16"
|
|
7
|
+
fill="none"
|
|
8
|
+
>
|
|
9
|
+
<g clipPath="url(#clip0_2312_498)">
|
|
10
|
+
<path
|
|
11
|
+
d="M13.3334 5.33331H6.66671C5.93033 5.33331 5.33337 5.93027 5.33337 6.66665V13.3333C5.33337 14.0697 5.93033 14.6666 6.66671 14.6666H13.3334C14.0698 14.6666 14.6667 14.0697 14.6667 13.3333V6.66665C14.6667 5.93027 14.0698 5.33331 13.3334 5.33331Z"
|
|
12
|
+
stroke="white"
|
|
13
|
+
strokeWidth="2"
|
|
14
|
+
strokeLinecap="round"
|
|
15
|
+
strokeLinejoin="round"
|
|
16
|
+
/>
|
|
17
|
+
<path
|
|
18
|
+
d="M2.66671 10.6666C1.93337 10.6666 1.33337 10.0666 1.33337 9.33331V2.66665C1.33337 1.93331 1.93337 1.33331 2.66671 1.33331H9.33337C10.0667 1.33331 10.6667 1.93331 10.6667 2.66665"
|
|
19
|
+
stroke="white"
|
|
20
|
+
strokeWidth="2"
|
|
21
|
+
strokeLinecap="round"
|
|
22
|
+
strokeLinejoin="round"
|
|
23
|
+
/>
|
|
24
|
+
</g>
|
|
25
|
+
<defs>
|
|
26
|
+
<clipPath id="clip0_2312_498">
|
|
27
|
+
<rect width="16" height="16" fill="white" />
|
|
28
|
+
</clipPath>
|
|
29
|
+
</defs>
|
|
30
|
+
</svg>
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export default IconCopy;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const IconDelete = () => (
|
|
2
|
+
<svg
|
|
3
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
4
|
+
width="16"
|
|
5
|
+
height="16"
|
|
6
|
+
viewBox="0 0 16 16"
|
|
7
|
+
fill="none"
|
|
8
|
+
>
|
|
9
|
+
<path
|
|
10
|
+
d="M2 4H14"
|
|
11
|
+
stroke="white"
|
|
12
|
+
strokeWidth="2"
|
|
13
|
+
strokeLinecap="round"
|
|
14
|
+
strokeLinejoin="round"
|
|
15
|
+
/>
|
|
16
|
+
<path
|
|
17
|
+
d="M12.6667 4V13.3333C12.6667 14 12 14.6667 11.3334 14.6667H4.66671C4.00004 14.6667 3.33337 14 3.33337 13.3333V4"
|
|
18
|
+
stroke="white"
|
|
19
|
+
strokeWidth="2"
|
|
20
|
+
strokeLinecap="round"
|
|
21
|
+
strokeLinejoin="round"
|
|
22
|
+
/>
|
|
23
|
+
<path
|
|
24
|
+
d="M5.33337 3.99998V2.66665C5.33337 1.99998 6.00004 1.33331 6.66671 1.33331H9.33337C10 1.33331 10.6667 1.99998 10.6667 2.66665V3.99998"
|
|
25
|
+
stroke="white"
|
|
26
|
+
strokeWidth="2"
|
|
27
|
+
strokeLinecap="round"
|
|
28
|
+
strokeLinejoin="round"
|
|
29
|
+
/>
|
|
30
|
+
</svg>
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export default IconDelete;
|
package/src/lib/AdminWidget.js
CHANGED
|
@@ -13,6 +13,8 @@ const AdminWidget = ({
|
|
|
13
13
|
onEdit,
|
|
14
14
|
onDelete,
|
|
15
15
|
onCopy,
|
|
16
|
+
onSelectWidget,
|
|
17
|
+
selectedWidgets,
|
|
16
18
|
}) => {
|
|
17
19
|
const currentWidget = library[widget.component];
|
|
18
20
|
const currentAdminWidget = adminLibrary[widget.component];
|
|
@@ -22,6 +24,11 @@ const AdminWidget = ({
|
|
|
22
24
|
return null;
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
const isSelected =
|
|
28
|
+
selectedWidgets.filter((w) => w === widget.widgetId).length > 0;
|
|
29
|
+
|
|
30
|
+
const handleSelectWidget = () => onSelectWidget(widget.widgetId);
|
|
31
|
+
|
|
25
32
|
const handleDeleteWidget = () => {
|
|
26
33
|
if (!confirm("Are you sure?")) return;
|
|
27
34
|
|
|
@@ -35,31 +42,49 @@ const AdminWidget = ({
|
|
|
35
42
|
|
|
36
43
|
return (
|
|
37
44
|
<AdminWidgetWrapper data-widget={widget.component}>
|
|
45
|
+
{isSelected && <div className="r-selected-widget" />}
|
|
38
46
|
<AdminWidgetToolbar data-toolbar>
|
|
39
|
-
<IconButton icon="iconMove" data-drag />
|
|
40
|
-
<IconButton
|
|
41
|
-
icon="iconEdit"
|
|
42
|
-
type="primary"
|
|
43
|
-
onClick={() => onEdit(widget)}
|
|
44
|
-
/>
|
|
45
|
-
<IconButton
|
|
46
|
-
icon="iconDelete"
|
|
47
|
-
type="danger"
|
|
48
|
-
onClick={() => handleDeleteWidget(widget.widgetId)}
|
|
49
|
-
/>
|
|
50
|
-
|
|
51
47
|
{!widgetData.deprecated(currentAdminWidget) && (
|
|
52
|
-
<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
<input
|
|
49
|
+
type="checkbox"
|
|
50
|
+
style={{
|
|
51
|
+
width: "32px",
|
|
52
|
+
height: "32px",
|
|
53
|
+
}}
|
|
54
|
+
onChange={handleSelectWidget}
|
|
55
|
+
checked={isSelected}
|
|
57
56
|
/>
|
|
58
57
|
)}
|
|
58
|
+
|
|
59
|
+
{!isSelected && (
|
|
60
|
+
<>
|
|
61
|
+
<IconButton icon="iconMove" data-drag />
|
|
62
|
+
<IconButton
|
|
63
|
+
icon="iconEdit"
|
|
64
|
+
type="primary"
|
|
65
|
+
onClick={() => onEdit(widget)}
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
<IconButton
|
|
69
|
+
icon="iconDelete"
|
|
70
|
+
type="danger"
|
|
71
|
+
onClick={() => handleDeleteWidget(widget.widgetId)}
|
|
72
|
+
/>
|
|
73
|
+
|
|
74
|
+
{!widgetData.deprecated(currentAdminWidget) && (
|
|
75
|
+
<IconButton
|
|
76
|
+
icon="iconCopy"
|
|
77
|
+
type="neutral"
|
|
78
|
+
onClick={handleCopyWidget}
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
81
|
+
</>
|
|
82
|
+
)}
|
|
59
83
|
</AdminWidgetToolbar>
|
|
60
84
|
|
|
61
85
|
<AdminWidgetLabel data-widget-label>
|
|
62
86
|
{widgetData.title(currentAdminWidget)}
|
|
87
|
+
{widgetData.deprecated(currentAdminWidget) && " (deprecated)"}
|
|
63
88
|
</AdminWidgetLabel>
|
|
64
89
|
|
|
65
90
|
{React.createElement(currentWidget, widget.settings)}
|
package/src/lib/IconButton.js
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
const ModalSelectedWidgetsToolbar = ({
|
|
4
|
+
selectedWidgets,
|
|
5
|
+
onSelectAll,
|
|
6
|
+
areAllSelected,
|
|
7
|
+
onCopy,
|
|
8
|
+
onRemove,
|
|
9
|
+
}) => (
|
|
10
|
+
<div className="r-selected-widget-toolbar-reorder">
|
|
11
|
+
<label
|
|
12
|
+
htmlFor="selectAll"
|
|
13
|
+
className="r-reset r-heading r-fs-base r-label-select-all"
|
|
14
|
+
>
|
|
15
|
+
<input
|
|
16
|
+
type="checkbox"
|
|
17
|
+
id="selectAll"
|
|
18
|
+
style={{
|
|
19
|
+
width: "16px",
|
|
20
|
+
height: "16px",
|
|
21
|
+
marginRight: "8px",
|
|
22
|
+
}}
|
|
23
|
+
onChange={onSelectAll}
|
|
24
|
+
checked={areAllSelected}
|
|
25
|
+
/>
|
|
26
|
+
Select all
|
|
27
|
+
</label>
|
|
28
|
+
|
|
29
|
+
{selectedWidgets.length > 0 && (
|
|
30
|
+
<>
|
|
31
|
+
<button
|
|
32
|
+
type="button"
|
|
33
|
+
className="r-button-reset r-reset r-heading r-fs-base r-button-toolbar-reorder"
|
|
34
|
+
onClick={onCopy}
|
|
35
|
+
>
|
|
36
|
+
Copy selected ({selectedWidgets.length})
|
|
37
|
+
</button>
|
|
38
|
+
|
|
39
|
+
<button
|
|
40
|
+
type="button"
|
|
41
|
+
className="r-button-reset r-reset r-heading r-fs-base r-button-toolbar-reorder"
|
|
42
|
+
onClick={onRemove}
|
|
43
|
+
>
|
|
44
|
+
Delete selected
|
|
45
|
+
</button>
|
|
46
|
+
</>
|
|
47
|
+
)}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
export default ModalSelectedWidgetsToolbar;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { IconCopy, IconDelete } from "../icons";
|
|
3
|
+
|
|
4
|
+
const SelectedWidgetsToolbar = ({ length, onRemove, onCopy }) => (
|
|
5
|
+
<div className="r-selected-widgets-toolbar">
|
|
6
|
+
<div className="r-toolbar-inner">
|
|
7
|
+
<button
|
|
8
|
+
type="button"
|
|
9
|
+
className="r-button-reset r-toolbar-button r-toolbar-button-copy"
|
|
10
|
+
onClick={onCopy}
|
|
11
|
+
>
|
|
12
|
+
<IconCopy />
|
|
13
|
+
Copy selected ({length})
|
|
14
|
+
</button>
|
|
15
|
+
|
|
16
|
+
<button
|
|
17
|
+
type="button"
|
|
18
|
+
className="r-button-reset r-toolbar-button r-toolbar-button-delete"
|
|
19
|
+
onClick={onRemove}
|
|
20
|
+
>
|
|
21
|
+
<IconDelete />
|
|
22
|
+
Delete selected
|
|
23
|
+
</button>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export default SelectedWidgetsToolbar;
|
package/src/lists/index.js
CHANGED
|
@@ -8,8 +8,12 @@ const removeByIndex = (items, idx) => [
|
|
|
8
8
|
const removeById = (items, id, idField = "id") =>
|
|
9
9
|
removeByIndex(
|
|
10
10
|
items,
|
|
11
|
-
items.findIndex((current) => current[idField] === id)
|
|
11
|
+
items.findIndex((current) => current[idField] === id)
|
|
12
12
|
);
|
|
13
|
+
|
|
14
|
+
const removeMultipleById = (items, selected) =>
|
|
15
|
+
items.filter((i) => !selected.some((c) => i.widgetId === c));
|
|
16
|
+
|
|
13
17
|
const updateFieldByIndex = (items, field, value, idx) => [
|
|
14
18
|
...items.slice(0, idx),
|
|
15
19
|
Object.assign({}, items[idx], { [field]: value }),
|
|
@@ -20,7 +24,7 @@ const updateFieldById = (items, field, value, id, idField = "id") =>
|
|
|
20
24
|
items,
|
|
21
25
|
field,
|
|
22
26
|
value,
|
|
23
|
-
items.findIndex((current) => current[idField] === id)
|
|
27
|
+
items.findIndex((current) => current[idField] === id)
|
|
24
28
|
);
|
|
25
29
|
const reorder = (items, order) => order.map((idx) => items[idx]);
|
|
26
30
|
|
|
@@ -38,4 +42,5 @@ export {
|
|
|
38
42
|
reorder,
|
|
39
43
|
randomId,
|
|
40
44
|
randomString,
|
|
45
|
+
removeMultipleById,
|
|
41
46
|
};
|