Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #607

Merged
merged 3 commits into from
Sep 1, 2024
Merged

Dev #607

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions packages/evershop/src/components/common/form/fields/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function Editor({
uploadApi,
folderCreateApi
}) {
const [draggable, setDragable] = React.useState(null);
const draggable = React.useRef(null);
const [fileBrowser, setFileBrowser] = React.useState(null);
const [rows, setRows] = React.useState(
value
Expand All @@ -84,10 +84,6 @@ export default function Editor({

React.useEffect(() => {
async function initSwappable() {
if (draggable) {
draggable.destroy();
}

const Swappable = await loadSwappable();
// eslint-disable-next-line new-cap
const swappable = new Swappable(document.querySelectorAll(`div#rows`), {
Expand All @@ -110,7 +106,11 @@ export default function Editor({
}
setRows((originRows) => {
// Swap the source and destination in the rows array
const newRows = [...originRows];
const newRows = originRows.map((r) => {
const newRow = { ...r };
newRow.columns = r.columns.map((c) => ({ ...c }));
return newRow;
});
const sourceIndex = newRows.findIndex((r) => r.id === source);
const destinationIndex = newRows.findIndex(
(r) => r.id === destination
Expand All @@ -121,10 +121,10 @@ export default function Editor({
return newRows;
});
});
setDragable(swappable);
draggable.current = swappable;
}
initSwappable();
}, [rows]);
}, []);

React.useEffect(() => {
const initEditors = async () => {
Expand Down Expand Up @@ -200,16 +200,10 @@ export default function Editor({
}, []);

const removeRow = (rowId) => {
if (draggable) {
draggable.destroy();
}
setRows(rows.filter((i) => i.id !== rowId));
};

const addRow = (row) => {
if (draggable) {
draggable.destroy();
}
setRows(rows.concat(row));
};

Expand Down Expand Up @@ -288,6 +282,7 @@ export default function Editor({
type="hidden"
value={JSON.stringify(
rows.map((row) => ({
id: row.id,
size: row.size,
columns: row.columns.map((column) => ({
id: column.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function BasicMenu({
{item.name}
</a>
{item.children.length > 0 && (
<ul className="md:absolute left-0 top-full mt-0 md:mt-3 w-48 bg-white md:shadow-lg rounded-md md:opacity-0 md:group-hover:opacity-100 md:group-hover:translate-y-0 transform transition-all duration-300 ease-in-out min-w-full md:min-w-[250px] z-30 border-t-4">
<ul className="md:absolute left-0 top-full mt-0 md:mt-3 w-48 bg-white md:shadow-lg rounded-md md:opacity-0 md:group-hover:opacity-100 md:group-hover:translate-y-0 transform transition-all duration-300 ease-in-out min-w-full md:min-w-[250px] z-30 md:border-t-4">
{item.children.map((subItem, subIndex) => (
<li key={subIndex}>
<a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function Logo({
}
}) {
return (
<div className="logo ml-9 md:ml-0 flex justify-center">
<div className="logo md:ml-0 flex justify-center items-center">
{src && (
<a href="/" className="logo-icon">
<img src={src} alt={alt} width={width} height={height} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
.logo {
a.logo-icon {
svg {
width: 3rem;
height: 3rem;
width: 4rem;
height: 4rem;
}
margin-right: 0.5rem;
}
}
Loading