@vue/runtime-dom 3.2.43 → 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.
@@ -136,6 +136,7 @@ function patchStyle(el, prev, next) {
136
136
  }
137
137
  }
138
138
  }
139
+ const semicolonRE = /[^\\];\s*$/;
139
140
  const importantRE = /\s*!important$/;
140
141
  function setStyle(style, name, val) {
141
142
  if (shared.isArray(val)) {
@@ -144,6 +145,11 @@ function setStyle(style, name, val) {
144
145
  else {
145
146
  if (val == null)
146
147
  val = '';
148
+ {
149
+ if (semicolonRE.test(val)) {
150
+ runtimeCore.warn(`Unexpected semicolon at the end of '${name}' style value: '${val}'`);
151
+ }
152
+ }
147
153
  if (name.startsWith('--')) {
148
154
  // custom property definition
149
155
  style.setProperty(name, val);
@@ -473,12 +479,21 @@ class VueElement extends BaseClass {
473
479
  `defined as hydratable. Use \`defineSSRCustomElement\`.`);
474
480
  }
475
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
+ }
476
486
  }
477
487
  }
478
488
  connectedCallback() {
479
489
  this._connected = true;
480
490
  if (!this._instance) {
481
- this._resolveDef();
491
+ if (this._resolved) {
492
+ this._update();
493
+ }
494
+ else {
495
+ this._resolveDef();
496
+ }
482
497
  }
483
498
  }
484
499
  disconnectedCallback() {
@@ -494,9 +509,6 @@ class VueElement extends BaseClass {
494
509
  * resolve inner component definition (handle possible async component)
495
510
  */
496
511
  _resolveDef() {
497
- if (this._resolved) {
498
- return;
499
- }
500
512
  this._resolved = true;
501
513
  // set initial attrs
502
514
  for (let i = 0; i < this.attributes.length; i++) {
@@ -508,38 +520,26 @@ class VueElement extends BaseClass {
508
520
  this._setAttr(m.attributeName);
509
521
  }
510
522
  }).observe(this, { attributes: true });
511
- const resolve = (def) => {
512
- const { props = {}, styles } = def;
513
- const hasOptions = !shared.isArray(props);
514
- const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
523
+ const resolve = (def, isAsync = false) => {
524
+ const { props, styles } = def;
515
525
  // cast Number-type props set before resolve
516
526
  let numberProps;
517
- if (hasOptions) {
518
- for (const key in this._props) {
527
+ if (props && !shared.isArray(props)) {
528
+ for (const key in props) {
519
529
  const opt = props[key];
520
530
  if (opt === Number || (opt && opt.type === Number)) {
521
- this._props[key] = shared.toNumber(this._props[key]);
522
- (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;
523
535
  }
524
536
  }
525
537
  }
526
538
  this._numberProps = numberProps;
527
- // check if there are props set pre-upgrade or connect
528
- for (const key of Object.keys(this)) {
529
- if (key[0] !== '_') {
530
- this._setProp(key, this[key], true, false);
531
- }
532
- }
533
- // defining getter/setters on prototype
534
- for (const key of rawKeys.map(shared.camelize)) {
535
- Object.defineProperty(this, key, {
536
- get() {
537
- return this._getProp(key);
538
- },
539
- set(val) {
540
- this._setProp(key, val);
541
- }
542
- });
539
+ if (isAsync) {
540
+ // defining getter/setters on prototype
541
+ // for sync defs, this already happened in the constructor
542
+ this._resolveProps(def);
543
543
  }
544
544
  // apply CSS
545
545
  this._applyStyles(styles);
@@ -548,12 +548,33 @@ class VueElement extends BaseClass {
548
548
  };
549
549
  const asyncDef = this._def.__asyncLoader;
550
550
  if (asyncDef) {
551
- asyncDef().then(resolve);
551
+ asyncDef().then(def => resolve(def, true));
552
552
  }
553
553
  else {
554
554
  resolve(this._def);
555
555
  }
556
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
+ }
557
578
  _setAttr(key) {
558
579
  let value = this.getAttribute(key);
559
580
  const camelKey = shared.camelize(key);
@@ -609,27 +630,31 @@ class VueElement extends BaseClass {
609
630
  this._styles.length = 0;
610
631
  }
611
632
  this._applyStyles(newStyles);
612
- // if this is an async component, ceReload is called from the inner
613
- // component so no need to reload the async wrapper
614
- if (!this._def.__asyncLoader) {
615
- // reload
616
- this._instance = null;
617
- this._update();
618
- }
633
+ this._instance = null;
634
+ this._update();
619
635
  };
620
636
  }
621
- // intercept emit
622
- instance.emit = (event, ...args) => {
637
+ const dispatch = (event, args) => {
623
638
  this.dispatchEvent(new CustomEvent(event, {
624
639
  detail: args
625
640
  }));
626
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
+ };
627
651
  // locate nearest Vue custom element parent for provide/inject
628
652
  let parent = this;
629
653
  while ((parent =
630
654
  parent && (parent.parentNode || parent.host))) {
631
655
  if (parent instanceof VueElement) {
632
656
  instance.parent = parent._instance;
657
+ instance.provides = parent._instance.provides;
633
658
  break;
634
659
  }
635
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 */