@raketa-builder/builder 1.8.0 → 1.8.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.
@@ -1,6 +1,5 @@
1
1
  import { __spreadValues } from '../chunk-BBZEL7EG.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import 'react';
4
3
  import TextArea from '../forms/TextArea';
5
4
  import TextInput from '../forms/TextInput';
6
5
  import SelectMenu from '../forms/SelectMenu';
@@ -1,6 +1,5 @@
1
1
  import { __spreadProps, __spreadValues } from '../chunk-BBZEL7EG.js';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import 'react';
4
3
  import { Panel, PanelTitle, PanelContent } from '@raketa-builder/ui';
5
4
  import { capitalize, humanize } from '../helpers/humanize';
6
5
  import List from '../List';
package/dist/Canvas.js CHANGED
@@ -20,6 +20,8 @@ const Canvas = React.memo(
20
20
  onRemove,
21
21
  onCopy,
22
22
  onSelectWidget,
23
+ onInsert,
24
+ onPaste,
23
25
  canvasClassName,
24
26
  wrapWidget
25
27
  }) {
@@ -39,7 +41,7 @@ const Canvas = React.memo(
39
41
  direction: "horizontal",
40
42
  dragoverBubble: true,
41
43
  className: canvasClassName,
42
- children: widgets.map((widget) => /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(
44
+ children: widgets.map((widget, index) => /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(
43
45
  AdminWidget,
44
46
  {
45
47
  library,
@@ -50,7 +52,11 @@ const Canvas = React.memo(
50
52
  onCopy,
51
53
  onSelectWidget,
52
54
  selectedWidgets,
53
- wrapWidget
55
+ wrapWidget,
56
+ index,
57
+ isLast: index === widgets.length - 1,
58
+ onInsert,
59
+ onPaste
54
60
  }
55
61
  ) }, widget.widgetId))
56
62
  }
@@ -8,7 +8,7 @@ class ErrorBoundary extends Component {
8
8
  hasError: false
9
9
  };
10
10
  }
11
- static getDerivedStateFromError(error) {
11
+ static getDerivedStateFromError(_error) {
12
12
  return {
13
13
  hasError: true
14
14
  };
package/dist/List.js CHANGED
@@ -116,7 +116,7 @@ const extractPrimaryField = (primaryField, item, idx) => {
116
116
  return item[primaryField];
117
117
  }
118
118
  return primaryField.split(".").reduce((acc, key) => {
119
- const newValue = acc && acc[key] || "";
119
+ const newValue = (acc == null ? void 0 : acc[key]) || "";
120
120
  return newValue;
121
121
  }, item);
122
122
  };
package/dist/ListInput.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { __spreadValues } from './chunk-BBZEL7EG.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import 'react';
4
3
  import List from './List';
5
4
 
6
5
  const ListInput = (props) => /* @__PURE__ */ jsx(List, __spreadValues({}, props));
@@ -6,13 +6,13 @@ class MediaManager {
6
6
  "MediaManager is no longer part of @raketa-builder/builder. Please use @raketa-builder/image-input. "
7
7
  );
8
8
  }
9
- findAll(callback, params = {}) {
9
+ findAll(_callback, _params = {}) {
10
10
  }
11
- uploadFile(file, callback) {
11
+ uploadFile(_file, _callback) {
12
12
  }
13
- update(image, params, callback) {
13
+ update(_image, _params, _callback) {
14
14
  }
15
- destroy(image, callback) {
15
+ destroy(_image, _callback) {
16
16
  }
17
17
  }
18
18
 
@@ -1,13 +1,14 @@
1
1
  import { __spreadProps, __spreadValues, __async } from './chunk-BBZEL7EG.js';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import React from 'react';
4
- import { add, removeById, removeMultipleById, randomString, updateFieldById } from './lists';
4
+ import { addAt, removeById, removeMultipleById, randomString, insertManyAt, updateFieldById } from './lists';
5
5
  import HostContext from './HostContext';
6
6
  import LibraryContext from './LibraryContext';
7
7
  import Canvas from './Canvas';
8
8
  import AdminSidebar from './lib/AdminSidebar';
9
9
  import ReorderDialog from './dialogs/ReorderDialog';
10
10
  import SettingsDialog from './dialogs/SettingsDialog';
11
+ import InsertWidgetDialog from './dialogs/InsertWidgetDialog';
11
12
  import widgetData from './helpers/widgetData';
12
13
  import { validateButtons, SelectedWidgetsToolbar } from '@raketa-builder/support';
13
14
  import Notification from './AutoSaveNotification';
@@ -67,7 +68,13 @@ const PageBuilder = ({
67
68
  notifications,
68
69
  autoSave = true
69
70
  }) => {
70
- const [page, setPage] = React.useState(initialPage);
71
+ const [page, setPageState] = React.useState(initialPage);
72
+ const pageRef = React.useRef(initialPage);
73
+ const setPage = (nextPage) => {
74
+ pageRef.current = nextPage;
75
+ setPageState(nextPage);
76
+ };
77
+ const addWidgetRef = React.useRef(null);
71
78
  const [preloadedData, setPreloadedData] = React.useState(preloaded);
72
79
  React.useMemo(
73
80
  () => validateButtons(selectedWidgetsButtons),
@@ -77,6 +84,7 @@ const PageBuilder = ({
77
84
  const [historyIndex, setHistoryIndex] = React.useState(0);
78
85
  const [selectedWidget, setSelectedWidget] = React.useState(null);
79
86
  const [reorderOpen, setReorderOpen] = React.useState(false);
87
+ const [insertIndex, setInsertIndex] = React.useState(null);
80
88
  const [selectedWidgets, setSelectedWidgets] = React.useState([]);
81
89
  const [autoSaveActive, setAutoSaveActive] = React.useState(() => {
82
90
  if (typeof window === "undefined") {
@@ -136,7 +144,7 @@ const PageBuilder = ({
136
144
  const data = yield fetchers[widgetName](__spreadProps(__spreadValues({}, settings), {
137
145
  __ctx: context
138
146
  }));
139
- setPreloadedData(__spreadProps(__spreadValues({}, preloadedData), { [widgetId]: data }));
147
+ setPreloadedData((current) => __spreadProps(__spreadValues({}, current), { [widgetId]: data }));
140
148
  }
141
149
  return {
142
150
  widgetId,
@@ -145,11 +153,33 @@ const PageBuilder = ({
145
153
  };
146
154
  });
147
155
  const handleSelectAll = (items) => setSelectedWidgets(items);
148
- const handleAdd = (widgetName) => __async(null, null, function* () {
149
- const widgets2 = add(page.widgets, yield factory(widgetName));
150
- const widgetTitle = widgetData.title(adminLibrary[widgetName]);
151
- const newPage = __spreadProps(__spreadValues({}, page), {
152
- widgets: widgets2
156
+ const handleAdd = (widgetName, index) => __async(null, null, function* () {
157
+ var _a, _b;
158
+ const currentWidgets = pageRef.current.widgets;
159
+ const anchor = index === void 0 ? null : {
160
+ before: (_a = currentWidgets[index]) == null ? void 0 : _a.widgetId,
161
+ after: (_b = currentWidgets[index - 1]) == null ? void 0 : _b.widgetId
162
+ };
163
+ const widget = yield factory(widgetName);
164
+ addWidgetRef.current(widget, anchor);
165
+ });
166
+ addWidgetRef.current = (widget, anchor) => {
167
+ const currentPage = pageRef.current;
168
+ const beforeIndex = (anchor == null ? void 0 : anchor.before) === void 0 ? -1 : currentPage.widgets.findIndex(
169
+ (item) => item.widgetId === anchor.before
170
+ );
171
+ const afterIndex = (anchor == null ? void 0 : anchor.after) === void 0 ? -1 : currentPage.widgets.findIndex(
172
+ (item) => item.widgetId === anchor.after
173
+ );
174
+ let index = currentPage.widgets.length;
175
+ if (beforeIndex >= 0) {
176
+ index = beforeIndex;
177
+ } else if (afterIndex >= 0) {
178
+ index = afterIndex + 1;
179
+ }
180
+ const widgetTitle = widgetData.title(adminLibrary[widget.component]);
181
+ const newPage = __spreadProps(__spreadValues({}, currentPage), {
182
+ widgets: addAt(currentPage.widgets, widget, index)
153
183
  });
154
184
  setPage(newPage);
155
185
  setDirty(true);
@@ -158,7 +188,7 @@ const PageBuilder = ({
158
188
  onSave(sanitizeWidgets(newPage), `${widgetTitle} added to page`);
159
189
  }
160
190
  notifyChange(newPage);
161
- });
191
+ };
162
192
  const handleUpdate = (widget) => __async(null, null, function* () {
163
193
  const widgets2 = updateFieldById(
164
194
  page.widgets,
@@ -252,7 +282,7 @@ const PageBuilder = ({
252
282
  const widgetCount = Array.isArray(widgets2) ? widgets2.length : 1;
253
283
  setNumberOfCopies(widgetCount);
254
284
  };
255
- const handlePasteWidget = () => {
285
+ const handlePasteWidget = (index = page.widgets.length) => {
256
286
  const clipboardWidgets = JSON.parse(
257
287
  window.localStorage.getItem(`clipboard\u2013${identifier}`)
258
288
  );
@@ -261,13 +291,14 @@ const PageBuilder = ({
261
291
  }
262
292
  if (!(Array.isArray(clipboardWidgets) && clipboardWidgets.length > 0)) {
263
293
  console.error("Invalid widgets to paste", clipboardWidgets);
294
+ return;
264
295
  }
265
296
  const newWidgets = clipboardWidgets.reduce((list, widget) => {
266
297
  list.push(__spreadProps(__spreadValues({}, widget), { widgetId: randomString(6) }));
267
298
  return list;
268
299
  }, []);
269
300
  const newPage = __spreadProps(__spreadValues({}, page), {
270
- widgets: [...page.widgets, ...newWidgets]
301
+ widgets: insertManyAt(page.widgets, newWidgets, index)
271
302
  });
272
303
  const widgetName = clipboardWidgets[0].component;
273
304
  const widgetTitle = widgetData.title(adminLibrary[widgetName]);
@@ -280,6 +311,19 @@ const PageBuilder = ({
280
311
  }
281
312
  notifyChange(newPage);
282
313
  };
314
+ const pasteWidgetRef = React.useRef(handlePasteWidget);
315
+ React.useEffect(() => {
316
+ pasteWidgetRef.current = handlePasteWidget;
317
+ });
318
+ const handlePasteWidgetAt = React.useCallback(
319
+ (index) => pasteWidgetRef.current(index),
320
+ []
321
+ );
322
+ const handleInsertWidget = (widgetName) => __async(null, null, function* () {
323
+ const index = insertIndex;
324
+ setInsertIndex(null);
325
+ yield handleAdd(widgetName, index);
326
+ });
283
327
  const handleSave = () => {
284
328
  handlePageHistory(page);
285
329
  onSave(page);
@@ -347,7 +391,7 @@ const PageBuilder = ({
347
391
  onAddWidget: (widgetName) => handleAdd(widgetName),
348
392
  onReorderDialog: () => setReorderOpen(true),
349
393
  onExit,
350
- onPasteWidget: handlePasteWidget,
394
+ onPasteWidget: () => handlePasteWidget(),
351
395
  pageHistory,
352
396
  setPage,
353
397
  undoChanges: handleUndoChanges,
@@ -371,10 +415,19 @@ const PageBuilder = ({
371
415
  onCopy: handleCopyWidgets,
372
416
  selectedWidgets,
373
417
  onSelectWidget: handleSelectWidget,
418
+ onInsert: setInsertIndex,
419
+ onPaste: handlePasteWidgetAt,
374
420
  canvasClassName,
375
421
  wrapWidget
376
422
  }
377
423
  ),
424
+ insertIndex !== null && /* @__PURE__ */ jsx(
425
+ InsertWidgetDialog,
426
+ {
427
+ onInsert: handleInsertWidget,
428
+ onClose: () => setInsertIndex(null)
429
+ }
430
+ ),
378
431
  selectedWidget && /* @__PURE__ */ jsx(
379
432
  SettingsDialog,
380
433
  {
@@ -1,6 +1,5 @@
1
1
  import '../chunk-BBZEL7EG.js';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
- import 'react';
4
3
  import { Modal, Button } from '@raketa-builder/ui';
5
4
 
6
5
  function checkForChanges(hasChanges, onClose) {
@@ -0,0 +1,22 @@
1
+ import '../chunk-BBZEL7EG.js';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import React from 'react';
4
+ import Dialog from './Dialog';
5
+ import WidgetsList from '../lib/WidgetsList';
6
+ import LibraryContext from '../LibraryContext';
7
+
8
+ const InsertWidgetDialog = ({ onInsert, onClose }) => {
9
+ const { adminLibrary } = React.useContext(LibraryContext);
10
+ return /* @__PURE__ */ jsx(Dialog, { open: true, title: "Insert widget", onClose, children: /* @__PURE__ */ jsx(
11
+ WidgetsList,
12
+ {
13
+ library: adminLibrary,
14
+ onAddWidget: onInsert,
15
+ variant: "dialog",
16
+ autoFocus: true
17
+ }
18
+ ) });
19
+ };
20
+ var InsertWidgetDialog_default = InsertWidgetDialog;
21
+
22
+ export { InsertWidgetDialog_default as default };
@@ -15,7 +15,7 @@ const ReorderDialogItem = (_a) => {
15
15
  const cleanup = (string) => string.replace(/<[^>]*>?/gm, "");
16
16
  const truncate = (str, num) => {
17
17
  if (str.length <= num) return str;
18
- return str.slice(0, num) + "\u2026";
18
+ return `${str.slice(0, num)}\u2026`;
19
19
  };
20
20
  const getWidgetTitle = (library, widget) => {
21
21
  const widgetComponent = library[widget.component];
@@ -1,6 +1,5 @@
1
1
  import '../chunk-BBZEL7EG.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import 'react';
4
3
 
5
4
  const Button = ({ settings, className }) => {
6
5
  const {
@@ -1,6 +1,5 @@
1
1
  import { __objRest, __spreadValues } from '../chunk-BBZEL7EG.js';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
- import 'react';
4
3
  import { FormGroup, Hint, cn } from '@raketa-builder/ui';
5
4
  import TextInput from './TextInput';
6
5
  import SelectMenu from './SelectMenu';
@@ -1,6 +1,5 @@
1
1
  import { __spreadProps, __spreadValues } from '../chunk-BBZEL7EG.js';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import 'react';
4
3
  import { FormGroup, Label, Select, Hint } from '@raketa-builder/ui';
5
4
  import { randomString } from '../lists';
6
5
 
@@ -1,6 +1,5 @@
1
1
  import { __objRest, __spreadValues } from '../chunk-BBZEL7EG.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import 'react';
4
3
  import TextInput from './TextInput';
5
4
 
6
5
  function TextArea(_a) {
@@ -2,12 +2,10 @@ import { __spreadValues } from '../chunk-BBZEL7EG.js';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
3
  import React from 'react';
4
4
  import { H } from '@raketa-builder/ui';
5
- import { SideNav, NavGroup, NavItem, NavButton, NavPanel, SideNavSearchWrapper } from '../lib/SideNav';
5
+ import { SideNav, NavGroup, NavItem, NavButton, NavPanel } from '../lib/SideNav';
6
6
  import LanguageSwitcher from '../lib/LanguageSwitcher';
7
- import { SidebarItem } from '../lib/SidebarItem';
8
- import TextInput from '../forms/TextInput';
7
+ import WidgetsList from './WidgetsList';
9
8
  import LibraryContext from '../LibraryContext';
10
- import widgetData from '../helpers/widgetData';
11
9
 
12
10
  const ICONS = {
13
11
  add: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIHdpZHRoPSIyMnB4IiBoZWlnaHQ9IjIycHgiIHZpZXdCb3g9IjAgMCAyMiAyMiIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9y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itle.toUpperCase();
27
- var nameB = b.widgetTitle.toUpperCase();
28
- if (nameA < nameB) return -1;
29
- if (nameA > nameB) return 1;
30
- return 0;
31
- };
32
- const WidgetsList = ({ library, onAddWidget }) => {
33
- const [q, setQ] = React.useState("");
34
- const widgets = Object.keys(library).filter((widgetName) => !widgetData.deprecated(library[widgetName])).filter((widgetName) => {
35
- return widgetData.title(library[widgetName]).toLowerCase().indexOf(q.toLowerCase()) !== -1;
36
- });
37
- const widgetsCategories = widgets.map((widgetName) => widgetData.category(library[widgetName])).filter((c, idx, self) => self.indexOf(c) === idx);
38
- return /* @__PURE__ */ jsxs("div", { children: [
39
- /* @__PURE__ */ jsx(SideNavSearchWrapper, { children: /* @__PURE__ */ jsx(
40
- TextInput,
41
- {
42
- type: "search",
43
- className: "r-admin-sidenav-search-input",
44
- value: q,
45
- onChange: setQ,
46
- placeholder: "Search..."
47
- }
48
- ) }),
49
- widgetsCategories.map((categoryName, idx) => /* @__PURE__ */ jsxs("div", { style: { marginBottom: "25px" }, children: [
50
- /* @__PURE__ */ jsx(H, { size: "medium", style: { color: "#fff" }, children: categoryName }),
51
- widgets.filter(
52
- (widgetName) => widgetData.category(library[widgetName]) === categoryName
53
- ).map((widgetName) => ({
54
- widgetName,
55
- widgetTitle: widgetData.title(library[widgetName])
56
- })).sort(sortByTitle).map((item, idx2) => /* @__PURE__ */ jsx(
57
- SidebarItem,
58
- {
59
- onClick: () => onAddWidget(item.widgetName),
60
- children: item.widgetTitle
61
- },
62
- idx2
63
- ))
64
- ] }, idx))
65
- ] });
66
- };
67
23
  const AdminSidebar = ({
68
24
  buttons,
69
25
  languageSwitcherSettings,
@@ -5,6 +5,7 @@ import AdminWidgetWrapper from './AdminWidgetWrapper';
5
5
  import AdminWidgetToolbar from './AdminWidgetToolbar';
6
6
  import AdminWidgetLabel from './AdminWidgetLabel';
7
7
  import IconButton from './IconButton';
8
+ import InsertWidgetControls from './InsertWidgetControls';
8
9
  import widgetData from '../helpers/widgetData';
9
10
  import { Container } from '@raketa-builder/support';
10
11
  import { cn } from '@raketa-builder/ui';
@@ -18,7 +19,11 @@ const AdminWidget = ({
18
19
  onCopy,
19
20
  onSelectWidget,
20
21
  selectedWidgets,
21
- wrapWidget
22
+ wrapWidget,
23
+ index,
24
+ isLast,
25
+ onInsert,
26
+ onPaste
22
27
  }) => {
23
28
  var _a;
24
29
  const currentWidget = library[widget.component];
@@ -34,9 +39,30 @@ const AdminWidget = ({
34
39
  const widgetsToCopy = [widget];
35
40
  onCopy(widgetsToCopy);
36
41
  };
42
+ const insertControls = /* @__PURE__ */ jsxs(Fragment, { children: [
43
+ /* @__PURE__ */ jsx(
44
+ InsertWidgetControls,
45
+ {
46
+ index,
47
+ position: "top",
48
+ onInsert,
49
+ onPaste
50
+ }
51
+ ),
52
+ isLast && /* @__PURE__ */ jsx(
53
+ InsertWidgetControls,
54
+ {
55
+ index: index + 1,
56
+ position: "bottom",
57
+ onInsert,
58
+ onPaste
59
+ }
60
+ )
61
+ ] });
37
62
  if (!currentWidget || !currentAdminWidget) {
38
63
  console.error(`Unknown widget: ${widget.component}`);
39
64
  return /* @__PURE__ */ jsxs(AdminWidgetWrapper, { "data-widget": widget.component, children: [
65
+ insertControls,
40
66
  /* @__PURE__ */ jsx(AdminWidgetToolbar, { "data-toolbar": true, children: !isSelected && /* @__PURE__ */ jsx(
41
67
  IconButton,
42
68
  {
@@ -50,6 +76,7 @@ const AdminWidget = ({
50
76
  }
51
77
  return /* @__PURE__ */ jsxs(AdminWidgetWrapper, { "data-widget": widget.component, children: [
52
78
  isSelected && /* @__PURE__ */ jsx("div", { className: "r-selected-widget" }),
79
+ insertControls,
53
80
  /* @__PURE__ */ jsxs(AdminWidgetToolbar, { "data-toolbar": true, children: [
54
81
  !widgetData.deprecated(currentAdminWidget) && /* @__PURE__ */ jsx(
55
82
  "input",
@@ -1,6 +1,5 @@
1
1
  import { __objRest, __spreadValues } from '../chunk-BBZEL7EG.js';
2
2
  import { jsx } from 'react/jsx-runt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9wYXRoPiAgICAgICAgICAgIDxwYXRoIGQ9Ik0xMCwwIEwxMCwyMCI+PC9wYXRoPiAgICAgICAgPC9nPiAgICA8L2c+PC9zdmc+",
package/dist/lib/Image.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { __objRest, __spreadValues } from '../chunk-BBZEL7EG.js';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
- import 'react';
4
3
 
5
4
  const getWebp = (url) => {
6
5
  if (!url) return null;
@@ -52,7 +51,7 @@ const getSrc = (src, variant) => {
52
51
  };
53
52
  const getImageObjOrSrc = (value) => {
54
53
  const type = typeof value;
55
- if (type === "object" && value.hasOwnProperty("image")) {
54
+ if (type === "object" && Object.hasOwn(value, "image")) {
56
55
  return value.image;
57
56
  }
58
57
  return value;
@@ -0,0 +1,44 @@
1
+ import '../chunk-BBZEL7EG.js';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { cn } from '@raketa-builder/ui';
4
+
5
+ const InsertWidgetControls = ({
6
+ index,
7
+ position = "top",
8
+ onInsert,
9
+ onPaste
10
+ }) => /* @__PURE__ */ jsxs(
11
+ "div",
12
+ {
13
+ "data-insert-controls": true,
14
+ className: cn(
15
+ "r-reset",
16
+ "r-insert-widget-controls",
17
+ `r-insert-widget-controls-${position}`,
18
+ position === "top" && index === 0 && "r-insert-widget-controls-first"
19
+ ),
20
+ children: [
21
+ onInsert && /* @__PURE__ */ jsx(
22
+ "button",
23
+ {
24
+ type: "button",
25
+ className: "r-reset r-reset-button r-insert-widget-button",
26
+ onClick: () => onInsert(index),
27
+ children: "+ Insert widget"
28
+ }
29
+ ),
30
+ onPaste && /* @__PURE__ */ jsx(
31
+ "button",
32
+ {
33
+ type: "button",
34
+ className: "r-reset r-reset-button r-insert-widget-button",
35
+ onClick: () => onPaste(index),
36
+ children: "+ Paste widgets"
37
+ }
38
+ )
39
+ ]
40
+ }
41
+ );
42
+ var InsertWidgetControls_default = InsertWidgetControls;
43
+
44
+ export { InsertWidgetControls_default as default };
@@ -1,6 +1,5 @@
1
1
  import { __objRest, __spreadValues } from '../chunk-BBZEL7EG.js';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
- import 'react';
4
3
  import { cn } from '@raketa-builder/ui';
5
4
 
6
5
  const LanguageSwitcherWrapper = (_a) => {
@@ -76,7 +75,7 @@ const LanguageSwitcher = ({ current, navigation }) => {
76
75
  path: navItem.path,
77
76
  label: navItem.label
78
77
  },
79
- idx
78
+ `${idx}-${navItem.path}`
80
79
  );
81
80
  }) })
82
81
  ] });
package/dist/lib/Link.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import '../chunk-BBZEL7EG.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import 'react';
4
3
 
5
4
  const Link = ({ settings, children, className }) => {
6
5
  const { id, label, link, target, rel } = settings;
@@ -1,6 +1,5 @@
1
1
  import { __objRest, __spreadValues, __spreadProps } from '../chunk-BBZEL7EG.js';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import 'react';
4
3
  import { cn } from '@raketa-builder/ui';
5
4
 
6
5
  const SideNav = (_a) => {
@@ -101,7 +100,15 @@ const Tooltip = (_k) => {
101
100
  );
102
101
  };
103
102
  const NavButton = (_m) => {
104
- var _n = _m, { tooltip, link = {}, hasChanges = true } = _n, props = __objRest(_n, ["tooltip", "link", "hasChanges"]);
103
+ var _n = _m, {
104
+ tooltip,
105
+ link = {},
106
+ hasChanges = true
107
+ } = _n, props = __objRest(_n, [
108
+ "tooltip",
109
+ "link",
110
+ "hasChanges"
111
+ ]);
105
112
  if (link.link) {
106
113
  return /* @__PURE__ */ jsx("a", { href: link.link, target: link.target || "_self", children: /* @__PURE__ */ jsxs(TooltipWrapper, { children: [
107
114
  /* @__PURE__ */ jsx(NavButtonStyle, __spreadProps(__spreadValues({}, props), { hasChanges })),
@@ -0,0 +1,80 @@
1
+ import { __objRest, __spreadValues } from '../chunk-BBZEL7EG.js';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import React from 'react';
4
+ import { H, cn } from '@raketa-builder/ui';
5
+ import { SideNavSearchWrapper } from './SideNav';
6
+ import { SidebarItem } from './SidebarItem';
7
+ import TextInput from '../forms/TextInput';
8
+ import widgetData from '../helpers/widgetData';
9
+
10
+ const sortByTitle = (a, b) => {
11
+ const nameA = a.widgetTitle.toUpperCase();
12
+ const nameB = b.widgetTitle.toUpperCase();
13
+ if (nameA < nameB) return -1;
14
+ if (nameA > nameB) return 1;
15
+ return 0;
16
+ };
17
+ const DialogItem = (_a) => {
18
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
19
+ return /* @__PURE__ */ jsx(
20
+ "button",
21
+ __spreadValues({
22
+ type: "button",
23
+ className: cn(
24
+ "r-reset",
25
+ "r-reset-button",
26
+ "r-fs-base",
27
+ "r-widgets-list-dialog-item",
28
+ className
29
+ )
30
+ }, props)
31
+ );
32
+ };
33
+ const WidgetsList = ({
34
+ library,
35
+ onAddWidget,
36
+ variant = "sidebar",
37
+ autoFocus = false
38
+ }) => {
39
+ const [q, setQ] = React.useState("");
40
+ const isSidebar = variant === "sidebar";
41
+ const widgets = Object.keys(library).filter((widgetName) => !widgetData.deprecated(library[widgetName])).filter((widgetName) => {
42
+ return widgetData.title(library[widgetName]).toLowerCase().indexOf(q.toLowerCase()) !== -1;
43
+ });
44
+ const widgetsCategories = widgets.map((widgetName) => widgetData.category(library[widgetName])).filter((c, idx, self) => self.indexOf(c) === idx);
45
+ const Item = isSidebar ? SidebarItem : DialogItem;
46
+ const searchInput = /* @__PURE__ */ jsx(
47
+ TextInput,
48
+ {
49
+ type: "search",
50
+ className: isSidebar ? "r-admin-sidenav-search-input" : void 0,
51
+ value: q,
52
+ onChange: setQ,
53
+ placeholder: "Search...",
54
+ autoFocus
55
+ }
56
+ );
57
+ return /* @__PURE__ */ jsxs("div", { children: [
58
+ isSidebar ? /* @__PURE__ */ jsx(SideNavSearchWrapper, { children: searchInput }) : searchInput,
59
+ widgetsCategories.length === 0 && !isSidebar && /* @__PURE__ */ jsx("p", { className: "r-reset r-fs-base", children: "No widgets match your search." }),
60
+ widgetsCategories.map((categoryName, idx) => /* @__PURE__ */ jsxs("div", { style: { marginBottom: "25px" }, children: [
61
+ /* @__PURE__ */ jsx(H, { size: "medium", style: isSidebar ? { color: "#fff" } : void 0, children: categoryName }),
62
+ widgets.filter(
63
+ (widgetName) => widgetData.category(library[widgetName]) === categoryName
64
+ ).map((widgetName) => ({
65
+ widgetName,
66
+ widgetTitle: widgetData.title(library[widgetName])
67
+ })).sort(sortByTitle).map((item, idx2) => /* @__PURE__ */ jsx(
68
+ Item,
69
+ {
70
+ onClick: () => onAddWidget(item.widgetName),
71
+ children: item.widgetTitle
72
+ },
73
+ `${idx2}-${item.widgetName}`
74
+ ))
75
+ ] }, `${idx}-${categoryName}`))
76
+ ] });
77
+ };
78
+ var WidgetsList_default = WidgetsList;
79
+
80
+ export { WidgetsList_default as default };
@@ -2,7 +2,11 @@ import '../chunk-BBZEL7EG.js';
2
2
 
3
3
  const add = (items, item) => [...items, item];
4
4
  const addAtBeggining = (items, item) => [item, ...items];
5
- const addAt = (items, item, idx) => console.log("TODO: Implement me");
5
+ const addAt = (items, item, idx) => insertManyAt(items, [item], idx);
6
+ const insertManyAt = (items, newItems, idx = items.length) => {
7
+ const position = Math.max(0, Math.min(idx, items.length));
8
+ return [...items.slice(0, position), ...newItems, ...items.slice(position)];
9
+ };
6
10
  const duplicate = (items, field, idx) => [
7
11
  ...items.slice(0, idx + 1),
8
12
  field,
@@ -32,4 +36,4 @@ const reorder = (items, order) => order.map((idx) => items[idx]);
32
36
  const randomId = () => Math.floor(Math.random() * (999 - 100 + 1)) + 100;
33
37
  const randomString = (length) => Math.random().toString(36).substring(length);
34
38
 
35
- export { add, addAt, addAtBeggining, duplicate, randomId, randomString, removeById, removeByIndex, removeMultipleById, reorder, updateFieldById, updateFieldByIndex };
39
+ export { add, addAt, addAtBeggining, duplicate, insertManyAt, randomId, randomString, removeById, removeByIndex, removeMultipleById, reorder, updateFieldById, updateFieldByIndex };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-builder/builder",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -27,8 +27,10 @@
27
27
  "scripts": {
28
28
  "build": "tsup",
29
29
  "dev": "tsup --watch",
30
- "format": "prettier --write .",
31
- "lint": "biome lint --max-diagnostics=5000 ."
30
+ "format": "prettier --ignore-path ../../.prettierignore --write .",
31
+ "format:check": "prettier --ignore-path ../../.prettierignore --check .",
32
+ "lint": "biome lint --write --max-diagnostics=5000 .",
33
+ "lint:check": "biome lint --max-diagnostics=5000 ."
32
34
  },
33
35
  "peerDependencies": {
34
36
  "react": ">=19.1.0 && <=19.3.0",
@@ -36,8 +38,8 @@
36
38
  },
37
39
  "dependencies": {
38
40
  "react-sortablejs": "6.1.4",
39
- "@raketa-builder/support": "1.8.0",
40
- "@raketa-builder/ui": "1.8.0"
41
+ "@raketa-builder/support": "1.8.1",
42
+ "@raketa-builder/ui": "1.8.1"
41
43
  },
42
44
  "devDependencies": {
43
45
  "@biomejs/biome": "2.1.2",