@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,5 +1,5 @@
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
  **/
@@ -735,12 +735,9 @@ const defineSSRCustomElement = (/* @__NO_SIDE_EFFECTS__ */ (options, extraOption
735
735
  });
736
736
  const BaseClass = typeof HTMLElement !== "undefined" ? HTMLElement : class {
737
737
  };
738
- class VueElement extends BaseClass {
739
- constructor(_def, _props = {}, _createApp = createApp) {
738
+ class VueElementBase extends BaseClass {
739
+ constructor(def, props = {}, createAppFn) {
740
740
  super();
741
- this._def = _def;
742
- this._props = _props;
743
- this._createApp = _createApp;
744
741
  this._isVueCE = true;
745
742
  /**
746
743
  * @internal
@@ -750,23 +747,23 @@ class VueElement extends BaseClass {
750
747
  * @internal
751
748
  */
752
749
  this._app = null;
753
- /**
754
- * @internal
755
- */
756
- this._nonce = this._def.nonce;
757
750
  this._connected = false;
758
751
  this._resolved = false;
759
- this._patching = false;
760
- this._dirty = false;
761
752
  this._numberProps = null;
762
753
  this._styleChildren = /* @__PURE__ */ new WeakSet();
754
+ this._patching = false;
755
+ this._dirty = false;
763
756
  this._ob = null;
764
- if (this.shadowRoot && _createApp !== createApp) {
757
+ this._def = def;
758
+ this._props = props;
759
+ this._createApp = createAppFn;
760
+ this._nonce = def.nonce;
761
+ if (this._needsHydration()) {
765
762
  this._root = this.shadowRoot;
766
763
  } else {
767
- if (_def.shadowRoot !== false) {
764
+ if (def.shadowRoot !== false) {
768
765
  this.attachShadow(
769
- shared.extend({}, _def.shadowRootOptions, {
766
+ shared.extend({}, def.shadowRootOptions, {
770
767
  mode: "open"
771
768
  })
772
769
  );
@@ -784,14 +781,14 @@ class VueElement extends BaseClass {
784
781
  this._connected = true;
785
782
  let parent = this;
786
783
  while (parent = parent && (parent.parentNode || parent.host)) {
787
- if (parent instanceof VueElement) {
784
+ if (parent instanceof VueElementBase) {
788
785
  this._parent = parent;
789
786
  break;
790
787
  }
791
788
  }
792
789
  if (!this._instance) {
793
790
  if (this._resolved) {
794
- this._mount(this._def);
791
+ this._mountComponent(this._def);
795
792
  } else {
796
793
  if (parent && parent._pendingResolve) {
797
794
  this._pendingResolve = parent._pendingResolve.then(() => {
@@ -804,20 +801,6 @@ class VueElement extends BaseClass {
804
801
  }
805
802
  }
806
803
  }
807
- _setParent(parent = this._parent) {
808
- if (parent) {
809
- this._instance.parent = parent._instance;
810
- this._inheritParentContext(parent);
811
- }
812
- }
813
- _inheritParentContext(parent = this._parent) {
814
- if (parent && this._app) {
815
- Object.setPrototypeOf(
816
- this._app._context.provides,
817
- parent._instance.provides
818
- );
819
- }
820
- }
821
804
  disconnectedCallback() {
822
805
  this._connected = false;
823
806
  runtimeCore.nextTick(() => {
@@ -826,9 +809,7 @@ class VueElement extends BaseClass {
826
809
  this._ob.disconnect();
827
810
  this._ob = null;
828
811
  }
829
- this._app && this._app.unmount();
830
- if (this._instance) this._instance.ce = void 0;
831
- this._app = this._instance = null;
812
+ this._unmount();
832
813
  if (this._teleportTargets) {
833
814
  this._teleportTargets.clear();
834
815
  this._teleportTargets = void 0;
@@ -836,6 +817,20 @@ class VueElement extends BaseClass {
836
817
  }
837
818
  });
838
819
  }
820
+ _setParent(parent = this._parent) {
821
+ if (parent && this._instance) {
822
+ this._instance.parent = parent._instance;
823
+ this._inheritParentContext(parent);
824
+ }
825
+ }
826
+ _inheritParentContext(parent = this._parent) {
827
+ if (parent && this._app) {
828
+ Object.setPrototypeOf(
829
+ this._app._context.provides,
830
+ parent._instance.provides
831
+ );
832
+ }
833
+ }
839
834
  _processMutations(mutations) {
840
835
  for (const m of mutations) {
841
836
  this._setAttr(m.attributeName);
@@ -853,7 +848,7 @@ class VueElement extends BaseClass {
853
848
  }
854
849
  this._ob = new MutationObserver(this._processMutations.bind(this));
855
850
  this._ob.observe(this, { attributes: true });
856
- const resolve = (def, isAsync = false) => {
851
+ const resolve = (def) => {
857
852
  this._resolved = true;
858
853
  this._pendingResolve = void 0;
859
854
  const { props, styles } = def;
@@ -874,26 +869,25 @@ class VueElement extends BaseClass {
874
869
  if (this.shadowRoot) {
875
870
  this._applyStyles(styles);
876
871
  }
877
- this._mount(def);
872
+ this._mountComponent(def);
878
873
  };
879
874
  const asyncDef = this._def.__asyncLoader;
880
875
  if (asyncDef) {
876
+ const { configureApp } = this._def;
881
877
  this._pendingResolve = asyncDef().then((def) => {
882
- def.configureApp = this._def.configureApp;
883
- resolve(this._def = def, true);
878
+ def.configureApp = configureApp;
879
+ this._def = def;
880
+ resolve(def);
884
881
  });
885
882
  } else {
886
883
  resolve(this._def);
887
884
  }
888
885
  }
889
- _mount(def) {
890
- this._app = this._createApp(def);
891
- this._inheritParentContext();
892
- if (def.configureApp) {
893
- def.configureApp(this._app);
894
- }
895
- this._app._ceVNode = this._createVNode();
896
- this._app.mount(this._root);
886
+ _mountComponent(def) {
887
+ this._mount(def);
888
+ this._processExposed();
889
+ }
890
+ _processExposed() {
897
891
  const exposed = this._instance && this._instance.exposed;
898
892
  if (!exposed) return;
899
893
  for (const key in exposed) {
@@ -905,6 +899,25 @@ class VueElement extends BaseClass {
905
899
  }
906
900
  }
907
901
  }
902
+ _processInstance() {
903
+ this._instance.ce = this;
904
+ this._instance.isCE = true;
905
+ const dispatch = (event, args) => {
906
+ this.dispatchEvent(
907
+ new CustomEvent(
908
+ event,
909
+ shared.isPlainObject(args[0]) ? shared.extend({ detail: args }, args[0]) : { detail: args }
910
+ )
911
+ );
912
+ };
913
+ this._instance.emit = (event, ...args) => {
914
+ dispatch(event, args);
915
+ if (shared.hyphenate(event) !== event) {
916
+ dispatch(shared.hyphenate(event), args);
917
+ }
918
+ };
919
+ this._setParent();
920
+ }
908
921
  _resolveProps(def) {
909
922
  const { props } = def;
910
923
  const declaredPropKeys = shared.isArray(props) ? props : Object.keys(props || {});
@@ -950,7 +963,7 @@ class VueElement extends BaseClass {
950
963
  delete this._props[key];
951
964
  } else {
952
965
  this._props[key] = val;
953
- if (key === "key" && this._app) {
966
+ if (key === "key" && this._app && this._app._ceVNode) {
954
967
  this._app._ceVNode.key = val;
955
968
  }
956
969
  }
@@ -974,41 +987,6 @@ class VueElement extends BaseClass {
974
987
  }
975
988
  }
976
989
  }
977
- _update() {
978
- const vnode = this._createVNode();
979
- if (this._app) vnode.appContext = this._app._context;
980
- render(vnode, this._root);
981
- }
982
- _createVNode() {
983
- const baseProps = {};
984
- if (!this.shadowRoot) {
985
- baseProps.onVnodeMounted = baseProps.onVnodeUpdated = this._renderSlots.bind(this);
986
- }
987
- const vnode = runtimeCore.createVNode(this._def, shared.extend(baseProps, this._props));
988
- if (!this._instance) {
989
- vnode.ce = (instance) => {
990
- this._instance = instance;
991
- instance.ce = this;
992
- instance.isCE = true;
993
- const dispatch = (event, args) => {
994
- this.dispatchEvent(
995
- new CustomEvent(
996
- event,
997
- shared.isPlainObject(args[0]) ? shared.extend({ detail: args }, args[0]) : { detail: args }
998
- )
999
- );
1000
- };
1001
- instance.emit = (event, ...args) => {
1002
- dispatch(event, args);
1003
- if (shared.hyphenate(event) !== event) {
1004
- dispatch(shared.hyphenate(event), args);
1005
- }
1006
- };
1007
- this._setParent();
1008
- };
1009
- }
1010
- return vnode;
1011
- }
1012
990
  _applyStyles(styles, owner) {
1013
991
  if (!styles) return;
1014
992
  if (owner) {
@@ -1043,11 +1021,13 @@ class VueElement extends BaseClass {
1043
1021
  _renderSlots() {
1044
1022
  const outlets = this._getSlots();
1045
1023
  const scopeId = this._instance.type.__scopeId;
1024
+ const slotReplacements = /* @__PURE__ */ new Map();
1046
1025
  for (let i = 0; i < outlets.length; i++) {
1047
1026
  const o = outlets[i];
1048
1027
  const slotName = o.getAttribute("name") || "default";
1049
1028
  const content = this._slots[slotName];
1050
1029
  const parent = o.parentNode;
1030
+ const replacementNodes = [];
1051
1031
  if (content) {
1052
1032
  for (const n of content) {
1053
1033
  if (scopeId && n.nodeType === 1) {
@@ -1060,12 +1040,19 @@ class VueElement extends BaseClass {
1060
1040
  }
1061
1041
  }
1062
1042
  parent.insertBefore(n, o);
1043
+ replacementNodes.push(n);
1063
1044
  }
1064
1045
  } else {
1065
- while (o.firstChild) parent.insertBefore(o.firstChild, o);
1046
+ while (o.firstChild) {
1047
+ const child = o.firstChild;
1048
+ parent.insertBefore(child, o);
1049
+ replacementNodes.push(child);
1050
+ }
1066
1051
  }
1067
1052
  parent.removeChild(o);
1053
+ slotReplacements.set(o, replacementNodes);
1068
1054
  }
1055
+ this._updateSlotNodes(slotReplacements);
1069
1056
  }
1070
1057
  /**
1071
1058
  * @internal
@@ -1112,9 +1099,63 @@ class VueElement extends BaseClass {
1112
1099
  _removeChildStyle(comp) {
1113
1100
  }
1114
1101
  }
1102
+ class VueElement extends VueElementBase {
1103
+ constructor(def, props = {}, createAppFn = createApp) {
1104
+ super(def, props, createAppFn);
1105
+ }
1106
+ _needsHydration() {
1107
+ if (this.shadowRoot && this._createApp !== createApp) {
1108
+ return true;
1109
+ }
1110
+ return false;
1111
+ }
1112
+ _mount(def) {
1113
+ this._app = this._createApp(def);
1114
+ this._inheritParentContext();
1115
+ if (def.configureApp) {
1116
+ def.configureApp(this._app);
1117
+ }
1118
+ this._app._ceVNode = this._createVNode();
1119
+ this._app.mount(this._root);
1120
+ }
1121
+ _update() {
1122
+ if (!this._app) return;
1123
+ const vnode = this._createVNode();
1124
+ vnode.appContext = this._app._context;
1125
+ render(vnode, this._root);
1126
+ }
1127
+ _unmount() {
1128
+ if (this._app) {
1129
+ this._app.unmount();
1130
+ }
1131
+ if (this._instance && this._instance.ce) {
1132
+ this._instance.ce = void 0;
1133
+ }
1134
+ this._app = this._instance = null;
1135
+ }
1136
+ /**
1137
+ * Only called when shadowRoot is false
1138
+ */
1139
+ _updateSlotNodes(replacements) {
1140
+ }
1141
+ _createVNode() {
1142
+ const baseProps = {};
1143
+ if (!this.shadowRoot) {
1144
+ baseProps.onVnodeMounted = baseProps.onVnodeUpdated = this._renderSlots.bind(this);
1145
+ }
1146
+ const vnode = runtimeCore.createVNode(this._def, shared.extend(baseProps, this._props));
1147
+ if (!this._instance) {
1148
+ vnode.ce = (instance) => {
1149
+ this._instance = instance;
1150
+ this._processInstance();
1151
+ };
1152
+ }
1153
+ return vnode;
1154
+ }
1155
+ }
1115
1156
  function useHost(caller) {
1116
- const instance = runtimeCore.getCurrentInstance();
1117
- const el = instance && instance.ce;
1157
+ const { hasInstance, value } = runtimeCore.useInstanceOption("ce", true);
1158
+ const el = value;
1118
1159
  if (el) {
1119
1160
  return el;
1120
1161
  }
@@ -1127,11 +1168,11 @@ function useShadowRoot() {
1127
1168
 
1128
1169
  function useCssModule(name = "$style") {
1129
1170
  {
1130
- const instance = runtimeCore.getCurrentInstance();
1131
- if (!instance) {
1171
+ const { hasInstance, value: type } = runtimeCore.useInstanceOption("type", true);
1172
+ if (!hasInstance) {
1132
1173
  return shared.EMPTY_OBJ;
1133
1174
  }
1134
- const modules = instance.type.__cssModules;
1175
+ const modules = type.__cssModules;
1135
1176
  if (!modules) {
1136
1177
  return shared.EMPTY_OBJ;
1137
1178
  }
@@ -1731,12 +1772,15 @@ const initDirectivesForSSR = () => {
1731
1772
  exports.Transition = Transition;
1732
1773
  exports.TransitionGroup = TransitionGroup;
1733
1774
  exports.VueElement = VueElement;
1775
+ exports.VueElementBase = VueElementBase;
1734
1776
  exports.createApp = createApp;
1735
1777
  exports.createSSRApp = createSSRApp;
1736
1778
  exports.defineCustomElement = defineCustomElement;
1737
1779
  exports.defineSSRCustomElement = defineSSRCustomElement;
1738
1780
  exports.hydrate = hydrate;
1739
1781
  exports.initDirectivesForSSR = initDirectivesForSSR;
1782
+ exports.nodeOps = nodeOps;
1783
+ exports.patchProp = patchProp;
1740
1784
  exports.render = render;
1741
1785
  exports.useCssModule = useCssModule;
1742
1786
  exports.useCssVars = useCssVars;
@@ -1,7 +1,12 @@
1
- import { BaseTransitionProps, FunctionalComponent, ObjectDirective, Directive, SetupContext, RenderFunction, ComponentOptions, App, ComponentCustomElementInterface, ConcreteComponent, CreateAppFunction, ComponentObjectPropsOptions, EmitsOptions, ComputedOptions, MethodOptions, ComponentOptionsMixin, ComponentInjectOptions, SlotsType, Component, ComponentProvideOptions, ExtractPropTypes, EmitsToProps, ComponentOptionsBase, CreateComponentPublicInstanceWithMixins, ComponentPublicInstance, DefineComponent, VNodeRef, RootRenderFunction, RootHydrateFunction } from '@vue/runtime-core';
1
+ import { RendererOptions, BaseTransitionProps, FunctionalComponent, ObjectDirective, Directive, SetupContext, RenderFunction, ComponentOptions, App, Component, ConcreteComponent, ComponentCustomElementInterface, CreateAppFunction, ComponentObjectPropsOptions, EmitsOptions, ComputedOptions, MethodOptions, ComponentOptionsMixin, ComponentInjectOptions, SlotsType, ComponentProvideOptions, ExtractPropTypes, EmitsToProps, ComponentOptionsBase, CreateComponentPublicInstanceWithMixins, ComponentPublicInstance, DefineComponent, VNodeRef, RootRenderFunction, RootHydrateFunction } from '@vue/runtime-core';
2
2
  export * from '@vue/runtime-core';
3
3
  import * as CSS from 'csstype';
4
4
 
5
+ export declare const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'>;
6
+
7
+ type DOMRendererOptions = RendererOptions<Node, Element>;
8
+ export declare const patchProp: DOMRendererOptions['patchProp'];
9
+
5
10
  declare const TRANSITION = "transition";
6
11
  declare const ANIMATION = "animation";
7
12
  type AnimationTypes = typeof TRANSITION | typeof ANIMATION;
@@ -114,54 +119,62 @@ export declare function defineCustomElement<T extends {
114
119
  export declare const defineSSRCustomElement: typeof defineCustomElement;
115
120
  declare const BaseClass: typeof HTMLElement;
116
121
  type InnerComponentDef = ConcreteComponent & CustomElementOptions;
117
- export declare class VueElement extends BaseClass implements ComponentCustomElementInterface {
118
- /**
119
- * Component def - note this may be an AsyncWrapper, and this._def will
120
- * be overwritten by the inner component when resolved.
121
- */
122
- private _def;
123
- private _props;
124
- private _createApp;
122
+ export declare abstract class VueElementBase<E = Element, C = Component, Def extends CustomElementOptions & {
123
+ props?: any;
124
+ } = InnerComponentDef> extends BaseClass implements ComponentCustomElementInterface {
125
125
  _isVueCE: boolean;
126
- private _connected;
127
- private _resolved;
128
- private _patching;
129
- private _dirty;
130
- private _numberProps;
131
- private _styleChildren;
132
- private _pendingResolve;
133
- private _parent;
126
+ protected _connected: boolean;
127
+ protected _resolved: boolean;
128
+ protected _numberProps: Record<string, true> | null;
129
+ protected _styleChildren: WeakSet<object>;
130
+ protected _pendingResolve: Promise<void> | undefined;
131
+ protected _parent: VueElementBase | undefined;
132
+ protected _patching: boolean;
133
+ protected _dirty: boolean;
134
+ protected _def: Def;
135
+ protected _props: Record<string, any>;
136
+ protected _createApp: CreateAppFunction<E, C>;
134
137
  /**
135
138
  * dev only
136
139
  */
137
- private _styles?;
140
+ protected _styles?: HTMLStyleElement[];
138
141
  /**
139
142
  * dev only
140
143
  */
141
- private _childStyles?;
142
- private _ob?;
143
- private _slots?;
144
+ protected _childStyles?: Map<string, HTMLStyleElement[]>;
145
+ protected _ob?: MutationObserver | null;
146
+ protected _slots?: Record<string, Node[]>;
147
+ /**
148
+ * Check if this custom element needs hydration.
149
+ * Returns true if it has a pre-rendered declarative shadow root that
150
+ * needs to be hydrated.
151
+ */
152
+ protected abstract _needsHydration(): boolean;
153
+ protected abstract _mount(def: Def): void;
154
+ protected abstract _update(): void;
155
+ protected abstract _unmount(): void;
156
+ protected abstract _updateSlotNodes(slot: Map<Node, Node[]>): void;
144
157
  constructor(
145
158
  /**
146
159
  * Component def - note this may be an AsyncWrapper, and this._def will
147
160
  * be overwritten by the inner component when resolved.
148
161
  */
149
- _def: InnerComponentDef, _props?: Record<string, any>, _createApp?: CreateAppFunction<Element>);
162
+ def: Def, props: Record<string, any> | undefined, createAppFn: CreateAppFunction<E, C>);
150
163
  connectedCallback(): void;
151
- private _setParent;
152
- private _inheritParentContext;
153
164
  disconnectedCallback(): void;
165
+ protected _setParent(parent?: VueElementBase | undefined): void;
166
+ protected _inheritParentContext(parent?: VueElementBase | undefined): void;
154
167
  private _processMutations;
155
168
  /**
156
169
  * resolve inner component definition (handle possible async component)
157
170
  */
158
171
  private _resolveDef;
159
- private _mount;
172
+ private _mountComponent;
173
+ protected _processExposed(): void;
174
+ protected _processInstance(): void;
160
175
  private _resolveProps;
161
- protected _setAttr(key: string): void;
162
- private _update;
163
- private _createVNode;
164
- private _applyStyles;
176
+ private _setAttr;
177
+ protected _applyStyles(styles: string[] | undefined, owner?: ConcreteComponent): void;
165
178
  /**
166
179
  * Only called when shadowRoot is false
167
180
  */
@@ -169,9 +182,21 @@ export declare class VueElement extends BaseClass implements ComponentCustomElem
169
182
  /**
170
183
  * Only called when shadowRoot is false
171
184
  */
172
- private _renderSlots;
185
+ protected _renderSlots(): void;
186
+ }
187
+ export declare class VueElement extends VueElementBase<Element, Component, InnerComponentDef> {
188
+ constructor(def: InnerComponentDef, props?: Record<string, any> | undefined, createAppFn?: CreateAppFunction<Element, Component>);
189
+ protected _needsHydration(): boolean;
190
+ protected _mount(def: InnerComponentDef): void;
191
+ protected _update(): void;
192
+ protected _unmount(): void;
193
+ /**
194
+ * Only called when shadowRoot is false
195
+ */
196
+ protected _updateSlotNodes(replacements: Map<Node, Node[]>): void;
197
+ private _createVNode;
173
198
  }
174
- export declare function useHost(caller?: string): VueElement | null;
199
+ export declare function useHost(caller?: string): VueElementBase | null;
175
200
  /**
176
201
  * Retrieve the shadowRoot of the current custom element. Only usable in setup()
177
202
  * of a `defineCustomElement` component.