Skip to content

Commit

Permalink
modified useNode and added default class
Browse files Browse the repository at this point in the history
  • Loading branch information
N00ts committed Jul 19, 2021
1 parent 4a93132 commit f34bb87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/misc/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { INodeState } from '../structure/INodeState';

export const defaultSize = 8;

export const defaultDisabledClass = "disabled";

export const defaultFocusClass = "focused";

const defaultViewBox = "0 0 123.958 123.959";

const defaultOpenDraw = `M117.979,28.017h-112c-5.3,0-8,6.4-4.2,10.2l56,56c2.3,2.3,6.1,2.3,8.401,0l56-56C125.979,34.417,123.279,28.017,117.979,28.017z`;
Expand Down
28 changes: 13 additions & 15 deletions src/setup/useNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import isArray from "lodash-es/isArray";
import { computed, ref, watch, nextTick } from 'vue';
import { nodeEvents } from '../misc/nodeEvents';
import IUseCommon from '../structure/IUseCommon';
import { defaultDisabledClass, defaultFocusClass } from '../misc/default';

export function useNode(cmn: IUseCommon, props: INodeProps): IUseNode {
const node = cmn.node;
const config = cmn.config;
const wrapper = cmn.wrapper;
const editing = cmn.editing;
const level = ref(null);
const depth = ref(props.depth);
const index = ref(props.index);

const id = computed(() => {
return hasNode.value && node.value.id;
Expand Down Expand Up @@ -66,28 +69,24 @@ export function useNode(cmn: IUseCommon, props: INodeProps): IUseNode {
};
});

const disabled = computed(() => {
return config.value.disabled || node.value.state.disabled;
});

const disabledClass = computed(() => {
if (!disabled.value) {
if (!cmn.disabled.value) {
return null;
}

return config.value.disabledClass ? config.value.disabledClass : "disabled";
return config.value.disabledClass ? config.value.disabledClass : defaultDisabledClass;
});

const hideIcons = computed(() => {
for (const id of config.value.roots) {
for (const id of roots.value) {
const node = state.nodes.value[id];

if (node.children && node.children.length > 0) {
return false;
}
}

return false;
return true;
});

const isLeaf = computed(() => {
Expand All @@ -97,15 +96,15 @@ export function useNode(cmn: IUseCommon, props: INodeProps): IUseNode {
return Number.isFinite(idx) && idx >= 0;
}

return !isArray(node.value.children) || node.value.children.length === 0;
return isNil(node.value.children) || !isArray(node.value.children) || node.value.children.length === 0;
});

const isFocused = computed(() => {
return state.focused.value === node.value.id;
});

const tabIndex = computed(() => {
if (props.depth === 0 && props.index === 0 && !isFocused.value) {
if (depth.value === 0 && index.value === 0 && !isFocused.value) {
return 0;
}

Expand All @@ -117,7 +116,7 @@ export function useNode(cmn: IUseCommon, props: INodeProps): IUseNode {
return null;
}

return config.value.focusClass ? config.value.focusClass : "focused";
return config.value.focusClass ? config.value.focusClass : defaultFocusClass;
})

watch(opened, (nv: boolean) => {
Expand Down Expand Up @@ -169,7 +168,7 @@ export function useNode(cmn: IUseCommon, props: INodeProps): IUseNode {
if (n.children && n.children.length > 0) {
const idx = n.children.indexOf(node.value.id);
const prev = n.children[idx - 1];

if (!isNil(prev)) {
return lastChild(prev);
}
Expand Down Expand Up @@ -217,9 +216,8 @@ export function useNode(cmn: IUseCommon, props: INodeProps): IUseNode {
});

const nextRoot = ((id: string) => {
const roots = config.value.roots;
const idx = roots.indexOf(id);
return roots[idx + 1] || null;
const idx = roots.value.indexOf(id);
return roots.value[idx + 1] || null;
})

const next = ((p: INode, id: string): string => {
Expand Down

0 comments on commit f34bb87

Please sign in to comment.