@vue/runtime-dom 3.6.0-alpha.3 → 3.6.0-alpha.4

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.4
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;
@@ -828,12 +828,9 @@ const defineSSRCustomElement = (/* @__NO_SIDE_EFFECTS__ */ (options, extraOption
828
828
  });
829
829
  const BaseClass = typeof HTMLElement !== "undefined" ? HTMLElement : class {
830
830
  };
831
- class VueElement extends BaseClass {
832
- constructor(_def, _props = {}, _createApp = createApp) {
831
+ class VueElementBase extends BaseClass {
832
+ constructor(def, props = {}, createAppFn) {
833
833
  super();
834
- this._def = _def;
835
- this._props = _props;
836
- this._createApp = _createApp;
837
834
  this._isVueCE = true;
838
835
  /**
839
836
  * @internal
@@ -843,28 +840,23 @@ class VueElement extends BaseClass {
843
840
  * @internal
844
841
  */
845
842
  this._app = null;
846
- /**
847
- * @internal
848
- */
849
- this._nonce = this._def.nonce;
850
843
  this._connected = false;
851
844
  this._resolved = false;
852
- this._patching = false;
853
- this._dirty = false;
854
845
  this._numberProps = null;
855
846
  this._styleChildren = /* @__PURE__ */ new WeakSet();
847
+ this._patching = false;
848
+ this._dirty = false;
856
849
  this._ob = null;
857
- if (this.shadowRoot && _createApp !== createApp) {
850
+ this._def = def;
851
+ this._props = props;
852
+ this._createApp = createAppFn;
853
+ this._nonce = def.nonce;
854
+ if (this._needsHydration()) {
858
855
  this._root = this.shadowRoot;
859
856
  } 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) {
857
+ if (def.shadowRoot !== false) {
866
858
  this.attachShadow(
867
- extend({}, _def.shadowRootOptions, {
859
+ extend({}, def.shadowRootOptions, {
868
860
  mode: "open"
869
861
  })
870
862
  );
@@ -882,14 +874,14 @@ class VueElement extends BaseClass {
882
874
  this._connected = true;
883
875
  let parent = this;
884
876
  while (parent = parent && (parent.parentNode || parent.host)) {
885
- if (parent instanceof VueElement) {
877
+ if (parent instanceof VueElementBase) {
886
878
  this._parent = parent;
887
879
  break;
888
880
  }
889
881
  }
890
882
  if (!this._instance) {
891
883
  if (this._resolved) {
892
- this._mount(this._def);
884
+ this._mountComponent(this._def);
893
885
  } else {
894
886
  if (parent && parent._pendingResolve) {
895
887
  this._pendingResolve = parent._pendingResolve.then(() => {
@@ -902,20 +894,6 @@ class VueElement extends BaseClass {
902
894
  }
903
895
  }
904
896
  }
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
897
  disconnectedCallback() {
920
898
  this._connected = false;
921
899
  nextTick(() => {
@@ -924,9 +902,7 @@ class VueElement extends BaseClass {
924
902
  this._ob.disconnect();
925
903
  this._ob = null;
926
904
  }
927
- this._app && this._app.unmount();
928
- if (this._instance) this._instance.ce = void 0;
929
- this._app = this._instance = null;
905
+ this._unmount();
930
906
  if (this._teleportTargets) {
931
907
  this._teleportTargets.clear();
932
908
  this._teleportTargets = void 0;
@@ -934,6 +910,20 @@ class VueElement extends BaseClass {
934
910
  }
935
911
  });
936
912
  }
913
+ _setParent(parent = this._parent) {
914
+ if (parent && this._instance) {
915
+ this._instance.parent = parent._instance;
916
+ this._inheritParentContext(parent);
917
+ }
918
+ }
919
+ _inheritParentContext(parent = this._parent) {
920
+ if (parent && this._app) {
921
+ Object.setPrototypeOf(
922
+ this._app._context.provides,
923
+ parent._instance.provides
924
+ );
925
+ }
926
+ }
937
927
  _processMutations(mutations) {
938
928
  for (const m of mutations) {
939
929
  this._setAttr(m.attributeName);
@@ -951,7 +941,7 @@ class VueElement extends BaseClass {
951
941
  }
952
942
  this._ob = new MutationObserver(this._processMutations.bind(this));
953
943
  this._ob.observe(this, { attributes: true });
954
- const resolve = (def, isAsync = false) => {
944
+ const resolve = (def) => {
955
945
  this._resolved = true;
956
946
  this._pendingResolve = void 0;
957
947
  const { props, styles } = def;
@@ -976,29 +966,25 @@ class VueElement extends BaseClass {
976
966
  "Custom element style injection is not supported when using shadowRoot: false"
977
967
  );
978
968
  }
979
- this._mount(def);
969
+ this._mountComponent(def);
980
970
  };
981
971
  const asyncDef = this._def.__asyncLoader;
982
972
  if (asyncDef) {
973
+ const { configureApp } = this._def;
983
974
  this._pendingResolve = asyncDef().then((def) => {
984
- def.configureApp = this._def.configureApp;
985
- resolve(this._def = def, true);
975
+ def.configureApp = configureApp;
976
+ this._def = def;
977
+ resolve(def);
986
978
  });
987
979
  } else {
988
980
  resolve(this._def);
989
981
  }
990
982
  }
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);
983
+ _mountComponent(def) {
984
+ this._mount(def);
985
+ this._processExposed();
986
+ }
987
+ _processExposed() {
1002
988
  const exposed = this._instance && this._instance.exposed;
1003
989
  if (!exposed) return;
1004
990
  for (const key in exposed) {
@@ -1012,6 +998,38 @@ class VueElement extends BaseClass {
1012
998
  }
1013
999
  }
1014
1000
  }
1001
+ _processInstance() {
1002
+ this._instance.ce = this;
1003
+ this._instance.isCE = true;
1004
+ if (!!(process.env.NODE_ENV !== "production")) {
1005
+ this._instance.ceReload = (newStyles) => {
1006
+ if (this._styles) {
1007
+ this._styles.forEach((s) => this._root.removeChild(s));
1008
+ this._styles.length = 0;
1009
+ }
1010
+ this._applyStyles(newStyles);
1011
+ if (!this._instance.vapor) {
1012
+ this._instance = null;
1013
+ }
1014
+ this._update();
1015
+ };
1016
+ }
1017
+ const dispatch = (event, args) => {
1018
+ this.dispatchEvent(
1019
+ new CustomEvent(
1020
+ event,
1021
+ isPlainObject(args[0]) ? extend({ detail: args }, args[0]) : { detail: args }
1022
+ )
1023
+ );
1024
+ };
1025
+ this._instance.emit = (event, ...args) => {
1026
+ dispatch(event, args);
1027
+ if (hyphenate(event) !== event) {
1028
+ dispatch(hyphenate(event), args);
1029
+ }
1030
+ };
1031
+ this._setParent();
1032
+ }
1015
1033
  _resolveProps(def) {
1016
1034
  const { props } = def;
1017
1035
  const declaredPropKeys = isArray(props) ? props : Object.keys(props || {});
@@ -1057,7 +1075,7 @@ class VueElement extends BaseClass {
1057
1075
  delete this._props[key];
1058
1076
  } else {
1059
1077
  this._props[key] = val;
1060
- if (key === "key" && this._app) {
1078
+ if (key === "key" && this._app && this._app._ceVNode) {
1061
1079
  this._app._ceVNode.key = val;
1062
1080
  }
1063
1081
  }
@@ -1081,52 +1099,6 @@ class VueElement extends BaseClass {
1081
1099
  }
1082
1100
  }
1083
1101
  }
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
1102
  _applyStyles(styles, owner) {
1131
1103
  if (!styles) return;
1132
1104
  if (owner) {
@@ -1175,11 +1147,13 @@ class VueElement extends BaseClass {
1175
1147
  _renderSlots() {
1176
1148
  const outlets = this._getSlots();
1177
1149
  const scopeId = this._instance.type.__scopeId;
1150
+ const slotReplacements = /* @__PURE__ */ new Map();
1178
1151
  for (let i = 0; i < outlets.length; i++) {
1179
1152
  const o = outlets[i];
1180
1153
  const slotName = o.getAttribute("name") || "default";
1181
1154
  const content = this._slots[slotName];
1182
1155
  const parent = o.parentNode;
1156
+ const replacementNodes = [];
1183
1157
  if (content) {
1184
1158
  for (const n of content) {
1185
1159
  if (scopeId && n.nodeType === 1) {
@@ -1192,12 +1166,19 @@ class VueElement extends BaseClass {
1192
1166
  }
1193
1167
  }
1194
1168
  parent.insertBefore(n, o);
1169
+ replacementNodes.push(n);
1195
1170
  }
1196
1171
  } else {
1197
- while (o.firstChild) parent.insertBefore(o.firstChild, o);
1172
+ while (o.firstChild) {
1173
+ const child = o.firstChild;
1174
+ parent.insertBefore(child, o);
1175
+ replacementNodes.push(child);
1176
+ }
1198
1177
  }
1199
1178
  parent.removeChild(o);
1179
+ slotReplacements.set(o, replacementNodes);
1200
1180
  }
1181
+ this._updateSlotNodes(slotReplacements);
1201
1182
  }
1202
1183
  /**
1203
1184
  * @internal
@@ -1254,13 +1235,76 @@ class VueElement extends BaseClass {
1254
1235
  }
1255
1236
  }
1256
1237
  }
1238
+ class VueElement extends VueElementBase {
1239
+ constructor(def, props = {}, createAppFn = createApp) {
1240
+ super(def, props, createAppFn);
1241
+ }
1242
+ _needsHydration() {
1243
+ if (this.shadowRoot && this._createApp !== createApp) {
1244
+ return true;
1245
+ } else {
1246
+ if (!!(process.env.NODE_ENV !== "production") && this.shadowRoot) {
1247
+ warn(
1248
+ `Custom element has pre-rendered declarative shadow root but is not defined as hydratable. Use \`defineSSRCustomElement\`.`
1249
+ );
1250
+ }
1251
+ }
1252
+ return false;
1253
+ }
1254
+ _mount(def) {
1255
+ if ((!!(process.env.NODE_ENV !== "production") || __VUE_PROD_DEVTOOLS__) && !def.name) {
1256
+ def.name = "VueElement";
1257
+ }
1258
+ this._app = this._createApp(def);
1259
+ this._inheritParentContext();
1260
+ if (def.configureApp) {
1261
+ def.configureApp(this._app);
1262
+ }
1263
+ this._app._ceVNode = this._createVNode();
1264
+ this._app.mount(this._root);
1265
+ }
1266
+ _update() {
1267
+ if (!this._app) return;
1268
+ const vnode = this._createVNode();
1269
+ vnode.appContext = this._app._context;
1270
+ render(vnode, this._root);
1271
+ }
1272
+ _unmount() {
1273
+ if (this._app) {
1274
+ this._app.unmount();
1275
+ }
1276
+ if (this._instance && this._instance.ce) {
1277
+ this._instance.ce = void 0;
1278
+ }
1279
+ this._app = this._instance = null;
1280
+ }
1281
+ /**
1282
+ * Only called when shadowRoot is false
1283
+ */
1284
+ _updateSlotNodes(replacements) {
1285
+ }
1286
+ _createVNode() {
1287
+ const baseProps = {};
1288
+ if (!this.shadowRoot) {
1289
+ baseProps.onVnodeMounted = baseProps.onVnodeUpdated = this._renderSlots.bind(this);
1290
+ }
1291
+ const vnode = createVNode(this._def, extend(baseProps, this._props));
1292
+ if (!this._instance) {
1293
+ vnode.ce = (instance) => {
1294
+ this._instance = instance;
1295
+ this._processInstance();
1296
+ };
1297
+ }
1298
+ return vnode;
1299
+ }
1300
+ }
1257
1301
  function useHost(caller) {
1258
- const instance = getCurrentInstance();
1259
- const el = instance && instance.ce;
1302
+ const { hasInstance, value } = useInstanceOption("ce", true);
1303
+ const el = value;
1260
1304
  if (el) {
1261
1305
  return el;
1262
1306
  } else if (!!(process.env.NODE_ENV !== "production")) {
1263
- if (!instance) {
1307
+ if (!hasInstance) {
1264
1308
  warn(
1265
1309
  `${caller || "useHost"} called without an active component instance.`
1266
1310
  );
@@ -1279,12 +1323,12 @@ function useShadowRoot() {
1279
1323
 
1280
1324
  function useCssModule(name = "$style") {
1281
1325
  {
1282
- const instance = getCurrentInstance();
1283
- if (!instance) {
1326
+ const { hasInstance, value: type } = useInstanceOption("type", true);
1327
+ if (!hasInstance) {
1284
1328
  !!(process.env.NODE_ENV !== "production") && warn(`useCssModule must be called inside setup()`);
1285
1329
  return EMPTY_OBJ;
1286
1330
  }
1287
- const modules = instance.type.__cssModules;
1331
+ const modules = type.__cssModules;
1288
1332
  if (!modules) {
1289
1333
  !!(process.env.NODE_ENV !== "production") && warn(`Current instance does not have CSS modules injected.`);
1290
1334
  return EMPTY_OBJ;
@@ -1941,4 +1985,4 @@ const initDirectivesForSSR = () => {
1941
1985
  }
1942
1986
  } ;
1943
1987
 
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 };
1988
+ export { Transition, TransitionGroup, TransitionPropsValidators, VueElement, VueElementBase, baseApplyTranslation, callPendingCbs, createApp, createSSRApp, defineCustomElement, defineSSRCustomElement, ensureHydrationRenderer, ensureRenderer, forceReflow, handleMovedChildren, hasCSSTransform, hydrate, initDirectivesForSSR, nodeOps, normalizeContainer, patchProp, patchStyle, render, resolveTransitionProps, 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 };