@material/dialog
Version:
The Material Components Web dialog component
1,159 lines (1,125 loc) • 122 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/dialog", [], factory);
else if(typeof exports === 'object')
exports["dialog"] = factory();
else
root["mdc"] = root["mdc"] || {}, root["mdc"]["dialog"] = 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-dialog/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-dialog/adapter.ts":
/*!****************************************!*\
!*** ./packages/mdc-dialog/adapter.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 });
/***/ }),
/***/ "./packages/mdc-dialog/component.ts":
/*!******************************************!*\
!*** ./packages/mdc-dialog/component.ts ***!
\******************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* @license
* Copyright 2017 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 __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 __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
} : function (o, v) {
o["default"] = v;
});
var __importStar = this && this.__importStar || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) {
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
}__setModuleDefault(result, mod);
return result;
};
var __values = this && this.__values || function (o) {
var s = typeof Symbol === "function" && Symbol.iterator,
m = s && o[s],
i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function next() {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MDCDialog = void 0;
var component_1 = __webpack_require__(/*! @material/base/component */ "./packages/mdc-base/component.ts");
var focus_trap_1 = __webpack_require__(/*! @material/dom/focus-trap */ "./packages/mdc-dom/focus-trap.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__(/*! ./foundation */ "./packages/mdc-dialog/foundation.ts");
var util = __importStar(__webpack_require__(/*! ./util */ "./packages/mdc-dialog/util.ts"));
var strings = foundation_1.MDCDialogFoundation.strings;
var MDCDialog = /** @class */function (_super) {
__extends(MDCDialog, _super);
function MDCDialog() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(MDCDialog.prototype, "isOpen", {
get: function get() {
return this.foundation.isOpen();
},
enumerable: false,
configurable: true
});
Object.defineProperty(MDCDialog.prototype, "escapeKeyAction", {
get: function get() {
return this.foundation.getEscapeKeyAction();
},
set: function set(action) {
this.foundation.setEscapeKeyAction(action);
},
enumerable: false,
configurable: true
});
Object.defineProperty(MDCDialog.prototype, "scrimClickAction", {
get: function get() {
return this.foundation.getScrimClickAction();
},
set: function set(action) {
this.foundation.setScrimClickAction(action);
},
enumerable: false,
configurable: true
});
Object.defineProperty(MDCDialog.prototype, "autoStackButtons", {
get: function get() {
return this.foundation.getAutoStackButtons();
},
set: function set(autoStack) {
this.foundation.setAutoStackButtons(autoStack);
},
enumerable: false,
configurable: true
});
MDCDialog.attachTo = function (root) {
return new MDCDialog(root);
};
MDCDialog.prototype.initialize = function (focusTrapFactory) {
var e_1, _a;
if (focusTrapFactory === void 0) {
focusTrapFactory = function focusTrapFactory(el, focusOptions) {
return new focus_trap_1.FocusTrap(el, focusOptions);
};
}
var container = this.root.querySelector(strings.CONTAINER_SELECTOR);
if (!container) {
throw new Error("Dialog component requires a " + strings.CONTAINER_SELECTOR + " container element");
}
this.container = container;
this.content = this.root.querySelector(strings.CONTENT_SELECTOR);
this.buttons = [].slice.call(this.root.querySelectorAll(strings.BUTTON_SELECTOR));
this.defaultButton = this.root.querySelector("[" + strings.BUTTON_DEFAULT_ATTRIBUTE + "]");
this.focusTrapFactory = focusTrapFactory;
this.buttonRipples = [];
try {
for (var _b = __values(this.buttons), _c = _b.next(); !_c.done; _c = _b.next()) {
var buttonEl = _c.value;
this.buttonRipples.push(new component_2.MDCRipple(buttonEl));
}
} catch (e_1_1) {
e_1 = { error: e_1_1 };
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_1) throw e_1.error;
}
}
};
MDCDialog.prototype.initialSyncWithDOM = function () {
var _this = this;
this.focusTrap = util.createFocusTrapInstance(this.container, this.focusTrapFactory, this.getInitialFocusEl() || undefined);
this.handleClick = this.foundation.handleClick.bind(this.foundation);
this.handleKeydown = this.foundation.handleKeydown.bind(this.foundation);
this.handleDocumentKeydown = this.foundation.handleDocumentKeydown.bind(this.foundation);
// this.handleLayout = this.layout.bind(this);
this.handleOpening = function () {
document.addEventListener('keydown', _this.handleDocumentKeydown);
};
this.handleClosing = function () {
document.removeEventListener('keydown', _this.handleDocumentKeydown);
};
this.listen('click', this.handleClick);
this.listen('keydown', this.handleKeydown);
this.listen(strings.OPENING_EVENT, this.handleOpening);
this.listen(strings.CLOSING_EVENT, this.handleClosing);
};
MDCDialog.prototype.destroy = function () {
this.unlisten('click', this.handleClick);
this.unlisten('keydown', this.handleKeydown);
this.unlisten(strings.OPENING_EVENT, this.handleOpening);
this.unlisten(strings.CLOSING_EVENT, this.handleClosing);
this.handleClosing();
this.buttonRipples.forEach(function (ripple) {
ripple.destroy();
});
_super.prototype.destroy.call(this);
};
MDCDialog.prototype.layout = function () {
this.foundation.layout();
};
MDCDialog.prototype.open = function () {
this.foundation.open();
};
MDCDialog.prototype.close = function (action) {
if (action === void 0) {
action = '';
}
this.foundation.close(action);
};
MDCDialog.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 = {
addBodyClass: function addBodyClass(className) {
return document.body.classList.add(className);
},
addClass: function addClass(className) {
return _this.root.classList.add(className);
},
areButtonsStacked: function areButtonsStacked() {
return util.areTopsMisaligned(_this.buttons);
},
clickDefaultButton: function clickDefaultButton() {
if (_this.defaultButton && !_this.defaultButton.disabled) {
_this.defaultButton.click();
}
},
eventTargetMatches: function eventTargetMatches(target, selector) {
return target ? ponyfill_1.matches(target, selector) : false;
},
getActionFromEvent: function getActionFromEvent(evt) {
if (!evt.target) {
return '';
}
var element = ponyfill_1.closest(evt.target, "[" + strings.ACTION_ATTRIBUTE + "]");
return element && element.getAttribute(strings.ACTION_ATTRIBUTE);
},
getInitialFocusEl: function getInitialFocusEl() {
return _this.getInitialFocusEl();
},
hasClass: function hasClass(className) {
return _this.root.classList.contains(className);
},
isContentScrollable: function isContentScrollable() {
return util.isScrollable(_this.content);
},
notifyClosed: function notifyClosed(action) {
return _this.emit(strings.CLOSED_EVENT, action ? { action: action } : {});
},
notifyClosing: function notifyClosing(action) {
return _this.emit(strings.CLOSING_EVENT, action ? { action: action } : {});
},
notifyOpened: function notifyOpened() {
return _this.emit(strings.OPENED_EVENT, {});
},
notifyOpening: function notifyOpening() {
return _this.emit(strings.OPENING_EVENT, {});
},
releaseFocus: function releaseFocus() {
_this.focusTrap.releaseFocus();
},
removeBodyClass: function removeBodyClass(className) {
return document.body.classList.remove(className);
},
removeClass: function removeClass(className) {
return _this.root.classList.remove(className);
},
reverseButtons: function reverseButtons() {
_this.buttons.reverse();
_this.buttons.forEach(function (button) {
button.parentElement.appendChild(button);
});
},
trapFocus: function trapFocus() {
_this.focusTrap.trapFocus();
},
registerContentEventHandler: function registerContentEventHandler(evt, handler) {
if (_this.content instanceof HTMLElement) {
_this.content.addEventListener(evt, handler);
}
},
deregisterContentEventHandler: function deregisterContentEventHandler(evt, handler) {
if (_this.content instanceof HTMLElement) {
_this.content.removeEventListener(evt, handler);
}
},
isScrollableContentAtTop: function isScrollableContentAtTop() {
return util.isScrollAtTop(_this.content);
},
isScrollableContentAtBottom: function isScrollableContentAtBottom() {
return util.isScrollAtBottom(_this.content);
},
registerWindowEventHandler: function registerWindowEventHandler(evt, handler) {
window.addEventListener(evt, handler);
},
deregisterWindowEventHandler: function deregisterWindowEventHandler(evt, handler) {
window.removeEventListener(evt, handler);
}
};
return new foundation_1.MDCDialogFoundation(adapter);
};
MDCDialog.prototype.getInitialFocusEl = function () {
return this.root.querySelector("[" + strings.INITIAL_FOCUS_ATTRIBUTE + "]");
};
return MDCDialog;
}(component_1.MDCComponent);
exports.MDCDialog = MDCDialog;
/***/ }),
/***/ "./packages/mdc-dialog/constants.ts":
/*!******************************************!*\
!*** ./packages/mdc-dialog/constants.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.numbers = exports.strings = exports.cssClasses = void 0;
exports.cssClasses = {
CLOSING: 'mdc-dialog--closing',
OPEN: 'mdc-dialog--open',
OPENING: 'mdc-dialog--opening',
SCROLLABLE: 'mdc-dialog--scrollable',
SCROLL_LOCK: 'mdc-dialog-scroll-lock',
STACKED: 'mdc-dialog--stacked',
FULLSCREEN: 'mdc-dialog--fullscreen',
// Class for showing a scroll divider on full-screen dialog header element.
// Should only be displayed on scrollable content, when the dialog content is
// scrolled "underneath" the header.
SCROLL_DIVIDER_HEADER: 'mdc-dialog-scroll-divider-header',
// Class for showing a scroll divider on a full-screen dialog footer element.
// Should only be displayed on scrolalble content, when the dialog content is
// obscured "underneath" the footer.
SCROLL_DIVIDER_FOOTER: 'mdc-dialog-scroll-divider-footer',
// The "surface scrim" is a scrim covering only the surface of a dialog. This
// is used in situations where a confirmation dialog is shown over an already
// opened full-screen dialog. On larger screen-sizes, the full-screen dialog
// is sized as a modal and so in these situations we display a "surface scrim"
// to prevent a "double scrim" (where the scrim from the secondary
// confirmation dialog would overlap with the scrim from the full-screen
// dialog).
SURFACE_SCRIM_SHOWN: 'mdc-dialog__surface-scrim--shown',
// "Showing" animating class for the surface-scrim.
SURFACE_SCRIM_SHOWING: 'mdc-dialog__surface-scrim--showing',
// "Hiding" animating class for the surface-scrim.
SURFACE_SCRIM_HIDING: 'mdc-dialog__surface-scrim--hiding',
// Class to hide a dialog's scrim (used in conjunction with a surface-scrim).
// Note that we only hide the original scrim rather than removing it entirely
// to prevent interactions with the content behind this scrim, and to capture
// scrim clicks.
SCRIM_HIDDEN: 'mdc-dialog__scrim--hidden'
};
exports.strings = {
ACTION_ATTRIBUTE: 'data-mdc-dialog-action',
BUTTON_DEFAULT_ATTRIBUTE: 'data-mdc-dialog-button-default',
BUTTON_SELECTOR: '.mdc-dialog__button',
CLOSED_EVENT: 'MDCDialog:closed',
CLOSE_ACTION: 'close',
CLOSING_EVENT: 'MDCDialog:closing',
CONTAINER_SELECTOR: '.mdc-dialog__container',
CONTENT_SELECTOR: '.mdc-dialog__content',
DESTROY_ACTION: 'destroy',
INITIAL_FOCUS_ATTRIBUTE: 'data-mdc-dialog-initial-focus',
OPENED_EVENT: 'MDCDialog:opened',
OPENING_EVENT: 'MDCDialog:opening',
SCRIM_SELECTOR: '.mdc-dialog__scrim',
SUPPRESS_DEFAULT_PRESS_SELECTOR: ['textarea', '.mdc-menu .mdc-list-item', '.mdc-menu .mdc-deprecated-list-item'].join(', '),
SURFACE_SELECTOR: '.mdc-dialog__surface'
};
exports.numbers = {
DIALOG_ANIMATION_CLOSE_TIME_MS: 75,
DIALOG_ANIMATION_OPEN_TIME_MS: 150
};
/***/ }),
/***/ "./packages/mdc-dialog/foundation.ts":
/*!*******************************************!*\
!*** ./packages/mdc-dialog/foundation.ts ***!
\*******************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* @license
* Copyright 2017 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.MDCDialogFoundation = void 0;
var animationframe_1 = __webpack_require__(/*! @material/animation/animationframe */ "./packages/mdc-animation/animationframe.ts");
var foundation_1 = __webpack_require__(/*! @material/base/foundation */ "./packages/mdc-base/foundation.ts");
var constants_1 = __webpack_require__(/*! ./constants */ "./packages/mdc-dialog/constants.ts");
var AnimationKeys;
(function (AnimationKeys) {
AnimationKeys["POLL_SCROLL_POS"] = "poll_scroll_position";
AnimationKeys["POLL_LAYOUT_CHANGE"] = "poll_layout_change";
})(AnimationKeys || (AnimationKeys = {}));
var MDCDialogFoundation = /** @class */function (_super) {
__extends(MDCDialogFoundation, _super);
function MDCDialogFoundation(adapter) {
var _this = _super.call(this, __assign(__assign({}, MDCDialogFoundation.defaultAdapter), adapter)) || this;
_this.dialogOpen = false;
_this.isFullscreen = false;
_this.animationFrame = 0;
_this.animationTimer = 0;
_this.escapeKeyAction = constants_1.strings.CLOSE_ACTION;
_this.scrimClickAction = constants_1.strings.CLOSE_ACTION;
_this.autoStackButtons = true;
_this.areButtonsStacked = false;
_this.suppressDefaultPressSelector = constants_1.strings.SUPPRESS_DEFAULT_PRESS_SELECTOR;
_this.animFrame = new animationframe_1.AnimationFrame();
_this.contentScrollHandler = function () {
_this.handleScrollEvent();
};
_this.windowResizeHandler = function () {
_this.layout();
};
_this.windowOrientationChangeHandler = function () {
_this.layout();
};
return _this;
}
Object.defineProperty(MDCDialogFoundation, "cssClasses", {
get: function get() {
return constants_1.cssClasses;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MDCDialogFoundation, "strings", {
get: function get() {
return constants_1.strings;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MDCDialogFoundation, "numbers", {
get: function get() {
return constants_1.numbers;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MDCDialogFoundation, "defaultAdapter", {
get: function get() {
return {
addBodyClass: function addBodyClass() {
return undefined;
},
addClass: function addClass() {
return undefined;
},
areButtonsStacked: function areButtonsStacked() {
return false;
},
clickDefaultButton: function clickDefaultButton() {
return undefined;
},
eventTargetMatches: function eventTargetMatches() {
return false;
},
getActionFromEvent: function getActionFromEvent() {
return '';
},
getInitialFocusEl: function getInitialFocusEl() {
return null;
},
hasClass: function hasClass() {
return false;
},
isContentScrollable: function isContentScrollable() {
return false;
},
notifyClosed: function notifyClosed() {
return undefined;
},
notifyClosing: function notifyClosing() {
return undefined;
},
notifyOpened: function notifyOpened() {
return undefined;
},
notifyOpening: function notifyOpening() {
return undefined;
},
releaseFocus: function releaseFocus() {
return undefined;
},
removeBodyClass: function removeBodyClass() {
return undefined;
},
removeClass: function removeClass() {
return undefined;
},
reverseButtons: function reverseButtons() {
return undefined;
},
trapFocus: function trapFocus() {
return undefined;
},
registerContentEventHandler: function registerContentEventHandler() {
return undefined;
},
deregisterContentEventHandler: function deregisterContentEventHandler() {
return undefined;
},
isScrollableContentAtTop: function isScrollableContentAtTop() {
return false;
},
isScrollableContentAtBottom: function isScrollableContentAtBottom() {
return false;
},
registerWindowEventHandler: function registerWindowEventHandler() {
return undefined;
},
deregisterWindowEventHandler: function deregisterWindowEventHandler() {
return undefined;
}
};
},
enumerable: false,
configurable: true
});
MDCDialogFoundation.prototype.init = function () {
if (this.adapter.hasClass(constants_1.cssClasses.STACKED)) {
this.setAutoStackButtons(false);
}
this.isFullscreen = this.adapter.hasClass(constants_1.cssClasses.FULLSCREEN);
};
MDCDialogFoundation.prototype.destroy = function () {
if (this.animationTimer) {
clearTimeout(this.animationTimer);
this.handleAnimationTimerEnd();
}
if (this.isFullscreen) {
this.adapter.deregisterContentEventHandler('scroll', this.contentScrollHandler);
}
this.animFrame.cancelAll();
this.adapter.deregisterWindowEventHandler('resize', this.windowResizeHandler);
this.adapter.deregisterWindowEventHandler('orientationchange', this.windowOrientationChangeHandler);
};
MDCDialogFoundation.prototype.open = function (dialogOptions) {
var _this = this;
this.dialogOpen = true;
this.adapter.notifyOpening();
this.adapter.addClass(constants_1.cssClasses.OPENING);
if (this.isFullscreen) {
// A scroll event listener is registered even if the dialog is not
// scrollable on open, since the window resize event, or orientation
// change may make the dialog scrollable after it is opened.
this.adapter.registerContentEventHandler('scroll', this.contentScrollHandler);
}
if (dialogOptions && dialogOptions.isAboveFullscreenDialog) {
this.adapter.addClass(constants_1.cssClasses.SCRIM_HIDDEN);
}
this.adapter.registerWindowEventHandler('resize', this.windowResizeHandler);
this.adapter.registerWindowEventHandler('orientationchange', this.windowOrientationChangeHandler);
// Wait a frame once display is no longer "none", to establish basis for
// animation
this.runNextAnimationFrame(function () {
_this.adapter.addClass(constants_1.cssClasses.OPEN);
_this.adapter.addBodyClass(constants_1.cssClasses.SCROLL_LOCK);
_this.layout();
_this.animationTimer = setTimeout(function () {
_this.handleAnimationTimerEnd();
_this.adapter.trapFocus(_this.adapter.getInitialFocusEl());
_this.adapter.notifyOpened();
}, constants_1.numbers.DIALOG_ANIMATION_OPEN_TIME_MS);
});
};
MDCDialogFoundation.prototype.close = function (action) {
var _this = this;
if (action === void 0) {
action = '';
}
if (!this.dialogOpen) {
// Avoid redundant close calls (and events), e.g. from keydown on elements
// that inherently emit click
return;
}
this.dialogOpen = false;
this.adapter.notifyClosing(action);
this.adapter.addClass(constants_1.cssClasses.CLOSING);
this.adapter.removeClass(constants_1.cssClasses.OPEN);
this.adapter.removeBodyClass(constants_1.cssClasses.SCROLL_LOCK);
if (this.isFullscreen) {
this.adapter.deregisterContentEventHandler('scroll', this.contentScrollHandler);
}
this.adapter.deregisterWindowEventHandler('resize', this.windowResizeHandler);
this.adapter.deregisterWindowEventHandler('orientationchange', this.windowOrientationChangeHandler);
cancelAnimationFrame(this.animationFrame);
this.animationFrame = 0;
clearTimeout(this.animationTimer);
this.animationTimer = setTimeout(function () {
_this.adapter.releaseFocus();
_this.handleAnimationTimerEnd();
_this.adapter.notifyClosed(action);
}, constants_1.numbers.DIALOG_ANIMATIO