@vue/runtime-dom 3.2.24 → 3.2.25

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.
@@ -37,7 +37,7 @@ var VueRuntimeDOM = (function (exports) {
37
37
  const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
38
38
  /**
39
39
  * Boolean attributes should be included if the value is truthy or ''.
40
- * e.g. <select multiple> compiles to { multiple: '' }
40
+ * e.g. `<select multiple>` compiles to `{ multiple: '' }`
41
41
  */
42
42
  function includeBooleanAttr(value) {
43
43
  return !!value || value === '';
@@ -269,7 +269,7 @@ var VueRuntimeDOM = (function (exports) {
269
269
  '' + parseInt(key, 10) === key;
270
270
  const isReservedProp = /*#__PURE__*/ makeMap(
271
271
  // the leading comma is intentional so empty string "" is also included
272
- ',key,ref,' +
272
+ ',key,ref,ref_for,ref_key,' +
273
273
  'onVnodeBeforeMount,onVnodeMounted,' +
274
274
  'onVnodeBeforeUpdate,onVnodeUpdated,' +
275
275
  'onVnodeBeforeUnmount,onVnodeUnmounted');
@@ -1364,21 +1364,25 @@ var VueRuntimeDOM = (function (exports) {
1364
1364
  return ret;
1365
1365
  }
1366
1366
  class ObjectRefImpl {
1367
- constructor(_object, _key) {
1367
+ constructor(_object, _key, _defaultValue) {
1368
1368
  this._object = _object;
1369
1369
  this._key = _key;
1370
+ this._defaultValue = _defaultValue;
1370
1371
  this.__v_isRef = true;
1371
1372
  }
1372
1373
  get value() {
1373
- return this._object[this._key];
1374
+ const val = this._object[this._key];
1375
+ return val === undefined ? this._defaultValue : val;
1374
1376
  }
1375
1377
  set value(newVal) {
1376
1378
  this._object[this._key] = newVal;
1377
1379
  }
1378
1380
  }
1379
- function toRef(object, key) {
1381
+ function toRef(object, key, defaultValue) {
1380
1382
  const val = object[key];
1381
- return isRef(val) ? val : new ObjectRefImpl(object, key);
1383
+ return isRef(val)
1384
+ ? val
1385
+ : new ObjectRefImpl(object, key, defaultValue);
1382
1386
  }
1383
1387
 
1384
1388
  class ComputedRefImpl {
@@ -4637,6 +4641,102 @@ var VueRuntimeDOM = (function (exports) {
4637
4641
  };
4638
4642
  }
4639
4643
 
4644
+ /**
4645
+ * Function for handling a template ref
4646
+ */
4647
+ function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
4648
+ if (isArray(rawRef)) {
4649
+ rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
4650
+ return;
4651
+ }
4652
+ if (isAsyncWrapper(vnode) && !isUnmount) {
4653
+ // when mounting async components, nothing needs to be done,
4654
+ // because the template ref is forwarded to inner component
4655
+ return;
4656
+ }
4657
+ const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
4658
+ ? getExposeProxy(vnode.component) || vnode.component.proxy
4659
+ : vnode.el;
4660
+ const value = isUnmount ? null : refValue;
4661
+ const { i: owner, r: ref } = rawRef;
4662
+ if (!owner) {
4663
+ warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
4664
+ `A vnode with ref must be created inside the render function.`);
4665
+ return;
4666
+ }
4667
+ const oldRef = oldRawRef && oldRawRef.r;
4668
+ const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
4669
+ const setupState = owner.setupState;
4670
+ // dynamic ref changed. unset old ref
4671
+ if (oldRef != null && oldRef !== ref) {
4672
+ if (isString(oldRef)) {
4673
+ refs[oldRef] = null;
4674
+ if (hasOwn(setupState, oldRef)) {
4675
+ setupState[oldRef] = null;
4676
+ }
4677
+ }
4678
+ else if (isRef(oldRef)) {
4679
+ oldRef.value = null;
4680
+ }
4681
+ }
4682
+ if (isFunction(ref)) {
4683
+ callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
4684
+ }
4685
+ else {
4686
+ const _isString = isString(ref);
4687
+ const _isRef = isRef(ref);
4688
+ if (_isString || _isRef) {
4689
+ const doSet = () => {
4690
+ if (rawRef.f) {
4691
+ const existing = _isString ? refs[ref] : ref.value;
4692
+ if (isUnmount) {
4693
+ isArray(existing) && remove(existing, refValue);
4694
+ }
4695
+ else {
4696
+ if (!isArray(existing)) {
4697
+ if (_isString) {
4698
+ refs[ref] = [refValue];
4699
+ }
4700
+ else {
4701
+ ref.value = [refValue];
4702
+ if (rawRef.k)
4703
+ refs[rawRef.k] = ref.value;
4704
+ }
4705
+ }
4706
+ else if (!existing.includes(refValue)) {
4707
+ existing.push(refValue);
4708
+ }
4709
+ }
4710
+ }
4711
+ else if (_isString) {
4712
+ refs[ref] = value;
4713
+ if (hasOwn(setupState, ref)) {
4714
+ setupState[ref] = value;
4715
+ }
4716
+ }
4717
+ else if (isRef(ref)) {
4718
+ ref.value = value;
4719
+ if (rawRef.k)
4720
+ refs[rawRef.k] = value;
4721
+ }
4722
+ else {
4723
+ warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
4724
+ }
4725
+ };
4726
+ if (value) {
4727
+ doSet.id = -1;
4728
+ queuePostRenderEffect(doSet, parentSuspense);
4729
+ }
4730
+ else {
4731
+ doSet();
4732
+ }
4733
+ }
4734
+ else {
4735
+ warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
4736
+ }
4737
+ }
4738
+ }
4739
+
4640
4740
  let hasMismatch = false;
4641
4741
  const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
4642
4742
  const isComment = (node) => node.nodeType === 8 /* COMMENT */;
@@ -5269,12 +5369,15 @@ var VueRuntimeDOM = (function (exports) {
5269
5369
  const oldProps = n1.props || EMPTY_OBJ;
5270
5370
  const newProps = n2.props || EMPTY_OBJ;
5271
5371
  let vnodeHook;
5372
+ // disable recurse in beforeUpdate hooks
5373
+ parentComponent && toggleRecurse(parentComponent, false);
5272
5374
  if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
5273
5375
  invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
5274
5376
  }
5275
5377
  if (dirs) {
5276
5378
  invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
5277
5379
  }
5380
+ parentComponent && toggleRecurse(parentComponent, true);
5278
5381
  if (isHmrUpdating) {
5279
5382
  // HMR updated, force full diff
5280
5383
  patchFlag = 0;
@@ -5554,7 +5657,7 @@ var VueRuntimeDOM = (function (exports) {
5554
5657
  const { el, props } = initialVNode;
5555
5658
  const { bm, m, parent } = instance;
5556
5659
  const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
5557
- effect.allowRecurse = false;
5660
+ toggleRecurse(instance, false);
5558
5661
  // beforeMount hook
5559
5662
  if (bm) {
5560
5663
  invokeArrayFns(bm);
@@ -5564,7 +5667,7 @@ var VueRuntimeDOM = (function (exports) {
5564
5667
  (vnodeHook = props && props.onVnodeBeforeMount)) {
5565
5668
  invokeVNodeHook(vnodeHook, parent, initialVNode);
5566
5669
  }
5567
- effect.allowRecurse = true;
5670
+ toggleRecurse(instance, true);
5568
5671
  if (el && hydrateNode) {
5569
5672
  // vnode has adopted host node - perform hydration instead of mount.
5570
5673
  const hydrateSubTree = () => {
@@ -5646,7 +5749,7 @@ var VueRuntimeDOM = (function (exports) {
5646
5749
  pushWarningContext(next || instance.vnode);
5647
5750
  }
5648
5751
  // Disallow component effect recursion during pre-lifecycle hooks.
5649
- effect.allowRecurse = false;
5752
+ toggleRecurse(instance, false);
5650
5753
  if (next) {
5651
5754
  next.el = vnode.el;
5652
5755
  updateComponentPreRender(instance, next, optimized);
@@ -5662,7 +5765,7 @@ var VueRuntimeDOM = (function (exports) {
5662
5765
  if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
5663
5766
  invokeVNodeHook(vnodeHook, parent, next, vnode);
5664
5767
  }
5665
- effect.allowRecurse = true;
5768
+ toggleRecurse(instance, true);
5666
5769
  // render
5667
5770
  {
5668
5771
  startMeasure(instance, `render`);
@@ -5708,13 +5811,13 @@ var VueRuntimeDOM = (function (exports) {
5708
5811
  }
5709
5812
  };
5710
5813
  // create reactive effect for rendering
5711
- const effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
5712
- );
5814
+ const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
5815
+ ));
5713
5816
  const update = (instance.update = effect.run.bind(effect));
5714
5817
  update.id = instance.uid;
5715
5818
  // allowRecurse
5716
5819
  // #1801, #2043 component render effects should allow recursive updates
5717
- effect.allowRecurse = update.allowRecurse = true;
5820
+ toggleRecurse(instance, true);
5718
5821
  {
5719
5822
  effect.onTrack = instance.rtc
5720
5823
  ? e => invokeArrayFns(instance.rtc, e)
@@ -6238,85 +6341,8 @@ var VueRuntimeDOM = (function (exports) {
6238
6341
  createApp: createAppAPI(render, hydrate)
6239
6342
  };
6240
6343
  }
6241
- function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
6242
- if (isArray(rawRef)) {
6243
- rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
6244
- return;
6245
- }
6246
- if (isAsyncWrapper(vnode) && !isUnmount) {
6247
- // when mounting async components, nothing needs to be done,
6248
- // because the template ref is forwarded to inner component
6249
- return;
6250
- }
6251
- const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
6252
- ? getExposeProxy(vnode.component) || vnode.component.proxy
6253
- : vnode.el;
6254
- const value = isUnmount ? null : refValue;
6255
- const { i: owner, r: ref } = rawRef;
6256
- if (!owner) {
6257
- warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
6258
- `A vnode with ref must be created inside the render function.`);
6259
- return;
6260
- }
6261
- const oldRef = oldRawRef && oldRawRef.r;
6262
- const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
6263
- const setupState = owner.setupState;
6264
- // dynamic ref changed. unset old ref
6265
- if (oldRef != null && oldRef !== ref) {
6266
- if (isString(oldRef)) {
6267
- refs[oldRef] = null;
6268
- if (hasOwn(setupState, oldRef)) {
6269
- setupState[oldRef] = null;
6270
- }
6271
- }
6272
- else if (isRef(oldRef)) {
6273
- oldRef.value = null;
6274
- }
6275
- }
6276
- if (isString(ref)) {
6277
- const doSet = () => {
6278
- {
6279
- refs[ref] = value;
6280
- }
6281
- if (hasOwn(setupState, ref)) {
6282
- setupState[ref] = value;
6283
- }
6284
- };
6285
- // #1789: for non-null values, set them after render
6286
- // null values means this is unmount and it should not overwrite another
6287
- // ref with the same key
6288
- if (value) {
6289
- doSet.id = -1;
6290
- queuePostRenderEffect(doSet, parentSuspense);
6291
- }
6292
- else {
6293
- doSet();
6294
- }
6295
- }
6296
- else if (isRef(ref)) {
6297
- const doSet = () => {
6298
- ref.value = value;
6299
- };
6300
- if (value) {
6301
- doSet.id = -1;
6302
- queuePostRenderEffect(doSet, parentSuspense);
6303
- }
6304
- else {
6305
- doSet();
6306
- }
6307
- }
6308
- else if (isFunction(ref)) {
6309
- callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
6310
- }
6311
- else {
6312
- warn$1('Invalid template ref type:', value, `(${typeof value})`);
6313
- }
6314
- }
6315
- function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
6316
- callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
6317
- vnode,
6318
- prevVNode
6319
- ]);
6344
+ function toggleRecurse({ effect, update }, allowed) {
6345
+ effect.allowRecurse = update.allowRecurse = allowed;
6320
6346
  }
6321
6347
  /**
6322
6348
  * #1156
@@ -6775,10 +6801,10 @@ var VueRuntimeDOM = (function (exports) {
6775
6801
  };
6776
6802
  const InternalObjectKey = `__vInternal`;
6777
6803
  const normalizeKey = ({ key }) => key != null ? key : null;
6778
- const normalizeRef = ({ ref }) => {
6804
+ const normalizeRef = ({ ref, ref_key, ref_for }) => {
6779
6805
  return (ref != null
6780
6806
  ? isString(ref) || isRef(ref) || isFunction(ref)
6781
- ? { i: currentRenderingInstance, r: ref }
6807
+ ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
6782
6808
  : ref
6783
6809
  : null);
6784
6810
  };
@@ -7120,6 +7146,12 @@ var VueRuntimeDOM = (function (exports) {
7120
7146
  }
7121
7147
  }
7122
7148
  return ret;
7149
+ }
7150
+ function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
7151
+ callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
7152
+ vnode,
7153
+ prevVNode
7154
+ ]);
7123
7155
  }
7124
7156
 
7125
7157
  /**
@@ -7531,6 +7563,7 @@ var VueRuntimeDOM = (function (exports) {
7531
7563
  root: null,
7532
7564
  next: null,
7533
7565
  subTree: null,
7566
+ effect: null,
7534
7567
  update: null,
7535
7568
  scope: new EffectScope(true /* detached */),
7536
7569
  render: null,
@@ -8967,7 +9000,7 @@ var VueRuntimeDOM = (function (exports) {
8967
9000
  }
8968
9001
 
8969
9002
  // Core API ------------------------------------------------------------------
8970
- const version = "3.2.24";
9003
+ const version = "3.2.25";
8971
9004
  /**
8972
9005
  * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
8973
9006
  * @internal