2021-08-22 14:22:22 +00:00
|
|
|
import type {
|
|
|
|
FlattenDataNode,
|
|
|
|
InternalDataEntity,
|
|
|
|
Key,
|
|
|
|
LegacyDataNode,
|
|
|
|
RawValueType,
|
|
|
|
} from './interface';
|
2021-08-20 13:39:59 +00:00
|
|
|
import type { SkipType } from './hooks/useKeyValueMapping';
|
2021-08-21 14:55:19 +00:00
|
|
|
import type { ComputedRef, InjectionKey, PropType } from 'vue';
|
|
|
|
import { computed, defineComponent, inject, provide } from 'vue';
|
2021-08-20 13:39:59 +00:00
|
|
|
|
|
|
|
interface ContextProps {
|
|
|
|
checkable: boolean;
|
2021-08-20 15:21:49 +00:00
|
|
|
customCheckable: () => any;
|
2021-08-20 13:39:59 +00:00
|
|
|
checkedKeys: Key[];
|
|
|
|
halfCheckedKeys: Key[];
|
|
|
|
treeExpandedKeys: Key[];
|
|
|
|
treeDefaultExpandedKeys: Key[];
|
|
|
|
onTreeExpand: (keys: Key[]) => void;
|
|
|
|
treeDefaultExpandAll: boolean;
|
|
|
|
treeIcon: any;
|
|
|
|
showTreeIcon: boolean;
|
|
|
|
switcherIcon: any;
|
|
|
|
treeLine: boolean;
|
|
|
|
treeNodeFilterProp: string;
|
|
|
|
treeLoadedKeys: Key[];
|
|
|
|
treeMotion: any;
|
|
|
|
loadData: (treeNode: LegacyDataNode) => Promise<unknown>;
|
|
|
|
onTreeLoad: (loadedKeys: Key[]) => void;
|
|
|
|
|
|
|
|
// Cache help content. These can be generated by parent component.
|
|
|
|
// Let's reuse this.
|
|
|
|
getEntityByKey: (key: Key, skipType?: SkipType, ignoreDisabledCheck?: boolean) => FlattenDataNode;
|
|
|
|
getEntityByValue: (
|
|
|
|
value: RawValueType,
|
|
|
|
skipType?: SkipType,
|
|
|
|
ignoreDisabledCheck?: boolean,
|
|
|
|
) => FlattenDataNode;
|
|
|
|
|
2021-08-22 14:22:22 +00:00
|
|
|
slots: {
|
|
|
|
title?: (data: InternalDataEntity) => any;
|
|
|
|
titleRender?: (data: InternalDataEntity) => any;
|
|
|
|
[key: string]: (d: any) => any | undefined;
|
|
|
|
};
|
2021-08-20 13:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const SelectContextKey: InjectionKey<ComputedRef<ContextProps>> = Symbol('SelectContextKey');
|
|
|
|
|
|
|
|
export const SelectContext = defineComponent({
|
|
|
|
name: 'SelectContext',
|
|
|
|
props: {
|
|
|
|
value: { type: Object as PropType<ContextProps> },
|
|
|
|
},
|
|
|
|
setup(props, { slots }) {
|
|
|
|
provide(
|
|
|
|
SelectContextKey,
|
|
|
|
computed(() => props.value),
|
|
|
|
);
|
|
|
|
return () => slots.default?.();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-08-22 08:59:13 +00:00
|
|
|
export const useInjectTreeSelectContext = () => {
|
2021-08-20 13:39:59 +00:00
|
|
|
return inject(
|
|
|
|
SelectContextKey,
|
|
|
|
computed(() => ({} as ContextProps)),
|
|
|
|
);
|
|
|
|
};
|