|
1 | 1 | import Sortable from "sortablejs";
|
2 | 2 | import { insertNodeAt, removeNode } from "./util/htmlHelper";
|
3 | 3 | import { console } from "./util/console";
|
4 |
| -import { isHtmlTag, isTransition as isTransitionName } from "./util/tags"; |
| 4 | +import { isTransition as isTransitionName } from "./util/tags"; |
5 | 5 | import {
|
6 | 6 | getComponentAttributes,
|
7 | 7 | createSortableOption,
|
8 | 8 | getValidSortableEntries
|
9 | 9 | } from "./core/componentBuilderHelper";
|
| 10 | +import { computeRenderContext } from "./core/renderHelper"; |
10 | 11 | import { h, defineComponent, nextTick, resolveComponent } from "vue";
|
11 | 12 |
|
12 | 13 | function computeVmIndex(vNodes, element) {
|
@@ -60,29 +61,7 @@ function isTransition(slots) {
|
60 | 61 | return !!type && (isTransitionName(type) || isTransitionName(type.name));
|
61 | 62 | }
|
62 | 63 |
|
63 |
| -function getSlot(slot, key) { |
64 |
| - const slotValue = slot[key]; |
65 |
| - return slotValue ? slotValue() : undefined; |
66 |
| -} |
67 |
| - |
68 |
| -function computeChildrenAndOffsets(defaultNodes, slot) { |
69 |
| - let children = [...defaultNodes]; |
70 |
| - let headerOffset = 0; |
71 |
| - let footerOffset = 0; |
72 |
| - const header = getSlot(slot, "header"); |
73 |
| - if (header) { |
74 |
| - headerOffset = header.length; |
75 |
| - children = [...header, ...children]; |
76 |
| - } |
77 |
| - const footer = getSlot(slot, "footer"); |
78 |
| - if (footer) { |
79 |
| - footerOffset = footer.length; |
80 |
| - children = [...children, ...footer]; |
81 |
| - } |
82 |
| - return { children, headerOffset, footerOffset }; |
83 |
| -} |
84 |
| - |
85 |
| -var draggingElement = null; |
| 64 | +let draggingElement = null; |
86 | 65 |
|
87 | 66 | const props = {
|
88 | 67 | list: {
|
@@ -132,19 +111,14 @@ const draggableComponent = defineComponent({
|
132 | 111 |
|
133 | 112 | render() {
|
134 | 113 | const { $slots, $attrs, tag, componentData } = this;
|
135 |
| - const defaultSlots = getSlot($slots, "default") || []; |
136 |
| - this.transitionMode = isTransition(defaultSlots); |
137 |
| - const { children, headerOffset, footerOffset } = computeChildrenAndOffsets( |
138 |
| - defaultSlots, |
139 |
| - $slots |
140 |
| - ); |
141 |
| - this.headerOffset = headerOffset; |
142 |
| - this.footerOffset = footerOffset; |
143 |
| - this.defaultSlots = defaultSlots; |
| 114 | + const renderContext = computeRenderContext({ $slots, tag }); |
| 115 | + this.transitionMode = isTransition(renderContext.nodes.default); |
| 116 | + this.headerOffset = renderContext.offsets.header; |
| 117 | + this.footerOffset = renderContext.offsets.footer; |
| 118 | + this.defaultSlots = renderContext.nodes.default; |
144 | 119 | const attributes = getComponentAttributes({ $attrs, componentData });
|
145 |
| - const realRoot = |
146 |
| - isHtmlTag(tag) || isTransitionName(tag) ? tag : resolveComponent(tag); |
147 |
| - const mainNode = h(realRoot, attributes, children); |
| 120 | + |
| 121 | + const mainNode = h(renderContext.tag, attributes, renderContext.children); |
148 | 122 | this.mainNode = mainNode;
|
149 | 123 | return mainNode;
|
150 | 124 | },
|
@@ -269,8 +243,8 @@ const draggableComponent = defineComponent({
|
269 | 243 | });
|
270 | 244 | },
|
271 | 245 |
|
272 |
| - getUnderlyingVm(htmlElt) { |
273 |
| - const index = computeVmIndex(this.getChildrenNodes() || [], htmlElt); |
| 246 | + getUnderlyingVm(htmlElement) { |
| 247 | + const index = computeVmIndex(this.getChildrenNodes(), htmlElement); |
274 | 248 | if (index === -1) {
|
275 | 249 | //Edge case during move callback: related element might be
|
276 | 250 | //an element different from collection
|
|
0 commit comments