Giter Site home page Giter Site logo

Comments (2)

elbywan avatar elbywan commented on August 21, 2024

Hi @jago86,

I need to open multiple folder nodes (multiselection ), but with only one file item selected at the same time.

Do you mean being able to select multiple folders, plus with a maximum of one file selected inside each folder?

If so, I think that you try to use the neighbours arguments in the selection strategy to achieve what you want:

strategies: {
    selection: [
        'multiple',
        (item, selection, neighbours) => {
            // If deselected
            if(!selection.includes(item)) {
                return selection
            }
            if (!item.children && neighbours) {
                return [
                    // Exclude file siblings
                    ...selection.filter(
                        node => node.children || !(neighbours.includes(node))
                    ),
                    item
                ]
            }
            return [
                ...selection,
                item
            ]

        }
    ],
    click: ['select'],
    fold: ['no-child-selection'],
}

I made a little fiddle to demonstrate. Hope that will help!

from bosket.

jago86 avatar jago86 commented on August 21, 2024

Thanks @elbywan !! Is more or less what I want. I added some changes to adjust to my needs:

strategies() {
    return {
        selection: [
            'multiple',
            (item, selection, neighbours, ancestors) => {
                // If deselected
                if(!selection.includes(item)) {
                    return [
                        ...selection,
                        ...ancestors,
                    ];
                }

                return [
                    // Exclude file siblings
                    ...selection.filter(
                        node => node.children || !(neighbours.includes(node))
                    ),
                    // Include item itself
                    item,
                    // Include the ancestors
                    ...ancestors
                ];

          },

          (item, selection, neighbours, ancestors) => {
            // If deselected
            if(!selection.includes(item)) {
                // If deselected item is a file, don't allow deselection
                if(!item.children) {
                    return [
                        ...selection,
                        item,
                    ];
                }

                // If deselected item is a folder, exclude their children
                if (item.children) {

                    return [
                        ...selection.filter((node) => {
                            return !item.children.includes( node );
                        }),
                    ];
                }
            }

            return selection;
          },

        ],
        click: ['select'],
        fold: [
            // 'not-selected',
            'no-child-selection',
        ]
    };
}

Thanks a lot

from bosket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.