generated from filamentphp/plugin-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use a less generic name for the alpine component to not clash wi…
…th other plugins
- Loading branch information
Showing
4 changed files
with
36 additions
and
34 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,44 @@ | ||
import Sortable from "sortablejs" | ||
|
||
export default ({ | ||
export default function adjacencyList({ | ||
treeId, | ||
statePath, | ||
disabled, | ||
maxDepth | ||
}) => ({ | ||
statePath, | ||
sortable: null, | ||
}) { | ||
return { | ||
statePath, | ||
sortable: null, | ||
|
||
init() { | ||
this.sortable = new Sortable(this.$el, { | ||
disabled, | ||
group: treeId, | ||
animation: 150, | ||
fallbackOnBody: true, | ||
swapThreshold: 0.25, | ||
invertSwap: true, | ||
draggable: "[data-sortable-item]", | ||
handle: "[data-sortable-handle]", | ||
onMove: (evt) => { | ||
if (maxDepth && maxDepth >= 0 && this.getDepth(evt.related) > maxDepth) { | ||
return false; // Prevent dragging items to a depth greater than maxDepth | ||
init() { | ||
this.sortable = new Sortable(this.$el, { | ||
disabled, | ||
group: treeId, | ||
animation: 150, | ||
fallbackOnBody: true, | ||
swapThreshold: 0.25, | ||
invertSwap: true, | ||
draggable: "[data-sortable-item]", | ||
handle: "[data-sortable-handle]", | ||
onMove: (evt) => { | ||
if (maxDepth && maxDepth >= 0 && this.getDepth(evt.related) > maxDepth) { | ||
return false; // Prevent dragging items to a depth greater than maxDepth | ||
} | ||
}, | ||
onSort: () => { | ||
this.$wire.dispatchFormEvent('builder::sort', this.statePath, this.sortable.toArray()) | ||
} | ||
}, | ||
onSort: () => { | ||
this.$wire.dispatchFormEvent('builder::sort', this.statePath, this.sortable.toArray()) | ||
} | ||
}) | ||
}, | ||
}) | ||
}, | ||
|
||
getDepth(el, depth = 0) { | ||
const parentElement = el.parentElement.closest('[data-sortable-item]'); | ||
getDepth(el, depth = 0) { | ||
const parentElement = el.parentElement.closest('[data-sortable-item]'); | ||
|
||
if (parentElement) { | ||
return this.getDepth(parentElement, ++depth); | ||
} | ||
if (parentElement) { | ||
return this.getDepth(parentElement, ++depth); | ||
} | ||
|
||
return depth; | ||
}, | ||
}) | ||
return depth; | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters