UNPKG

102 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://github.com/material-components/material-components-web/blob/master/LICENSE
7 */
8(function webpackUniversalModuleDefinition(root, factory) {
9 if(typeof exports === 'object' && typeof module === 'object')
10 module.exports = factory();
11 else if(typeof define === 'function' && define.amd)
12 define("@material/list", [], factory);
13 else if(typeof exports === 'object')
14 exports["list"] = factory();
15 else
16 root["mdc"] = root["mdc"] || {}, root["mdc"]["list"] = factory();
17})(this, function() {
18return /******/ (function(modules) { // webpackBootstrap
19/******/ // The module cache
20/******/ var installedModules = {};
21/******/
22/******/ // The require function
23/******/ function __webpack_require__(moduleId) {
24/******/
25/******/ // Check if module is in cache
26/******/ if(installedModules[moduleId]) {
27/******/ return installedModules[moduleId].exports;
28/******/ }
29/******/ // Create a new module (and put it into the cache)
30/******/ var module = installedModules[moduleId] = {
31/******/ i: moduleId,
32/******/ l: false,
33/******/ exports: {}
34/******/ };
35/******/
36/******/ // Execute the module function
37/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
38/******/
39/******/ // Flag the module as loaded
40/******/ module.l = true;
41/******/
42/******/ // Return the exports of the module
43/******/ return module.exports;
44/******/ }
45/******/
46/******/
47/******/ // expose the modules object (__webpack_modules__)
48/******/ __webpack_require__.m = modules;
49/******/
50/******/ // expose the module cache
51/******/ __webpack_require__.c = installedModules;
52/******/
53/******/ // define getter function for harmony exports
54/******/ __webpack_require__.d = function(exports, name, getter) {
55/******/ if(!__webpack_require__.o(exports, name)) {
56/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
57/******/ }
58/******/ };
59/******/
60/******/ // define __esModule on exports
61/******/ __webpack_require__.r = function(exports) {
62/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
63/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
64/******/ }
65/******/ Object.defineProperty(exports, '__esModule', { value: true });
66/******/ };
67/******/
68/******/ // create a fake namespace object
69/******/ // mode & 1: value is a module id, require it
70/******/ // mode & 2: merge all properties of value into the ns
71/******/ // mode & 4: return value when already ns object
72/******/ // mode & 8|1: behave like require
73/******/ __webpack_require__.t = function(value, mode) {
74/******/ if(mode & 1) value = __webpack_require__(value);
75/******/ if(mode & 8) return value;
76/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
77/******/ var ns = Object.create(null);
78/******/ __webpack_require__.r(ns);
79/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
80/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
81/******/ return ns;
82/******/ };
83/******/
84/******/ // getDefaultExport function for compatibility with non-harmony modules
85/******/ __webpack_require__.n = function(module) {
86/******/ var getter = module && module.__esModule ?
87/******/ function getDefault() { return module['default']; } :
88/******/ function getModuleExports() { return module; };
89/******/ __webpack_require__.d(getter, 'a', getter);
90/******/ return getter;
91/******/ };
92/******/
93/******/ // Object.prototype.hasOwnProperty.call
94/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
95/******/
96/******/ // __webpack_public_path__
97/******/ __webpack_require__.p = "";
98/******/
99/******/
100/******/ // Load entry module and return exports
101/******/ return __webpack_require__(__webpack_require__.s = "./packages/mdc-list/index.ts");
102/******/ })
103/************************************************************************/
104/******/ ({
105
106/***/ "./packages/mdc-base/component.ts":
107/*!****************************************!*\
108 !*** ./packages/mdc-base/component.ts ***!
109 \****************************************/
110/*! no static exports found */
111/***/ (function(module, exports, __webpack_require__) {
112
113"use strict";
114
115/**
116 * @license
117 * Copyright 2016 Google Inc.
118 *
119 * Permission is hereby granted, free of charge, to any person obtaining a copy
120 * of this software and associated documentation files (the "Software"), to deal
121 * in the Software without restriction, including without limitation the rights
122 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
123 * copies of the Software, and to permit persons to whom the Software is
124 * furnished to do so, subject to the following conditions:
125 *
126 * The above copyright notice and this permission notice shall be included in
127 * all copies or substantial portions of the Software.
128 *
129 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
130 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
131 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
132 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
133 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
134 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
135 * THE SOFTWARE.
136 */
137
138var __read = this && this.__read || function (o, n) {
139 var m = typeof Symbol === "function" && o[Symbol.iterator];
140 if (!m) return o;
141 var i = m.call(o),
142 r,
143 ar = [],
144 e;
145 try {
146 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
147 ar.push(r.value);
148 }
149 } catch (error) {
150 e = { error: error };
151 } finally {
152 try {
153 if (r && !r.done && (m = i["return"])) m.call(i);
154 } finally {
155 if (e) throw e.error;
156 }
157 }
158 return ar;
159};
160var __spreadArray = this && this.__spreadArray || function (to, from) {
161 for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) {
162 to[j] = from[i];
163 }return to;
164};
165Object.defineProperty(exports, "__esModule", { value: true });
166exports.MDCComponent = void 0;
167var foundation_1 = __webpack_require__(/*! ./foundation */ "./packages/mdc-base/foundation.ts");
168var MDCComponent = /** @class */function () {
169 function MDCComponent(root, foundation) {
170 var args = [];
171 for (var _i = 2; _i < arguments.length; _i++) {
172 args[_i - 2] = arguments[_i];
173 }
174 this.root = root;
175 this.initialize.apply(this, __spreadArray([], __read(args)));
176 // Note that we initialize foundation here and not within the constructor's
177 // default param so that this.root is defined and can be used within the
178 // foundation class.
179 this.foundation = foundation === undefined ? this.getDefaultFoundation() : foundation;
180 this.foundation.init();
181 this.initialSyncWithDOM();
182 }
183 MDCComponent.attachTo = function (root) {
184 // Subclasses which extend MDCBase should provide an attachTo() method that takes a root element and
185 // returns an instantiated component with its root set to that element. Also note that in the cases of
186 // subclasses, an explicit foundation class will not have to be passed in; it will simply be initialized
187 // from getDefaultFoundation().
188 return new MDCComponent(root, new foundation_1.MDCFoundation({}));
189 };
190 /* istanbul ignore next: method param only exists for typing purposes; it does not need to be unit tested */
191 MDCComponent.prototype.initialize = function () {
192 var _args = [];
193 for (var _i = 0; _i < arguments.length; _i++) {
194 _args[_i] = arguments[_i];
195 }
196 // Subclasses can override this to do any additional setup work that would be considered part of a
197 // "constructor". Essentially, it is a hook into the parent constructor before the foundation is
198 // initialized. Any additional arguments besides root and foundation will be passed in here.
199 };
200 MDCComponent.prototype.getDefaultFoundation = function () {
201 // Subclasses must override this method to return a properly configured foundation class for the
202 // component.
203 throw new Error('Subclasses must override getDefaultFoundation to return a properly configured ' + 'foundation class');
204 };
205 MDCComponent.prototype.initialSyncWithDOM = function () {
206 // Subclasses should override this method if they need to perform work to synchronize with a host DOM
207 // object. An example of this would be a form control wrapper that needs to synchronize its internal state
208 // to some property or attribute of the host DOM. Please note: this is *not* the place to perform DOM
209 // reads/writes that would cause layout / paint, as this is called synchronously from within the constructor.
210 };
211 MDCComponent.prototype.destroy = function () {
212 // Subclasses may implement this method to release any resources / deregister any listeners they have
213 // attached. An example of this might be deregistering a resize event from the window object.
214 this.foundation.destroy();
215 };
216 MDCComponent.prototype.listen = function (evtType, handler, options) {
217 this.root.addEventListener(evtType, handler, options);
218 };
219 MDCComponent.prototype.unlisten = function (evtType, handler, options) {
220 this.root.removeEventListener(evtType, handler, options);
221 };
222 /**
223 * Fires a cross-browser-compatible custom event from the component root of the given type, with the given data.
224 */
225 MDCComponent.prototype.emit = function (evtType, evtData, shouldBubble) {
226 if (shouldBubble === void 0) {
227 shouldBubble = false;
228 }
229 var evt;
230 if (typeof CustomEvent === 'function') {
231 evt = new CustomEvent(evtType, {
232 bubbles: shouldBubble,
233 detail: evtData
234 });
235 } else {
236 evt = document.createEvent('CustomEvent');
237 evt.initCustomEvent(evtType, shouldBubble, false, evtData);
238 }
239 this.root.dispatchEvent(evt);
240 };
241 return MDCComponent;
242}();
243exports.MDCComponent = MDCComponent;
244// tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
245exports.default = MDCComponent;
246
247/***/ }),
248
249/***/ "./packages/mdc-base/foundation.ts":
250/*!*****************************************!*\
251 !*** ./packages/mdc-base/foundation.ts ***!
252 \*****************************************/
253/*! no static exports found */
254/***/ (function(module, exports, __webpack_require__) {
255
256"use strict";
257
258/**
259 * @license
260 * Copyright 2016 Google Inc.
261 *
262 * Permission is hereby granted, free of charge, to any person obtaining a copy
263 * of this software and associated documentation files (the "Software"), to deal
264 * in the Software without restriction, including without limitation the rights
265 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
266 * copies of the Software, and to permit persons to whom the Software is
267 * furnished to do so, subject to the following conditions:
268 *
269 * The above copyright notice and this permission notice shall be included in
270 * all copies or substantial portions of the Software.
271 *
272 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
273 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
274 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
275 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
276 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
277 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
278 * THE SOFTWARE.
279 */
280
281Object.defineProperty(exports, "__esModule", { value: true });
282exports.MDCFoundation = void 0;
283var MDCFoundation = /** @class */function () {
284 function MDCFoundation(adapter) {
285 if (adapter === void 0) {
286 adapter = {};
287 }
288 this.adapter = adapter;
289 }
290 Object.defineProperty(MDCFoundation, "cssClasses", {
291 get: function get() {
292 // Classes extending MDCFoundation should implement this method to return an object which exports every
293 // CSS class the foundation class needs as a property. e.g. {ACTIVE: 'mdc-component--active'}
294 return {};
295 },
296 enumerable: false,
297 configurable: true
298 });
299 Object.defineProperty(MDCFoundation, "strings", {
300 get: function get() {
301 // Classes extending MDCFoundation should implement this method to return an object which exports all
302 // semantic strings as constants. e.g. {ARIA_ROLE: 'tablist'}
303 return {};
304 },
305 enumerable: false,
306 configurable: true
307 });
308 Object.defineProperty(MDCFoundation, "numbers", {
309 get: function get() {
310 // Classes extending MDCFoundation should implement this method to return an object which exports all
311 // of its semantic numbers as constants. e.g. {ANIMATION_DELAY_MS: 350}
312 return {};
313 },
314 enumerable: false,
315 configurable: true
316 });
317 Object.defineProperty(MDCFoundation, "defaultAdapter", {
318 get: function get() {
319 // Classes extending MDCFoundation may choose to implement this getter in order to provide a convenient
320 // way of viewing the necessary methods of an adapter. In the future, this could also be used for adapter
321 // validation.
322 return {};
323 },
324 enumerable: false,
325 configurable: true
326 });
327 MDCFoundation.prototype.init = function () {
328 // Subclasses should override this method to perform initialization routines (registering events, etc.)
329 };
330 MDCFoundation.prototype.destroy = function () {
331 // Subclasses should override this method to perform de-initialization routines (de-registering events, etc.)
332 };
333 return MDCFoundation;
334}();
335exports.MDCFoundation = MDCFoundation;
336// tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
337exports.default = MDCFoundation;
338
339/***/ }),
340
341/***/ "./packages/mdc-dom/keyboard.ts":
342/*!**************************************!*\
343 !*** ./packages/mdc-dom/keyboard.ts ***!
344 \**************************************/
345/*! no static exports found */
346/***/ (function(module, exports, __webpack_require__) {
347
348"use strict";
349
350/**
351 * @license
352 * Copyright 2020 Google Inc.
353 *
354 * Permission is hereby granted, free of charge, to any person obtaining a copy
355 * of this software and associated documentation files (the "Software"), to deal
356 * in the Software without restriction, including without limitation the rights
357 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
358 * copies of the Software, and to permit persons to whom the Software is
359 * furnished to do so, subject to the following conditions:
360 *
361 * The above copyright notice and this permission notice shall be included in
362 * all copies or substantial portions of the Software.
363 *
364 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
365 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
366 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
367 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
368 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
369 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
370 * THE SOFTWARE.
371 */
372
373Object.defineProperty(exports, "__esModule", { value: true });
374exports.isNavigationEvent = exports.normalizeKey = exports.KEY = void 0;
375/**
376 * KEY provides normalized string values for keys.
377 */
378exports.KEY = {
379 UNKNOWN: 'Unknown',
380 BACKSPACE: 'Backspace',
381 ENTER: 'Enter',
382 SPACEBAR: 'Spacebar',
383 PAGE_UP: 'PageUp',
384 PAGE_DOWN: 'PageDown',
385 END: 'End',
386 HOME: 'Home',
387 ARROW_LEFT: 'ArrowLeft',
388 ARROW_UP: 'ArrowUp',
389 ARROW_RIGHT: 'ArrowRight',
390 ARROW_DOWN: 'ArrowDown',
391 DELETE: 'Delete',
392 ESCAPE: 'Escape',
393 TAB: 'Tab'
394};
395var normalizedKeys = new Set();
396// IE11 has no support for new Map with iterable so we need to initialize this
397// by hand.
398normalizedKeys.add(exports.KEY.BACKSPACE);
399normalizedKeys.add(exports.KEY.ENTER);
400normalizedKeys.add(exports.KEY.SPACEBAR);
401normalizedKeys.add(exports.KEY.PAGE_UP);
402normalizedKeys.add(exports.KEY.PAGE_DOWN);
403normalizedKeys.add(exports.KEY.END);
404normalizedKeys.add(exports.KEY.HOME);
405normalizedKeys.add(exports.KEY.ARROW_LEFT);
406normalizedKeys.add(exports.KEY.ARROW_UP);
407normalizedKeys.add(exports.KEY.ARROW_RIGHT);
408normalizedKeys.add(exports.KEY.ARROW_DOWN);
409normalizedKeys.add(exports.KEY.DELETE);
410normalizedKeys.add(exports.KEY.ESCAPE);
411normalizedKeys.add(exports.KEY.TAB);
412var KEY_CODE = {
413 BACKSPACE: 8,
414 ENTER: 13,
415 SPACEBAR: 32,
416 PAGE_UP: 33,
417 PAGE_DOWN: 34,
418 END: 35,
419 HOME: 36,
420 ARROW_LEFT: 37,
421 ARROW_UP: 38,
422 ARROW_RIGHT: 39,
423 ARROW_DOWN: 40,
424 DELETE: 46,
425 ESCAPE: 27,
426 TAB: 9
427};
428var mappedKeyCodes = new Map();
429// IE11 has no support for new Map with iterable so we need to initialize this
430// by hand.
431mappedKeyCodes.set(KEY_CODE.BACKSPACE, exports.KEY.BACKSPACE);
432mappedKeyCodes.set(KEY_CODE.ENTER, exports.KEY.ENTER);
433mappedKeyCodes.set(KEY_CODE.SPACEBAR, exports.KEY.SPACEBAR);
434mappedKeyCodes.set(KEY_CODE.PAGE_UP, exports.KEY.PAGE_UP);
435mappedKeyCodes.set(KEY_CODE.PAGE_DOWN, exports.KEY.PAGE_DOWN);
436mappedKeyCodes.set(KEY_CODE.END, exports.KEY.END);
437mappedKeyCodes.set(KEY_CODE.HOME, exports.KEY.HOME);
438mappedKeyCodes.set(KEY_CODE.ARROW_LEFT, exports.KEY.ARROW_LEFT);
439mappedKeyCodes.set(KEY_CODE.ARROW_UP, exports.KEY.ARROW_UP);
440mappedKeyCodes.set(KEY_CODE.ARROW_RIGHT, exports.KEY.ARROW_RIGHT);
441mappedKeyCodes.set(KEY_CODE.ARROW_DOWN, exports.KEY.ARROW_DOWN);
442mappedKeyCodes.set(KEY_CODE.DELETE, exports.KEY.DELETE);
443mappedKeyCodes.set(KEY_CODE.ESCAPE, exports.KEY.ESCAPE);
444mappedKeyCodes.set(KEY_CODE.TAB, exports.KEY.TAB);
445var navigationKeys = new Set();
446// IE11 has no support for new Set with iterable so we need to initialize this
447// by hand.
448navigationKeys.add(exports.KEY.PAGE_UP);
449navigationKeys.add(exports.KEY.PAGE_DOWN);
450navigationKeys.add(exports.KEY.END);
451navigationKeys.add(exports.KEY.HOME);
452navigationKeys.add(exports.KEY.ARROW_LEFT);
453navigationKeys.add(exports.KEY.ARROW_UP);
454navigationKeys.add(exports.KEY.ARROW_RIGHT);
455navigationKeys.add(exports.KEY.ARROW_DOWN);
456/**
457 * normalizeKey returns the normalized string for a navigational action.
458 */
459function normalizeKey(evt) {
460 var key = evt.key;
461 // If the event already has a normalized key, return it
462 if (normalizedKeys.has(key)) {
463 return key;
464 }
465 // tslint:disable-next-line:deprecation
466 var mappedKey = mappedKeyCodes.get(evt.keyCode);
467 if (mappedKey) {
468 return mappedKey;
469 }
470 return exports.KEY.UNKNOWN;
471}
472exports.normalizeKey = normalizeKey;
473/**
474 * isNavigationEvent returns whether the event is a navigation event
475 */
476function isNavigationEvent(evt) {
477 return navigationKeys.has(normalizeKey(evt));
478}
479exports.isNavigationEvent = isNavigationEvent;
480
481/***/ }),
482
483/***/ "./packages/mdc-dom/ponyfill.ts":
484/*!**************************************!*\
485 !*** ./packages/mdc-dom/ponyfill.ts ***!
486 \**************************************/
487/*! no static exports found */
488/***/ (function(module, exports, __webpack_require__) {
489
490"use strict";
491
492/**
493 * @license
494 * Copyright 2018 Google Inc.
495 *
496 * Permission is hereby granted, free of charge, to any person obtaining a copy
497 * of this software and associated documentation files (the "Software"), to deal
498 * in the Software without restriction, including without limitation the rights
499 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
500 * copies of the Software, and to permit persons to whom the Software is
501 * furnished to do so, subject to the following conditions:
502 *
503 * The above copyright notice and this permission notice shall be included in
504 * all copies or substantial portions of the Software.
505 *
506 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
507 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
508 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
509 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
510 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
511 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
512 * THE SOFTWARE.
513 */
514
515Object.defineProperty(exports, "__esModule", { value: true });
516exports.estimateScrollWidth = exports.matches = exports.closest = void 0;
517/**
518 * @fileoverview A "ponyfill" is a polyfill that doesn't modify the global prototype chain.
519 * This makes ponyfills safer than traditional polyfills, especially for libraries like MDC.
520 */
521function closest(element, selector) {
522 if (element.closest) {
523 return element.closest(selector);
524 }
525 var el = element;
526 while (el) {
527 if (matches(el, selector)) {
528 return el;
529 }
530 el = el.parentElement;
531 }
532 return null;
533}
534exports.closest = closest;
535function matches(element, selector) {
536 var nativeMatches = element.matches || element.webkitMatchesSelector || element.msMatchesSelector;
537 return nativeMatches.call(element, selector);
538}
539exports.matches = matches;
540/**
541 * Used to compute the estimated scroll width of elements. When an element is
542 * hidden due to display: none; being applied to a parent element, the width is
543 * returned as 0. However, the element will have a true width once no longer
544 * inside a display: none context. This method computes an estimated width when
545 * the element is hidden or returns the true width when the element is visble.
546 * @param {Element} element the element whose width to estimate
547 */
548function estimateScrollWidth(element) {
549 // Check the offsetParent. If the element inherits display: none from any
550 // parent, the offsetParent property will be null (see
551 // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent).
552 // This check ensures we only clone the node when necessary.
553 var htmlEl = element;
554 if (htmlEl.offsetParent !== null) {
555 return htmlEl.scrollWidth;
556 }
557 var clone = htmlEl.cloneNode(true);
558 clone.style.setProperty('position', 'absolute');
559 clone.style.setProperty('transform', 'translate(-9999px, -9999px)');
560 document.documentElement.appendChild(clone);
561 var scrollWidth = clone.scrollWidth;
562 document.documentElement.removeChild(clone);
563 return scrollWidth;
564}
565exports.estimateScrollWidth = estimateScrollWidth;
566
567/***/ }),
568
569/***/ "./packages/mdc-list/adapter.ts":
570/*!**************************************!*\
571 !*** ./packages/mdc-list/adapter.ts ***!
572 \**************************************/
573/*! no static exports found */
574/***/ (function(module, exports, __webpack_require__) {
575
576"use strict";
577
578/**
579 * @license
580 * Copyright 2018 Google Inc.
581 *
582 * Permission is hereby granted, free of charge, to any person obtaining a copy
583 * of this software and associated documentation files (the "Software"), to deal
584 * in the Software without restriction, including without limitation the rights
585 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
586 * copies of the Software, and to permit persons to whom the Software is
587 * furnished to do so, subject to the following conditions:
588 *
589 * The above copyright notice and this permission notice shall be included in
590 * all copies or substantial portions of the Software.
591 *
592 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
593 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
594 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
595 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
596 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
597 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
598 * THE SOFTWARE.
599 */
600
601Object.defineProperty(exports, "__esModule", { value: true });
602
603/***/ }),
604
605/***/ "./packages/mdc-list/component.ts":
606/*!****************************************!*\
607 !*** ./packages/mdc-list/component.ts ***!
608 \****************************************/
609/*! no static exports found */
610/***/ (function(module, exports, __webpack_require__) {
611
612"use strict";
613
614/**
615 * @license
616 * Copyright 2018 Google Inc.
617 *
618 * Permission is hereby granted, free of charge, to any person obtaining a copy
619 * of this software and associated documentation files (the "Software"), to deal
620 * in the Software without restriction, including without limitation the rights
621 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
622 * copies of the Software, and to permit persons to whom the Software is
623 * furnished to do so, subject to the following conditions:
624 *
625 * The above copyright notice and this permission notice shall be included in
626 * all copies or substantial portions of the Software.
627 *
628 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
629 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
630 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
631 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
632 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
633 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
634 * THE SOFTWARE.
635 */
636
637var __extends = this && this.__extends || function () {
638 var _extendStatics = function extendStatics(d, b) {
639 _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
640 d.__proto__ = b;
641 } || function (d, b) {
642 for (var p in b) {
643 if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
644 }
645 };
646 return _extendStatics(d, b);
647 };
648 return function (d, b) {
649 if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
650 _extendStatics(d, b);
651 function __() {
652 this.constructor = d;
653 }
654 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
655 };
656}();
657Object.defineProperty(exports, "__esModule", { value: true });
658exports.MDCList = void 0;
659var component_1 = __webpack_require__(/*! @material/base/component */ "./packages/mdc-base/component.ts");
660var ponyfill_1 = __webpack_require__(/*! @material/dom/ponyfill */ "./packages/mdc-dom/ponyfill.ts");
661var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-list/constants.ts");
662var foundation_1 = __webpack_require__(/*! ./foundation */ "./packages/mdc-list/foundation.ts");
663var MDCList = /** @class */function (_super) {
664 __extends(MDCList, _super);
665 function MDCList() {
666 return _super !== null && _super.apply(this, arguments) || this;
667 }
668 Object.defineProperty(MDCList.prototype, "vertical", {
669 set: function set(value) {
670 this.foundation.setVerticalOrientation(value);
671 },
672 enumerable: false,
673 configurable: true
674 });
675 Object.defineProperty(MDCList.prototype, "listElements", {
676 get: function get() {
677 return Array.from(this.root.querySelectorAll("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS]));
678 },
679 enumerable: false,
680 configurable: true
681 });
682 Object.defineProperty(MDCList.prototype, "wrapFocus", {
683 set: function set(value) {
684 this.foundation.setWrapFocus(value);
685 },
686 enumerable: false,
687 configurable: true
688 });
689 Object.defineProperty(MDCList.prototype, "typeaheadInProgress", {
690 /**
691 * @return Whether typeahead is currently matching a user-specified prefix.
692 */
693 get: function get() {
694 return this.foundation.isTypeaheadInProgress();
695 },
696 enumerable: false,
697 configurable: true
698 });
699 Object.defineProperty(MDCList.prototype, "hasTypeahead", {
700 /**
701 * Sets whether typeahead functionality is enabled on the list.
702 * @param hasTypeahead Whether typeahead is enabled.
703 */
704 set: function set(hasTypeahead) {
705 this.foundation.setHasTypeahead(hasTypeahead);
706 },
707 enumerable: false,
708 configurable: true
709 });
710 Object.defineProperty(MDCList.prototype, "singleSelection", {
711 set: function set(isSingleSelectionList) {
712 this.foundation.setSingleSelection(isSingleSelectionList);
713 },
714 enumerable: false,
715 configurable: true
716 });
717 Object.defineProperty(MDCList.prototype, "selectedIndex", {
718 get: function get() {
719 return this.foundation.getSelectedIndex();
720 },
721 set: function set(index) {
722 this.foundation.setSelectedIndex(index);
723 },
724 enumerable: false,
725 configurable: true
726 });
727 MDCList.attachTo = function (root) {
728 return new MDCList(root);
729 };
730 MDCList.prototype.initialSyncWithDOM = function () {
731 this.isEvolutionEnabled = constants_1.evolutionAttribute in this.root.dataset;
732 if (this.isEvolutionEnabled) {
733 this.classNameMap = constants_1.evolutionClassNameMap;
734 } else if (ponyfill_1.matches(this.root, constants_1.strings.DEPRECATED_SELECTOR)) {
735 this.classNameMap = constants_1.deprecatedClassNameMap;
736 } else {
737 this.classNameMap = Object.values(constants_1.cssClasses).reduce(function (obj, className) {
738 obj[className] = className;
739 return obj;
740 }, {});
741 }
742 this.handleClick = this.handleClickEvent.bind(this);
743 this.handleKeydown = this.handleKeydownEvent.bind(this);
744 this.focusInEventListener = this.handleFocusInEvent.bind(this);
745 this.focusOutEventListener = this.handleFocusOutEvent.bind(this);
746 this.listen('keydown', this.handleKeydown);
747 this.listen('click', this.handleClick);
748 this.listen('focusin', this.focusInEventListener);
749 this.listen('focusout', this.focusOutEventListener);
750 this.layout();
751 this.initializeListType();
752 this.ensureFocusable();
753 };
754 MDCList.prototype.destroy = function () {
755 this.unlisten('keydown', this.handleKeydown);
756 this.unlisten('click', this.handleClick);
757 this.unlisten('focusin', this.focusInEventListener);
758 this.unlisten('focusout', this.focusOutEventListener);
759 };
760 MDCList.prototype.layout = function () {
761 var direction = this.root.getAttribute(constants_1.strings.ARIA_ORIENTATION);
762 this.vertical = direction !== constants_1.strings.ARIA_ORIENTATION_HORIZONTAL;
763 var itemSelector = "." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS] + ":not([tabindex])";
764 var childSelector = constants_1.strings.FOCUSABLE_CHILD_ELEMENTS;
765 // List items need to have at least tabindex=-1 to be focusable.
766 var itemEls = this.root.querySelectorAll(itemSelector);
767 if (itemEls.length) {
768 Array.prototype.forEach.call(itemEls, function (el) {
769 el.setAttribute('tabindex', '-1');
770 });
771 }
772 // Child button/a elements are not tabbable until the list item is focused.
773 var focusableChildEls = this.root.querySelectorAll(childSelector);
774 if (focusableChildEls.length) {
775 Array.prototype.forEach.call(focusableChildEls, function (el) {
776 el.setAttribute('tabindex', '-1');
777 });
778 }
779 if (this.isEvolutionEnabled) {
780 this.foundation.setUseSelectedAttribute(true);
781 }
782 this.foundation.layout();
783 };
784 /**
785 * Extracts the primary text from a list item.
786 * @param item The list item element.
787 * @return The primary text in the element.
788 */
789 MDCList.prototype.getPrimaryText = function (item) {
790 var _a;
791 var primaryText = item.querySelector("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS]);
792 if (this.isEvolutionEnabled || primaryText) {
793 return (_a = primaryText === null || primaryText === void 0 ? void 0 : primaryText.textContent) !== null && _a !== void 0 ? _a : '';
794 }
795 var singleLineText = item.querySelector("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_TEXT_CLASS]);
796 return singleLineText && singleLineText.textContent || '';
797 };
798 /**
799 * Initialize selectedIndex value based on pre-selected list items.
800 */
801 MDCList.prototype.initializeListType = function () {
802 var _this = this;
803 this.isInteractive = ponyfill_1.matches(this.root, constants_1.strings.ARIA_INTERACTIVE_ROLES_SELECTOR);
804 if (this.isEvolutionEnabled && this.isInteractive) {
805 var selection = Array.from(this.root.querySelectorAll(constants_1.strings.SELECTED_ITEM_SELECTOR), function (listItem) {
806 return _this.listElements.indexOf(listItem);
807 });
808 if (ponyfill_1.matches(this.root, constants_1.strings.ARIA_MULTI_SELECTABLE_SELECTOR)) {
809 this.selectedIndex = selection;
810 } else if (selection.length > 0) {
811 this.selectedIndex = selection[0];
812 }
813 return;
814 }
815 var checkboxListItems = this.root.querySelectorAll(constants_1.strings.ARIA_ROLE_CHECKBOX_SELECTOR);
816 var radioSelectedListItem = this.root.querySelector(constants_1.strings.ARIA_CHECKED_RADIO_SELECTOR);
817 if (checkboxListItems.length) {
818 var preselectedItems = this.root.querySelectorAll(constants_1.strings.ARIA_CHECKED_CHECKBOX_SELECTOR);
819 this.selectedIndex = Array.from(preselectedItems, function (listItem) {
820 return _this.listElements.indexOf(listItem);
821 });
822 } else if (radioSelectedListItem) {
823 this.selectedIndex = this.listElements.indexOf(radioSelectedListItem);
824 }
825 };
826 /**
827 * Updates the list item at itemIndex to the desired isEnabled state.
828 * @param itemIndex Index of the list item
829 * @param isEnabled Sets the list item to enabled or disabled.
830 */
831 MDCList.prototype.setEnabled = function (itemIndex, isEnabled) {
832 this.foundation.setEnabled(itemIndex, isEnabled);
833 };
834 /**
835 * Given the next desired character from the user, adds it to the typeahead
836 * buffer. Then, attempts to find the next option matching the buffer. Wraps
837 * around if at the end of options.
838 *
839 * @param nextChar The next character to add to the prefix buffer.
840 * @param startingIndex The index from which to start matching. Defaults to
841 * the currently focused index.
842 * @return The index of the matched item.
843 */
844 MDCList.prototype.typeaheadMatchItem = function (nextChar, startingIndex) {
845 return this.foundation.typeaheadMatchItem(nextChar, startingIndex, /** skipFocus */true);
846 };
847 MDCList.prototype.getDefaultFoundation = function () {
848 var _this = this;
849 // DO NOT INLINE this variable. For backward compatibility, foundations take
850 // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
851 // methods, we need a separate, strongly typed adapter variable.
852 var adapter = {
853 addClassForElementIndex: function addClassForElementIndex(index, className) {
854 var element = _this.listElements[index];
855 if (element) {
856 element.classList.add(_this.classNameMap[className]);
857 }
858 },
859 focusItemAtIndex: function focusItemAtIndex(index) {
860 var element = _this.listElements[index];
861 if (element) {
862 element.focus();
863 }
864 },
865 getAttributeForElementIndex: function getAttributeForElementIndex(index, attr) {
866 return _this.listElements[index].getAttribute(attr);
867 },
868 getFocusedElementIndex: function getFocusedElementIndex() {
869 return _this.listElements.indexOf(document.activeElement);
870 },
871 getListItemCount: function getListItemCount() {
872 return _this.listElements.length;
873 },
874 getPrimaryTextAtIndex: function getPrimaryTextAtIndex(index) {
875 return _this.getPrimaryText(_this.listElements[index]);
876 },
877 hasCheckboxAtIndex: function hasCheckboxAtIndex(index) {
878 var listItem = _this.listElements[index];
879 return !!listItem.querySelector(constants_1.strings.CHECKBOX_SELECTOR);
880 },
881 hasRadioAtIndex: function hasRadioAtIndex(index) {
882 var listItem = _this.listElements[index];
883 return !!listItem.querySelector(constants_1.strings.RADIO_SELECTOR);
884 },
885 isCheckboxCheckedAtIndex: function isCheckboxCheckedAtIndex(index) {
886 var listItem = _this.listElements[index];
887 var toggleEl = listItem.querySelector(constants_1.strings.CHECKBOX_SELECTOR);
888 return toggleEl.checked;
889 },
890 isFocusInsideList: function isFocusInsideList() {
891 return _this.root !== document.activeElement && _this.root.contains(document.activeElement);
892 },
893 isRootFocused: function isRootFocused() {
894 return document.activeElement === _this.root;
895 },
896 listItemAtIndexHasClass: function listItemAtIndexHasClass(index, className) {
897 return _this.listElements[index].classList.contains(_this.classNameMap[className]);
898 },
899 notifyAction: function notifyAction(index) {
900 _this.emit(constants_1.strings.ACTION_EVENT, { index: index }, /** shouldBubble */true);
901 },
902 removeClassForElementIndex: function removeClassForElementIndex(index, className) {
903 var element = _this.listElements[index];
904 if (element) {
905 element.classList.remove(_this.classNameMap[className]);
906 }
907 },
908 setAttributeForElementIndex: function setAttributeForElementIndex(index, attr, value) {
909 var element = _this.listElements[index];
910 if (element) {
911 element.setAttribute(attr, value);
912 }
913 },
914 setCheckedCheckboxOrRadioAtIndex: function setCheckedCheckboxOrRadioAtIndex(index, isChecked) {
915 var listItem = _this.listElements[index];
916 var toggleEl = listItem.querySelector(constants_1.strings.CHECKBOX_RADIO_SELECTOR);
917 toggleEl.checked = isChecked;
918 var event = document.createEvent('Event');
919 event.initEvent('change', true, true);
920 toggleEl.dispatchEvent(event);
921 },
922 setTabIndexForListItemChildren: function setTabIndexForListItemChildren(listItemIndex, tabIndexValue) {
923 var element = _this.listElements[listItemIndex];
924 var selector = constants_1.strings.CHILD_ELEMENTS_TO_TOGGLE_TABINDEX;
925 Array.prototype.forEach.call(element.querySelectorAll(selector), function (el) {
926 el.setAttribute('tabindex', tabIndexValue);
927 });
928 }
929 };
930 return new foundation_1.MDCListFoundation(adapter);
931 };
932 /**
933 * Ensures that at least one item is focusable if the list is interactive and
934 * doesn't specify a suitable tabindex.
935 */
936 MDCList.prototype.ensureFocusable = function () {
937 if (this.isEvolutionEnabled && this.isInteractive) {
938 if (!this.root.querySelector("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS] + "[tabindex=\"0\"]")) {
939 var index = this.initialFocusIndex();
940 if (index !== -1) {
941 this.listElements[index].tabIndex = 0;
942 }
943 }
944 }
945 };
946 MDCList.prototype.initialFocusIndex = function () {
947 if (this.selectedIndex instanceof Array && this.selectedIndex.length > 0) {
948 return this.selectedIndex[0];
949 }
950 if (typeof this.selectedIndex === 'number' && this.selectedIndex !== constants_1.numbers.UNSET_INDEX) {
951 return this.selectedIndex;
952 }
953 var el = this.root.querySelector("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS] + ":not(." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS] + ")");
954 if (el === null) {
955 return -1;
956 }
957 return this.getListItemIndex(el);
958 };
959 /**
960 * Used to figure out which list item this event is targetting. Or returns -1
961 * if there is no list item
962 */
963 MDCList.prototype.getListItemIndex = function (el) {
964 var nearestParent = ponyfill_1.closest(el, "." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS] + ", ." + this.classNameMap[constants_1.cssClasses.ROOT]);
965 // Get the index of the element if it is a list item.
966 if (nearestParent && ponyfill_1.matches(nearestParent, "." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS])) {
967 return this.listElements.indexOf(nearestParent);
968 }
969 return -1;
970 };
971 /**
972 * Used to figure out which element was clicked before sending the event to
973 * the foundation.
974 */
975 MDCList.prototype.handleFocusInEvent = function (evt) {
976 var index = this.getListItemIndex(evt.target);
977 this.foundation.handleFocusIn(index);
978 };
979 /**
980 * Used to figure out which element was clicked before sending the event to
981 * the foundation.
982 */
983 MDCList.prototype.handleFocusOutEvent = function (evt) {
984 var index = this.getListItemIndex(evt.target);
985 this.foundation.handleFocusOut(index);
986 };
987 /**
988 * Used to figure out which element was focused when keydown event occurred
989 * before sending the event to the foundation.
990 */
991 MDCList.prototype.handleKeydownEvent = function (evt) {
992 var index = this.getListItemIndex(evt.target);
993 var target = evt.target;
994 this.foundation.handleKeydown(evt, target.classList.contains(this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS]), index);
995 };
996 /**
997 * Used to figure out which element was clicked before sending the event to
998 * the foundation.
999 */
1000 MDCList.prototype.handleClickEvent = function (evt) {
1001 var index = this.getListItemIndex(evt.target);
1002 var target = evt.target;
1003 // Toggle the checkbox only if it's not the target of the event, or the
1004 // checkbox will have 2 change events.
1005 var toggleCheckbox = !ponyfill_1.matches(target, constants_1.strings.CHECKBOX_RADIO_SELECTOR);
1006 this.foundation.handleClick(index, toggleCheckbox);
1007 };
1008 return MDCList;
1009}(component_1.MDCComponent);
1010exports.MDCList = MDCList;
1011
1012/***/ }),
1013
1014/***/ "./packages/mdc-list/constants.ts":
1015/*!****************************************!*\
1016 !*** ./packages/mdc-list/constants.ts ***!
1017 \****************************************/
1018/*! no static exports found */
1019/***/ (function(module, exports, __webpack_require__) {
1020
1021"use strict";
1022
1023/**
1024 * @license
1025 * Copyright 2018 Google Inc.
1026 *
1027 * Permission is hereby granted, free of charge, to any person obtaining a copy
1028 * of this software and associated documentation files (the "Software"), to deal
1029 * in the Software without restriction, including without limitation the rights
1030 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1031 * copies of the Software, and to permit persons to whom the Software is
1032 * furnished to do so, subject to the following conditions:
1033 *
1034 * The above copyright notice and this permission notice shall be included in
1035 * all copies or substantial portions of the Software.
1036 *
1037 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1038 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1039 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1040 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1041 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1042 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1043 * THE SOFTWARE.
1044 */
1045
1046var _a, _b;
1047Object.defineProperty(exports, "__esModule", { value: true });
1048exports.evolutionClassNameMap = exports.evolutionAttribute = exports.deprecatedClassNameMap = exports.numbers = exports.cssClasses = exports.strings = void 0;
1049var cssClasses = {
1050 LIST_ITEM_ACTIVATED_CLASS: 'mdc-list-item--activated',
1051 LIST_ITEM_CLASS: 'mdc-list-item',
1052 LIST_ITEM_DISABLED_CLASS: 'mdc-list-item--disabled',
1053 LIST_ITEM_SELECTED_CLASS: 'mdc-list-item--selected',
1054 LIST_ITEM_TEXT_CLASS: 'mdc-list-item__text',
1055 LIST_ITEM_PRIMARY_TEXT_CLASS: 'mdc-list-item__primary-text',
1056 ROOT: 'mdc-list'
1057};
1058exports.cssClasses = cssClasses;
1059var evolutionClassNameMap = (_a = {}, _a["" + cssClasses.LIST_ITEM_ACTIVATED_CLASS] = 'mdc-list-item--activated', _a["" + cssClasses.LIST_ITEM_CLASS] = 'mdc-list-item', _a["" + cssClasses.LIST_ITEM_DISABLED_CLASS] = 'mdc-list-item--disabled', _a["" + cssClasses.LIST_ITEM_SELECTED_CLASS] = 'mdc-list-item--selected', _a["" + cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS] = 'mdc-list-item__primary-text', _a["" + cssClasses.ROOT] = 'mdc-list', _a);
1060exports.evolutionClassNameMap = evolutionClassNameMap;
1061var deprecatedClassNameMap = (_b = {}, _b["" + cssClasses.LIST_ITEM_ACTIVATED_CLASS] = 'mdc-deprecated-list-item--activated', _b["" + cssClasses.LIST_ITEM_CLASS] = 'mdc-deprecated-list-item', _b["" + cssClasses.LIST_ITEM_DISABLED_CLASS] = 'mdc-deprecated-list-item--disabled', _b["" + cssClasses.LIST_ITEM_SELECTED_CLASS] = 'mdc-deprecated-list-item--selected', _b["" + cssClasses.LIST_ITEM_TEXT_CLASS] = 'mdc-deprecated-list-item__text', _b["" + cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS] = 'mdc-deprecated-list-item__primary-text', _b["" + cssClasses.ROOT] = 'mdc-deprecated-list', _b);
1062exports.deprecatedClassNameMap = deprecatedClassNameMap;
1063var strings = {
1064 ACTION_EVENT: 'MDCList:action',
1065 ARIA_CHECKED: 'aria-checked',
1066 ARIA_CHECKED_CHECKBOX_SELECTOR: '[role="checkbox"][aria-checked="true"]',
1067 ARIA_CHECKED_RADIO_SELECTOR: '[role="radio"][aria-checked="true"]',
1068 ARIA_CURRENT: 'aria-current',
1069 ARIA_DISABLED: 'aria-disabled',
1070 ARIA_ORIENTATION: 'aria-orientation',
1071 ARIA_ORIENTATION_HORIZONTAL: 'horizontal',
1072 ARIA_ROLE_CHECKBOX_SELECTOR: '[role="checkbox"]',
1073 ARIA_SELECTED: 'aria-selected',
1074 ARIA_INTERACTIVE_ROLES_SELECTOR: '[role="listbox"], [role="menu"]',
1075 ARIA_MULTI_SELECTABLE_SELECTOR: '[aria-multiselectable="true"]',
1076 CHECKBOX_RADIO_SELECTOR: 'input[type="checkbox"], input[type="radio"]',
1077 CHECKBOX_SELECTOR: 'input[type="checkbox"]',
1078 CHILD_ELEMENTS_TO_TOGGLE_TABINDEX: "\n ." + cssClasses.LIST_ITEM_CLASS + " button:not(:disabled),\n ." + cssClasses.LIST_ITEM_CLASS + " a,\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " button:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " a\n ",
1079 DEPRECATED_SELECTOR: '.mdc-deprecated-list',
1080 FOCUSABLE_CHILD_ELEMENTS: "\n ." + cssClasses.LIST_ITEM_CLASS + " button:not(:disabled),\n ." + cssClasses.LIST_ITEM_CLASS + " a,\n ." + cssClasses.LIST_ITEM_CLASS + " input[type=\"radio\"]:not(:disabled),\n ." + cssClasses.LIST_ITEM_CLASS + " input[type=\"checkbox\"]:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " button:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " a,\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " input[type=\"radio\"]:not(:disabled),\n ." + deprecatedClassNameMap[cssClasses.LIST_ITEM_CLASS] + " input[type=\"checkbox\"]:not(:disabled)\n ",
1081 RADIO_SELECTOR: 'input[type="radio"]',
1082 SELECTED_ITEM_SELECTOR: '[aria-selected="true"], [aria-current="true"]'
1083};
1084exports.strings = strings;
1085var numbers = {
1086 UNSET_INDEX: -1,
1087 TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS: 300
1088};
1089exports.numbers = numbers;
1090var evolutionAttribute = 'evolution';
1091exports.evolutionAttribute = evolutionAttribute;
1092
1093/***/ }),
1094
1095/***/ "./packages/mdc-list/events.ts":
1096/*!*************************************!*\
1097 !*** ./packages/mdc-list/events.ts ***!
1098 \*************************************/
1099/*! no static exports found */
1100/***/ (function(module, exports, __webpack_require__) {
1101
1102"use strict";
1103
1104/**
1105 * @license
1106 * Copyright 2020 Google Inc.
1107 *
1108 * Permission is hereby granted, free of charge, to any person obtaining a copy
1109 * of this software and associated documentation files (the "Software"), to deal
1110 * in the Software without restriction, including without limitation the rights
1111 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1112 * copies of the Software, and to permit persons to whom the Software is
1113 * furnished to do so, subject to the following conditions:
1114 *
1115 * The above copyright notice and this permission notice shall be included in
1116 * all copies or substantial portions of the Software.
1117 *
1118 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1119 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1120 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1121 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1122 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1123 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1124 * THE SOFTWARE.
1125 */
1126
1127Object.defineProperty(exports, "__esModule", { value: true });
1128exports.preventDefaultEvent = void 0;
1129var ELEMENTS_KEY_ALLOWED_IN = ['input', 'button', 'textarea', 'select'];
1130/**
1131 * Ensures that preventDefault is only called if the containing element
1132 * doesn't consume the event, and it will cause an unintended scroll.
1133 *
1134 * @param evt keyboard event to be prevented.
1135 */
1136var preventDefaultEvent = function preventDefaultEvent(evt) {
1137 var target = evt.target;
1138 if (!target) {
1139 return;
1140 }
1141 var tagName = ("" + target.tagName).toLowerCase();
1142 if (ELEMENTS_KEY_ALLOWED_IN.indexOf(tagName) === -1) {
1143 evt.preventDefault();
1144 }
1145};
1146exports.preventDefaultEvent = preventDefaultEvent;
1147
1148/***/ }),
1149
1150/***/ "./packages/mdc-list/foundation.ts":
1151/*!*****************************************!*\
1152 !*** ./packages/mdc-list/foundation.ts ***!
1153 \*****************************************/
1154/*! no static exports found */
1155/***/ (function(module, exports, __webpack_require__) {
1156
1157"use strict";
1158
1159/**
1160 * @license
1161 * Copyright 2018 Google Inc.
1162 *
1163 * Permission is hereby granted, free of charge, to any person obtaining a copy
1164 * of this software and associated documentation files (the "Software"), to deal
1165 * in the Software without restriction, including without limitation the rights
1166 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1167 * copies of the Software, and to permit persons to whom the Software is
1168 * furnished to do so, subject to the following conditions:
1169 *
1170 * The above copyright notice and this permission notice shall be included in
1171 * all copies or substantial portions of the Software.
1172 *
1173 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1174 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1175 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1176 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1177 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1178 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1179 * THE SOFTWARE.
1180 */
1181
1182var __extends = this && this.__extends || function () {
1183 var _extendStatics = function extendStatics(d, b) {
1184 _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
1185 d.__proto__ = b;
1186 } || function (d, b) {
1187 for (var p in b) {
1188 if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
1189 }
1190 };
1191 return _extendStatics(d, b);
1192 };
1193 return function (d, b) {
1194 if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1195 _extendStatics(d, b);
1196 function __() {
1197 this.constructor = d;
1198 }
1199 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1200 };
1201}();
1202var __assign = this && this.__assign || function () {
1203 __assign = Object.assign || function (t) {
1204 for (var s, i = 1, n = arguments.length; i < n; i++) {
1205 s = arguments[i];
1206 for (var p in s) {
1207 if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
1208 }
1209 }
1210 return t;
1211 };
1212 return __assign.apply(this, arguments);
1213};
1214var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
1215 if (k2 === undefined) k2 = k;
1216 Object.defineProperty(o, k2, { enumerable: true, get: function get() {
1217 return m[k];
1218 } });
1219} : function (o, m, k, k2) {
1220 if (k2 === undefined) k2 = k;
1221 o[k2] = m[k];
1222});
1223var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
1224 Object.defineProperty(o, "default", { enumerable: true, value: v });
1225} : function (o, v) {
1226 o["default"] = v;
1227});
1228var __importStar = this && this.__importStar || function (mod) {
1229 if (mod && mod.__esModule) return mod;
1230 var result = {};
1231 if (mod != null) for (var k in mod) {
1232 if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1233 }__setModuleDefault(result, mod);
1234 return result;
1235};
1236Object.defineProperty(exports, "__esModule", { value: true });
1237exports.MDCListFoundation = void 0;
1238var foundation_1 = __webpack_require__(/*! @material/base/foundation */ "./packages/mdc-base/foundation.ts");
1239var keyboard_1 = __webpack_require__(/*! @material/dom/keyboard */ "./packages/mdc-dom/keyboard.ts");
1240var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-list/constants.ts");
1241var events_1 = __webpack_require__(/*! ./events */ "./packages/mdc-list/events.ts");
1242var typeahead = __importStar(__webpack_require__(/*! ./typeahead */ "./packages/mdc-list/typeahead.ts"));
1243function isNumberArray(selectedIndex) {
1244 return selectedIndex instanceof Array;
1245}
1246var MDCListFoundation = /** @class */function (_super) {
1247 __extends(MDCListFoundation, _super);
1248 function MDCListFoundation(adapter) {
1249 var _this = _super.call(this, __assign(__assign({}, MDCListFoundation.defaultAdapter), adapter)) || this;
1250 _this.wrapFocus = false;
1251 _this.isVertical = true;
1252 _this.isSingleSelectionList = false;
1253 _this.selectedIndex = constants_1.numbers.UNSET_INDEX;
1254 _this.focusedItemIndex = constants_1.numbers.UNSET_INDEX;
1255 _this.useActivatedClass = false;
1256 _this.useSelectedAttr = false;
1257 _this.ariaCurrentAttrValue = null;
1258 _this.isCheckboxList = false;
1259 _this.isRadioList = false;
1260 _this.hasTypeahead = false;
1261 // Transiently holds current typeahead prefix from user.
1262 _this.typeaheadState = typeahead.initState();
1263 _this.sortedIndexByFirstChar = new Map();
1264 return _this;
1265 }
1266 Object.defineProperty(MDCListFoundation, "strings", {
1267 get: function get() {
1268 return constants_1.strings;
1269 },
1270 enumerable: false,
1271 configurable: true
1272 });
1273 Object.defineProperty(MDCListFoundation, "cssClasses", {
1274 get: function get() {
1275 return constants_1.cssClasses;
1276 },
1277 enumerable: false,
1278 configurable: true
1279 });
1280 Object.defineProperty(MDCListFoundation, "numbers", {
1281 get: function get() {
1282 return constants_1.numbers;
1283 },
1284 enumerable: false,
1285 configurable: true
1286 });
1287 Object.defineProperty(MDCListFoundation, "defaultAdapter", {
1288 get: function get() {
1289 return {
1290 addClassForElementIndex: function addClassForElementIndex() {
1291 return undefined;
1292 },
1293 focusItemAtIndex: function focusItemAtIndex() {
1294 return undefined;
1295 },
1296 getAttributeForElementIndex: function getAttributeForElementIndex() {
1297 return null;
1298 },
1299 getFocusedElementIndex: function getFocusedElementIndex() {
1300 return 0;
1301 },
1302 getListItemCount: function getListItemCount() {
1303 return 0;
1304 },
1305 hasCheckboxAtIndex: function hasCheckboxAtIndex() {
1306 return false;
1307 },
1308 hasRadioAtIndex: function hasRadioAtIndex() {
1309 return false;
1310 },
1311 isCheckboxCheckedAtIndex: function isCheckboxCheckedAtIndex() {
1312 return false;
1313 },
1314 isFocusInsideList: function isFocusInsideList() {
1315 return false;
1316 },
1317 isRootFocused: function isRootFocused() {
1318 return false;
1319 },
1320 listItemAtIndexHasClass: function listItemAtIndexHasClass() {
1321 return false;
1322 },
1323 notifyAction: function notifyAction() {
1324 return undefined;
1325 },
1326 removeClassForElementIndex: function removeClassForElementIndex() {
1327 return undefined;
1328 },
1329 setAttributeForElementIndex: function setAttributeForElementIndex() {
1330 return undefined;
1331 },
1332 setCheckedCheckboxOrRadioAtIndex: function setCheckedCheckboxOrRadioAtIndex() {
1333 return undefined;
1334 },
1335 setTabIndexForListItemChildren: function setTabIndexForListItemChildren() {
1336 return undefined;
1337 },
1338 getPrimaryTextAtIndex: function getPrimaryTextAtIndex() {
1339 return '';
1340 }
1341 };
1342 },
1343 enumerable: false,
1344 configurable: true
1345 });
1346 MDCListFoundation.prototype.layout = function () {
1347 if (this.adapter.getListItemCount() === 0) {
1348 return;
1349 }
1350 // TODO(b/172274142): consider all items when determining the list's type.
1351 if (this.adapter.hasCheckboxAtIndex(0)) {
1352 this.isCheckboxList = true;
1353 } else if (this.adapter.hasRadioAtIndex(0)) {
1354 this.isRadioList = true;
1355 } else {
1356 this.maybeInitializeSingleSelection();
1357 }
1358 if (this.hasTypeahead) {
1359 this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
1360 }
1361 };
1362 /** Returns the index of the item that was last focused. */
1363 MDCListFoundation.prototype.getFocusedItemIndex = function () {
1364 return this.focusedItemIndex;
1365 };
1366 /** Toggles focus wrapping with keyboard navigation. */
1367 MDCListFoundation.prototype.setWrapFocus = function (value) {
1368 this.wrapFocus = value;
1369 };
1370 /**
1371 * Toggles orientation direction for keyboard navigation (true for vertical,
1372 * false for horizontal).
1373 */
1374 MDCListFoundation.prototype.setVerticalOrientation = function (value) {
1375 this.isVertical = value;
1376 };
1377 /** Toggles single-selection behavior. */
1378 MDCListFoundation.prototype.setSingleSelection = function (value) {
1379 this.isSingleSelectionList = value;
1380 if (value) {
1381 this.maybeInitializeSingleSelection();
1382 this.selectedIndex = this.getSelectedIndexFromDOM();
1383 }
1384 };
1385 /**
1386 * Automatically determines whether the list is single selection list. If so,
1387 * initializes the internal state to match the selected item.
1388 */
1389 MDCListFoundation.prototype.maybeInitializeSingleSelection = function () {
1390 var selectedItemIndex = this.getSelectedIndexFromDOM();
1391 if (selectedItemIndex === constants_1.numbers.UNSET_INDEX) return;
1392 var hasActivatedClass = this.adapter.listItemAtIndexHasClass(selectedItemIndex, constants_1.cssClasses.LIST_ITEM_ACTIVATED_CLASS);
1393 if (hasActivatedClass) {
1394 this.setUseActivatedClass(true);
1395 }
1396 this.isSingleSelectionList = true;
1397 this.selectedIndex = selectedItemIndex;
1398 };
1399 /** @return Index of the first selected item based on the DOM state. */
1400 MDCListFoundation.prototype.getSelectedIndexFromDOM = function () {
1401 var selectedIndex = constants_1.numbers.UNSET_INDEX;
1402 var listItemsCount = this.adapter.getListItemCount();
1403 for (var i = 0; i < listItemsCount; i++) {
1404 var hasSelectedClass = this.adapter.listItemAtIndexHasClass(i, constants_1.cssClasses.LIST_ITEM_SELECTED_CLASS);
1405 var hasActivatedClass = this.adapter.listItemAtIndexHasClass(i, constants_1.cssClasses.LIST_ITEM_ACTIVATED_CLASS);
1406 if (!(hasSelectedClass || hasActivatedClass)) {
1407 continue;
1408 }
1409 selectedIndex = i;
1410 break;
1411 }
1412 return selectedIndex;
1413 };
1414 /**
1415 * Sets whether typeahead is enabled on the list.
1416 * @param hasTypeahead Whether typeahead is enabled.
1417 */
1418 MDCListFoundation.prototype.setHasTypeahead = function (hasTypeahead) {
1419 this.hasTypeahead = hasTypeahead;
1420 if (hasTypeahead) {
1421 this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
1422 }
1423 };
1424 /**
1425 * @return Whether typeahead is currently matching a user-specified prefix.
1426 */
1427 MDCListFoundation.prototype.isTypeaheadInProgress = function () {
1428 return this.hasTypeahead && typeahead.isTypingInProgress(this.typeaheadState);
1429 };
1430 /** Toggle use of the "activated" CSS class. */
1431 MDCListFoundation.prototype.setUseActivatedClass = function (useActivated) {
1432 this.useActivatedClass = useActivated;
1433 };
1434 /**
1435 * Toggles use of the selected attribute (true for aria-selected, false for
1436 * aria-checked).
1437 */
1438 MDCListFoundation.prototype.setUseSelectedAttribute = function (useSelected) {
1439 this.useSelectedAttr = useSelected;
1440 };
1441 MDCListFoundation.prototype.getSelectedIndex = function () {
1442 return this.selectedIndex;
1443 };
1444 MDCListFoundation.prototype.setSelectedIndex = function (index, _a) {
1445 var _b = _a === void 0 ? {} : _a,
1446 forceUpdate = _b.forceUpdate;
1447 if (!this.isIndexValid(index)) {
1448 return;
1449 }
1450 if (this.isCheckboxList) {
1451 this.setCheckboxAtIndex(index);
1452 } else if (this.isRadioList) {
1453 this.setRadioAtIndex(index);
1454 } else {
1455 this.setSingleSelectionAtIndex(index, { forceUpdate: forceUpdate });
1456 }
1457 };
1458 /**
1459 * Focus in handler for the list items.
1460 */
1461 MDCListFoundation.prototype.handleFocusIn = function (listItemIndex) {
1462 if (listItemIndex >= 0) {
1463 this.focusedItemIndex = listItemIndex;
1464 this.adapter.setAttributeForElementIndex(listItemIndex, 'tabindex', '0');
1465 this.adapter.setTabIndexForListItemChildren(listItemIndex, '0');
1466 }
1467 };
1468 /**
1469 * Focus out handler for the list items.
1470 */
1471 MDCListFoundation.prototype.handleFocusOut = function (listItemIndex) {
1472 var _this = this;
1473 if (listItemIndex >= 0) {
1474 this.adapter.setAttributeForElementIndex(listItemIndex, 'tabindex', '-1');
1475 this.adapter.setTabIndexForListItemChildren(listItemIndex, '-1');
1476 }
1477 /**
1478 * Between Focusout & Focusin some browsers do not have focus on any
1479 * element. Setting a delay to wait till the focus is moved to next element.
1480 */
1481 setTimeout(function () {
1482 if (!_this.adapter.isFocusInsideList()) {
1483 _this.setTabindexToFirstSelectedOrFocusedItem();
1484 }
1485 }, 0);
1486 };
1487 /**
1488 * Key handler for the list.
1489 */
1490 MDCListFoundation.prototype.handleKeydown = function (event, isRootListItem, listItemIndex) {
1491 var _this = this;
1492 var isArrowLeft = keyboard_1.normalizeKey(event) === 'ArrowLeft';
1493 var isArrowUp = keyboard_1.normalizeKey(event) === 'ArrowUp';
1494 var isArrowRight = keyboard_1.normalizeKey(event) === 'ArrowRight';
1495 var isArrowDown = keyboard_1.normalizeKey(event) === 'ArrowDown';
1496 var isHome = keyboard_1.normalizeKey(event) === 'Home';
1497 var isEnd = keyboard_1.normalizeKey(event) === 'End';
1498 var isEnter = keyboard_1.normalizeKey(event) === 'Enter';
1499 var isSpace = keyboard_1.normalizeKey(event) === 'Spacebar';
1500 // Have to check both upper and lower case, because having caps lock on
1501 // affects the value.
1502 var isLetterA = event.key === 'A' || event.key === 'a';
1503 if (this.adapter.isRootFocused()) {
1504 if (isArrowUp || isEnd) {
1505 event.preventDefault();
1506 this.focusLastElement();
1507 } else if (isArrowDown || isHome) {
1508 event.preventDefault();
1509 this.focusFirstElement();
1510 }
1511 if (this.hasTypeahead) {
1512 var handleKeydownOpts = {
1513 event: event,
1514 focusItemAtIndex: function focusItemAtIndex(index) {
1515 _this.focusItemAtIndex(index);
1516 },
1517 focusedItemIndex: -1,
1518 isTargetListItem: isRootListItem,
1519 sortedIndexByFirstChar: this.sortedIndexByFirstChar,
1520 isItemAtIndexDisabled: function isItemAtIndexDisabled(index) {
1521 return _this.adapter.listItemAtIndexHasClass(index, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS);
1522 }
1523 };
1524 typeahead.handleKeydown(handleKeydownOpts, this.typeaheadState);
1525 }
1526 return;
1527 }
1528 var currentIndex = this.adapter.getFocusedElementIndex();
1529 if (currentIndex === -1) {
1530 currentIndex = listItemIndex;
1531 if (currentIndex < 0) {
1532 // If this event doesn't have a mdc-list-item ancestor from the
1533 // current list (not from a sublist), return early.
1534 return;
1535 }
1536 }
1537 if (this.isVertical && isArrowDown || !this.isVertical && isArrowRight) {
1538 events_1.preventDefaultEvent(event);
1539 this.focusNextElement(currentIndex);
1540 } else if (this.isVertical && isArrowUp || !this.isVertical && isArrowLeft) {
1541 events_1.preventDefaultEvent(event);
1542 this.focusPrevElement(currentIndex);
1543 } else if (isHome) {
1544 events_1.preventDefaultEvent(event);
1545 this.focusFirstElement();
1546 } else if (isEnd) {
1547 events_1.preventDefaultEvent(event);
1548 this.focusLastElement();
1549 } else if (isLetterA && event.ctrlKey && this.isCheckboxList) {
1550 event.preventDefault();
1551 this.toggleAll(this.selectedIndex === constants_1.numbers.UNSET_INDEX ? [] : this.selectedIndex);
1552 } else if (isEnter || isSpace) {
1553 if (isRootListItem) {
1554 // Return early if enter key is pressed on anchor element which triggers
1555 // synthetic MouseEvent event.
1556 var target = event.target;
1557 if (target && target.tagName === 'A' && isEnter) {
1558 return;
1559 }
1560 events_1.preventDefaultEvent(event);
1561 if (this.adapter.listItemAtIndexHasClass(currentIndex, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS)) {
1562 return;
1563 }
1564 if (!this.isTypeaheadInProgress()) {
1565 if (this.isSelectableList()) {
1566 this.setSelectedIndexOnAction(currentIndex);
1567 }
1568 this.adapter.notifyAction(currentIndex);
1569 }
1570 }
1571 }
1572 if (this.hasTypeahead) {
1573 var handleKeydownOpts = {
1574 event: event,
1575 focusItemAtIndex: function focusItemAtIndex(index) {
1576 _this.focusItemAtIndex(index);
1577 },
1578 focusedItemIndex: this.focusedItemIndex,
1579 isTargetListItem: isRootListItem,
1580 sortedIndexByFirstChar: this.sortedIndexByFirstChar,
1581 isItemAtIndexDisabled: function isItemAtIndexDisabled(index) {
1582 return _this.adapter.listItemAtIndexHasClass(index, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS);
1583 }
1584 };
1585 typeahead.handleKeydown(handleKeydownOpts, this.typeaheadState);
1586 }
1587 };
1588 /**
1589 * Click handler for the list.
1590 */
1591 MDCListFoundation.prototype.handleClick = function (index, toggleCheckbox) {
1592 if (index === constants_1.numbers.UNSET_INDEX) {
1593 return;
1594 }
1595 if (this.adapter.listItemAtIndexHasClass(index, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS)) {
1596 return;
1597 }
1598 if (this.isSelectableList()) {
1599 this.setSelectedIndexOnAction(index, toggleCheckbox);
1600 }
1601 this.adapter.notifyAction(index);
1602 };
1603 /**
1604 * Focuses the next element on the list.
1605 */
1606 MDCListFoundation.prototype.focusNextElement = function (index) {
1607 var count = this.adapter.getListItemCount();
1608 var nextIndex = index + 1;
1609 if (nextIndex >= count) {
1610 if (this.wrapFocus) {
1611 nextIndex = 0;
1612 } else {
1613 // Return early because last item is already focused.
1614 return index;
1615 }
1616 }
1617 this.focusItemAtIndex(nextIndex);
1618 return nextIndex;
1619 };
1620 /**
1621 * Focuses the previous element on the list.
1622 */
1623 MDCListFoundation.prototype.focusPrevElement = function (index) {
1624 var prevIndex = index - 1;
1625 if (prevIndex < 0) {
1626 if (this.wrapFocus) {
1627 prevIndex = this.adapter.getListItemCount() - 1;
1628 } else {
1629 // Return early because first item is already focused.
1630 return index;
1631 }
1632 }
1633 this.focusItemAtIndex(prevIndex);
1634 return prevIndex;
1635 };
1636 MDCListFoundation.prototype.focusFirstElement = function () {
1637 this.focusItemAtIndex(0);
1638 return 0;
1639 };
1640 MDCListFoundation.prototype.focusLastElement = function () {
1641 var lastIndex = this.adapter.getListItemCount() - 1;
1642 this.focusItemAtIndex(lastIndex);
1643 return lastIndex;
1644 };
1645 MDCListFoundation.prototype.focusInitialElement = function () {
1646 var initialIndex = this.getFirstSelectedOrFocusedItemIndex();
1647 this.focusItemAtIndex(initialIndex);
1648 return initialIndex;
1649 };
1650 /**
1651 * @param itemIndex Index of the list item
1652 * @param isEnabled Sets the list item to enabled or disabled.
1653 */
1654 MDCListFoundation.prototype.setEnabled = function (itemIndex, isEnabled) {
1655 if (!this.isIndexValid(itemIndex)) {
1656 return;
1657 }
1658 if (isEnabled) {
1659 this.adapter.removeClassForElementIndex(itemIndex, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS);
1660 this.adapter.setAttributeForElementIndex(itemIndex, constants_1.strings.ARIA_DISABLED, 'false');
1661 } else {
1662 this.adapter.addClassForElementIndex(itemIndex, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS);
1663 this.adapter.setAttributeForElementIndex(itemIndex, constants_1.strings.ARIA_DISABLED, 'true');
1664 }
1665 };
1666 MDCListFoundation.prototype.setSingleSelectionAtIndex = function (index, _a) {
1667 var _b = _a === void 0 ? {} : _a,
1668 forceUpdate = _b.forceUpdate;
1669 if (this.selectedIndex === index && !forceUpdate) {
1670 return;
1671 }
1672 var selectedClassName = constants_1.cssClasses.LIST_ITEM_SELECTED_CLASS;
1673 if (this.useActivatedClass) {
1674 selectedClassName = constants_1.cssClasses.LIST_ITEM_ACTIVATED_CLASS;
1675 }
1676 if (this.selectedIndex !== constants_1.numbers.UNSET_INDEX) {
1677 this.adapter.removeClassForElementIndex(this.selectedIndex, selectedClassName);
1678 }
1679 this.setAriaForSingleSelectionAtIndex(index);
1680 this.setTabindexAtIndex(index);
1681 if (index !== constants_1.numbers.UNSET_INDEX) {
1682 this.adapter.addClassForElementIndex(index, selectedClassName);
1683 }
1684 this.selectedIndex = index;
1685 };
1686 /**
1687 * Sets aria attribute for single selection at given index.
1688 */
1689 MDCListFoundation.prototype.setAriaForSingleSelectionAtIndex = function (index) {
1690 // Detect the presence of aria-current and get the value only during list
1691 // initialization when it is in unset state.
1692 if (this.selectedIndex === constants_1.numbers.UNSET_INDEX) {
1693 this.ariaCurrentAttrValue = this.adapter.getAttributeForElementIndex(index, constants_1.strings.ARIA_CURRENT);
1694 }
1695 var isAriaCurrent = this.ariaCurrentAttrValue !== null;
1696 var ariaAttribute = isAriaCurrent ? constants_1.strings.ARIA_CURRENT : constants_1.strings.ARIA_SELECTED;
1697 if (this.selectedIndex !== constants_1.numbers.UNSET_INDEX) {
1698 this.adapter.setAttributeForElementIndex(this.selectedIndex, ariaAttribute, 'false');
1699 }
1700 if (index !== constants_1.numbers.UNSET_INDEX) {
1701 var ariaAttributeValue = isAriaCurrent ? this.ariaCurrentAttrValue : 'true';
1702 this.adapter.setAttributeForElementIndex(index, ariaAttribute, ariaAttributeValue);
1703 }
1704 };
1705 /**
1706 * Returns the attribute to use for indicating selection status.
1707 */
1708 MDCListFoundation.prototype.getSelectionAttribute = function () {
1709 return this.useSelectedAttr ? constants_1.strings.ARIA_SELECTED : constants_1.strings.ARIA_CHECKED;
1710 };
1711 /**
1712 * Toggles radio at give index. Radio doesn't change the checked state if it
1713 * is already checked.
1714 */
1715 MDCListFoundation.prototype.setRadioAtIndex = function (index) {
1716 var selectionAttribute = this.getSelectionAttribute();
1717 this.adapter.setCheckedCheckboxOrRadioAtIndex(index, true);
1718 if (this.selectedIndex !== constants_1.numbers.UNSET_INDEX) {
1719 this.adapter.setAttributeForElementIndex(this.selectedIndex, selectionAttribute, 'false');
1720 }
1721 this.adapter.setAttributeForElementIndex(index, selectionAttribute, 'true');
1722 this.selectedIndex = index;
1723 };
1724 MDCListFoundation.prototype.setCheckboxAtIndex = function (index) {
1725 var selectionAttribute = this.getSelectionAttribute();
1726 for (var i = 0; i < this.adapter.getListItemCount(); i++) {
1727 var isChecked = false;
1728 if (index.indexOf(i) >= 0) {
1729 isChecked = true;
1730 }
1731 this.adapter.setCheckedCheckboxOrRadioAtIndex(i, isChecked);
1732 this.adapter.setAttributeForElementIndex(i, selectionAttribute, isChecked ? 'true' : 'false');
1733 }
1734 this.selectedIndex = index;
1735 };
1736 MDCListFoundation.prototype.setTabindexAtIndex = function (index) {
1737 if (this.focusedItemIndex === constants_1.numbers.UNSET_INDEX && index !== 0) {
1738 // If some list item was selected set first list item's tabindex to -1.
1739 // Generally, tabindex is set to 0 on first list item of list that has no
1740 // preselected items.
1741 this.adapter.setAttributeForElementIndex(0, 'tabindex', '-1');
1742 } else if (this.focusedItemIndex >= 0 && this.focusedItemIndex !== index) {
1743 this.adapter.setAttributeForElementIndex(this.focusedItemIndex, 'tabindex', '-1');
1744 }
1745 // Set the previous selection's tabindex to -1. We need this because
1746 // in selection menus that are not visible, programmatically setting an
1747 // option will not change focus but will change where tabindex should be 0.
1748 if (!(this.selectedIndex instanceof Array) && this.selectedIndex !== index) {
1749 this.adapter.setAttributeForElementIndex(this.selectedIndex, 'tabindex', '-1');
1750 }
1751 if (index !== constants_1.numbers.UNSET_INDEX) {
1752 this.adapter.setAttributeForElementIndex(index, 'tabindex', '0');
1753 }
1754 };
1755 /**
1756 * @return Return true if it is single selectin list, checkbox list or radio
1757 * list.
1758 */
1759 MDCListFoundation.prototype.isSelectableList = function () {
1760 return this.isSingleSelectionList || this.isCheckboxList || this.isRadioList;
1761 };
1762 MDCListFoundation.prototype.setTabindexToFirstSelectedOrFocusedItem = function () {
1763 var targetIndex = this.getFirstSelectedOrFocusedItemIndex();
1764 this.setTabindexAtIndex(targetIndex);
1765 };
1766 MDCListFoundation.prototype.getFirstSelectedOrFocusedItemIndex = function () {
1767 // Action lists retain focus on the most recently focused item.
1768 if (!this.isSelectableList()) {
1769 return Math.max(this.focusedItemIndex, 0);
1770 }
1771 // Single-selection lists focus the selected item.
1772 if (typeof this.selectedIndex === 'number' && this.selectedIndex !== constants_1.numbers.UNSET_INDEX) {
1773 return this.selectedIndex;
1774 }
1775 // Multiple-selection lists focus the first selected item.
1776 if (isNumberArray(this.selectedIndex) && this.selectedIndex.length > 0) {
1777 return this.selectedIndex.reduce(function (minIndex, currentIndex) {
1778 return Math.min(minIndex, currentIndex);
1779 });
1780 }
1781 // Selection lists without a selection focus the first item.
1782 return 0;
1783 };
1784 MDCListFoundation.prototype.isIndexValid = function (index) {
1785 var _this = this;
1786 if (index instanceof Array) {
1787 if (!this.isCheckboxList) {
1788 throw new Error('MDCListFoundation: Array of index is only supported for checkbox based list');
1789 }
1790 if (index.length === 0) {
1791 return true;
1792 } else {
1793 return index.some(function (i) {
1794 return _this.isIndexInRange(i);
1795 });
1796 }
1797 } else if (typeof index === 'number') {
1798 if (this.isCheckboxList) {
1799 throw new Error("MDCListFoundation: Expected array of index for checkbox based list but got number: " + index);
1800 }
1801 return this.isIndexInRange(index) || this.isSingleSelectionList && index === constants_1.numbers.UNSET_INDEX;
1802 } else {
1803 return false;
1804 }
1805 };
1806 MDCListFoundation.prototype.isIndexInRange = function (index) {
1807 var listSize = this.adapter.getListItemCount();
1808 return index >= 0 && index < listSize;
1809 };
1810 /**
1811 * Sets selected index on user action, toggles checkbox / radio based on
1812 * toggleCheckbox value. User interaction should not toggle list item(s) when
1813 * disabled.
1814 */
1815 MDCListFoundation.prototype.setSelectedIndexOnAction = function (index, toggleCheckbox) {
1816 if (toggleCheckbox === void 0) {
1817 toggleCheckbox = true;
1818 }
1819 if (this.isCheckboxList) {
1820 this.toggleCheckboxAtIndex(index, toggleCheckbox);
1821 } else {
1822 this.setSelectedIndex(index);
1823 }
1824 };
1825 MDCListFoundation.prototype.toggleCheckboxAtIndex = function (index, toggleCheckbox) {
1826 var selectionAttribute = this.getSelectionAttribute();
1827 var isChecked = this.adapter.isCheckboxCheckedAtIndex(index);
1828 if (toggleCheckbox) {
1829 isChecked = !isChecked;
1830 this.adapter.setCheckedCheckboxOrRadioAtIndex(index, isChecked);
1831 }
1832 this.adapter.setAttributeForElementIndex(index, selectionAttribute, isChecked ? 'true' : 'false');
1833 // If none of the checkbox items are selected and selectedIndex is not
1834 // initialized then provide a default value.
1835 var selectedIndexes = this.selectedIndex === constants_1.numbers.UNSET_INDEX ? [] : this.selectedIndex.slice();
1836 if (isChecked) {
1837 selectedIndexes.push(index);
1838 } else {
1839 selectedIndexes = selectedIndexes.filter(function (i) {
1840 return i !== index;
1841 });
1842 }
1843 this.selectedIndex = selectedIndexes;
1844 };
1845 MDCListFoundation.prototype.focusItemAtIndex = function (index) {
1846 this.adapter.focusItemAtIndex(index);
1847 this.focusedItemIndex = index;
1848 };
1849 MDCListFoundation.prototype.toggleAll = function (currentlySelectedIndexes) {
1850 var count = this.adapter.getListItemCount();
1851 // If all items are selected, deselect everything.
1852 if (currentlySelectedIndexes.length === count) {
1853 this.setCheckboxAtIndex([]);
1854 } else {
1855 // Otherwise select all enabled options.
1856 var allIndexes = [];
1857 for (var i = 0; i < count; i++) {
1858 if (!this.adapter.listItemAtIndexHasClass(i, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS) || currentlySelectedIndexes.indexOf(i) > -1) {
1859 allIndexes.push(i);
1860 }
1861 }
1862 this.setCheckboxAtIndex(allIndexes);
1863 }
1864 };
1865 /**
1866 * Given the next desired character from the user, adds it to the typeahead
1867 * buffer. Then, attempts to find the next option matching the buffer. Wraps
1868 * around if at the end of options.
1869 *
1870 * @param nextChar The next character to add to the prefix buffer.
1871 * @param startingIndex The index from which to start matching. Only relevant
1872 * when starting a new match sequence. To start a new match sequence,
1873 * clear the buffer using `clearTypeaheadBuffer`, or wait for the buffer
1874 * to clear after a set interval defined in list foundation. Defaults to
1875 * the currently focused index.
1876 * @return The index of the matched item, or -1 if no match.
1877 */
1878 MDCListFoundation.prototype.typeaheadMatchItem = function (nextChar, startingIndex, skipFocus) {
1879 var _this = this;
1880 if (skipFocus === void 0) {
1881 skipFocus = false;
1882 }
1883 var opts = {
1884 focusItemAtIndex: function focusItemAtIndex(index) {
1885 _this.focusItemAtIndex(index);
1886 },
1887 focusedItemIndex: startingIndex ? startingIndex : this.focusedItemIndex,
1888 nextChar: nextChar,
1889 sortedIndexByFirstChar: this.sortedIndexByFirstChar,
1890 skipFocus: skipFocus,
1891 isItemAtIndexDisabled: function isItemAtIndexDisabled(index) {
1892 return _this.adapter.listItemAtIndexHasClass(index, constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS);
1893 }
1894 };
1895 return typeahead.matchItem(opts, this.typeaheadState);
1896 };
1897 /**
1898 * Initializes the MDCListTextAndIndex data structure by indexing the current
1899 * list items by primary text.
1900 *
1901 * @return The primary texts of all the list items sorted by first character.
1902 */
1903 MDCListFoundation.prototype.typeaheadInitSortedIndex = function () {
1904 return typeahead.initSortedIndex(this.adapter.getListItemCount(), this.adapter.getPrimaryTextAtIndex);
1905 };
1906 /**
1907 * Clears the typeahead buffer.
1908 */
1909 MDCListFoundation.prototype.clearTypeaheadBuffer = function () {
1910 typeahead.clearBuffer(this.typeaheadState);
1911 };
1912 return MDCListFoundation;
1913}(foundation_1.MDCFoundation);
1914exports.MDCListFoundation = MDCListFoundation;
1915// tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
1916exports.default = MDCListFoundation;
1917
1918/***/ }),
1919
1920/***/ "./packages/mdc-list/index.ts":
1921/*!************************************!*\
1922 !*** ./packages/mdc-list/index.ts ***!
1923 \************************************/
1924/*! no static exports found */
1925/***/ (function(module, exports, __webpack_require__) {
1926
1927"use strict";
1928
1929/**
1930 * @license
1931 * Copyright 2019 Google Inc.
1932 *
1933 * Permission is hereby granted, free of charge, to any person obtaining a copy
1934 * of this software and associated documentation files (the "Software"), to deal
1935 * in the Software without restriction, including without limitation the rights
1936 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1937 * copies of the Software, and to permit persons to whom the Software is
1938 * furnished to do so, subject to the following conditions:
1939 *
1940 * The above copyright notice and this permission notice shall be included in
1941 * all copies or substantial portions of the Software.
1942 *
1943 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1944 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1945 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1946 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1947 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1948 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1949 * THE SOFTWARE.
1950 */
1951
1952var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
1953 if (k2 === undefined) k2 = k;
1954 Object.defineProperty(o, k2, { enumerable: true, get: function get() {
1955 return m[k];
1956 } });
1957} : function (o, m, k, k2) {
1958 if (k2 === undefined) k2 = k;
1959 o[k2] = m[k];
1960});
1961var __exportStar = this && this.__exportStar || function (m, exports) {
1962 for (var p in m) {
1963 if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1964 }
1965};
1966Object.defineProperty(exports, "__esModule", { value: true });
1967__exportStar(__webpack_require__(/*! ./adapter */ "./packages/mdc-list/adapter.ts"), exports);
1968__exportStar(__webpack_require__(/*! ./component */ "./packages/mdc-list/component.ts"), exports);
1969__exportStar(__webpack_require__(/*! ./constants */ "./packages/mdc-list/constants.ts"), exports);
1970__exportStar(__webpack_require__(/*! ./foundation */ "./packages/mdc-list/foundation.ts"), exports);
1971__exportStar(__webpack_require__(/*! ./types */ "./packages/mdc-list/types.ts"), exports);
1972
1973/***/ }),
1974
1975/***/ "./packages/mdc-list/typeahead.ts":
1976/*!****************************************!*\
1977 !*** ./packages/mdc-list/typeahead.ts ***!
1978 \****************************************/
1979/*! no static exports found */
1980/***/ (function(module, exports, __webpack_require__) {
1981
1982"use strict";
1983
1984/**
1985 * @license
1986 * Copyright 2020 Google Inc.
1987 *
1988 * Permission is hereby granted, free of charge, to any person obtaining a copy
1989 * of this software and associated documentation files (the "Software"), to deal
1990 * in the Software without restriction, including without limitation the rights
1991 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1992 * copies of the Software, and to permit persons to whom the Software is
1993 * furnished to do so, subject to the following conditions:
1994 *
1995 * The above copyright notice and this permission notice shall be included in
1996 * all copies or substantial portions of the Software.
1997 *
1998 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1999 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2000 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2001 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2002 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2003 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2004 * THE SOFTWARE.
2005 */
2006
2007Object.defineProperty(exports, "__esModule", { value: true });
2008exports.handleKeydown = exports.clearBuffer = exports.isTypingInProgress = exports.matchItem = exports.initSortedIndex = exports.initState = void 0;
2009var keyboard_1 = __webpack_require__(/*! @material/dom/keyboard */ "./packages/mdc-dom/keyboard.ts");
2010var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-list/constants.ts");
2011var events_1 = __webpack_require__(/*! ./events */ "./packages/mdc-list/events.ts");
2012/**
2013 * Initializes a state object for typeahead. Use the same reference for calls to
2014 * typeahead functions.
2015 *
2016 * @return The current state of the typeahead process. Each state reference
2017 * represents a typeahead instance as the reference is typically mutated
2018 * in-place.
2019 */
2020function initState() {
2021 var state = {
2022 bufferClearTimeout: 0,
2023 currentFirstChar: '',
2024 sortedIndexCursor: 0,
2025 typeaheadBuffer: ''
2026 };
2027 return state;
2028}
2029exports.initState = initState;
2030/**
2031 * Initializes typeahead state by indexing the current list items by primary
2032 * text into the sortedIndexByFirstChar data structure.
2033 *
2034 * @param listItemCount numer of items in the list
2035 * @param getPrimaryTextByItemIndex function that returns the primary text at a
2036 * given index
2037 *
2038 * @return Map that maps the first character of the primary text to the full
2039 * list text and it's index
2040 */
2041function initSortedIndex(listItemCount, getPrimaryTextByItemIndex) {
2042 var sortedIndexByFirstChar = new Map();
2043 // Aggregate item text to index mapping
2044 for (var i = 0; i < listItemCount; i++) {
2045 var primaryText = getPrimaryTextByItemIndex(i).trim();
2046 if (!primaryText) {
2047 continue;
2048 }
2049 var firstChar = primaryText[0].toLowerCase();
2050 if (!sortedIndexByFirstChar.has(firstChar)) {
2051 sortedIndexByFirstChar.set(firstChar, []);
2052 }
2053 sortedIndexByFirstChar.get(firstChar).push({ text: primaryText.toLowerCase(), index: i });
2054 }
2055 // Sort the mapping
2056 // TODO(b/157162694): Investigate replacing forEach with Map.values()
2057 sortedIndexByFirstChar.forEach(function (values) {
2058 values.sort(function (first, second) {
2059 return first.index - second.index;
2060 });
2061 });
2062 return sortedIndexByFirstChar;
2063}
2064exports.initSortedIndex = initSortedIndex;
2065/**
2066 * Given the next desired character from the user, it attempts to find the next
2067 * list option matching the buffer. Wraps around if at the end of options.
2068 *
2069 * @param opts Options and accessors
2070 * - nextChar - the next character to match against items
2071 * - sortedIndexByFirstChar - output of `initSortedIndex(...)`
2072 * - focusedItemIndex - the index of the currently focused item
2073 * - focusItemAtIndex - function that focuses a list item at given index
2074 * - skipFocus - whether or not to focus the matched item
2075 * - isItemAtIndexDisabled - function that determines whether an item at a
2076 * given index is disabled
2077 * @param state The typeahead state instance. See `initState`.
2078 *
2079 * @return The index of the matched item, or -1 if no match.
2080 */
2081function matchItem(opts, state) {
2082 var nextChar = opts.nextChar,
2083 focusItemAtIndex = opts.focusItemAtIndex,
2084 sortedIndexByFirstChar = opts.sortedIndexByFirstChar,
2085 focusedItemIndex = opts.focusedItemIndex,
2086 skipFocus = opts.skipFocus,
2087 isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
2088 clearTimeout(state.bufferClearTimeout);
2089 state.bufferClearTimeout = setTimeout(function () {
2090 clearBuffer(state);
2091 }, constants_1.numbers.TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS);
2092 state.typeaheadBuffer = state.typeaheadBuffer + nextChar;
2093 var index;
2094 if (state.typeaheadBuffer.length === 1) {
2095 index = matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state);
2096 } else {
2097 index = matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state);
2098 }
2099 if (index !== -1 && !skipFocus) {
2100 focusItemAtIndex(index);
2101 }
2102 return index;
2103}
2104exports.matchItem = matchItem;
2105/**
2106 * Matches the user's single input character in the buffer to the
2107 * next option that begins with such character. Wraps around if at
2108 * end of options. Returns -1 if no match is found.
2109 */
2110function matchFirstChar(sortedIndexByFirstChar, focusedItemIndex, isItemAtIndexDisabled, state) {
2111 var firstChar = state.typeaheadBuffer[0];
2112 var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
2113 if (!itemsMatchingFirstChar) {
2114 return -1;
2115 }
2116 // Has the same firstChar been recently matched?
2117 // Also, did starting index remain the same between key presses?
2118 // If both hold true, simply increment index.
2119 if (firstChar === state.currentFirstChar && itemsMatchingFirstChar[state.sortedIndexCursor].index === focusedItemIndex) {
2120 state.sortedIndexCursor = (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
2121 var newIndex = itemsMatchingFirstChar[state.sortedIndexCursor].index;
2122 if (!isItemAtIndexDisabled(newIndex)) {
2123 return newIndex;
2124 }
2125 }
2126 // If we're here, it means one of the following happened:
2127 // - either firstChar or startingIndex has changed, invalidating the
2128 // cursor.
2129 // - The next item of typeahead is disabled, so we have to look further.
2130 state.currentFirstChar = firstChar;
2131 var newCursorPosition = -1;
2132 var cursorPosition;
2133 // Find the first non-disabled item as a fallback.
2134 for (cursorPosition = 0; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
2135 if (!isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
2136 newCursorPosition = cursorPosition;
2137 break;
2138 }
2139 }
2140 // Advance cursor to first item matching the firstChar that is positioned
2141 // after starting item. Cursor is unchanged from fallback if there's no
2142 // such item.
2143 for (; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
2144 if (itemsMatchingFirstChar[cursorPosition].index > focusedItemIndex && !isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
2145 newCursorPosition = cursorPosition;
2146 break;
2147 }
2148 }
2149 if (newCursorPosition !== -1) {
2150 state.sortedIndexCursor = newCursorPosition;
2151 return itemsMatchingFirstChar[state.sortedIndexCursor].index;
2152 }
2153 return -1;
2154}
2155/**
2156 * Attempts to find the next item that matches all of the typeahead buffer.
2157 * Wraps around if at end of options. Returns -1 if no match is found.
2158 */
2159function matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state) {
2160 var firstChar = state.typeaheadBuffer[0];
2161 var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
2162 if (!itemsMatchingFirstChar) {
2163 return -1;
2164 }
2165 // Do nothing if text already matches
2166 var startingItem = itemsMatchingFirstChar[state.sortedIndexCursor];
2167 if (startingItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0 && !isItemAtIndexDisabled(startingItem.index)) {
2168 return startingItem.index;
2169 }
2170 // Find next item that matches completely; if no match, we'll eventually
2171 // loop around to same position
2172 var cursorPosition = (state.sortedIndexCursor + 1) % itemsMatchingFirstChar.length;
2173 var nextCursorPosition = -1;
2174 while (cursorPosition !== state.sortedIndexCursor) {
2175 var currentItem = itemsMatchingFirstChar[cursorPosition];
2176 var matches = currentItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0;
2177 var isEnabled = !isItemAtIndexDisabled(currentItem.index);
2178 if (matches && isEnabled) {
2179 nextCursorPosition = cursorPosition;
2180 break;
2181 }
2182 cursorPosition = (cursorPosition + 1) % itemsMatchingFirstChar.length;
2183 }
2184 if (nextCursorPosition !== -1) {
2185 state.sortedIndexCursor = nextCursorPosition;
2186 return itemsMatchingFirstChar[state.sortedIndexCursor].index;
2187 }
2188 return -1;
2189}
2190/**
2191 * Whether or not the given typeahead instaance state is currently typing.
2192 *
2193 * @param state The typeahead state instance. See `initState`.
2194 */
2195function isTypingInProgress(state) {
2196 return state.typeaheadBuffer.length > 0;
2197}
2198exports.isTypingInProgress = isTypingInProgress;
2199/**
2200 * Clears the typeahaed buffer so that it resets item matching to the first
2201 * character.
2202 *
2203 * @param state The typeahead state instance. See `initState`.
2204 */
2205function clearBuffer(state) {
2206 state.typeaheadBuffer = '';
2207}
2208exports.clearBuffer = clearBuffer;
2209/**
2210 * Given a keydown event, it calculates whether or not to automatically focus a
2211 * list item depending on what was typed mimicing the typeahead functionality of
2212 * a standard <select> element that is open.
2213 *
2214 * @param opts Options and accessors
2215 * - event - the KeyboardEvent to handle and parse
2216 * - sortedIndexByFirstChar - output of `initSortedIndex(...)`
2217 * - focusedItemIndex - the index of the currently focused item
2218 * - focusItemAtIndex - function that focuses a list item at given index
2219 * - isItemAtFocusedIndexDisabled - whether or not the currently focused item
2220 * is disabled
2221 * - isTargetListItem - whether or not the event target is a list item
2222 * @param state The typeahead state instance. See `initState`.
2223 *
2224 * @returns index of the item matched by the keydown. -1 if not matched.
2225 */
2226function handleKeydown(opts, state) {
2227 var event = opts.event,
2228 isTargetListItem = opts.isTargetListItem,
2229 focusedItemIndex = opts.focusedItemIndex,
2230 focusItemAtIndex = opts.focusItemAtIndex,
2231 sortedIndexByFirstChar = opts.sortedIndexByFirstChar,
2232 isItemAtIndexDisabled = opts.isItemAtIndexDisabled;
2233 var isArrowLeft = keyboard_1.normalizeKey(event) === 'ArrowLeft';
2234 var isArrowUp = keyboard_1.normalizeKey(event) === 'ArrowUp';
2235 var isArrowRight = keyboard_1.normalizeKey(event) === 'ArrowRight';
2236 var isArrowDown = keyboard_1.normalizeKey(event) === 'ArrowDown';
2237 var isHome = keyboard_1.normalizeKey(event) === 'Home';
2238 var isEnd = keyboard_1.normalizeKey(event) === 'End';
2239 var isEnter = keyboard_1.normalizeKey(event) === 'Enter';
2240 var isSpace = keyboard_1.normalizeKey(event) === 'Spacebar';
2241 if (event.ctrlKey || event.metaKey || isArrowLeft || isArrowUp || isArrowRight || isArrowDown || isHome || isEnd || isEnter) {
2242 return -1;
2243 }
2244 var isCharacterKey = !isSpace && event.key.length === 1;
2245 if (isCharacterKey) {
2246 events_1.preventDefaultEvent(event);
2247 var matchItemOpts = {
2248 focusItemAtIndex: focusItemAtIndex,
2249 focusedItemIndex: focusedItemIndex,
2250 nextChar: event.key.toLowerCase(),
2251 sortedIndexByFirstChar: sortedIndexByFirstChar,
2252 skipFocus: false,
2253 isItemAtIndexDisabled: isItemAtIndexDisabled
2254 };
2255 return matchItem(matchItemOpts, state);
2256 }
2257 if (!isSpace) {
2258 return -1;
2259 }
2260 if (isTargetListItem) {
2261 events_1.preventDefaultEvent(event);
2262 }
2263 var typeaheadOnListItem = isTargetListItem && isTypingInProgress(state);
2264 if (typeaheadOnListItem) {
2265 var matchItemOpts = {
2266 focusItemAtIndex: focusItemAtIndex,
2267 focusedItemIndex: focusedItemIndex,
2268 nextChar: ' ',
2269 sortedIndexByFirstChar: sortedIndexByFirstChar,
2270 skipFocus: false,
2271 isItemAtIndexDisabled: isItemAtIndexDisabled
2272 };
2273 // space participates in typeahead matching if in rapid typing mode
2274 return matchItem(matchItemOpts, state);
2275 }
2276 return -1;
2277}
2278exports.handleKeydown = handleKeydown;
2279
2280/***/ }),
2281
2282/***/ "./packages/mdc-list/types.ts":
2283/*!************************************!*\
2284 !*** ./packages/mdc-list/types.ts ***!
2285 \************************************/
2286/*! no static exports found */
2287/***/ (function(module, exports, __webpack_require__) {
2288
2289"use strict";
2290
2291/**
2292 * @license
2293 * Copyright 2019 Google Inc.
2294 *
2295 * Permission is hereby granted, free of charge, to any person obtaining a copy
2296 * of this software and associated documentation files (the "Software"), to deal
2297 * in the Software without restriction, including without limitation the rights
2298 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2299 * copies of the Software, and to permit persons to whom the Software is
2300 * furnished to do so, subject to the following conditions:
2301 *
2302 * The above copyright notice and this permission notice shall be included in
2303 * all copies or substantial portions of the Software.
2304 *
2305 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2306 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2307 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2308 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2309 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2310 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2311 * THE SOFTWARE.
2312 */
2313
2314Object.defineProperty(exports, "__esModule", { value: true });
2315
2316/***/ })
2317
2318/******/ });
2319});
2320//# sourceMappingURL=mdc.list.js.map
\No newline at end of file