@vue/runtime-dom 3.2.44 → 3.2.46

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.
@@ -1,6 +1,6 @@
1
- import { warn, camelize, callWithAsyncErrorHandling, defineComponent, nextTick, createVNode, getCurrentInstance, watchPostEffect, onMounted, onUnmounted, Fragment, Static, h, BaseTransition, useTransitionState, onUpdated, toRaw, getTransitionRawChildren, setTransitionHooks, resolveTransitionHooks, createRenderer, isRuntimeOnly, createHydrationRenderer } from '@vue/runtime-core';
1
+ import { warn, camelize, callWithAsyncErrorHandling, defineComponent, nextTick, createVNode, getCurrentInstance, watchPostEffect, onMounted, onUnmounted, Fragment, Static, h, BaseTransition, assertNumber, useTransitionState, onUpdated, toRaw, getTransitionRawChildren, setTransitionHooks, resolveTransitionHooks, isRuntimeOnly, createRenderer, createHydrationRenderer } from '@vue/runtime-core';
2
2
  export * from '@vue/runtime-core';
3
- import { isString, isArray, hyphenate, capitalize, isSpecialBooleanAttr, includeBooleanAttr, isOn, isModelListener, isFunction, camelize as camelize$1, toNumber, extend, EMPTY_OBJ, isObject, invokeArrayFns, looseIndexOf, isSet, looseEqual, isHTMLTag, isSVGTag } from '@vue/shared';
3
+ import { isString, isArray, hyphenate, capitalize, isSpecialBooleanAttr, includeBooleanAttr, isOn, isModelListener, isFunction, camelize as camelize$1, toNumber, extend, EMPTY_OBJ, isObject, looseToNumber, looseIndexOf, isSet, looseEqual, invokeArrayFns, isHTMLTag, isSVGTag } from '@vue/shared';
4
4
 
5
5
  const svgNS = 'http://www.w3.org/2000/svg';
6
6
  const doc = (typeof document !== 'undefined' ? document : null);
@@ -104,9 +104,6 @@ function patchStyle(el, prev, next) {
104
104
  const style = el.style;
105
105
  const isCssString = isString(next);
106
106
  if (next && !isCssString) {
107
- for (const key in next) {
108
- setStyle(style, key, next[key]);
109
- }
110
107
  if (prev && !isString(prev)) {
111
108
  for (const key in prev) {
112
109
  if (next[key] == null) {
@@ -114,6 +111,9 @@ function patchStyle(el, prev, next) {
114
111
  }
115
112
  }
116
113
  }
114
+ for (const key in next) {
115
+ setStyle(style, key, next[key]);
116
+ }
117
117
  }
118
118
  else {
119
119
  const currentDisplay = style.display;
@@ -476,12 +476,21 @@ class VueElement extends BaseClass {
476
476
  `defined as hydratable. Use \`defineSSRCustomElement\`.`);
477
477
  }
478
478
  this.attachShadow({ mode: 'open' });
479
+ if (!this._def.__asyncLoader) {
480
+ // for sync component defs we can immediately resolve props
481
+ this._resolveProps(this._def);
482
+ }
479
483
  }
480
484
  }
481
485
  connectedCallback() {
482
486
  this._connected = true;
483
487
  if (!this._instance) {
484
- this._resolveDef();
488
+ if (this._resolved) {
489
+ this._update();
490
+ }
491
+ else {
492
+ this._resolveDef();
493
+ }
485
494
  }
486
495
  }
