@raketa-builder/menu-builder 1.3.8 → 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.
package/package.json CHANGED
@@ -1,12 +1,26 @@
1
1
  {
2
2
  "name": "@raketa-builder/menu-builder",
3
- "version": "1.3.8",
3
+ "version": "1.3.10",
4
+ "type": "module",
4
5
  "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
5
7
  "types": "./dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./*": {
14
+ "import": "./dist/*.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
6
20
  "license": "MIT",
7
21
  "scripts": {
8
- "build": "tsup src/index.js --format cjs --loader \".js=jsx\"",
9
- "dev": "tsup src/index.js --format cjs --loader \".js=jsx\" --watch",
22
+ "build": "tsup",
23
+ "dev": "tsup --watch",
10
24
  "format": "prettier --write .",
11
25
  "lint": "biome lint --max-diagnostics=5000 ."
12
26
  },
@@ -15,8 +29,8 @@
15
29
  "react-dom": "19.1.0"
16
30
  },
17
31
  "dependencies": {
18
- "@raketa-builder/builder": "1.3.8",
19
- "@raketa-builder/ui": "1.3.8",
32
+ "@raketa-builder/builder": "1.3.10",
33
+ "@raketa-builder/ui": "1.3.10",
20
34
  "react-sortablejs": "6.1.4"
21
35
  },
22
36
  "devDependencies": {
package/CHANGELOG.md DELETED
@@ -1,7 +0,0 @@
1
- # @raketa-builder/menu-builder
2
-
3
- ## 0.1.0
4
-
5
- ### Minor Changes
6
-
7
- - First publishing of @raketa-builder/menu-builder
package/biome.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": ["../../biome.json"]
3
- }
@@ -1,30 +0,0 @@
1
- import React from "react";
2
- import { Modal, cn } from "@raketa-builder/ui";
3
- import WidgetContext from "./WidgetContext";
4
-
5
- const WidgetButton = ({ className, ...props }) => (
6
- <div className={cn("r-reset-button r-widget-button", className)} {...props} />
7
- );
8
-
9
- const AddWidget = ({ onAdd, onClose }) => {
10
- return (
11
- <Modal open title="Select widget" onClose={onClose}>
12
- <WidgetContext.Consumer>
13
- {(WIDGETS) => (
14
- <React.Fragment>
15
- {Object.keys(WIDGETS).map((widgetName) => (
16
- <WidgetButton
17
- key={widgetName}
18
- onClick={() => onAdd(widgetName, WIDGETS[widgetName])}
19
- >
20
- {widgetName}
21
- </WidgetButton>
22
- ))}
23
- </React.Fragment>
24
- )}
25
- </WidgetContext.Consumer>
26
- </Modal>
27
- );
28
- };
29
-
30
- export default AddWidget;
@@ -1,69 +0,0 @@
1
- import React from "react";
2
- import { Button } from "@raketa-builder/ui";
3
- import { AdminForm } from "@raketa-builder/builder";
4
-
5
- function checkForChanges(hasChanges, onClose) {
6
- if (!hasChanges) {
7
- onClose();
8
- return;
9
- }
10
-
11
- if (
12
- !confirm(
13
- "You’ve made changes to the widget. Are you sure you want to cancel?"
14
- )
15
- )
16
- return;
17
-
18
- onClose();
19
- }
20
-
21
- const AdminWidget = ({
22
- widget,
23
- settings,
24
- onChange,
25
- handleChanges,
26
- onCancel,
27
- }) => {
28
- const [state, setState] = React.useState(settings);
29
-
30
- const areChanges = JSON.stringify(state) !== JSON.stringify(settings);
31
-
32
- const schema = widget.admin;
33
-
34
- if (typeof schema !== "object") {
35
- console.warn(
36
- `Legacy widget with React admin definition: "${widget.name}". Update to schema defined inputs!`
37
- );
38
- }
39
-
40
- return (
41
- <div>
42
- <AdminForm
43
- schema={schema}
44
- value={state}
45
- onChange={(newState) => {
46
- console.log({ newState });
47
- setState({ ...newState });
48
- handleChanges({ ...newState });
49
- }}
50
- />
51
-
52
- <Button
53
- type="submit"
54
- variant="primary"
55
- onClick={() => onChange({ ...state })}
56
- >
57
- Save
58
- </Button>
59
- <Button
60
- variant="secondary"
61
- onClick={() => checkForChanges(areChanges, onCancel)}
62
- >
63
- Cancel
64
- </Button>
65
- </div>
66
- );
67
- };
68
-
69
- export default AdminWidget;
@@ -1,136 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import { ReactSortable } from "react-sortablejs";
3
- import Factories from "./Factories";
4
- import { append, remove, update, rand } from "./utils";
5
- import { Copy, Delete } from "./icons";
6
- import {
7
- Button,
8
- Toolbar,
9
- Stack,
10
- Handle,
11
- Panel,
12
- PanelTitle,
13
- PanelContent,
14
- cn,
15
- } from "@raketa-builder/ui";
16
- import ContentBuilder from "./ContentBuilder";
17
-
18
- const Wrapper = ({ className, ...props }) => (
19
- <div className={cn("r-reset", className)} {...props} />
20
- );
21
-
22
- const ColumnBuilder = ({ value, onChange }) => {
23
- const [state, setState] = React.useState(value);
24
-
25
- useEffect(() => {
26
- setState(value);
27
- }, [value]);
28
-
29
- const addColumn = (items, item) => {
30
- const newState = {
31
- ...state,
32
- columns: [...items, item],
33
- };
34
-
35
- setState(newState);
36
- onChange(newState);
37
- };
38
-
39
- const updateColumn = (items, item) => {
40
- const newState = {
41
- ...state,
42
- columns: update(items, item),
43
- };
44
-
45
- setState(newState);
46
- onChange(newState);
47
- };
48
-
49
- const duplicateColumn = (items, item) => {
50
- const newState = {
51
- ...state,
52
- columns: append(items, {
53
- ...item,
54
- id: rand(),
55
- label: `${item.label} (copy)`,
56
- }),
57
- };
58
-
59
- setState(newState);
60
- };
61
-
62
- const removeColumn = (items, item) => {
63
- if (!confirm("Are you sure?")) return;
64
-
65
- const newState = {
66
- ...state,
67
- columns: remove(items, item),
68
- };
69
-
70
- setState(newState);
71
- onChange(newState);
72
- };
73
-
74
- const reorder = (columns) => {
75
- const newState = { ...state, columns };
76
-
77
- setState(newState);
78
- onChange(newState);
79
- };
80
-
81
- return (
82
- <Wrapper>
83
- <Toolbar>
84
- <Button
85
- variant="secondary"
86
- onClick={() => addColumn(state.columns, Factories.column())}
87
- >
88
- Add column
89
- </Button>
90
- </Toolbar>
91
-
92
- <ReactSortable
93
- list={state.columns}
94
- setList={(columns) => reorder(columns)}
95
- className="r-list"
96
- handle=".r-chandle"
97
- direction="vertical"
98
- >
99
- {state.columns.map((column, idx) => (
100
- <Panel key={column.id} style={{ flex: 1, marginRight: "0.5em" }}>
101
- <PanelTitle>
102
- <Stack className="r-stack-align-center">
103
- <Handle className="r-chandle" />
104
- Column #{idx + 1}
105
- </Stack>
106
-
107
- <Stack className="r-stack-align-center">
108
- <Button
109
- variant="secondary"
110
- onClick={() => duplicateColumn(state.columns, column)}
111
- >
112
- <Copy />
113
- </Button>
114
- <Button
115
- variant="secondary"
116
- onClick={() => removeColumn(state.columns, column)}
117
- >
118
- <Delete />
119
- </Button>
120
- </Stack>
121
- </PanelTitle>
122
-
123
- <PanelContent>
124
- <ContentBuilder
125
- value={column}
126
- onChange={(column) => updateColumn(state.columns, column)}
127
- />
128
- </PanelContent>
129
- </Panel>
130
- ))}
131
- </ReactSortable>
132
- </Wrapper>
133
- );
134
- };
135
-
136
- export default ColumnBuilder;
@@ -1,164 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import { ReactSortable } from "react-sortablejs";
3
- import WidgetContext from "./WidgetContext";
4
- import Factories from "./Factories";
5
- import AdminWidget from "./AdminWidget";
6
- import AddWidget from "./AddWidget";
7
- import { remove, update } from "./utils";
8
- import { Edit, Delete } from "./icons";
9
- import {
10
- Button,
11
- Stack,
12
- Handle,
13
- Panel,
14
- PanelTitle,
15
- Modal,
16
- } from "@raketa-builder/ui";
17
-
18
- const getWidget = (widgets, name) => widgets[name];
19
- const getTitle = (widgets, widget) => {
20
- const { component } = widget;
21
- const primaryField = getWidget(widgets, component).primaryField;
22
- return primaryField
23
- ? `${component}: ${widget.settings[primaryField]}`
24
- : component;
25
- };
26
-
27
- const ContentBuilder = ({ value, onChange }) => {
28
- const [widget, setWidget] = React.useState({
29
- open: false,
30
- current: null,
31
- });
32
- const [open, setOpen] = React.useState(false);
33
- const [state, setState] = React.useState(value);
34
- const [areChanges, setAreChanges] = React.useState(false);
35
-
36
- useEffect(() => {
37
- setState(value);
38
- }, [value]);
39
-
40
- const addWidget = (items, item) => {
41
- const newState = {
42
- ...state,
43
- widgets: [...items, item],
44
- };
45
-
46
- setOpen(false);
47
- setState(newState);
48
- onChange(newState);
49
- };
50
-
51
- const removeWidget = (items, item) => {
52
- if (!confirm("Are you sure?")) return;
53
-
54
- const newState = {
55
- ...state,
56
- widgets: remove(items, item),
57
- };
58
-
59
- setState(newState);
60
- onChange(newState);
61
- };
62
-
63
- const reorder = (widgets) => {
64
- const newState = { ...state, widgets };
65
-
66
- setState(newState);
67
- onChange(newState);
68
- };
69
-
70
- const closeWidget = () => {
71
- setWidget({ open: false, current: null });
72
- setAreChanges(false);
73
- };
74
-
75
- const updateWidget = (widget, settings) => {
76
- const newState = {
77
- ...state,
78
- widgets: update(state.widgets, { ...widget, settings }),
79
- };
80
-
81
- closeWidget();
82
- setState(newState);
83
- onChange(newState);
84
- };
85
-
86
- const handleChanges = (settings) =>
87
- setAreChanges(widget.current.settings !== settings);
88
-
89
- return (
90
- <WidgetContext.Consumer>
91
- {(WIDGETS) => (
92
- <React.Fragment>
93
- <ReactSortable
94
- list={state.widgets}
95
- setList={(widgets) => reorder(widgets)}
96
- handle=".r-handle"
97
- direction="vertical"
98
- >
99
- {state.widgets.map((widget) => (
100
- <Panel key={widget.id}>
101
- <PanelTitle>
102
- <Stack className="r-stack-align-center">
103
- <Handle className="r-handle" />
104
- {getTitle(WIDGETS, widget)}
105
- </Stack>
106
-
107
- <Stack className="r-stack-align-center">
108
- <Button
109
- variant="secondary"
110
- onClick={() => setWidget({ open: true, current: widget })}
111
- >
112
- <Edit />
113
- </Button>
114
- <Button
115
- variant="secondary"
116
- onClick={() => removeWidget(state.widgets, widget)}
117
- >
118
- <Delete />
119
- </Button>
120
- </Stack>
121
- </PanelTitle>
122
- </Panel>
123
- ))}
124
- </ReactSortable>
125
-
126
- <Button variant="secondary" onClick={() => setOpen(true)}>
127
- Add widget
128
- </Button>
129
-
130
- {widget.open && (
131
- <Modal
132
- title="Settings"
133
- open={widget.open}
134
- areChanges={areChanges}
135
- onClose={closeWidget}
136
- >
137
- <AdminWidget
138
- widget={getWidget(WIDGETS, widget.current.component)}
139
- settings={widget.current.settings}
140
- onChange={(settings) => updateWidget(widget.current, settings)}
141
- handleChanges={handleChanges}
142
- onCancel={closeWidget}
143
- />
144
- </Modal>
145
- )}
146
-
147
- {open && (
148
- <AddWidget
149
- onAdd={(component, widget) =>
150
- addWidget(
151
- state.widgets,
152
- Factories.widget(component, widget.defaults)
153
- )
154
- }
155
- onClose={() => setOpen(false)}
156
- />
157
- )}
158
- </React.Fragment>
159
- )}
160
- </WidgetContext.Consumer>
161
- );
162
- };
163
-
164
- export default ContentBuilder;
@@ -1,114 +0,0 @@
1
- import React from "react";
2
- import { Copy, Delete } from "./icons";
3
- import {
4
- Button,
5
- Toolbar,
6
- FormGroup,
7
- Label,
8
- Input,
9
- Select,
10
- Stack,
11
- } from "@raketa-builder/ui";
12
-
13
- const ItemForm = ({ item, onChange, onRemove, onDuplicate }) => (
14
- <div>
15
- <Stack>
16
- <FormGroup>
17
- <Label htmlFor="label">Label</Label>
18
-
19
- <Input
20
- name="label"
21
- type="text"
22
- wrapperProps={{ style: { marginRight: "0.5em" } }}
23
- value={item.label}
24
- onChange={(e) =>
25
- onChange({
26
- ...item,
27
- label: e.target.value,
28
- })
29
- }
30
- />
31
- </FormGroup>
32
-
33
- <FormGroup>
34
- <Label htmlFor="url">URL</Label>
35
-
36
- <Input
37
- name="url"
38
- type="text"
39
- value={item.url}
40
- onChange={(e) =>
41
- onChange({
42
- ...item,
43
- url: e.target.value,
44
- })
45
- }
46
- />
47
- </FormGroup>
48
-
49
- <FormGroup>
50
- <Label htmlFor="html_id">ID</Label>
51
-
52
- <Input
53
- name="html_id"
54
- type="text"
55
- value={item.html_id}
56
- onChange={(e) =>
57
- onChange({
58
- ...item,
59
- html_id: e.target.value,
60
- })
61
- }
62
- />
63
- </FormGroup>
64
-
65
- <FormGroup>
66
- <Label htmlFor="class_name">CSS class</Label>
67
-
68
- <Input
69
- name="class_name"
70
- type="text"
71
- value={item.class_name}
72
- onChange={(e) =>
73
- onChange({
74
- ...item,
75
- class_name: e.target.value,
76
- })
77
- }
78
- />
79
- </FormGroup>
80
-
81
- <FormGroup>
82
- <Label htmlFor="target">Target</Label>
83
-
84
- <Select
85
- name="target"
86
- value={item.target}
87
- onChange={(e) =>
88
- onChange({
89
- ...item,
90
- target: e.target.value,
91
- })
92
- }
93
- >
94
- <option value="">Please select</option>
95
- <option value="_self">Open in same tab</option>
96
- <option value="_blank">Open in new tab</option>
97
- </Select>
98
- </FormGroup>
99
- </Stack>
100
-
101
- <Toolbar>
102
- <Stack>
103
- <Button variant="secondary" onClick={onDuplicate}>
104
- <Copy />
105
- </Button>
106
- <Button variant="secondary" onClick={onRemove}>
107
- <Delete />
108
- </Button>
109
- </Stack>
110
- </Toolbar>
111
- </div>
112
- );
113
-
114
- export default ItemForm;
@@ -1,58 +0,0 @@
1
- import React from "react";
2
- import { ReactSortable } from "react-sortablejs";
3
- import { append } from "./utils";
4
- import Factories from "./Factories";
5
- import { Button, Stack, Container, cn } from "@raketa-builder/ui";
6
-
7
- const Item = ({ className, ...props }) => (
8
- <div
9
- className={cn(
10
- "r-reset",
11
- "r-main-nav-item",
12
- props.active ? "active" : "",
13
- className
14
- )}
15
- {...props}
16
- />
17
- );
18
-
19
- const TabButton = ({ className, ...props }) => (
20
- <div
21
- className={cn("r-reset-button r-main-nav-tab-button", className)}
22
- {...props}
23
- />
24
- );
25
-
26
- const MainNavigation = ({ items, tab, onTab, onChange }) => (
27
- <Container bottom>
28
- <Stack>
29
- <ReactSortable
30
- list={items}
31
- setList={onChange}
32
- direction="horizontal"
33
- dragoverBubble
34
- >
35
- {items.map((item, idx) => (
36
- <Item key={item.id} active={idx === tab}>
37
- <TabButton
38
- type="button"
39
- active={(idx === tab).toString()}
40
- onClick={() => onTab(idx)}
41
- >
42
- {item.label}
43
- </TabButton>
44
- </Item>
45
- ))}
46
- </ReactSortable>
47
-
48
- <Button
49
- variant="secondary"
50
- onClick={() => onChange(append(items, Factories.item()))}
51
- >
52
- Add item
53
- </Button>
54
- </Stack>
55
- </Container>
56
- );
57
-
58
- export default MainNavigation;