Enable users to define which node types can be selected when TypedInput's type is node

I have a use case where it is necessary to limit the node types that can be selected when TypedInput's type is node. To enable this, my proposal is to include of a new filter prop to typedInput that will be used to prevent users from selecting nodes that are not valid during the selection stage. When a node of a specific type isn't valid, it should not react on mouse events, like onhover or onclick

It can be an array containing the node types

$(elm).typedInput({
    default: "node",
    types: ["node"],
    node: {
       filter: ["type-a", "type-b"]
    }
})

or a function that returns an array of node types

$(elm).typedInput({
    default: "node",
    types: ["node"],
    node: {
       filter:  () => ["type-a", "type-b"]
    }
})

It can be done easily :wink:

But with the following format:

$(elm).typedInput({
    default: "node",
    types: ["node"],
    filter:  (node) => ["type-a", "type-b"].includes(node.type)
})

Not sure that's right. The node typedInput type doesn't support a filter option (not needed one). But would be reasonable to add. @AllanOricil please do raise a feature request issue on the repo so it doesn't got forgotten.

I meant that it can be supported with that format.

@knolleary, if you accept the format, I can directly create the PR :slightly_smiling_face:

I tried to open a feature in the repo but github sends me to this app

The main issue here is we don't have any other examples where additional options are provided for one specific type (node in this case) - where the type is a built-in one specified by its name.

So we have to come up with an api design that works more generally.

I suspect that may be why @AllanOricil nested the option under a top level node property - to indicate these are additional options for the node type. I think that makes sense to follow.

I tried to open a feature in the repo but github sends me to this app

You can use the 'Blank Issue' option to raise an issue - and link back to this thread to show it has been discussed.

1 Like

Ok, to be more consistent the prototype will be:

filter: string;            // must be a node type
filter: string[];          // must be a list of node type
filter: (node) => boolean; // function
1 Like

That was the idea

I liked it

2 Likes

You are fast @GogoVega !

1 Like