@vue/runtime-dom 3.6.0-alpha.3 → 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.
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @vue/runtime-dom v3.6.0-alpha.3
2
+ * @vue/runtime-dom v3.6.0-alpha.5
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
6
- import { warn, BaseTransitionPropsValidators, assertNumber, h, BaseTransition, getCurrentInstance, onBeforeUpdate, queuePostFlushCb, onMounted, watch, onUnmounted, Fragment, Static, camelize, callWithAsyncErrorHandling, defineComponent, nextTick, unref, createVNode, useTransitionState, onUpdated, toRaw, getTransitionRawChildren, setTransitionHooks, resolveTransitionHooks, Text, createRenderer, createHydrationRenderer, isRuntimeOnly } from '@vue/runtime-core';
6
+ import { warn, BaseTransitionPropsValidators, assertNumber, h, BaseTransition, getCurrentInstance, onBeforeUpdate, queuePostFlushCb, onMounted, watch, onUnmounted, Fragment, Static, camelize, callWithAsyncErrorHandling, defineComponent, useInstanceOption, createVNode, nextTick, unref, useTransitionState, onUpdated, toRaw, getTransitionRawChildren, setTransitionHooks, resolveTransitionHooks, Text, createRenderer, createHydrationRenderer, isRuntimeOnly } from '@vue/runtime-core';
7
7
  export * from '@vue/runtime-core';
8
- import { extend, isObject, isArray, toNumber, NOOP, normalizeCssVarValue, isString, hyphenate, capitalize, isSpecialBooleanAttr, includeBooleanAttr, isSymbol, canSetValueDirectly, isFunction, isNativeOn, shouldSetAsAttr, isOn, isModelListener, camelize as camelize$1, isPlainObject, hasOwn, EMPTY_OBJ, looseEqual, looseToNumber, looseIndexOf, isSet, invokeArrayFns, isHTMLTag, isSVGTag, isMathMLTag } from '@vue/shared';
8
+ import { extend, isObject, isArray, toNumber, NOOP, normalizeCssVarValue, isString, hyphenate, capitalize, isSpecialBooleanAttr, includeBooleanAttr, isSymbol, canSetValueDirectly, isFunction, isOn, isModelListener, camelize as camelize$1, isNativeOn, shouldSetAsAttr, isPlainObject, hasOwn, EMPTY_OBJ, looseEqual, looseToNumber, looseIndexOf, isSet, invokeArrayFns, isHTMLTag, isSVGTag, isMathMLTag } from '@vue/shared';
9
9
 
10
10
  let policy = void 0;
11
11
  const tt = typeof window !== "undefined" && window.trustedTypes;
