* Find the objects that have been added via `addSelectable` * whose css selector is contained in the given css selector. * @param cssSelector A css selector * @param matchedCallback This callback will be called with the object handed into `addSelectable` * @return boolean true if a match
(
cssSelector: CssSelector,
matchedCallback: ((c: CssSelector, a: T) => void) | null,
)
| 338 | * @return boolean true if a match was found |
| 339 | */ |
| 340 | match( |
| 341 | cssSelector: CssSelector, |
| 342 | matchedCallback: ((c: CssSelector, a: T) => void) | null, |
| 343 | ): boolean { |
| 344 | let result = false; |
| 345 | const element = cssSelector.element!; |
| 346 | const classNames = cssSelector.classNames; |
| 347 | const attrs = cssSelector.attrs; |
| 348 | |
| 349 | for (let i = 0; i < this._listContexts.length; i++) { |
| 350 | this._listContexts[i].alreadyMatched = false; |
| 351 | } |
| 352 | |
| 353 | result = this._matchTerminal(this._elementMap, element, cssSelector, matchedCallback) || result; |
| 354 | result = |
| 355 | this._matchPartial(this._elementPartialMap, element, cssSelector, matchedCallback) || result; |
| 356 | |
| 357 | if (classNames) { |
| 358 | for (let i = 0; i < classNames.length; i++) { |
| 359 | const className = classNames[i]; |
| 360 | result = |
| 361 | this._matchTerminal(this._classMap, className, cssSelector, matchedCallback) || result; |
| 362 | result = |
| 363 | this._matchPartial(this._classPartialMap, className, cssSelector, matchedCallback) || |
| 364 | result; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | if (attrs) { |
| 369 | for (let i = 0; i < attrs.length; i += 2) { |
| 370 | const name = attrs[i]; |
| 371 | const value = attrs[i + 1]; |
| 372 | |
| 373 | const terminalValuesMap = this._attrValueMap.get(name)!; |
| 374 | if (value) { |
| 375 | result = |
| 376 | this._matchTerminal(terminalValuesMap, '', cssSelector, matchedCallback) || result; |
| 377 | } |
| 378 | result = |
| 379 | this._matchTerminal(terminalValuesMap, value, cssSelector, matchedCallback) || result; |
| 380 | |
| 381 | const partialValuesMap = this._attrValuePartialMap.get(name)!; |
| 382 | if (value) { |
| 383 | result = this._matchPartial(partialValuesMap, '', cssSelector, matchedCallback) || result; |
| 384 | } |
| 385 | result = |
| 386 | this._matchPartial(partialValuesMap, value, cssSelector, matchedCallback) || result; |
| 387 | } |
| 388 | } |
| 389 | return result; |
| 390 | } |
| 391 | |
| 392 | /** @internal */ |
| 393 | _matchTerminal( |