Getting the next possible child for a node only return required

I have a custom schema with these nodes

nodes: {
  doc: {
      content: "topic"
  },
  topic: {
      content: "title shortdesc? prolog? body?"
  },
  title: {
      content: "text"
  }
}

When I try to get the possible children for a nodeType like topic using nodeType.contentMatch.edge it will only returned the required title node and ignore the rest.

Is there a way around this or a way to get all possible content from the schema aside from contentMatch?

A content match represents a position in the node’s content expression. nodeType.contentMatch will give you the position at the start which, in your case, indeed only allows title. You can move forward past the title by following that edge, to get a match position that allows shortdesc, prolog, or body.

1 Like

Thanks @marijn for the quick reply, sorry for the nuisance but can you expand on You can move forward past the title by following that edge?

I assume you mean the next function on the contentMatch, but since that function is not part of the documentation I hesitated to use it.

As for nodeType.contentMatch, when it comes to the topic nodes it’s count is only 1 :

if(nodeType.name === 'topic') {
    const edgeCount = nodeType.contentMatch.edgeCount; // 1

    for(let i = 0; i < edgeCount; i++) {
      const edge = nodeType.contentMatch.edge(i);
      console.log(edge.type);
    }
// only returns title, contrast to the schema "title shortdesc? prolog? body?"

Each edge has both a type and a destination match.