"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.ObjectComponent = void 0; var _lodash = _interopRequireDefault(require("lodash")); var _2 = require("."); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ /** * @param constants list of components that represent constant keys * @param patternsAndWildCards list of components that represent patterns and should be matched only if * there is no constant matches */ class ObjectComponent extends _2.SharedComponent { constructor(name, constants, patternsAndWildCards) { super(name); this.constants = constants; this.patternsAndWildCards = patternsAndWildCards; } getTerms(context, editor) { const options = []; _lodash.default.each(this.constants, function (component) { options.push.apply(options, component.getTerms(context, editor)); }); _lodash.default.each(this.patternsAndWildCards, function (component) { options.push.apply(options, component.getTerms(context, editor)); }); return options; } match(token, context, editor) { const result = { next: [] }; _lodash.default.each(this.constants, function (component) { const componentResult = component.match(token, context, editor); if (componentResult && componentResult.next) { result.next.push.apply(result.next, componentResult.next); } }); // try to link to GLOBAL rules const globalRules = context.globalComponentResolver(token, false); if (globalRules) { result.next.push.apply(result.next, globalRules); } if (result.next.length) { return result; } _lodash.default.each(this.patternsAndWildCards, function (component) { const componentResult = component.match(token, context, editor); if (componentResult && componentResult.next) { result.next.push.apply(result.next, componentResult.next); } }); return result; } } exports.ObjectComponent = ObjectComponent;