@raketa-builder/menu-builder 1.0.7 → 1.0.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.
Files changed (2) hide show
  1. package/dist/index.js +831 -0
  2. package/package.json +3 -4
package/dist/index.js ADDED
@@ -0,0 +1,831 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __export = (target, all) => {
38
+ for (var name in all)
39
+ __defProp(target, name, { get: all[name], enumerable: true });
40
+ };
41
+ var __copyProps = (to, from, except, desc) => {
42
+ if (from && typeof from === "object" || typeof from === "function") {
43
+ for (let key of __getOwnPropNames(from))
44
+ if (!__hasOwnProp.call(to, key) && key !== except)
45
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
46
+ }
47
+ return to;
48
+ };
49
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
50
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
51
+ mod
52
+ ));
53
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
54
+
55
+ // src/index.js
56
+ var src_exports = {};
57
+ __export(src_exports, {
58
+ MenuBuilder: () => MenuBuilder_default
59
+ });
60
+ module.exports = __toCommonJS(src_exports);
61
+
62
+ // src/MenuBuilder/index.js
63
+ var import_react9 = __toESM(require("react"));
64
+
65
+ // src/MenuBuilder/WidgetContext.js
66
+ var import_react = __toESM(require("react"));
67
+ var WidgetContext_default = import_react.default.createContext();
68
+
69
+ // src/MenuBuilder/MainNavigation.js
70
+ var import_react2 = __toESM(require("react"));
71
+ var import_react_sortablejs = require("react-sortablejs");
72
+
73
+ // src/MenuBuilder/utils.js
74
+ var rand = (length) => Math.random().toString(36).substring(length);
75
+ var remove = (items, item) => {
76
+ const idx = items.findIndex((i) => i.id === item.id);
77
+ return [...items.slice(0, idx), ...items.slice(idx + 1)];
78
+ };
79
+ var update = (items, item) => {
80
+ const idx = items.findIndex((i) => i.id === item.id);
81
+ return [...items.slice(0, idx), item, ...items.slice(idx + 1)];
82
+ };
83
+ var append = (items, item) => [...items, item];
84
+
85
+ // src/MenuBuilder/Factories.js
86
+ var Factories = {
87
+ item: () => ({
88
+ id: rand(4),
89
+ html_id: "",
90
+ class_name: "",
91
+ label: "New item",
92
+ url: "#",
93
+ target: "",
94
+ rows: []
95
+ }),
96
+ row: () => ({ id: rand(4), columns: [] }),
97
+ column: () => ({ id: rand(4), widgets: [] }),
98
+ widget: (component, settings) => ({ id: rand(4), component, settings })
99
+ };
100
+ var Factories_default = Factories;
101
+
102
+ // src/MenuBuilder/MainNavigation.js
103
+ var import_ui = require("@raketa-builder/ui");
104
+ var import_jsx_runtime = require("react/jsx-runtime");
105
+ var Item = (_a) => {
106
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
107
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
108
+ "div",
109
+ __spreadValues({
110
+ className: (0, import_ui.cn)(
111
+ "r-reset",
112
+ "r-main-nav-item",
113
+ props.active ? "active" : "",
114
+ className
115
+ )
116
+ }, props)
117
+ );
118
+ };
119
+ var TabButton = (_a) => {
120
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
121
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
122
+ "div",
123
+ __spreadValues({
124
+ className: (0, import_ui.cn)("r-reset-button r-main-nav-tab-button", className)
125
+ }, props)
126
+ );
127
+ };
128
+ var MainNavigation = ({ items, tab, onTab, onChange }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Container, { bottom: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Stack, { children: [
129
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
130
+ import_react_sortablejs.ReactSortable,
131
+ {
132
+ list: items,
133
+ setList: onChange,
134
+ direction: "horizontal",
135
+ dragoverBubble: true,
136
+ children: items.map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Item, { active: idx === tab, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
137
+ TabButton,
138
+ {
139
+ type: "button",
140
+ active: (idx === tab).toString(),
141
+ onClick: () => onTab(idx),
142
+ children: item.label
143
+ }
144
+ ) }, item.id))
145
+ }
146
+ ),
147
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
148
+ import_ui.Button,
149
+ {
150
+ variant: "secondary",
151
+ onClick: () => onChange(append(items, Factories_default.item())),
152
+ children: "Add item"
153
+ }
154
+ )
155
+ ] }) });
156
+ var MainNavigation_default = MainNavigation;
157
+
158
+ // src/MenuBuilder/ItemForm.js
159
+ var import_react3 = __toESM(require("react"));
160
+
161
+ // src/MenuBuilder/icons.js
162
+ var import_ui2 = require("@raketa-builder/ui");
163
+ var import_jsx_runtime2 = require("react/jsx-runtime");
164
+ function filterStyle(props) {
165
+ const value = props.invert ? 1 : 0;
166
+ return { filter: `invert(${value})` };
167
+ }
168
+ function Edit(_a) {
169
+ var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
170
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
171
+ "svg",
172
+ __spreadProps(__spreadValues({
173
+ className: (0, import_ui2.cn)(
174
+ "r-reset",
175
+ "r-menu-icon",
176
+ "feather",
177
+ "feather-edit-2",
178
+ className
179
+ ),
180
+ style: filterStyle(rest),
181
+ xmlns: "http://www.w3.org/2000/svg",
182
+ width: "24",
183
+ height: "24",
184
+ viewBox: "0 0 24 24",
185
+ fill: "none",
186
+ stroke: "#000",
187
+ strokeWidth: "2",
188
+ strokeLinecap: "round",
189
+ strokeLinejoin: "round"
190
+ }, rest), {
191
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z" })
192
+ })
193
+ );
194
+ }
195
+ function Delete(_a) {
196
+ var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
197
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
198
+ "svg",
199
+ __spreadProps(__spreadValues({
200
+ className: (0, import_ui2.cn)(
201
+ "r-reset",
202
+ "r-menu-icon",
203
+ "feather",
204
+ "feather-trash",
205
+ className
206
+ ),
207
+ style: filterStyle(rest),
208
+ xmlns: "http://www.w3.org/2000/svg",
209
+ width: "24",
210
+ height: "24",
211
+ viewBox: "0 0 24 24",
212
+ fill: "none",
213
+ stroke: "#000",
214
+ strokeWidth: "2",
215
+ strokeLinecap: "round",
216
+ strokeLinejoin: "round"
217
+ }, rest), {
218
+ children: [
219
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "3 6 5 6 21 6" }),
220
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" })
221
+ ]
222
+ })
223
+ );
224
+ }
225
+ function Copy(_a) {
226
+ var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
227
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
228
+ "svg",
229
+ __spreadProps(__spreadValues({
230
+ className: (0, import_ui2.cn)(
231
+ "r-reset",
232
+ "r-menu-icon",
233
+ "feather",
234
+ "feather-copy",
235
+ className
236
+ ),
237
+ style: filterStyle(rest),
238
+ xmlns: "http://www.w3.org/2000/svg",
239
+ width: "24",
240
+ height: "24",
241
+ viewBox: "0 0 24 24",
242
+ fill: "none",
243
+ stroke: "#000",
244
+ strokeWidth: "2",
245
+ strokeLinecap: "round",
246
+ strokeLinejoin: "round"
247
+ }, rest), {
248
+ children: [
249
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
250
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
251
+ ]
252
+ })
253
+ );
254
+ }
255
+
256
+ // src/MenuBuilder/ItemForm.js
257
+ var import_ui3 = require("@raketa-builder/ui");
258
+ var import_jsx_runtime3 = require("react/jsx-runtime");
259
+ var ItemForm = ({ item, onChange, onRemove, onDuplicate }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
260
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui3.Stack, { children: [
261
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui3.FormGroup, { children: [
262
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Label, { htmlFor: "label", children: "Label" }),
263
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
264
+ import_ui3.Input,
265
+ {
266
+ name: "label",
267
+ type: "text",
268
+ wrapperProps: { style: { marginRight: "0.5em" } },
269
+ value: item.label,
270
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, item), {
271
+ label: e.target.value
272
+ }))
273
+ }
274
+ )
275
+ ] }),
276
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui3.FormGroup, { children: [
277
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Label, { htmlFor: "url", children: "URL" }),
278
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
279
+ import_ui3.Input,
280
+ {
281
+ name: "url",
282
+ type: "text",
283
+ value: item.url,
284
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, item), {
285
+ url: e.target.value
286
+ }))
287
+ }
288
+ )
289
+ ] }),
290
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui3.FormGroup, { children: [
291
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Label, { htmlFor: "html_id", children: "ID" }),
292
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
293
+ import_ui3.Input,
294
+ {
295
+ name: "html_id",
296
+ type: "text",
297
+ value: item.html_id,
298
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, item), {
299
+ html_id: e.target.value
300
+ }))
301
+ }
302
+ )
303
+ ] }),
304
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui3.FormGroup, { children: [
305
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Label, { htmlFor: "class_name", children: "CSS class" }),
306
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
307
+ import_ui3.Input,
308
+ {
309
+ name: "class_name",
310
+ type: "text",
311
+ value: item.class_name,
312
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, item), {
313
+ class_name: e.target.value
314
+ }))
315
+ }
316
+ )
317
+ ] }),
318
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui3.FormGroup, { children: [
319
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Label, { htmlFor: "target", children: "Target" }),
320
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
321
+ import_ui3.Select,
322
+ {
323
+ name: "target",
324
+ value: item.target,
325
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, item), {
326
+ target: e.target.value
327
+ })),
328
+ children: [
329
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "", children: "Please select" }),
330
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "_self", children: "Open in same tab" }),
331
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "_blank", children: "Open in new tab" })
332
+ ]
333
+ }
334
+ )
335
+ ] })
336
+ ] }),
337
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Toolbar, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui3.Stack, { children: [
338
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Button, { variant: "secondary", onClick: onDuplicate, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Copy, {}) }),
339
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Button, { variant: "secondary", onClick: onRemove, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Delete, {}) })
340
+ ] }) })
341
+ ] });
342
+ var ItemForm_default = ItemForm;
343
+
344
+ // src/MenuBuilder/RowBuilder.js
345
+ var import_react8 = __toESM(require("react"));
346
+ var import_react_sortablejs4 = require("react-sortablejs");
347
+
348
+ // src/MenuBuilder/ColumnBuilder.js
349
+ var import_react7 = __toESM(require("react"));
350
+ var import_react_sortablejs3 = require("react-sortablejs");
351
+ var import_ui7 = require("@raketa-builder/ui");
352
+
353
+ // src/MenuBuilder/ContentBuilder.js
354
+ var import_react6 = __toESM(require("react"));
355
+ var import_react_sortablejs2 = require("react-sortablejs");
356
+
357
+ // src/MenuBuilder/AdminWidget.js
358
+ var import_react4 = __toESM(require("react"));
359
+ var import_ui4 = require("@raketa-builder/ui");
360
+ var import_builder = require("@raketa-builder/builder");
361
+ var import_jsx_runtime4 = require("react/jsx-runtime");
362
+ function checkForChanges(hasChanges, onClose) {
363
+ if (!hasChanges) {
364
+ onClose();
365
+ return;
366
+ }
367
+ if (!confirm(
368
+ "You\u2019ve made changes to the widget. Are you sure you want to cancel?"
369
+ ))
370
+ return;
371
+ onClose();
372
+ }
373
+ var AdminWidget = ({
374
+ widget,
375
+ settings,
376
+ onChange,
377
+ handleChanges,
378
+ onCancel
379
+ }) => {
380
+ const [state, setState] = import_react4.default.useState(settings);
381
+ const areChanges = JSON.stringify(state) !== JSON.stringify(settings);
382
+ const schema = widget.admin;
383
+ if (typeof schema !== "object") {
384
+ console.warn(
385
+ `Legacy widget with React admin definition: "${widget.name}". Update to schema defined inputs!`
386
+ );
387
+ }
388
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
389
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
390
+ import_builder.AdminForm,
391
+ {
392
+ schema,
393
+ value: state,
394
+ onChange: (newState) => {
395
+ console.log({ newState });
396
+ setState(__spreadValues({}, newState));
397
+ handleChanges(__spreadValues({}, newState));
398
+ }
399
+ }
400
+ ),
401
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
402
+ import_ui4.Button,
403
+ {
404
+ type: "submit",
405
+ variant: "primary",
406
+ onClick: () => onChange(__spreadValues({}, state)),
407
+ children: "Save"
408
+ }
409
+ ),
410
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
411
+ import_ui4.Button,
412
+ {
413
+ variant: "secondary",
414
+ onClick: () => checkForChanges(areChanges, onCancel),
415
+ children: "Cancel"
416
+ }
417
+ )
418
+ ] });
419
+ };
420
+ var AdminWidget_default = AdminWidget;
421
+
422
+ // src/MenuBuilder/AddWidget.js
423
+ var import_react5 = __toESM(require("react"));
424
+ var import_ui5 = require("@raketa-builder/ui");
425
+ var import_jsx_runtime5 = require("react/jsx-runtime");
426
+ var WidgetButton = (_a) => {
427
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
428
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", __spreadValues({ className: (0, import_ui5.cn)("r-reset-button r-widget-button", className) }, props));
429
+ };
430
+ var AddWidget = ({ onAdd, onClose }) => {
431
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_ui5.Modal, { open: true, title: "Select widget", onClose, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(WidgetContext_default.Consumer, { children: (WIDGETS) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react5.default.Fragment, { children: Object.keys(WIDGETS).map((widgetName) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
432
+ WidgetButton,
433
+ {
434
+ onClick: () => onAdd(widgetName, WIDGETS[widgetName]),
435
+ children: widgetName
436
+ },
437
+ widgetName
438
+ )) }) }) });
439
+ };
440
+ var AddWidget_default = AddWidget;
441
+
442
+ // src/MenuBuilder/ContentBuilder.js
443
+ var import_ui6 = require("@raketa-builder/ui");
444
+ var import_jsx_runtime6 = require("react/jsx-runtime");
445
+ var getWidget = (widgets, name) => widgets[name];
446
+ var getTitle = (widgets, widget) => {
447
+ const { component } = widget;
448
+ const primaryField = getWidget(widgets, component).primaryField;
449
+ return primaryField ? `${component}: ${widget.settings[primaryField]}` : component;
450
+ };
451
+ var ContentBuilder = ({ value, onChange }) => {
452
+ const [widget, setWidget] = import_react6.default.useState({
453
+ open: false,
454
+ current: null
455
+ });
456
+ const [open, setOpen] = import_react6.default.useState(false);
457
+ const [state, setState] = import_react6.default.useState(value);
458
+ const [areChanges, setAreChanges] = import_react6.default.useState(false);
459
+ (0, import_react6.useEffect)(() => {
460
+ setState(value);
461
+ }, [value]);
462
+ const addWidget = (items, item) => {
463
+ const newState = __spreadProps(__spreadValues({}, state), {
464
+ widgets: [...items, item]
465
+ });
466
+ setOpen(false);
467
+ setState(newState);
468
+ onChange(newState);
469
+ };
470
+ const removeWidget = (items, item) => {
471
+ if (!confirm("Are you sure?"))
472
+ return;
473
+ const newState = __spreadProps(__spreadValues({}, state), {
474
+ widgets: remove(items, item)
475
+ });
476
+ setState(newState);
477
+ onChange(newState);
478
+ };
479
+ const reorder = (widgets) => {
480
+ const newState = __spreadProps(__spreadValues({}, state), { widgets });
481
+ setState(newState);
482
+ onChange(newState);
483
+ };
484
+ const closeWidget = () => {
485
+ setWidget({ open: false, current: null });
486
+ setAreChanges(false);
487
+ };
488
+ const updateWidget = (widget2, settings) => {
489
+ const newState = __spreadProps(__spreadValues({}, state), {
490
+ widgets: update(state.widgets, __spreadProps(__spreadValues({}, widget2), { settings }))
491
+ });
492
+ closeWidget();
493
+ setState(newState);
494
+ onChange(newState);
495
+ };
496
+ const handleChanges = (settings) => setAreChanges(widget.current.settings !== settings);
497
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(WidgetContext_default.Consumer, { children: (WIDGETS) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react6.default.Fragment, { children: [
498
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
499
+ import_react_sortablejs2.ReactSortable,
500
+ {
501
+ list: state.widgets,
502
+ setList: (widgets) => reorder(widgets),
503
+ handle: ".r-handle",
504
+ direction: "vertical",
505
+ children: state.widgets.map((widget2) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui6.Panel, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui6.PanelTitle, { children: [
506
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui6.Stack, { className: "r-stack-align-center", children: [
507
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui6.Handle, { className: "r-handle" }),
508
+ getTitle(WIDGETS, widget2)
509
+ ] }),
510
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui6.Stack, { className: "r-stack-align-center", children: [
511
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
512
+ import_ui6.Button,
513
+ {
514
+ variant: "secondary",
515
+ onClick: () => setWidget({ open: true, current: widget2 }),
516
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Edit, {})
517
+ }
518
+ ),
519
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
520
+ import_ui6.Button,
521
+ {
522
+ variant: "secondary",
523
+ onClick: () => removeWidget(state.widgets, widget2),
524
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Delete, {})
525
+ }
526
+ )
527
+ ] })
528
+ ] }) }, widget2.id))
529
+ }
530
+ ),
531
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui6.Button, { variant: "secondary", onClick: () => setOpen(true), children: "Add widget" }),
532
+ widget.open && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
533
+ import_ui6.Modal,
534
+ {
535
+ title: "Settings",
536
+ open: widget.open,
537
+ areChanges,
538
+ onClose: closeWidget,
539
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
540
+ AdminWidget_default,
541
+ {
542
+ widget: getWidget(WIDGETS, widget.current.component),
543
+ settings: widget.current.settings,
544
+ onChange: (settings) => updateWidget(widget.current, settings),
545
+ handleChanges,
546
+ onCancel: closeWidget
547
+ }
548
+ )
549
+ }
550
+ ),
551
+ open && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
552
+ AddWidget_default,
553
+ {
554
+ onAdd: (component, widget2) => addWidget(
555
+ state.widgets,
556
+ Factories_default.widget(component, widget2.defaults)
557
+ ),
558
+ onClose: () => setOpen(false)
559
+ }
560
+ )
561
+ ] }) });
562
+ };
563
+ var ContentBuilder_default = ContentBuilder;
564
+
565
+ // src/MenuBuilder/ColumnBuilder.js
566
+ var import_jsx_runtime7 = require("react/jsx-runtime");
567
+ var Wrapper = (_a) => {
568
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
569
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", __spreadValues({ className: (0, import_ui7.cn)("r-reset", className) }, props));
570
+ };
571
+ var ColumnBuilder = ({ value, onChange }) => {
572
+ const [state, setState] = import_react7.default.useState(value);
573
+ (0, import_react7.useEffect)(() => {
574
+ setState(value);
575
+ }, [value]);
576
+ const addColumn = (items, item) => {
577
+ const newState = __spreadProps(__spreadValues({}, state), {
578
+ columns: [...items, item]
579
+ });
580
+ setState(newState);
581
+ onChange(newState);
582
+ };
583
+ const updateColumn = (items, item) => {
584
+ const newState = __spreadProps(__spreadValues({}, state), {
585
+ columns: update(items, item)
586
+ });
587
+ setState(newState);
588
+ onChange(newState);
589
+ };
590
+ const duplicateColumn = (items, item) => {
591
+ const newState = __spreadProps(__spreadValues({}, state), {
592
+ columns: append(items, __spreadProps(__spreadValues({}, item), {
593
+ id: rand(),
594
+ label: `${item.label} (copy)`
595
+ }))
596
+ });
597
+ setState(newState);
598
+ };
599
+ const removeColumn = (items, item) => {
600
+ if (!confirm("Are you sure?"))
601
+ return;
602
+ const newState = __spreadProps(__spreadValues({}, state), {
603
+ columns: remove(items, item)
604
+ });
605
+ setState(newState);
606
+ onChange(newState);
607
+ };
608
+ const reorder = (columns) => {
609
+ const newState = __spreadProps(__spreadValues({}, state), { columns });
610
+ setState(newState);
611
+ onChange(newState);
612
+ };
613
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Wrapper, { children: [
614
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui7.Toolbar, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
615
+ import_ui7.Button,
616
+ {
617
+ variant: "secondary",
618
+ onClick: () => addColumn(state.columns, Factories_default.column()),
619
+ children: "Add column"
620
+ }
621
+ ) }),
622
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
623
+ import_react_sortablejs3.ReactSortable,
624
+ {
625
+ list: state.columns,
626
+ setList: (columns) => reorder(columns),
627
+ className: "r-list",
628
+ handle: ".r-chandle",
629
+ direction: "vertical",
630
+ children: state.columns.map((column, idx) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui7.Panel, { style: { flex: 1, marginRight: "0.5em" }, children: [
631
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui7.PanelTitle, { children: [
632
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui7.Stack, { className: "r-stack-align-center", children: [
633
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui7.Handle, { className: "r-chandle" }),
634
+ "Column #",
635
+ idx + 1
636
+ ] }),
637
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui7.Stack, { className: "r-stack-align-center", children: [
638
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
639
+ import_ui7.Button,
640
+ {
641
+ variant: "secondary",
642
+ onClick: () => duplicateColumn(state.columns, column),
643
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Copy, {})
644
+ }
645
+ ),
646
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
647
+ import_ui7.Button,
648
+ {
649
+ variant: "secondary",
650
+ onClick: () => removeColumn(state.columns, column),
651
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Delete, {})
652
+ }
653
+ )
654
+ ] })
655
+ ] }),
656
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui7.PanelContent, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
657
+ ContentBuilder_default,
658
+ {
659
+ value: column,
660
+ onChange: (column2) => updateColumn(state.columns, column2)
661
+ }
662
+ ) })
663
+ ] }, column.id))
664
+ }
665
+ )
666
+ ] });
667
+ };
668
+ var ColumnBuilder_default = ColumnBuilder;
669
+
670
+ // src/MenuBuilder/RowBuilder.js
671
+ var import_ui8 = require("@raketa-builder/ui");
672
+ var import_jsx_runtime8 = require("react/jsx-runtime");
673
+ var RowBuilder = ({ value, onChange }) => {
674
+ const [state, setState] = import_react8.default.useState(value);
675
+ (0, import_react8.useEffect)(() => {
676
+ setState(value);
677
+ }, [value]);
678
+ const addRow = (items, item) => {
679
+ const newState = __spreadProps(__spreadValues({}, state), {
680
+ rows: [...items, item]
681
+ });
682
+ setState(newState);
683
+ onChange(newState);
684
+ };
685
+ const updateRow = (items, item) => {
686
+ const newState = __spreadProps(__spreadValues({}, state), {
687
+ rows: update(items, item)
688
+ });
689
+ setState(newState);
690
+ onChange(newState);
691
+ };
692
+ const removeRow = (items, item) => {
693
+ if (!confirm("Are you sure?"))
694
+ return;
695
+ const newState = __spreadProps(__spreadValues({}, state), {
696
+ rows: remove(items, item)
697
+ });
698
+ setState(newState);
699
+ onChange(newState);
700
+ };
701
+ const reorder = (rows) => {
702
+ const newState = __spreadProps(__spreadValues({}, state), { rows });
703
+ setState(newState);
704
+ onChange(newState);
705
+ };
706
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react8.default.Fragment, { children: [
707
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
708
+ import_react_sortablejs4.ReactSortable,
709
+ {
710
+ list: state.rows,
711
+ setList: (rows) => reorder(rows),
712
+ handle: ".r-handle",
713
+ direction: "vertical",
714
+ children: state.rows.map((row, idx) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui8.Panel, { children: [
715
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui8.PanelTitle, { children: [
716
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_ui8.Stack, { className: "r-stack-align-center", children: [
717
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui8.Handle, { className: "r-handle" }),
718
+ "Row #",
719
+ idx + 1
720
+ ] }),
721
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
722
+ import_ui8.Button,
723
+ {
724
+ variant: "secondary",
725
+ onClick: () => removeRow(state.rows, row),
726
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Delete, {})
727
+ }
728
+ )
729
+ ] }),
730
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui8.PanelContent, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
731
+ ColumnBuilder_default,
732
+ {
733
+ value: row,
734
+ onChange: (row2) => updateRow(state.rows, row2)
735
+ }
736
+ ) })
737
+ ] }, row.id))
738
+ }
739
+ ),
740
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui8.Toolbar, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
741
+ import_ui8.Button,
742
+ {
743
+ variant: "secondary",
744
+ onClick: () => addRow(state.rows, Factories_default.row()),
745
+ children: "Add row"
746
+ }
747
+ ) })
748
+ ] });
749
+ };
750
+ var RowBuilder_default = RowBuilder;
751
+
752
+ // src/MenuBuilder/index.js
753
+ var import_ui9 = require("@raketa-builder/ui");
754
+ var import_jsx_runtime9 = require("react/jsx-runtime");
755
+ var MenuBuilder = ({ widgets, value, onChange }) => {
756
+ const [state, setState] = import_react9.default.useState(value);
757
+ const currentTab = state.tab;
758
+ const currentItem = state.items ? state.items[currentTab] : null;
759
+ const removeItem = (items, item) => {
760
+ if (!confirm("Are you sure?"))
761
+ return;
762
+ const newState = __spreadProps(__spreadValues({}, state), {
763
+ tab: 0,
764
+ items: remove(items, item)
765
+ });
766
+ setState(newState);
767
+ if (onChange)
768
+ onChange(newState);
769
+ };
770
+ const updateItem = (items, item) => {
771
+ const newState = __spreadProps(__spreadValues({}, state), {
772
+ items: update(items, item)
773
+ });
774
+ setState(newState);
775
+ if (onChange)
776
+ onChange(newState);
777
+ };
778
+ const duplicateItem = (items, item) => {
779
+ const newState = __spreadProps(__spreadValues({}, state), {
780
+ items: append(items, __spreadProps(__spreadValues({}, item), {
781
+ id: rand(),
782
+ label: `${item.label} (copy)`
783
+ }))
784
+ });
785
+ setState(newState);
786
+ if (onChange)
787
+ onChange(newState);
788
+ };
789
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(WidgetContext_default.Provider, { value: widgets, children: [
790
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
791
+ MainNavigation_default,
792
+ {
793
+ items: state.items,
794
+ tab: currentTab,
795
+ onTab: (tab) => setState(__spreadProps(__spreadValues({}, state), { tab })),
796
+ onChange: (items) => {
797
+ const newState = __spreadProps(__spreadValues({}, state), { items });
798
+ setState(newState);
799
+ if (onChange)
800
+ onChange(newState);
801
+ }
802
+ }
803
+ ),
804
+ currentItem && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { children: [
805
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
806
+ ItemForm_default,
807
+ {
808
+ item: currentItem,
809
+ onChange: (item) => {
810
+ updateItem(state.items, __spreadValues(__spreadValues({}, currentItem), item));
811
+ },
812
+ onRemove: () => removeItem(state.items, currentItem),
813
+ onDuplicate: () => duplicateItem(state.items, currentItem)
814
+ }
815
+ ),
816
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui9.H, { as: "h4", size: "large", children: "Menu content" }),
817
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
818
+ RowBuilder_default,
819
+ {
820
+ value: currentItem,
821
+ onChange: (item) => updateItem(state.items, __spreadValues(__spreadValues({}, currentItem), item))
822
+ }
823
+ )
824
+ ] })
825
+ ] });
826
+ };
827
+ var MenuBuilder_default = MenuBuilder;
828
+ // Annotate the CommonJS export names for ESM import in node:
829
+ 0 && (module.exports = {
830
+ MenuBuilder
831
+ });
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@raketa-builder/menu-builder",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "main": "./dist/index.js",
5
- "module": "./src/index.js",
6
5
  "types": "./dist/index.d.ts",
7
6
  "license": "MIT",
8
7
  "scripts": {
@@ -17,8 +16,8 @@
17
16
  },
18
17
  "dependencies": {
19
18
  "react-sortablejs": "2.0.11",
20
- "@raketa-builder/ui": "1.0.7",
21
- "@raketa-builder/builder": "1.0.7"
19
+ "@raketa-builder/ui": "1.0.9",
20
+ "@raketa-builder/builder": "1.0.9"
22
21
  },
23
22
  "devDependencies": {
24
23
  "@biomejs/biome": "1.5.2",