123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- /* eslint-disable sonarjs/no-identical-functions */
- // Utilities
- import { toRaw } from 'vue';
- import { wrapInArray } from "../../util/index.mjs";
- 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.mjs.map
|