vue-winbox-no-types
Version:
A wrapper component for WinBox.js with the ability to mount Vue components.
164 lines (152 loc) • 5.77 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vueDemi = require('vue-demi');
require('winbox');
var nanoid = require('nanoid');
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
const adaptOnsV3 = (ons) => {
if (!ons)
return null;
return Object.entries(ons).reduce((ret, [key, handler]) => {
key = key.charAt(0).toUpperCase() + key.slice(1);
key = `on${key}`;
return Object.assign(Object.assign({}, ret), { [key]: handler });
}, {});
};
const h = (type, options = {}, chidren) => {
if (vueDemi.isVue2)
return vueDemi.h(type, options, chidren);
const { props, domProps, on } = options, extraOptions = __rest(options, ["props", "domProps", "on"]);
let ons = adaptOnsV3(on);
const params = Object.assign(Object.assign(Object.assign(Object.assign({}, extraOptions), props), domProps), ons);
return vueDemi.h(type, params, chidren);
};
const slot = (defaultSlots) => {
if (typeof defaultSlots == 'function')
return defaultSlots();
return defaultSlots;
};
var VueWinBox = vueDemi.defineComponent({
props: {
options: {
type: Object,
required: true
},
portalSelector: {
type: String,
required: false,
default: 'selector'
},
portalComponent: {
type: String,
required: false,
default: 'portal'
},
portalAttributes: {
type: Object,
required: false,
default: () => { }
}
},
emits: [
'onmove',
'onresize',
'onclose',
'onfocus',
'onblur'
],
data() {
return {
winbox: null,
initialized: false,
selector: 'vuewinbox-' + nanoid.nanoid()
};
},
methods: {
initialize() {
if (this.initialized) {
console.error('Please close the window first before reinitializing.');
return;
}
this.winbox = new WinBox(Object.assign(Object.assign({ onresize: (width, height) => {
var _a;
this.$emit('onresize', {
id: (_a = this.winbox) === null || _a === void 0 ? void 0 : _a.id,
width,
height
});
}, onclose: () => {
var _a;
this.$emit('onclose', { id: (_a = this.winbox) === null || _a === void 0 ? void 0 : _a.id });
this.initialized = false;
return false;
}, onfocus: () => {
var _a;
this.$emit('onfocus', { id: (_a = this.winbox) === null || _a === void 0 ? void 0 : _a.id });
}, onblur: () => {
var _a;
this.$emit('onblur', { id: (_a = this.winbox) === null || _a === void 0 ? void 0 : _a.id });
}, onmove: (x, y) => {
var _a;
this.$emit('onmove', {
id: (_a = this.winbox) === null || _a === void 0 ? void 0 : _a.id,
x,
y
});
} }, this.options), { id: this.selector }));
this.initialized = true;
}
},
mounted() {
this.initialize();
},
unmounted() {
var _a;
(_a = this.winbox) === null || _a === void 0 ? void 0 : _a.close();
},
render() {
const slot$1 = this.$slots.default ? slot(this.$slots.default) : [];
const attr = {};
const winboxId = `#${this.selector} .wb-body`;
const component = vueDemi.isVue2 ? this.portalComponent : vueDemi.Teleport;
if (vueDemi.isVue2) {
attr.attrs = Object.assign(Object.assign({}, this.portalAttributes), { [this.portalSelector]: winboxId });
}
else {
attr.to = winboxId;
}
return this.initialized ? h(component, attr, slot$1) : null;
}
});
function useWinBox() {
return (options) => new WinBox(options);
}
if (vueDemi.isVue2) {
vueDemi.Vue2.prototype.$WinBox = (options) => {
return new WinBox(Object.assign({}, options));
};
}
exports['default'] = VueWinBox;
exports.useWinBox = useWinBox;