routie dev init since i didn't adhere to any proper guidance up until now
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
type ActiveStrategyFunction = (data: {
|
||||
id: unknown;
|
||||
value: boolean;
|
||||
activated: Set<unknown>;
|
||||
children: Map<unknown, unknown[]>;
|
||||
parents: Map<unknown, unknown>;
|
||||
event?: Event;
|
||||
}) => Set<unknown>;
|
||||
type ActiveStrategyTransformInFunction = (v: unknown | undefined, children: Map<unknown, unknown[]>, parents: Map<unknown, unknown>) => Set<unknown>;
|
||||
type ActiveStrategyTransformOutFunction = (v: Set<unknown>, children: Map<unknown, unknown[]>, parents: Map<unknown, unknown>) => unknown;
|
||||
export type ActiveStrategy = {
|
||||
activate: ActiveStrategyFunction;
|
||||
in: ActiveStrategyTransformInFunction;
|
||||
out: ActiveStrategyTransformOutFunction;
|
||||
};
|
||||
export declare const independentActiveStrategy: (mandatory?: boolean) => ActiveStrategy;
|
||||
export declare const independentSingleActiveStrategy: (mandatory?: boolean) => ActiveStrategy;
|
||||
export declare const leafActiveStrategy: (mandatory?: boolean) => ActiveStrategy;
|
||||
export declare const leafSingleActiveStrategy: (mandatory?: boolean) => ActiveStrategy;
|
||||
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/* eslint-disable sonarjs/no-identical-functions */
|
||||
// Utilities
|
||||
import { toRaw } from 'vue';
|
||||
import { wrapInArray } from "../../util/index.js";
|
||||
export const independentActiveStrategy = mandatory => {
|
||||
const strategy = {
|
||||
activate: ({
|
||||
id,
|
||||
value,
|
||||
activated
|
||||
}) => {
|
||||
id = toRaw(id);
|
||||
|
||||
// When mandatory and we're trying to deselect when id
|
||||
// is the only currently selected item then do nothing
|
||||
if (mandatory && !value && activated.size === 1 && activated.has(id)) return activated;
|
||||
if (value) {
|
||||
activated.add(id);
|
||||
} else {
|
||||
activated.delete(id);
|
||||
}
|
||||
return activated;
|
||||
},
|
||||
in: (v, children, parents) => {
|
||||
let set = new Set();
|
||||
if (v != null) {
|
||||
for (const id of wrapInArray(v)) {
|
||||
set = strategy.activate({
|
||||
id,
|
||||
value: true,
|
||||
activated: new Set(set),
|
||||
children,
|
||||
parents
|
||||
});
|
||||
}
|
||||
}
|
||||
return set;
|
||||
},
|
||||
out: v => {
|
||||
return Array.from(v);
|
||||
}
|
||||
};
|
||||
return strategy;
|
||||
};
|
||||
export const independentSingleActiveStrategy = mandatory => {
|
||||
const parentStrategy = independentActiveStrategy(mandatory);
|
||||
const strategy = {
|
||||
activate: ({
|
||||
activated,
|
||||
id,
|
||||
...rest
|
||||
}) => {
|
||||
id = toRaw(id);
|
||||
const singleSelected = activated.has(id) ? new Set([id]) : new Set();
|
||||
return parentStrategy.activate({
|
||||
...rest,
|
||||
id,
|
||||
activated: singleSelected
|
||||
});
|
||||
},
|
||||
in: (v, children, parents) => {
|
||||
let set = new Set();
|
||||
if (v != null) {
|
||||
const arr = wrapInArray(v);
|
||||
if (arr.length) {
|
||||
set = parentStrategy.in(arr.slice(0, 1), children, parents);
|
||||
}
|
||||
}
|
||||
return set;
|
||||
},
|
||||
out: (v, children, parents) => {
|
||||
return parentStrategy.out(v, children, parents);
|
||||
}
|
||||
};
|
||||
return strategy;
|
||||
};
|
||||
export const leafActiveStrategy = mandatory => {
|
||||
const parentStrategy = independentActiveStrategy(mandatory);
|
||||
const strategy = {
|
||||
activate: ({
|
||||
id,
|
||||
activated,
|
||||
children,
|
||||
...rest
|
||||
}) => {
|
||||
id = toRaw(id);
|
||||
if (children.has(id)) return activated;
|
||||
return parentStrategy.activate({
|
||||
id,
|
||||
activated,
|
||||
children,
|
||||
...rest
|
||||
});
|
||||
},
|
||||
in: parentStrategy.in,
|
||||
out: parentStrategy.out
|
||||
};
|
||||
return strategy;
|
||||
};
|
||||
export const leafSingleActiveStrategy = mandatory => {
|
||||
const parentStrategy = independentSingleActiveStrategy(mandatory);
|
||||
const strategy = {
|
||||
activate: ({
|
||||
id,
|
||||
activated,
|
||||
children,
|
||||
...rest
|
||||
}) => {
|
||||
id = toRaw(id);
|
||||
if (children.has(id)) return activated;
|
||||
return parentStrategy.activate({
|
||||
id,
|
||||
activated,
|
||||
children,
|
||||
...rest
|
||||
});
|
||||
},
|
||||
in: parentStrategy.in,
|
||||
out: parentStrategy.out
|
||||
};
|
||||
return strategy;
|
||||
};
|
||||
//# sourceMappingURL=activeStrategies.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+174
@@ -0,0 +1,174 @@
|
||||
import type { InjectionKey, MaybeRefOrGetter, PropType, Ref } from 'vue';
|
||||
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';
|
||||
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;
|
||||
export type ItemsRegistrationType = 'props' | 'render';
|
||||
export interface NestedProps {
|
||||
activatable: boolean;
|
||||
selectable: boolean;
|
||||
activeStrategy: ActiveStrategyProp | undefined;
|
||||
selectStrategy: SelectStrategyProp | undefined;
|
||||
openStrategy: OpenStrategyProp | undefined;
|
||||
activated: any;
|
||||
selected: any;
|
||||
opened: any;
|
||||
mandatory: boolean;
|
||||
itemsRegistration: ItemsRegistrationType;
|
||||
'onUpdate:activated': EventProp<[any]> | undefined;
|
||||
'onUpdate:selected': EventProp<[any]> | undefined;
|
||||
'onUpdate:opened': EventProp<[any]> | undefined;
|
||||
}
|
||||
type NestedProvide = {
|
||||
id: Ref<unknown>;
|
||||
isGroupActivator?: boolean;
|
||||
root: {
|
||||
children: Ref<Map<unknown, unknown[]>>;
|
||||
parents: Ref<Map<unknown, unknown>>;
|
||||
disabled: Ref<Set<unknown>>;
|
||||
activatable: Ref<boolean>;
|
||||
selectable: Ref<boolean>;
|
||||
opened: Ref<Set<unknown>>;
|
||||
activated: Ref<Set<unknown>>;
|
||||
scrollToActive: Ref<boolean>;
|
||||
selected: Ref<Map<unknown, 'on' | 'off' | 'indeterminate'>>;
|
||||
selectedValues: Ref<unknown[]>;
|
||||
itemsRegistration: Ref<ItemsRegistrationType>;
|
||||
register: (id: unknown, parentId: unknown, isDisabled: boolean, isGroup?: boolean) => void;
|
||||
unregister: (id: unknown) => void;
|
||||
updateDisabled: (id: unknown, isDisabled: boolean) => void;
|
||||
open: (id: unknown, value: boolean, event?: Event) => void;
|
||||
activate: (id: unknown, value: boolean, event?: Event) => void;
|
||||
select: (id: unknown, value: boolean, event?: Event) => void;
|
||||
openOnSelect: (id: unknown, value: boolean, event?: Event) => void;
|
||||
getPath: (id: unknown) => unknown[];
|
||||
};
|
||||
};
|
||||
export declare const VNestedSymbol: InjectionKey<NestedProvide>;
|
||||
export declare const emptyNested: NestedProvide;
|
||||
export declare const makeNestedProps: <Defaults extends {
|
||||
activatable?: unknown;
|
||||
selectable?: unknown;
|
||||
activeStrategy?: unknown;
|
||||
selectStrategy?: unknown;
|
||||
openStrategy?: unknown;
|
||||
opened?: unknown;
|
||||
activated?: unknown;
|
||||
selected?: unknown;
|
||||
mandatory?: unknown;
|
||||
itemsRegistration?: unknown;
|
||||
} = {}>(defaults?: Defaults | undefined) => {
|
||||
activatable: unknown extends Defaults["activatable"] ? BooleanConstructor : {
|
||||
type: PropType<unknown extends Defaults["activatable"] ? boolean : boolean | Defaults["activatable"]>;
|
||||
default: unknown extends Defaults["activatable"] ? boolean : boolean | Defaults["activatable"];
|
||||
};
|
||||
selectable: unknown extends Defaults["selectable"] ? BooleanConstructor : {
|
||||
type: PropType<unknown extends Defaults["selectable"] ? boolean : boolean | Defaults["selectable"]>;
|
||||
default: unknown extends Defaults["selectable"] ? boolean : boolean | Defaults["selectable"];
|
||||
};
|
||||
activeStrategy: unknown extends Defaults["activeStrategy"] ? PropType<ActiveStrategyProp> : {
|
||||
type: PropType<unknown extends Defaults["activeStrategy"] ? ActiveStrategyProp : Defaults["activeStrategy"] | ActiveStrategyProp>;
|
||||
default: unknown extends Defaults["activeStrategy"] ? ActiveStrategyProp : Defaults["activeStrategy"] | NonNullable<ActiveStrategyProp>;
|
||||
};
|
||||
selectStrategy: unknown extends Defaults["selectStrategy"] ? PropType<SelectStrategyProp> : {
|
||||
type: PropType<unknown extends Defaults["selectStrategy"] ? SelectStrategyProp : Defaults["selectStrategy"] | SelectStrategyProp>;
|
||||
default: unknown extends Defaults["selectStrategy"] ? SelectStrategyProp : Defaults["selectStrategy"] | NonNullable<SelectStrategyProp>;
|
||||
};
|
||||
openStrategy: unknown extends Defaults["openStrategy"] ? PropType<OpenStrategyProp> : {
|
||||
type: PropType<unknown extends Defaults["openStrategy"] ? OpenStrategyProp : Defaults["openStrategy"] | OpenStrategyProp>;
|
||||
default: unknown extends Defaults["openStrategy"] ? OpenStrategyProp : Defaults["openStrategy"] | NonNullable<OpenStrategyProp>;
|
||||
};
|
||||
opened: unknown extends Defaults["opened"] ? null : {
|
||||
type: PropType<unknown extends Defaults["opened"] ? any : any>;
|
||||
default: unknown extends Defaults["opened"] ? any : any;
|
||||
};
|
||||
activated: unknown extends Defaults["activated"] ? null : {
|
||||
type: PropType<unknown extends Defaults["activated"] ? any : any>;
|
||||
default: unknown extends Defaults["activated"] ? any : any;
|
||||
};
|
||||
selected: unknown extends Defaults["selected"] ? null : {
|
||||
type: PropType<unknown extends Defaults["selected"] ? any : any>;
|
||||
default: unknown extends Defaults["selected"] ? any : any;
|
||||
};
|
||||
mandatory: unknown extends Defaults["mandatory"] ? BooleanConstructor : {
|
||||
type: PropType<unknown extends Defaults["mandatory"] ? boolean : boolean | Defaults["mandatory"]>;
|
||||
default: unknown extends Defaults["mandatory"] ? boolean : boolean | Defaults["mandatory"];
|
||||
};
|
||||
itemsRegistration: unknown extends Defaults["itemsRegistration"] ? {
|
||||
type: PropType<ItemsRegistrationType>;
|
||||
default: string;
|
||||
} : Omit<{
|
||||
type: PropType<ItemsRegistrationType>;
|
||||
default: string;
|
||||
}, "default" | "type"> & {
|
||||
type: PropType<unknown extends Defaults["itemsRegistration"] ? ItemsRegistrationType : Defaults["itemsRegistration"] | ItemsRegistrationType>;
|
||||
default: unknown extends Defaults["itemsRegistration"] ? ItemsRegistrationType : Defaults["itemsRegistration"] | NonNullable<ItemsRegistrationType>;
|
||||
};
|
||||
};
|
||||
export declare const useNested: (props: NestedProps, { items, returnObject, scrollToActive, }: {
|
||||
items: Ref<ListItem[]>;
|
||||
returnObject: MaybeRefOrGetter<boolean>;
|
||||
scrollToActive: MaybeRefOrGetter<boolean>;
|
||||
}) => {
|
||||
children: Ref<Map<unknown, unknown[]>>;
|
||||
parents: Ref<Map<unknown, unknown>>;
|
||||
disabled: Ref<Set<unknown>>;
|
||||
activatable: Ref<boolean>;
|
||||
selectable: Ref<boolean>;
|
||||
opened: Ref<Set<unknown>>;
|
||||
activated: Ref<Set<unknown>>;
|
||||
scrollToActive: Ref<boolean>;
|
||||
selected: Ref<Map<unknown, 'on' | 'off' | 'indeterminate'>>;
|
||||
selectedValues: Ref<unknown[]>;
|
||||
itemsRegistration: Ref<ItemsRegistrationType>;
|
||||
register: (id: unknown, parentId: unknown, isDisabled: boolean, isGroup?: boolean) => void;
|
||||
unregister: (id: unknown) => void;
|
||||
updateDisabled: (id: unknown, isDisabled: boolean) => void;
|
||||
open: (id: unknown, value: boolean, event?: Event) => void;
|
||||
activate: (id: unknown, value: boolean, event?: Event) => void;
|
||||
select: (id: unknown, value: boolean, event?: Event) => void;
|
||||
openOnSelect: (id: unknown, value: boolean, event?: Event) => void;
|
||||
getPath: (id: unknown) => unknown[];
|
||||
};
|
||||
export declare const useNestedItem: (id: MaybeRefOrGetter<unknown>, isDisabled: MaybeRefOrGetter<boolean>, isGroup: boolean) => {
|
||||
root: {
|
||||
children: Ref<Map<unknown, unknown[]>>;
|
||||
parents: Ref<Map<unknown, unknown>>;
|
||||
disabled: Ref<Set<unknown>>;
|
||||
activatable: Ref<boolean>;
|
||||
selectable: Ref<boolean>;
|
||||
opened: Ref<Set<unknown>>;
|
||||
activated: Ref<Set<unknown>>;
|
||||
scrollToActive: Ref<boolean>;
|
||||
selected: Ref<Map<unknown, 'on' | 'off' | 'indeterminate'>>;
|
||||
selectedValues: Ref<unknown[]>;
|
||||
itemsRegistration: Ref<ItemsRegistrationType>;
|
||||
register: (id: unknown, parentId: unknown, isDisabled: boolean, isGroup?: boolean) => void;
|
||||
unregister: (id: unknown) => void;
|
||||
updateDisabled: (id: unknown, isDisabled: boolean) => void;
|
||||
open: (id: unknown, value: boolean, event?: Event) => void;
|
||||
activate: (id: unknown, value: boolean, event?: Event) => void;
|
||||
select: (id: unknown, value: boolean, event?: Event) => void;
|
||||
openOnSelect: (id: unknown, value: boolean, event?: Event) => void;
|
||||
getPath: (id: unknown) => unknown[];
|
||||
};
|
||||
id: import("vue").ComputedRef<{} | null>;
|
||||
open: (open: boolean, e: Event) => void;
|
||||
openOnSelect: (open: boolean, e?: Event) => void;
|
||||
isOpen: import("vue").ComputedRef<boolean>;
|
||||
parent: import("vue").ComputedRef<unknown>;
|
||||
activate: (activated: boolean, e?: Event) => void;
|
||||
isActivated: import("vue").ComputedRef<boolean>;
|
||||
scrollToActive: Ref<boolean, boolean>;
|
||||
select: (selected: boolean, e?: Event) => void;
|
||||
isSelected: import("vue").ComputedRef<boolean>;
|
||||
isIndeterminate: import("vue").ComputedRef<boolean>;
|
||||
isLeaf: import("vue").ComputedRef<boolean>;
|
||||
isGroupActivator: boolean | undefined;
|
||||
};
|
||||
export declare const useNestedGroupActivator: () => void;
|
||||
|
||||
+368
@@ -0,0 +1,368 @@
|
||||
// Composables
|
||||
import { useProxiedModel } from "../proxiedModel.js"; // Utilities
|
||||
import { computed, inject, nextTick, onBeforeMount, onBeforeUnmount, provide, ref, shallowRef, toRaw, toRef, toValue, watch } from 'vue';
|
||||
import { independentActiveStrategy, independentSingleActiveStrategy, leafActiveStrategy, leafSingleActiveStrategy } from "./activeStrategies.js";
|
||||
import { listOpenStrategy, multipleOpenStrategy, singleOpenStrategy } from "./openStrategies.js";
|
||||
import { branchSelectStrategy, classicSelectStrategy, independentSelectStrategy, independentSingleSelectStrategy, leafSelectStrategy, leafSingleSelectStrategy, trunkSelectStrategy } from "./selectStrategies.js";
|
||||
import { consoleError, getCurrentInstance, propsFactory, throttle } from "../../util/index.js"; // Types
|
||||
export const VNestedSymbol = Symbol.for('vuetify:nested');
|
||||
export const emptyNested = {
|
||||
id: shallowRef(),
|
||||
root: {
|
||||
itemsRegistration: ref('render'),
|
||||
register: () => null,
|
||||
unregister: () => null,
|
||||
updateDisabled: () => null,
|
||||
children: ref(new Map()),
|
||||
parents: ref(new Map()),
|
||||
disabled: ref(new Set()),
|
||||
open: () => null,
|
||||
openOnSelect: () => null,
|
||||
activate: () => null,
|
||||
select: () => null,
|
||||
activatable: ref(false),
|
||||
scrollToActive: ref(false),
|
||||
selectable: ref(false),
|
||||
opened: ref(new Set()),
|
||||
activated: ref(new Set()),
|
||||
selected: ref(new Map()),
|
||||
selectedValues: ref([]),
|
||||
getPath: () => []
|
||||
}
|
||||
};
|
||||
export const makeNestedProps = propsFactory({
|
||||
activatable: Boolean,
|
||||
selectable: Boolean,
|
||||
activeStrategy: [String, Function, Object],
|
||||
selectStrategy: [String, Function, Object],
|
||||
openStrategy: [String, Object],
|
||||
opened: null,
|
||||
activated: null,
|
||||
selected: null,
|
||||
mandatory: Boolean,
|
||||
itemsRegistration: {
|
||||
type: String,
|
||||
default: 'render'
|
||||
}
|
||||
}, 'nested');
|
||||
export const useNested = (props, {
|
||||
items,
|
||||
returnObject,
|
||||
scrollToActive
|
||||
}) => {
|
||||
let isUnmounted = false;
|
||||
const children = shallowRef(new Map());
|
||||
const parents = shallowRef(new Map());
|
||||
const disabled = shallowRef(new Set());
|
||||
const opened = useProxiedModel(props, 'opened', props.opened, v => new Set(Array.isArray(v) ? v.map(i => toRaw(i)) : v), v => [...v.values()]);
|
||||
const activeStrategy = computed(() => {
|
||||
if (typeof props.activeStrategy === 'object') return props.activeStrategy;
|
||||
if (typeof props.activeStrategy === 'function') return props.activeStrategy(props.mandatory);
|
||||
switch (props.activeStrategy) {
|
||||
case 'leaf':
|
||||
return leafActiveStrategy(props.mandatory);
|
||||
case 'single-leaf':
|
||||
return leafSingleActiveStrategy(props.mandatory);
|
||||
case 'independent':
|
||||
return independentActiveStrategy(props.mandatory);
|
||||
case 'single-independent':
|
||||
default:
|
||||
return independentSingleActiveStrategy(props.mandatory);
|
||||
}
|
||||
});
|
||||
const selectStrategy = computed(() => {
|
||||
if (typeof props.selectStrategy === 'object') return props.selectStrategy;
|
||||
if (typeof props.selectStrategy === 'function') return props.selectStrategy(props.mandatory);
|
||||
switch (props.selectStrategy) {
|
||||
case 'single-leaf':
|
||||
return leafSingleSelectStrategy(props.mandatory);
|
||||
case 'leaf':
|
||||
return leafSelectStrategy(props.mandatory);
|
||||
case 'independent':
|
||||
return independentSelectStrategy(props.mandatory);
|
||||
case 'single-independent':
|
||||
return independentSingleSelectStrategy(props.mandatory);
|
||||
case 'trunk':
|
||||
return trunkSelectStrategy(props.mandatory);
|
||||
case 'branch':
|
||||
return branchSelectStrategy(props.mandatory);
|
||||
case 'classic':
|
||||
default:
|
||||
return classicSelectStrategy(props.mandatory);
|
||||
}
|
||||
});
|
||||
const openStrategy = computed(() => {
|
||||
if (typeof props.openStrategy === 'object') return props.openStrategy;
|
||||
switch (props.openStrategy) {
|
||||
case 'list':
|
||||
return listOpenStrategy;
|
||||
case 'single':
|
||||
return singleOpenStrategy;
|
||||
case 'multiple':
|
||||
default:
|
||||
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));
|
||||
onBeforeUnmount(() => {
|
||||
isUnmounted = true;
|
||||
});
|
||||
function getPath(id) {
|
||||
const path = [];
|
||||
let parent = toRaw(id);
|
||||
while (parent !== undefined) {
|
||||
path.unshift(parent);
|
||||
parent = parents.value.get(parent);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
const vm = getCurrentInstance('nested');
|
||||
const nodeIds = new Set();
|
||||
const itemsUpdatePropagation = throttle(() => {
|
||||
nextTick(() => {
|
||||
children.value = new Map(children.value);
|
||||
parents.value = new Map(parents.value);
|
||||
});
|
||||
}, 100);
|
||||
watch(() => [items.value, toValue(returnObject)], () => {
|
||||
if (props.itemsRegistration === 'props') {
|
||||
updateInternalMaps();
|
||||
}
|
||||
}, {
|
||||
immediate: true
|
||||
});
|
||||
function updateInternalMaps() {
|
||||
const _parents = new Map();
|
||||
const _children = new Map();
|
||||
const _disabled = new Set();
|
||||
const getValue = toValue(returnObject) ? item => toRaw(item.raw) : item => item.value;
|
||||
const stack = [...items.value];
|
||||
let i = 0;
|
||||
while (i < stack.length) {
|
||||
const item = stack[i++];
|
||||
const itemValue = getValue(item);
|
||||
if (item.children) {
|
||||
const childValues = [];
|
||||
for (const child of item.children) {
|
||||
const childValue = getValue(child);
|
||||
_parents.set(childValue, itemValue);
|
||||
childValues.push(childValue);
|
||||
stack.push(child);
|
||||
}
|
||||
_children.set(itemValue, childValues);
|
||||
}
|
||||
if (item.props.disabled) {
|
||||
_disabled.add(itemValue);
|
||||
}
|
||||
}
|
||||
children.value = _children;
|
||||
parents.value = _parents;
|
||||
disabled.value = _disabled;
|
||||
}
|
||||
const nested = {
|
||||
id: shallowRef(),
|
||||
root: {
|
||||
opened,
|
||||
activatable: toRef(() => props.activatable),
|
||||
scrollToActive: toRef(() => toValue(scrollToActive)),
|
||||
selectable: toRef(() => props.selectable),
|
||||
activated,
|
||||
selected,
|
||||
selectedValues: computed(() => {
|
||||
const arr = [];
|
||||
for (const [key, value] of selected.value.entries()) {
|
||||
if (value === 'on') arr.push(key);
|
||||
}
|
||||
return arr;
|
||||
}),
|
||||
itemsRegistration: toRef(() => props.itemsRegistration),
|
||||
register: (id, parentId, isDisabled, isGroup) => {
|
||||
if (nodeIds.has(id)) {
|
||||
const path = getPath(id).map(String).join(' -> ');
|
||||
const newPath = getPath(parentId).concat(id).map(String).join(' -> ');
|
||||
consoleError(`Multiple nodes with the same ID\n\t${path}\n\t${newPath}`);
|
||||
return;
|
||||
} else {
|
||||
nodeIds.add(id);
|
||||
}
|
||||
parentId && id !== parentId && parents.value.set(id, parentId);
|
||||
isDisabled && disabled.value.add(id);
|
||||
isGroup && children.value.set(id, []);
|
||||
if (parentId != null) {
|
||||
children.value.set(parentId, [...(children.value.get(parentId) || []), id]);
|
||||
}
|
||||
itemsUpdatePropagation();
|
||||
},
|
||||
unregister: id => {
|
||||
if (isUnmounted) return;
|
||||
nodeIds.delete(id);
|
||||
children.value.delete(id);
|
||||
disabled.value.delete(id);
|
||||
const parent = parents.value.get(id);
|
||||
if (parent) {
|
||||
const list = children.value.get(parent) ?? [];
|
||||
children.value.set(parent, list.filter(child => child !== id));
|
||||
}
|
||||
parents.value.delete(id);
|
||||
itemsUpdatePropagation();
|
||||
},
|
||||
updateDisabled: (id, isDisabled) => {
|
||||
if (isDisabled) {
|
||||
disabled.value.add(id);
|
||||
} else {
|
||||
disabled.value.delete(id);
|
||||
}
|
||||
// classic selection requires refresh to re-evaluate on/off/indeterminate but
|
||||
// currently it is only run for selection interactions, so it will set new disabled
|
||||
// to "off" and the visual state becomes out of sync
|
||||
// -- selected.value = new Map(selected.value)
|
||||
// it is not clear if the framework should un-select when disabled changed to true
|
||||
// more discussion is needed
|
||||
},
|
||||
open: (id, value, event) => {
|
||||
vm.emit('click:open', {
|
||||
id,
|
||||
value,
|
||||
path: getPath(id),
|
||||
event
|
||||
});
|
||||
const newOpened = openStrategy.value.open({
|
||||
id,
|
||||
value,
|
||||
opened: new Set(opened.value),
|
||||
children: children.value,
|
||||
parents: parents.value,
|
||||
event
|
||||
});
|
||||
newOpened && (opened.value = newOpened);
|
||||
},
|
||||
openOnSelect: (id, value, event) => {
|
||||
const newOpened = openStrategy.value.select({
|
||||
id,
|
||||
value,
|
||||
selected: new Map(selected.value),
|
||||
opened: new Set(opened.value),
|
||||
children: children.value,
|
||||
parents: parents.value,
|
||||
event
|
||||
});
|
||||
newOpened && (opened.value = newOpened);
|
||||
},
|
||||
select: (id, value, event) => {
|
||||
vm.emit('click:select', {
|
||||
id,
|
||||
value,
|
||||
path: getPath(id),
|
||||
event
|
||||
});
|
||||
const newSelected = selectStrategy.value.select({
|
||||
id,
|
||||
value,
|
||||
selected: new Map(selected.value),
|
||||
children: children.value,
|
||||
parents: parents.value,
|
||||
disabled: disabled.value,
|
||||
event
|
||||
});
|
||||
newSelected && (selected.value = newSelected);
|
||||
nested.root.openOnSelect(id, value, event);
|
||||
},
|
||||
activate: (id, value, event) => {
|
||||
if (!props.activatable) {
|
||||
return nested.root.select(id, true, event);
|
||||
}
|
||||
vm.emit('click:activate', {
|
||||
id,
|
||||
value,
|
||||
path: getPath(id),
|
||||
event
|
||||
});
|
||||
const newActivated = activeStrategy.value.activate({
|
||||
id,
|
||||
value,
|
||||
activated: new Set(activated.value),
|
||||
children: children.value,
|
||||
parents: parents.value,
|
||||
event
|
||||
});
|
||||
if (newActivated.size !== activated.value.size) {
|
||||
activated.value = newActivated;
|
||||
} else {
|
||||
for (const value of newActivated) {
|
||||
if (!activated.value.has(value)) {
|
||||
activated.value = newActivated;
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (const value of activated.value) {
|
||||
if (!newActivated.has(value)) {
|
||||
activated.value = newActivated;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
children,
|
||||
parents,
|
||||
disabled,
|
||||
getPath
|
||||
}
|
||||
};
|
||||
provide(VNestedSymbol, nested);
|
||||
return nested.root;
|
||||
};
|
||||
export const useNestedItem = (id, isDisabled, isGroup) => {
|
||||
const parent = inject(VNestedSymbol, emptyNested);
|
||||
const uidSymbol = Symbol('nested item');
|
||||
const computedId = computed(() => {
|
||||
const idValue = toRaw(toValue(id));
|
||||
return idValue !== undefined ? idValue : uidSymbol;
|
||||
});
|
||||
const item = {
|
||||
...parent,
|
||||
id: computedId,
|
||||
open: (open, e) => parent.root.open(computedId.value, open, e),
|
||||
openOnSelect: (open, e) => parent.root.openOnSelect(computedId.value, open, e),
|
||||
isOpen: computed(() => parent.root.opened.value.has(computedId.value)),
|
||||
parent: computed(() => parent.root.parents.value.get(computedId.value)),
|
||||
activate: (activated, e) => parent.root.activate(computedId.value, activated, e),
|
||||
isActivated: computed(() => parent.root.activated.value.has(computedId.value)),
|
||||
scrollToActive: parent.root.scrollToActive,
|
||||
select: (selected, e) => parent.root.select(computedId.value, selected, e),
|
||||
isSelected: computed(() => parent.root.selected.value.get(computedId.value) === 'on'),
|
||||
isIndeterminate: computed(() => parent.root.selected.value.get(computedId.value) === 'indeterminate'),
|
||||
isLeaf: computed(() => !parent.root.children.value.get(computedId.value)),
|
||||
isGroupActivator: parent.isGroupActivator
|
||||
};
|
||||
onBeforeMount(() => {
|
||||
if (parent.isGroupActivator || parent.root.itemsRegistration.value === 'props') return;
|
||||
nextTick(() => {
|
||||
parent.root.register(computedId.value, parent.id.value, toValue(isDisabled), isGroup);
|
||||
});
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
if (parent.isGroupActivator || parent.root.itemsRegistration.value === 'props') return;
|
||||
parent.root.unregister(computedId.value);
|
||||
});
|
||||
watch(computedId, (val, oldVal) => {
|
||||
if (parent.isGroupActivator || parent.root.itemsRegistration.value === 'props') return;
|
||||
parent.root.unregister(oldVal);
|
||||
nextTick(() => {
|
||||
parent.root.register(val, parent.id.value, toValue(isDisabled), isGroup);
|
||||
});
|
||||
});
|
||||
watch(() => toValue(isDisabled), val => {
|
||||
parent.root.updateDisabled(computedId.value, val);
|
||||
});
|
||||
isGroup && provide(VNestedSymbol, item);
|
||||
return item;
|
||||
};
|
||||
export const useNestedGroupActivator = () => {
|
||||
const parent = inject(VNestedSymbol, emptyNested);
|
||||
provide(VNestedSymbol, {
|
||||
...parent,
|
||||
isGroupActivator: true
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=nested.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+25
@@ -0,0 +1,25 @@
|
||||
type OpenStrategyFunction = (data: {
|
||||
id: unknown;
|
||||
value: boolean;
|
||||
opened: Set<unknown>;
|
||||
children: Map<unknown, unknown[]>;
|
||||
parents: Map<unknown, unknown>;
|
||||
event?: Event;
|
||||
}) => Set<unknown>;
|
||||
type OpenSelectStrategyFunction = (data: {
|
||||
id: unknown;
|
||||
value: boolean;
|
||||
opened: Set<unknown>;
|
||||
selected: Map<unknown, 'on' | 'off' | 'indeterminate'>;
|
||||
children: Map<unknown, unknown[]>;
|
||||
parents: Map<unknown, unknown>;
|
||||
event?: Event;
|
||||
}) => Set<unknown> | null;
|
||||
export type OpenStrategy = {
|
||||
open: OpenStrategyFunction;
|
||||
select: OpenSelectStrategyFunction;
|
||||
};
|
||||
export declare const singleOpenStrategy: OpenStrategy;
|
||||
export declare const multipleOpenStrategy: OpenStrategy;
|
||||
export declare const listOpenStrategy: OpenStrategy;
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
export const singleOpenStrategy = {
|
||||
open: ({
|
||||
id,
|
||||
value,
|
||||
opened,
|
||||
parents
|
||||
}) => {
|
||||
if (value) {
|
||||
const newOpened = new Set();
|
||||
newOpened.add(id);
|
||||
let parent = parents.get(id);
|
||||
while (parent != null) {
|
||||
newOpened.add(parent);
|
||||
parent = parents.get(parent);
|
||||
}
|
||||
return newOpened;
|
||||
} else {
|
||||
opened.delete(id);
|
||||
return opened;
|
||||
}
|
||||
},
|
||||
select: () => null
|
||||
};
|
||||
export const multipleOpenStrategy = {
|
||||
open: ({
|
||||
id,
|
||||
value,
|
||||
opened,
|
||||
parents
|
||||
}) => {
|
||||
if (value) {
|
||||
let parent = parents.get(id);
|
||||
opened.add(id);
|
||||
while (parent != null && parent !== id) {
|
||||
opened.add(parent);
|
||||
parent = parents.get(parent);
|
||||
}
|
||||
return opened;
|
||||
} else {
|
||||
opened.delete(id);
|
||||
}
|
||||
return opened;
|
||||
},
|
||||
select: () => null
|
||||
};
|
||||
export const listOpenStrategy = {
|
||||
open: multipleOpenStrategy.open,
|
||||
select: ({
|
||||
id,
|
||||
value,
|
||||
opened,
|
||||
parents
|
||||
}) => {
|
||||
if (!value) return opened;
|
||||
const path = [];
|
||||
let parent = parents.get(id);
|
||||
while (parent != null) {
|
||||
path.push(parent);
|
||||
parent = parents.get(parent);
|
||||
}
|
||||
return new Set(path);
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=openStrategies.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"openStrategies.js","names":["singleOpenStrategy","open","id","value","opened","parents","newOpened","Set","add","parent","get","delete","select","multipleOpenStrategy","listOpenStrategy","path","push"],"sources":["../../../src/composables/nested/openStrategies.ts"],"sourcesContent":["type OpenStrategyFunction = (data: {\n id: unknown\n value: boolean\n opened: Set<unknown>\n children: Map<unknown, unknown[]>\n parents: Map<unknown, unknown>\n event?: Event\n}) => Set<unknown>\n\ntype OpenSelectStrategyFunction = (data: {\n id: unknown\n value: boolean\n opened: Set<unknown>\n selected: Map<unknown, 'on' | 'off' | 'indeterminate'>\n children: Map<unknown, unknown[]>\n parents: Map<unknown, unknown>\n event?: Event\n}) => Set<unknown> | null\n\nexport type OpenStrategy = {\n open: OpenStrategyFunction\n select: OpenSelectStrategyFunction\n}\n\nexport const singleOpenStrategy: OpenStrategy = {\n open: ({ id, value, opened, parents }) => {\n if (value) {\n const newOpened = new Set<unknown>()\n newOpened.add(id)\n\n let parent = parents.get(id)\n\n while (parent != null) {\n newOpened.add(parent)\n parent = parents.get(parent)\n }\n\n return newOpened\n } else {\n opened.delete(id)\n return opened\n }\n },\n select: () => null,\n}\n\nexport const multipleOpenStrategy: OpenStrategy = {\n open: ({ id, value, opened, parents }) => {\n if (value) {\n let parent = parents.get(id)\n opened.add(id)\n\n while (parent != null && parent !== id) {\n opened.add(parent)\n parent = parents.get(parent)\n }\n\n return opened\n } else {\n opened.delete(id)\n }\n return opened\n },\n select: () => null,\n}\n\nexport const listOpenStrategy: OpenStrategy = {\n open: multipleOpenStrategy.open,\n select: ({ id, value, opened, parents }) => {\n if (!value) return opened\n\n const path: unknown[] = []\n\n let parent = parents.get(id)\n\n while (parent != null) {\n path.push(parent)\n parent = parents.get(parent)\n }\n\n return new Set(path)\n },\n}\n"],"mappings":"AAwBA,OAAO,MAAMA,kBAAgC,GAAG;EAC9CC,IAAI,EAAEA,CAAC;IAAEC,EAAE;IAAEC,KAAK;IAAEC,MAAM;IAAEC;EAAQ,CAAC,KAAK;IACxC,IAAIF,KAAK,EAAE;MACT,MAAMG,SAAS,GAAG,IAAIC,GAAG,CAAU,CAAC;MACpCD,SAAS,CAACE,GAAG,CAACN,EAAE,CAAC;MAEjB,IAAIO,MAAM,GAAGJ,OAAO,CAACK,GAAG,CAACR,EAAE,CAAC;MAE5B,OAAOO,MAAM,IAAI,IAAI,EAAE;QACrBH,SAAS,CAACE,GAAG,CAACC,MAAM,CAAC;QACrBA,MAAM,GAAGJ,OAAO,CAACK,GAAG,CAACD,MAAM,CAAC;MAC9B;MAEA,OAAOH,SAAS;IAClB,CAAC,MAAM;MACLF,MAAM,CAACO,MAAM,CAACT,EAAE,CAAC;MACjB,OAAOE,MAAM;IACf;EACF,CAAC;EACDQ,MAAM,EAAEA,CAAA,KAAM;AAChB,CAAC;AAED,OAAO,MAAMC,oBAAkC,GAAG;EAChDZ,IAAI,EAAEA,CAAC;IAAEC,EAAE;IAAEC,KAAK;IAAEC,MAAM;IAAEC;EAAQ,CAAC,KAAK;IACxC,IAAIF,KAAK,EAAE;MACT,IAAIM,MAAM,GAAGJ,OAAO,CAACK,GAAG,CAACR,EAAE,CAAC;MAC5BE,MAAM,CAACI,GAAG,CAACN,EAAE,CAAC;MAEd,OAAOO,MAAM,IAAI,IAAI,IAAIA,MAAM,KAAKP,EAAE,EAAE;QACtCE,MAAM,CAACI,GAAG,CAACC,MAAM,CAAC;QAClBA,MAAM,GAAGJ,OAAO,CAACK,GAAG,CAACD,MAAM,CAAC;MAC9B;MAEA,OAAOL,MAAM;IACf,CAAC,MAAM;MACLA,MAAM,CAACO,MAAM,CAACT,EAAE,CAAC;IACnB;IACA,OAAOE,MAAM;EACf,CAAC;EACDQ,MAAM,EAAEA,CAAA,KAAM;AAChB,CAAC;AAED,OAAO,MAAME,gBAA8B,GAAG;EAC5Cb,IAAI,EAAEY,oBAAoB,CAACZ,IAAI;EAC/BW,MAAM,EAAEA,CAAC;IAAEV,EAAE;IAAEC,KAAK;IAAEC,MAAM;IAAEC;EAAQ,CAAC,KAAK;IAC1C,IAAI,CAACF,KAAK,EAAE,OAAOC,MAAM;IAEzB,MAAMW,IAAe,GAAG,EAAE;IAE1B,IAAIN,MAAM,GAAGJ,OAAO,CAACK,GAAG,CAACR,EAAE,CAAC;IAE5B,OAAOO,MAAM,IAAI,IAAI,EAAE;MACrBM,IAAI,CAACC,IAAI,CAACP,MAAM,CAAC;MACjBA,MAAM,GAAGJ,OAAO,CAACK,GAAG,CAACD,MAAM,CAAC;IAC9B;IAEA,OAAO,IAAIF,GAAG,CAACQ,IAAI,CAAC;EACtB;AACF,CAAC","ignoreList":[]}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
type SelectStrategyFunction = (data: {
|
||||
id: unknown;
|
||||
value: boolean;
|
||||
selected: Map<unknown, 'on' | 'off' | 'indeterminate'>;
|
||||
children: Map<unknown, unknown[]>;
|
||||
parents: Map<unknown, unknown>;
|
||||
disabled: Set<unknown>;
|
||||
event?: Event;
|
||||
}) => Map<unknown, 'on' | 'off' | 'indeterminate'>;
|
||||
type SelectStrategyTransformInFunction = (v: readonly unknown[] | undefined, children: Map<unknown, unknown[]>, parents: Map<unknown, unknown>, disabled: Set<unknown>) => Map<unknown, 'on' | 'off' | 'indeterminate'>;
|
||||
type SelectStrategyTransformOutFunction = (v: Map<unknown, 'on' | 'off' | 'indeterminate'>, children: Map<unknown, unknown[]>, parents: Map<unknown, unknown>) => unknown[];
|
||||
export type SelectStrategy = {
|
||||
select: SelectStrategyFunction;
|
||||
in: SelectStrategyTransformInFunction;
|
||||
out: SelectStrategyTransformOutFunction;
|
||||
};
|
||||
export declare const independentSelectStrategy: (mandatory?: boolean) => SelectStrategy;
|
||||
export declare const independentSingleSelectStrategy: (mandatory?: boolean) => SelectStrategy;
|
||||
export declare const leafSelectStrategy: (mandatory?: boolean) => SelectStrategy;
|
||||
export declare const leafSingleSelectStrategy: (mandatory?: boolean) => SelectStrategy;
|
||||
export declare const classicSelectStrategy: (mandatory?: boolean) => SelectStrategy;
|
||||
export declare const trunkSelectStrategy: (mandatory?: boolean) => SelectStrategy;
|
||||
export declare const branchSelectStrategy: (mandatory?: boolean) => SelectStrategy;
|
||||
|
||||
+247
@@ -0,0 +1,247 @@
|
||||
/* eslint-disable sonarjs/no-identical-functions */
|
||||
// Utilities
|
||||
import { toRaw } from 'vue';
|
||||
export const independentSelectStrategy = mandatory => {
|
||||
const strategy = {
|
||||
select: ({
|
||||
id,
|
||||
value,
|
||||
selected
|
||||
}) => {
|
||||
id = toRaw(id);
|
||||
|
||||
// When mandatory and we're trying to deselect when id
|
||||
// is the only currently selected item then do nothing
|
||||
if (mandatory && !value) {
|
||||
const on = Array.from(selected.entries()).reduce((arr, [key, value]) => {
|
||||
if (value === 'on') arr.push(key);
|
||||
return arr;
|
||||
}, []);
|
||||
if (on.length === 1 && on[0] === id) return selected;
|
||||
}
|
||||
selected.set(id, value ? 'on' : 'off');
|
||||
return selected;
|
||||
},
|
||||
in: (v, children, parents, disabled) => {
|
||||
const map = new Map();
|
||||
for (const id of v || []) {
|
||||
strategy.select({
|
||||
id,
|
||||
value: true,
|
||||
selected: map,
|
||||
children,
|
||||
parents,
|
||||
disabled
|
||||
});
|
||||
}
|
||||
return map;
|
||||
},
|
||||
out: v => {
|
||||
const arr = [];
|
||||
for (const [key, value] of v.entries()) {
|
||||
if (value === 'on') arr.push(key);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
};
|
||||
return strategy;
|
||||
};
|
||||
export const independentSingleSelectStrategy = mandatory => {
|
||||
const parentStrategy = independentSelectStrategy(mandatory);
|
||||
const strategy = {
|
||||
select: ({
|
||||
selected,
|
||||
id,
|
||||
...rest
|
||||
}) => {
|
||||
id = toRaw(id);
|
||||
const singleSelected = selected.has(id) ? new Map([[id, selected.get(id)]]) : new Map();
|
||||
return parentStrategy.select({
|
||||
...rest,
|
||||
id,
|
||||
selected: singleSelected
|
||||
});
|
||||
},
|
||||
in: (v, children, parents, disabled) => {
|
||||
if (v?.length) {
|
||||
return parentStrategy.in(v.slice(0, 1), children, parents, disabled);
|
||||
}
|
||||
return new Map();
|
||||
},
|
||||
out: (v, children, parents) => {
|
||||
return parentStrategy.out(v, children, parents);
|
||||
}
|
||||
};
|
||||
return strategy;
|
||||
};
|
||||
export const leafSelectStrategy = mandatory => {
|
||||
const parentStrategy = independentSelectStrategy(mandatory);
|
||||
const strategy = {
|
||||
select: ({
|
||||
id,
|
||||
selected,
|
||||
children,
|
||||
...rest
|
||||
}) => {
|
||||
id = toRaw(id);
|
||||
if (children.has(id)) return selected;
|
||||
return parentStrategy.select({
|
||||
id,
|
||||
selected,
|
||||
children,
|
||||
...rest
|
||||
});
|
||||
},
|
||||
in: parentStrategy.in,
|
||||
out: parentStrategy.out
|
||||
};
|
||||
return strategy;
|
||||
};
|
||||
export const leafSingleSelectStrategy = mandatory => {
|
||||
const parentStrategy = independentSingleSelectStrategy(mandatory);
|
||||
const strategy = {
|
||||
select: ({
|
||||
id,
|
||||
selected,
|
||||
children,
|
||||
...rest
|
||||
}) => {
|
||||
id = toRaw(id);
|
||||
if (children.has(id)) return selected;
|
||||
return parentStrategy.select({
|
||||
id,
|
||||
selected,
|
||||
children,
|
||||
...rest
|
||||
});
|
||||
},
|
||||
in: parentStrategy.in,
|
||||
out: parentStrategy.out
|
||||
};
|
||||
return strategy;
|
||||
};
|
||||
export const classicSelectStrategy = mandatory => {
|
||||
const strategy = {
|
||||
select: ({
|
||||
id,
|
||||
value,
|
||||
selected,
|
||||
children,
|
||||
parents,
|
||||
disabled
|
||||
}) => {
|
||||
id = toRaw(id);
|
||||
const original = new Map(selected);
|
||||
const items = [id];
|
||||
while (items.length) {
|
||||
const item = items.shift();
|
||||
if (!disabled.has(item)) {
|
||||
selected.set(toRaw(item), value ? 'on' : 'off');
|
||||
}
|
||||
if (children.has(item)) {
|
||||
items.push(...children.get(item));
|
||||
}
|
||||
}
|
||||
let parent = toRaw(parents.get(id));
|
||||
while (parent) {
|
||||
let everySelected = true;
|
||||
let noneSelected = true;
|
||||
for (const child of children.get(parent)) {
|
||||
const cid = toRaw(child);
|
||||
if (disabled.has(cid)) continue;
|
||||
if (selected.get(cid) !== 'on') everySelected = false;
|
||||
if (selected.has(cid) && selected.get(cid) !== 'off') noneSelected = false;
|
||||
if (!everySelected && !noneSelected) break;
|
||||
}
|
||||
selected.set(parent, everySelected ? 'on' : noneSelected ? 'off' : 'indeterminate');
|
||||
parent = toRaw(parents.get(parent));
|
||||
}
|
||||
|
||||
// If mandatory and planned deselect results in no selected
|
||||
// items then we can't do it, so return original state
|
||||
if (mandatory && !value) {
|
||||
const on = Array.from(selected.entries()).reduce((arr, [key, value]) => {
|
||||
if (value === 'on') arr.push(key);
|
||||
return arr;
|
||||
}, []);
|
||||
if (on.length === 0) return original;
|
||||
}
|
||||
return selected;
|
||||
},
|
||||
in: (v, children, parents) => {
|
||||
let map = new Map();
|
||||
for (const id of v || []) {
|
||||
map = strategy.select({
|
||||
id,
|
||||
value: true,
|
||||
selected: map,
|
||||
children,
|
||||
parents,
|
||||
disabled: new Set()
|
||||
});
|
||||
}
|
||||
return map;
|
||||
},
|
||||
out: (v, children) => {
|
||||
const arr = [];
|
||||
for (const [key, value] of v.entries()) {
|
||||
if (value === 'on' && !children.has(key)) arr.push(key);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
};
|
||||
return strategy;
|
||||
};
|
||||
export const trunkSelectStrategy = mandatory => {
|
||||
const parentStrategy = classicSelectStrategy(mandatory);
|
||||
const strategy = {
|
||||
select: parentStrategy.select,
|
||||
in: parentStrategy.in,
|
||||
out: (v, children, parents) => {
|
||||
const arr = [];
|
||||
for (const [key, value] of v.entries()) {
|
||||
if (value === 'on') {
|
||||
if (parents.has(key)) {
|
||||
const parent = parents.get(key);
|
||||
if (v.get(parent) === 'on') continue;
|
||||
}
|
||||
arr.push(key);
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
};
|
||||
return strategy;
|
||||
};
|
||||
export const branchSelectStrategy = mandatory => {
|
||||
const parentStrategy = classicSelectStrategy(mandatory);
|
||||
const strategy = {
|
||||
select: parentStrategy.select,
|
||||
in: (v, children, parents, disabled) => {
|
||||
let map = new Map();
|
||||
for (const id of v || []) {
|
||||
if (children.has(id)) continue;
|
||||
map = strategy.select({
|
||||
id,
|
||||
value: true,
|
||||
selected: map,
|
||||
children,
|
||||
parents,
|
||||
disabled
|
||||
});
|
||||
}
|
||||
return map;
|
||||
},
|
||||
out: v => {
|
||||
const arr = [];
|
||||
for (const [key, value] of v.entries()) {
|
||||
if (value === 'on' || value === 'indeterminate') {
|
||||
arr.push(key);
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
};
|
||||
return strategy;
|
||||
};
|
||||
//# sourceMappingURL=selectStrategies.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user