vue-mount-plugin 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ require('core-js/modules/es.object.assign.js');
4
+ var vueDemi = require('vue-demi');
5
+
6
+ var Mount = function () {
7
+ function Mount(component, options) {
8
+ if (options === void 0) {
9
+ options = {};
10
+ }
11
+ this.vNode = null;
12
+ this.options = {};
13
+ this.seed = 1;
14
+ if (typeof document === 'undefined') throw new Error('This plugin works in browser');
15
+ this.options = options;
16
+ this.target = (typeof options.target === 'string' ? document.querySelector(options.target) : options.target) || document.createElement(options.tagName || 'div');
17
+ this.vNode = this.createVM(component, options);
18
+ }
19
+ Mount.prototype.createVM = function (component, _a) {
20
+ var _b = _a === void 0 ? {} : _a,
21
+ props = _b.props,
22
+ children = _b.children,
23
+ patchFlag = _b.patchFlag,
24
+ dynamicProps = _b.dynamicProps,
25
+ isBlockNode = _b.isBlockNode,
26
+ app = _b.app,
27
+ context = _b.context,
28
+ parent = _b.parent;
29
+ var vNode;
30
+ if (vueDemi.isVue2) {
31
+ var VueConstructor = vueDemi.Vue2.extend(Object.assign({}, context || {}, component));
32
+ vNode = new VueConstructor({
33
+ parent: parent,
34
+ propsData: props
35
+ });
36
+ vNode.id = 'mount-plugin-' + this.seed++;
37
+ return vNode;
38
+ } else {
39
+ vNode = vueDemi.createVNode(component, props, children, patchFlag, dynamicProps, isBlockNode);
40
+ if (app === null || app === void 0 ? void 0 : app._context) vNode.appContext = app._context;
41
+ return vNode;
42
+ }
43
+ };
44
+ Mount.prototype.mount = function () {
45
+ !this.options.target && document.body.appendChild(this.target);
46
+ if (vueDemi.isVue2) {
47
+ this.vNode && this.vNode.$mount(this.target);
48
+ } else {
49
+ vueDemi.render(this.vNode, this.target);
50
+ }
51
+ };
52
+ Mount.prototype.unmount = function () {
53
+ if (vueDemi.isVue2) {
54
+ this.vNode.$destroy();
55
+ document.body.removeChild(this.vNode.$el);
56
+ } else {
57
+ vueDemi.render(null, this.target);
58
+ document.body.removeChild(this.target);
59
+ }
60
+ this.vNode = null;
61
+ this.target = null;
62
+ };
63
+ return Mount;
64
+ }();
65
+
66
+ module.exports = Mount;
@@ -0,0 +1,42 @@
1
+ import type { App } from 'vue-demi';
2
+ import { createVNode } from 'vue-demi';
3
+ import type { VNode } from 'vue-demi';
4
+ import type { VNodeProps } from 'vue-demi';
5
+ import { Vue2 } from 'vue-demi';
6
+
7
+ export declare type Component = CreateVNodeParameters['0'];
8
+
9
+ export declare type CreateVNodeParameters = Parameters<typeof createVNode>;
10
+
11
+ export declare type Data = Record<string, unknown>;
12
+
13
+ declare class Mount {
14
+ vNode: VNode | typeof Vue2 | null;
15
+ target: Element | ShadowRoot;
16
+ options: Options;
17
+ seed: number;
18
+ constructor(component: Component, options?: Options);
19
+ createVM(component: Component, { props, children, patchFlag, dynamicProps, isBlockNode, app, context, parent }?: Options): any;
20
+ mount(): void;
21
+ unmount(): void;
22
+ }
23
+ export default Mount;
24
+
25
+ export declare interface Options {
26
+ props?: (Data & VNodeProps) | null;
27
+ children?: unknown;
28
+ patchFlag?: number;
29
+ dynamicProps?: string[] | null;
30
+ isBlockNode?: boolean;
31
+ target?: Element | ShadowRoot;
32
+ tagName?: keyof HTMLElementTagNameMap;
33
+ app?: App;
34
+ context?: Data & {
35
+ router: unknown;
36
+ store: unknown;
37
+ i18n: unknown;
38
+ };
39
+ parent?: unknown;
40
+ }
41
+
42
+ export { }