UNPKG

@enact/ui

Version:

A collection of simplified unstyled cross-platform UI components for Enact

66 lines (65 loc) 3.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = exports.FloatingLayerContainer = void 0; var _Registry = _interopRequireDefault(require("@enact/core/internal/Registry")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var FloatingLayerContainer = exports.FloatingLayerContainer = /*#__PURE__*/function () { function FloatingLayerContainer(config) { var _this = this; _classCallCheck(this, FloatingLayerContainer); this.getFloatingLayer = function () { // FIXME: if a component that resides in the floating layer is rendered at the same time // as the floating layer, this.floatingLayer may not have been initialized yet since // componentDidMount runs inside-out. As a fallback, we search by id but this could // introduce issues (e.g. for duplicate layer ids). return _this.floatingLayer || typeof document !== 'undefined' && document.getElementById(_this.config.floatLayerId) || null; }; this.handleNotify = function (_ref) { var action = _ref.action; if (action === 'register') { _this.notifyMount(); } else if (action === 'closeAll') { _this.handleCloseAll(); } }; this.setFloatingLayer = function (node) { _this.floatingLayer = node; }; var floatLayerId = config.floatLayerId; this.registry = _Registry["default"].create(this.handleNotify); this.floatingLayer = null; this.config = { floatLayerId: floatLayerId }; } _createClass(FloatingLayerContainer, [{ key: "load", value: function load() { this.notifyMount(); } }, { key: "handleCloseAll", value: function handleCloseAll() { this.registry.notify({ action: 'close' }); } }, { key: "notifyMount", value: function notifyMount() { this.registry.notify({ action: 'mount', floatingLayer: this.getFloatingLayer() }); } }]); return FloatingLayerContainer; }(); var _default = exports["default"] = FloatingLayerContainer;