Skip to content

Commit

Permalink
Increase drop zone size for content items
Browse files Browse the repository at this point in the history
  • Loading branch information
sfnelson committed Dec 5, 2023
1 parent 0cede4a commit 97bc919
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/katalyst/content/editor/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ $status-dirty-color: #aaa !default;
}

[data-controller="content--editor--list"] {
min-height: var(--row-height);
min-height: calc(var(--row-height) * 8);

// tree items
& > li {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

.content--editor--new-items {
display: grid;
grid-template-columns: repeat(3, calc((100% - 1rem)/3));
grid-template-columns: repeat(3, calc((100% - 1rem) / 3));
grid-auto-rows: minmax(5rem, auto);
gap: 0.5rem;

Expand Down
14 changes: 12 additions & 2 deletions app/javascript/content/editor/list_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export default class ListController extends Controller {
}

dropTarget(e) {
return e && e.closest("[data-controller='content--editor--list'] > *");
return (
e.closest("[data-controller='content--editor--list'] > *") ||
e.closest("[data-controller='content--editor--list']")
);
}

reindex() {
Expand All @@ -95,12 +98,19 @@ export default class ListController extends Controller {
}

function swap(target, item) {
if (target && target !== item) {
if (!target) return;
if (target === item) return;

if (target.nodeName === "LI") {
const positionComparison = target.compareDocumentPosition(item);
if (positionComparison & Node.DOCUMENT_POSITION_FOLLOWING) {
target.insertAdjacentElement("beforebegin", item);
} else if (positionComparison & Node.DOCUMENT_POSITION_PRECEDING) {
target.insertAdjacentElement("afterend", item);
}
}

if (target.nodeName === "OL") {
target.appendChild(item);
}
}

0 comments on commit 97bc919

Please sign in to comment.