UNPKG

vuetify

Version:

Vue Material Component Framework

127 lines (126 loc) 3.06 kB
/* eslint-disable sonarjs/no-identical-functions */ // Utilities import { toRaw } from 'vue'; import { wrapInArray } from "../../util/index.js"; export const independentActiveStrategy = mandatory => { const strategy = { activate: _ref => { let { id, value, activated } = _ref; 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: _ref2 => { let { activated, id, ...rest } = _ref2; 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: _ref3 => { let { id, activated, children, ...rest } = _ref3; 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: _ref4 => { let { id, activated, children, ...rest } = _ref4; 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