1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
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() {
|
18 | return (function(modules) {
|
19 |
|
20 | var installedModules = {};
|
21 |
|
22 |
|
23 | function __webpack_require__(moduleId) {
|
24 |
|
25 |
|
26 | if(installedModules[moduleId]) {
|
27 | return installedModules[moduleId].exports;
|
28 | }
|
29 |
|
30 | var module = installedModules[moduleId] = {
|
31 | i: moduleId,
|
32 | l: false,
|
33 | exports: {}
|
34 | };
|
35 |
|
36 |
|
37 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
38 |
|
39 |
|
40 | module.l = true;
|
41 |
|
42 |
|
43 | return module.exports;
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 | __webpack_require__.m = modules;
|
49 |
|
50 |
|
51 | __webpack_require__.c = installedModules;
|
52 |
|
53 |
|
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 |
|
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 |
|
69 |
|
70 |
|
71 |
|
72 |
|
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 |
|
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 |
|
94 | __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
95 |
|
96 |
|
97 | __webpack_require__.p = "";
|
98 |
|
99 |
|
100 |
|
101 | return __webpack_require__(__webpack_require__.s = "./packages/mdc-list/index.ts");
|
102 | })
|
103 |
|
104 | ({
|
105 |
|
106 | "./packages/mdc-base/component.ts":
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | (function(module, exports, __webpack_require__) {
|
112 |
|
113 | "use strict";
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | var __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 | };
|
160 | var __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 | };
|
165 | Object.defineProperty(exports, "__esModule", { value: true });
|
166 | exports.MDCComponent = void 0;
|
167 | var foundation_1 = __webpack_require__( "./packages/mdc-base/foundation.ts");
|
168 | var MDCComponent = 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 |
|
177 |
|
178 |
|
179 | this.foundation = foundation === undefined ? this.getDefaultFoundation() : foundation;
|
180 | this.foundation.init();
|
181 | this.initialSyncWithDOM();
|
182 | }
|
183 | MDCComponent.attachTo = function (root) {
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | return new MDCComponent(root, new foundation_1.MDCFoundation({}));
|
189 | };
|
190 |
|
191 | MDCComponent.prototype.initialize = function () {
|
192 | var _args = [];
|
193 | for (var _i = 0; _i < arguments.length; _i++) {
|
194 | _args[_i] = arguments[_i];
|
195 | }
|
196 |
|
197 |
|
198 |
|
199 | };
|
200 | MDCComponent.prototype.getDefaultFoundation = function () {
|
201 |
|
202 |
|
203 | throw new Error('Subclasses must override getDefaultFoundation to return a properly configured ' + 'foundation class');
|
204 | };
|
205 | MDCComponent.prototype.initialSyncWithDOM = function () {
|
206 |
|
207 |
|
208 |
|
209 |
|
210 | };
|
211 | MDCComponent.prototype.destroy = function () {
|
212 |
|
213 |
|
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 |
|
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 | }();
|
243 | exports.MDCComponent = MDCComponent;
|
244 |
|
245 | exports.default = MDCComponent;
|
246 |
|
247 | }),
|
248 |
|
249 | "./packages/mdc-base/foundation.ts":
|
250 |
|
251 |
|
252 |
|
253 |
|
254 | (function(module, exports, __webpack_require__) {
|
255 |
|
256 | "use strict";
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 | Object.defineProperty(exports, "__esModule", { value: true });
|
282 | exports.MDCFoundation = void 0;
|
283 | var MDCFoundation = 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 |
|
293 |
|
294 | return {};
|
295 | },
|
296 | enumerable: false,
|
297 | configurable: true
|
298 | });
|
299 | Object.defineProperty(MDCFoundation, "strings", {
|
300 | get: function get() {
|
301 |
|
302 |
|
303 | return {};
|
304 | },
|
305 | enumerable: false,
|
306 | configurable: true
|
307 | });
|
308 | Object.defineProperty(MDCFoundation, "numbers", {
|
309 | get: function get() {
|
310 |
|
311 |
|
312 | return {};
|
313 | },
|
314 | enumerable: false,
|
315 | configurable: true
|
316 | });
|
317 | Object.defineProperty(MDCFoundation, "defaultAdapter", {
|
318 | get: function get() {
|
319 |
|
320 |
|
321 |
|
322 | return {};
|
323 | },
|
324 | enumerable: false,
|
325 | configurable: true
|
326 | });
|
327 | MDCFoundation.prototype.init = function () {
|
328 |
|
329 | };
|
330 | MDCFoundation.prototype.destroy = function () {
|
331 |
|
332 | };
|
333 | return MDCFoundation;
|
334 | }();
|
335 | exports.MDCFoundation = MDCFoundation;
|
336 |
|
337 | exports.default = MDCFoundation;
|
338 |
|
339 | }),
|
340 |
|
341 | "./packages/mdc-dom/keyboard.ts":
|
342 |
|
343 |
|
344 |
|
345 |
|
346 | (function(module, exports, __webpack_require__) {
|
347 |
|
348 | "use strict";
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 | Object.defineProperty(exports, "__esModule", { value: true });
|
374 | exports.isNavigationEvent = exports.normalizeKey = exports.KEY = void 0;
|
375 |
|
376 |
|
377 |
|
378 | exports.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 | };
|
395 | var normalizedKeys = new Set();
|
396 |
|
397 |
|
398 | normalizedKeys.add(exports.KEY.BACKSPACE);
|
399 | normalizedKeys.add(exports.KEY.ENTER);
|
400 | normalizedKeys.add(exports.KEY.SPACEBAR);
|
401 | normalizedKeys.add(exports.KEY.PAGE_UP);
|
402 | normalizedKeys.add(exports.KEY.PAGE_DOWN);
|
403 | normalizedKeys.add(exports.KEY.END);
|
404 | normalizedKeys.add(exports.KEY.HOME);
|
405 | normalizedKeys.add(exports.KEY.ARROW_LEFT);
|
406 | normalizedKeys.add(exports.KEY.ARROW_UP);
|
407 | normalizedKeys.add(exports.KEY.ARROW_RIGHT);
|
408 | normalizedKeys.add(exports.KEY.ARROW_DOWN);
|
409 | normalizedKeys.add(exports.KEY.DELETE);
|
410 | normalizedKeys.add(exports.KEY.ESCAPE);
|
411 | normalizedKeys.add(exports.KEY.TAB);
|
412 | var 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 | };
|
428 | var mappedKeyCodes = new Map();
|
429 |
|
430 |
|
431 | mappedKeyCodes.set(KEY_CODE.BACKSPACE, exports.KEY.BACKSPACE);
|
432 | mappedKeyCodes.set(KEY_CODE.ENTER, exports.KEY.ENTER);
|
433 | mappedKeyCodes.set(KEY_CODE.SPACEBAR, exports.KEY.SPACEBAR);
|
434 | mappedKeyCodes.set(KEY_CODE.PAGE_UP, exports.KEY.PAGE_UP);
|
435 | mappedKeyCodes.set(KEY_CODE.PAGE_DOWN, exports.KEY.PAGE_DOWN);
|
436 | mappedKeyCodes.set(KEY_CODE.END, exports.KEY.END);
|
437 | mappedKeyCodes.set(KEY_CODE.HOME, exports.KEY.HOME);
|
438 | mappedKeyCodes.set(KEY_CODE.ARROW_LEFT, exports.KEY.ARROW_LEFT);
|
439 | mappedKeyCodes.set(KEY_CODE.ARROW_UP, exports.KEY.ARROW_UP);
|
440 | mappedKeyCodes.set(KEY_CODE.ARROW_RIGHT, exports.KEY.ARROW_RIGHT);
|
441 | mappedKeyCodes.set(KEY_CODE.ARROW_DOWN, exports.KEY.ARROW_DOWN);
|
442 | mappedKeyCodes.set(KEY_CODE.DELETE, exports.KEY.DELETE);
|
443 | mappedKeyCodes.set(KEY_CODE.ESCAPE, exports.KEY.ESCAPE);
|
444 | mappedKeyCodes.set(KEY_CODE.TAB, exports.KEY.TAB);
|
445 | var navigationKeys = new Set();
|
446 |
|
447 |
|
448 | navigationKeys.add(exports.KEY.PAGE_UP);
|
449 | navigationKeys.add(exports.KEY.PAGE_DOWN);
|
450 | navigationKeys.add(exports.KEY.END);
|
451 | navigationKeys.add(exports.KEY.HOME);
|
452 | navigationKeys.add(exports.KEY.ARROW_LEFT);
|
453 | navigationKeys.add(exports.KEY.ARROW_UP);
|
454 | navigationKeys.add(exports.KEY.ARROW_RIGHT);
|
455 | navigationKeys.add(exports.KEY.ARROW_DOWN);
|
456 |
|
457 |
|
458 |
|
459 | function normalizeKey(evt) {
|
460 | var key = evt.key;
|
461 |
|
462 | if (normalizedKeys.has(key)) {
|
463 | return key;
|
464 | }
|
465 |
|
466 | var mappedKey = mappedKeyCodes.get(evt.keyCode);
|
467 | if (mappedKey) {
|
468 | return mappedKey;
|
469 | }
|
470 | return exports.KEY.UNKNOWN;
|
471 | }
|
472 | exports.normalizeKey = normalizeKey;
|
473 |
|
474 |
|
475 |
|
476 | function isNavigationEvent(evt) {
|
477 | return navigationKeys.has(normalizeKey(evt));
|
478 | }
|
479 | exports.isNavigationEvent = isNavigationEvent;
|
480 |
|
481 | }),
|
482 |
|
483 | "./packages/mdc-dom/ponyfill.ts":
|
484 |
|
485 |
|
486 |
|
487 |
|
488 | (function(module, exports, __webpack_require__) {
|
489 |
|
490 | "use strict";
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 | Object.defineProperty(exports, "__esModule", { value: true });
|
516 | exports.estimateScrollWidth = exports.matches = exports.closest = void 0;
|
517 |
|
518 |
|
519 |
|
520 |
|
521 | function 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 | }
|
534 | exports.closest = closest;
|
535 | function matches(element, selector) {
|
536 | var nativeMatches = element.matches || element.webkitMatchesSelector || element.msMatchesSelector;
|
537 | return nativeMatches.call(element, selector);
|
538 | }
|
539 | exports.matches = matches;
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 | function estimateScrollWidth(element) {
|
549 |
|
550 |
|
551 |
|
552 |
|
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 | }
|
565 | exports.estimateScrollWidth = estimateScrollWidth;
|
566 |
|
567 | }),
|
568 |
|
569 | "./packages/mdc-list/adapter.ts":
|
570 |
|
571 |
|
572 |
|
573 |
|
574 | (function(module, exports, __webpack_require__) {
|
575 |
|
576 | "use strict";
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 | Object.defineProperty(exports, "__esModule", { value: true });
|
602 |
|
603 | }),
|
604 |
|
605 | "./packages/mdc-list/component.ts":
|
606 |
|
607 |
|
608 |
|
609 |
|
610 | (function(module, exports, __webpack_require__) {
|
611 |
|
612 | "use strict";
|
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 | var __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 | }();
|
657 | Object.defineProperty(exports, "__esModule", { value: true });
|
658 | exports.MDCList = void 0;
|
659 | var component_1 = __webpack_require__( "./packages/mdc-base/component.ts");
|
660 | var ponyfill_1 = __webpack_require__( "./packages/mdc-dom/ponyfill.ts");
|
661 | var constants_1 = __webpack_require__( "./packages/mdc-list/constants.ts");
|
662 | var foundation_1 = __webpack_require__( "./packages/mdc-list/foundation.ts");
|
663 | var MDCList = 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 |
|
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 |
|
702 |
|
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 |
|
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 |
|
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 |
|
786 |
|
787 |
|
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 |
|
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 |
|
828 |
|
829 |
|
830 |
|
831 | MDCList.prototype.setEnabled = function (itemIndex, isEnabled) {
|
832 | this.foundation.setEnabled(itemIndex, isEnabled);
|
833 | };
|
834 | |
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 | MDCList.prototype.typeaheadMatchItem = function (nextChar, startingIndex) {
|
845 | return this.foundation.typeaheadMatchItem(nextChar, startingIndex, true);
|
846 | };
|
847 | MDCList.prototype.getDefaultFoundation = function () {
|
848 | var _this = this;
|
849 |
|
850 |
|
851 |
|
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 }, 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 |
|
934 |
|
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 |
|
961 |
|
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 |
|
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 |
|
973 |
|
974 |
|
975 | MDCList.prototype.handleFocusInEvent = function (evt) {
|
976 | var index = this.getListItemIndex(evt.target);
|
977 | this.foundation.handleFocusIn(index);
|
978 | };
|
979 | |
980 |
|
981 |
|
982 |
|
983 | MDCList.prototype.handleFocusOutEvent = function (evt) {
|
984 | var index = this.getListItemIndex(evt.target);
|
985 | this.foundation.handleFocusOut(index);
|
986 | };
|
987 | |
988 |
|
989 |
|
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 |
|
998 |
|
999 |
|
1000 | MDCList.prototype.handleClickEvent = function (evt) {
|
1001 | var index = this.getListItemIndex(evt.target);
|
1002 | var target = evt.target;
|
1003 |
|
1004 |
|
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);
|
1010 | exports.MDCList = MDCList;
|
1011 |
|
1012 | }),
|
1013 |
|
1014 | "./packages/mdc-list/constants.ts":
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 | (function(module, exports, __webpack_require__) {
|
1020 |
|
1021 | "use strict";
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 | var _a, _b;
|
1047 | Object.defineProperty(exports, "__esModule", { value: true });
|
1048 | exports.evolutionClassNameMap = exports.evolutionAttribute = exports.deprecatedClassNameMap = exports.numbers = exports.cssClasses = exports.strings = void 0;
|
1049 | var 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 | };
|
1058 | exports.cssClasses = cssClasses;
|
1059 | var 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);
|
1060 | exports.evolutionClassNameMap = evolutionClassNameMap;
|
1061 | var 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);
|
1062 | exports.deprecatedClassNameMap = deprecatedClassNameMap;
|
1063 | var 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 | };
|
1084 | exports.strings = strings;
|
1085 | var numbers = {
|
1086 | UNSET_INDEX: -1,
|
1087 | TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS: 300
|
1088 | };
|
1089 | exports.numbers = numbers;
|
1090 | var evolutionAttribute = 'evolution';
|
1091 | exports.evolutionAttribute = evolutionAttribute;
|
1092 |
|
1093 | }),
|
1094 |
|
1095 | "./packages/mdc-list/events.ts":
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 | (function(module, exports, __webpack_require__) {
|
1101 |
|
1102 | "use strict";
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 | Object.defineProperty(exports, "__esModule", { value: true });
|
1128 | exports.preventDefaultEvent = void 0;
|
1129 | var ELEMENTS_KEY_ALLOWED_IN = ['input', 'button', 'textarea', 'select'];
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 |
|
1136 | var 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 | };
|
1146 | exports.preventDefaultEvent = preventDefaultEvent;
|
1147 |
|
1148 | }),
|
1149 |
|
1150 | "./packages/mdc-list/foundation.ts":
|
1151 |
|
1152 |
|
1153 |
|
1154 |
|
1155 | (function(module, exports, __webpack_require__) {
|
1156 |
|
1157 | "use strict";
|
1158 |
|
1159 |
|
1160 |
|
1161 |
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 |
|
1179 |
|
1180 |
|
1181 |
|
1182 | var __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 | }();
|
1202 | var __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 | };
|
1214 | var __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 | });
|
1223 | var __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 | });
|
1228 | var __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 | };
|
1236 | Object.defineProperty(exports, "__esModule", { value: true });
|
1237 | exports.MDCListFoundation = void 0;
|
1238 | var foundation_1 = __webpack_require__( "./packages/mdc-base/foundation.ts");
|
1239 | var keyboard_1 = __webpack_require__( "./packages/mdc-dom/keyboard.ts");
|
1240 | var constants_1 = __webpack_require__( "./packages/mdc-list/constants.ts");
|
1241 | var events_1 = __webpack_require__( "./packages/mdc-list/events.ts");
|
1242 | var typeahead = __importStar(__webpack_require__( "./packages/mdc-list/typeahead.ts"));
|
1243 | function isNumberArray(selectedIndex) {
|
1244 | return selectedIndex instanceof Array;
|
1245 | }
|
1246 | var MDCListFoundation = 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 |
|
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 |
|
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 |
|
1363 | MDCListFoundation.prototype.getFocusedItemIndex = function () {
|
1364 | return this.focusedItemIndex;
|
1365 | };
|
1366 |
|
1367 | MDCListFoundation.prototype.setWrapFocus = function (value) {
|
1368 | this.wrapFocus = value;
|
1369 | };
|
1370 | |
1371 |
|
1372 |
|
1373 |
|
1374 | MDCListFoundation.prototype.setVerticalOrientation = function (value) {
|
1375 | this.isVertical = value;
|
1376 | };
|
1377 |
|
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 |
|
1387 |
|
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 |
|
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 |
|
1416 |
|
1417 |
|
1418 | MDCListFoundation.prototype.setHasTypeahead = function (hasTypeahead) {
|
1419 | this.hasTypeahead = hasTypeahead;
|
1420 | if (hasTypeahead) {
|
1421 | this.sortedIndexByFirstChar = this.typeaheadInitSortedIndex();
|
1422 | }
|
1423 | };
|
1424 | |
1425 |
|
1426 |
|
1427 | MDCListFoundation.prototype.isTypeaheadInProgress = function () {
|
1428 | return this.hasTypeahead && typeahead.isTypingInProgress(this.typeaheadState);
|
1429 | };
|
1430 |
|
1431 | MDCListFoundation.prototype.setUseActivatedClass = function (useActivated) {
|
1432 | this.useActivatedClass = useActivated;
|
1433 | };
|
1434 | |
1435 |
|
1436 |
|
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 |
|
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 |
|
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 |
|
1479 |
|
1480 |
|
1481 | setTimeout(function () {
|
1482 | if (!_this.adapter.isFocusInsideList()) {
|
1483 | _this.setTabindexToFirstSelectedOrFocusedItem();
|
1484 | }
|
1485 | }, 0);
|
1486 | };
|
1487 | |
1488 |
|
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 |
|
1501 |
|
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 |
|
1533 |
|
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 |
|
1555 |
|
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 |
|
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 |
|
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 |
|
1614 | return index;
|
1615 | }
|
1616 | }
|
1617 | this.focusItemAtIndex(nextIndex);
|
1618 | return nextIndex;
|
1619 | };
|
1620 | |
1621 |
|
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 |
|
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 |
|
1652 |
|
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 |
|
1688 |
|
1689 | MDCListFoundation.prototype.setAriaForSingleSelectionAtIndex = function (index) {
|
1690 |
|
1691 |
|
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 |
|
1707 |
|
1708 | MDCListFoundation.prototype.getSelectionAttribute = function () {
|
1709 | return this.useSelectedAttr ? constants_1.strings.ARIA_SELECTED : constants_1.strings.ARIA_CHECKED;
|
1710 | };
|
1711 | |
1712 |
|
1713 |
|
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 |
|
1739 |
|
1740 |
|
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 |
|
1746 |
|
1747 |
|
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 |
|
1757 |
|
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 |
|
1768 | if (!this.isSelectableList()) {
|
1769 | return Math.max(this.focusedItemIndex, 0);
|
1770 | }
|
1771 |
|
1772 | if (typeof this.selectedIndex === 'number' && this.selectedIndex !== constants_1.numbers.UNSET_INDEX) {
|
1773 | return this.selectedIndex;
|
1774 | }
|
1775 |
|
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 |
|
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 |
|
1812 |
|
1813 |
|
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 |
|
1834 |
|
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 |
|
1852 | if (currentlySelectedIndexes.length === count) {
|
1853 | this.setCheckboxAtIndex([]);
|
1854 | } else {
|
1855 |
|
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 |
|
1867 |
|
1868 |
|
1869 |
|
1870 |
|
1871 |
|
1872 |
|
1873 |
|
1874 |
|
1875 |
|
1876 |
|
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 |
|
1899 |
|
1900 |
|
1901 |
|
1902 |
|
1903 | MDCListFoundation.prototype.typeaheadInitSortedIndex = function () {
|
1904 | return typeahead.initSortedIndex(this.adapter.getListItemCount(), this.adapter.getPrimaryTextAtIndex);
|
1905 | };
|
1906 | |
1907 |
|
1908 |
|
1909 | MDCListFoundation.prototype.clearTypeaheadBuffer = function () {
|
1910 | typeahead.clearBuffer(this.typeaheadState);
|
1911 | };
|
1912 | return MDCListFoundation;
|
1913 | }(foundation_1.MDCFoundation);
|
1914 | exports.MDCListFoundation = MDCListFoundation;
|
1915 |
|
1916 | exports.default = MDCListFoundation;
|
1917 |
|
1918 | }),
|
1919 |
|
1920 | "./packages/mdc-list/index.ts":
|
1921 |
|
1922 |
|
1923 |
|
1924 |
|
1925 | (function(module, exports, __webpack_require__) {
|
1926 |
|
1927 | "use strict";
|
1928 |
|
1929 |
|
1930 |
|
1931 |
|
1932 |
|
1933 |
|
1934 |
|
1935 |
|
1936 |
|
1937 |
|
1938 |
|
1939 |
|
1940 |
|
1941 |
|
1942 |
|
1943 |
|
1944 |
|
1945 |
|
1946 |
|
1947 |
|
1948 |
|
1949 |
|
1950 |
|
1951 |
|
1952 | var __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 | });
|
1961 | var __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 | };
|
1966 | Object.defineProperty(exports, "__esModule", { value: true });
|
1967 | __exportStar(__webpack_require__( "./packages/mdc-list/adapter.ts"), exports);
|
1968 | __exportStar(__webpack_require__( "./packages/mdc-list/component.ts"), exports);
|
1969 | __exportStar(__webpack_require__( "./packages/mdc-list/constants.ts"), exports);
|
1970 | __exportStar(__webpack_require__( "./packages/mdc-list/foundation.ts"), exports);
|
1971 | __exportStar(__webpack_require__( "./packages/mdc-list/types.ts"), exports);
|
1972 |
|
1973 | }),
|
1974 |
|
1975 | "./packages/mdc-list/typeahead.ts":
|
1976 |
|
1977 |
|
1978 |
|
1979 |
|
1980 | (function(module, exports, __webpack_require__) {
|
1981 |
|
1982 | "use strict";
|
1983 |
|
1984 |
|
1985 |
|
1986 |
|
1987 |
|
1988 |
|
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 |
|
1997 |
|
1998 |
|
1999 |
|
2000 |
|
2001 |
|
2002 |
|
2003 |
|
2004 |
|
2005 |
|
2006 |
|
2007 | Object.defineProperty(exports, "__esModule", { value: true });
|
2008 | exports.handleKeydown = exports.clearBuffer = exports.isTypingInProgress = exports.matchItem = exports.initSortedIndex = exports.initState = void 0;
|
2009 | var keyboard_1 = __webpack_require__( "./packages/mdc-dom/keyboard.ts");
|
2010 | var constants_1 = __webpack_require__( "./packages/mdc-list/constants.ts");
|
2011 | var events_1 = __webpack_require__( "./packages/mdc-list/events.ts");
|
2012 |
|
2013 |
|
2014 |
|
2015 |
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 | function initState() {
|
2021 | var state = {
|
2022 | bufferClearTimeout: 0,
|
2023 | currentFirstChar: '',
|
2024 | sortedIndexCursor: 0,
|
2025 | typeaheadBuffer: ''
|
2026 | };
|
2027 | return state;
|
2028 | }
|
2029 | exports.initState = initState;
|
2030 |
|
2031 |
|
2032 |
|
2033 |
|
2034 |
|
2035 |
|
2036 |
|
2037 |
|
2038 |
|
2039 |
|
2040 |
|
2041 | function initSortedIndex(listItemCount, getPrimaryTextByItemIndex) {
|
2042 | var sortedIndexByFirstChar = new Map();
|
2043 |
|
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 |
|
2056 |
|
2057 | sortedIndexByFirstChar.forEach(function (values) {
|
2058 | values.sort(function (first, second) {
|
2059 | return first.index - second.index;
|
2060 | });
|
2061 | });
|
2062 | return sortedIndexByFirstChar;
|
2063 | }
|
2064 | exports.initSortedIndex = initSortedIndex;
|
2065 |
|
2066 |
|
2067 |
|
2068 |
|
2069 |
|
2070 |
|
2071 |
|
2072 |
|
2073 |
|
2074 |
|
2075 |
|
2076 |
|
2077 |
|
2078 |
|
2079 |
|
2080 |
|
2081 | function 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 | }
|
2104 | exports.matchItem = matchItem;
|
2105 |
|
2106 |
|
2107 |
|
2108 |
|
2109 |
|
2110 | function 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 |
|
2117 |
|
2118 |
|
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 |
|
2127 |
|
2128 |
|
2129 |
|
2130 | state.currentFirstChar = firstChar;
|
2131 | var newCursorPosition = -1;
|
2132 | var cursorPosition;
|
2133 |
|
2134 | for (cursorPosition = 0; cursorPosition < itemsMatchingFirstChar.length; cursorPosition++) {
|
2135 | if (!isItemAtIndexDisabled(itemsMatchingFirstChar[cursorPosition].index)) {
|
2136 | newCursorPosition = cursorPosition;
|
2137 | break;
|
2138 | }
|
2139 | }
|
2140 |
|
2141 |
|
2142 |
|
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 |
|
2157 |
|
2158 |
|
2159 | function matchAllChars(sortedIndexByFirstChar, isItemAtIndexDisabled, state) {
|
2160 | var firstChar = state.typeaheadBuffer[0];
|
2161 | var itemsMatchingFirstChar = sortedIndexByFirstChar.get(firstChar);
|
2162 | if (!itemsMatchingFirstChar) {
|
2163 | return -1;
|
2164 | }
|
2165 |
|
2166 | var startingItem = itemsMatchingFirstChar[state.sortedIndexCursor];
|
2167 | if (startingItem.text.lastIndexOf(state.typeaheadBuffer, 0) === 0 && !isItemAtIndexDisabled(startingItem.index)) {
|
2168 | return startingItem.index;
|
2169 | }
|
2170 |
|
2171 |
|
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 |
|
2192 |
|
2193 |
|
2194 |
|
2195 | function isTypingInProgress(state) {
|
2196 | return state.typeaheadBuffer.length > 0;
|
2197 | }
|
2198 | exports.isTypingInProgress = isTypingInProgress;
|
2199 |
|
2200 |
|
2201 |
|
2202 |
|
2203 |
|
2204 |
|
2205 | function clearBuffer(state) {
|
2206 | state.typeaheadBuffer = '';
|
2207 | }
|
2208 | exports.clearBuffer = clearBuffer;
|
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 |
|
2214 |
|
2215 |
|
2216 |
|
2217 |
|
2218 |
|
2219 |
|
2220 |
|
2221 |
|
2222 |
|
2223 |
|
2224 |
|
2225 |
|
2226 | function 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 |
|
2274 | return matchItem(matchItemOpts, state);
|
2275 | }
|
2276 | return -1;
|
2277 | }
|
2278 | exports.handleKeydown = handleKeydown;
|
2279 |
|
2280 | }),
|
2281 |
|
2282 | "./packages/mdc-list/types.ts":
|
2283 |
|
2284 |
|
2285 |
|
2286 |
|
2287 | (function(module, exports, __webpack_require__) {
|
2288 |
|
2289 | "use strict";
|
2290 |
|
2291 |
|
2292 |
|
2293 |
|
2294 |
|
2295 |
|
2296 |
|
2297 |
|
2298 |
|
2299 |
|
2300 |
|
2301 |
|
2302 |
|
2303 |
|
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 |
|
2309 |
|
2310 |
|
2311 |
|
2312 |
|
2313 |
|
2314 | Object.defineProperty(exports, "__esModule", { value: true });
|
2315 |
|
2316 | })
|
2317 |
|
2318 | });
|
2319 | });
|
2320 |
|
\ | No newline at end of file |