@vue/runtime-dom 3.2.44 → 3.2.45

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.
@@ -479,12 +479,21 @@ class VueElement extends BaseClass {
479
479
  `defined as hydratable. Use \`defineSSRCustomElement\`.`);
480
480
  }
481
481
  this.attachShadow({ mode: 'open' });
482
+ if (!this._def.__asyncLoader) {
483
+ // for sync component defs we can immediately resolve props
484
+ this._resolveProps(this._def);
485
+ }
482
486
  }
483
487
  }
484
488
  connectedCallback() {
485
489
  this._connected = true;
486
490
  if (!this._instance) {
487
- this._resolveDef();
491
+ if (this._resolved) {
492
+ this._update();
493
+ }
494
+ else {
495
+ this._resolveDef();
496
+ }
488
497
  }
489
498
  }
490
499
  disconnectedCallback() {
@@ -500,9 +509,6 @@ class VueElement extends BaseClass {
500
509
  * resolve inner component definition (handle possible async component)
501
510
  */
502
511
  _resolveDef() {
503
- if (this._resolved) {
504
- return;
505
- }
506
512
  this._resolved = true;
507
513
  // set initial attrs
508
514
  for (let i = 0; i < this.attributes.length; i++) {
@@ -514,38 +520,26 @@ class VueElement extends BaseClass {
514
520
  this._setAttr(m.attributeName);
515
521
  }
516
522
  }).observe(this, { attributes: true });
517
- const resolve = (def) => {
518
- const { props = {}, styles } = def;
519
- const hasOptions = !shared.isArray(props);
520
- const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
523
+ const resolve = (def, isAsync = false) => {
524
+ const { props, styles } = def;
521
525
  // cast Number-type props set before resolve
522
526
  let numberProps;
523
- if (hasOptions) {
524
- for (const key in this._props) {
527
+ if (props && !shared.isArray(props)) {
528
+ for (const key in props) {
525
529
  const opt = props[key];
526
530
  if (opt === Number || (opt && opt.type === Number)) {
527
- this._props[key] = shared.toNumber(this._props[key]);
528
- (numberProps || (numberProps = Object.create(null)))[key] = true;
531
+ if (key in this._props) {
532
+ this._props[key] = shared.toNumber(this._props[key]);
533
+ }
534
+ (numberProps || (numberProps = Object.create(null)))[shared.camelize(key)] = true;
529
535
  }
530
536
  }
531
537
  }
532
538
  this._numberProps = numberProps;
533
- // check if there are props set pre-upgrade or connect
534
- for (const key of Object.keys(this)) {
535
- if (key[0] !== '_') {
536
- this._setProp(key, this[key], true, false);
537
- }
538
- }
539
- // defining getter/setters on prototype
540
- for (const key of rawKeys.map(shared.camelize)) {
541
- Object.defineProperty(this, key, {
542
- get() {
543
- return this._getProp(key);
544
- },
545
- set(val) {
546
- this._setProp(key, val);
547
- }
548
- });
539
+ if (isAsync) {
540
+ // defining getter/setters on prototype
541
+ // for sync defs, this already happened in the constructor
542
+ this._resolveProps(def);
549
543
  }
550
544
  // apply CSS
551
545
  this._applyStyles(styles);
@@ -554,12 +548,33 @@ class VueElement extends BaseClass {
554
548
  };
555
549
  const asyncDef = this._def.__asyncLoader;
556
550
  if (asyncDef) {
557
- asyncDef().then(resolve);
551
+ asyncDef().then(def => resolve(def, true));
558
552
  }
559
553
  else {
560
554
  resolve(this._def);
561
555
  }
562
556
  }
557
+ _resolveProps(def) {
558
+ const { props } = def;
559
+ const declaredPropKeys = shared.isArray(props) ? props : Object.keys(props || {});
560
+ // check if there are props set pre-upgrade or connect
561
+ for (const key of Object.keys(this)) {
562
+ if (key[0] !== '_' && declaredPropKeys.includes(key)) {
563
+ this._setProp(key, this[key], true, false);
564
+ }
565
+ }
566
+ // defining getter/setters on prototype
567
+ for (const key of declaredPropKeys.map(shared.camelize)) {
568
+ Object.defineProperty(this, key, {
569
+ get() {
570
+ return this._getProp(key);
571
+ },
572
+ set(val) {
573
+ this._setProp(key, val);
574
+ }
575
+ });
576
+ }
577
+ }
563
578
  _setAttr(key) {
564
579
  let value = this.getAttribute(key);
565
580
  const camelKey = shared.camelize(key);
@@ -615,27 +630,31 @@ class VueElement extends BaseClass {
615
630
  this._styles.length = 0;
616
631
  }
617
632
  this._applyStyles(newStyles);
618
- // if this is an async component, ceReload is called from the inner
619
- // component so no need to reload the async wrapper
620
- if (!this._def.__asyncLoader) {
621
- // reload
622
- this._instance = null;
623
- this._update();
624
- }
633
+ this._instance = null;
634
+ this._update();
625
635
  };
626
636
  }
627
- // intercept emit
628
- instance.emit = (event, ...args) => {
637
+ const dispatch = (event, args) => {
629
638
  this.dispatchEvent(new CustomEvent(event, {
630
639
  detail: args
631
640
  }));
632
641
  };
642
+ // intercept emit
643
+ instance.emit = (event, ...args) => {
644
+ // dispatch both the raw and hyphenated versions of an event
645
+ // to match Vue behavior
646
+ dispatch(event, args);
647
+ if (shared.hyphenate(event) !== event) {
648
+ dispatch(shared.hyphenate(event), args);
649
+ }
650
+ };
633
651
  // locate nearest Vue custom element parent for provide/inject
634
652
  let parent = this;
635
653
  while ((parent =
636
654
  parent && (parent.parentNode || parent.host))) {
637
655
  if (parent instanceof VueElement) {
638
656
  instance.parent = parent._instance;
657
+ instance.provides = parent._instance.provides;
639
658
  break;
640
659
  }
641
660
  }
@@ -464,12 +464,21 @@ class VueElement extends BaseClass {
464
464
  }
465
465
  else {
466
466
  this.attachShadow({ mode: 'open' });
467
+ if (!this._def.__asyncLoader) {
468
+ // for sync component defs we can immediately resolve props
469
+ this._resolveProps(this._def);
470
+ }
467
471
  }
468
472
  }
469
473
  connectedCallback() {
470
474
  this._connected = true;
471
475
  if (!this._instance) {
472
- this._resolveDef();
476
+ if (this._resolved) {
477
+ this._update();
478
+ }
479
+ else {
480
+ this._resolveDef();
481
+ }
473
482
  }
474
483
  }
475
484
  disconnectedCallback() {
@@ -485,9 +494,6 @@ class VueElement extends BaseClass {
485
494
  * resolve inner component definition (handle possible async component)
486
495
  */
487
496
  _resolveDef() {
488
- if (this._resolved) {
489
- return;
490
- }
491
497
  this._resolved = true;
492
498
  // set initial attrs
493
499
  for (let i = 0; i < this.attributes.length; i++) {
@@ -499,38 +505,26 @@ class VueElement extends BaseClass {
499
505
  this._setAttr(m.attributeName);
500
506
  }
501
507
  }).observe(this, { attributes: true });
502
- const resolve = (def) => {
503
- const { props = {}, styles } = def;
504
- const hasOptions = !shared.isArray(props);
505
- const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
508
+ const resolve = (def, isAsync = false) => {
509
+ const { props, styles } = def;
506
510
  // cast Number-type props set before resolve
507
511
  let numberProps;
508
- if (hasOptions) {
509
- for (const key in this._props) {
512
+ if (props && !shared.isArray(props)) {
513
+ for (const key in props) {
510
514
  const opt = props[key];
511
515
  if (opt === Number || (opt && opt.type === Number)) {
512
- this._props[key] = shared.toNumber(this._props[key]);
513
- (numberProps || (numberProps = Object.create(null)))[key] = true;
516
+ if (key in this._props) {
517
+ this._props[key] = shared.toNumber(this._props[key]);
518
+ }
519
+ (numberProps || (numberProps = Object.create(null)))[shared.camelize(key)] = true;
514
520
  }
515
521
  }
516
522
  }
517
523
  this._numberProps = numberProps;
518
- // check if there are props set pre-upgrade or connect
519
- for (const key of Object.keys(this)) {
520
- if (key[0] !== '_') {
521
- this._setProp(key, this[key], true, false);
522
- }
523
- }
524
- // defining getter/setters on prototype
525
- for (const key of rawKeys.map(shared.camelize)) {
526
- Object.defineProperty(this, key, {
527
- get() {
528
- return this._getProp(key);
529
- },
530
- set(val) {
531
- this._setProp(key, val);
532
- }
533
- });
524
+ if (isAsync) {
525
+ // defining getter/setters on prototype
526
+ // for sync defs, this already happened in the constructor
527
+ this._resolveProps(def);
534
528
  }
535
529
  // apply CSS
536
530
  this._applyStyles(styles);
@@ -539,12 +533,33 @@ class VueElement extends BaseClass {
539
533
  };
540
534
  const asyncDef = this._def.__asyncLoader;
541
535
  if (asyncDef) {
542
- asyncDef().then(resolve);
536
+ asyncDef().then(def => resolve(def, true));
543
537
  }
544
538
  else {
545
539
  resolve(this._def);
546
540
  }
547
541
  }
542
+ _resolveProps(def) {
543
+ const { props } = def;
544
+ const declaredPropKeys = shared.isArray(props) ? props : Object.keys(props || {});
545
+ // check if there are props set pre-upgrade or connect
546
+ for (const key of Object.keys(this)) {
547
+ if (key[0] !== '_' && declaredPropKeys.includes(key)) {
548
+ this._setProp(key, this[key], true, false);
549
+ }
550
+ }
551
+ // defining getter/setters on prototype
552
+ for (const key of declaredPropKeys.map(shared.camelize)) {
553
+ Object.defineProperty(this, key, {
554
+ get() {
555
+ return this._getProp(key);
556
+ },
557
+ set(val) {
558
+ this._setProp(key, val);
559
+ }
560
+ });
561
+ }
562
+ }
548
563
  _setAttr(key) {
549
564
  let value = this.getAttribute(key);
550
565
  const camelKey = shared.camelize(key);
@@ -591,18 +606,27 @@ class VueElement extends BaseClass {
591
606
  vnode.ce = instance => {
592
607
  this._instance = instance;
593
608
  instance.isCE = true;
594
- // intercept emit
595
- instance.emit = (event, ...args) => {
609
+ const dispatch = (event, args) => {
596
610
  this.dispatchEvent(new CustomEvent(event, {
597
611
  detail: args
598
612
  }));
599
613
  };
614
+ // intercept emit
615
+ instance.emit = (event, ...args) => {
616
+ // dispatch both the raw and hyphenated versions of an event
617
+ // to match Vue behavior
618
+ dispatch(event, args);
619
+ if (shared.hyphenate(event) !== event) {
620
+ dispatch(shared.hyphenate(event), args);
621
+ }
622
+ };
600
623
  // locate nearest Vue custom element parent for provide/inject
601
624
  let parent = this;
602
625
  while ((parent =
603
626
  parent && (parent.parentNode || parent.host))) {
604
627
  if (parent instanceof VueElement) {
605
628
  instance.parent = parent._instance;
629
+ instance.provides = parent._instance.provides;
606
630
  break;
607
631
  }
608
632
  }
@@ -142,6 +142,7 @@ export declare class VueElement extends BaseClass {
142
142
  * resolve inner component definition (handle possible async component)
143
143
  */
144
144
  private _resolveDef;
145
+ private _resolveProps;
145
146
  protected _setAttr(key: string): void;
146
147
  /* Excluded from this release type: _getProp */
147
148
  /* Excluded from this release type: _setProp */