@raketa-builder/menu-builder 1.3.9 → 1.3.10

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.
@@ -0,0 +1,23 @@
1
+ import { __objRest, __spreadValues } from '../chunk-ORMEWXMH.js';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import React from 'react';
4
+ import { Modal, cn } from '@raketa-builder/ui';
5
+ import WidgetContext from './WidgetContext';
6
+
7
+ const WidgetButton = (_a) => {
8
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
9
+ return /* @__PURE__ */ jsx("div", __spreadValues({ className: cn("r-reset-button r-widget-button", className) }, props));
10
+ };
11
+ const AddWidget = ({ onAdd, onClose }) => {
12
+ return /* @__PURE__ */ jsx(Modal, { open: true, title: "Select widget", onClose, children: /* @__PURE__ */ jsx(WidgetContext.Consumer, { children: (WIDGETS) => /* @__PURE__ */ jsx(React.Fragment, { children: Object.keys(WIDGETS).map((widgetName) => /* @__PURE__ */ jsx(
13
+ WidgetButton,
14
+ {
15
+ onClick: () => onAdd(widgetName, WIDGETS[widgetName]),
16
+ children: widgetName
17
+ },
18
+ widgetName
19
+ )) }) }) });
20
+ };
21
+ var AddWidget_default = AddWidget;
22
+
23
+ export { AddWidget_default as default };
@@ -0,0 +1,67 @@
1
+ import { __spreadValues } from '../chunk-ORMEWXMH.js';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import React from 'react';
4
+ import { Button } from '@raketa-builder/ui';
5
+ import { AdminForm } from '@raketa-builder/builder';
6
+
7
+ function checkForChanges(hasChanges, onClose) {
8
+ if (!hasChanges) {
9
+ onClose();
10
+ return;
11
+ }
12
+ if (!confirm(
13
+ "You\u2019ve made changes to the widget. Are you sure you want to cancel?"
14
+ ))
15
+ return;
16
+ onClose();
17
+ }
18
+ const AdminWidget = ({
19
+ widget,
20
+ settings,
21
+ onChange,
22
+ handleChanges,
23
+ onCancel
24
+ }) => {
25
+ const [state, setState] = React.useState(settings);
26
+ const areChanges = JSON.stringify(state) !== JSON.stringify(settings);
27
+ const schema = widget.admin;
28
+ if (typeof schema !== "object") {
29
+ console.warn(
30
+ `Legacy widget with React admin definition: "${widget.name}". Update to schema defined inputs!`
31
+ );
32
+ }
33
+ return /* @__PURE__ */ jsxs("div", { children: [
34
+ /* @__PURE__ */ jsx(
35
+ AdminForm,
36
+ {
37
+ schema,
38
+ value: state,
39
+ onChange: (newState) => {
40
+ console.log({ newState });
41
+ setState(__spreadValues({}, newState));
42
+ handleChanges(__spreadValues({}, newState));
43
+ }
44
+ }
45
+ ),
46
+ /* @__PURE__ */ jsx(
47
+ Button,
48
+ {
49
+ type: "submit",
50
+ variant: "primary",
51
+ onClick: () => onChange(__spreadValues({}, state)),
52
+ children: "Save"
53
+ }
54
+ ),
55
+ /* @__PURE__ */ jsx(
56
+ Button,
57
+ {
58
+ variant: "secondary",
59
+ onClick: () => checkForChanges(areChanges, onCancel),
60
+ children: "Cancel"
61
+ }
62
+ )
63
+ ] });
64
+ };
65
+ var AdminWidget_default = AdminWidget;
66
+
67
+ export { AdminWidget_default as default };
@@ -0,0 +1,113 @@
1
+ import { __spreadProps, __spreadValues, __objRest } from '../chunk-ORMEWXMH.js';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import React, { useEffect } from 'react';
4
+ import { ReactSortable } from 'react-sortablejs';
5
+ import Factories from './Factories';
6
+ import { update, append, rand, remove } from './utils';
7
+ import { Copy, Delete } from './icons';
8
+ import { Toolbar, Button, Panel, PanelTitle, Stack, Handle, PanelContent, cn } from '@raketa-builder/ui';
9
+ import ContentBuilder from './ContentBuilder';
10
+
11
+ const Wrapper = (_a) => {
12
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
13
+ return /* @__PURE__ */ jsx("div", __spreadValues({ className: cn("r-reset", className) }, props));
14
+ };
15
+ const ColumnBuilder = ({ value, onChange }) => {
16
+ const [state, setState] = React.useState(value);
17
+ useEffect(() => {
18
+ setState(value);
19
+ }, [value]);
20
+ const addColumn = (items, item) => {
21
+ const newState = __spreadProps(__spreadValues({}, state), {
22
+ columns: [...items, item]
23
+ });
24
+ setState(newState);
25
+ onChange(newState);
26
+ };
27
+ const updateColumn = (items, item) => {
28
+ const newState = __spreadProps(__spreadValues({}, state), {
29
+ columns: update(items, item)
30
+ });
31
+ setState(newState);
32
+ onChange(newState);
33
+ };
34
+ const duplicateColumn = (items, item) => {
35
+ const newState = __spreadProps(__spreadValues({}, state), {
36
+ columns: append(items, __spreadProps(__spreadValues({}, item), {
37
+ id: rand(),
38
+ label: `${item.label} (copy)`
39
+ }))
40
+ });
41
+ setState(newState);
42
+ };
43
+ const removeColumn = (items, item) => {
44
+ if (!confirm("Are you sure?")) return;
45
+ const newState = __spreadProps(__spreadValues({}, state), {
46
+ columns: remove(items, item)
47
+ });
48
+ setState(newState);
49
+ onChange(newState);
50
+ };
51
+ const reorder = (columns) => {
52
+ const newState = __spreadProps(__spreadValues({}, state), { columns });
53
+ setState(newState);
54
+ onChange(newState);
55
+ };
56
+ return /* @__PURE__ */ jsxs(Wrapper, { children: [
57
+ /* @__PURE__ */ jsx(Toolbar, { children: /* @__PURE__ */ jsx(
58
+ Button,
59
+ {
60
+ variant: "secondary",
61
+ onClick: () => addColumn(state.columns, Factories.column()),
62
+ children: "Add column"
63
+ }
64
+ ) }),
65
+ /* @__PURE__ */ jsx(
66
+ ReactSortable,
67
+ {
68
+ list: state.columns,
69
+ setList: (columns) => reorder(columns),
70
+ className: "r-list",
71
+ handle: ".r-chandle",
72
+ direction: "vertical",
73
+ children: state.columns.map((column, idx) => /* @__PURE__ */ jsxs(Panel, { style: { flex: 1, marginRight: "0.5em" }, children: [
74
+ /* @__PURE__ */ jsxs(PanelTitle, { children: [
75
+ /* @__PURE__ */ jsxs(Stack, { className: "r-stack-align-center", children: [
76
+ /* @__PURE__ */ jsx(Handle, { className: "r-chandle" }),
77
+ "Column #",
78
+ idx + 1
79
+ ] }),
80
+ /* @__PURE__ */ jsxs(Stack, { className: "r-stack-align-center", children: [
81
+ /* @__PURE__ */ jsx(
82
+ Button,
83
+ {
84
+ variant: "secondary",
85
+ onClick: () => duplicateColumn(state.columns, column),
86
+ children: /* @__PURE__ */ jsx(Copy, {})
87
+ }
88
+ ),
89
+ /* @__PURE__ */ jsx(
90
+ Button,
91
+ {
92
+ variant: "secondary",
93
+ onClick: () => removeColumn(state.columns, column),
94
+ children: /* @__PURE__ */ jsx(Delete, {})
95
+ }
96
+ )
97
+ ] })
98
+ ] }),
99
+ /* @__PURE__ */ jsx(PanelContent, { children: /* @__PURE__ */ jsx(
100
+ ContentBuilder,
101
+ {
102
+ value: column,
103
+ onChange: (column2) => updateColumn(state.columns, column2)
104
+ }
105
+ ) })
106
+ ] }, column.id))
107
+ }
108
+ )
109
+ ] });
110
+ };
111
+ var ColumnBuilder_default = ColumnBuilder;
112
+
113
+ export { ColumnBuilder_default as default };
@@ -0,0 +1,132 @@
1
+ import { __spreadProps, __spreadValues } from '../chunk-ORMEWXMH.js';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import React, { useEffect } from 'react';
4
+ import { ReactSortable } from 'react-sortablejs';
5
+ import WidgetContext from './WidgetContext';
6
+ import Factories from './Factories';
7
+ import AdminWidget from './AdminWidget';
8
+ import AddWidget from './AddWidget';
9
+ import { remove, update } from './utils';
10
+ import { Edit, Delete } from './icons';
11
+ import { Panel, PanelTitle, Stack, Handle, Button, Modal } from '@raketa-builder/ui';
12
+
13
+ const getWidget = (widgets, name) => widgets[name];
14
+ const getTitle = (widgets, widget) => {
15
+ const { component } = widget;
16
+ const primaryField = getWidget(widgets, component).primaryField;
17
+ return primaryField ? `${component}: ${widget.settings[primaryField]}` : component;
18
+ };
19
+ const ContentBuilder = ({ value, onChange }) => {
20
+ const [widget, setWidget] = React.useState({
21
+ open: false,
22
+ current: null
23
+ });
24
+ const [open, setOpen] = React.useState(false);
25
+ const [state, setState] = React.useState(value);
26
+ const [areChanges, setAreChanges] = React.useState(false);
27
+ useEffect(() => {
28
+ setState(value);
29
+ }, [value]);
30
+ const addWidget = (items, item) => {
31
+ const newState = __spreadProps(__spreadValues({}, state), {
32
+ widgets: [...items, item]
33
+ });
34
+ setOpen(false);
35
+ setState(newState);
36
+ onChange(newState);
37
+ };
38
+ const removeWidget = (items, item) => {
39
+ if (!confirm("Are you sure?")) return;
40
+ const newState = __spreadProps(__spreadValues({}, state), {
41
+ widgets: remove(items, item)
42
+ });
43
+ setState(newState);
44
+ onChange(newState);
45
+ };
46
+ const reorder = (widgets) => {
47
+ const newState = __spreadProps(__spreadValues({}, state), { widgets });
48
+ setState(newState);
49
+ onChange(newState);
50
+ };
51
+ const closeWidget = () => {
52
+ setWidget({ open: false, current: null });
53
+ setAreChanges(false);
54
+ };
55
+ const updateWidget = (widget2, settings) => {
56
+ const newState = __spreadProps(__spreadValues({}, state), {
57
+ widgets: update(state.widgets, __spreadProps(__spreadValues({}, widget2), { settings }))
58
+ });
59
+ closeWidget();
60
+ setState(newState);
61
+ onChange(newState);
62
+ };
63
+ const handleChanges = (settings) => setAreChanges(widget.current.settings !== settings);
64
+ return /* @__PURE__ */ jsx(WidgetContext.Consumer, { children: (WIDGETS) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
65
+ /* @__PURE__ */ jsx(
66
+ ReactSortable,
67
+ {
68
+ list: state.widgets,
69
+ setList: (widgets) => reorder(widgets),
70
+ handle: ".r-handle",
71
+ direction: "vertical",
72
+ children: state.widgets.map((widget2) => /* @__PURE__ */ jsx(Panel, { children: /* @__PURE__ */ jsxs(PanelTitle, { children: [
73
+ /* @__PURE__ */ jsxs(Stack, { className: "r-stack-align-center", children: [
74
+ /* @__PURE__ */ jsx(Handle, { className: "r-handle" }),
75
+ getTitle(WIDGETS, widget2)
76
+ ] }),
77
+ /* @__PURE__ */ jsxs(Stack, { className: "r-stack-align-center", children: [
78
+ /* @__PURE__ */ jsx(
79
+ Button,
80
+ {
81
+ variant: "secondary",
82
+ onClick: () => setWidget({ open: true, current: widget2 }),
83
+ children: /* @__PURE__ */ jsx(Edit, {})
84
+ }
85
+ ),
86
+ /* @__PURE__ */ jsx(
87
+ Button,
88
+ {
89
+ variant: "secondary",
90
+ onClick: () => removeWidget(state.widgets, widget2),
91
+ children: /* @__PURE__ */ jsx(Delete, {})
92
+ }
93
+ )
94
+ ] })
95
+ ] }) }, widget2.id))
96
+ }
97
+ ),
98
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => setOpen(true), children: "Add widget" }),
99
+ widget.open && /* @__PURE__ */ jsx(
100
+ Modal,
101
+ {
102
+ title: "Settings",
103
+ open: widget.open,
104
+ areChanges,
105
+ onClose: closeWidget,
106
+ children: /* @__PURE__ */ jsx(
107
+ AdminWidget,
108
+ {
109
+ widget: getWidget(WIDGETS, widget.current.component),
110
+ settings: widget.current.settings,
111
+ onChange: (settings) => updateWidget(widget.current, settings),
112
+ handleChanges,
113
+ onCancel: closeWidget
114
+ }
115
+ )
116
+ }
117
+ ),
118
+ open && /* @__PURE__ */ jsx(
119
+ AddWidget,
120
+ {
121
+ onAdd: (component, widget2) => addWidget(
122
+ state.widgets,
123
+ Factories.widget(component, widget2.defaults)
124
+ ),
125
+ onClose: () => setOpen(false)
126
+ }
127
+ )
128
+ ] }) });
129
+ };
130
+ var ContentBuilder_default = ContentBuilder;
131
+
132
+ export { ContentBuilder_default as default };
@@ -0,0 +1,20 @@
1
+ import '../chunk-ORMEWXMH.js';
2
+ import { rand } from './utils';
3
+
4
+ const Factories = {
5
+ item: () => ({
6
+ id: rand(4),
7
+ html_id: "",
8
+ class_name: "",
9
+ label: "New item",
10
+ url: "#",
11
+ target: "",
12
+ rows: []
13
+ }),
14
+ row: () => ({ id: rand(4), columns: [] }),
15
+ column: () => ({ id: rand(4), widgets: [] }),
16
+ widget: (component, settings) => ({ id: rand(4), component, settings })
17
+ };
18
+ var Factories_default = Factories;
19
+
20
+ export { Factories_default as default };
@@ -0,0 +1,92 @@
1
+ import { __spreadProps, __spreadValues } from '../chunk-ORMEWXMH.js';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import 'react';
4
+ import { Copy, Delete } from './icons';
5
+ import { Stack, FormGroup, Label, Input, Select, Toolbar, Button } from '@raketa-builder/ui';
6
+
7
+ const ItemForm = ({ item, onChange, onRemove, onDuplicate }) => /* @__PURE__ */ jsxs("div", { children: [
8
+ /* @__PURE__ */ jsxs(Stack, { children: [
9
+ /* @__PURE__ */ jsxs(FormGroup, { children: [
10
+ /* @__PURE__ */ jsx(Label, { htmlFor: "label", children: "Label" }),
11
+ /* @__PURE__ */ jsx(
12
+ Input,
13
+ {
14
+ name: "label",
15
+ type: "text",
16
+ wrapperProps: { style: { marginRight: "0.5em" } },
17
+ value: item.label,
18
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, item), {
19
+ label: e.target.value
20
+ }))
21
+ }
22
+ )
23
+ ] }),
24
+ /* @__PURE__ */ jsxs(FormGroup, { children: [
25
+ /* @__PURE__ */ jsx(Label, { htmlFor: "url", children: "URL" }),
26
+ /* @__PURE__ */ jsx(
27
+ Input,
28
+ {
29
+ name: "url",
30
+ type: "text",
31
+ value: item.url,
32
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, item), {
33
+ url: e.target.value
34
+ }))
35
+ }
36
+ )
37
+ ] }),
38
+ /* @__PURE__ */ jsxs(FormGroup, { children: [
39
+ /* @__PURE__ */ jsx(Label, { htmlFor: "html_id", children: "ID" }),
40
+ /* @__PURE__ */ jsx(
41
+ Input,
42
+ {
43
+ name: "html_id",
44
+ type: "text",
45
+ value: item.html_id,
46
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, item), {
47
+ html_id: e.target.value
48
+ }))
49
+ }
50
+ )
51
+ ] }),
52
+ /* @__PURE__ */ jsxs(FormGroup, { children: [
53
+ /* @__PURE__ */ jsx(Label, { htmlFor: "class_name", children: "CSS class" }),
54
+ /* @__PURE__ */ jsx(
55
+ Input,
56
+ {
57
+ name: "class_name",
58
+ type: "text",
59
+ value: item.class_name,
60
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, item), {
61
+ class_name: e.target.value
62
+ }))
63
+ }
64
+ )
65
+ ] }),
66
+ /* @__PURE__ */ jsxs(FormGroup, { children: [
67
+ /* @__PURE__ */ jsx(Label, { htmlFor: "target", children: "Target" }),
68
+ /* @__PURE__ */ jsxs(
69
+ Select,
70
+ {
71
+ name: "target",
72
+ value: item.target,
73
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, item), {
74
+ target: e.target.value
75
+ })),
76
+ children: [
77
+ /* @__PURE__ */ jsx("option", { value: "", children: "Please select" }),
78
+ /* @__PURE__ */ jsx("option", { value: "_self", children: "Open in same tab" }),
79
+ /* @__PURE__ */ jsx("option", { value: "_blank", children: "Open in new tab" })
80
+ ]
81
+ }
82
+ )
83
+ ] })
84
+ ] }),
85
+ /* @__PURE__ */ jsx(Toolbar, { children: /* @__PURE__ */ jsxs(Stack, { children: [
86
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: onDuplicate, children: /* @__PURE__ */ jsx(Copy, {}) }),
87
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: onRemove, children: /* @__PURE__ */ jsx(Delete, {}) })
88
+ ] }) })
89
+ ] });
90
+ var ItemForm_default = ItemForm;
91
+
92
+ export { ItemForm_default as default };
@@ -0,0 +1,62 @@
1
+ import { __objRest, __spreadValues } from '../chunk-ORMEWXMH.js';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import 'react';
4
+ import { ReactSortable } from 'react-sortablejs';
5
+ import { append } from './utils';
6
+ import Factories from './Factories';
7
+ import { Container, Stack, Button, cn } from '@raketa-builder/ui';
8
+
9
+ const Item = (_a) => {
10
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
11
+ return /* @__PURE__ */ jsx(
12
+ "div",
13
+ __spreadValues({
14
+ className: cn(
15
+ "r-reset",
16
+ "r-main-nav-item",
17
+ props.active ? "active" : "",
18
+ className
19
+ )
20
+ }, props)
21
+ );
22
+ };
23
+ const TabButton = (_c) => {
24
+ var _d = _c, { className } = _d, props = __objRest(_d, ["className"]);
25
+ return /* @__PURE__ */ jsx(
26
+ "div",
27
+ __spreadValues({
28
+ className: cn("r-reset-button r-main-nav-tab-button", className)
29
+ }, props)
30
+ );
31
+ };
32
+ const MainNavigation = ({ items, tab, onTab, onChange }) => /* @__PURE__ */ jsx(Container, { bottom: true, children: /* @__PURE__ */ jsxs(Stack, { children: [
33
+ /* @__PURE__ */ jsx(
34
+ ReactSortable,
35
+ {
36
+ list: items,
37
+ setList: onChange,
38
+ direction: "horizontal",
39
+ dragoverBubble: true,
40
+ children: items.map((item, idx) => /* @__PURE__ */ jsx(Item, { active: idx === tab, children: /* @__PURE__ */ jsx(
41
+ TabButton,
42
+ {
43
+ type: "button",
44
+ active: (idx === tab).toString(),
45
+ onClick: () => onTab(idx),
46
+ children: item.label
47
+ }
48
+ ) }, item.id))
49
+ }
50
+ ),
51
+ /* @__PURE__ */ jsx(
52
+ Button,
53
+ {
54
+ variant: "secondary",
55
+ onClick: () => onChange(append(items, Factories.item())),
56
+ children: "Add item"
57
+ }
58
+ )
59
+ ] }) });
60
+ var MainNavigation_default = MainNavigation;
61
+
62
+ export { MainNavigation_default as default };
@@ -0,0 +1,89 @@
1
+ import { __spreadProps, __spreadValues } from '../chunk-ORMEWXMH.js';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import React, { useEffect } from 'react';
4
+ import { ReactSortable } from 'react-sortablejs';
5
+ import Factories from './Factories';
6
+ import { update, remove } from './utils';
7
+ import ColumnBuilder from './ColumnBuilder';
8
+ import { Delete } from './icons';
9
+ import { Panel, PanelTitle, Stack, Handle, Button, PanelContent, Toolbar } from '@raketa-builder/ui';
10
+
11
+ const RowBuilder = ({ value, onChange }) => {
12
+ const [state, setState] = React.useState(value);
13
+ useEffect(() => {
14
+ setState(value);
15
+ }, [value]);
16
+ const addRow = (items, item) => {
17
+ const newState = __spreadProps(__spreadValues({}, state), {
18
+ rows: [...items, item]
19
+ });
20
+ setState(newState);
21
+ onChange(newState);
22
+ };
23
+ const updateRow = (items, item) => {
24
+ const newState = __spreadProps(__spreadValues({}, state), {
25
+ rows: update(items, item)
26
+ });
27
+ setState(newState);
28
+ onChange(newState);
29
+ };
30
+ const removeRow = (items, item) => {
31
+ if (!confirm("Are you sure?")) return;
32
+ const newState = __spreadProps(__spreadValues({}, state), {
33
+ rows: remove(items, item)
34
+ });
35
+ setState(newState);
36
+ onChange(newState);
37
+ };
38
+ const reorder = (rows) => {
39
+ const newState = __spreadProps(__spreadValues({}, state), { rows });
40
+ setState(newState);
41
+ onChange(newState);
42
+ };
43
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [
44
+ /* @__PURE__ */ jsx(
45
+ ReactSortable,
46
+ {
47
+ list: state.rows,
48
+ setList: (rows) => reorder(rows),
49
+ handle: ".r-handle",
50
+ direction: "vertical",
51
+ children: state.rows.map((row, idx) => /* @__PURE__ */ jsxs(Panel, { children: [
52
+ /* @__PURE__ */ jsxs(PanelTitle, { children: [
53
+ /* @__PURE__ */ jsxs(Stack, { className: "r-stack-align-center", children: [
54
+ /* @__PURE__ */ jsx(Handle, { className: "r-handle" }),
55
+ "Row #",
56
+ idx + 1
57
+ ] }),
58
+ /* @__PURE__ */ jsx(
59
+ Button,
60
+ {
61
+ variant: "secondary",
62
+ onClick: () => removeRow(state.rows, row),
63
+ children: /* @__PURE__ */ jsx(Delete, {})
64
+ }
65
+ )
66
+ ] }),
67
+ /* @__PURE__ */ jsx(PanelContent, { children: /* @__PURE__ */ jsx(
68
+ ColumnBuilder,
69
+ {
70
+ value: row,
71
+ onChange: (row2) => updateRow(state.rows, row2)
72
+ }
73
+ ) })
74
+ ] }, row.id))
75
+ }
76
+ ),
77
+ /* @__PURE__ */ jsx(Toolbar, { children: /* @__PURE__ */ jsx(
78
+ Button,
79
+ {
80
+ variant: "secondary",
81
+ onClick: () => addRow(state.rows, Factories.row()),
82
+ children: "Add row"
83
+ }
84
+ ) })
85
+ ] });
86
+ };
87
+ var RowBuilder_default = RowBuilder;
88
+
89
+ export { RowBuilder_default as default };
@@ -0,0 +1,6 @@
1
+ import '../chunk-ORMEWXMH.js';
2
+ import React from 'react';
3
+
4
+ var WidgetContext_default = React.createContext();
5
+
6
+ export { WidgetContext_default as default };
@@ -0,0 +1,127 @@
1
+ import { __objRest, __spreadProps, __spreadValues } from '../chunk-ORMEWXMH.js';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import { cn } from '@raketa-builder/ui';
4
+
5
+ function filterStyle(props) {
6
+ const value = props.invert ? 1 : 0;
7
+ return { filter: `invert(${value})` };
8
+ }
9
+ function Edit(_a) {
10
+ var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
11
+ return /* @__PURE__ */ jsx(
12
+ "svg",
13
+ __spreadProps(__spreadValues({
14
+ className: cn(
15
+ "r-reset",
16
+ "r-menu-icon",
17
+ "feather",
18
+ "feather-edit-2",
19
+ className
20
+ ),
21
+ style: filterStyle(rest),
22
+ xmlns: "http://www.w3.org/2000/svg",
23
+ width: "24",
24
+ height: "24",
25
+ viewBox: "0 0 24 24",
26
+ fill: "none",
27
+ stroke: "#000",
28
+ strokeWidth: "2",
29
+ strokeLinecap: "round",
30
+ strokeLinejoin: "round"
31
+ }, rest), {
32
+ children: /* @__PURE__ */ jsx("path", { d: "M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z" })
33
+ })
34
+ );
35
+ }
36
+ function Delete(_c) {
37
+ var _d = _c, { className } = _d, rest = __objRest(_d, ["className"]);
38
+ return /* @__PURE__ */ jsxs(
39
+ "svg",
40
+ __spreadProps(__spreadValues({
41
+ className: cn(
42
+ "r-reset",
43
+ "r-menu-icon",
44
+ "feather",
45
+ "feather-trash",
46
+ className
47
+ ),
48
+ style: filterStyle(rest),
49
+ xmlns: "http://www.w3.org/2000/svg",
50
+ width: "24",
51
+ height: "24",
52
+ viewBox: "0 0 24 24",
53
+ fill: "none",
54
+ stroke: "#000",
55
+ strokeWidth: "2",
56
+ strokeLinecap: "round",
57
+ strokeLinejoin: "round"
58
+ }, rest), {
59
+ children: [
60
+ /* @__PURE__ */ jsx("polyline", { points: "3 6 5 6 21 6" }),
61
+ /* @__PURE__ */ 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" })
62
+ ]
63
+ })
64
+ );
65
+ }
66
+ function Plus(_e) {
67
+ var _f = _e, { className } = _f, rest = __objRest(_f, ["className"]);
68
+ return /* @__PURE__ */ jsxs(
69
+ "svg",
70
+ __spreadProps(__spreadValues({
71
+ className: cn(
72
+ "r-reset",
73
+ "r-menu-icon",
74
+ "feather",
75
+ "feather-plus",
76
+ className
77
+ ),
78
+ style: filterStyle(rest),
79
+ xmlns: "http://www.w3.org/2000/svg",
80
+ width: "24",
81
+ height: "24",
82
+ viewBox: "0 0 24 24",
83
+ fill: "none",
84
+ stroke: "#000",
85
+ strokeWidth: "2",
86
+ strokeLinecap: "round",
87
+ strokeLinejoin: "round"
88
+ }, rest), {
89
+ children: [
90
+ /* @__PURE__ */ jsx("line", { x1: "12", y1: "5", x2: "12", y2: "19" }),
91
+ /* @__PURE__ */ jsx("line", { x1: "5", y1: "12", x2: "19", y2: "12" })
92
+ ]
93
+ })
94
+ );
95
+ }
96
+ function Copy(_g) {
97
+ var _h = _g, { className } = _h, rest = __objRest(_h, ["className"]);
98
+ return /* @__PURE__ */ jsxs(
99
+ "svg",
100
+ __spreadProps(__spreadValues({
101
+ className: cn(
102
+ "r-reset",
103
+ "r-menu-icon",
104
+ "feather",
105
+ "feather-copy",
106
+ className
107
+ ),
108
+ style: filterStyle(rest),
109
+ xmlns: "http://www.w3.org/2000/svg",
110
+ width: "24",
111
+ height: "24",
112
+ viewBox: "0 0 24 24",
113
+ fill: "none",
114
+ stroke: "#000",
115
+ strokeWidth: "2",
116
+ strokeLinecap: "round",
117
+ strokeLinejoin: "round"
118
+ }, rest), {
119
+ children: [
120
+ /* @__PURE__ */ jsx("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
121
+ /* @__PURE__ */ jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
122
+ ]
123
+ })
124
+ );
125
+ }
126
+
127
+ export { Copy, Delete, Edit, Plus };
@@ -0,0 +1,80 @@
1
+ import { __spreadProps, __spreadValues } from '../chunk-ORMEWXMH.js';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import React from 'react';
4
+ import WidgetContext from './WidgetContext';
5
+ import MainNavigation from './MainNavigation';
6
+ import ItemForm from './ItemForm';
7
+ import RowBuilder from './RowBuilder';
8
+ import { remove, update, append, rand } from './utils';
9
+ import { H } from '@raketa-builder/ui';
10
+
11
+ const MenuBuilder = ({ widgets, value, onChange }) => {
12
+ const [state, setState] = React.useState(value);
13
+ const currentTab = state.tab;
14
+ const currentItem = state.items ? state.items[currentTab] : null;
15
+ const removeItem = (items, item) => {
16
+ if (!confirm("Are you sure?")) return;
17
+ const newState = __spreadProps(__spreadValues({}, state), {
18
+ tab: 0,
19
+ items: remove(items, item)
20
+ });
21
+ setState(newState);
22
+ if (onChange) onChange(newState);
23
+ };
24
+ const updateItem = (items, item) => {
25
+ const newState = __spreadProps(__spreadValues({}, state), {
26
+ items: update(items, item)
27
+ });
28
+ setState(newState);
29
+ if (onChange) onChange(newState);
30
+ };
31
+ const duplicateItem = (items, item) => {
32
+ const newState = __spreadProps(__spreadValues({}, state), {
33
+ items: append(items, __spreadProps(__spreadValues({}, item), {
34
+ id: rand(),
35
+ label: `${item.label} (copy)`
36
+ }))
37
+ });
38
+ setState(newState);
39
+ if (onChange) onChange(newState);
40
+ };
41
+ return /* @__PURE__ */ jsxs(WidgetContext.Provider, { value: widgets, children: [
42
+ /* @__PURE__ */ jsx(
43
+ MainNavigation,
44
+ {
45
+ items: state.items,
46
+ tab: currentTab,
47
+ onTab: (tab) => setState(__spreadProps(__spreadValues({}, state), { tab })),
48
+ onChange: (items) => {
49
+ const newState = __spreadProps(__spreadValues({}, state), { items });
50
+ setState(newState);
51
+ if (onChange) onChange(newState);
52
+ }
53
+ }
54
+ ),
55
+ currentItem && /* @__PURE__ */ jsxs("div", { children: [
56
+ /* @__PURE__ */ jsx(
57
+ ItemForm,
58
+ {
59
+ item: currentItem,
60
+ onChange: (item) => {
61
+ updateItem(state.items, __spreadValues(__spreadValues({}, currentItem), item));
62
+ },
63
+ onRemove: () => removeItem(state.items, currentItem),
64
+ onDuplicate: () => duplicateItem(state.items, currentItem)
65
+ }
66
+ ),
67
+ /* @__PURE__ */ jsx(H, { as: "h4", size: "large", children: "Menu content" }),
68
+ /* @__PURE__ */ jsx(
69
+ RowBuilder,
70
+ {
71
+ value: currentItem,
72
+ onChange: (item) => updateItem(state.items, __spreadValues(__spreadValues({}, currentItem), item))
73
+ }
74
+ )
75
+ ] })
76
+ ] });
77
+ };
78
+ var MenuBuilder_default = MenuBuilder;
79
+
80
+ export { MenuBuilder_default as default };
@@ -0,0 +1,14 @@
1
+ import '../chunk-ORMEWXMH.js';
2
+
3
+ const rand = (length) => Math.random().toString(36).substring(length);
4
+ const remove = (items, item) => {
5
+ const idx = items.findIndex((i) => i.id === item.id);
6
+ return [...items.slice(0, idx), ...items.slice(idx + 1)];
7
+ };
8
+ const update = (items, item) => {
9
+ const idx = items.findIndex((i) => i.id === item.id);
10
+ return [...items.slice(0, idx), item, ...items.slice(idx + 1)];
11
+ };
12
+ const append = (items, item) => [...items, item];
13
+
14
+ export { append, rand, remove, update };
@@ -0,0 +1,33 @@
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
+
33
+ export { __objRest, __spreadProps, __spreadValues };
package/dist/index.js CHANGED
@@ -1,14 +1,2 @@
1
- 'use strict';
2
-
3
- var MenuBuilder = require('./MenuBuilder');
4
-
5
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
-
7
- var MenuBuilder__default = /*#__PURE__*/_interopDefault(MenuBuilder);
8
-
9
-
10
-
11
- Object.defineProperty(exports, "MenuBuilder", {
12
- enumerable: true,
13
- get: function () { return MenuBuilder__default.default; }
14
- });
1
+ import './chunk-ORMEWXMH.js';
2
+ export { default as MenuBuilder } from './MenuBuilder';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-builder/menu-builder",
3
- "version": "1.3.9",
3
+ "version": "1.3.10",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -19,8 +19,8 @@
19
19
  ],
20
20
  "license": "MIT",
21
21
  "scripts": {
22
- "build": "tsup src/index.js --format cjs --loader \".js=jsx\"",
23
- "dev": "tsup src/index.js --format cjs --loader \".js=jsx\" --watch",
22
+ "build": "tsup",
23
+ "dev": "tsup --watch",
24
24
  "format": "prettier --write .",
25
25
  "lint": "biome lint --max-diagnostics=5000 ."
26
26
  },
@@ -29,8 +29,8 @@
29
29
  "react-dom": "19.1.0"
30
30
  },
31
31
  "dependencies": {
32
- "@raketa-builder/builder": "1.3.9",
33
- "@raketa-builder/ui": "1.3.9",
32
+ "@raketa-builder/builder": "1.3.10",
33
+ "@raketa-builder/ui": "1.3.10",
34
34
  "react-sortablejs": "6.1.4"
35
35
  },
36
36
  "devDependencies": {