487
496
  disconnectedCallback() {
@@ -497,9 +506,6 @@ class VueElement extends BaseClass {
497
506
  * resolve inner component definition (handle possible async component)
498
507
  */
499
508
  _resolveDef() {
500
- if (this._resolved) {
501
- return;
502
- }
503
509
  this._resolved = true;
504
510
  // set initial attrs
505
511
  for (let i = 0; i < this.attributes.length; i++) {
@@ -511,38 +517,26 @@ class VueElement extends BaseClass {
511
517
  this._setAttr(m.attributeName);
512
518
  }
513
519
  }).observe(this, { attributes: true });
514
- const resolve = (def) => {
515
- const { props = {}, styles } = def;
516
- const hasOptions = !isArray(props);
517
- const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
520
+ const resolve = (def, isAsync = false) => {
521
+ const { props, styles } = def;
518
522
  // cast Number-type props set before resolve
519
523
  let numberProps;
520
- if (hasOptions) {
521
- for (const key in this._props) {
524
+ if (props && !isArray(props)) {
525
+ for (const key in props) {
522
526
  const opt = props[key];
523
527
  if (opt === Number || (opt && opt.type === Number)) {
524
- this._props[key] = toNumber(this._props[key]);
525
- (numberProps || (numberProps = Object.create(null)))[key] = true;
528
+ if (key in this._props) {
529
+ this._props[key] = toNumber(this._props[key]);
530
+ }
531
+ (numberProps || (numberProps = Object.create(null)))[camelize$1(key)] = true;
526
532
  }
527
533
  }
528
534
  }
529
535
  this._numberProps = numberProps;
530
- // check if there are props set pre-upgrade or connect
531
- for (const key of Object.keys(this)) {
532
- if (key[0] !== '_') {
533
- this._setProp(key, this[key], true, false);
534
- }
535
- }
536
- // defining getter/setters on prototype
537
- for (const key of rawKeys.map(camelize$1)) {
538
- Object.defineProperty(this, key, {
539
- get() {
540
- return this._getProp(key);
541
- },
542
- set(val) {
543
- this._setProp(key, val);
544
- }
545
- });
536
+ if (isAsync) {
537
+ // defining getter/setters on prototype
538
+ // for sync defs, this already happened in the constructor
539
+ this._resolveProps(def);
546
540
  }
547
541
  // apply CSS
548
542
  this._applyStyles(styles);
@@ -551,12 +545,33 @@ class VueElement extends BaseClass {
551
545
  };
552
546
  const asyncDef = this._def.__asyncLoader;
553
547
  if (asyncDef) {
554
- asyncDef().then(resolve);
548
+ asyncDef().then(def => resolve(def, true));
555
549
  }
556
550
  else {
557
551
  resolve(this._def);
558
552
  }
559
553
  }
554
+ _resolveProps(def) {
555
+ const { props } = def;
556
+ const declaredPropKeys = isArray(props) ? props : Object.keys(props || {});
557
+ // check if there are props set pre-upgrade or connect
558
+ for (const key of Object.keys(this)) {
559
+ if (key[0] !== '_' && declaredPropKeys.includes(key)) {
560
+ this._setProp(key, this[key], true, false);
561
+ }
562
+ }
563
+ // defining getter/setters on prototype
564
+ for (const key of declaredPropKeys.map(camelize$1)) {
565
+ Object.defineProperty(this, key, {
566
+ get() {
567
+ return this._getProp(key);
568
+ },
569
+ set(val) {
570
+ this._setProp(key, val);
571
+ }
572
+ });
573
+ }
574
+ }
560
575
  _setAttr(key) {
561
576
  let value = this.getAttribute(key);
562
577
  const camelKey = camelize$1(key);
@@ -612,27 +627,31 @@ class VueElement extends BaseClass {
612
627
  this._styles.length = 0;
613
628
  }
614
629
  this._applyStyles(newStyles);
615
- // if this is an async component, ceReload is called from the inner
616
- // component so no need to reload the async wrapper
617
- if (!this._def.__asyncLoader) {
618
- // reload
619
- this._instance = null;
620
- this._update();
621
- }
630
+ this._instance = null;
631
+ this._update();
622
632
  };
623
633
  }
624
- // intercept emit
625
- instance.emit = (event, ...args) => {
634
+ const dispatch = (event, args) => {
626
635
  this.dispatchEvent(new CustomEvent(event, {
627
636
  detail: args
628
637
  }));
629
638
  };
639
+ // intercept emit
640
+ instance.emit = (event, ...args) => {
641
+ // dispatch both the raw and hyphenated versions of an event
642
+ // to match Vue behavior
643
+ dispatch(event, args);
644
+ if (hyphenate(event) !== event) {
645
+ dispatch(hyphenate(event), args);
646
+ }
647
+ };
630
648
  // locate nearest Vue custom element parent for provide/inject
631
649
  let parent = this;
632
650
  while ((parent =
633
651
  parent && (parent.parentNode || parent.host))) {
634
652
  if (parent instanceof VueElement) {
635
653
  instance.parent = parent._instance;
654
+ instance.provides = parent._instance.provides;
636
655
  break;
637
656
  }
638
657
  }
@@ -690,7 +709,14 @@ function useCssVars(getter) {
690
709
  warn(`useCssVars is called without current active component instance.`);
691
710
  return;
692
711
  }
693
- const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
712
+ const updateTeleports = (instance.ut = (vars = getter(instance.proxy)) => {
713
+ Array.from(document.querySelectorAll(`[data-v-owner="${instance.uid}"]`)).forEach(node => setVarsOnNode(node, vars));
714
+ });
715
+ const setVars = () => {
716
+ const vars = getter(instance.proxy);
717
+ setVarsOnVNode(instance.subTree, vars);
718
+ updateTeleports(vars);
719
+ };
694
720
  watchPostEffect(setVars);
695
721
  onMounted(() => {
696
722
  const ob = new MutationObserver(setVars);
@@ -888,19 +914,10 @@ function normalizeDuration(duration) {
888
914
  }
889
915
  function NumberOf(val) {
890
916
  const res = toNumber(val);
891
- if ((process.env.NODE_ENV !== 'production'))
892
- validateDuration(res);
893
- return res;
894
- }
895
- function validateDuration(val) {
896
- if (typeof val !== 'number') {
897
- warn(`<transition> explicit duration is not a valid number - ` +
898
- `got ${JSON.stringify(val)}.`);
899
- }
900
- else if (isNaN(val)) {
901
- warn(`<transition> explicit duration is NaN - ` +
902
- 'the duration expression might be incorrect.');
917
+ if ((process.env.NODE_ENV !== 'production')) {
918
+ assertNumber(res, '<transition> explicit duration');
903
919
  }
920
+ return res;
904
921
  }
905
922
  function addTransitionClass(el, cls) {
906
923
  cls.split(/\s+/).forEach(c => c && el.classList.add(c));
@@ -1097,6 +1114,14 @@ const TransitionGroupImpl = {
1097
1114
  };
1098
1115
  }
1099
1116
  };
1117
+ /**
1118
+ * TransitionGroup does not support "mode" so we need to remove it from the
1119
+ * props declarations, but direct delete operation is considered a side effect
1120
+ * and will make the entire transition feature non-tree-shakeable, so we do it
1121
+ * in a function and mark the function's invocation as pure.
1122
+ */
1123
+ const removeMode = (props) => delete props.mode;
1124
+ /*#__PURE__*/ removeMode(TransitionGroupImpl.props);
1100
1125
  const TransitionGroup = TransitionGroupImpl;
1101
1126
  function callPendingCbs(c) {
1102
1127
  const el = c.el;
@@ -1172,7 +1197,7 @@ const vModelText = {
1172
1197
  domValue = domValue.trim();
1173
1198
  }
1174
1199
  if (castToNumber) {
1175
- domValue = toNumber(domValue);
1200
+ domValue = looseToNumber(domValue);
1176
1201
  }
1177
1202
  el._assign(domValue);
1178
1203
  });
@@ -1207,7 +1232,8 @@ const vModelText = {
1207
1232
  if (trim && el.value.trim() === value) {
1208
1233
  return;
1209
1234
  }
1210
- if ((number || el.type === 'number') && toNumber(el.value) === value) {
1235
+ if ((number || el.type === 'number') &&
1236
+ looseToNumber(el.value) === value) {
1211
1237
  return;
1212
1238
  }
1213
1239
  }
@@ -1296,7 +1322,7 @@ const vModelSelect = {
1296
1322
  addEventListener(el, 'change', () => {
1297
1323
  const selectedVal = Array.prototype.filter
1298
1324
  .call(el.options, (o) => o.selected)
1299
- .map((o) => number ? toNumber(getValue(o)) : getValue(o));
1325
+ .map((o) => number ? looseToNumber(getValue(o)) : getValue(o));
1300
1326
  el._assign(el.multiple
1301
1327
  ? isSetModel
1302
1328
  ? new Set(selectedVal)