gitea push
This commit is contained in:
+3
-2
@@ -3,7 +3,7 @@ import type { ActiveStrategy } from './activeStrategies.js';
|
||||
import type { OpenStrategy } from './openStrategies.js';
|
||||
import type { SelectStrategy } from './selectStrategies.js';
|
||||
import type { ListItem } from '../list-items.js';
|
||||
import type { EventProp } from '../../util/index.js';
|
||||
import type { EventProp, ValueComparator } from '../../util/index.js';
|
||||
export type ActiveStrategyProp = 'single-leaf' | 'leaf' | 'independent' | 'single-independent' | ActiveStrategy | ((mandatory: boolean) => ActiveStrategy);
|
||||
export type SelectStrategyProp = 'single-leaf' | 'leaf' | 'independent' | 'single-independent' | 'classic' | 'trunk' | 'branch' | SelectStrategy | ((mandatory: boolean) => SelectStrategy);
|
||||
export type OpenStrategyProp = 'single' | 'multiple' | 'list' | OpenStrategy;
|
||||
@@ -109,10 +109,11 @@ export declare const makeNestedProps: <Defaults extends {
|
||||
default: unknown extends Defaults["itemsRegistration"] ? ItemsRegistrationType : Defaults["itemsRegistration"] | NonNullable<ItemsRegistrationType>;
|
||||
};
|
||||
};
|
||||
export declare const useNested: (props: NestedProps, { items, returnObject, scrollToActive, }: {
|
||||
export declare const useNested: (props: NestedProps, { items, returnObject, scrollToActive, valueComparator, }: {
|
||||
items: Ref<ListItem[]>;
|
||||
returnObject: MaybeRefOrGetter<boolean>;
|
||||
scrollToActive: MaybeRefOrGetter<boolean>;
|
||||
valueComparator?: MaybeRefOrGetter<ValueComparator | undefined>;
|
||||
}) => {
|
||||
children: Ref<Map<unknown, unknown[]>>;
|
||||
parents: Ref<Map<unknown, unknown>>;
|
||||
|
||||
+24
-3
@@ -48,7 +48,8 @@ export const makeNestedProps = propsFactory({
|
||||
export const useNested = (props, {
|
||||
items,
|
||||
returnObject,
|
||||
scrollToActive
|
||||
scrollToActive,
|
||||
valueComparator
|
||||
}) => {
|
||||
let isUnmounted = false;
|
||||
const children = shallowRef(new Map());
|
||||
@@ -103,8 +104,28 @@ export const useNested = (props, {
|
||||
return multipleOpenStrategy;
|
||||
}
|
||||
});
|
||||
const activated = useProxiedModel(props, 'activated', props.activated, v => activeStrategy.value.in(v, children.value, parents.value), v => activeStrategy.value.out(v, children.value, parents.value));
|
||||
const selected = useProxiedModel(props, 'selected', props.selected, v => selectStrategy.value.in(v, children.value, parents.value, disabled.value), v => selectStrategy.value.out(v, children.value, parents.value));
|
||||
const flatItems = computed(() => {
|
||||
const flat = [];
|
||||
const stack = [...items.value];
|
||||
while (stack.length) {
|
||||
const item = stack.pop();
|
||||
flat.push(item);
|
||||
if (item.children) stack.push(...item.children);
|
||||
}
|
||||
return flat;
|
||||
});
|
||||
function resolveValue(value) {
|
||||
const comparator = toValue(valueComparator);
|
||||
if (!comparator) return value;
|
||||
const _returnObject = toValue(returnObject);
|
||||
for (const item of flatItems.value) {
|
||||
const itemVal = _returnObject ? toRaw(item.raw) : item.value;
|
||||
if (comparator(value, itemVal)) return itemVal;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const activated = useProxiedModel(props, 'activated', props.activated, v => activeStrategy.value.in(Array.isArray(v) ? v.map(resolveValue) : v, children.value, parents.value), v => activeStrategy.value.out(v, children.value, parents.value));
|
||||
const selected = useProxiedModel(props, 'selected', props.selected, v => selectStrategy.value.in(Array.isArray(v) ? v.map(resolveValue) : v, children.value, parents.value, disabled.value), v => selectStrategy.value.out(v, children.value, parents.value));
|
||||
onBeforeUnmount(() => {
|
||||
isUnmounted = true;
|
||||
});
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user