vue-mount-plugin 1.0.0-alpha.1 → 1.0.0-beta.1
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.
- package/README.md +87 -0
- package/dist/index.cjs +33 -28
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +33 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,93 @@ $ yarn add vue-mount-plugin
|
|
|
35
35
|
|
|
36
36
|
## Usage
|
|
37
37
|
|
|
38
|
+
### Use in Vue `>=3.0`
|
|
39
|
+
|
|
40
|
+
```vue
|
|
41
|
+
<template>
|
|
42
|
+
<div></div>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script setup>
|
|
46
|
+
import { getCurrentInstance } from 'vue'
|
|
47
|
+
import Mount from 'vue-mount-plugin'
|
|
48
|
+
import DemoVue from './demo.vue'
|
|
49
|
+
|
|
50
|
+
const { proxy } = getCurrentInstance()
|
|
51
|
+
const instance = new Mount(DemoVue, { parent: proxy.$root })
|
|
52
|
+
|
|
53
|
+
// mount to the end of document.body
|
|
54
|
+
instance.mount()
|
|
55
|
+
|
|
56
|
+
// destroy
|
|
57
|
+
instance.destroy()
|
|
58
|
+
</script>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Use in Vue `2.7`
|
|
62
|
+
|
|
63
|
+
```vue
|
|
64
|
+
<template>
|
|
65
|
+
<div></div>
|
|
66
|
+
</template>
|
|
67
|
+
|
|
68
|
+
<script>
|
|
69
|
+
import { getCurrentInstance } from 'vue'
|
|
70
|
+
import Mount from 'vue-mount-plugin'
|
|
71
|
+
import DemoVue from './demo.vue'
|
|
72
|
+
|
|
73
|
+
export default {
|
|
74
|
+
setup() {
|
|
75
|
+
const { proxy } = getCurrentInstance()
|
|
76
|
+
const instance = new Mount(DemoVue, { parent: proxy.$root })
|
|
77
|
+
|
|
78
|
+
// mount to the end of document.body
|
|
79
|
+
instance.mount()
|
|
80
|
+
|
|
81
|
+
// destroy
|
|
82
|
+
instance.destroy()
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
</script>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Use in Vue `<=2.6`
|
|
89
|
+
|
|
90
|
+
> Add `@vue/composition-api` to the `project.json` dependencies and run install.
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"dependencies": {
|
|
95
|
+
"@vue/composition-api": "latest"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```vue
|
|
101
|
+
<template>
|
|
102
|
+
<div></div>
|
|
103
|
+
</template>
|
|
104
|
+
|
|
105
|
+
<script>
|
|
106
|
+
import { getCurrentInstance } from '@vue/composition-api'
|
|
107
|
+
import Mount from 'vue-mount-plugin'
|
|
108
|
+
import DemoVue from './demo.vue'
|
|
109
|
+
|
|
110
|
+
export default {
|
|
111
|
+
setup() {
|
|
112
|
+
const { proxy } = getCurrentInstance()
|
|
113
|
+
const instance = new Mount(DemoVue, { parent: proxy.$root })
|
|
114
|
+
|
|
115
|
+
// mount to the end of document.body
|
|
116
|
+
instance.mount()
|
|
117
|
+
|
|
118
|
+
// destroy
|
|
119
|
+
instance.destroy()
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
</script>
|
|
123
|
+
```
|
|
124
|
+
|
|
38
125
|
## Support & Issues
|
|
39
126
|
|
|
40
127
|
Please open an issue [here](https://github.com/saqqdy/vue-mount-plugin/issues).
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-mount-plugin v1.0.0-
|
|
2
|
+
* vue-mount-plugin v1.0.0-beta.1
|
|
3
3
|
* A simple and easy to use vue instance extension plugin that supports vue2.0 and vue3.0
|
|
4
4
|
* (c) 2021-2023 saqqdy
|
|
5
5
|
* Released under the MIT License.
|
|
@@ -8,59 +8,64 @@
|
|
|
8
8
|
|
|
9
9
|
var vueDemi = require('vue-demi');
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
class Mount {
|
|
12
|
+
constructor(component, options) {
|
|
13
13
|
if (options === void 0) {
|
|
14
14
|
options = {};
|
|
15
15
|
}
|
|
16
16
|
this.vNode = null;
|
|
17
|
+
this.options = {};
|
|
17
18
|
this.seed = 1;
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
19
|
+
if (typeof document === 'undefined') throw new Error('This plugin works in browser');
|
|
20
|
+
this.options = options;
|
|
21
|
+
this.target = options.target || document.createElement('div');
|
|
22
22
|
this.vNode = this.createVM(component, options);
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
props
|
|
27
|
-
children
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
createVM(component, _temp) {
|
|
25
|
+
let {
|
|
26
|
+
props,
|
|
27
|
+
children,
|
|
28
|
+
patchFlag,
|
|
29
|
+
dynamicProps,
|
|
30
|
+
isBlockNode,
|
|
31
|
+
app,
|
|
32
|
+
context,
|
|
33
|
+
parent
|
|
34
|
+
} = _temp === void 0 ? {} : _temp;
|
|
35
|
+
let vNode;
|
|
31
36
|
if (vueDemi.isVue2) {
|
|
32
|
-
|
|
37
|
+
const VueConstructor = vueDemi.Vue2.extend(Object.assign({}, context || {}, component));
|
|
33
38
|
vNode = new VueConstructor({
|
|
34
|
-
|
|
39
|
+
parent,
|
|
35
40
|
propsData: props
|
|
36
41
|
});
|
|
37
42
|
vNode.id = 'captcha' + this.seed++;
|
|
38
43
|
return vNode;
|
|
39
44
|
} else {
|
|
40
|
-
vNode = vueDemi.createVNode(component, props, children);
|
|
45
|
+
vNode = vueDemi.createVNode(component, props, children, patchFlag, dynamicProps, isBlockNode);
|
|
41
46
|
if (app === null || app === void 0 ? void 0 : app._context) vNode.appContext = app._context;
|
|
42
47
|
return vNode;
|
|
43
48
|
}
|
|
44
|
-
}
|
|
45
|
-
|
|
49
|
+
}
|
|
50
|
+
mount() {
|
|
51
|
+
!this.options.target && document.body.appendChild(this.target);
|
|
46
52
|
if (vueDemi.isVue2) {
|
|
47
|
-
this.vNode && this.vNode.$mount();
|
|
53
|
+
this.vNode && this.vNode.$mount(this.target);
|
|
48
54
|
} else {
|
|
49
55
|
vueDemi.render(this.vNode, this.target);
|
|
50
56
|
}
|
|
51
|
-
}
|
|
52
|
-
|
|
57
|
+
}
|
|
58
|
+
destroy() {
|
|
53
59
|
if (vueDemi.isVue2) {
|
|
54
60
|
this.vNode.$destroy();
|
|
55
61
|
document.body.removeChild(this.vNode.$el);
|
|
56
|
-
this.vNode = null;
|
|
57
62
|
} else {
|
|
58
63
|
vueDemi.render(null, this.target);
|
|
59
64
|
document.body.removeChild(this.target);
|
|
60
|
-
this.vNode = null;
|
|
61
65
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
66
|
+
this.vNode = null;
|
|
67
|
+
this.target = null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
65
70
|
|
|
66
|
-
module.exports =
|
|
71
|
+
module.exports = Mount;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,16 +10,17 @@ export declare type CreateVNodeParameters = Parameters<typeof createVNode>;
|
|
|
10
10
|
|
|
11
11
|
export declare type Data = Record<string, unknown>;
|
|
12
12
|
|
|
13
|
-
declare class
|
|
13
|
+
declare class Mount {
|
|
14
14
|
vNode: VNode | typeof Vue2 | null;
|
|
15
15
|
target: Element | ShadowRoot;
|
|
16
|
+
options: Options;
|
|
16
17
|
seed: number;
|
|
17
18
|
constructor(component: Component, options?: Options);
|
|
18
|
-
createVM(component: Component, { props, children, app, context }?: Options): any;
|
|
19
|
+
createVM(component: Component, { props, children, patchFlag, dynamicProps, isBlockNode, app, context, parent }?: Options): any;
|
|
19
20
|
mount(): void;
|
|
20
21
|
destroy(): void;
|
|
21
22
|
}
|
|
22
|
-
export default
|
|
23
|
+
export default Mount;
|
|
23
24
|
|
|
24
25
|
export declare interface Options {
|
|
25
26
|
props?: (Data & VNodeProps) | null;
|
|
@@ -34,6 +35,7 @@ export declare interface Options {
|
|
|
34
35
|
store: unknown;
|
|
35
36
|
i18n: unknown;
|
|
36
37
|
};
|
|
38
|
+
parent?: unknown;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
export { }
|
package/dist/index.mjs
CHANGED
|
@@ -1,64 +1,69 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-mount-plugin v1.0.0-
|
|
2
|
+
* vue-mount-plugin v1.0.0-beta.1
|
|
3
3
|
* A simple and easy to use vue instance extension plugin that supports vue2.0 and vue3.0
|
|
4
4
|
* (c) 2021-2023 saqqdy
|
|
5
5
|
* Released under the MIT License.
|
|
6
6
|
*/
|
|
7
7
|
import { isVue2, Vue2, createVNode, render } from 'vue-demi';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
class Mount {
|
|
10
|
+
constructor(component, options) {
|
|
11
11
|
if (options === void 0) {
|
|
12
12
|
options = {};
|
|
13
13
|
}
|
|
14
14
|
this.vNode = null;
|
|
15
|
+
this.options = {};
|
|
15
16
|
this.seed = 1;
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
if (typeof document === 'undefined') throw new Error('This plugin works in browser');
|
|
18
|
+
this.options = options;
|
|
19
|
+
this.target = options.target || document.createElement('div');
|
|
20
20
|
this.vNode = this.createVM(component, options);
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
props
|
|
25
|
-
children
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
createVM(component, _temp) {
|
|
23
|
+
let {
|
|
24
|
+
props,
|
|
25
|
+
children,
|
|
26
|
+
patchFlag,
|
|
27
|
+
dynamicProps,
|
|
28
|
+
isBlockNode,
|
|
29
|
+
app,
|
|
30
|
+
context,
|
|
31
|
+
parent
|
|
32
|
+
} = _temp === void 0 ? {} : _temp;
|
|
33
|
+
let vNode;
|
|
29
34
|
if (isVue2) {
|
|
30
|
-
|
|
35
|
+
const VueConstructor = Vue2.extend(Object.assign({}, context || {}, component));
|
|
31
36
|
vNode = new VueConstructor({
|
|
32
|
-
|
|
37
|
+
parent,
|
|
33
38
|
propsData: props
|
|
34
39
|
});
|
|
35
40
|
vNode.id = 'captcha' + this.seed++;
|
|
36
41
|
return vNode;
|
|
37
42
|
} else {
|
|
38
|
-
vNode = createVNode(component, props, children);
|
|
43
|
+
vNode = createVNode(component, props, children, patchFlag, dynamicProps, isBlockNode);
|
|
39
44
|
if (app === null || app === void 0 ? void 0 : app._context) vNode.appContext = app._context;
|
|
40
45
|
return vNode;
|
|
41
46
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
47
|
+
}
|
|
48
|
+
mount() {
|
|
49
|
+
!this.options.target && document.body.appendChild(this.target);
|
|
44
50
|
if (isVue2) {
|
|
45
|
-
this.vNode && this.vNode.$mount();
|
|
51
|
+
this.vNode && this.vNode.$mount(this.target);
|
|
46
52
|
} else {
|
|
47
53
|
render(this.vNode, this.target);
|
|
48
54
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
55
|
+
}
|
|
56
|
+
destroy() {
|
|
51
57
|
if (isVue2) {
|
|
52
58
|
this.vNode.$destroy();
|
|
53
59
|
document.body.removeChild(this.vNode.$el);
|
|
54
|
-
this.vNode = null;
|
|
55
60
|
} else {
|
|
56
61
|
render(null, this.target);
|
|
57
62
|
document.body.removeChild(this.target);
|
|
58
|
-
this.vNode = null;
|
|
59
63
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
64
|
+
this.vNode = null;
|
|
65
|
+
this.target = null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
63
68
|
|
|
64
|
-
export {
|
|
69
|
+
export { Mount as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-mount-plugin",
|
|
3
3
|
"description": "A simple and easy to use vue instance extension plugin that supports vue2.0 and vue3.0",
|
|
4
|
-
"version": "1.0.0-
|
|
4
|
+
"version": "1.0.0-beta.1",
|
|
5
5
|
"packageManager": "pnpm@7.26.1",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.mjs",
|