"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _vue = require("vue");

var _vueTypes = _interopRequireDefault(require("./vue-types"));

var _default = (0, _vue.defineComponent)({
  name: 'Portal',
  inheritAttrs: false,
  props: {
    getContainer: _vueTypes.default.func.isRequired,
    didUpdate: _vueTypes.default.func
  },
  setup: function setup(props, _ref) {
    var slots = _ref.slots;
    // getContainer 不会改变，不用响应式
    var container = props.getContainer();
    (0, _vue.onUpdated)(function () {
      (0, _vue.nextTick)(function () {
        var _props$didUpdate;

        (_props$didUpdate = props.didUpdate) === null || _props$didUpdate === void 0 ? void 0 : _props$didUpdate.call(props, props);
      });
    });
    (0, _vue.onBeforeUnmount)(function () {
      if (container && container.parentNode) {
        container.parentNode.removeChild(container);
      }
    });
    return function () {
      return container ? (0, _vue.createVNode)(_vue.Teleport, {
        "to": container
      }, slots) : null;
    };
  }
});

exports.default = _default;