Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions dist/vue-wc-wrapper.global.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function getAttributes (node) {
return res
}

function wrap (Vue, Component) {
function wrap (Vue, Component, plugin) {
const isAsync = typeof Component === 'function' && !Component.cid;
let isInitialized = false;
let hyphenatedPropsList;
Expand Down Expand Up @@ -167,12 +167,21 @@ function wrap (Vue, Component) {
);
}

const _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function _isObjectEmpty(obj) {
return (
Object.prototype.toString.call(obj) === '[object Object]' &&
JSON.stringify(obj) === '{}'
);
}

class CustomElement extends HTMLElement {
constructor () {
const self = super();
self.attachShadow({ mode: 'open' });

const wrapper = self._wrapper = new Vue({
const vueProps = _extends({
name: 'shadow-root',
customElement: self,
shadowRoot: self.shadowRoot,
Expand All @@ -188,7 +197,9 @@ function wrap (Vue, Component) {
props: this.props
}, this.slotChildren)
}
});
}, !_isObjectEmpty(plugin) && _extends({}, plugin));

const wrapper = self._wrapper = new Vue(vueProps);

// Use MutationObserver to react to future attribute & slot content change
const observer = new MutationObserver(mutations => {
Expand Down
17 changes: 14 additions & 3 deletions dist/vue-wc-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function getAttributes (node) {
return res
}

function wrap (Vue, Component) {
function wrap (Vue, Component, plugin) {
const isAsync = typeof Component === 'function' && !Component.cid;
let isInitialized = false;
let hyphenatedPropsList;
Expand Down Expand Up @@ -164,12 +164,21 @@ function wrap (Vue, Component) {
);
}

const _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function _isObjectEmpty(obj) {
return (
Object.prototype.toString.call(obj) === '[object Object]' &&
JSON.stringify(obj) === '{}'
);
}

class CustomElement extends HTMLElement {
constructor () {
const self = super();
self.attachShadow({ mode: 'open' });

const wrapper = self._wrapper = new Vue({
const vueProps = _extends({
name: 'shadow-root',
customElement: self,
shadowRoot: self.shadowRoot,
Expand All @@ -185,7 +194,9 @@ function wrap (Vue, Component) {
props: this.props
}, this.slotChildren)
}
});
}, !_isObjectEmpty(plugin) && _extends({}, plugin));

const wrapper = self._wrapper = new Vue(vueProps);

// Use MutationObserver to react to future attribute & slot content change
const observer = new MutationObserver(mutations => {
Expand Down
17 changes: 14 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
convertAttributeValue
} from './utils.js'

export default function wrap (Vue, Component) {
export default function wrap (Vue, Component, plugin) {
const isAsync = typeof Component === 'function' && !Component.cid
let isInitialized = false
let hyphenatedPropsList
Expand Down Expand Up @@ -78,12 +78,21 @@ export default function wrap (Vue, Component) {
)
}

const _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function _isObjectEmpty(obj) {
return (
Object.prototype.toString.call(obj) === '[object Object]' &&
JSON.stringify(obj) === '{}'
);
}

class CustomElement extends HTMLElement {
constructor () {
const self = super()
self.attachShadow({ mode: 'open' })

const wrapper = self._wrapper = new Vue({
const vueProps = _extends({
name: 'shadow-root',
customElement: self,
shadowRoot: self.shadowRoot,
Expand All @@ -99,7 +108,9 @@ export default function wrap (Vue, Component) {
props: this.props
}, this.slotChildren)
}
})
}, !_isObjectEmpty(plugin) && _extends({}, plugin));

const wrapper = self._wrapper = new Vue(vueProps)

// Use MutationObserver to react to future attribute & slot content change
const observer = new MutationObserver(mutations => {
Expand Down
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import _Vue, { Component, AsyncComponent } from 'vue'

declare function wrap(
Vue: typeof _Vue,
Component: Component | AsyncComponent
Component: Component | AsyncComponent,
plugin?: any // update any to a better typing (i.e. VueConstructor...)
): HTMLElement

export default wrap