| 148 | |
| 149 | @observer |
| 150 | export class InsertBox extends React.Component<InsertBoxProps, InsertBoxState> { |
| 151 | private inputRef: React.RefObject<HTMLInputElement> |
| 152 | private suggestionsRef: React.RefObject<HTMLUListElement> |
| 153 | |
| 154 | constructor(props: InsertBoxProps) { |
| 155 | super(props) |
| 156 | this.inputRef = React.createRef() |
| 157 | this.suggestionsRef = React.createRef() |
| 158 | |
| 159 | this.state = { |
| 160 | userInput: '', |
| 161 | autoWidth: this.getWidth(''), |
| 162 | cursorPosition: null, |
| 163 | filteredSuggestions: [], |
| 164 | autocompleters: [], |
| 165 | staticSuggestions: [], |
| 166 | staticSuggestionKeys: new Set(), |
| 167 | activeSuggestion: 0, |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | static getDerivedStateFromProps(props: InsertBoxProps, state: InsertBoxState) { |
| 172 | const { cursorPosition, selection } = props |
| 173 | |
| 174 | if (cursorPosition !== state.cursorPosition) { |
| 175 | const cursors = selection.getAutocompleteNodeCursors() |
| 176 | const staticSuggestions: RenderedSuggestion[] = [] |
| 177 | const autocompleters: CursorAutocompleter[] = [] |
| 178 | const categorySet = new Set<NodeCategory>() |
| 179 | |
| 180 | for (const cursor of cursors) { |
| 181 | const childSetBlock = cursor.listBlock |
| 182 | const category = childSetBlock.childSet.nodeCategory |
| 183 | if (!childSetBlock.allowInsert() || category in categorySet) { |
| 184 | continue |
| 185 | } |
| 186 | |
| 187 | const autocompleter = new CursorAutocompleter(cursor, categorySet) |
| 188 | categorySet.add(category) |
| 189 | getAutocompleteRegistry() |
| 190 | .getAdapatableCategories(category) |
| 191 | .forEach((cat) => categorySet.add(cat)) |
| 192 | autocompleters.push(autocompleter) |
| 193 | staticSuggestions.push(...autocompleter.getStaticSuggestions()) |
| 194 | } |
| 195 | |
| 196 | const staticSuggestionKeys: Set<string> = new Set() |
| 197 | staticSuggestions.forEach((suggestion) => { |
| 198 | staticSuggestionKeys.add(suggestion.key) |
| 199 | }) |
| 200 | |
| 201 | const userInput = selection.state === SelectionState.Cursor ? '' : state.userInput |
| 202 | |
| 203 | return { |
| 204 | filteredSuggestions: [], |
| 205 | userInput: userInput, |
| 206 | cursorPosition: cursorPosition, |
| 207 | staticSuggestions: staticSuggestions, |
nothing calls this directly
no test coverage detected