@material/chips
Version:
The Material Components for the Web chips component
1,138 lines (1,090 loc) • 302 kB
JavaScript
/**
* @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/chips", [], factory);
else if(typeof exports === 'object')
exports["chips"] = factory();
else
root["mdc"] = root["mdc"] || {}, root["mdc"]["chips"] = 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-chips/index.ts");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./packages/mdc-animation/animationframe.ts":
/*!**************************************************!*\
!*** ./packages/mdc-animation/animationframe.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.AnimationFrame = void 0;
/**
* AnimationFrame provides a user-friendly abstraction around requesting
* and canceling animation frames.
*/
var AnimationFrame = /** @class */function () {
function AnimationFrame() {
this.rafIDs = new Map();
}
/**
* Requests an animation frame. Cancels any existing frame with the same key.
* @param {string} key The key for this callback.
* @param {FrameRequestCallback} callback The callback to be executed.
*/
AnimationFrame.prototype.request = function (key, callback) {
var _this = this;
this.cancel(key);
var frameID = requestAnimationFrame(function (frame) {
_this.rafIDs.delete(key);
// Callback must come *after* the key is deleted so that nested calls to
// request with the same key are not deleted.
callback(frame);
});
this.rafIDs.set(key, frameID);
};
/**
* Cancels a queued callback with the given key.
* @param {string} key The key for this callback.
*/
AnimationFrame.prototype.cancel = function (key) {
var rafID = this.rafIDs.get(key);
if (rafID) {
cancelAnimationFrame(rafID);
this.rafIDs.delete(key);
}
};
/**
* Cancels all queued callback.
*/
AnimationFrame.prototype.cancelAll = function () {
var _this = this;
// Need to use forEach because it's the only iteration method supported
// by IE11. Suppress the underscore because we don't need it.
// tslint:disable-next-line:enforce-name-casing
this.rafIDs.forEach(function (_, key) {
_this.cancel(key);
});
};
/**
* Returns the queue of unexecuted callback keys.
*/
AnimationFrame.prototype.getQueue = function () {
var queue = [];
// Need to use forEach because it's the only iteration method supported
// by IE11. Suppress the underscore because we don't need it.
// tslint:disable-next-line:enforce-name-casing
this.rafIDs.forEach(function (_, key) {
queue.push(key);
});
return queue;
};
return AnimationFrame;
}();
exports.AnimationFrame = AnimationFrame;
/***/ }),
/***/ "./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-chips/action/adapter.ts":
/*!**********************************************!*\
!*** ./packages/mdc-chips/action/adapter.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 });
/***/ }),
/***/ "./packages/mdc-chips/action/component-ripple.ts":
/*!*******************************************************!*\
!*** ./packages/mdc-chips/action/component-ripple.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.GRAPHIC_SELECTED_WIDTH_STYLE_PROP = exports.computePrimaryActionRippleClientRect = void 0;
/**
* Computes the ripple client rect for the primary action given the raw client
* rect and the selected width graphic style property.
*/
function computePrimaryActionRippleClientRect(clientRect, graphicSelectedWidthStyleValue) {
// parseInt is banned so we need to manually format and parse the string.
var graphicWidth = Number(graphicSelectedWidthStyleValue.replace('px', ''));
if (Number.isNaN(graphicWidth)) {
return clientRect;
}
// Can't use the spread operator because it has internal problems
return {
width: clientRect.width + graphicWidth,
height: clientRect.height,
top: clientRect.top,
right: clientRect.right,
bottom: clientRect.bottom,
left: clientRect.left
};
}
exports.computePrimaryActionRippleClientRect = computePrimaryActionRippleClientRect;
/**
* Provides the CSS custom property whose value is read by
* computePrimaryRippleClientRect. The CSS custom property provides the width
* of the chip graphic when selected. It is only set for the unselected chip
* variant without a leadinc icon. In all other cases, it will have no value.
*/
exports.GRAPHIC_SELECTED_WIDTH_STYLE_PROP = '--mdc-chip-graphic-selected-width';
/***/ }),
/***/ "./packages/mdc-chips/action/component.ts":
/*!************************************************!*\
!*** ./packages/mdc-chips/action/component.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.
*/
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 __());
};
}();
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MDCChipAction = 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 component_2 = __webpack_require__(/*! @material/ripple/component */ "./packages/mdc-ripple/component.ts");
var foundation_1 = __webpack_require__(/*! @material/ripple/foundation */ "./packages/mdc-ripple/foundation.ts");
var component_ripple_1 = __webpack_require__(/*! ./component-ripple */ "./packages/mdc-chips/action/component-ripple.ts");
var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-chips/action/constants.ts");
var primary_foundation_1 = __webpack_require__(/*! ./primary-foundation */ "./packages/mdc-chips/action/primary-foundation.ts");
var trailing_foundation_1 = __webpack_require__(/*! ./trailing-foundation */ "./packages/mdc-chips/action/trailing-foundation.ts");
/**
* MDCChipAction provides component encapsulation of the different foundation
* implementations.
*/
var MDCChipAction = /** @class */function (_super) {
__extends(MDCChipAction, _super);
function MDCChipAction() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.rootHTML = _this.root;
return _this;
}
MDCChipAction.attachTo = function (root) {
return new MDCChipAction(root);
};
Object.defineProperty(MDCChipAction.prototype, "ripple", {
get: function get() {
return this.rippleInstance;
},
enumerable: false,
configurable: true
});
MDCChipAction.prototype.initialize = function (rippleFactory) {
var _this = this;
if (rippleFactory === void 0) {
rippleFactory = function rippleFactory(el, foundation) {
return new component_2.MDCRipple(el, foundation);
};
}
var rippleAdapter = __assign(__assign({}, component_2.MDCRipple.createAdapter(this)), { computeBoundingRect: function computeBoundingRect() {
return _this.computeRippleClientRect();
} });
this.rippleInstance = rippleFactory(this.root, new foundation_1.MDCRippleFoundation(rippleAdapter));
};
MDCChipAction.prototype.initialSyncWithDOM = function () {
var _this = this;
this.handleClick = function () {
_this.foundation.handleClick();
};
this.handleKeydown = function (event) {
_this.foundation.handleKeydown(event);
};
this.listen('click', this.handleClick);
this.listen('keydown', this.handleKeydown);
};
MDCChipAction.prototype.destroy = function () {
this.ripple.destroy();
this.unlisten('click', this.handleClick);
this.unlisten('keydown', this.handleKeydown);
_super.prototype.destroy.call(this);
};
MDCChipAction.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 = {
emitEvent: function emitEvent(eventName, eventDetail) {
_this.emit(eventName, eventDetail, true /* shouldBubble */);
},
focus: function focus() {
_this.rootHTML.focus();
},
getAttribute: function getAttribute(attrName) {
return _this.root.getAttribute(attrName);
},
getElementID: function getElementID() {
return _this.root.id;
},
removeAttribute: function removeAttribute(name) {
_this.root.removeAttribute(name);
},
setAttribute: function setAttribute(name, value) {
_this.root.setAttribute(name, value);
}
};
if (this.root.classList.contains(constants_1.MDCChipActionCssClasses.TRAILING_ACTION)) {
return new trailing_foundation_1.MDCChipTrailingActionFoundation(adapter);
}
// Default to the primary foundation
return new primary_foundation_1.MDCChipPrimaryActionFoundation(adapter);
};
MDCChipAction.prototype.setDisabled = function (isDisabled) {
this.foundation.setDisabled(isDisabled);
};
MDCChipAction.prototype.isDisabled = function () {
return this.foundation.isDisabled();
};
MDCChipAction.prototype.setFocus = function (behavior) {
this.foundation.setFocus(behavior);
};
MDCChipAction.prototype.isFocusable = function () {
return this.foundation.isFocusable();
};
MDCChipAction.prototype.setSelected = function (isSelected) {
this.foundation.setSelected(isSelected);
};
MDCChipAction.prototype.isSelected = function () {
return this.foundation.isSelected();
};
MDCChipAction.prototype.isSelectable = function () {
return this.foundation.isSelectable();
};
MDCChipAction.prototype.actionType = function () {
return this.foundation.actionType();
};
MDCChipAction.prototype.computeRippleClientRect = function () {
if (this.root.classList.contains(constants_1.MDCChipActionCssClasses.PRIMARY_ACTION)) {
var chipRoot = ponyfill_1.closest(this.root, "." + constants_1.MDCChipActionCssClasses.CHIP_ROOT);
// Return the root client rect since it's better than nothing
if (!chipRoot) return this.root.getBoundingClientRect();
var graphicWidth = window.getComputedStyle(chipRoot).getPropertyValue(component_ripple_1.GRAPHIC_SELECTED_WIDTH_STYLE_PROP);
return component_ripple_1.computePrimaryActionRippleClientRect(chipRoot.getBoundingClientRect(), graphicWidth);
}
return this.root.getBoundingClientRect();
};
return MDCChipAction;
}(component_1.MDCComponent);
exports.MDCChipAction = MDCChipAction;
/***/ }),
/***/ "./packages/mdc-chips/action/constants.ts":
/*!************************************************!*\
!*** ./packages/mdc-chips/action/constants.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.MDCChipActionAttributes = exports.MDCChipActionFocusBehavior = exports.MDCChipActionEvents = exports.MDCChipActionType = exports.MDCChipActionInteractionTrigger = exports.MDCChipActionCssClasses = void 0;
/**
* MDCChipActionCssClasses provides the classes to be queried and manipulated on
* the root.
*/
var MDCChipActionCssClasses;
(function (MDCChipActionCssClasses) {
MDCChipActionCssClasses["PRIMARY_ACTION"] = "mdc-evolution-chip__action--primary";
MDCChipActionCssClasses["TRAILING_ACTION"] = "mdc-evolution-chip__action--trailing";
MDCChipActionCssClasses["CHIP_ROOT"] = "mdc-evolution-chip";
})(MDCChipActionCssClasses = exports.MDCChipActionCssClasses || (exports.MDCChipActionCssClasses = {}));
/**
* MDCChipActionInteractionTrigger provides detail of the different triggers for
* action interactions.
*/
var MDCChipActionInteractionTrigger;
(function (MDCChipActionInteractionTrigger) {
MDCChipActionInteractionTrigger[MDCChipActionInteractionTrigger["UNSPECIFIED"] = 0] = "UNSPECIFIED";
MDCChipActionInteractionTrigger[MDCChipActionInteractionTrigger["CLICK"] = 1] = "CLICK";
MDCChipActionInteractionTrigger[MDCChipActionInteractionTrigger["BACKSPACE_KEY"] = 2] = "BACKSPACE_KEY";
MDCChipActionInteractionTrigger[MDCChipActionInteractionTrigger["DELETE_KEY"] = 3] = "DELETE_KEY";
MDCChipActionInteractionTrigger[MDCChipActionInteractionTrigger["SPACEBAR_KEY"] = 4] = "SPACEBAR_KEY";
MDCChipActionInteractionTrigger[MDCChipActionInteractionTrigger["ENTER_KEY"] = 5] = "ENTER_KEY";
})(MDCChipActionInteractionTrigger = exports.MDCChipActionInteractionTrigger || (exports.MDCChipActionInteractionTrigger = {}));
/**
* MDCChipActionType provides the different types of available actions.
*/
var MDCChipActionType;
(function (MDCChipActionType) {
MDCChipActionType[MDCChipActionType["UNSPECIFIED"] = 0] = "UNSPECIFIED";
MDCChipActionType[MDCChipActionType["PRIMARY"] = 1] = "PRIMARY";
MDCChipActionType[MDCChipActionType["TRAILING"] = 2] = "TRAILING";
})(MDCChipActionType = exports.MDCChipActionType || (exports.MDCChipActionType = {}));
/**
* MDCChipActionEvents provides the different events emitted by the action.
*/
var MDCChipActionEvents;
(function (MDCChipActionEvents) {
MDCChipActionEvents["INTERACTION"] = "MDCChipAction:interaction";
MDCChipActionEvents["NAVIGATION"] = "MDCChipAction:navigation";
})(MDCChipActionEvents = exports.MDCChipActionEvents || (exports.MDCChipActionEvents = {}));
/**
* MDCChipActionFocusBehavior provides configurations for focusing or unfocusing
* an action.
*/
var MDCChipActionFocusBehavior;
(function (MDCChipActionFocusBehavior) {
MDCChipActionFocusBehavior[MDCChipActionFocusBehavior["FOCUSABLE"] = 0] = "FOCUSABLE";
MDCChipActionFocusBehavior[MDCChipActionFocusBehavior["FOCUSABLE_AND_FOCUSED"] = 1] = "FOCUSABLE_AND_FOCUSED";
MDCChipActionFocusBehavior[MDCChipActionFocusBehavior["NOT_FOCUSABLE"] = 2] = "NOT_FOCUSABLE";
})(MDCChipActionFocusBehavior = exports.MDCChipActionFocusBehavior || (exports.MDCChipActionFocusBehavior = {}));
/**
* MDCChipActionAttributes provides the HTML attributes used by the foundation.
*/
var MDCChipActionAttributes;
(function (MDCChipActionAttributes) {
MDCChipActionAttributes["ARIA_DISABLED"] = "aria-disabled";
MDCChipActionAttributes["ARIA_HIDDEN"] = "aria-hidden";
MDCChipActionAttributes["ARIA_SELECTED"] = "aria-selected";
MDCChipActionAttributes["DATA_DELETABLE"] = "data-mdc-deletable";
MDCChipActionAttributes["DISABLED"] = "disabled";
MDCChipActionAttributes["ROLE"] = "role";
MDCChipActionAttributes["TAB_INDEX"] = "tabindex";
})(MDCChipActionAttributes = exports.MDCChipActionAttributes || (exports.MDCChipActionAttributes = {}));
/***/ }),
/***/ "./packages/mdc-chips/action/foundation.ts":
/*!*************************************************!*\
!*** ./packages/mdc-chips/action/foundation.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.
*/
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 __());
};
}();
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MDCChipActionFoundation = void 0;
var foundation_1 = __webpack_require__(/*! @material/base/foundation */ "./packages/mdc-base/foundation.ts");
var keyboard_1 = __webpack_require__(/*! @material/dom/keyboard */ "./packages/mdc-dom/keyboard.ts");
var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-chips/action/constants.ts");
var triggerMap = new Map();
triggerMap.set(keyboard_1.KEY.SPACEBAR, constants_1.MDCChipActionInteractionTrigger.SPACEBAR_KEY);
triggerMap.set(keyboard_1.KEY.ENTER, constants_1.MDCChipActionInteractionTrigger.ENTER_KEY);
triggerMap.set(keyboard_1.KEY.DELETE, constants_1.MDCChipActionInteractionTrigger.DELETE_KEY);
triggerMap.set(keyboard_1.KEY.BACKSPACE, constants_1.MDCChipActionInteractionTrigger.BACKSPACE_KEY);
/**
* MDCChipActionFoundation provides a base abstract foundation for all chip
* actions.
*/
var MDCChipActionFoundation = /** @class */function (_super) {
__extends(MDCChipActionFoundation, _super);
function MDCChipActionFoundation(adapter) {
return _super.call(this, __assign(__assign({}, MDCChipActionFoundation.defaultAdapter), adapter)) || this;
}
Object.defineProperty(MDCChipActionFoundation, "defaultAdapter", {
get: function get() {
return {
emitEvent: function emitEvent() {
return undefined;
},
focus: function focus() {
return undefined;
},
getAttribute: function getAttribute() {
return null;
},
getElementID: function getElementID() {
return '';
},
removeAttribute: function removeAttribute() {
return undefined;
},
setAttribute: function setAttribute() {
return undefined;
}
};
},
enumerable: false,
configurable: true
});
MDCChipActionFoundation.prototype.handleClick = function () {
// Early exit for cases where the click comes from a source other than the
// user's pointer (i.e. programmatic click from AT).
if (this.isDisabled()) return;
this.emitInteraction(constants_1.MDCChipActionInteractionTrigger.CLICK);
};
MDCChipActionFoundation.prototype.handleKeydown = function (event) {
var key = keyboard_1.normalizeKey(event);
if (this.shouldNotifyInteractionFromKey(key)) {
event.preventDefault();
this.emitInteraction(this.getTriggerFromKey(key));
return;
}
if (keyboard_1.isNavigationEvent(event)) {
event.preventDefault();
this.emitNavigation(key);
return;
}
};
MDCChipActionFoundation.prototype.setDisabled = function (isDisabled) {
// Use `aria-disabled` for the selectable (listbox) disabled state
if (this.isSelectable()) {
this.adapter.setAttribute(constants_1.MDCChipActionAttributes.ARIA_DISABLED, "" + isDisabled);
return;
}
if (isDisabled) {
this.adapter.setAttribute(constants_1.MDCChipActionAttributes.DISABLED, 'true');
} else {
this.adapter.removeAttribute(constants_1.MDCChipActionAttributes.DISABLED);
}
};
MDCChipActionFoundation.prototype.isDisabled = function () {
if (this.adapter.getAttribute(constants_1.MDCChipActionAttributes.ARIA_DISABLED) === 'true') {
return true;
}
if (this.adapter.getAttribute(constants_1.MDCChipActionAttributes.DISABLED) !== null) {
return true;
}
return false;
};
MDCChipActionFoundation.prototype.setFocus = function (behavior) {
// Early exit if not focusable
if (!this.isFocusable()) {
return;
}
// Add it to the tab order and give focus
if (behavior === constants_1.MDCChipActionFocusBehavior.FOCUSABLE_AND_FOCUSED) {
this.adapter.setAttribute(constants_1.MDCChipActionAttributes.TAB_INDEX, '0');
this.adapter.focus();
return;
}
// Add to the tab order
if (behavior === constants_1.MDCChipActionFocusBehavior.FOCUSABLE) {
this.adapter.setAttribute(constants_1.MDCChipActionAttributes.TAB_INDEX, '0');
return;
}
// Remove it from the tab order
if (behavior === constants_1.MDCChipActionFocusBehavior.NOT_FOCUSABLE) {
this.adapter.setAttribute(constants_1.MDCChipActionAttributes.TAB_INDEX, '-1');
return;
}
};
MDCChipActionFoundation.prototype.isFocusable = function () {
if (this.isDisabled()) {
return false;
}
if (this.adapter.getAttribute(constants_1.MDCChipActionAttributes.ARIA_HIDDEN) === 'true') {
return false;
}
return true;
};
MDCChipActionFoundation.prototype.setSelected = function (isSelected) {
// Early exit if not selectable
if (!this.isSelectable()) {
return;
}
this.adapter.setAttribute(constants_1.MDCChipActionAttributes.ARIA_SELECTED, "" + isSelected);
};
MDCChipActionFoundation.prototype.isSelected = function () {
return this.adapter.getAttribute(constants_1.MDCChipActionAttributes.ARIA_SELECTED) === 'true';
};
MDCChipActionFoundation.prototype.emitInteraction = function (trigger) {
this.adapter.emitEvent(constants_1.MDCChipActionEvents.INTERACTION, {
actionID: this.adapter.getElementID(),
source: this.actionType(),
trigger: trigger
});
};
MDCChipActionFoundation.prototype.emitNavigation = function (key) {
this.adapter.emitEvent(constants_1.MDCChipActionEvents.NAVIGATION, {
source: this.actionType(),
key: key
});
};
MDCChipActionFoundation.prototype.shouldNotifyInteractionFromKey = function (key) {
var isFromActionKey = key === keyboard_1.KEY.ENTER || key === keyboard_1.KEY.SPACEBAR;
var isFromRemoveKey = key === keyboard_1.KEY.BACKSPACE || key === keyboard_1.KEY.DELETE;
if (isFromActionKey) {
return true;
}
if (isFromRemoveKey && this.shouldEmitInteractionOnRemoveKey()) {
return true;
}
return false;
};
MDCChipActionFoundation.prototype.getTriggerFromKey = function (key) {
var trigger = triggerMap.get(key);
if (trigger) {
return trigger;
}
// Default case, should ideally never be returned
return constants_1.MDCChipActionInteractionTrigger.UNSPECIFIED;
};
return MDCChipActionFoundation;
}(foundation_1.MDCFoundation);
exports.MDCChipActionFoundation = MDCChipActionFoundation;
// tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
exports.default = MDCChipActionFoundation;
/***/ }),
/***/ "./packages/mdc-chips/action/index.ts":
/*!********************************************!*\
!*** ./packages/mdc-chips/action/index.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.
*/
var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function get() {
return m[k];
} });
} : function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});
var __exportStar = this && this.__exportStar || function (m, exports) {
for (var p in m) {
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
}
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(__webpack_require__(/*! ./adapter */ "./packages/mdc-chips/action/adapter.ts"), exports);
__exportStar(__webpack_require__(/*! ./component */ "./packages/mdc-chips/action/component.ts"), exports);
__exportStar(__webpack_require__(/*! ./constants */ "./packages/mdc-chips/action/constants.ts"), exports);
__exportStar(__webpack_require__(/*! ./foundation */ "./packages/mdc-chips/action/foundation.ts"), exports);
__exportStar(__webpack_require__(/*! ./primary-foundation */ "./packages/mdc-chips/action/primary-foundation.ts"), exports);
__exportStar(__webpack_require__(/*! ./trailing-foundation */ "./packages/mdc-chips/action/trailing-foundation.ts"), exports);
__exportStar(__webpack_require__(/*! ./types */ "./packages/mdc-chips/action/types.ts"), exports);
/***/ }),
/***/ "./packages/mdc-chips/action/primary-foundation.ts":
/*!*********************************************************!*\
!*** ./packages/mdc-chips/action/primary-foundation.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