@@ -436,36 +436,20 @@ function initVShowForSSR() {
436
436
  const CSS_VAR_TEXT = Symbol(!!(process.env.NODE_ENV !== "production") ? "CSS_VAR_TEXT" : "");
437
437
  function useCssVars(getter) {
438
438
  const instance = getCurrentInstance();
439
- if (!instance) {
440
- !!(process.env.NODE_ENV !== "production") && warn(`useCssVars is called without current active component instance.`);
441
- return;
442
- }
443
- const updateTeleports = instance.ut = (vars = getter(instance.proxy)) => {
444
- Array.from(
445
- document.querySelectorAll(`[data-v-owner="${instance.uid}"]`)
446
- ).forEach((node) => setVarsOnNode(node, vars));
447
- };
448
- if (!!(process.env.NODE_ENV !== "production")) {
449
- instance.getCssVars = () => getter(instance.proxy);
450
- }
451
- const setVars = () => {
452
- const vars = getter(instance.proxy);
439
+ const getVars = () => getter(instance.proxy);
440
+ const setVars = (vars) => {
453
441
  if (instance.ce) {
454
442
  setVarsOnNode(instance.ce, vars);
455
443
  } else {
456
444
  setVarsOnVNode(instance.subTree, vars);
457
445
  }
458
- updateTeleports(vars);
459
446
  };
460
- onBeforeUpdate(() => {
461
- queuePostFlushCb(setVars);
462
- });
463
- onMounted(() => {
464
- watch(setVars, NOOP, { flush: "post" });
465
- const ob = new MutationObserver(setVars);
466
- ob.observe(instance.subTree.el.parentNode, { childList: true });
467
- onUnmounted(() => ob.disconnect());
468
- });
447
+ baseUseCssVars(
448
+ instance,
449
+ () => instance.subTree.el.parentNode,
450
+ getVars,
451
+ setVars
452
+ );
469
453
  }
470
454
  function setVarsOnVNode(vnode, vars) {
471
455
  if (vnode.shapeFlag & 128) {
@@ -493,6 +477,34 @@ function setVarsOnVNode(vnode, vars) {
493
477
  }
494
478
  }
495
479
  }
480
+ function baseUseCssVars(instance, getParentNode, getVars, setVars) {
481
+ if (!instance) {
482
+ !!(process.env.NODE_ENV !== "production") && warn(`useCssVars is called without current active component instance.`);
483
+ return;
484
+ }
485
+ if (!!(process.env.NODE_ENV !== "production")) {
486
+ instance.getCssVars = getVars;
487
+ }
488
+ const updateTeleports = instance.ut = (vars = getVars()) => {
489
+ Array.from(
490
+ document.querySelectorAll(`[data-v-owner="${instance.uid}"]`)
491
+ ).forEach((node) => setVarsOnNode(node, vars));
492
+ };
493
+ const applyCssCars = () => {
494
+ const vars = getVars();
495
+ setVars(vars);
496
+ updateTeleports(vars);
497
+ };
498
+ onBeforeUpdate(() => {
499
+ queuePostFlushCb(applyCssCars);
500
+ });
501
+ onMounted(() => {
502
+ watch(applyCssCars, NOOP, { flush: "post" });
503
+ const ob = new MutationObserver(applyCssCars);
504
+ ob.observe(getParentNode(), { childList: true });
505
+ onUnmounted(() => ob.disconnect());
506
+ });
507
+ }
496
508
  function setVarsOnNode(el, vars) {
497
509
  if (el.nodeType === 1) {
498
510
  const style = el.style;
@@ -828,12 +840,9 @@ const defineSSRCustomElement = (/* @__NO_SIDE_EFFECTS__ */ (options, extraOption
828
840
  });
829
841
  const BaseClass = typeof HTMLElement !== "undefined" ? HTMLElement : class {
830
842
  };
831
- class VueElement extends BaseClass {
832
- constructor(_def, _props = {}, _createApp = createApp) {
843
+ class VueElementBase extends BaseClass {
844
+ constructor(def, props = {}, createAppFn) {
833
845
  super();
834
- this._def = _def;
835
- this._props = _props;
836
- this._createApp = _createApp;
837
846
  this._isVueCE = true;
838
847
  /**
839
848
  * @internal
@@ -843,28 +852,23 @@ class VueElement extends BaseClass {
843
852
  * @internal
844
853
  */
845
854
  this._app = null;
846
- /**
847
- * @internal
848
- */
849
- this._nonce = this._def.nonce;
850
855
  this._connected = false;
851
856
  this._resolved = false;
852
- this._patching = false;
853
- this._dirty = false;
854
857
  this._numberProps = null;
855
858
  this._styleChildren = /* @__PURE__ */ new WeakSet();
859
+ this._patching = false;
860
+ this._dirty = false;
856
861
  this._ob = null;
857
- if (this.shadowRoot && _createApp !== createApp) {
862
+ this._def = def;
863
+ this._props = props;
864
+ this._createApp = createAppFn;
865
+ this._nonce = def.nonce;
866
+ if (this._needsHydration()) {
858
867
  this._root = this.shadowRoot;
859
868
  } else {
860
- if (!!(process.env.NODE_ENV !== "production") && this.shadowRoot) {
861
- warn(
862
- `Custom element has pre-rendered declarative shadow root but is not defined as hydratable. Use \`defineSSRCustomElement\`.`
863
- );
864
- }
865
- if (_def.shadowRoot !== false) {
869
+ if (def.shadowRoot !== false) {
866
870
  this.attachShadow(
867
- extend({}, _def.shadowRootOptions, {
871
+ extend({}, def.shadowRootOptions, {
868
872
  mode: "open"
869
873
  })
870
874
  );
@@ -882,14 +886,14 @@ class VueElement extends BaseClass {
882
886
  this._connected = true;
883
887
  let parent = this;
884
888
  while (parent = parent && (parent.parentNode || parent.host)) {
885
- if (parent instanceof VueElement) {
889
+ if (parent instanceof VueElementBase) {
886
890
  this._parent = parent;
887
891
  break;
888
892
  }
889
893
  }
890
894
  if (!this._instance) {
891
895
  if (this._resolved) {
892
- this._mount(this._def);
896
+ this._mountComponent(this._def);
893
897
  } else {
894
898
  if (parent && parent._pendingResolve) {
895
899
  this._pendingResolve = parent._pendingResolve.then(() => {
@@ -902,20 +906,6 @@ class VueElement extends BaseClass {
902
906
  }
903
907
  }
904
908
  }
905
- _setParent(parent = this._parent) {
906
- if (parent) {
907
- this._instance.parent = parent._instance;
908
- this._inheritParentContext(parent);
909
- }
910
- }
911
- _inheritParentContext(parent = this._parent) {
912
- if (parent && this._app) {
913
- Object.setPrototypeOf(
914
- this._app._context.provides,
915
- parent._instance.provides
916
- );
917
- }
918
- }
919
909
  disconnectedCallback() {
920
910
  this._connected = false;
921
911
  nextTick(() => {
@@ -924,9 +914,7 @@ class VueElement extends BaseClass {
924
914
  this._ob.disconnect();
925
915
  this._ob = null;
926
916
  }
927
- this._app && this._app.unmount();
928
- if (this._instance) this._instance.ce = void 0;
929
- this._app = this._instance = null;
917
+ this._unmount();
930
918
  if (this._teleportTargets) {
931
919
  this._teleportTargets.clear();
932
920
  this._teleportTargets = void 0;
@@ -934,6 +922,20 @@ class VueElement extends BaseClass {
934
922
  }
935
923
  });
936
924
  }
925
+ _setParent(parent = this._parent) {
926
+ if (parent && this._instance) {
927
+ this._instance.parent = parent._instance;
928
+ this._inheritParentContext(parent);
929
+ }
930
+ }
931
+ _inheritParentContext(parent = this._parent) {
932
+ if (parent && this._app) {
933
+ Object.setPrototypeOf(
934
+ this._app._context.provides,
935
+ parent._instance.provides
936
+ );
937
+ }
938
+ }
937
939
  _processMutations(mutations) {
938
940
  for (const m of mutations) {
939
941
  this._setAttr(m.attributeName);
@@ -951,7 +953,7 @@ class VueElement extends BaseClass {
951
953
  }
952
954
  this._ob = new MutationObserver(this._processMutations.bind(this));
953
955
  this._ob.observe(this, { attributes: true });
954
- const resolve = (def, isAsync = false) => {
956
+ const resolve = (def) => {
955
957
  this._resolved = true;
956
958
  this._pendingResolve = void 0;
957
959
  const { props, styles } = def;
@@ -976,29 +978,25 @@ class VueElement extends BaseClass {
976
978
  "Custom element style injection is not supported when using shadowRoot: false"
977
979
  );
978
980
  }
979
- this._mount(def);
981
+ this._mountComponent(def);
980
982
  };
981
983
  const asyncDef = this._def.__asyncLoader;
982
984
  if (asyncDef) {
985
+ const { configureApp } = this._def;
983
986
  this._pendingResolve = asyncDef().then((def) => {
984
- def.configureApp = this._def.configureApp;
985
- resolve(this._def = def, true);
987
+ def.configureApp = configureApp;
988
+ this._def = def;
989
+ resolve(def);
986
990
  });
987
991
  } else {
988
992
  resolve(this._def);
989
993
  }
990
994
  }
991
- _mount(def) {
992
- if ((!!(process.env.NODE_ENV !== "production") || __VUE_PROD_DEVTOOLS__) && !def.name) {
993
- def.name = "VueElement";
994
- }
995
- this._app = this._createApp(def);
996
- this._inheritParentContext();
997
- if (def.configureApp) {
998
- def.configureApp(this._app);
999
- }
1000
- this._app._ceVNode = this._createVNode();
1001
- this._app.mount(this._root);
995
+ _mountComponent(def) {
996
+ this._mount(def);
997
+ this._processExposed();
998
+ }
999
+ _processExposed() {
1002
1000
  const exposed = this._instance && this._instance.exposed;
1003
1001
  if (!exposed) return;
1004
1002
  for (const key in exposed) {
@@ -1012,6 +1010,38 @@ class VueElement extends BaseClass {
1012
1010
  }
1013
1011
  }
1014
1012
  }
1013
+ _processInstance() {
1014
+ this._instance.ce = this;
1015
+ this._instance.isCE = true;
1016
+ if (!!(process.env.NODE_ENV !== "production")) {
1017
+ this._instance.ceReload = (newStyles) => {
1018
+ if (this._styles) {
1019
+ this._styles.forEach((s) => this._root.removeChild(s));
1020
+ this._styles.length = 0;
1021
+ }
1022
+ this._applyStyles(newStyles);
1023
+ if (!this._instance.vapor) {
1024
+ this._instance = null;
1025
+ }
1026
+ this._update();
1027
+ };
1028
+ }
1029
+ const dispatch = (event, args) => {
1030
+ this.dispatchEvent(
1031
+ new CustomEvent(
1032
+ event,
1033
+ isPlainObject(args[0]) ? extend({ detail: args }, args[0]) : { detail: args }
1034
+ )
1035
+ );
1036
+ };
1037
+ this._instance.emit = (event, ...args) => {
1038
+ dispatch(event, args);
1039
+ if (hyphenate(event) !== event) {
1040
+ dispatch(hyphenate(event), args);
1041
+ }
1042
+ };
1043
+ this._setParent();
1044
+ }
1015
1045
  _resolveProps(def) {
1016
1046
  const { props } = def;
1017
1047
  const declaredPropKeys = isArray(props) ? props : Object.keys(props || {});
@@ -1057,7 +1087,7 @@ class VueElement extends BaseClass {
1057
1087
  delete this._props[key];
1058
1088
  } else {
1059
1089
  this._props[key] = val;
1060
- if (key === "key" && this._app) {
1090
+ if (key === "key" && this._app && this._app._ceVNode) {
1061
1091
  this._app._ceVNode.key = val;
1062
1092
  }
1063
1093
  }
@@ -1081,52 +1111,6 @@ class VueElement extends BaseClass {
1081
1111
  }
1082
1112
  }
1083
1113
  }
1084
- _update() {
1085
- const vnode = this._createVNode();
1086
- if (this._app) vnode.appContext = this._app._context;
1087
- render(vnode, this._root);
1088
- }
1089
- _createVNode() {
1090
- const baseProps = {};
1091
- if (!this.shadowRoot) {
1092
- baseProps.onVnodeMounted = baseProps.onVnodeUpdated = this._renderSlots.bind(this);
1093
- }
1094
- const vnode = createVNode(this._def, extend(baseProps, this._props));
1095
- if (!this._instance) {
1096
- vnode.ce = (instance) => {
1097
- this._instance = instance;
1098
- instance.ce = this;
1099
- instance.isCE = true;
1100
- if (!!(process.env.NODE_ENV !== "production")) {
1101
- instance.ceReload = (newStyles) => {
1102
- if (this._styles) {
1103
- this._styles.forEach((s) => this._root.removeChild(s));
1104
- this._styles.length = 0;
1105
- }
1106
- this._applyStyles(newStyles);
1107
- this._instance = null;
1108
- this._update();
1109
- };
1110
- }
1111
- const dispatch = (event, args) => {
1112
- this.dispatchEvent(
1113
- new CustomEvent(
1114
- event,
1115
- isPlainObject(args[0]) ? extend({ detail: args }, args[0]) : { detail: args }
1116
- )
1117
- );
1118
- };
1119
- instance.emit = (event, ...args) => {
1120
- dispatch(event, args);
1121
- if (hyphenate(event) !== event) {
1122
- dispatch(hyphenate(event), args);
1123
- }
1124
- };
1125
- this._setParent();
1126
- };
1127
- }
1128
- return vnode;
1129
- }
1130
1114
  _applyStyles(styles, owner) {
1131
1115
  if (!styles) return;
1132
1116
  if (owner) {
@@ -1175,11 +1159,13 @@ class VueElement extends BaseClass {
1175
1159
  _renderSlots() {
1176
1160
  const outlets = this._getSlots();
1177
1161
  const scopeId = this._instance.type.__scopeId;
1162
+ const slotReplacements = /* @__PURE__ */ new Map();
1178
1163
  for (let i = 0; i < outlets.length; i++) {
1179
1164
  const o = outlets[i];
1180
1165
  const slotName = o.getAttribute("name") || "default";
1181
1166
  const content = this._slots[slotName];
1182
1167
  const parent = o.parentNode;
1168
+ const replacementNodes = [];
1183
1169
  if (content) {
1184
1170
  for (const n of content) {
1185
1171
  if (scopeId && n.nodeType === 1) {
@@ -1192,12 +1178,19 @@ class VueElement extends BaseClass {
1192
1178
  }
1193
1179
  }
1194
1180
  parent.insertBefore(n, o);
1181
+ replacementNodes.push(n);
1195
1182
  }
1196
1183
  } else {
1197
- while (o.firstChild) parent.insertBefore(o.firstChild, o);
1184
+ while (o.firstChild) {
1185
+ const child = o.firstChild;
1186
+ parent.insertBefore(child, o);
1187
+ replacementNodes.push(child);
1188
+ }
1198
1189
  }
1199
1190
  parent.removeChild(o);
1191
+ slotReplacements.set(o, replacementNodes);
1200
1192
  }
1193
+ this._updateSlotNodes(slotReplacements);
1201
1194
  }
1202
1195
  /**
1203
1196
  * @internal
@@ -1254,13 +1247,76 @@ class VueElement extends BaseClass {
1254
1247
  }
1255
1248
  }
1256
1249
  }
1250
+ class VueElement extends VueElementBase {
1251
+ constructor(def, props = {}, createAppFn = createApp) {
1252
+ super(def, props, createAppFn);
1253
+ }
1254
+ _needsHydration() {
1255
+ if (this.shadowRoot && this._createApp !== createApp) {
1256
+ return true;
1257
+ } else {
1258
+ if (!!(process.env.NODE_ENV !== "production") && this.shadowRoot) {
1259
+ warn(
1260
+ `Custom element has pre-rendered declarative shadow root but is not defined as hydratable. Use \`defineSSRCustomElement\`.`
1261
+ );
1262
+ }
1263
+ }
1264
+ return false;
1265
+ }
1266
+ _mount(def) {
1267
+ if ((!!(process.env.NODE_ENV !== "production") || __VUE_PROD_DEVTOOLS__) && !def.name) {
1268
+ def.name = "VueElement";
1269
+ }
1270
+ this._app = this._createApp(def);
1271
+ this._inheritParentContext();
1272
+ if (def.configureApp) {
1273
+ def.configureApp(this._app);
1274
+ }
1275
+ this._app._ceVNode = this._createVNode();
1276
+ this._app.mount(this._root);
1277
+ }
1278
+ _update() {
1279
+ if (!this._app) return;
1280
+ const vnode = this._createVNode();
1281
+ vnode.appContext = this._app._context;
1282
+ render(vnode, this._root);
1283
+ }
1284
+ _unmount() {
1285
+ if (this._app) {
1286
+ this._app.unmount();
1287
+ }
1288
+ if (this._instance && this._instance.ce) {
1289
+ this._instance.ce = void 0;
1290
+ }
1291
+ this._app = this._instance = null;
1292
+ }
1293
+ /**
1294
+ * Only called when shadowRoot is false
1295
+ */
1296
+ _updateSlotNodes(replacements) {
1297
+ }
1298
+ _createVNode() {
1299
+ const baseProps = {};
1300
+ if (!this.shadowRoot) {
1301
+ baseProps.onVnodeMounted = baseProps.onVnodeUpdated = this._renderSlots.bind(this);
1302
+ }
1303
+ const vnode = createVNode(this._def, extend(baseProps, this._props));
1304
+ if (!this._instance) {
1305
+ vnode.ce = (instance) => {
1306
+ this._instance = instance;
1307
+ this._processInstance();
1308
+ };
1309
+ }
1310
+ return vnode;
1311
+ }
1312
+ }
1257
1313
  function useHost(caller) {
1258
- const instance = getCurrentInstance();
1259
- const el = instance && instance.ce;
1314
+ const { hasInstance, value } = useInstanceOption("ce", true);
1315
+ const el = value;
1260
1316
  if (el) {
1261
1317
  return el;
1262
1318
  } else if (!!(process.env.NODE_ENV !== "production")) {
1263
- if (!instance) {
1319
+ if (!hasInstance) {
1264
1320
  warn(
1265
1321
  `${caller || "useHost"} called without an active component instance.`
1266
1322
  );
@@ -1279,12 +1335,12 @@ function useShadowRoot() {
1279
1335
 
1280
1336
  function useCssModule(name = "$style") {
1281
1337
  {
1282
- const instance = getCurrentInstance();
1283
- if (!instance) {
1338
+ const { hasInstance, value: type } = useInstanceOption("type", true);
1339
+ if (!hasInstance) {
1284
1340
  !!(process.env.NODE_ENV !== "production") && warn(`useCssModule must be called inside setup()`);
1285
1341
  return EMPTY_OBJ;
1286
1342
  }
1287
- const modules = instance.type.__cssModules;
1343
+ const modules = type.__cssModules;
1288
1344
  if (!modules) {
1289
1345
  !!(process.env.NODE_ENV !== "production") && warn(`Current instance does not have CSS modules injected.`);
1290
1346
  return EMPTY_OBJ;
@@ -1941,4 +1997,4 @@ const initDirectivesForSSR = () => {
1941
1997
  }
1942
1998
  } ;
1943
1999
 
1944
- export { Transition, TransitionGroup, TransitionPropsValidators, VueElement, addTransitionClass, baseApplyTranslation, callPendingCbs, createApp, createSSRApp, defineCustomElement, defineSSRCustomElement, ensureHydrationRenderer, ensureRenderer, forceReflow, handleMovedChildren, hasCSSTransform, hydrate, initDirectivesForSSR, moveCbKey, normalizeContainer, patchStyle, removeTransitionClass, render, resolveTransitionProps, shouldSetAsProp, unsafeToTrustedHTML, useCssModule, useCssVars, useHost, useShadowRoot, vModelCheckbox, vModelCheckboxInit, vModelCheckboxUpdate, vModelDynamic, getValue as vModelGetValue, vModelRadio, vModelSelect, vModelSelectInit, vModelSetSelected, vModelText, vModelTextInit, vModelTextUpdate, vShow, vShowHidden, vShowOriginalDisplay, withKeys, withModifiers };
2000
+ export { Transition, TransitionGroup, TransitionPropsValidators, VueElement, VueElementBase, baseApplyTranslation, baseUseCssVars, callPendingCbs, createApp, createSSRApp, defineCustomElement, defineSSRCustomElement, ensureHydrationRenderer, ensureRenderer, forceReflow, handleMovedChildren, hasCSSTransform, hydrate, initDirectivesForSSR, nodeOps, normalizeContainer, patchProp, patchStyle, render, resolveTransitionProps, setVarsOnNode, shouldSetAsProp, svgNS, unsafeToTrustedHTML, useCssModule, useCssVars, useHost, useShadowRoot, vModelCheckbox, vModelCheckboxInit, vModelCheckboxUpdate, vModelDynamic, getValue as vModelGetValue, vModelRadio, vModelSelect, vModelSelectInit, vModelSetSelected, vModelText, vModelTextInit, vModelTextUpdate, vShow, vShowHidden, vShowOriginalDisplay, withKeys, withModifiers, xlinkNS };