{"size": 1324, "ext": "js", "max_stars_repo_path": "src/js/core/tools/TableRegistry.js", "max_stars_repo_name": "MarkkuPekkarinen/tabulator", "max_stars_repo_stars_event_min_datetime": "2015-11-03T13:57:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:25:56.000Z", "max_issues_repo_path": "src/js/core/tools/TableRegistry.js", "max_issues_repo_name": "MarkkuPekkarinen/tabulator", "max_issues_repo_issues_event_min_datetime": "2015-11-11T17:53:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T23:48:10.000Z", "max_forks_repo_path": "src/js/core/tools/TableRegistry.js", "max_forks_repo_name": "MarkkuPekkarinen/tabulator", "max_forks_repo_forks_event_min_datetime": "2015-11-09T12:04:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T21:26:49.000Z"}
{"max_stars_count": 4596, "max_issues_count": 3598, "max_forks_count": 748, "avg_line_length": 21.3548387097, "max_line_length": 111, "alphanum_fraction": 0.667673716}
import Tabulator from '../Tabulator.js';

class TableRegistry {

	static register(table){
		TableRegistry.tables.push(table);
	}

	static deregister(table){
		var index = TableRegistry.tables.indexOf(table);

		if(index > -1){
			TableRegistry.tables.splice(index, 1);
		}
	}

	static lookupTable(query, silent){
		var results = [],
		matches, match;

		if(typeof query === "string"){
			matches = document.querySelectorAll(query);

			if(matches.length){
				for(var i = 0; i < matches.length; i++){
					match = TableRegistry.matchElement(matches[i]);

					if(match){
						results.push(match);
					}
				}
			}

		}else if((typeof HTMLElement !== "undefined" && query instanceof HTMLElement) || query instanceof Tabulator){
			match = TableRegistry.matchElement(query);

			if(match){
				results.push(match);
			}
		}else if(Array.isArray(query)){
			query.forEach(function(item){
				results = results.concat(TableRegistry.lookupTable(item));
			});
		}else{
			if(!silent){
				console.warn("Table Connection Error - Invalid Selector", query);
			}
		}

		return results;
	}

	static matchElement(element){
		return TableRegistry.tables.find(function(table){
			return element instanceof Tabulator ? table === element : table.element === element;
		});
	}
}

TableRegistry.tables = [];

export default TableRegistry;