UNPKG

@material/menu

Version:
1,145 lines (1,111 loc) • 195 kB
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/material-components/material-components-web/blob/master/LICENSE */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define("@material/menu", [], factory); else if(typeof exports === 'object') exports["menu"] = factory(); else root["mdc"] = root["mdc"] || {}, root["mdc"]["menu"] = factory(); })(this, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = "./packages/mdc-menu/index.ts"); /******/ }) /************************************************************************/ /******/ ({ /***/ "./packages/mdc-animation/util.ts": /*!****************************************!*\ !*** ./packages/mdc-animation/util.ts ***! \****************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * @license * Copyright 2016 Google Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getCorrectEventName = exports.getCorrectPropertyName = void 0; var cssPropertyNameMap = { animation: { prefixed: '-webkit-animation', standard: 'animation' }, transform: { prefixed: '-webkit-transform', standard: 'transform' }, transition: { prefixed: '-webkit-transition', standard: 'transition' } }; var jsEventTypeMap = { animationend: { cssProperty: 'animation', prefixed: 'webkitAnimationEnd', standard: 'animationend' }, animationiteration: { cssProperty: 'animation', prefixed: 'webkitAnimationIteration', standard: 'animationiteration' }, animationstart: { cssProperty: 'animation', prefixed: 'webkitAnimationStart', standard: 'animationstart' }, transitionend: { cssProperty: 'transition', prefixed: 'webkitTransitionEnd', standard: 'transitionend' } }; function isWindow(windowObj) { return Boolean(windowObj.document) && typeof windowObj.document.createElement === 'function'; } function getCorrectPropertyName(windowObj, cssProperty) { if (isWindow(windowObj) && cssProperty in cssPropertyNameMap) { var el = windowObj.document.createElement('div'); var _a = cssPropertyNameMap[cssProperty], standard = _a.standard, prefixed = _a.prefixed; var isStandard = standard in el.style; return isStandard ? standard : prefixed; } return cssProperty; } exports.getCorrectPropertyName = getCorrectPropertyName; function getCorrectEventName(windowObj, eventType) { if (isWindow(windowObj) && eventType in jsEventTypeMap) { var el = windowObj.document.createElement('div'); var _a = jsEventTypeMap[eventType], standard = _a.standard, prefixed = _a.prefixed, cssProperty = _a.cssProperty; var isStandard = cssProperty in el.style; return isStandard ? standard : prefixed; } return eventType; } exports.getCorrectEventName = getCorrectEventName; /***/ }), /***/ "./packages/mdc-base/component.ts": /*!****************************************!*\ !*** ./packages/mdc-base/component.ts ***! \****************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * @license * Copyright 2016 Google Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ var __read = this && this.__read || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) { ar.push(r.value); } } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = this && this.__spreadArray || function (to, from) { for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) { to[j] = from[i]; }return to; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MDCComponent = void 0; var foundation_1 = __webpack_require__(/*! ./foundation */ "./packages/mdc-base/foundation.ts"); var MDCComponent = /** @class */function () { function MDCComponent(root, foundation) { var args = []; for (var _i = 2; _i < arguments.length; _i++) { args[_i - 2] = arguments[_i]; } this.root = root; this.initialize.apply(this, __spreadArray([], __read(args))); // Note that we initialize foundation here and not within the constructor's // default param so that this.root is defined and can be used within the // foundation class. this.foundation = foundation === undefined ? this.getDefaultFoundation() : foundation; this.foundation.init(); this.initialSyncWithDOM(); } MDCComponent.attachTo = function (root) { // Subclasses which extend MDCBase should provide an attachTo() method that takes a root element and // returns an instantiated component with its root set to that element. Also note that in the cases of // subclasses, an explicit foundation class will not have to be passed in; it will simply be initialized // from getDefaultFoundation(). return new MDCComponent(root, new foundation_1.MDCFoundation({})); }; /* istanbul ignore next: method param only exists for typing purposes; it does not need to be unit tested */ MDCComponent.prototype.initialize = function () { var _args = []; for (var _i = 0; _i < arguments.length; _i++) { _args[_i] = arguments[_i]; } // Subclasses can override this to do any additional setup work that would be considered part of a // "constructor". Essentially, it is a hook into the parent constructor before the foundation is // initialized. Any additional arguments besides root and foundation will be passed in here. }; MDCComponent.prototype.getDefaultFoundation = function () { // Subclasses must override this method to return a properly configured foundation class for the // component. throw new Error('Subclasses must override getDefaultFoundation to return a properly configured ' + 'foundation class'); }; MDCComponent.prototype.initialSyncWithDOM = function () { // Subclasses should override this method if they need to perform work to synchronize with a host DOM // object. An example of this would be a form control wrapper that needs to synchronize its internal state // to some property or attribute of the host DOM. Please note: this is *not* the place to perform DOM // reads/writes that would cause layout / paint, as this is called synchronously from within the constructor. }; MDCComponent.prototype.destroy = function () { // Subclasses may implement this method to release any resources / deregister any listeners they have // attached. An example of this might be deregistering a resize event from the window object. this.foundation.destroy(); }; MDCComponent.prototype.listen = function (evtType, handler, options) { this.root.addEventListener(evtType, handler, options); }; MDCComponent.prototype.unlisten = function (evtType, handler, options) { this.root.removeEventListener(evtType, handler, options); }; /** * Fires a cross-browser-compatible custom event from the component root of the given type, with the given data. */ MDCComponent.prototype.emit = function (evtType, evtData, shouldBubble) { if (shouldBubble === void 0) { shouldBubble = false; } var evt; if (typeof CustomEvent === 'function') { evt = new CustomEvent(evtType, { bubbles: shouldBubble, detail: evtData }); } else { evt = document.createEvent('CustomEvent'); evt.initCustomEvent(evtType, shouldBubble, false, evtData); } this.root.dispatchEvent(evt); }; return MDCComponent; }(); exports.MDCComponent = MDCComponent; // tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier. exports.default = MDCComponent; /***/ }), /***/ "./packages/mdc-base/foundation.ts": /*!*****************************************!*\ !*** ./packages/mdc-base/foundation.ts ***! \*****************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * @license * Copyright 2016 Google Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.MDCFoundation = void 0; var MDCFoundation = /** @class */function () { function MDCFoundation(adapter) { if (adapter === void 0) { adapter = {}; } this.adapter = adapter; } Object.defineProperty(MDCFoundation, "cssClasses", { get: function get() { // Classes extending MDCFoundation should implement this method to return an object which exports every // CSS class the foundation class needs as a property. e.g. {ACTIVE: 'mdc-component--active'} return {}; }, enumerable: false, configurable: true }); Object.defineProperty(MDCFoundation, "strings", { get: function get() { // Classes extending MDCFoundation should implement this method to return an object which exports all // semantic strings as constants. e.g. {ARIA_ROLE: 'tablist'} return {}; }, enumerable: false, configurable: true }); Object.defineProperty(MDCFoundation, "numbers", { get: function get() { // Classes extending MDCFoundation should implement this method to return an object which exports all // of its semantic numbers as constants. e.g. {ANIMATION_DELAY_MS: 350} return {}; }, enumerable: false, configurable: true }); Object.defineProperty(MDCFoundation, "defaultAdapter", { get: function get() { // Classes extending MDCFoundation may choose to implement this getter in order to provide a convenient // way of viewing the necessary methods of an adapter. In the future, this could also be used for adapter // validation. return {}; }, enumerable: false, configurable: true }); MDCFoundation.prototype.init = function () { // Subclasses should override this method to perform initialization routines (registering events, etc.) }; MDCFoundation.prototype.destroy = function () { // Subclasses should override this method to perform de-initialization routines (de-registering events, etc.) }; return MDCFoundation; }(); exports.MDCFoundation = MDCFoundation; // tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier. exports.default = MDCFoundation; /***/ }), /***/ "./packages/mdc-dom/keyboard.ts": /*!**************************************!*\ !*** ./packages/mdc-dom/keyboard.ts ***! \**************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * @license * Copyright 2020 Google Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.isNavigationEvent = exports.normalizeKey = exports.KEY = void 0; /** * KEY provides normalized string values for keys. */ exports.KEY = { UNKNOWN: 'Unknown', BACKSPACE: 'Backspace', ENTER: 'Enter', SPACEBAR: 'Spacebar', PAGE_UP: 'PageUp', PAGE_DOWN: 'PageDown', END: 'End', HOME: 'Home', ARROW_LEFT: 'ArrowLeft', ARROW_UP: 'ArrowUp', ARROW_RIGHT: 'ArrowRight', ARROW_DOWN: 'ArrowDown', DELETE: 'Delete', ESCAPE: 'Escape', TAB: 'Tab' }; var normalizedKeys = new Set(); // IE11 has no support for new Map with iterable so we need to initialize this // by hand. normalizedKeys.add(exports.KEY.BACKSPACE); normalizedKeys.add(exports.KEY.ENTER); normalizedKeys.add(exports.KEY.SPACEBAR); normalizedKeys.add(exports.KEY.PAGE_UP); normalizedKeys.add(exports.KEY.PAGE_DOWN); normalizedKeys.add(exports.KEY.END); normalizedKeys.add(exports.KEY.HOME); normalizedKeys.add(exports.KEY.ARROW_LEFT); normalizedKeys.add(exports.KEY.ARROW_UP); normalizedKeys.add(exports.KEY.ARROW_RIGHT); normalizedKeys.add(exports.KEY.ARROW_DOWN); normalizedKeys.add(exports.KEY.DELETE); normalizedKeys.add(exports.KEY.ESCAPE); normalizedKeys.add(exports.KEY.TAB); var KEY_CODE = { BACKSPACE: 8, ENTER: 13, SPACEBAR: 32, PAGE_UP: 33, PAGE_DOWN: 34, END: 35, HOME: 36, ARROW_LEFT: 37, ARROW_UP: 38, ARROW_RIGHT: 39, ARROW_DOWN: 40, DELETE: 46, ESCAPE: 27, TAB: 9 }; var mappedKeyCodes = new Map(); // IE11 has no support for new Map with iterable so we need to initialize this // by hand. mappedKeyCodes.set(KEY_CODE.BACKSPACE, exports.KEY.BACKSPACE); mappedKeyCodes.set(KEY_CODE.ENTER, exports.KEY.ENTER); mappedKeyCodes.set(KEY_CODE.SPACEBAR, exports.KEY.SPACEBAR); mappedKeyCodes.set(KEY_CODE.PAGE_UP, exports.KEY.PAGE_UP); mappedKeyCodes.set(KEY_CODE.PAGE_DOWN, exports.KEY.PAGE_DOWN); mappedKeyCodes.set(KEY_CODE.END, exports.KEY.END); mappedKeyCodes.set(KEY_CODE.HOME, exports.KEY.HOME); mappedKeyCodes.set(KEY_CODE.ARROW_LEFT, exports.KEY.ARROW_LEFT); mappedKeyCodes.set(KEY_CODE.ARROW_UP, exports.KEY.ARROW_UP); mappedKeyCodes.set(KEY_CODE.ARROW_RIGHT, exports.KEY.ARROW_RIGHT); mappedKeyCodes.set(KEY_CODE.ARROW_DOWN, exports.KEY.ARROW_DOWN); mappedKeyCodes.set(KEY_CODE.DELETE, exports.KEY.DELETE); mappedKeyCodes.set(KEY_CODE.ESCAPE, exports.KEY.ESCAPE); mappedKeyCodes.set(KEY_CODE.TAB, exports.KEY.TAB); var navigationKeys = new Set(); // IE11 has no support for new Set with iterable so we need to initialize this // by hand. navigationKeys.add(exports.KEY.PAGE_UP); navigationKeys.add(exports.KEY.PAGE_DOWN); navigationKeys.add(exports.KEY.END); navigationKeys.add(exports.KEY.HOME); navigationKeys.add(exports.KEY.ARROW_LEFT); navigationKeys.add(exports.KEY.ARROW_UP); navigationKeys.add(exports.KEY.ARROW_RIGHT); navigationKeys.add(exports.KEY.ARROW_DOWN); /** * normalizeKey returns the normalized string for a navigational action. */ function normalizeKey(evt) { var key = evt.key; // If the event already has a normalized key, return it if (normalizedKeys.has(key)) { return key; } // tslint:disable-next-line:deprecation var mappedKey = mappedKeyCodes.get(evt.keyCode); if (mappedKey) { return mappedKey; } return exports.KEY.UNKNOWN; } exports.normalizeKey = normalizeKey; /** * isNavigationEvent returns whether the event is a navigation event */ function isNavigationEvent(evt) { return navigationKeys.has(normalizeKey(evt)); } exports.isNavigationEvent = isNavigationEvent; /***/ }), /***/ "./packages/mdc-dom/ponyfill.ts": /*!**************************************!*\ !*** ./packages/mdc-dom/ponyfill.ts ***! \**************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * @license * Copyright 2018 Google Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.estimateScrollWidth = exports.matches = exports.closest = void 0; /** * @fileoverview A "ponyfill" is a polyfill that doesn't modify the global prototype chain. * This makes ponyfills safer than traditional polyfills, especially for libraries like MDC. */ function closest(element, selector) { if (element.closest) { return element.closest(selector); } var el = element; while (el) { if (matches(el, selector)) { return el; } el = el.parentElement; } return null; } exports.closest = closest; function matches(element, selector) { var nativeMatches = element.matches || element.webkitMatchesSelector || element.msMatchesSelector; return nativeMatches.call(element, selector); } exports.matches = matches; /** * Used to compute the estimated scroll width of elements. When an element is * hidden due to display: none; being applied to a parent element, the width is * returned as 0. However, the element will have a true width once no longer * inside a display: none context. This method computes an estimated width when * the element is hidden or returns the true width when the element is visble. * @param {Element} element the element whose width to estimate */ function estimateScrollWidth(element) { // Check the offsetParent. If the element inherits display: none from any // parent, the offsetParent property will be null (see // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent). // This check ensures we only clone the node when necessary. var htmlEl = element; if (htmlEl.offsetParent !== null) { return htmlEl.scrollWidth; } var clone = htmlEl.cloneNode(true); clone.style.setProperty('position', 'absolute'); clone.style.setProperty('transform', 'translate(-9999px, -9999px)'); document.documentElement.appendChild(clone); var scrollWidth = clone.scrollWidth; document.documentElement.removeChild(clone); return scrollWidth; } exports.estimateScrollWidth = estimateScrollWidth; /***/ }), /***/ "./packages/mdc-list/component.ts": /*!****************************************!*\ !*** ./packages/mdc-list/component.ts ***! \****************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * @license * Copyright 2018 Google Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ var __extends = this && this.__extends || function () { var _extendStatics = function extendStatics(d, b) { _extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; } || function (d, b) { for (var p in b) { if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; } }; return _extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); _extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); Object.defineProperty(exports, "__esModule", { value: true }); exports.MDCList = void 0; var component_1 = __webpack_require__(/*! @material/base/component */ "./packages/mdc-base/component.ts"); var ponyfill_1 = __webpack_require__(/*! @material/dom/ponyfill */ "./packages/mdc-dom/ponyfill.ts"); var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-list/constants.ts"); var foundation_1 = __webpack_require__(/*! ./foundation */ "./packages/mdc-list/foundation.ts"); var MDCList = /** @class */function (_super) { __extends(MDCList, _super); function MDCList() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(MDCList.prototype, "vertical", { set: function set(value) { this.foundation.setVerticalOrientation(value); }, enumerable: false, configurable: true }); Object.defineProperty(MDCList.prototype, "listElements", { get: function get() { return Array.from(this.root.querySelectorAll("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS])); }, enumerable: false, configurable: true }); Object.defineProperty(MDCList.prototype, "wrapFocus", { set: function set(value) { this.foundation.setWrapFocus(value); }, enumerable: false, configurable: true }); Object.defineProperty(MDCList.prototype, "typeaheadInProgress", { /** * @return Whether typeahead is currently matching a user-specified prefix. */ get: function get() { return this.foundation.isTypeaheadInProgress(); }, enumerable: false, configurable: true }); Object.defineProperty(MDCList.prototype, "hasTypeahead", { /** * Sets whether typeahead functionality is enabled on the list. * @param hasTypeahead Whether typeahead is enabled. */ set: function set(hasTypeahead) { this.foundation.setHasTypeahead(hasTypeahead); }, enumerable: false, configurable: true }); Object.defineProperty(MDCList.prototype, "singleSelection", { set: function set(isSingleSelectionList) { this.foundation.setSingleSelection(isSingleSelectionList); }, enumerable: false, configurable: true }); Object.defineProperty(MDCList.prototype, "disabledItemsFocusable", { set: function set(areDisabledItemsFocusable) { this.foundation.setDisabledItemsFocusable(areDisabledItemsFocusable); }, enumerable: false, configurable: true }); Object.defineProperty(MDCList.prototype, "selectedIndex", { get: function get() { return this.foundation.getSelectedIndex(); }, set: function set(index) { this.foundation.setSelectedIndex(index); }, enumerable: false, configurable: true }); MDCList.attachTo = function (root) { return new MDCList(root); }; MDCList.prototype.initialSyncWithDOM = function () { this.isEvolutionEnabled = constants_1.evolutionAttribute in this.root.dataset; if (this.isEvolutionEnabled) { this.classNameMap = constants_1.evolutionClassNameMap; } else if (ponyfill_1.matches(this.root, constants_1.strings.DEPRECATED_SELECTOR)) { this.classNameMap = constants_1.deprecatedClassNameMap; } else { this.classNameMap = Object.values(constants_1.cssClasses).reduce(function (obj, className) { obj[className] = className; return obj; }, {}); } this.handleClick = this.handleClickEvent.bind(this); this.handleKeydown = this.handleKeydownEvent.bind(this); this.focusInEventListener = this.handleFocusInEvent.bind(this); this.focusOutEventListener = this.handleFocusOutEvent.bind(this); this.listen('keydown', this.handleKeydown); this.listen('click', this.handleClick); this.listen('focusin', this.focusInEventListener); this.listen('focusout', this.focusOutEventListener); this.layout(); this.initializeListType(); this.ensureFocusable(); }; MDCList.prototype.destroy = function () { this.unlisten('keydown', this.handleKeydown); this.unlisten('click', this.handleClick); this.unlisten('focusin', this.focusInEventListener); this.unlisten('focusout', this.focusOutEventListener); }; MDCList.prototype.layout = function () { var direction = this.root.getAttribute(constants_1.strings.ARIA_ORIENTATION); this.vertical = direction !== constants_1.strings.ARIA_ORIENTATION_HORIZONTAL; var itemSelector = "." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS] + ":not([tabindex])"; var childSelector = constants_1.strings.FOCUSABLE_CHILD_ELEMENTS; // List items need to have at least tabindex=-1 to be focusable. var itemEls = this.root.querySelectorAll(itemSelector); if (itemEls.length) { Array.prototype.forEach.call(itemEls, function (el) { el.setAttribute('tabindex', '-1'); }); } // Child button/a elements are not tabbable until the list item is focused. var focusableChildEls = this.root.querySelectorAll(childSelector); if (focusableChildEls.length) { Array.prototype.forEach.call(focusableChildEls, function (el) { el.setAttribute('tabindex', '-1'); }); } if (this.isEvolutionEnabled) { this.foundation.setUseSelectedAttribute(true); } this.foundation.layout(); }; /** * Extracts the primary text from a list item. * @param item The list item element. * @return The primary text in the element. */ MDCList.prototype.getPrimaryText = function (item) { var _a; var primaryText = item.querySelector("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_PRIMARY_TEXT_CLASS]); if (this.isEvolutionEnabled || primaryText) { return (_a = primaryText === null || primaryText === void 0 ? void 0 : primaryText.textContent) !== null && _a !== void 0 ? _a : ''; } var singleLineText = item.querySelector("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_TEXT_CLASS]); return singleLineText && singleLineText.textContent || ''; }; /** * Initialize selectedIndex value based on pre-selected list items. */ MDCList.prototype.initializeListType = function () { var _this = this; this.isInteractive = ponyfill_1.matches(this.root, constants_1.strings.ARIA_INTERACTIVE_ROLES_SELECTOR); if (this.isEvolutionEnabled && this.isInteractive) { var selection = Array.from(this.root.querySelectorAll(constants_1.strings.SELECTED_ITEM_SELECTOR), function (listItem) { return _this.listElements.indexOf(listItem); }); if (ponyfill_1.matches(this.root, constants_1.strings.ARIA_MULTI_SELECTABLE_SELECTOR)) { this.selectedIndex = selection; } else if (selection.length > 0) { this.selectedIndex = selection[0]; } return; } var checkboxListItems = this.root.querySelectorAll(constants_1.strings.ARIA_ROLE_CHECKBOX_SELECTOR); var radioSelectedListItem = this.root.querySelector(constants_1.strings.ARIA_CHECKED_RADIO_SELECTOR); if (checkboxListItems.length) { var preselectedItems = this.root.querySelectorAll(constants_1.strings.ARIA_CHECKED_CHECKBOX_SELECTOR); this.selectedIndex = Array.from(preselectedItems, function (listItem) { return _this.listElements.indexOf(listItem); }); } else if (radioSelectedListItem) { this.selectedIndex = this.listElements.indexOf(radioSelectedListItem); } }; /** * Updates the list item at itemIndex to the desired isEnabled state. * @param itemIndex Index of the list item * @param isEnabled Sets the list item to enabled or disabled. */ MDCList.prototype.setEnabled = function (itemIndex, isEnabled) { this.foundation.setEnabled(itemIndex, isEnabled); }; /** * Given the next desired character from the user, adds it to the typeahead * buffer. Then, attempts to find the next option matching the buffer. Wraps * around if at the end of options. * * @param nextChar The next character to add to the prefix buffer. * @param startingIndex The index from which to start matching. Defaults to * the currently focused index. * @return The index of the matched item. */ MDCList.prototype.typeaheadMatchItem = function (nextChar, startingIndex) { return this.foundation.typeaheadMatchItem(nextChar, startingIndex, /** skipFocus */true); }; MDCList.prototype.getDefaultFoundation = function () { var _this = this; // DO NOT INLINE this variable. For backward compatibility, foundations take // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any // methods, we need a separate, strongly typed adapter variable. var adapter = { addClassForElementIndex: function addClassForElementIndex(index, className) { var element = _this.listElements[index]; if (element) { element.classList.add(_this.classNameMap[className]); } }, focusItemAtIndex: function focusItemAtIndex(index) { var element = _this.listElements[index]; if (element) { element.focus(); } }, getAttributeForElementIndex: function getAttributeForElementIndex(index, attr) { return _this.listElements[index].getAttribute(attr); }, getFocusedElementIndex: function getFocusedElementIndex() { return _this.listElements.indexOf(document.activeElement); }, getListItemCount: function getListItemCount() { return _this.listElements.length; }, getPrimaryTextAtIndex: function getPrimaryTextAtIndex(index) { return _this.getPrimaryText(_this.listElements[index]); }, hasCheckboxAtIndex: function hasCheckboxAtIndex(index) { var listItem = _this.listElements[index]; return !!listItem.querySelector(constants_1.strings.CHECKBOX_SELECTOR); }, hasRadioAtIndex: function hasRadioAtIndex(index) { var listItem = _this.listElements[index]; return !!listItem.querySelector(constants_1.strings.RADIO_SELECTOR); }, isCheckboxCheckedAtIndex: function isCheckboxCheckedAtIndex(index) { var listItem = _this.listElements[index]; var toggleEl = listItem.querySelector(constants_1.strings.CHECKBOX_SELECTOR); return toggleEl.checked; }, isFocusInsideList: function isFocusInsideList() { return _this.root !== document.activeElement && _this.root.contains(document.activeElement); }, isRootFocused: function isRootFocused() { return document.activeElement === _this.root; }, listItemAtIndexHasClass: function listItemAtIndexHasClass(index, className) { return _this.listElements[index].classList.contains(_this.classNameMap[className]); }, notifyAction: function notifyAction(index) { _this.emit(constants_1.strings.ACTION_EVENT, { index: index }, /** shouldBubble */true); }, notifySelectionChange: function notifySelectionChange(changedIndices) { _this.emit(constants_1.strings.SELECTION_CHANGE_EVENT, { changedIndices: changedIndices }, /** shouldBubble */true); }, removeClassForElementIndex: function removeClassForElementIndex(index, className) { var element = _this.listElements[index]; if (element) { element.classList.remove(_this.classNameMap[className]); } }, setAttributeForElementIndex: function setAttributeForElementIndex(index, attr, value) { var element = _this.listElements[index]; if (element) { element.setAttribute(attr, value); } }, setCheckedCheckboxOrRadioAtIndex: function setCheckedCheckboxOrRadioAtIndex(index, isChecked) { var listItem = _this.listElements[index]; var toggleEl = listItem.querySelector(constants_1.strings.CHECKBOX_RADIO_SELECTOR); toggleEl.checked = isChecked; var event = document.createEvent('Event'); event.initEvent('change', true, true); toggleEl.dispatchEvent(event); }, setTabIndexForListItemChildren: function setTabIndexForListItemChildren(listItemIndex, tabIndexValue) { var element = _this.listElements[listItemIndex]; var selector = constants_1.strings.CHILD_ELEMENTS_TO_TOGGLE_TABINDEX; Array.prototype.forEach.call(element.querySelectorAll(selector), function (el) { el.setAttribute('tabindex', tabIndexValue); }); } }; return new foundation_1.MDCListFoundation(adapter); }; /** * Ensures that at least one item is focusable if the list is interactive and * doesn't specify a suitable tabindex. */ MDCList.prototype.ensureFocusable = function () { if (this.isEvolutionEnabled && this.isInteractive) { if (!this.root.querySelector("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS] + "[tabindex=\"0\"]")) { var index = this.initialFocusIndex(); if (index !== -1) { this.listElements[index].tabIndex = 0; } } } }; MDCList.prototype.initialFocusIndex = function () { if (this.selectedIndex instanceof Array && this.selectedIndex.length > 0) { return this.selectedIndex[0]; } if (typeof this.selectedIndex === 'number' && this.selectedIndex !== constants_1.numbers.UNSET_INDEX) { return this.selectedIndex; } var el = this.root.querySelector("." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS] + ":not(." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_DISABLED_CLASS] + ")"); if (el === null) { return -1; } return this.getListItemIndex(el); }; /** * Used to figure out which list item this event is targetting. Or returns -1 * if there is no list item */ MDCList.prototype.getListItemIndex = function (el) { var nearestParent = ponyfill_1.closest(el, "." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS] + ", ." + this.classNameMap[constants_1.cssClasses.ROOT]); // Get the index of the element if it is a list item. if (nearestParent && ponyfill_1.matches(nearestParent, "." + this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS])) { return this.listElements.indexOf(nearestParent); } return -1; }; /** * Used to figure out which element was clicked before sending the event to * the foundation. */ MDCList.prototype.handleFocusInEvent = function (evt) { var index = this.getListItemIndex(evt.target); this.foundation.handleFocusIn(index); }; /** * Used to figure out which element was clicked before sending the event to * the foundation. */ MDCList.prototype.handleFocusOutEvent = function (evt) { var index = this.getListItemIndex(evt.target); this.foundation.handleFocusOut(index); }; /** * Used to figure out which element was focused when keydown event occurred * before sending the event to the foundation. */ MDCList.prototype.handleKeydownEvent = function (evt) { var index = this.getListItemIndex(evt.target); var target = evt.target; this.foundation.handleKeydown(evt, target.classList.contains(this.classNameMap[constants_1.cssClasses.LIST_ITEM_CLASS]), index); }; /** * Used to figure out which element was clicked before sending the event to * the foundation. */ MDCList.prototype.handleClickEvent = function (evt) { var index = this.getListItemIndex(evt.target); var target = evt.target; // Toggle the checkbox only if it's not the target of the event, or the // checkbox will have 2 change events. var toggleCheckbox = !ponyfill_1.matches(target, constants_1.strings.CHECKBOX_RADIO_SELECTOR); this.foundation.handleClick(index, toggleCheckbox, evt); }; return MDCList; }(component_1.MDCComponent); exports.MDCList = MDCList; /***/ }), /***/ "./packages/mdc-list/constants.ts": /*!****************************************!*\ !*** ./packages/mdc-list/constants.ts ***! \****************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * @license * Copyright 2018 Google Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ var _a, _b; Object.defineProperty(exports, "__esModule", { value: true }); exports.evolutionClassNameMap = exports.evolutionAttribute = exports.deprecatedClassNameMap = exports.numbers = exports.cssClasses = exports.strings = void 0; var cssClasses = { LIST_ITEM_ACTIVATED_CLASS: 'mdc-list-item--activated', LIST_ITEM_CLASS: 'mdc-list-item', LIST_ITEM_DISABLED_CLASS: 'mdc-list-item--disabled', LIST_ITEM_SELECTED_CLASS: 'mdc-list-item--selected', LIST_ITEM_TEXT_CLASS: 'mdc-list-item__text', LIST_ITEM_PRIMARY_TEXT_CLASS: 'mdc-list-item__primary-text', ROOT: 'mdc-list' }; exports.cssClasses = cssClasses; 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); exports.evolutionClassNameMap = evolutionClassNameMap; 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); exports.deprecatedClassNameMap = deprecatedClassNameMap; var strings = { ACTION_EVENT: 'MDCList:action', SELECTION_CHANGE_EVENT: 'MDCList:selectionChange', ARIA_CHECKED: 'aria-checked', ARIA_CHECKED_CHECKBOX_SELECTOR: '[role="checkbox"][aria-checked="true"]', ARIA_CHECKED_RADIO_SELECTOR: '[role="radio"][aria-checked="true"]', ARIA_CURRENT: 'aria-current', ARIA_DISABLED: 'aria-disabled