vue-mount-plugin 2.1.1 → 3.0.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.
- package/README.md +2 -4
- package/dist/index.cjs.js +122 -0
- package/dist/index.esm-browser.js +65 -0
- package/dist/index.esm-browser.prod.js +7 -0
- package/dist/index.esm-bundler.js +59 -0
- package/dist/index.global.js +245 -0
- package/dist/index.global.prod.js +8 -0
- package/dist/index.mjs +106 -49
- package/package.json +42 -43
- package/dist/es5/index.cjs +0 -66
- package/dist/es5/index.d.ts +0 -42
- package/dist/es5/index.iife.js +0 -1050
- package/dist/es5/index.iife.min.js +0 -7
- package/dist/es5/index.mjs +0 -64
- package/dist/index.cjs +0 -65
- package/dist/index.iife.js +0 -76
- package/dist/index.iife.min.js +0 -7
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ A simple and easy to use vue instance extension plugin that supports vue2.0 and
|
|
|
17
17
|
|
|
18
18
|
<div style="text-align: center; margin-bottom: 20px;" align="center">
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
### **[Documentation](https://www.saqqdy.com/vue-mount-plugin)** • **[Change Log](./CHANGELOG.md)**
|
|
21
21
|
|
|
22
22
|
</div>
|
|
23
23
|
|
|
@@ -122,10 +122,8 @@ Import `vue-mount-plugin` through browser HTML tags directly, and use global var
|
|
|
122
122
|
<head>
|
|
123
123
|
<!-- Import vue3 or vue2 -->
|
|
124
124
|
<script src="//unpkg.com/vue@3"></script>
|
|
125
|
-
<!-- Import vue-demi library -->
|
|
126
|
-
<script src="//unpkg.com/vue-demi"></script>
|
|
127
125
|
<!-- Import vue-mount-plugin library -->
|
|
128
|
-
<script src="//unpkg.com/vue-mount-plugin"></script>
|
|
126
|
+
<script src="//unpkg.com/vue-mount-plugin@3.0.0/dist/index.global.prod.js"></script>
|
|
129
127
|
</head>
|
|
130
128
|
```
|
|
131
129
|
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vueDemi = require('vue-demi');
|
|
4
|
+
|
|
5
|
+
function _classCallCheck(instance, Constructor) {
|
|
6
|
+
if (!(instance instanceof Constructor)) {
|
|
7
|
+
throw new TypeError("Cannot call a class as a function");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function _defineProperties(target, props) {
|
|
11
|
+
for (var i = 0; i < props.length; i++) {
|
|
12
|
+
var descriptor = props[i];
|
|
13
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
14
|
+
descriptor.configurable = true;
|
|
15
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
16
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
20
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
21
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
22
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
23
|
+
writable: false
|
|
24
|
+
});
|
|
25
|
+
return Constructor;
|
|
26
|
+
}
|
|
27
|
+
function _defineProperty(obj, key, value) {
|
|
28
|
+
key = _toPropertyKey(key);
|
|
29
|
+
if (key in obj) {
|
|
30
|
+
Object.defineProperty(obj, key, {
|
|
31
|
+
value: value,
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
obj[key] = value;
|
|
38
|
+
}
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
function _toPrimitive(input, hint) {
|
|
42
|
+
if (typeof input !== "object" || input === null) return input;
|
|
43
|
+
var prim = input[Symbol.toPrimitive];
|
|
44
|
+
if (prim !== undefined) {
|
|
45
|
+
var res = prim.call(input, hint || "default");
|
|
46
|
+
if (typeof res !== "object") return res;
|
|
47
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
48
|
+
}
|
|
49
|
+
return (hint === "string" ? String : Number)(input);
|
|
50
|
+
}
|
|
51
|
+
function _toPropertyKey(arg) {
|
|
52
|
+
var key = _toPrimitive(arg, "string");
|
|
53
|
+
return typeof key === "symbol" ? key : String(key);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var Mount = /*#__PURE__*/function () {
|
|
57
|
+
function Mount(component) {
|
|
58
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
59
|
+
_classCallCheck(this, Mount);
|
|
60
|
+
_defineProperty(this, "vNode", null);
|
|
61
|
+
_defineProperty(this, "options", {});
|
|
62
|
+
_defineProperty(this, "seed", 1);
|
|
63
|
+
if (typeof document === 'undefined') throw new Error('This plugin works in browser');
|
|
64
|
+
this.options = options;
|
|
65
|
+
this.target = (typeof options.target === 'string' ? document.querySelector(options.target) : options.target) || document.createElement(options.tagName || 'div');
|
|
66
|
+
this.vNode = this.createVM(component, options);
|
|
67
|
+
}
|
|
68
|
+
_createClass(Mount, [{
|
|
69
|
+
key: "createVM",
|
|
70
|
+
value: function createVM(component) {
|
|
71
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
72
|
+
props = _ref.props,
|
|
73
|
+
children = _ref.children,
|
|
74
|
+
patchFlag = _ref.patchFlag,
|
|
75
|
+
dynamicProps = _ref.dynamicProps,
|
|
76
|
+
isBlockNode = _ref.isBlockNode,
|
|
77
|
+
app = _ref.app,
|
|
78
|
+
context = _ref.context,
|
|
79
|
+
parent = _ref.parent;
|
|
80
|
+
var vNode;
|
|
81
|
+
if (vueDemi.isVue2) {
|
|
82
|
+
var VueConstructor = vueDemi.Vue2.extend(Object.assign({}, context || {}, component));
|
|
83
|
+
vNode = new VueConstructor({
|
|
84
|
+
parent: parent,
|
|
85
|
+
propsData: props
|
|
86
|
+
});
|
|
87
|
+
vNode.id = 'mount-plugin-' + this.seed++;
|
|
88
|
+
return vNode;
|
|
89
|
+
} else {
|
|
90
|
+
vNode = vueDemi.createVNode(component, props, children, patchFlag, dynamicProps, isBlockNode);
|
|
91
|
+
if (app !== null && app !== void 0 && app._context) vNode.appContext = app._context;
|
|
92
|
+
return vNode;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: "mount",
|
|
97
|
+
value: function mount() {
|
|
98
|
+
!this.options.target && document.body.appendChild(this.target);
|
|
99
|
+
if (vueDemi.isVue2) {
|
|
100
|
+
this.vNode && this.vNode.$mount(this.target);
|
|
101
|
+
} else {
|
|
102
|
+
vueDemi.render(this.vNode, this.target);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
key: "unmount",
|
|
107
|
+
value: function unmount() {
|
|
108
|
+
if (vueDemi.isVue2) {
|
|
109
|
+
this.vNode.$destroy();
|
|
110
|
+
document.body.removeChild(this.vNode.$el);
|
|
111
|
+
} else {
|
|
112
|
+
vueDemi.render(null, this.target);
|
|
113
|
+
document.body.removeChild(this.target);
|
|
114
|
+
}
|
|
115
|
+
this.vNode = null;
|
|
116
|
+
this.target = null;
|
|
117
|
+
}
|
|
118
|
+
}]);
|
|
119
|
+
return Mount;
|
|
120
|
+
}();
|
|
121
|
+
|
|
122
|
+
module.exports = Mount;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* vue-mount-plugin v3.0.0
|
|
3
|
+
* A simple and easy to use vue instance extension plugin that supports vue2.0 and vue3.0
|
|
4
|
+
* (c) 2021-2023 saqqdy <saqqdy@qq.com>
|
|
5
|
+
* Released under the MIT License.
|
|
6
|
+
*/
|
|
7
|
+
import { isVue2, Vue2, createVNode, render } from 'vue-demi';
|
|
8
|
+
|
|
9
|
+
class Mount {
|
|
10
|
+
vNode = null;
|
|
11
|
+
target;
|
|
12
|
+
options = {};
|
|
13
|
+
seed = 1;
|
|
14
|
+
constructor(component, options = {}) {
|
|
15
|
+
if (typeof document === 'undefined')
|
|
16
|
+
throw new Error('This plugin works in browser');
|
|
17
|
+
this.options = options;
|
|
18
|
+
this.target =
|
|
19
|
+
(typeof options.target === 'string'
|
|
20
|
+
? document.querySelector(options.target)
|
|
21
|
+
: options.target) || document.createElement(options.tagName || 'div');
|
|
22
|
+
this.vNode = this.createVM(component, options);
|
|
23
|
+
}
|
|
24
|
+
createVM(component, { props, children, patchFlag, dynamicProps, isBlockNode, app, context, parent } = {}) {
|
|
25
|
+
let vNode;
|
|
26
|
+
if (isVue2) {
|
|
27
|
+
const VueConstructor = Vue2.extend(Object.assign({}, context || {}, component));
|
|
28
|
+
vNode = new VueConstructor({
|
|
29
|
+
parent,
|
|
30
|
+
propsData: props
|
|
31
|
+
});
|
|
32
|
+
vNode.id = 'mount-plugin-' + this.seed++;
|
|
33
|
+
return vNode;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
vNode = createVNode(component, props, children, patchFlag, dynamicProps, isBlockNode);
|
|
37
|
+
if (app?._context)
|
|
38
|
+
vNode.appContext = app._context;
|
|
39
|
+
return vNode;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
mount() {
|
|
43
|
+
!this.options.target && document.body.appendChild(this.target);
|
|
44
|
+
if (isVue2) {
|
|
45
|
+
this.vNode && this.vNode.$mount(this.target);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
render(this.vNode, this.target);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
unmount() {
|
|
52
|
+
if (isVue2) {
|
|
53
|
+
this.vNode.$destroy();
|
|
54
|
+
document.body.removeChild(this.vNode.$el);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
render(null, this.target);
|
|
58
|
+
document.body.removeChild(this.target);
|
|
59
|
+
}
|
|
60
|
+
this.vNode = null;
|
|
61
|
+
this.target = null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { Mount as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* vue-mount-plugin v3.0.0
|
|
3
|
+
* A simple and easy to use vue instance extension plugin that supports vue2.0 and vue3.0
|
|
4
|
+
* (c) 2021-2023 saqqdy <saqqdy@qq.com>
|
|
5
|
+
* Released under the MIT License.
|
|
6
|
+
*/
|
|
7
|
+
import{isVue2 as t,Vue2 as e,createVNode as o,render as r}from"vue-demi";class s{vNode=null;target;options={};seed=1;constructor(t,e={}){if("undefined"==typeof document)throw new Error("This plugin works in browser");this.options=e,this.target=("string"==typeof e.target?document.querySelector(e.target):e.target)||document.createElement(e.tagName||"div"),this.vNode=this.createVM(t,e)}createVM(r,{props:s,children:n,patchFlag:i,dynamicProps:a,isBlockNode:d,app:h,context:u,parent:p}={}){let c;return t?(c=new(e.extend(Object.assign({},u||{},r)))({parent:p,propsData:s}),c.id="mount-plugin-"+this.seed++,c):(c=o(r,s,n,i,a,d),h?._context&&(c.appContext=h._context),c)}mount(){!this.options.target&&document.body.appendChild(this.target),t?this.vNode&&this.vNode.$mount(this.target):r(this.vNode,this.target)}unmount(){t?(this.vNode.$destroy(),document.body.removeChild(this.vNode.$el)):(r(null,this.target),document.body.removeChild(this.target)),this.vNode=null,this.target=null}}export{s as default};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { isVue2, Vue2, createVNode, render } from 'vue-demi';
|
|
2
|
+
|
|
3
|
+
class Mount {
|
|
4
|
+
vNode = null;
|
|
5
|
+
target;
|
|
6
|
+
options = {};
|
|
7
|
+
seed = 1;
|
|
8
|
+
constructor(component, options = {}) {
|
|
9
|
+
if (typeof document === 'undefined')
|
|
10
|
+
throw new Error('This plugin works in browser');
|
|
11
|
+
this.options = options;
|
|
12
|
+
this.target =
|
|
13
|
+
(typeof options.target === 'string'
|
|
14
|
+
? document.querySelector(options.target)
|
|
15
|
+
: options.target) || document.createElement(options.tagName || 'div');
|
|
16
|
+
this.vNode = this.createVM(component, options);
|
|
17
|
+
}
|
|
18
|
+
createVM(component, { props, children, patchFlag, dynamicProps, isBlockNode, app, context, parent } = {}) {
|
|
19
|
+
let vNode;
|
|
20
|
+
if (isVue2) {
|
|
21
|
+
const VueConstructor = Vue2.extend(Object.assign({}, context || {}, component));
|
|
22
|
+
vNode = new VueConstructor({
|
|
23
|
+
parent,
|
|
24
|
+
propsData: props
|
|
25
|
+
});
|
|
26
|
+
vNode.id = 'mount-plugin-' + this.seed++;
|
|
27
|
+
return vNode;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
vNode = createVNode(component, props, children, patchFlag, dynamicProps, isBlockNode);
|
|
31
|
+
if (app?._context)
|
|
32
|
+
vNode.appContext = app._context;
|
|
33
|
+
return vNode;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
mount() {
|
|
37
|
+
!this.options.target && document.body.appendChild(this.target);
|
|
38
|
+
if (isVue2) {
|
|
39
|
+
this.vNode && this.vNode.$mount(this.target);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
render(this.vNode, this.target);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
unmount() {
|
|
46
|
+
if (isVue2) {
|
|
47
|
+
this.vNode.$destroy();
|
|
48
|
+
document.body.removeChild(this.vNode.$el);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
render(null, this.target);
|
|
52
|
+
document.body.removeChild(this.target);
|
|
53
|
+
}
|
|
54
|
+
this.vNode = null;
|
|
55
|
+
this.target = null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { Mount as default };
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
|
|
2
|
+
if (VueDemi.install) {
|
|
3
|
+
return VueDemi
|
|
4
|
+
}
|
|
5
|
+
if (!Vue) {
|
|
6
|
+
console.error('[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.')
|
|
7
|
+
return VueDemi
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Vue 2.7
|
|
11
|
+
if (Vue.version.slice(0, 4) === '2.7.') {
|
|
12
|
+
for (var key in Vue) {
|
|
13
|
+
VueDemi[key] = Vue[key]
|
|
14
|
+
}
|
|
15
|
+
VueDemi.isVue2 = true
|
|
16
|
+
VueDemi.isVue3 = false
|
|
17
|
+
VueDemi.install = function () {}
|
|
18
|
+
VueDemi.Vue = Vue
|
|
19
|
+
VueDemi.Vue2 = Vue
|
|
20
|
+
VueDemi.version = Vue.version
|
|
21
|
+
VueDemi.warn = Vue.util.warn
|
|
22
|
+
VueDemi.hasInjectionContext = () => !!VueDemi.getCurrentInstance()
|
|
23
|
+
function createApp(rootComponent, rootProps) {
|
|
24
|
+
var vm
|
|
25
|
+
var provide = {}
|
|
26
|
+
var app = {
|
|
27
|
+
config: Vue.config,
|
|
28
|
+
use: Vue.use.bind(Vue),
|
|
29
|
+
mixin: Vue.mixin.bind(Vue),
|
|
30
|
+
component: Vue.component.bind(Vue),
|
|
31
|
+
provide: function (key, value) {
|
|
32
|
+
provide[key] = value
|
|
33
|
+
return this
|
|
34
|
+
},
|
|
35
|
+
directive: function (name, dir) {
|
|
36
|
+
if (dir) {
|
|
37
|
+
Vue.directive(name, dir)
|
|
38
|
+
return app
|
|
39
|
+
} else {
|
|
40
|
+
return Vue.directive(name)
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
mount: function (el, hydrating) {
|
|
44
|
+
if (!vm) {
|
|
45
|
+
vm = new Vue(Object.assign({ propsData: rootProps }, rootComponent, { provide: Object.assign(provide, rootComponent.provide) }))
|
|
46
|
+
vm.$mount(el, hydrating)
|
|
47
|
+
return vm
|
|
48
|
+
} else {
|
|
49
|
+
return vm
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
unmount: function () {
|
|
53
|
+
if (vm) {
|
|
54
|
+
vm.$destroy()
|
|
55
|
+
vm = undefined
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
return app
|
|
60
|
+
}
|
|
61
|
+
VueDemi.createApp = createApp
|
|
62
|
+
}
|
|
63
|
+
// Vue 2.6.x
|
|
64
|
+
else if (Vue.version.slice(0, 2) === '2.') {
|
|
65
|
+
if (VueCompositionAPI) {
|
|
66
|
+
for (var key in VueCompositionAPI) {
|
|
67
|
+
VueDemi[key] = VueCompositionAPI[key]
|
|
68
|
+
}
|
|
69
|
+
VueDemi.isVue2 = true
|
|
70
|
+
VueDemi.isVue3 = false
|
|
71
|
+
VueDemi.install = function () {}
|
|
72
|
+
VueDemi.Vue = Vue
|
|
73
|
+
VueDemi.Vue2 = Vue
|
|
74
|
+
VueDemi.version = Vue.version
|
|
75
|
+
VueDemi.hasInjectionContext = () => !!VueDemi.getCurrentInstance()
|
|
76
|
+
} else {
|
|
77
|
+
console.error('[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.')
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Vue 3
|
|
81
|
+
else if (Vue.version.slice(0, 2) === '3.') {
|
|
82
|
+
for (var key in Vue) {
|
|
83
|
+
VueDemi[key] = Vue[key]
|
|
84
|
+
}
|
|
85
|
+
VueDemi.isVue2 = false
|
|
86
|
+
VueDemi.isVue3 = true
|
|
87
|
+
VueDemi.install = function () {}
|
|
88
|
+
VueDemi.Vue = Vue
|
|
89
|
+
VueDemi.Vue2 = undefined
|
|
90
|
+
VueDemi.version = Vue.version
|
|
91
|
+
VueDemi.set = function (target, key, val) {
|
|
92
|
+
if (Array.isArray(target)) {
|
|
93
|
+
target.length = Math.max(target.length, key)
|
|
94
|
+
target.splice(key, 1, val)
|
|
95
|
+
return val
|
|
96
|
+
}
|
|
97
|
+
target[key] = val
|
|
98
|
+
return val
|
|
99
|
+
}
|
|
100
|
+
VueDemi.del = function (target, key) {
|
|
101
|
+
if (Array.isArray(target)) {
|
|
102
|
+
target.splice(key, 1)
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
delete target[key]
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
console.error('[vue-demi] Vue version ' + Vue.version + ' is unsupported.')
|
|
109
|
+
}
|
|
110
|
+
return VueDemi
|
|
111
|
+
})(
|
|
112
|
+
(this.VueDemi = this.VueDemi || (typeof VueDemi !== 'undefined' ? VueDemi : {})),
|
|
113
|
+
this.Vue || (typeof Vue !== 'undefined' ? Vue : undefined),
|
|
114
|
+
this.VueCompositionAPI || (typeof VueCompositionAPI !== 'undefined' ? VueCompositionAPI : undefined)
|
|
115
|
+
);
|
|
116
|
+
;
|
|
117
|
+
/*!
|
|
118
|
+
* vue-mount-plugin v3.0.0
|
|
119
|
+
* A simple and easy to use vue instance extension plugin that supports vue2.0 and vue3.0
|
|
120
|
+
* (c) 2021-2023 saqqdy <saqqdy@qq.com>
|
|
121
|
+
* Released under the MIT License.
|
|
122
|
+
*/
|
|
123
|
+
this.VueMount = (function (vueDemi) {
|
|
124
|
+
'use strict';
|
|
125
|
+
|
|
126
|
+
function _classCallCheck(instance, Constructor) {
|
|
127
|
+
if (!(instance instanceof Constructor)) {
|
|
128
|
+
throw new TypeError("Cannot call a class as a function");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function _defineProperties(target, props) {
|
|
132
|
+
for (var i = 0; i < props.length; i++) {
|
|
133
|
+
var descriptor = props[i];
|
|
134
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
135
|
+
descriptor.configurable = true;
|
|
136
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
137
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
141
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
142
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
143
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
144
|
+
writable: false
|
|
145
|
+
});
|
|
146
|
+
return Constructor;
|
|
147
|
+
}
|
|
148
|
+
function _defineProperty(obj, key, value) {
|
|
149
|
+
key = _toPropertyKey(key);
|
|
150
|
+
if (key in obj) {
|
|
151
|
+
Object.defineProperty(obj, key, {
|
|
152
|
+
value: value,
|
|
153
|
+
enumerable: true,
|
|
154
|
+
configurable: true,
|
|
155
|
+
writable: true
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
obj[key] = value;
|
|
159
|
+
}
|
|
160
|
+
return obj;
|
|
161
|
+
}
|
|
162
|
+
function _toPrimitive(input, hint) {
|
|
163
|
+
if (typeof input !== "object" || input === null) return input;
|
|
164
|
+
var prim = input[Symbol.toPrimitive];
|
|
165
|
+
if (prim !== undefined) {
|
|
166
|
+
var res = prim.call(input, hint || "default");
|
|
167
|
+
if (typeof res !== "object") return res;
|
|
168
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
169
|
+
}
|
|
170
|
+
return (hint === "string" ? String : Number)(input);
|
|
171
|
+
}
|
|
172
|
+
function _toPropertyKey(arg) {
|
|
173
|
+
var key = _toPrimitive(arg, "string");
|
|
174
|
+
return typeof key === "symbol" ? key : String(key);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
var Mount = /*#__PURE__*/function () {
|
|
178
|
+
function Mount(component) {
|
|
179
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
180
|
+
_classCallCheck(this, Mount);
|
|
181
|
+
_defineProperty(this, "vNode", null);
|
|
182
|
+
_defineProperty(this, "options", {});
|
|
183
|
+
_defineProperty(this, "seed", 1);
|
|
184
|
+
if (typeof document === 'undefined') throw new Error('This plugin works in browser');
|
|
185
|
+
this.options = options;
|
|
186
|
+
this.target = (typeof options.target === 'string' ? document.querySelector(options.target) : options.target) || document.createElement(options.tagName || 'div');
|
|
187
|
+
this.vNode = this.createVM(component, options);
|
|
188
|
+
}
|
|
189
|
+
_createClass(Mount, [{
|
|
190
|
+
key: "createVM",
|
|
191
|
+
value: function createVM(component) {
|
|
192
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
193
|
+
props = _ref.props,
|
|
194
|
+
children = _ref.children,
|
|
195
|
+
patchFlag = _ref.patchFlag,
|
|
196
|
+
dynamicProps = _ref.dynamicProps,
|
|
197
|
+
isBlockNode = _ref.isBlockNode,
|
|
198
|
+
app = _ref.app,
|
|
199
|
+
context = _ref.context,
|
|
200
|
+
parent = _ref.parent;
|
|
201
|
+
var vNode;
|
|
202
|
+
if (vueDemi.isVue2) {
|
|
203
|
+
var VueConstructor = vueDemi.Vue2.extend(Object.assign({}, context || {}, component));
|
|
204
|
+
vNode = new VueConstructor({
|
|
205
|
+
parent: parent,
|
|
206
|
+
propsData: props
|
|
207
|
+
});
|
|
208
|
+
vNode.id = 'mount-plugin-' + this.seed++;
|
|
209
|
+
return vNode;
|
|
210
|
+
} else {
|
|
211
|
+
vNode = vueDemi.createVNode(component, props, children, patchFlag, dynamicProps, isBlockNode);
|
|
212
|
+
if (app !== null && app !== void 0 && app._context) vNode.appContext = app._context;
|
|
213
|
+
return vNode;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}, {
|
|
217
|
+
key: "mount",
|
|
218
|
+
value: function mount() {
|
|
219
|
+
!this.options.target && document.body.appendChild(this.target);
|
|
220
|
+
if (vueDemi.isVue2) {
|
|
221
|
+
this.vNode && this.vNode.$mount(this.target);
|
|
222
|
+
} else {
|
|
223
|
+
vueDemi.render(this.vNode, this.target);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}, {
|
|
227
|
+
key: "unmount",
|
|
228
|
+
value: function unmount() {
|
|
229
|
+
if (vueDemi.isVue2) {
|
|
230
|
+
this.vNode.$destroy();
|
|
231
|
+
document.body.removeChild(this.vNode.$el);
|
|
232
|
+
} else {
|
|
233
|
+
vueDemi.render(null, this.target);
|
|
234
|
+
document.body.removeChild(this.target);
|
|
235
|
+
}
|
|
236
|
+
this.vNode = null;
|
|
237
|
+
this.target = null;
|
|
238
|
+
}
|
|
239
|
+
}]);
|
|
240
|
+
return Mount;
|
|
241
|
+
}();
|
|
242
|
+
|
|
243
|
+
return Mount;
|
|
244
|
+
|
|
245
|
+
})(VueDemi);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var VueDemi=function(e,t,i){if(e.install)return e;if(!t)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),e;if("2.7."===t.version.slice(0,4)){for(var n in t)e[n]=t[n];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=t,e.Vue2=t,e.version=t.version,e.warn=t.util.warn,e.hasInjectionContext=()=>!!e.getCurrentInstance(),e.createApp=function(e,i){var n,o={},r={config:t.config,use:t.use.bind(t),mixin:t.mixin.bind(t),component:t.component.bind(t),provide:function(e,t){return o[e]=t,this},directive:function(e,i){return i?(t.directive(e,i),r):t.directive(e)},mount:function(r,s){return n||((n=new t(Object.assign({propsData:i},e,{provide:Object.assign(o,e.provide)}))).$mount(r,s),n)},unmount:function(){n&&(n.$destroy(),n=void 0)}};return r}}else if("2."===t.version.slice(0,2))if(i){for(var n in i)e[n]=i[n];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=t,e.Vue2=t,e.version=t.version,e.hasInjectionContext=()=>!!e.getCurrentInstance()}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if("3."===t.version.slice(0,2)){for(var n in t)e[n]=t[n];e.isVue2=!1,e.isVue3=!0,e.install=function(){},e.Vue=t,e.Vue2=void 0,e.version=t.version,e.set=function(e,t,i){return Array.isArray(e)?(e.length=Math.max(e.length,t),e.splice(t,1,i),i):(e[t]=i,i)},e.del=function(e,t){Array.isArray(e)?e.splice(t,1):delete e[t]}}else console.error("[vue-demi] Vue version "+t.version+" is unsupported.");return e}(this.VueDemi=this.VueDemi||(void 0!==VueDemi?VueDemi:{}),this.Vue||("undefined"!=typeof Vue?Vue:void 0),this.VueCompositionAPI||("undefined"!=typeof VueCompositionAPI?VueCompositionAPI:void 0));
|
|
2
|
+
/*!
|
|
3
|
+
* vue-mount-plugin v3.0.0
|
|
4
|
+
* A simple and easy to use vue instance extension plugin that supports vue2.0 and vue3.0
|
|
5
|
+
* (c) 2021-2023 saqqdy <saqqdy@qq.com>
|
|
6
|
+
* Released under the MIT License.
|
|
7
|
+
*/
|
|
8
|
+
this.VueMount=function(e){"use strict";return class{vNode=null;target;options={};seed=1;constructor(e,t={}){if("undefined"==typeof document)throw new Error("This plugin works in browser");this.options=t,this.target=("string"==typeof t.target?document.querySelector(t.target):t.target)||document.createElement(t.tagName||"div"),this.vNode=this.createVM(e,t)}createVM(t,{props:i,children:n,patchFlag:o,dynamicProps:r,isBlockNode:s,app:u,context:d,parent:a}={}){let c;return e.isVue2?(c=new(e.Vue2.extend(Object.assign({},d||{},t)))({parent:a,propsData:i}),c.id="mount-plugin-"+this.seed++,c):(c=e.createVNode(t,i,n,o,r,s),u?._context&&(c.appContext=u._context),c)}mount(){!this.options.target&&document.body.appendChild(this.target),e.isVue2?this.vNode&&this.vNode.$mount(this.target):e.render(this.vNode,this.target)}unmount(){e.isVue2?(this.vNode.$destroy(),document.body.removeChild(this.vNode.$el)):(e.render(null,this.target),document.body.removeChild(this.target)),this.vNode=null,this.target=null}}}(VueDemi);
|