@raketa-builder/builder 1.3.6 → 1.3.9
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/AdminForm/SchemaInput.js +1 -0
- package/dist/AdminForm/SimpleInput.js +26 -0
- package/dist/AdminForm/index.js +136 -0
- package/dist/AutoSaveNotification.js +20 -0
- package/dist/Canvas.js +67 -0
- package/{src → dist}/ErrorBoundary/ErrorBoundary.js +7 -9
- package/dist/ErrorBoundary/index.js +6 -0
- package/dist/HostContext.js +7 -0
- package/dist/LibraryContext.js +7 -0
- package/dist/List.js +255 -0
- package/dist/ListInput.js +9 -0
- package/dist/MediaManager.js +19 -0
- package/dist/PageBuilder.js +312 -0
- package/dist/chunk-BBZEL7EG.js +53 -0
- package/dist/contexts/BuilderContext.js +10 -0
- package/dist/dialogs/Dialog.js +50 -0
- package/dist/dialogs/ReorderDialog.js +164 -0
- package/dist/dialogs/SettingsDialog.js +57 -0
- package/{src → dist}/forms/Button.js +16 -16
- package/dist/forms/ButtonSettings.js +121 -0
- package/dist/forms/LinkSettings.js +105 -0
- package/dist/forms/SelectMenu.js +55 -0
- package/dist/forms/TextArea.js +12 -0
- package/dist/forms/TextInput.js +44 -0
- package/dist/helpers/humanize.js +10 -0
- package/{src → dist}/helpers/imageSrc.js +5 -8
- package/{src → dist}/helpers/widgetData.js +5 -8
- package/dist/icons/IconCopy.js +41 -0
- package/dist/icons/IconDelete.js +48 -0
- package/dist/icons/index.js +3 -0
- package/dist/index.js +17 -0
- package/dist/lib/AdminSidebar.js +149 -0
- package/dist/lib/AdminWidget.js +102 -0
- package/dist/lib/AdminWidgetLabel.js +16 -0
- package/dist/lib/AdminWidgetToolbar.js +16 -0
- package/dist/lib/AdminWidgetWrapper.js +11 -0
- package/dist/lib/IconButton.js +45 -0
- package/{src → dist}/lib/Image.js +30 -54
- package/dist/lib/LanguageSwitcher.js +86 -0
- package/dist/lib/Link.js +21 -0
- package/dist/lib/ModalSelectedWidgetsToolbar.js +63 -0
- package/dist/lib/SelectedWidgetsToolbar.js +36 -0
- package/dist/lib/SideNav.js +134 -0
- package/dist/lib/SidebarItem.js +21 -0
- package/{src → dist}/lists/index.js +17 -32
- package/package.json +19 -5
- package/CHANGELOG.md +0 -26
- package/biome.json +0 -3
- package/dist/index.mjs +0 -2460
- package/src/AdminForm/SchemaInput.js +0 -0
- package/src/AdminForm/SimpleInput.js +0 -28
- package/src/AdminForm/index.js +0 -141
- package/src/AutoSaveNotification.js +0 -24
- package/src/Canvas.js +0 -85
- package/src/ErrorBoundary/index.js +0 -3
- package/src/HostContext.js +0 -5
- package/src/LibraryContext.js +0 -5
- package/src/List.js +0 -302
- package/src/ListInput.js +0 -6
- package/src/MediaManager.js +0 -15
- package/src/PageBuilder.js +0 -407
- package/src/contexts/BuilderContext.js +0 -8
- package/src/dialogs/Dialog.js +0 -61
- package/src/dialogs/ReorderDialog.js +0 -173
- package/src/dialogs/SettingsDialog.js +0 -56
- package/src/forms/ButtonSettings.js +0 -115
- package/src/forms/LinkSettings.js +0 -96
- package/src/forms/SelectMenu.js +0 -69
- package/src/forms/TextArea.js +0 -10
- package/src/forms/TextInput.js +0 -41
- package/src/helpers/humanize.js +0 -9
- package/src/icons/IconCopy.js +0 -33
- package/src/icons/IconDelete.js +0 -33
- package/src/icons/index.js +0 -4
- package/src/index.js +0 -36
- package/src/lib/AdminSidebar.js +0 -210
- package/src/lib/AdminWidget.js +0 -118
- package/src/lib/AdminWidgetLabel.js +0 -10
- package/src/lib/AdminWidgetToolbar.js +0 -10
- package/src/lib/AdminWidgetWrapper.js +0 -7
- package/src/lib/IconButton.js +0 -45
- package/src/lib/LanguageSwitcher.js +0 -87
- package/src/lib/Link.js +0 -19
- package/src/lib/ModalSelectedWidgetsToolbar.js +0 -51
- package/src/lib/SelectedWidgetsToolbar.js +0 -28
- package/src/lib/SideNav.js +0 -118
- package/src/lib/SidebarItem.js +0 -14
- package/src/styles.css +0 -649
- package/tsconfig.json +0 -5
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { __spreadProps, __spreadValues, __async } from './chunk-BBZEL7EG.js';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { add, removeById, removeMultipleById, randomString, updateFieldById } from './lists';
|
|
5
|
+
import HostContext from './HostContext';
|
|
6
|
+
import LibraryContext from './LibraryContext';
|
|
7
|
+
import Canvas from './Canvas';
|
|
8
|
+
import AdminSidebar from './lib/AdminSidebar';
|
|
9
|
+
import ReorderDialog from './dialogs/ReorderDialog';
|
|
10
|
+
import SettingsDialog from './dialogs/SettingsDialog';
|
|
11
|
+
import widgetData from './helpers/widgetData';
|
|
12
|
+
import SelectedWidgetsToolbar from './lib/SelectedWidgetsToolbar';
|
|
13
|
+
import Notification from './AutoSaveNotification';
|
|
14
|
+
|
|
15
|
+
const saveToLocalStorage = (identifier, widgets) => window.localStorage.setItem(
|
|
16
|
+
`clipboard\u2013${identifier}`,
|
|
17
|
+
JSON.stringify(widgets)
|
|
18
|
+
);
|
|
19
|
+
function sanitizeWidgets(page) {
|
|
20
|
+
const sanitizedWidgets = page.widgets.map((w) => {
|
|
21
|
+
Object.keys(w.settings).forEach((key) => {
|
|
22
|
+
if (key.includes("__")) {
|
|
23
|
+
delete w.settings[key];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return __spreadValues({}, w);
|
|
27
|
+
});
|
|
28
|
+
return __spreadProps(__spreadValues({}, page), { widgets: sanitizedWidgets });
|
|
29
|
+
}
|
|
30
|
+
const PageBuilder = ({
|
|
31
|
+
context = {},
|
|
32
|
+
preloaded = {},
|
|
33
|
+
page: initialPage,
|
|
34
|
+
library,
|
|
35
|
+
adminLibrary,
|
|
36
|
+
fetchers = {},
|
|
37
|
+
languageSwitcherSettings,
|
|
38
|
+
identifier,
|
|
39
|
+
sidebarButtons,
|
|
40
|
+
host,
|
|
41
|
+
onChange,
|
|
42
|
+
onSave,
|
|
43
|
+
onExit,
|
|
44
|
+
canvasClassName = "",
|
|
45
|
+
notifications
|
|
46
|
+
}) => {
|
|
47
|
+
const [page, setPage] = React.useState(initialPage);
|
|
48
|
+
const [preloadedData, setPreloadedData] = React.useState(preloaded);
|
|
49
|
+
const [pageHistory, setPageHistory] = React.useState([initialPage]);
|
|
50
|
+
const [historyIndex, setHistoryIndex] = React.useState(0);
|
|
51
|
+
const [selectedWidget, setSelectedWidget] = React.useState(null);
|
|
52
|
+
const [reorderOpen, setReorderOpen] = React.useState(false);
|
|
53
|
+
const [selectedWidgets, setSelectedWidgets] = React.useState([]);
|
|
54
|
+
const [numberOfCopies, setNumberOfCopies] = React.useState(0);
|
|
55
|
+
const handleUndoChanges = () => {
|
|
56
|
+
const newPage = pageHistory[historyIndex - 1];
|
|
57
|
+
if (historyIndex > 0) setHistoryIndex(historyIndex - 1);
|
|
58
|
+
setPage(newPage);
|
|
59
|
+
onSave(sanitizeWidgets(newPage), "Changes undone. Revision saved");
|
|
60
|
+
};
|
|
61
|
+
const handleRedoChanges = () => {
|
|
62
|
+
const newPage = pageHistory[historyIndex + 1];
|
|
63
|
+
if (historyIndex < pageHistory.length) setHistoryIndex(historyIndex + 1);
|
|
64
|
+
setPage(newPage);
|
|
65
|
+
onSave(sanitizeWidgets(newPage), "Changes restored. Revision saved");
|
|
66
|
+
};
|
|
67
|
+
const handlePageHistory = (newPage) => {
|
|
68
|
+
let newPageHistory = [];
|
|
69
|
+
newPageHistory = [...pageHistory.slice(0, historyIndex + 1), newPage];
|
|
70
|
+
setPageHistory(newPageHistory);
|
|
71
|
+
setHistoryIndex(newPageHistory.length - 1);
|
|
72
|
+
};
|
|
73
|
+
const handleSelectWidget = (newWidget) => {
|
|
74
|
+
setSelectedWidgets((oldList) => {
|
|
75
|
+
const isUnique = oldList.filter((w) => w === newWidget).length <= 0;
|
|
76
|
+
if (isUnique) {
|
|
77
|
+
return [...oldList, newWidget];
|
|
78
|
+
} else {
|
|
79
|
+
return oldList.filter((w) => w !== newWidget);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
if (!adminLibrary) {
|
|
84
|
+
console.warn("No adminLibrary provided to AdminBuilder.");
|
|
85
|
+
}
|
|
86
|
+
const currentWidget = selectedWidget ? adminLibrary[selectedWidget.component] : null;
|
|
87
|
+
const factory = (widgetName) => __async(null, null, function* () {
|
|
88
|
+
const widget = adminLibrary[widgetName];
|
|
89
|
+
const settings = widgetData.defaults(widget);
|
|
90
|
+
const widgetId = randomString(6);
|
|
91
|
+
if (fetchers[widgetName]) {
|
|
92
|
+
const data = yield fetchers[widgetName](__spreadProps(__spreadValues({}, settings), {
|
|
93
|
+
__ctx: context
|
|
94
|
+
}));
|
|
95
|
+
setPreloadedData(__spreadProps(__spreadValues({}, preloadedData), { [widgetId]: data }));
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
widgetId,
|
|
99
|
+
component: widgetName,
|
|
100
|
+
settings
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
const handleSelectAll = (items) => setSelectedWidgets(items);
|
|
104
|
+
const handleAdd = (widgetName) => __async(null, null, function* () {
|
|
105
|
+
const widgets2 = add(page.widgets, yield factory(widgetName));
|
|
106
|
+
const widgetTitle = widgetData.title(adminLibrary[widgetName]);
|
|
107
|
+
const newPage = __spreadProps(__spreadValues({}, page), {
|
|
108
|
+
widgets: widgets2
|
|
109
|
+
});
|
|
110
|
+
setPage(newPage);
|
|
111
|
+
handlePageHistory(newPage);
|
|
112
|
+
onSave(sanitizeWidgets(newPage), `${widgetTitle} added to page`);
|
|
113
|
+
notifyChange(newPage);
|
|
114
|
+
});
|
|
115
|
+
const handleUpdate = (widget) => __async(null, null, function* () {
|
|
116
|
+
const widgets2 = updateFieldById(
|
|
117
|
+
page.widgets,
|
|
118
|
+
"settings",
|
|
119
|
+
widget.settings,
|
|
120
|
+
widget.widgetId,
|
|
121
|
+
"widgetId"
|
|
122
|
+
);
|
|
123
|
+
const newPage = __spreadProps(__spreadValues({}, page), {
|
|
124
|
+
widgets: widgets2
|
|
125
|
+
});
|
|
126
|
+
if (preloadedData[widget.widgetId]) {
|
|
127
|
+
const data = yield fetchers[widget.component](__spreadProps(__spreadValues({}, widget.settings), {
|
|
128
|
+
__ctx: context
|
|
129
|
+
}));
|
|
130
|
+
setPreloadedData(__spreadProps(__spreadValues({}, preloadedData), {
|
|
131
|
+
[widget.widgetId]: data
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
setPage(newPage);
|
|
135
|
+
handlePageHistory(newPage);
|
|
136
|
+
onSave(sanitizeWidgets(newPage));
|
|
137
|
+
notifyChange(newPage);
|
|
138
|
+
});
|
|
139
|
+
const handleRemove = (id) => {
|
|
140
|
+
const widgets2 = removeById(page.widgets, id, "widgetId");
|
|
141
|
+
const newPage = __spreadProps(__spreadValues({}, page), {
|
|
142
|
+
widgets: widgets2
|
|
143
|
+
});
|
|
144
|
+
const widgetName = page.widgets.filter(
|
|
145
|
+
(current) => current.widgetId === id
|
|
146
|
+
)[0].component;
|
|
147
|
+
let widgetTitle = null;
|
|
148
|
+
if (adminLibrary[widgetName]) {
|
|
149
|
+
widgetTitle = widgetData.title(adminLibrary[widgetName]);
|
|
150
|
+
} else {
|
|
151
|
+
widgetTitle = widgetName;
|
|
152
|
+
}
|
|
153
|
+
setPage(newPage);
|
|
154
|
+
handlePageHistory(newPage);
|
|
155
|
+
onSave(sanitizeWidgets(newPage), `${widgetTitle} removed`);
|
|
156
|
+
notifyChange(newPage);
|
|
157
|
+
};
|
|
158
|
+
const handleRemoveMultiple = () => {
|
|
159
|
+
if (!confirm("Are you sure?")) return;
|
|
160
|
+
const widgets2 = removeMultipleById(page.widgets, selectedWidgets);
|
|
161
|
+
const newPage = __spreadProps(__spreadValues({}, page), {
|
|
162
|
+
widgets: widgets2
|
|
163
|
+
});
|
|
164
|
+
setPage(newPage);
|
|
165
|
+
handlePageHistory(newPage);
|
|
166
|
+
onSave(sanitizeWidgets(newPage), "Widgets removed");
|
|
167
|
+
setSelectedWidgets([]);
|
|
168
|
+
notifyChange(newPage);
|
|
169
|
+
};
|
|
170
|
+
const handleReorder = (widgets2) => {
|
|
171
|
+
if (page.widgets.map((w) => w.widgetId).join() !== widgets2.map((w) => w.widgetId).join()) {
|
|
172
|
+
const newPage = __spreadProps(__spreadValues({}, page), {
|
|
173
|
+
widgets: widgets2
|
|
174
|
+
});
|
|
175
|
+
setPage(newPage);
|
|
176
|
+
handlePageHistory(newPage);
|
|
177
|
+
onSave(sanitizeWidgets(newPage), "Order saved");
|
|
178
|
+
notifyChange(newPage);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const notifyChange = (page2) => onChange(sanitizeWidgets(page2));
|
|
182
|
+
const handleCopyWidgets = (widgets2, copyType) => {
|
|
183
|
+
if (copyType === "multiple") {
|
|
184
|
+
const filterSelected = page.widgets.filter(
|
|
185
|
+
(w) => widgets2.some((c) => w.widgetId === c)
|
|
186
|
+
);
|
|
187
|
+
saveToLocalStorage(identifier, filterSelected);
|
|
188
|
+
setSelectedWidgets([]);
|
|
189
|
+
setNumberOfCopies(filterSelected.length);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
saveToLocalStorage(identifier, widgets2);
|
|
193
|
+
const widgetCount = Array.isArray(widgets2) ? widgets2.length : 1;
|
|
194
|
+
setNumberOfCopies(widgetCount);
|
|
195
|
+
};
|
|
196
|
+
const handlePasteWidget = () => {
|
|
197
|
+
const clipboardWidgets = JSON.parse(
|
|
198
|
+
window.localStorage.getItem(`clipboard\u2013${identifier}`)
|
|
199
|
+
);
|
|
200
|
+
if (!clipboardWidgets) {
|
|
201
|
+
return alert("Nothing to paste, yet");
|
|
202
|
+
}
|
|
203
|
+
if (!(Array.isArray(clipboardWidgets) && clipboardWidgets.length > 0)) {
|
|
204
|
+
console.error("Invalid widgets to paste", clipboardWidgets);
|
|
205
|
+
}
|
|
206
|
+
const newWidgets = clipboardWidgets.reduce((list, widget) => {
|
|
207
|
+
list.push(__spreadProps(__spreadValues({}, widget), { widgetId: randomString(6) }));
|
|
208
|
+
return list;
|
|
209
|
+
}, []);
|
|
210
|
+
const newPage = __spreadProps(__spreadValues({}, page), {
|
|
211
|
+
widgets: [...page.widgets, ...newWidgets]
|
|
212
|
+
});
|
|
213
|
+
const widgetName = clipboardWidgets[0].component;
|
|
214
|
+
const widgetTitle = widgetData.title(adminLibrary[widgetName]);
|
|
215
|
+
const notificationText = clipboardWidgets.length === 1 ? `${widgetTitle} pasted` : "Widgets pasted";
|
|
216
|
+
setPage(newPage);
|
|
217
|
+
handlePageHistory(newPage);
|
|
218
|
+
onSave(sanitizeWidgets(newPage), notificationText);
|
|
219
|
+
notifyChange(newPage);
|
|
220
|
+
};
|
|
221
|
+
const handleSaveWidget = (settings) => __async(null, null, function* () {
|
|
222
|
+
yield handleUpdate(__spreadProps(__spreadValues({}, selectedWidget), {
|
|
223
|
+
settings
|
|
224
|
+
}));
|
|
225
|
+
setSelectedWidget(null);
|
|
226
|
+
});
|
|
227
|
+
const handleClose = () => {
|
|
228
|
+
setSelectedWidget(null);
|
|
229
|
+
};
|
|
230
|
+
const { widgets } = page;
|
|
231
|
+
const sortableWidgets = widgets.map((widget) => __spreadProps(__spreadValues({}, widget), {
|
|
232
|
+
settings: __spreadProps(__spreadValues({}, widget.settings), {
|
|
233
|
+
__ctx: context,
|
|
234
|
+
__data: preloadedData[widget.widgetId]
|
|
235
|
+
}),
|
|
236
|
+
id: widget.widgetId,
|
|
237
|
+
chosen: false,
|
|
238
|
+
selected: false
|
|
239
|
+
}));
|
|
240
|
+
return /* @__PURE__ */ jsx(HostContext.Provider, { value: { host }, children: /* @__PURE__ */ jsxs(LibraryContext.Provider, { value: { library, adminLibrary }, children: [
|
|
241
|
+
notifications.length > 0 && notifications.map((notif) => {
|
|
242
|
+
return /* @__PURE__ */ jsx(Notification, __spreadValues({}, notif), notif.id);
|
|
243
|
+
}),
|
|
244
|
+
/* @__PURE__ */ jsxs("div", { style: { paddingLeft: "64px" }, children: [
|
|
245
|
+
!reorderOpen && selectedWidgets.length > 0 && /* @__PURE__ */ jsx(
|
|
246
|
+
SelectedWidgetsToolbar,
|
|
247
|
+
{
|
|
248
|
+
length: selectedWidgets.length,
|
|
249
|
+
onCopy: () => handleCopyWidgets(selectedWidgets, "multiple"),
|
|
250
|
+
onRemove: handleRemoveMultiple
|
|
251
|
+
}
|
|
252
|
+
),
|
|
253
|
+
reorderOpen && /* @__PURE__ */ jsx(
|
|
254
|
+
ReorderDialog,
|
|
255
|
+
{
|
|
256
|
+
widgets: sortableWidgets,
|
|
257
|
+
onChange: handleReorder,
|
|
258
|
+
onDelete: handleRemove,
|
|
259
|
+
onSelectWidget: setSelectedWidget,
|
|
260
|
+
onClose: () => setReorderOpen(false),
|
|
261
|
+
selectedWidgets,
|
|
262
|
+
onSelectWidgets: handleSelectWidget,
|
|
263
|
+
onCopy: () => handleCopyWidgets(selectedWidgets, "multiple"),
|
|
264
|
+
onRemove: handleRemoveMultiple,
|
|
265
|
+
onSelectAll: handleSelectAll
|
|
266
|
+
}
|
|
267
|
+
),
|
|
268
|
+
/* @__PURE__ */ jsx(
|
|
269
|
+
AdminSidebar,
|
|
270
|
+
{
|
|
271
|
+
languageSwitcherSettings,
|
|
272
|
+
buttons: sidebarButtons,
|
|
273
|
+
onAddWidget: (widgetName) => handleAdd(widgetName),
|
|
274
|
+
onReorderDialog: () => setReorderOpen(true),
|
|
275
|
+
onExit,
|
|
276
|
+
onPasteWidget: handlePasteWidget,
|
|
277
|
+
pageHistory,
|
|
278
|
+
setPage,
|
|
279
|
+
undoChanges: handleUndoChanges,
|
|
280
|
+
redoChanges: handleRedoChanges,
|
|
281
|
+
historyIndex,
|
|
282
|
+
clipboardCopiesCount: numberOfCopies
|
|
283
|
+
}
|
|
284
|
+
),
|
|
285
|
+
/* @__PURE__ */ jsx(
|
|
286
|
+
Canvas,
|
|
287
|
+
{
|
|
288
|
+
widgets: sortableWidgets,
|
|
289
|
+
onReorder: handleReorder,
|
|
290
|
+
onEdit: setSelectedWidget,
|
|
291
|
+
onRemove: handleRemove,
|
|
292
|
+
onCopy: handleCopyWidgets,
|
|
293
|
+
selectedWidgets,
|
|
294
|
+
onSelectWidget: handleSelectWidget,
|
|
295
|
+
canvasClassName
|
|
296
|
+
}
|
|
297
|
+
),
|
|
298
|
+
selectedWidget && /* @__PURE__ */ jsx(
|
|
299
|
+
SettingsDialog,
|
|
300
|
+
{
|
|
301
|
+
widget: currentWidget,
|
|
302
|
+
settings: selectedWidget.settings,
|
|
303
|
+
onSave: handleSaveWidget,
|
|
304
|
+
onClose: handleClose
|
|
305
|
+
}
|
|
306
|
+
)
|
|
307
|
+
] })
|
|
308
|
+
] }) });
|
|
309
|
+
};
|
|
310
|
+
var PageBuilder_default = PageBuilder;
|
|
311
|
+
|
|
312
|
+
export { PageBuilder_default as default };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.next(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.throw(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { __async, __objRest, __spreadProps, __spreadValues };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import '../chunk-BBZEL7EG.js';
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import 'react';
|
|
4
|
+
import { Modal, Button } from '@raketa-builder/ui';
|
|
5
|
+
|
|
6
|
+
function checkForChanges(hasChanges, onClose) {
|
|
7
|
+
if (!hasChanges) {
|
|
8
|
+
onClose();
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (!confirm(
|
|
12
|
+
"You\u2019ve made changes to the widget. Are you sure you want to cancel?"
|
|
13
|
+
))
|
|
14
|
+
return;
|
|
15
|
+
onClose();
|
|
16
|
+
}
|
|
17
|
+
const Dialog = ({
|
|
18
|
+
open,
|
|
19
|
+
onClose,
|
|
20
|
+
title,
|
|
21
|
+
children = [],
|
|
22
|
+
primaryLabel,
|
|
23
|
+
secondaryLabel = "Cancel",
|
|
24
|
+
onPrimary,
|
|
25
|
+
areChanges
|
|
26
|
+
}) => /* @__PURE__ */ jsx(
|
|
27
|
+
Modal,
|
|
28
|
+
{
|
|
29
|
+
open,
|
|
30
|
+
title,
|
|
31
|
+
onClose,
|
|
32
|
+
areChanges,
|
|
33
|
+
FooterContent: () => (primaryLabel || secondaryLabel) && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
34
|
+
primaryLabel && /* @__PURE__ */ jsx(Button, { type: "button", variant: "primary", onClick: onPrimary, children: primaryLabel }),
|
|
35
|
+
secondaryLabel && /* @__PURE__ */ jsx(
|
|
36
|
+
Button,
|
|
37
|
+
{
|
|
38
|
+
type: "button",
|
|
39
|
+
variant: "secondary",
|
|
40
|
+
onClick: () => checkForChanges(areChanges, onClose),
|
|
41
|
+
children: secondaryLabel
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
] }),
|
|
45
|
+
children
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
var Dialog_default = Dialog;
|
|
49
|
+
|
|
50
|
+
export { Dialog_default as default };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { __objRest, __spreadValues } from '../chunk-BBZEL7EG.js';
|
|
2
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { ReactSortable } from 'react-sortablejs';
|
|
5
|
+
import { P, H, Button, cn } from '@raketa-builder/ui';
|
|
6
|
+
import Dialog from './Dialog';
|
|
7
|
+
import LibraryContext from '../LibraryContext';
|
|
8
|
+
import widgetData from '../helpers/widgetData';
|
|
9
|
+
import ModalSelectedWidgetsToolbar from '../lib/ModalSelectedWidgetsToolbar';
|
|
10
|
+
|
|
11
|
+
const ReorderDialogItem = (_a) => {
|
|
12
|
+
var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
|
|
13
|
+
return /* @__PURE__ */ jsx("div", __spreadValues({ className: cn("r-reorder-dialog-item", className) }, props));
|
|
14
|
+
};
|
|
15
|
+
const cleanup = (string) => string.replace(/<[^>]*>?/gm, "");
|
|
16
|
+
const truncate = (str, num) => {
|
|
17
|
+
if (str.length <= num) return str;
|
|
18
|
+
return str.slice(0, num) + "\u2026";
|
|
19
|
+
};
|
|
20
|
+
const getWidgetTitle = (library, widget) => {
|
|
21
|
+
const widgetComponent = library[widget.component];
|
|
22
|
+
if (!widgetComponent) {
|
|
23
|
+
console.error(`Unknown widget: ${widget.component}`);
|
|
24
|
+
return `Unknown widget: ${widget.component}`;
|
|
25
|
+
}
|
|
26
|
+
const widgetName = widgetData.title(widgetComponent) || widget.component;
|
|
27
|
+
const primaryField = widgetData.primaryField(widgetComponent) && widget.settings[widgetData.primaryField(widgetComponent)];
|
|
28
|
+
if (primaryField && typeof primaryField !== "string") {
|
|
29
|
+
throw new Error(
|
|
30
|
+
`The primaryField value of '${widget.component}' must be either a string or not present!`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
const widgetTitle = primaryField ? truncate(cleanup(primaryField), 32) : "";
|
|
34
|
+
return [widgetName, widgetTitle].filter((s) => s !== "").join(": ");
|
|
35
|
+
};
|
|
36
|
+
const ReorderDialog = ({
|
|
37
|
+
widgets = [],
|
|
38
|
+
onClose,
|
|
39
|
+
onChange,
|
|
40
|
+
onDelete,
|
|
41
|
+
onSelectWidget,
|
|
42
|
+
selectedWidgets,
|
|
43
|
+
onSelectWidgets,
|
|
44
|
+
onCopy,
|
|
45
|
+
onRemove,
|
|
46
|
+
onSelectAll
|
|
47
|
+
}) => {
|
|
48
|
+
const { adminLibrary } = React.useContext(LibraryContext);
|
|
49
|
+
const isSelected = (id) => selectedWidgets.filter((w) => w === id).length > 0;
|
|
50
|
+
const areAllSelected = selectedWidgets.length === widgets.length;
|
|
51
|
+
const handleSelectWidget = (id) => onSelectWidgets(id);
|
|
52
|
+
const handleSelectAll = () => {
|
|
53
|
+
if (areAllSelected) return onSelectAll([]);
|
|
54
|
+
onSelectAll(widgets.map((w) => w.widgetId));
|
|
55
|
+
};
|
|
56
|
+
return /* @__PURE__ */ jsxs(
|
|
57
|
+
Dialog,
|
|
58
|
+
{
|
|
59
|
+
open: true,
|
|
60
|
+
onClose,
|
|
61
|
+
title: "Reorder",
|
|
62
|
+
primaryLabel: "",
|
|
63
|
+
secondaryLabel: "Close",
|
|
64
|
+
children: [
|
|
65
|
+
widgets.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
66
|
+
/* @__PURE__ */ jsx(P, { children: "Drag and drop elements below to reorder the page layout." }),
|
|
67
|
+
/* @__PURE__ */ jsx(
|
|
68
|
+
ModalSelectedWidgetsToolbar,
|
|
69
|
+
{
|
|
70
|
+
selectedWidgets,
|
|
71
|
+
onSelectAll: handleSelectAll,
|
|
72
|
+
areAllSelected,
|
|
73
|
+
onCopy,
|
|
74
|
+
onRemove
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
] }) : /* @__PURE__ */ jsx(P, { children: "It's always good to start with a clean slate. Use the sidebar to add content." }),
|
|
78
|
+
/* @__PURE__ */ jsx(
|
|
79
|
+
ReactSortable,
|
|
80
|
+
{
|
|
81
|
+
list: widgets,
|
|
82
|
+
setList: onChange,
|
|
83
|
+
handle: "[data-drag]",
|
|
84
|
+
direction: "horizontal",
|
|
85
|
+
dragoverBubble: true,
|
|
86
|
+
children: widgets.map((widget) => /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
|
|
87
|
+
ReorderDialogItem,
|
|
88
|
+
{
|
|
89
|
+
"data-drag": true,
|
|
90
|
+
className: isSelected(widget.widgetId) ? "r-selected" : "",
|
|
91
|
+
children: [
|
|
92
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center" }, children: [
|
|
93
|
+
/* @__PURE__ */ jsx(
|
|
94
|
+
"input",
|
|
95
|
+
{
|
|
96
|
+
type: "checkbox",
|
|
97
|
+
style: {
|
|
98
|
+
width: "16px",
|
|
99
|
+
marginRight: "8px",
|
|
100
|
+
aspectRatio: 1
|
|
101
|
+
},
|
|
102
|
+
onChange: () => handleSelectWidget(widget.widgetId),
|
|
103
|
+
checked: isSelected(widget.widgetId)
|
|
104
|
+
}
|
|
105
|
+
),
|
|
106
|
+
/* @__PURE__ */ jsx(
|
|
107
|
+
H,
|
|
108
|
+
{
|
|
109
|
+
size: "base",
|
|
110
|
+
style: {
|
|
111
|
+
paddingBottom: 0,
|
|
112
|
+
fontWeight: 500
|
|
113
|
+
},
|
|
114
|
+
children: getWidgetTitle(adminLibrary, widget)
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
] }),
|
|
118
|
+
!isSelected(widget.widgetId) && /* @__PURE__ */ jsxs(
|
|
119
|
+
"div",
|
|
120
|
+
{
|
|
121
|
+
style: {
|
|
122
|
+
display: "flex",
|
|
123
|
+
alignItems: "center"
|
|
124
|
+
},
|
|
125
|
+
children: [
|
|
126
|
+
adminLibrary[widget.component] && /* @__PURE__ */ jsx(
|
|
127
|
+
Button,
|
|
128
|
+
{
|
|
129
|
+
type: "button",
|
|
130
|
+
variant: "primary",
|
|
131
|
+
onClick: () => {
|
|
132
|
+
onClose();
|
|
133
|
+
onSelectWidget(widget);
|
|
134
|
+
},
|
|
135
|
+
children: "Edit"
|
|
136
|
+
}
|
|
137
|
+
),
|
|
138
|
+
/* @__PURE__ */ jsx(
|
|
139
|
+
Button,
|
|
140
|
+
{
|
|
141
|
+
type: "button",
|
|
142
|
+
variant: "danger",
|
|
143
|
+
onClick: () => {
|
|
144
|
+
if (!confirm("Are you sure?")) return;
|
|
145
|
+
onDelete(widget.widgetId);
|
|
146
|
+
},
|
|
147
|
+
children: "\xD7"
|
|
148
|
+
}
|
|
149
|
+
)
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
) }, widget.widgetId))
|
|
156
|
+
}
|
|
157
|
+
)
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
var ReorderDialog_default = ReorderDialog;
|
|
163
|
+
|
|
164
|
+
export { ReorderDialog_default as default };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { __spreadValues, __spreadProps } from '../chunk-BBZEL7EG.js';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Tabs } from '@raketa-builder/ui';
|
|
5
|
+
import BuilderContext from '../contexts/BuilderContext';
|
|
6
|
+
import Dialog from './Dialog';
|
|
7
|
+
import widgetData from '../helpers/widgetData';
|
|
8
|
+
import AdminForm from '../AdminForm';
|
|
9
|
+
|
|
10
|
+
const SettingsDialog = ({ widget, settings, onSave, onClose }) => {
|
|
11
|
+
const { containerAdmin } = React.useContext(BuilderContext);
|
|
12
|
+
const [localSettings, setLocalSettings] = React.useState(settings);
|
|
13
|
+
const handleChangeContainer = (value) => {
|
|
14
|
+
setLocalSettings(__spreadProps(__spreadValues({}, localSettings), { containerSettings: __spreadValues({}, value) }));
|
|
15
|
+
};
|
|
16
|
+
const schema = widgetData.adminFields(widget);
|
|
17
|
+
if (typeof schema !== "object") {
|
|
18
|
+
console.warn(
|
|
19
|
+
`Legacy widget with React admin definition: ${widgetData.title(
|
|
20
|
+
widget
|
|
21
|
+
)}. Update to custom inputs. `
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
const areChanges = JSON.stringify(settings) !== JSON.stringify(localSettings);
|
|
25
|
+
return /* @__PURE__ */ jsx(
|
|
26
|
+
Dialog,
|
|
27
|
+
{
|
|
28
|
+
open: true,
|
|
29
|
+
title: widgetData.title(widget),
|
|
30
|
+
primaryLabel: "OK",
|
|
31
|
+
onPrimary: () => onSave(localSettings),
|
|
32
|
+
onClose,
|
|
33
|
+
areChanges,
|
|
34
|
+
children: /* @__PURE__ */ jsxs(Tabs, { children: [
|
|
35
|
+
/* @__PURE__ */ jsx("div", { title: "Content", children: /* @__PURE__ */ jsx(
|
|
36
|
+
AdminForm,
|
|
37
|
+
{
|
|
38
|
+
schema,
|
|
39
|
+
value: localSettings,
|
|
40
|
+
onChange: (newValue) => setLocalSettings(__spreadValues({}, newValue))
|
|
41
|
+
}
|
|
42
|
+
) }),
|
|
43
|
+
/* @__PURE__ */ jsx("div", { title: "Container", children: /* @__PURE__ */ jsx(
|
|
44
|
+
AdminForm,
|
|
45
|
+
{
|
|
46
|
+
schema: containerAdmin,
|
|
47
|
+
value: localSettings.containerSettings,
|
|
48
|
+
onChange: handleChangeContainer
|
|
49
|
+
}
|
|
50
|
+
) })
|
|
51
|
+
] })
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
var SettingsDialog_default = SettingsDialog;
|
|
56
|
+
|
|
57
|
+
export { SettingsDialog_default as default };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import '../chunk-BBZEL7EG.js';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import 'react';
|
|
2
4
|
|
|
3
5
|
const Button = ({ settings, className }) => {
|
|
4
6
|
const {
|
|
@@ -7,27 +9,25 @@ const Button = ({ settings, className }) => {
|
|
|
7
9
|
button_link,
|
|
8
10
|
button_target,
|
|
9
11
|
button_type,
|
|
10
|
-
follow_link
|
|
12
|
+
follow_link
|
|
11
13
|
} = settings;
|
|
12
|
-
|
|
13
14
|
let buttonClass;
|
|
14
|
-
|
|
15
15
|
if (button_type === "accented") buttonClass = "btn-active-dark";
|
|
16
16
|
if (button_type === "regular") buttonClass = "btn-passive-light";
|
|
17
17
|
if (button_type === "link") buttonClass = "btn-text";
|
|
18
18
|
if (className) buttonClass = `${buttonClass} ${className}`;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
href
|
|
23
|
-
className
|
|
24
|
-
id
|
|
25
|
-
target
|
|
26
|
-
rel
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
</a>
|
|
19
|
+
return /* @__PURE__ */ jsx(
|
|
20
|
+
"a",
|
|
21
|
+
{
|
|
22
|
+
href: button_link,
|
|
23
|
+
className: buttonClass,
|
|
24
|
+
id: button_id,
|
|
25
|
+
target: button_target,
|
|
26
|
+
rel: follow_link === "no-follow" ? "nofollow" : "",
|
|
27
|
+
children: button_label
|
|
28
|
+
}
|
|
30
29
|
);
|
|
31
30
|
};
|
|
31
|
+
var Button_default = Button;
|
|
32
32
|
|
|
33
|
-
export default
|
|
33
|
+
export { Button_default as default };
|