forked from profectus/Profectus
Made TreeNodes VueFeatures
This commit is contained in:
parent
d988b37e8d
commit
5b45642a58
3 changed files with 93 additions and 76 deletions
|
@ -1,37 +1,17 @@
|
||||||
<template>
|
<template>
|
||||||
<span class="row" v-for="(row, index) in unref(nodes)" :key="index" v-bind="$attrs">
|
<component :is="nodesComp" />
|
||||||
<TreeNode
|
<component v-if="leftNodesComp" :is="leftNodesComp" />
|
||||||
v-for="(node, nodeIndex) in row"
|
<component v-if="rightNodesComp" :is="rightNodesComp" />
|
||||||
:key="nodeIndex"
|
|
||||||
v-bind="gatherNodeProps(node)"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
<span class="left-side-nodes" v-if="unref(leftSideNodes)">
|
|
||||||
<TreeNode
|
|
||||||
v-for="(node, nodeIndex) in unref(leftSideNodes)"
|
|
||||||
:key="nodeIndex"
|
|
||||||
v-bind="gatherNodeProps(node)"
|
|
||||||
small
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
<span class="side-nodes" v-if="unref(rightSideNodes)">
|
|
||||||
<TreeNode
|
|
||||||
v-for="(node, nodeIndex) in unref(rightSideNodes)"
|
|
||||||
:key="nodeIndex"
|
|
||||||
v-bind="gatherNodeProps(node)"
|
|
||||||
small
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
<Links v-if="branches" :links="unref(branches)" />
|
<Links v-if="branches" :links="unref(branches)" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="tsx">
|
||||||
import "components/common/table.css";
|
import "components/common/table.css";
|
||||||
import { GenericTreeNode, TreeBranch } from "features/trees/tree";
|
import { GenericTreeNode, TreeBranch } from "features/trees/tree";
|
||||||
import { processedPropType } from "util/vue";
|
import { coerceComponent, processedPropType, renderJSX, unwrapRef } from "util/vue";
|
||||||
import { defineComponent, unref } from "vue";
|
import { Component, defineComponent, shallowRef, toRefs, unref, watchEffect } from "vue";
|
||||||
import TreeNode from "./TreeNode.vue";
|
|
||||||
import Links from "features/links/Links.vue";
|
import Links from "features/links/Links.vue";
|
||||||
|
import { jsx } from "features/feature";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
|
@ -43,40 +23,51 @@ export default defineComponent({
|
||||||
rightSideNodes: processedPropType<GenericTreeNode[]>(Array),
|
rightSideNodes: processedPropType<GenericTreeNode[]>(Array),
|
||||||
branches: processedPropType<TreeBranch[]>(Array)
|
branches: processedPropType<TreeBranch[]>(Array)
|
||||||
},
|
},
|
||||||
components: { TreeNode, Links },
|
components: { Links },
|
||||||
setup() {
|
setup(props) {
|
||||||
function gatherNodeProps(node: GenericTreeNode) {
|
const { nodes, leftSideNodes, rightSideNodes } = toRefs(props);
|
||||||
const {
|
|
||||||
display,
|
const nodesComp = shallowRef<Component | "">();
|
||||||
visibility,
|
watchEffect(() => {
|
||||||
style,
|
const currNodes = unwrapRef(nodes);
|
||||||
classes,
|
nodesComp.value = coerceComponent(
|
||||||
onClick,
|
jsx(() => (
|
||||||
onHold,
|
<>
|
||||||
color,
|
{currNodes.map(row => (
|
||||||
glowColor,
|
<span class="row">{row.map(renderJSX)}</span>
|
||||||
canClick,
|
))}
|
||||||
mark,
|
</>
|
||||||
id
|
))
|
||||||
} = node;
|
);
|
||||||
return {
|
});
|
||||||
display,
|
|
||||||
visibility,
|
const leftNodesComp = shallowRef<Component | "">();
|
||||||
style,
|
watchEffect(() => {
|
||||||
classes,
|
const currNodes = unwrapRef(leftSideNodes);
|
||||||
onClick,
|
leftNodesComp.value = currNodes
|
||||||
onHold,
|
? coerceComponent(
|
||||||
color,
|
jsx(() => (
|
||||||
glowColor,
|
<span class="left-side-nodes small">{currNodes.map(renderJSX)}</span>
|
||||||
canClick,
|
))
|
||||||
mark,
|
)
|
||||||
id
|
: "";
|
||||||
};
|
});
|
||||||
}
|
|
||||||
|
const rightNodesComp = shallowRef<Component | "">();
|
||||||
|
watchEffect(() => {
|
||||||
|
const currNodes = unwrapRef(rightSideNodes);
|
||||||
|
rightNodesComp.value = currNodes
|
||||||
|
? coerceComponent(
|
||||||
|
jsx(() => <span class="side-nodes small">{currNodes.map(renderJSX)}</span>)
|
||||||
|
)
|
||||||
|
: "";
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
gatherNodeProps,
|
unref,
|
||||||
unref
|
nodesComp,
|
||||||
|
leftNodesComp,
|
||||||
|
rightNodesComp
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -98,4 +89,13 @@ export default defineComponent({
|
||||||
right: 15px;
|
right: 15px;
|
||||||
top: 65px;
|
top: 65px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.small :deep(.treeNode) {
|
||||||
|
height: 60px;
|
||||||
|
width: 60px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.small :deep(.treeNode) > *:first-child {
|
||||||
|
font-size: 30px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
:class="{
|
:class="{
|
||||||
treeNode: true,
|
treeNode: true,
|
||||||
can: unref(canClick),
|
can: unref(canClick),
|
||||||
small: unref(small),
|
|
||||||
...unref(classes)
|
...unref(classes)
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
|
@ -67,8 +66,7 @@ export default defineComponent({
|
||||||
id: {
|
id: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
}
|
||||||
small: processedPropType<boolean>(Boolean)
|
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
MarkNode,
|
MarkNode,
|
||||||
|
@ -114,18 +112,4 @@ export default defineComponent({
|
||||||
text-transform: capitalize;
|
text-transform: capitalize;
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.treeNode.small {
|
|
||||||
height: 60px;
|
|
||||||
width: 60px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.treeNode.small > *:first-child {
|
|
||||||
font-size: 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ghost {
|
|
||||||
visibility: hidden;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -13,6 +13,7 @@ import { Link } from "features/links/links";
|
||||||
import { GenericReset } from "features/reset";
|
import { GenericReset } from "features/reset";
|
||||||
import { displayResource, Resource } from "features/resources/resource";
|
import { displayResource, Resource } from "features/resources/resource";
|
||||||
import TreeComponent from "features/trees/Tree.vue";
|
import TreeComponent from "features/trees/Tree.vue";
|
||||||
|
import TreeNodeComponent from "features/trees/TreeNode.vue";
|
||||||
import Decimal, { DecimalSource, format, formatWhole } from "util/bignum";
|
import Decimal, { DecimalSource, format, formatWhole } from "util/bignum";
|
||||||
import {
|
import {
|
||||||
Computable,
|
Computable,
|
||||||
|
@ -45,6 +46,8 @@ export interface TreeNodeOptions {
|
||||||
export interface BaseTreeNode {
|
export interface BaseTreeNode {
|
||||||
id: string;
|
id: string;
|
||||||
type: typeof TreeNodeType;
|
type: typeof TreeNodeType;
|
||||||
|
[Component]: typeof TreeNodeComponent;
|
||||||
|
[GatherProps]: () => Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TreeNode<T extends TreeNodeOptions> = Replace<
|
export type TreeNode<T extends TreeNodeOptions> = Replace<
|
||||||
|
@ -76,6 +79,7 @@ export function createTreeNode<T extends TreeNodeOptions>(
|
||||||
const treeNode = optionsFunc();
|
const treeNode = optionsFunc();
|
||||||
treeNode.id = getUniqueID("treeNode-");
|
treeNode.id = getUniqueID("treeNode-");
|
||||||
treeNode.type = TreeNodeType;
|
treeNode.type = TreeNodeType;
|
||||||
|
treeNode[Component] = TreeNodeComponent;
|
||||||
|
|
||||||
processComputable(treeNode as T, "visibility");
|
processComputable(treeNode as T, "visibility");
|
||||||
setDefault(treeNode, "visibility", Visibility.Visible);
|
setDefault(treeNode, "visibility", Visibility.Visible);
|
||||||
|
@ -105,6 +109,35 @@ export function createTreeNode<T extends TreeNodeOptions>(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
treeNode[GatherProps] = function (this: GenericTreeNode) {
|
||||||
|
const {
|
||||||
|
display,
|
||||||
|
visibility,
|
||||||
|
style,
|
||||||
|
classes,
|
||||||
|
onClick,
|
||||||
|
onHold,
|
||||||
|
color,
|
||||||
|
glowColor,
|
||||||
|
canClick,
|
||||||
|
mark,
|
||||||
|
id
|
||||||
|
} = this;
|
||||||
|
return {
|
||||||
|
display,
|
||||||
|
visibility,
|
||||||
|
style,
|
||||||
|
classes,
|
||||||
|
onClick,
|
||||||
|
onHold,
|
||||||
|
color,
|
||||||
|
glowColor,
|
||||||
|
canClick,
|
||||||
|
mark,
|
||||||
|
id
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
return treeNode as unknown as TreeNode<T>;
|
return treeNode as unknown as TreeNode<T>;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue