@vue/runtime-vapor 3.6.0-alpha.4 → 3.6.0-alpha.5

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.
@@ -4,7 +4,7 @@ import { Namespace, NormalizedStyle } from '@vue/shared';
4
4
 
5
5
  type NodeRef = string | Ref | ((ref: Element | VaporComponentInstance, refs: Record<string, any>) => void);
6
6
  type RefEl = Element | VaporComponentInstance;
7
- type setRefFn = (el: RefEl, ref: NodeRef, oldRef?: NodeRef, refFor?: boolean) => NodeRef | undefined;
7
+ type setRefFn = (el: RefEl, ref: NodeRef, oldRef?: NodeRef, refFor?: boolean, refKey?: string) => NodeRef | undefined;
8
8
  export declare function createTemplateRefSetter(): setRefFn;
9
9
 
10
10
  export declare class VaporFragment<T extends Block = Block> implements TransitionOptions {
@@ -18,6 +18,7 @@ export declare class VaporFragment<T extends Block = Block> implements Transitio
18
18
  remove?: (parent?: ParentNode, transitionHooks?: TransitionHooks) => void;
19
19
  hydrate?: (...args: any[]) => void;
20
20
  setRef?: (instance: VaporComponentInstance, ref: NodeRef, refFor: boolean, refKey: string | undefined) => void;
21
+ updated?: ((nodes?: Block) => void)[];
21
22
  constructor(nodes: T);
22
23
  }
23
24
  declare class ForFragment extends VaporFragment<Block[]> {
@@ -29,8 +30,9 @@ declare class DynamicFragment extends VaporFragment {
29
30
  current?: BlockFn;
30
31
  fallback?: BlockFn;
31
32
  anchorLabel?: string;
32
- inKeepAlive?: boolean;
33
- keptAliveScopes?: Map<any, EffectScope>;
33
+ getScope?: (key: any) => EffectScope | undefined;
34
+ beforeTeardown?: ((oldKey: any, nodes: Block, scope: EffectScope) => boolean)[];
35
+ beforeMount?: ((newKey: any, nodes: Block, scope: EffectScope) => void)[];
34
36
  constructor(anchorLabel?: string);
35
37
  update(render?: BlockFn, key?: any): void;
36
38
  private render;
@@ -109,6 +111,7 @@ declare class TeleportFragment extends VaporFragment {
109
111
  private rawProps?;
110
112
  private resolvedProps?;
111
113
  private rawSlots?;
114
+ isDisabled?: boolean;
112
115
  target?: ParentNode | null;
113
116
  targetAnchor?: Node | null;
114
117
  targetStart?: Node | null;
@@ -348,7 +351,7 @@ export declare function setHtml(el: TargetElement, value: any): void;
348
351
  export declare function setBlockHtml(block: Block & {
349
352
  $html?: string;
350
353
  }, value: any): void;
351
- export declare function setDynamicProps(el: any, args: any[], root?: boolean, isSVG?: boolean): void;
354
+ export declare function setDynamicProps(el: any, args: any[], isSVG?: boolean): void;
352
355
 
353
356
  export declare function on(el: Element, event: string, handler: (e: Event) => any, options?: AddEventListenerOptions & {
354
357
  effect?: boolean;
@@ -370,6 +373,8 @@ export declare function createForSlots(rawSource: Source, getSlot: (item: any, k
370
373
  export declare function getRestElement(val: any, keys: string[]): any;
371
374
  export declare function getDefaultValue(val: any, defaultVal: any): any;
372
375
 
376
+ export declare function useVaporCssVars(getter: () => Record<string, string>): void;
377
+
373
378
  export declare function createDynamicComponent(getter: () => any, rawProps?: RawProps | null, rawSlots?: RawSlots | null, isSingleRoot?: boolean, once?: boolean): VaporFragment;
374
379
 
375
380
  export declare function applyVShow(target: Block, source: () => any): void;
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @vue/runtime-vapor v3.6.0-alpha.4
2
+ * @vue/runtime-vapor v3.6.0-alpha.5
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
6
- import { isMismatchAllowed, warn, currentInstance, startMeasure, setCurrentInstance, queuePostFlushCb, queueJob, TransitionPropsValidators, leaveCbKey, isAsyncWrapper, getComponentName, baseResolveTransitionHooks, isTemplateNode, checkTransitionMode, resolveTransitionProps, useTransitionState, isKeepAlive, callWithAsyncErrorHandling, unsafeToTrustedHTML, patchStyle, xlinkNS, mergeProps, shouldSetAsProp, toClassSet, isSetEqual, warnPropMismatch, toStyleMap, vShowHidden, isMapEqual, isValidHtmlOrSvgAttribute, getAttributeMismatch, isRef, onMounted, onUpdated, onBeforeUnmount, resetShapeFlag, watch, matches, devtoolsComponentAdded, ensureRenderer, shallowRef, simpleSetCurrentInstance, renderSlot, ensureVaporSlotFallback, createVNode, shallowReactive, createInternalObject, isEmitListener, onScopeDispose, activate as activate$1, setTransitionHooks as setTransitionHooks$1, normalizeRef, isVNode, Fragment, ensureHydrationRenderer, setRef as setRef$1, deactivate as deactivate$1, baseEmit, baseNormalizePropsOptions, pushWarningContext, validateProps, popWarningContext, resolvePropValue, resolveTeleportTarget, isTeleportDisabled, isTeleportDeferred, performTransitionEnter, performTransitionLeave, getInheritedScopeIds, registerHMR, endMeasure, unregisterHMR, nextUid, EffectScope as EffectScope$1, expose, callWithErrorHandling, createAppAPI, initFeatureFlags, setDevtoolsHook, flushOnAppMount, normalizeContainer, createAsyncComponentContext, markAsyncBoundary, useAsyncComponentState, performAsyncHydrate, handleError, VueElementBase, onBeforeUpdate, hasCSSTransform, callPendingCbs, forceReflow, handleMovedChildren, baseApplyTranslation, createCanSetSetupRefChecker, resolveDynamicComponent, vShowOriginalDisplay, vModelTextInit, vModelCheckboxInit, vModelSelectInit, vModelTextUpdate, vModelCheckboxUpdate, vModelGetValue, vModelSetSelected } from '@vue/runtime-dom';
7
- import { invokeArrayFns, isArray, extend, normalizeClass, normalizeStyle, includeBooleanAttr, toDisplayString, isString, parseStringStyle, isOn, canSetValueDirectly, camelize, stringifyStyle, EMPTY_OBJ, isFunction, NO, hasOwn, isReservedProp, EMPTY_ARR, YES, getGlobalThis, isPlainObject, isObject, remove as remove$1, looseEqual } from '@vue/shared';
6
+ import { isMismatchAllowed, warn, currentInstance, startMeasure, setCurrentInstance, queuePostFlushCb, queueJob, TransitionPropsValidators, leaveCbKey, isAsyncWrapper, getComponentName, baseResolveTransitionHooks, isTemplateNode, checkTransitionMode, resolveTransitionProps, useTransitionState, callWithAsyncErrorHandling, unsafeToTrustedHTML, patchStyle, xlinkNS, mergeProps, shouldSetAsProp, toClassSet, isSetEqual, warnPropMismatch, toStyleMap, vShowHidden, isMapEqual, isValidHtmlOrSvgAttribute, getAttributeMismatch, isRef, watch, onMounted, onUpdated, onBeforeUnmount, matches, devtoolsComponentAdded, resetShapeFlag, isKeepAlive, ensureRenderer, shallowRef, simpleSetCurrentInstance, renderSlot, ensureVaporSlotFallback, createVNode, shallowReactive, createInternalObject, isEmitListener, onScopeDispose, activate as activate$1, setTransitionHooks as setTransitionHooks$1, normalizeRef, isVNode, Fragment, ensureHydrationRenderer, setRef as setRef$1, deactivate as deactivate$1, baseEmit, baseNormalizePropsOptions, pushWarningContext, validateProps, popWarningContext, resolvePropValue, resolveTeleportTarget, isTeleportDisabled, isTeleportDeferred, performTransitionEnter, performTransitionLeave, getInheritedScopeIds, registerHMR, endMeasure, unregisterHMR, nextUid, EffectScope as EffectScope$1, expose, callWithErrorHandling, createAppAPI, initFeatureFlags, setDevtoolsHook, flushOnAppMount, normalizeContainer, createAsyncComponentContext, markAsyncBoundary, useAsyncComponentState, performAsyncHydrate, handleError, VueElementBase, onBeforeUpdate, hasCSSTransform, callPendingCbs, forceReflow, handleMovedChildren, baseApplyTranslation, createCanSetSetupRefChecker, baseUseCssVars, setVarsOnNode, resolveDynamicComponent, vShowOriginalDisplay, vModelTextInit, vModelCheckboxInit, vModelSelectInit, vModelTextUpdate, vModelCheckboxUpdate, vModelGetValue, vModelSetSelected } from '@vue/runtime-dom';
7
+ import { invokeArrayFns, isArray, extend, normalizeClass, normalizeStyle, includeBooleanAttr, toDisplayString, isString, parseStringStyle, isOn, canSetValueDirectly, camelize, stringifyStyle, normalizeCssVarValue, getEscapedCssVarName, EMPTY_OBJ, isFunction, NO, hasOwn, isReservedProp, EMPTY_ARR, YES, getGlobalThis, isPlainObject, isObject, remove as remove$1, looseEqual } from '@vue/shared';
8
8
  import { ReactiveEffect, setActiveSub, EffectScope, onEffectCleanup, pauseTracking, resetTracking, onScopeDispose as onScopeDispose$1, markRaw, unref, proxyRefs, watch as watch$1, isReactive, isShallow, shallowReadArray, isReadonly, toReadonly, toReactive, shallowRef as shallowRef$1, isRef as isRef$1, traverse } from '@vue/reactivity';
9
9
 
10
10
  let insertionParent;
@@ -733,14 +733,14 @@ class DynamicFragment extends VaporFragment {
733
733
  const prevSub = setActiveSub();
734
734
  const parent = isHydrating ? null : this.anchor.parentNode;
735
735
  const transition = this.$transition;
736
- const instance = currentInstance;
737
- this.inKeepAlive = isKeepAlive(instance);
738
736
  if (this.scope) {
739
- if (this.inKeepAlive) {
740
- instance.processFragment(this);
741
- if (!this.keptAliveScopes) this.keptAliveScopes = /* @__PURE__ */ new Map();
742
- this.keptAliveScopes.set(this.current, this.scope);
743
- } else {
737
+ let preserveScope = false;
738
+ if (this.beforeTeardown) {
739
+ preserveScope = this.beforeTeardown.some(
740
+ (hook) => hook(this.current, this.nodes, this.scope)
741
+ );
742
+ }
743
+ if (!preserveScope) {
744
744
  this.scope.stop();
745
745
  }
746
746
  const mode = transition && transition.mode;
@@ -748,7 +748,7 @@ class DynamicFragment extends VaporFragment {
748
748
  applyTransitionLeaveHooks(
749
749
  this.nodes,
750
750
  transition,
751
- () => this.render(render, instance, transition, parent)
751
+ () => this.render(render, transition, parent)
752
752
  );
753
753
  parent && remove(this.nodes, parent);
754
754
  if (mode === "out-in") {
@@ -759,7 +759,7 @@ class DynamicFragment extends VaporFragment {
759
759
  parent && remove(this.nodes, parent);
760
760
  }
761
761
  }
762
- this.render(render, instance, transition, parent);
762
+ this.render(render, transition, parent);
763
763
  if (this.fallback) {
764
764
  const hasNestedFragment = isFragment(this.nodes);
765
765
  if (hasNestedFragment) {
@@ -782,24 +782,29 @@ class DynamicFragment extends VaporFragment {
782
782
  setActiveSub(prevSub);
783
783
  if (isHydrating) this.hydrate();
784
784
  }
785
- render(render, instance, transition, parent) {
785
+ render(render, transition, parent) {
786
786
  if (render) {
787
- const scope = this.inKeepAlive && this.keptAliveScopes ? this.keptAliveScopes.get(this.current) : void 0;
787
+ const scope = this.getScope && this.getScope(this.current);
788
788
  if (scope) {
789
789
  this.scope = scope;
790
- this.keptAliveScopes.delete(this.current);
791
- this.scope.resume();
792
790
  } else {
793
791
  this.scope = new EffectScope();
794
792
  }
795
793
  this.nodes = this.scope.run(render) || [];
796
- if (this.inKeepAlive) {
797
- instance.cacheFragment(this);
798
- }
799
794
  if (transition) {
800
795
  this.$transition = applyTransitionHooks(this.nodes, transition);
801
796
  }
802
- if (parent) insert(this.nodes, parent, this.anchor);
797
+ if (this.beforeMount) {
798
+ this.beforeMount.forEach(
799
+ (hook) => hook(this.current, this.nodes, this.scope)
800
+ );
801
+ }
802
+ if (parent) {
803
+ insert(this.nodes, parent, this.anchor);
804
+ if (this.anchor.isConnected && this.updated) {
805
+ this.updated.forEach((hook) => hook(this.nodes));
806
+ }
807
+ }
803
808
  } else {
804
809
  this.scope = void 0;
805
810
  this.nodes = [];
@@ -837,6 +842,9 @@ function findInvalidFragment(fragment) {
837
842
  function isFragment(val) {
838
843
  return val instanceof VaporFragment;
839
844
  }
845
+ function isDynamicFragment(val) {
846
+ return val instanceof DynamicFragment;
847
+ }
840
848
 
841
849
  function addEventListener(el, event, handler, options) {
842
850
  el.addEventListener(event, handler, options);
@@ -1031,14 +1039,29 @@ function setClassIncremental(el, value) {
1031
1039
  }
1032
1040
  }
1033
1041
  }
1042
+ function shouldDeferCheckStyleMismatch(el) {
1043
+ return !!(process.env.NODE_ENV !== "production") && (!!currentInstance.getCssVars || Object.values(el.style).some((v) => v.startsWith("--")));
1044
+ }
1034
1045
  function setStyle(el, value) {
1035
1046
  if (el.$root) {
1036
1047
  setStyleIncremental(el, value);
1037
1048
  } else {
1038
1049
  const normalizedValue = normalizeStyle(value);
1039
- if ((!!(process.env.NODE_ENV !== "production") || __VUE_PROD_HYDRATION_MISMATCH_DETAILS__) && isHydrating && !styleHasMismatch(el, value, normalizedValue, false)) {
1040
- el.$sty = normalizedValue;
1041
- return;
1050
+ if ((!!(process.env.NODE_ENV !== "production") || __VUE_PROD_HYDRATION_MISMATCH_DETAILS__) && isHydrating) {
1051
+ if (shouldDeferCheckStyleMismatch(el)) {
1052
+ const instance = currentInstance;
1053
+ queuePostFlushCb(() => {
1054
+ if (!styleHasMismatch(el, value, normalizedValue, false, instance)) {
1055
+ el.$sty = normalizedValue;
1056
+ return;
1057
+ }
1058
+ patchStyle(el, el.$sty, el.$sty = normalizedValue);
1059
+ });
1060
+ return;
1061
+ } else if (!styleHasMismatch(el, value, normalizedValue, false)) {
1062
+ el.$sty = normalizedValue;
1063
+ return;
1064
+ }
1042
1065
  }
1043
1066
  patchStyle(el, el.$sty, el.$sty = normalizedValue);
1044
1067
  }
@@ -1046,9 +1069,21 @@ function setStyle(el, value) {
1046
1069
  function setStyleIncremental(el, value) {
1047
1070
  const cacheKey = `$styi${isApplyingFallthroughProps ? "$" : ""}`;
1048
1071
  const normalizedValue = isString(value) ? parseStringStyle(value) : normalizeStyle(value);
1049
- if ((!!(process.env.NODE_ENV !== "production") || __VUE_PROD_HYDRATION_MISMATCH_DETAILS__) && isHydrating && !styleHasMismatch(el, value, normalizedValue, true)) {
1050
- el[cacheKey] = normalizedValue;
1051
- return;
1072
+ if ((!!(process.env.NODE_ENV !== "production") || __VUE_PROD_HYDRATION_MISMATCH_DETAILS__) && isHydrating) {
1073
+ if (shouldDeferCheckStyleMismatch(el)) {
1074
+ const instance = currentInstance;
1075
+ queuePostFlushCb(() => {
1076
+ if (!styleHasMismatch(el, value, normalizedValue, true, instance)) {
1077
+ el[cacheKey] = normalizedValue;
1078
+ return;
1079
+ }
1080
+ patchStyle(el, el[cacheKey], el[cacheKey] = normalizedValue);
1081
+ });
1082
+ return;
1083
+ } else if (!styleHasMismatch(el, value, normalizedValue, true)) {
1084
+ el[cacheKey] = normalizedValue;
1085
+ return;
1086
+ }
1052
1087
  }
1053
1088
  patchStyle(el, el[cacheKey], el[cacheKey] = normalizedValue);
1054
1089
  }
@@ -1169,11 +1204,10 @@ function setHtmlToBlock(block, value) {
1169
1204
  setHtmlToBlock(block.nodes, value);
1170
1205
  }
1171
1206
  }
1172
- function setDynamicProps(el, args, root, isSVG) {
1207
+ function setDynamicProps(el, args, isSVG) {
1173
1208
  const props = args.length > 1 ? mergeProps(...args) : args[0];
1174
1209
  const cacheKey = `$dprops${isApplyingFallthroughProps ? "$" : ""}`;
1175
1210
  const prevKeys = el[cacheKey];
1176
- if (root) el.$root = root;
1177
1211
  if (prevKeys) {
1178
1212
  for (const key of prevKeys) {
1179
1213
  if (!(key in props)) {
@@ -1249,7 +1283,7 @@ function classHasMismatch(el, expected, isIncremental) {
1249
1283
  }
1250
1284
  return false;
1251
1285
  }
1252
- function styleHasMismatch(el, value, normalizedValue, isIncremental) {
1286
+ function styleHasMismatch(el, value, normalizedValue, isIncremental, instance = currentInstance) {
1253
1287
  const actual = el.getAttribute("style");
1254
1288
  const actualStyleMap = toStyleMap(actual || "");
1255
1289
  const expected = isString(value) ? value : stringifyStyle(normalizedValue);
@@ -1257,6 +1291,9 @@ function styleHasMismatch(el, value, normalizedValue, isIncremental) {
1257
1291
  if (el[vShowHidden]) {
1258
1292
  expectedStyleMap.set("display", "none");
1259
1293
  }
1294
+ if (instance) {
1295
+ resolveCssVars(instance, el, expectedStyleMap);
1296
+ }
1260
1297
  let hasMismatch = false;
1261
1298
  if (isIncremental) {
1262
1299
  if (expected) {
@@ -1274,6 +1311,24 @@ function styleHasMismatch(el, value, normalizedValue, isIncremental) {
1274
1311
  }
1275
1312
  return false;
1276
1313
  }
1314
+ function resolveCssVars(instance, block, expectedMap) {
1315
+ if (!instance.isMounted) return;
1316
+ const rootBlocks = normalizeBlock(instance);
1317
+ if (instance.getCssVars && normalizeBlock(block).every((b) => rootBlocks.includes(b))) {
1318
+ const cssVars = instance.getCssVars();
1319
+ for (const key in cssVars) {
1320
+ const value = normalizeCssVarValue(cssVars[key]);
1321
+ expectedMap.set(`--${getEscapedCssVarName(key, false)}`, value);
1322
+ }
1323
+ }
1324
+ if (normalizeBlock(block).every((b) => rootBlocks.includes(b)) && instance.parent) {
1325
+ resolveCssVars(
1326
+ instance.parent,
1327
+ instance.block,
1328
+ expectedMap
1329
+ );
1330
+ }
1331
+ }
1277
1332
  function attributeHasMismatch(el, key, value) {
1278
1333
  if (isValidHtmlOrSvgAttribute(el, key)) {
1279
1334
  const { actual, expected } = getAttributeMismatch(el, key, value);
@@ -1508,21 +1563,22 @@ const VaporKeepAliveImpl = defineVaporComponent({
1508
1563
  const cache = /* @__PURE__ */ new Map();
1509
1564
  const keys = /* @__PURE__ */ new Set();
1510
1565
  const storageContainer = createElement("div");
1566
+ const keptAliveScopes = /* @__PURE__ */ new Map();
1511
1567
  let current;
1512
1568
  if (!!(process.env.NODE_ENV !== "production") || __VUE_PROD_DEVTOOLS__) {
1513
1569
  keepAliveInstance.__v_cache = cache;
1514
1570
  }
1515
- function shouldCache(instance) {
1516
- if (isAsyncWrapper(instance) && !instance.type.__asyncResolved) {
1517
- return false;
1518
- }
1519
- const { include, exclude } = props;
1520
- const name = getComponentName(
1521
- isAsyncWrapper(instance) ? instance.type.__asyncResolved : instance.type
1522
- );
1523
- return !(include && (!name || !matches(include, name)) || exclude && name && matches(exclude, name));
1524
- }
1525
- function innerCacheBlock(key, instance) {
1571
+ keepAliveInstance.getStorageContainer = () => storageContainer;
1572
+ keepAliveInstance.getCachedComponent = (comp) => cache.get(comp);
1573
+ keepAliveInstance.activate = (instance, parentNode, anchor) => {
1574
+ current = instance;
1575
+ activate(instance, parentNode, anchor);
1576
+ };
1577
+ keepAliveInstance.deactivate = (instance) => {
1578
+ current = void 0;
1579
+ deactivate(instance, storageContainer);
1580
+ };
1581
+ const innerCacheBlock = (key, instance) => {
1526
1582
  const { max } = props;
1527
1583
  if (cache.has(key)) {
1528
1584
  keys.delete(key);
@@ -1535,116 +1591,49 @@ const VaporKeepAliveImpl = defineVaporComponent({
1535
1591
  }
1536
1592
  cache.set(key, instance);
1537
1593
  current = instance;
1538
- }
1539
- function cacheBlock() {
1540
- const block = keepAliveInstance.block;
1541
- const innerBlock = getInnerBlock(block);
1542
- if (!innerBlock || !shouldCache(innerBlock)) return;
1543
- let toCache;
1544
- let key;
1545
- let frag;
1546
- if (isFragment(block) && (frag = findInteropFragment(block))) {
1547
- toCache = frag;
1548
- key = frag.vnode.type;
1549
- } else {
1550
- toCache = innerBlock;
1551
- key = innerBlock.type;
1552
- }
1553
- innerCacheBlock(key, toCache);
1554
- }
1555
- onMounted(cacheBlock);
1556
- onUpdated(cacheBlock);
1557
- onBeforeUnmount(() => {
1558
- cache.forEach((cached, key) => {
1559
- const instance = getInstanceFromCache(cached);
1560
- if (!instance) return;
1561
- resetCachedShapeFlag(cached);
1562
- cache.delete(key);
1563
- if (current) {
1564
- const currentKey = isVaporComponent(current) ? current.type : current.vnode.type;
1565
- if (currentKey === key) {
1566
- const da = instance.da;
1567
- da && queuePostFlushCb(da);
1568
- return;
1569
- }
1570
- }
1571
- remove(cached, storageContainer);
1572
- });
1573
- });
1574
- keepAliveInstance.getStorageContainer = () => storageContainer;
1575
- keepAliveInstance.getCachedComponent = (comp) => {
1576
- return cache.get(comp);
1577
1594
  };
1578
- keepAliveInstance.cacheComponent = (instance) => {
1579
- if (!shouldCache(instance)) return;
1580
- instance.shapeFlag |= 256;
1581
- innerCacheBlock(instance.type, instance);
1595
+ const cacheBlock = () => {
1596
+ const block = keepAliveInstance.block;
1597
+ const [innerBlock, interop] = getInnerBlock(block);
1598
+ if (!innerBlock || !shouldCache(innerBlock, props, interop)) return;
1599
+ innerCacheBlock(
1600
+ interop ? innerBlock.vnode.type : innerBlock.type,
1601
+ innerBlock
1602
+ );
1582
1603
  };
1583
- keepAliveInstance.processFragment = (frag) => {
1584
- const innerBlock = getInnerBlock(frag.nodes);
1585
- if (!innerBlock) return;
1586
- const fragment = findInteropFragment(frag.nodes);
1587
- if (fragment) {
1588
- if (cache.has(fragment.vnode.type)) {
1589
- fragment.vnode.shapeFlag |= 512;
1604
+ const processFragment = (frag) => {
1605
+ const [innerBlock, interop] = getInnerBlock(frag.nodes);
1606
+ if (!innerBlock && !shouldCache(innerBlock, props, interop)) return;
1607
+ if (interop) {
1608
+ if (cache.has(innerBlock.vnode.type)) {
1609
+ innerBlock.vnode.shapeFlag |= 512;
1590
1610
  }
1591
- if (shouldCache(innerBlock)) {
1592
- fragment.vnode.shapeFlag |= 256;
1611
+ if (shouldCache(innerBlock, props, true)) {
1612
+ innerBlock.vnode.shapeFlag |= 256;
1593
1613
  }
1594
1614
  } else {
1595
1615
  if (cache.has(innerBlock.type)) {
1596
1616
  innerBlock.shapeFlag |= 512;
1597
1617
  }
1598
- if (shouldCache(innerBlock)) {
1618
+ if (shouldCache(innerBlock, props)) {
1599
1619
  innerBlock.shapeFlag |= 256;
1600
1620
  }
1601
1621
  }
1602
1622
  };
1603
- keepAliveInstance.cacheFragment = (fragment) => {
1604
- const innerBlock = getInnerBlock(fragment.nodes);
1605
- if (!innerBlock || !shouldCache(innerBlock)) return;
1606
- let toCache;
1623
+ const cacheFragment = (fragment) => {
1624
+ const [innerBlock, interop] = getInnerBlock(fragment.nodes);
1625
+ if (!innerBlock || !shouldCache(innerBlock, props, interop)) return;
1607
1626
  let key;
1608
- const frag = findInteropFragment(fragment);
1609
- if (frag) {
1610
- frag.vnode.shapeFlag |= 256;
1611
- toCache = frag;
1612
- key = frag.vnode.type;
1627
+ if (interop) {
1628
+ innerBlock.vnode.shapeFlag |= 256;
1629
+ key = innerBlock.vnode.type;
1613
1630
  } else {
1614
1631
  innerBlock.shapeFlag |= 256;
1615
- toCache = innerBlock;
1616
1632
  key = innerBlock.type;
1617
1633
  }
1618
- innerCacheBlock(key, toCache);
1634
+ innerCacheBlock(key, innerBlock);
1619
1635
  };
1620
- keepAliveInstance.activate = (instance, parentNode, anchor) => {
1621
- current = instance;
1622
- activate(instance, parentNode, anchor);
1623
- };
1624
- keepAliveInstance.deactivate = (instance) => {
1625
- current = void 0;
1626
- deactivate(instance, storageContainer);
1627
- };
1628
- function resetCachedShapeFlag(cached) {
1629
- if (isVaporComponent(cached)) {
1630
- resetShapeFlag(cached);
1631
- } else {
1632
- resetShapeFlag(cached.vnode);
1633
- }
1634
- }
1635
- let children = slots.default();
1636
- if (isArray(children) && children.length > 1) {
1637
- if (!!(process.env.NODE_ENV !== "production")) {
1638
- warn(`KeepAlive should contain exactly one component child.`);
1639
- }
1640
- return children;
1641
- }
1642
- if (isVaporComponent(children)) {
1643
- children.shapeFlag |= 256;
1644
- } else if (isInteropFragment(children)) {
1645
- children.vnode.shapeFlag |= 256;
1646
- }
1647
- function pruneCache(filter) {
1636
+ const pruneCache = (filter) => {
1648
1637
  cache.forEach((cached, key) => {
1649
1638
  const instance = getInstanceFromCache(cached);
1650
1639
  if (!instance) return;
@@ -1653,8 +1642,8 @@ const VaporKeepAliveImpl = defineVaporComponent({
1653
1642
  pruneCacheEntry(key);
1654
1643
  }
1655
1644
  });
1656
- }
1657
- function pruneCacheEntry(key) {
1645
+ };
1646
+ const pruneCacheEntry = (key) => {
1658
1647
  const cached = cache.get(key);
1659
1648
  resetCachedShapeFlag(cached);
1660
1649
  if (cached !== current) {
@@ -1662,7 +1651,7 @@ const VaporKeepAliveImpl = defineVaporComponent({
1662
1651
  }
1663
1652
  cache.delete(key);
1664
1653
  keys.delete(key);
1665
- }
1654
+ };
1666
1655
  watch(
1667
1656
  () => [props.include, props.exclude],
1668
1657
  ([include, exclude]) => {
@@ -1672,29 +1661,103 @@ const VaporKeepAliveImpl = defineVaporComponent({
1672
1661
  // prune post-render after `current` has been updated
1673
1662
  { flush: "post", deep: true }
1674
1663
  );
1664
+ onMounted(cacheBlock);
1665
+ onUpdated(cacheBlock);
1666
+ onBeforeUnmount(() => {
1667
+ cache.forEach((cached, key) => {
1668
+ const instance = getInstanceFromCache(cached);
1669
+ if (!instance) return;
1670
+ resetCachedShapeFlag(cached);
1671
+ cache.delete(key);
1672
+ if (current) {
1673
+ const currentKey = isVaporComponent(current) ? current.type : current.vnode.type;
1674
+ if (currentKey === key) {
1675
+ const da = instance.da;
1676
+ da && queuePostFlushCb(da);
1677
+ return;
1678
+ }
1679
+ }
1680
+ remove(cached, storageContainer);
1681
+ });
1682
+ keptAliveScopes.forEach((scope) => scope.stop());
1683
+ keptAliveScopes.clear();
1684
+ });
1685
+ let children = slots.default();
1686
+ if (isArray(children)) {
1687
+ children = children.filter((child) => !(child instanceof Comment));
1688
+ if (children.length > 1) {
1689
+ if (!!(process.env.NODE_ENV !== "production")) {
1690
+ warn(`KeepAlive should contain exactly one component child.`);
1691
+ }
1692
+ return children;
1693
+ }
1694
+ }
1695
+ const injectKeepAliveHooks = (frag) => {
1696
+ (frag.beforeTeardown || (frag.beforeTeardown = [])).push(
1697
+ (oldKey, nodes, scope) => {
1698
+ processFragment(frag);
1699
+ keptAliveScopes.set(oldKey, scope);
1700
+ return true;
1701
+ }
1702
+ );
1703
+ (frag.beforeMount || (frag.beforeMount = [])).push(
1704
+ () => cacheFragment(frag)
1705
+ );
1706
+ frag.getScope = (key) => {
1707
+ const scope = keptAliveScopes.get(key);
1708
+ if (scope) {
1709
+ keptAliveScopes.delete(key);
1710
+ return scope;
1711
+ }
1712
+ };
1713
+ };
1714
+ if (isVaporComponent(children)) {
1715
+ children.shapeFlag |= 256;
1716
+ if (isAsyncWrapper(children)) {
1717
+ injectKeepAliveHooks(children.block);
1718
+ }
1719
+ } else if (isInteropFragment(children)) {
1720
+ children.vnode.shapeFlag |= 256;
1721
+ } else if (isDynamicFragment(children)) {
1722
+ processFragment(children);
1723
+ injectKeepAliveHooks(children);
1724
+ if (isVaporComponent(children.nodes) && isAsyncWrapper(children.nodes)) {
1725
+ injectKeepAliveHooks(children.nodes.block);
1726
+ }
1727
+ }
1675
1728
  return children;
1676
1729
  }
1677
1730
  });
1731
+ const shouldCache = (block, props, interop = false) => {
1732
+ const isAsync = !interop && isAsyncWrapper(block);
1733
+ const type = interop ? block.vnode.type : block.type;
1734
+ if (isAsync && !type.__asyncResolved) {
1735
+ return true;
1736
+ }
1737
+ const { include, exclude } = props;
1738
+ const name = getComponentName(isAsync ? type.__asyncResolved : type);
1739
+ return !(include && (!name || !matches(include, name)) || exclude && name && matches(exclude, name));
1740
+ };
1741
+ const resetCachedShapeFlag = (cached) => {
1742
+ if (isVaporComponent(cached)) {
1743
+ resetShapeFlag(cached);
1744
+ } else {
1745
+ resetShapeFlag(cached.vnode);
1746
+ }
1747
+ };
1678
1748
  function getInnerBlock(block) {
1679
1749
  if (isVaporComponent(block)) {
1680
- return block;
1750
+ return [block, false];
1681
1751
  } else if (isInteropFragment(block)) {
1682
- return block.vnode;
1752
+ return [block, true];
1683
1753
  } else if (isFragment(block)) {
1684
1754
  return getInnerBlock(block.nodes);
1685
1755
  }
1756
+ return [void 0, false];
1686
1757
  }
1687
1758
  function isInteropFragment(block) {
1688
1759
  return !!(isFragment(block) && block.vnode);
1689
1760
  }
1690
- function findInteropFragment(block) {
1691
- if (isInteropFragment(block)) {
1692
- return block;
1693
- }
1694
- if (isFragment(block)) {
1695
- return findInteropFragment(block.nodes);
1696
- }
1697
- }
1698
1761
  function getInstanceFromCache(cached) {
1699
1762
  if (isVaporComponent(cached)) {
1700
1763
  return cached;
@@ -1976,6 +2039,7 @@ function createVDOMComponent(internals, component, parentComponent, rawProps, ra
1976
2039
  simpleSetCurrentInstance(prev);
1977
2040
  }
1978
2041
  frag.nodes = vnode.el;
2042
+ if (isMounted && frag.updated) frag.updated.forEach((m) => m());
1979
2043
  };
1980
2044
  frag.remove = unmount;
1981
2045
  frag.setRef = (instance, ref, refFor, refKey) => {
@@ -2017,6 +2081,7 @@ function renderVDOMSlot(internals, slotsRef, name, props, parentComponent, fallb
2017
2081
  internals.um(oldVNode, parentComponent, null);
2018
2082
  }
2019
2083
  };
2084
+ if (isMounted && frag.updated) frag.updated.forEach((m) => m());
2020
2085
  };
2021
2086
  const render = (parentNode, anchor) => {
2022
2087
  renderEffect(() => {
@@ -2559,6 +2624,7 @@ class TeleportFragment extends VaporFragment {
2559
2624
  rawPropsProxyHandlers
2560
2625
  )
2561
2626
  );
2627
+ this.isDisabled = isTeleportDisabled(this.resolvedProps);
2562
2628
  this.handlePropsUpdate();
2563
2629
  });
2564
2630
  if (!isHydrating) {
@@ -2574,8 +2640,21 @@ class TeleportFragment extends VaporFragment {
2574
2640
  this.rawSlots.default && this.rawSlots.default()
2575
2641
  );
2576
2642
  });
2643
+ const nodes = this.nodes;
2644
+ if (this.parentComponent && this.parentComponent.ut) {
2645
+ if (isFragment(nodes)) {
2646
+ (nodes.updated || (nodes.updated = [])).push(() => updateCssVars(this));
2647
+ } else if (isArray(nodes)) {
2648
+ nodes.forEach((node) => {
2649
+ if (isFragment(node)) {
2650
+ (node.updated || (node.updated = [])).push(
2651
+ () => updateCssVars(this)
2652
+ );
2653
+ }
2654
+ });
2655
+ }
2656
+ }
2577
2657
  if (!!(process.env.NODE_ENV !== "production")) {
2578
- const nodes = this.nodes;
2579
2658
  if (isVaporComponent(nodes)) {
2580
2659
  nodes.parentTeleport = this;
2581
2660
  } else if (isArray(nodes)) {
@@ -2623,6 +2702,7 @@ class TeleportFragment extends VaporFragment {
2623
2702
  (this.parentComponent.ce._teleportTargets || (this.parentComponent.ce._teleportTargets = /* @__PURE__ */ new Set())).add(target);
2624
2703
  }
2625
2704
  mount(target, this.targetAnchor);
2705
+ updateCssVars(this);
2626
2706
  } else if (!!(process.env.NODE_ENV !== "production")) {
2627
2707
  warn(
2628
2708
  `Invalid Teleport target on ${this.targetAnchor ? "update" : "mount"}:`,
@@ -2631,8 +2711,9 @@ class TeleportFragment extends VaporFragment {
2631
2711
  );
2632
2712
  }
2633
2713
  };
2634
- if (isTeleportDisabled(this.resolvedProps)) {
2714
+ if (this.isDisabled) {
2635
2715
  mount(this.parent, this.anchor);
2716
+ updateCssVars(this);
2636
2717
  } else {
2637
2718
  if (isTeleportDeferred(this.resolvedProps) || // force defer when the parent is not connected to the DOM,
2638
2719
  // typically due to an early insertion caused by setInsertionState.
@@ -2683,6 +2764,25 @@ function locateTeleportEndAnchor(node = currentHydrationNode) {
2683
2764
  }
2684
2765
  return null;
2685
2766
  }
2767
+ function updateCssVars(frag) {
2768
+ const ctx = frag.parentComponent;
2769
+ if (ctx && ctx.ut) {
2770
+ let node, anchor;
2771
+ if (frag.isDisabled) {
2772
+ node = frag.placeholder;
2773
+ anchor = frag.anchor;
2774
+ } else {
2775
+ node = frag.targetStart;
2776
+ anchor = frag.targetAnchor;
2777
+ }
2778
+ while (node && node !== anchor) {
2779
+ if (node.nodeType === 1)
2780
+ node.setAttribute("data-v-owner", String(ctx.uid));
2781
+ node = node.nextSibling;
2782
+ }
2783
+ ctx.ut();
2784
+ }
2785
+ }
2686
2786
 
2687
2787
  function isBlock(val) {
2688
2788
  return val instanceof Node || isArray(val) || isVaporComponent(val) || isFragment(val);
@@ -2765,11 +2865,6 @@ function remove(block, parent) {
2765
2865
  if (block.anchor) remove(block.anchor, parent);
2766
2866
  if (block.scope) {
2767
2867
  block.scope.stop();
2768
- const scopes = block.keptAliveScopes;
2769
- if (scopes) {
2770
- scopes.forEach((scope) => scope.stop());
2771
- scopes.clear();
2772
- }
2773
2868
  }
2774
2869
  }
2775
2870
  }
@@ -2881,6 +2976,10 @@ function hmrRerender(instance) {
2881
2976
  insert(instance.block, parent, anchor);
2882
2977
  }
2883
2978
  function hmrReload(instance, newComp) {
2979
+ if (instance.parent && isKeepAlive(instance.parent)) {
2980
+ instance.parent.hmrRerender();
2981
+ return;
2982
+ }
2884
2983
  const normalized = normalizeBlock(instance.block);
2885
2984
  const parent = normalized[0].parentNode;
2886
2985
  const anchor = normalized[normalized.length - 1].nextSibling;
@@ -2995,13 +3094,11 @@ function createComponent(component, rawProps, rawSlots, isSingleRoot, once, appC
2995
3094
  parentInstance
2996
3095
  );
2997
3096
  const prevSlotConsumer = setCurrentSlotConsumer(null);
2998
- if (!!(process.env.NODE_ENV !== "production") && component.__hmrId) {
3097
+ if (!!(process.env.NODE_ENV !== "production")) {
2999
3098
  registerHMR(instance);
3000
3099
  instance.isSingleRoot = isSingleRoot;
3001
3100
  instance.hmrRerender = hmrRerender.bind(null, instance);
3002
3101
  instance.hmrReload = hmrReload.bind(null, instance);
3003
- }
3004
- if (!!(process.env.NODE_ENV !== "production")) {
3005
3102
  pushWarningContext(instance);
3006
3103
  startMeasure(instance, `init`);
3007
3104
  instance.propsOptions = normalizePropsOptions(component);
@@ -3311,6 +3408,22 @@ function getRootElement(block) {
3311
3408
  return nodes;
3312
3409
  }
3313
3410
  }
3411
+ if (isArray(block)) {
3412
+ let singleRoot;
3413
+ let hasComment = false;
3414
+ for (const b of block) {
3415
+ if (b instanceof Comment) {
3416
+ hasComment = true;
3417
+ continue;
3418
+ }
3419
+ const thisRoot = getRootElement(b);
3420
+ if (!thisRoot || singleRoot) {
3421
+ return;
3422
+ }
3423
+ singleRoot = thisRoot;
3424
+ }
3425
+ return hasComment ? singleRoot : void 0;
3426
+ }
3314
3427
  }
3315
3428
 
3316
3429
  let _createApp;
@@ -3500,19 +3613,17 @@ function defineVaporAsyncComponent(source) {
3500
3613
  });
3501
3614
  }
3502
3615
  function createInnerComp(comp, parent, frag) {
3503
- const { rawProps, rawSlots, isSingleRoot, appContext, $transition } = parent;
3616
+ const { rawProps, rawSlots, appContext, $transition } = parent;
3504
3617
  const instance = createComponent(
3505
3618
  comp,
3506
3619
  rawProps,
3507
3620
  rawSlots,
3508
- isSingleRoot,
3621
+ // rawProps is shared and already contains fallthrough attrs.
3622
+ // so isSingleRoot should be undefined
3623
+ void 0,
3509
3624
  void 0,
3510
3625
  appContext
3511
3626
  );
3512
- if (parent.parent && isKeepAlive(parent.parent)) {
3513
- parent.parent.cacheComponent(instance);
3514
- parent.parent.cacheComponent(parent);
3515
- }
3516
3627
  if ($transition) setTransitionHooks(instance, $transition);
3517
3628
  frag && frag.setRef && frag.setRef(instance);
3518
3629
  return instance;
@@ -3810,9 +3921,7 @@ const VaporTransitionGroup = decorate({
3810
3921
  }
3811
3922
  return container;
3812
3923
  } else {
3813
- const frag = !!(process.env.NODE_ENV !== "production") ? new DynamicFragment("transition-group") : new DynamicFragment();
3814
- renderEffect(() => frag.update(() => slottedBlock));
3815
- return frag;
3924
+ return slottedBlock;
3816
3925
  }
3817
3926
  }
3818
3927
  });
@@ -3918,7 +4027,7 @@ const createFor = (src, renderItem, getKey, flags = 0, setup) => {
3918
4027
  newBlocks = new Array(newLength);
3919
4028
  let isFallback = false;
3920
4029
  const transitionHooks = frag.$transition;
3921
- if (transitionHooks && transitionHooks.group) {
4030
+ if (transitionHooks && transitionHooks.group && isMounted) {
3922
4031
  triggerTransitionGroupUpdate(transitionHooks);
3923
4032
  }
3924
4033
  const prevSub = setActiveSub();
@@ -4136,6 +4245,7 @@ const createFor = (src, renderItem, getKey, flags = 0, setup) => {
4136
4245
  } else {
4137
4246
  oldBlocks = [];
4138
4247
  }
4248
+ if (isMounted && frag.updated) frag.updated.forEach((m) => m());
4139
4249
  setActiveSub(prevSub);
4140
4250
  };
4141
4251
  const needKey = renderItem.length > 1;
@@ -4454,6 +4564,45 @@ const getRefValue = (el) => {
4454
4564
  return el;
4455
4565
  };
4456
4566
 
4567
+ function useVaporCssVars(getter) {
4568
+ const instance = currentInstance;
4569
+ baseUseCssVars(
4570
+ instance,
4571
+ () => resolveParentNode(instance.block),
4572
+ getter,
4573
+ (vars) => setVars(instance, vars)
4574
+ );
4575
+ }
4576
+ function resolveParentNode(block) {
4577
+ if (block instanceof Node) {
4578
+ return block.parentNode;
4579
+ } else if (isArray(block)) {
4580
+ return resolveParentNode(block[0]);
4581
+ } else if (isVaporComponent(block)) {
4582
+ return resolveParentNode(block.block);
4583
+ } else {
4584
+ return resolveParentNode(block.nodes);
4585
+ }
4586
+ }
4587
+ function setVars(instance, vars) {
4588
+ if (instance.ce) {
4589
+ setVarsOnNode(instance.ce, vars);
4590
+ } else {
4591
+ setVarsOnBlock(instance.block, vars);
4592
+ }
4593
+ }
4594
+ function setVarsOnBlock(block, vars) {
4595
+ if (block instanceof Node) {
4596
+ setVarsOnNode(block, vars);
4597
+ } else if (isArray(block)) {
4598
+ block.forEach((child) => setVarsOnBlock(child, vars));
4599
+ } else if (isVaporComponent(block)) {
4600
+ setVarsOnBlock(block.block, vars);
4601
+ } else {
4602
+ setVarsOnBlock(block.nodes, vars);
4603
+ }
4604
+ }
4605
+
4457
4606
  function createDynamicComponent(getter, rawProps, rawSlots, isSingleRoot, once) {
4458
4607
  const _insertionParent = insertionParent;
4459
4608
  const _insertionAnchor = insertionAnchor;
@@ -4511,7 +4660,7 @@ function applyVShow(target, source) {
4511
4660
  }
4512
4661
  function setDisplay(target, value) {
4513
4662
  if (isVaporComponent(target)) {
4514
- return setDisplay(target, value);
4663
+ return setDisplay(target.block, value);
4515
4664
  }
4516
4665
  if (isArray(target)) {
4517
4666
  if (target.length === 0) return;
@@ -4639,4 +4788,4 @@ function withVaporDirectives(node, dirs) {
4639
4788
  }
4640
4789
  }
4641
4790
 
4642
- export { VaporFragment, VaporKeepAliveImpl as VaporKeepAlive, VaporTeleportImpl as VaporTeleport, VaporTransition, VaporTransitionGroup, applyCheckboxModel, applyDynamicModel, applyRadioModel, applySelectModel, applyTextModel, applyVShow, child, createComponent, createComponentWithFallback, createDynamicComponent, createFor, createForSlots, createIf, createInvoker, createKeyedFragment, createPlainElement, createSlot, createTemplateRefSetter, createTextNode, createVaporApp, createVaporSSRApp, defineVaporAsyncComponent, defineVaporComponent, defineVaporCustomElement, defineVaporSSRCustomElement, delegate, delegateEvents, getDefaultValue, getRestElement, insert, isFragment, isVaporComponent, next, nthChild, on, prepend, remove, renderEffect, setAttr, setBlockHtml, setBlockText, setClass, setDOMProp, setDynamicEvents, setDynamicProps, setElementText, setHtml, setInsertionState, setProp, setStyle, setText, setValue, template, txt, vaporInteropPlugin, withVaporCtx, withVaporDirectives };
4791
+ export { VaporFragment, VaporKeepAliveImpl as VaporKeepAlive, VaporTeleportImpl as VaporTeleport, VaporTransition, VaporTransitionGroup, applyCheckboxModel, applyDynamicModel, applyRadioModel, applySelectModel, applyTextModel, applyVShow, child, createComponent, createComponentWithFallback, createDynamicComponent, createFor, createForSlots, createIf, createInvoker, createKeyedFragment, createPlainElement, createSlot, createTemplateRefSetter, createTextNode, createVaporApp, createVaporSSRApp, defineVaporAsyncComponent, defineVaporComponent, defineVaporCustomElement, defineVaporSSRCustomElement, delegate, delegateEvents, getDefaultValue, getRestElement, insert, isFragment, isVaporComponent, next, nthChild, on, prepend, remove, renderEffect, setAttr, setBlockHtml, setBlockText, setClass, setDOMProp, setDynamicEvents, setDynamicProps, setElementText, setHtml, setInsertionState, setProp, setStyle, setText, setValue, template, txt, useVaporCssVars, vaporInteropPlugin, withVaporCtx, withVaporDirectives };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/runtime-vapor",
3
- "version": "3.6.0-alpha.4",
3
+ "version": "3.6.0-alpha.5",
4
4
  "description": "@vue/runtime-vapor",
5
5
  "main": "index.js",
6
6
  "module": "dist/runtime-vapor.esm-bundler.js",
@@ -38,10 +38,10 @@
38
38
  },
39
39
  "homepage": "https://github.com/vuejs/core/tree/dev/packages/runtime-vapor#readme",
40
40
  "dependencies": {
41
- "@vue/reactivity": "3.6.0-alpha.4",
42
- "@vue/shared": "3.6.0-alpha.4"
41
+ "@vue/shared": "3.6.0-alpha.5",
42
+ "@vue/reactivity": "3.6.0-alpha.5"
43
43
  },
44
44
  "peerDependencies": {
45
- "@vue/runtime-dom": "3.6.0-alpha.4"
45
+ "@vue/runtime-dom": "3.6.0-alpha.5"
46
46
  }
47
47
  }