@bimdata/design-system 2.1.0-rc.15 → 2.1.0-rc.17
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
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="bimdata-tree"
|
|
4
|
+
@mousedown="onTreeMouseDown"
|
|
5
|
+
@mouseenter="onMouseEnter"
|
|
6
|
+
@mouseleave="onMouseLeave"
|
|
7
|
+
@mouseup.self="onMouseUp"
|
|
8
|
+
>
|
|
9
|
+
<div class="bimdata-tree__nodes" @mouseleave="onNodesMouseLeave">
|
|
10
|
+
<Node v-for="node of data" :key="node.id" :node="node">
|
|
11
|
+
<slot
|
|
12
|
+
name="node"
|
|
13
|
+
:node="node"
|
|
14
|
+
:depth="0"
|
|
15
|
+
:selected="node.id === state.selectedId"
|
|
16
|
+
:hovered="node.id === state.hoveredNode?.id"
|
|
17
|
+
:ancestor-selected="state.hasAncestorSelected(node)"
|
|
18
|
+
/>
|
|
19
|
+
</Node>
|
|
20
|
+
</div>
|
|
21
|
+
<div v-if="dropHelperDisplayed" class="bimdata-tree__drop-helper"></div>
|
|
22
|
+
</div>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script>
|
|
26
|
+
import { provide, computed, ref } from "vue";
|
|
27
|
+
|
|
28
|
+
import Node from "./Node.vue";
|
|
29
|
+
|
|
30
|
+
import useState from "./state.js";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @typedef { Object } Node
|
|
34
|
+
* @property { number } id
|
|
35
|
+
* @property { Array } [children=null]
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
export default {
|
|
39
|
+
components: {
|
|
40
|
+
Node,
|
|
41
|
+
},
|
|
42
|
+
provide() {
|
|
43
|
+
return {
|
|
44
|
+
root: this,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
props: {
|
|
48
|
+
/**
|
|
49
|
+
* @type { NodeData }
|
|
50
|
+
*/
|
|
51
|
+
data: {
|
|
52
|
+
type: Array,
|
|
53
|
+
required: true,
|
|
54
|
+
validator: value => {
|
|
55
|
+
if (!Array.isArray(value)) return false;
|
|
56
|
+
|
|
57
|
+
const ids = new Set();
|
|
58
|
+
|
|
59
|
+
for (const node of value) {
|
|
60
|
+
if (!Number.isFinite(node?.id)) return false;
|
|
61
|
+
if (node.children && !Array.isArray(node.children)) return false;
|
|
62
|
+
ids.add(node.id);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return ids.size === value.length;
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
selectedId: {
|
|
69
|
+
type: Number,
|
|
70
|
+
default: null,
|
|
71
|
+
},
|
|
72
|
+
highlightedId: {
|
|
73
|
+
type: Number,
|
|
74
|
+
default: null,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
emits: ["drop", "click", "hover"],
|
|
78
|
+
setup(props, { emit }) {
|
|
79
|
+
const state = useState(props, emit);
|
|
80
|
+
|
|
81
|
+
provide("state", state);
|
|
82
|
+
|
|
83
|
+
const onNodesMouseLeave = () => state.onNodesMouseLeave();
|
|
84
|
+
const onTreeMouseDown = () => state.onTreeMouseDown();
|
|
85
|
+
|
|
86
|
+
const hover = ref(false);
|
|
87
|
+
const onMouseEnter = () => {
|
|
88
|
+
hover.value = true;
|
|
89
|
+
};
|
|
90
|
+
const onMouseLeave = () => {
|
|
91
|
+
hover.value = false;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const onMouseUp = () => state.onTreeMouseUp();
|
|
95
|
+
|
|
96
|
+
const dropHelperDisplayed = computed(
|
|
97
|
+
() =>
|
|
98
|
+
hover.value && state.dragPosition !== null && state.hoveredNode === null
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
state,
|
|
103
|
+
dropHelperDisplayed,
|
|
104
|
+
onMouseEnter,
|
|
105
|
+
onMouseLeave,
|
|
106
|
+
onNodesMouseLeave,
|
|
107
|
+
onTreeMouseDown,
|
|
108
|
+
onMouseUp,
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
</script>
|
|
113
|
+
|
|
114
|
+
<style scoped lang="scss">
|
|
115
|
+
.bimdata-tree {
|
|
116
|
+
height: 100%;
|
|
117
|
+
|
|
118
|
+
&__drop-helper {
|
|
119
|
+
height: 2px;
|
|
120
|
+
background-color: var(--color-primary);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
</style>
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
ref="nodeRef"
|
|
4
|
+
class="bimdata-tree__node"
|
|
5
|
+
:class="{
|
|
6
|
+
'bimdata-tree__node--selected': node.id === state.selectedId,
|
|
7
|
+
'bimdata-tree__node--ancestor-selected': hasAncestorSelected(node),
|
|
8
|
+
'bimdata-tree__node--highlighted': node.id === state.highlightedId,
|
|
9
|
+
}"
|
|
10
|
+
@mouseenter="onMouseEnter"
|
|
11
|
+
@mousedown="onMouseDown"
|
|
12
|
+
@mousemove="onMouseMove"
|
|
13
|
+
@mouseup="onMouseUp"
|
|
14
|
+
>
|
|
15
|
+
<div
|
|
16
|
+
v-if="dropHelperPosition === 'top' || dropHelperPosition === 'bottom'"
|
|
17
|
+
class="bimdata-tree__node__drop-helper"
|
|
18
|
+
:style="`--drop-helper-top: ${
|
|
19
|
+
dropHelperPosition === 'top' ? '0px' : '30px'
|
|
20
|
+
};`"
|
|
21
|
+
></div>
|
|
22
|
+
<div
|
|
23
|
+
class="bimdata-tree__node__content"
|
|
24
|
+
:style="`padding-left: calc(var(--spacing-unit) * 2 * ${depth});`"
|
|
25
|
+
>
|
|
26
|
+
<div class="bimdata-tree__node__content__arrow" @mousedown.stop>
|
|
27
|
+
<div
|
|
28
|
+
v-if="node.children?.length > 0"
|
|
29
|
+
class="bimdata-tree__node__content__arrow__content"
|
|
30
|
+
@click="expanded = !expanded"
|
|
31
|
+
>
|
|
32
|
+
<BIMDataIcon name="chevron" size="xxxs" :rotate="expanded ? 90 : 0" />
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<div class="bimdata-tree__node__content__element">
|
|
37
|
+
<slot>
|
|
38
|
+
{{ node.label }}
|
|
39
|
+
</slot>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
<NodeChildren
|
|
44
|
+
v-if="node.children?.length > 0 && expanded"
|
|
45
|
+
:node="node"
|
|
46
|
+
:depth="depth + 1"
|
|
47
|
+
/>
|
|
48
|
+
</template>
|
|
49
|
+
|
|
50
|
+
<script>
|
|
51
|
+
import { inject, ref, computed, watch, isRef, h } from "vue";
|
|
52
|
+
|
|
53
|
+
const NodeChildren = {
|
|
54
|
+
inject: ["root"],
|
|
55
|
+
props: {
|
|
56
|
+
node: {
|
|
57
|
+
type: Object,
|
|
58
|
+
required: true,
|
|
59
|
+
validator: node => Number.isFinite(node?.id),
|
|
60
|
+
},
|
|
61
|
+
depth: {
|
|
62
|
+
type: Number,
|
|
63
|
+
default: 0,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
render() {
|
|
67
|
+
const { node, depth, root } = this;
|
|
68
|
+
|
|
69
|
+
const state = root.state;
|
|
70
|
+
|
|
71
|
+
return node.children.map(child =>
|
|
72
|
+
h(Node, { node: child, depth, key: child.id }, () =>
|
|
73
|
+
root.$slots.node?.({
|
|
74
|
+
node: child,
|
|
75
|
+
depth,
|
|
76
|
+
selected: child.id === state.selectedId,
|
|
77
|
+
hovered: child.id === state.hoveredNode?.id,
|
|
78
|
+
ancestorSelected: state.hasAncestorSelected(child),
|
|
79
|
+
})
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export default {
|
|
86
|
+
name: "Node",
|
|
87
|
+
components: {
|
|
88
|
+
NodeChildren,
|
|
89
|
+
},
|
|
90
|
+
inject: ["root"],
|
|
91
|
+
props: {
|
|
92
|
+
node: {
|
|
93
|
+
type: Object,
|
|
94
|
+
required: true,
|
|
95
|
+
},
|
|
96
|
+
depth: {
|
|
97
|
+
type: Number,
|
|
98
|
+
default: 0,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
setup(props) {
|
|
102
|
+
const state = inject("state");
|
|
103
|
+
|
|
104
|
+
let expanded = null;
|
|
105
|
+
if (isRef(props.node.expandedRef)) {
|
|
106
|
+
expanded = props.node.expandedRef;
|
|
107
|
+
} else {
|
|
108
|
+
expanded = ref(false);
|
|
109
|
+
}
|
|
110
|
+
const nodeRef = ref(null);
|
|
111
|
+
|
|
112
|
+
let expandTimer = null;
|
|
113
|
+
|
|
114
|
+
const handleExpandTimer = () => {
|
|
115
|
+
if (
|
|
116
|
+
!props.node.children?.length ||
|
|
117
|
+
!state.dragPosition ||
|
|
118
|
+
state.hoveredNode?.id !== props.node.id ||
|
|
119
|
+
expanded.value
|
|
120
|
+
) {
|
|
121
|
+
clearTimeout(expandTimer);
|
|
122
|
+
expandTimer = null;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const position = state.getNodeDropPosition(props.node, nodeRef.value);
|
|
127
|
+
|
|
128
|
+
if (position !== "center" && position !== "bottom") {
|
|
129
|
+
clearTimeout(expandTimer);
|
|
130
|
+
expandTimer = null;
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (expandTimer !== null) return;
|
|
135
|
+
|
|
136
|
+
expandTimer = setTimeout(() => {
|
|
137
|
+
expanded.value = true;
|
|
138
|
+
expandTimer = null;
|
|
139
|
+
}, 500);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
watch(() => state.dragPosition && state.hoveredNode, handleExpandTimer);
|
|
143
|
+
|
|
144
|
+
const onMouseEnter = () => state.onNodeMouseEnter(props.node);
|
|
145
|
+
|
|
146
|
+
const onMouseDown = mouseEvent =>
|
|
147
|
+
state.onNodeMouseDown(props.node, mouseEvent);
|
|
148
|
+
|
|
149
|
+
const onMouseMove = mouseEvent => {
|
|
150
|
+
state.onNodeMouseMove(mouseEvent);
|
|
151
|
+
handleExpandTimer();
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const dropHelperPosition = computed(() => {
|
|
155
|
+
if (!state.dragPosition || state.hoveredNode?.id !== props.node.id)
|
|
156
|
+
return null;
|
|
157
|
+
|
|
158
|
+
return state.getNodeDropPosition(props.node, nodeRef.value);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const onMouseUp = () =>
|
|
162
|
+
state.onNodeMouseUp(props.node, nodeRef.value, expanded.value);
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
state,
|
|
166
|
+
nodeRef,
|
|
167
|
+
expanded,
|
|
168
|
+
dropHelperPosition,
|
|
169
|
+
hasAncestorSelected: state.hasAncestorSelected,
|
|
170
|
+
onMouseEnter,
|
|
171
|
+
onMouseDown,
|
|
172
|
+
onMouseMove,
|
|
173
|
+
onMouseUp,
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
</script>
|
|
178
|
+
|
|
179
|
+
<style scoped lang="scss">
|
|
180
|
+
.bimdata-tree__node {
|
|
181
|
+
height: 32px;
|
|
182
|
+
display: flex;
|
|
183
|
+
align-items: center;
|
|
184
|
+
position: relative;
|
|
185
|
+
|
|
186
|
+
user-select: none;
|
|
187
|
+
|
|
188
|
+
&__drop-helper {
|
|
189
|
+
position: absolute;
|
|
190
|
+
left: 0px;
|
|
191
|
+
right: 0px;
|
|
192
|
+
height: 2px;
|
|
193
|
+
top: var(--drop-helper-top);
|
|
194
|
+
background-color: var(--color-primary);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
&--selected {
|
|
198
|
+
background-color: var(--color-secondary-light);
|
|
199
|
+
}
|
|
200
|
+
&--ancestor-selected {
|
|
201
|
+
background-color: var(--color-secondary-lighter);
|
|
202
|
+
}
|
|
203
|
+
&--highlighted {
|
|
204
|
+
outline-offset: -1px;
|
|
205
|
+
outline: solid var(--color-primary) 1px;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
&__content {
|
|
209
|
+
width: 100%;
|
|
210
|
+
height: 100%;
|
|
211
|
+
display: flex;
|
|
212
|
+
border-radius: 6px;
|
|
213
|
+
padding: 0 calc(var(--spacing-unit) / 2);
|
|
214
|
+
|
|
215
|
+
&__arrow {
|
|
216
|
+
width: 18px;
|
|
217
|
+
flex-shrink: 0;
|
|
218
|
+
|
|
219
|
+
&__content {
|
|
220
|
+
cursor: pointer;
|
|
221
|
+
height: 100%;
|
|
222
|
+
display: flex;
|
|
223
|
+
justify-content: center;
|
|
224
|
+
align-items: center;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
&__element {
|
|
229
|
+
padding-left: calc(var(--spacing-unit) / 2);
|
|
230
|
+
width: calc(100% - 18px);
|
|
231
|
+
height: 100%;
|
|
232
|
+
display: flex;
|
|
233
|
+
align-items: center;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
</style>
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { shallowReactive, watch, shallowRef } from "vue";
|
|
2
|
+
|
|
3
|
+
export default function useState(props, emit) {
|
|
4
|
+
const state = shallowReactive({
|
|
5
|
+
selectedId: null,
|
|
6
|
+
highlightedId: null,
|
|
7
|
+
hoveredNode: null,
|
|
8
|
+
trees: props.data,
|
|
9
|
+
dragPosition: null,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
watch(
|
|
13
|
+
() => props.selectedId,
|
|
14
|
+
() => {
|
|
15
|
+
state.selectedId = props.selectedId ?? null;
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
watch(
|
|
20
|
+
() => props.highlightedId,
|
|
21
|
+
() => {
|
|
22
|
+
state.highlightedId = props.highlightedId ?? null;
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
watch(
|
|
27
|
+
() => state.hoveredNode,
|
|
28
|
+
() => emit("hover", state.hoveredNode)
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const pressedNode = shallowRef(null);
|
|
32
|
+
|
|
33
|
+
watch(
|
|
34
|
+
() => props.data,
|
|
35
|
+
trees => {
|
|
36
|
+
state.trees = trees;
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const onMouseUp = () => {
|
|
41
|
+
pressedNode.value = null;
|
|
42
|
+
state.dragPosition = null;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const onNodeMouseEnter = node => {
|
|
46
|
+
state.hoveredNode = node;
|
|
47
|
+
};
|
|
48
|
+
const onNodeMouseDown = (node, event) => {
|
|
49
|
+
event.stopPropagation();
|
|
50
|
+
|
|
51
|
+
emit("click", node);
|
|
52
|
+
|
|
53
|
+
pressedNode.value = node;
|
|
54
|
+
|
|
55
|
+
window.addEventListener("mouseup", onMouseUp, { once: true });
|
|
56
|
+
};
|
|
57
|
+
const onNodeMouseMove = event => {
|
|
58
|
+
if (!pressedNode.value) return;
|
|
59
|
+
|
|
60
|
+
const { clientX, clientY } = event;
|
|
61
|
+
|
|
62
|
+
state.dragPosition = { x: clientX, y: clientY };
|
|
63
|
+
};
|
|
64
|
+
const onNodeMouseUp = (node, domElement, expanded) => {
|
|
65
|
+
if (!state.dragPosition) return;
|
|
66
|
+
|
|
67
|
+
if (state.hoveredNode?.id === pressedNode.value?.id) return;
|
|
68
|
+
|
|
69
|
+
if (state.isDescendant(node, pressedNode.value)) return;
|
|
70
|
+
|
|
71
|
+
const position = getNodeDropPosition(node, domElement);
|
|
72
|
+
|
|
73
|
+
let parent = null;
|
|
74
|
+
let index = null;
|
|
75
|
+
const previousParent = getParent(pressedNode.value);
|
|
76
|
+
|
|
77
|
+
switch (position) {
|
|
78
|
+
case "top":
|
|
79
|
+
parent = getParent(node);
|
|
80
|
+
index = (parent?.children ?? state.trees).findIndex(
|
|
81
|
+
child => child.id === node.id
|
|
82
|
+
);
|
|
83
|
+
break;
|
|
84
|
+
case "bottom":
|
|
85
|
+
if (node.children && expanded) {
|
|
86
|
+
parent = node;
|
|
87
|
+
index = 0;
|
|
88
|
+
} else {
|
|
89
|
+
parent = getParent(node);
|
|
90
|
+
index =
|
|
91
|
+
(parent?.children ?? state.trees).findIndex(
|
|
92
|
+
child => child.id === node.id
|
|
93
|
+
) + 1;
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
case "center":
|
|
97
|
+
parent = node;
|
|
98
|
+
index = 0;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const reorder = parent?.id === previousParent?.id;
|
|
103
|
+
const previousIndex = (previousParent?.children ?? state.trees).findIndex(
|
|
104
|
+
child => child.id === pressedNode.value.id
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
if (
|
|
108
|
+
reorder &&
|
|
109
|
+
(position === "top" || position === "bottom") &&
|
|
110
|
+
previousIndex < index
|
|
111
|
+
) {
|
|
112
|
+
index--;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (reorder && index === previousIndex) return;
|
|
116
|
+
|
|
117
|
+
emit("drop", {
|
|
118
|
+
node: pressedNode.value,
|
|
119
|
+
previousParent,
|
|
120
|
+
parent,
|
|
121
|
+
index,
|
|
122
|
+
position,
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const onNodesMouseLeave = () => {
|
|
127
|
+
state.hoveredNode = null;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const onTreeMouseDown = () => {
|
|
131
|
+
emit("click", null);
|
|
132
|
+
};
|
|
133
|
+
const onTreeMouseUp = () => {
|
|
134
|
+
if (!state.dragPosition) return;
|
|
135
|
+
|
|
136
|
+
if (state.trees.indexOf(pressedNode.value) === state.trees.length - 1) {
|
|
137
|
+
// to drop the last root node at the end of the list does not fire the drop event
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const nodeIsInRootPosition = state.trees.includes(pressedNode.value);
|
|
142
|
+
|
|
143
|
+
emit("drop", {
|
|
144
|
+
node: pressedNode.value,
|
|
145
|
+
parent: null,
|
|
146
|
+
index: nodeIsInRootPosition ? state.trees.length - 1 : state.trees.length,
|
|
147
|
+
previousParent: getParent(pressedNode.value),
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
state.onNodeMouseEnter = onNodeMouseEnter;
|
|
152
|
+
state.onNodeMouseDown = onNodeMouseDown;
|
|
153
|
+
state.onNodeMouseMove = onNodeMouseMove;
|
|
154
|
+
state.onNodeMouseUp = onNodeMouseUp;
|
|
155
|
+
|
|
156
|
+
state.onNodesMouseLeave = onNodesMouseLeave;
|
|
157
|
+
|
|
158
|
+
state.onTreeMouseDown = onTreeMouseDown;
|
|
159
|
+
state.onTreeMouseUp = onTreeMouseUp;
|
|
160
|
+
|
|
161
|
+
// UTILS
|
|
162
|
+
|
|
163
|
+
const getNodeDropPosition = (node, domElement) => {
|
|
164
|
+
const { y } = state.dragPosition;
|
|
165
|
+
|
|
166
|
+
const { top, height } = domElement.getBoundingClientRect();
|
|
167
|
+
|
|
168
|
+
if (node.children) {
|
|
169
|
+
if (y < top + height / 3) return "top";
|
|
170
|
+
if (y > top + (height * 2) / 3) return "bottom";
|
|
171
|
+
|
|
172
|
+
return "center";
|
|
173
|
+
} else {
|
|
174
|
+
if (y < top + height / 2) return "top";
|
|
175
|
+
|
|
176
|
+
return "bottom";
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const getParent = (node, nodes = state.trees) => {
|
|
181
|
+
for (const childNode of nodes) {
|
|
182
|
+
if (childNode.children?.length) {
|
|
183
|
+
if (childNode.children.some(child => child.id === node.id)) {
|
|
184
|
+
return childNode;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const expectedParent = getParent(node, childNode.children);
|
|
188
|
+
|
|
189
|
+
if (expectedParent) return expectedParent;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const isAncestor = (node, nodes = state.trees) => {
|
|
195
|
+
for (const childNode of nodes) {
|
|
196
|
+
if (childNode.id === node.id) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
if (childNode.children?.length && isAncestor(node, childNode.children)) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const getAncestors = (node, nodes = state.trees) => {
|
|
207
|
+
const ancestors = [];
|
|
208
|
+
for (const childNode of nodes) {
|
|
209
|
+
if (childNode.id === node.id) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (childNode.children?.length && isAncestor(node, childNode.children)) {
|
|
213
|
+
ancestors.push(childNode, ...getAncestors(node, childNode.children));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return ancestors;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const hasAncestorSelected = node => {
|
|
220
|
+
if (state.selectedId === null) return false;
|
|
221
|
+
|
|
222
|
+
return getAncestors(node).some(
|
|
223
|
+
ancestor => ancestor.id === state.selectedId
|
|
224
|
+
);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const isDescendant = (node, ancestor) =>
|
|
228
|
+
ancestor?.children?.some(
|
|
229
|
+
child => child.id === node.id || isDescendant(node, child)
|
|
230
|
+
) ?? false;
|
|
231
|
+
|
|
232
|
+
state.getNodeDropPosition = getNodeDropPosition;
|
|
233
|
+
state.getParent = getParent;
|
|
234
|
+
state.getAncestors = getAncestors;
|
|
235
|
+
state.hasAncestorSelected = hasAncestorSelected;
|
|
236
|
+
state.isDescendant = isDescendant;
|
|
237
|
+
|
|
238
|
+
return state;
|
|
239
|
+
}
|
|
@@ -44,3 +44,4 @@ export { default as BIMDataTextarea } from "./BIMDataTextarea/BIMDataTextarea.vu
|
|
|
44
44
|
export { default as BIMDataTextbox } from "./BIMDataTextbox/BIMDataTextbox.vue";
|
|
45
45
|
export { default as BIMDataToggle } from "./BIMDataToggle/BIMDataToggle.vue";
|
|
46
46
|
export { default as BIMDataTooltip } from "./BIMDataTooltip/BIMDataTooltip.vue";
|
|
47
|
+
export { default as BIMDataTree } from "./BIMDataTree/BIMDataTree.vue";
|