|
1 | 1 | /**
|
2 |
| - * vue-custom-element v3.2.14 |
3 |
| - * (c) 2020 Karol Fabjańczuk |
| 2 | + * vue-custom-element v3.3.0 |
| 3 | + * (c) 2021 Karol Fabjańczuk |
4 | 4 | * @license MIT
|
5 | 5 | */
|
6 | 6 | (function (global, factory) {
|
@@ -367,109 +367,113 @@ function customEmit(element, eventName) {
|
367 | 367 | }
|
368 | 368 |
|
369 | 369 | function createVueInstance(element, Vue, componentDefinition, props, options) {
|
370 |
| - if (!element.__vue_custom_element__) { |
371 |
| - var beforeCreate = function beforeCreate() { |
372 |
| - this.$emit = function emit() { |
373 |
| - var _proto__$$emit; |
| 370 | + if (element.__vue_custom_element__) { |
| 371 | + return Promise.resolve(element); |
| 372 | + } |
| 373 | + var ComponentDefinition = Vue.util.extend({}, componentDefinition); |
| 374 | + var propsData = getPropsData(element, ComponentDefinition, props); |
| 375 | + var vueVersion = Vue.version && parseInt(Vue.version.split('.')[0], 10) || 0; |
374 | 376 |
|
375 |
| - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { |
376 |
| - args[_key] = arguments[_key]; |
377 |
| - } |
| 377 | + function beforeCreate() { |
| 378 | + this.$emit = function emit() { |
| 379 | + var _proto__$$emit; |
378 | 380 |
|
379 |
| - customEmit.apply(undefined, [element].concat(args)); |
380 |
| - this.__proto__ && (_proto__$$emit = this.__proto__.$emit).call.apply(_proto__$$emit, [this].concat(args)); |
381 |
| - }; |
382 |
| - }; |
| 381 | + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { |
| 382 | + args[_key] = arguments[_key]; |
| 383 | + } |
383 | 384 |
|
384 |
| - var ComponentDefinition = Vue.util.extend({}, componentDefinition); |
385 |
| - var propsData = getPropsData(element, ComponentDefinition, props); |
386 |
| - var vueVersion = Vue.version && parseInt(Vue.version.split('.')[0], 10) || 0; |
| 385 | + customEmit.apply(undefined, [element].concat(args)); |
| 386 | + this.__proto__ && (_proto__$$emit = this.__proto__.$emit).call.apply(_proto__$$emit, [this].concat(args)); |
| 387 | + }; |
| 388 | + } |
| 389 | + ComponentDefinition.beforeCreate = [].concat(ComponentDefinition.beforeCreate || [], beforeCreate); |
| 390 | + |
| 391 | + if (ComponentDefinition._compiled) { |
| 392 | + var constructorOptions = {}; |
| 393 | + var _constructor = ComponentDefinition._Ctor; |
| 394 | + if (_constructor) { |
| 395 | + constructorOptions = Object.keys(_constructor).map(function (key) { |
| 396 | + return _constructor[key]; |
| 397 | + })[0].options; |
| 398 | + } |
| 399 | + constructorOptions.beforeCreate = ComponentDefinition.beforeCreate; |
| 400 | + } |
387 | 401 |
|
388 |
| - ComponentDefinition.beforeCreate = [].concat(ComponentDefinition.beforeCreate || [], beforeCreate); |
| 402 | + var rootElement = void 0; |
389 | 403 |
|
390 |
| - if (ComponentDefinition._compiled) { |
391 |
| - var constructorOptions = {}; |
392 |
| - var _constructor = ComponentDefinition._Ctor; |
393 |
| - if (_constructor) { |
394 |
| - constructorOptions = Object.keys(_constructor).map(function (key) { |
395 |
| - return _constructor[key]; |
396 |
| - })[0].options; |
397 |
| - } |
398 |
| - constructorOptions.beforeCreate = ComponentDefinition.beforeCreate; |
399 |
| - } |
| 404 | + if (vueVersion >= 2) { |
| 405 | + var elementOriginalChildren = element.cloneNode(true).childNodes; |
| 406 | + rootElement = { |
| 407 | + propsData: propsData, |
| 408 | + props: props.camelCase, |
| 409 | + computed: { |
| 410 | + reactiveProps: function reactiveProps$$1() { |
| 411 | + var _this = this; |
400 | 412 |
|
401 |
| - var rootElement = void 0; |
| 413 | + var reactivePropsList = {}; |
| 414 | + props.camelCase.forEach(function (prop) { |
| 415 | + typeof _this[prop] !== 'undefined' && (reactivePropsList[prop] = _this[prop]); |
| 416 | + }); |
402 | 417 |
|
403 |
| - if (vueVersion >= 2) { |
404 |
| - var elementOriginalChildren = element.cloneNode(true).childNodes; |
405 |
| - rootElement = { |
406 |
| - propsData: propsData, |
407 |
| - props: props.camelCase, |
408 |
| - computed: { |
409 |
| - reactiveProps: function reactiveProps$$1() { |
410 |
| - var _this = this; |
| 418 | + return reactivePropsList; |
| 419 | + } |
| 420 | + }, |
| 421 | + render: function render(createElement) { |
| 422 | + var data = { |
| 423 | + props: this.reactiveProps |
| 424 | + }; |
411 | 425 |
|
412 |
| - var reactivePropsList = {}; |
413 |
| - props.camelCase.forEach(function (prop) { |
414 |
| - typeof _this[prop] !== 'undefined' && (reactivePropsList[prop] = _this[prop]); |
415 |
| - }); |
| 426 | + return createElement(ComponentDefinition, data, getSlots(elementOriginalChildren, createElement)); |
| 427 | + } |
| 428 | + }; |
| 429 | + } else if (vueVersion === 1) { |
| 430 | + rootElement = ComponentDefinition; |
| 431 | + rootElement.propsData = propsData; |
| 432 | + } else { |
| 433 | + rootElement = ComponentDefinition; |
| 434 | + var propsWithDefault = {}; |
| 435 | + Object.keys(propsData).forEach(function (prop) { |
| 436 | + propsWithDefault[prop] = { default: propsData[prop] }; |
| 437 | + }); |
| 438 | + rootElement.props = propsWithDefault; |
| 439 | + } |
416 | 440 |
|
417 |
| - return reactivePropsList; |
418 |
| - } |
419 |
| - }, |
420 |
| - render: function render(createElement) { |
421 |
| - var data = { |
422 |
| - props: this.reactiveProps |
423 |
| - }; |
| 441 | + var elementInnerHtml = vueVersion >= 2 ? '<div></div>' : ('<div>' + element.innerHTML + '</div>').replace(/vue-slot=/g, 'slot='); |
| 442 | + if (options.shadow && element.shadowRoot) { |
| 443 | + element.shadowRoot.innerHTML = elementInnerHtml; |
| 444 | + rootElement.el = element.shadowRoot.children[0]; |
| 445 | + } else { |
| 446 | + element.innerHTML = elementInnerHtml; |
| 447 | + rootElement.el = element.children[0]; |
| 448 | + } |
424 | 449 |
|
425 |
| - return createElement(ComponentDefinition, data, getSlots(elementOriginalChildren, createElement)); |
426 |
| - } |
427 |
| - }; |
428 |
| - } else if (vueVersion === 1) { |
429 |
| - rootElement = ComponentDefinition; |
430 |
| - rootElement.propsData = propsData; |
431 |
| - } else { |
432 |
| - rootElement = ComponentDefinition; |
433 |
| - var propsWithDefault = {}; |
434 |
| - Object.keys(propsData).forEach(function (prop) { |
435 |
| - propsWithDefault[prop] = { default: propsData[prop] }; |
436 |
| - }); |
437 |
| - rootElement.props = propsWithDefault; |
438 |
| - } |
| 450 | + if (options.shadow && options.shadowCss && element.shadowRoot) { |
| 451 | + var style = document.createElement('style'); |
| 452 | + style.type = 'text/css'; |
| 453 | + style.appendChild(document.createTextNode(options.shadowCss)); |
439 | 454 |
|
440 |
| - var elementInnerHtml = vueVersion >= 2 ? '<div></div>' : ('<div>' + element.innerHTML + '</div>').replace(/vue-slot=/g, 'slot='); |
441 |
| - if (options.shadow && element.shadowRoot) { |
442 |
| - element.shadowRoot.innerHTML = elementInnerHtml; |
443 |
| - rootElement.el = element.shadowRoot.children[0]; |
444 |
| - } else { |
445 |
| - element.innerHTML = elementInnerHtml; |
446 |
| - rootElement.el = element.children[0]; |
447 |
| - } |
| 455 | + element.shadowRoot.appendChild(style); |
| 456 | + } |
448 | 457 |
|
449 |
| - reactiveProps(element, props); |
| 458 | + reactiveProps(element, props); |
450 | 459 |
|
451 |
| - if (typeof options.beforeCreateVueInstance === 'function') { |
452 |
| - rootElement = options.beforeCreateVueInstance(rootElement) || rootElement; |
453 |
| - } |
| 460 | + if (typeof options.beforeCreateVueInstance === 'function') { |
| 461 | + rootElement = options.beforeCreateVueInstance(rootElement) || rootElement; |
| 462 | + } |
454 | 463 |
|
455 |
| - element.__vue_custom_element__ = new Vue(rootElement); |
| 464 | + return Promise.resolve(rootElement).then(function (vueOpts) { |
| 465 | + element.__vue_custom_element__ = new Vue(vueOpts); |
456 | 466 | element.__vue_custom_element_props__ = props;
|
457 | 467 | element.getVueInstance = function () {
|
458 | 468 | var vueInstance = element.__vue_custom_element__;
|
459 | 469 | return vueInstance.$children.length ? vueInstance.$children[0] : vueInstance;
|
460 | 470 | };
|
461 | 471 |
|
462 |
| - if (options.shadow && options.shadowCss && element.shadowRoot) { |
463 |
| - var style = document.createElement('style'); |
464 |
| - style.type = 'text/css'; |
465 |
| - style.appendChild(document.createTextNode(options.shadowCss)); |
466 |
| - |
467 |
| - element.shadowRoot.appendChild(style); |
468 |
| - } |
469 | 472 | element.removeAttribute('vce-cloak');
|
470 | 473 | element.setAttribute('vce-ready', '');
|
471 | 474 | customEmit(element, 'vce-ready');
|
472 |
| - } |
| 475 | + return element; |
| 476 | + }); |
473 | 477 | }
|
474 | 478 |
|
475 | 479 | function install(Vue) {
|
@@ -497,14 +501,16 @@ function install(Vue) {
|
497 | 501 | }
|
498 | 502 | if (!this.__detached__) {
|
499 | 503 | if (isAsyncComponentPromise) {
|
500 |
| - asyncComponentPromise.then(function (lazyLoadedComponent) { |
501 |
| - var lazyLoadedComponentProps = getProps(lazyLoadedComponent); |
502 |
| - createVueInstance(_this, Vue, lazyLoadedComponent, lazyLoadedComponentProps, options); |
503 |
| - typeof options.vueInstanceCreatedCallback === 'function' && options.vueInstanceCreatedCallback.call(_this); |
| 504 | + asyncComponentPromise.then(function (lazyComponent) { |
| 505 | + var lazyProps = getProps(lazyComponent); |
| 506 | + createVueInstance(_this, Vue, lazyComponent, lazyProps, options).then(function () { |
| 507 | + typeof options.vueInstanceCreatedCallback === 'function' && options.vueInstanceCreatedCallback.call(_this); |
| 508 | + }); |
504 | 509 | });
|
505 | 510 | } else {
|
506 |
| - createVueInstance(this, Vue, componentDefinition, props, options); |
507 |
| - typeof options.vueInstanceCreatedCallback === 'function' && options.vueInstanceCreatedCallback.call(this); |
| 511 | + createVueInstance(this, Vue, componentDefinition, props, options).then(function () { |
| 512 | + typeof options.vueInstanceCreatedCallback === 'function' && options.vueInstanceCreatedCallback.call(_this); |
| 513 | + }); |
508 | 514 | }
|
509 | 515 | }
|
510 | 516 |
|
|
0 commit comments