@vue/runtime-core 3.1.0 → 3.1.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.
@@ -63,6 +63,7 @@ export declare interface App<HostElement = any> {
63
63
  _props: Data | null;
64
64
  _container: HostElement | null;
65
65
  _context: AppContext;
66
+ _instance: ComponentInternalInstance | null;
66
67
  /**
67
68
  * v2 compat only
68
69
  */
@@ -329,6 +330,7 @@ export declare interface ComponentInternalInstance {
329
330
  /* Excluded from this release type: inheritAttrs */
330
331
  proxy: ComponentPublicInstance | null;
331
332
  exposed: Record<string, any> | null;
333
+ exposeProxy: Record<string, any> | null;
332
334
  /* Excluded from this release type: withProxy */
333
335
  /* Excluded from this release type: ctx */
334
336
  data: Data;
@@ -503,7 +505,7 @@ declare function createCompatVue(createApp: CreateAppFunction<Element>, createSi
503
505
 
504
506
  declare function createComponentInstance(vnode: VNode, parent: ComponentInternalInstance | null, suspense: SuspenseBoundary | null): ComponentInternalInstance;
505
507
 
506
- declare type CreateComponentPublicInstance<P = {}, B = {}, D = {}, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = {}, PublicProps = P, Defaults = {}, MakeDefaultsOptional extends boolean = false, PublicMixin = IntersectionMixin<Mixin> & IntersectionMixin<Extends>, PublicP = UnwrapMixinsType<PublicMixin, 'P'> & EnsureNonVoid<P>, PublicB = UnwrapMixinsType<PublicMixin, 'B'> & EnsureNonVoid<B>, PublicD = UnwrapMixinsType<PublicMixin, 'D'> & EnsureNonVoid<D>, PublicC extends ComputedOptions = UnwrapMixinsType<PublicMixin, 'C'> & EnsureNonVoid<C>, PublicM extends MethodOptions = UnwrapMixinsType<PublicMixin, 'M'> & EnsureNonVoid<M>, PublicDefaults = UnwrapMixinsType<PublicMixin, 'Defaults'> & EnsureNonVoid<Defaults>> = ComponentPublicInstance<PublicP, PublicB, PublicD, PublicC, PublicM, E, PublicProps, PublicDefaults, MakeDefaultsOptional, ComponentOptionsBase<P, B, D, C, M, Mixin, Extends, E, string, Defaults>>;
508
+ export declare type CreateComponentPublicInstance<P = {}, B = {}, D = {}, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = {}, PublicProps = P, Defaults = {}, MakeDefaultsOptional extends boolean = false, PublicMixin = IntersectionMixin<Mixin> & IntersectionMixin<Extends>, PublicP = UnwrapMixinsType<PublicMixin, 'P'> & EnsureNonVoid<P>, PublicB = UnwrapMixinsType<PublicMixin, 'B'> & EnsureNonVoid<B>, PublicD = UnwrapMixinsType<PublicMixin, 'D'> & EnsureNonVoid<D>, PublicC extends ComputedOptions = UnwrapMixinsType<PublicMixin, 'C'> & EnsureNonVoid<C>, PublicM extends MethodOptions = UnwrapMixinsType<PublicMixin, 'M'> & EnsureNonVoid<M>, PublicDefaults = UnwrapMixinsType<PublicMixin, 'Defaults'> & EnsureNonVoid<Defaults>> = ComponentPublicInstance<PublicP, PublicB, PublicD, PublicC, PublicM, E, PublicProps, PublicDefaults, MakeDefaultsOptional, ComponentOptionsBase<P, B, D, C, M, Mixin, Extends, E, string, Defaults>>;
507
509
 
508
510
  export declare function createHydrationRenderer(options: RendererOptions<Node, Element>): HydrationRenderer;
509
511
 
@@ -584,18 +586,91 @@ export declare function defineComponent<PropNames extends string, RawBindings, D
584
586
 
585
587
  export declare function defineComponent<PropsOptions extends Readonly<ComponentPropsOptions>, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = Record<string, any>, EE extends string = string>(options: ComponentOptionsWithObjectProps<PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE>): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE>;
586
588
 
587
- export declare function defineEmit<TypeEmit = undefined, E extends EmitsOptions = EmitsOptions, EE extends string = string, InferredEmit = EmitFn<E>>(emitOptions?: E | EE[]): TypeEmit extends undefined ? InferredEmit : TypeEmit;
589
+ /**
590
+ * @deprecated use `defineEmits` instead.
591
+ */
592
+ export declare const defineEmit: typeof defineEmits;
593
+
594
+ /**
595
+ * Vue `<script setup>` compiler macro for declaring a component's emitted
596
+ * events. The expected argument is the same as the component `emits` option.
597
+ *
598
+ * Example runtime declaration:
599
+ * ```js
600
+ * const emit = defineEmits(['change', 'update'])
601
+ * ```
602
+ *
603
+ * Example type-based decalration:
604
+ * ```ts
605
+ * const emit = defineEmits<{
606
+ * (event: 'change'): void
607
+ * (event: 'update', id: number): void
608
+ * }>()
609
+ *
610
+ * emit('change')
611
+ * emit('update', 1)
612
+ * ```
613
+ *
614
+ * This is only usable inside `<script setup>`, is compiled away in the
615
+ * output and should **not** be actually called at runtime.
616
+ */
617
+ export declare function defineEmits<EE extends string = string>(emitOptions: EE[]): EmitFn<EE[]>;
618
+
619
+ export declare function defineEmits<E extends EmitsOptions = EmitsOptions>(emitOptions: E): EmitFn<E>;
620
+
621
+ export declare function defineEmits<TypeEmit>(): TypeEmit;
588
622
 
589
623
  /**
590
- * Compile-time-only helper used for declaring props inside `<script setup>`.
591
- * This is stripped away in the compiled code and should never be actually
592
- * called at runtime.
624
+ * Vue `<script setup>` compiler macro for declaring a component's exposed
625
+ * instance properties when it is accessed by a parent component via template
626
+ * refs.
627
+ *
628
+ * `<script setup>` components are closed by default - i.e. varaibles inside
629
+ * the `<script setup>` scope is not exposed to parent unless explicitly exposed
630
+ * via `defineExpose`.
631
+ *
632
+ * This is only usable inside `<script setup>`, is compiled away in the
633
+ * output and should **not** be actually called at runtime.
634
+ */
635
+ export declare function defineExpose(exposed?: Record<string, any>): void;
636
+
637
+ /**
638
+ * Vue `<script setup>` compiler macro for declaring component props. The
639
+ * expected argument is the same as the component `props` option.
640
+ *
641
+ * Example runtime declaration:
642
+ * ```js
643
+ * // using Array syntax
644
+ * const props = defineProps(['foo', 'bar'])
645
+ * // using Object syntax
646
+ * const props = defineProps({
647
+ * foo: String,
648
+ * bar: {
649
+ * type: Number,
650
+ * required: true
651
+ * }
652
+ * })
653
+ * ```
654
+ *
655
+ * Equivalent type-based decalration:
656
+ * ```ts
657
+ * // will be compiled into equivalent runtime declarations
658
+ * const props = defineProps<{
659
+ * foo?: string
660
+ * bar: number
661
+ * }>()
662
+ * ```
663
+ *
664
+ * This is only usable inside `<script setup>`, is compiled away in the
665
+ * output and should **not** be actually called at runtime.
593
666
  */
594
- export declare function defineProps<TypeProps = undefined, PropNames extends string = string, InferredProps = {
667
+ export declare function defineProps<PropNames extends string = string>(props: PropNames[]): Readonly<{
595
668
  [key in PropNames]?: any;
596
- }>(props?: PropNames[]): Readonly<TypeProps extends undefined ? InferredProps : TypeProps>;
669
+ }>;
670
+
671
+ export declare function defineProps<PP extends ComponentObjectPropsOptions = ComponentObjectPropsOptions>(props: PP): Readonly<ExtractPropTypes<PP>>;
597
672
 
598
- export declare function defineProps<TypeProps = undefined, PP extends ComponentObjectPropsOptions = ComponentObjectPropsOptions, InferredProps = ExtractPropTypes<PP>>(props?: PP): Readonly<TypeProps extends undefined ? InferredProps : TypeProps>;
673
+ export declare function defineProps<TypeProps>(): Readonly<TypeProps>;
599
674
 
600
675
  export declare const enum DeprecationTypes {
601
676
  GLOBAL_MOUNT = "GLOBAL_MOUNT",
@@ -717,6 +792,9 @@ declare type ExtractMixin<T> = {
717
792
  declare type ExtractOptionProp<T> = T extends ComponentOptionsBase<infer P, any, any, any, any, any, any, any> ? unknown extends P ? {} : P : {};
718
793
 
719
794
  export declare type ExtractPropTypes<O> = O extends object ? {
795
+ [K in keyof O]?: unknown;
796
+ } & // This is needed to keep the relation between the option prop and the props, allowing to use ctrl+click to navigate to the prop options. see: #3656
797
+ {
720
798
  [K in RequiredKeys<O>]: InferPropType<O[K]>;
721
799
  } & {
722
800
  [K in OptionalKeys<O>]?: InferPropType<O[K]>;
@@ -799,6 +877,10 @@ export declare interface HydrationRenderer extends Renderer<Element> {
799
877
  hydrate: RootHydrateFunction;
800
878
  }
801
879
 
880
+ declare type InferDefaults<T> = {
881
+ [K in keyof T]?: NotUndefined<T[K]> extends (number | string | boolean | symbol | Function) ? NotUndefined<T[K]> : (props: T) => NotUndefined<T[K]>;
882
+ };
883
+
802
884
  declare type InferPropType<T> = [T] extends [null] ? any : [T] extends [{
803
885
  type: null | true;
804
886
  }] ? any : [T] extends [ObjectConstructor | {
@@ -994,6 +1076,8 @@ declare type MergedComponentOptionsOverride = {
994
1076
  errorCaptured?: MergedHook<ErrorCapturedHook>;
995
1077
  };
996
1078
 
1079
+ /* Excluded from this release type: mergeDefaults */
1080
+
997
1081
  declare type MergedHook<T = (() => void)> = T | T[];
998
1082
 
999
1083
  export declare function mergeProps(...args: (Data & VNodeProps)[]): Data & VNodeProps;
@@ -1037,6 +1121,8 @@ declare function normalizeSuspenseChildren(vnode: VNode): void;
1037
1121
 
1038
1122
  declare function normalizeVNode(child: VNodeChild): VNode;
1039
1123
 
1124
+ declare type NotUndefined<T> = T extends undefined ? never : T;
1125
+
1040
1126
  declare const NULL_DYNAMIC_COMPONENT: unique symbol;
1041
1127
 
1042
1128
  export declare interface ObjectDirective<T = any, V = any> {
@@ -1162,6 +1248,10 @@ declare interface PropOptions<T = any, D = T> {
1162
1248
  validator?(value: unknown): boolean;
1163
1249
  }
1164
1250
 
1251
+ declare type PropsWithDefaults<Base, Defaults> = Base & {
1252
+ [K in keyof Defaults]: K extends keyof Base ? NotUndefined<Base[K]> : never;
1253
+ };
1254
+
1165
1255
  export declare type PropType<T> = PropConstructor<T> | PropConstructor<T>[];
1166
1256
 
1167
1257
  export declare function provide<T>(key: InjectionKey<T> | string | number, value: T): void;
@@ -1251,7 +1341,7 @@ export declare interface RendererOptions<HostNode = RendererNode, HostElement =
1251
1341
  querySelector?(selector: string): HostElement | null;
1252
1342
  setScopeId?(el: HostElement, id: string): void;
1253
1343
  cloneNode?(node: HostNode): HostNode;
1254
- insertStaticContent?(content: string, parent: HostElement, anchor: HostNode | null, isSVG: boolean): HostElement[];
1344
+ insertStaticContent?(content: string, parent: HostElement, anchor: HostNode | null, isSVG: boolean, cached?: HostNode[] | null): HostElement[];
1255
1345
  }
1256
1346
 
1257
1347
  export declare type RenderFunction = () => VNodeChild;
@@ -1383,7 +1473,7 @@ export declare interface SetupContext<E = EmitsOptions> {
1383
1473
  attrs: Data;
1384
1474
  slots: Slots;
1385
1475
  emit: EmitFn<E>;
1386
- expose: (exposed: Record<string, any>) => void;
1476
+ expose: (exposed?: Record<string, any>) => void;
1387
1477
  }
1388
1478
 
1389
1479
  declare type SetupRenderEffectFn = (instance: ComponentInternalInstance, initialVNode: VNode, container: RendererElement, anchor: RendererNode | null, parentSuspense: SuspenseBoundary | null, isSVG: boolean, optimized: boolean) => void;
@@ -1541,8 +1631,15 @@ export { unref }
1541
1631
  declare type UnwrapMixinsType<T, Type extends OptionTypesKeys> = T extends OptionTypesType ? T[Type] : never;
1542
1632
  export { UnwrapRef }
1543
1633
 
1634
+ export declare function useAttrs(): SetupContext['attrs'];
1635
+
1636
+ /**
1637
+ * @deprecated use `useSlots` and `useAttrs` instead.
1638
+ */
1544
1639
  export declare function useContext(): SetupContext;
1545
1640
 
1641
+ export declare function useSlots(): SetupContext['slots'];
1642
+
1546
1643
  export declare const useSSRContext: <T = Record<string, any>>() => T | undefined;
1547
1644
 
1548
1645
  export declare function useTransitionState(): TransitionState;
@@ -1579,7 +1676,8 @@ export declare interface VNode<HostNode = RendererNode, HostElement = RendererEl
1579
1676
  anchor: HostNode | null;
1580
1677
  target: HostElement | null;
1581
1678
  targetAnchor: HostNode | null;
1582
- staticCount: number;
1679
+ staticCount?: number;
1680
+ staticCache?: HostNode[];
1583
1681
  suspense: SuspenseBoundary | null;
1584
1682
  ssContent: VNode | null;
1585
1683
  ssFallback: VNode | null;
@@ -1662,12 +1760,38 @@ export declare type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T);
1662
1760
 
1663
1761
  export declare type WatchStopHandle = () => void;
1664
1762
 
1763
+ /**
1764
+ * Runtime helper for storing and resuming current instance context in
1765
+ * async setup().
1766
+ */
1767
+ export declare function withAsyncContext<T>(awaitable: T | Promise<T>): Promise<T>;
1768
+
1665
1769
  /**
1666
1770
  * Wrap a slot function to memoize current rendering instance
1667
1771
  * @private compiler helper
1668
1772
  */
1669
1773
  export declare function withCtx(fn: Function, ctx?: ComponentInternalInstance | null, isNonScopedSlot?: boolean): Function;
1670
1774
 
1775
+ /**
1776
+ * Vue `<script setup>` compiler macro for providing props default values when
1777
+ * using type-based `defineProps` decalration.
1778
+ *
1779
+ * Example usage:
1780
+ * ```ts
1781
+ * withDefaults(defineProps<{
1782
+ * size?: number
1783
+ * labels?: string[]
1784
+ * }>(), {
1785
+ * size: 3,
1786
+ * labels: () => ['default label']
1787
+ * })
1788
+ * ```
1789
+ *
1790
+ * This is only usable inside `<script setup>`, is compiled away in the output
1791
+ * and should **not** be actually called at runtime.
1792
+ */
1793
+ export declare function withDefaults<Props, Defaults extends InferDefaults<Props>>(props: Props, defaults: Defaults): PropsWithDefaults<Props, Defaults>;
1794
+
1671
1795
  /**
1672
1796
  * Adds directives to a VNode.
1673
1797
  */
@@ -1697,3 +1821,17 @@ declare module '@vue/reactivity' {
1697
1821
  }
1698
1822
  }
1699
1823
  }
1824
+
1825
+ // Note: this file is auto concatenated to the end of the bundled d.ts during
1826
+ // build.
1827
+ type _defineProps = typeof defineProps
1828
+ type _defineEmits = typeof defineEmits
1829
+ type _defineExpose = typeof defineExpose
1830
+ type _withDefaults = typeof withDefaults
1831
+
1832
+ declare global {
1833
+ const defineProps: _defineProps
1834
+ const defineEmits: _defineEmits
1835
+ const defineExpose: _defineExpose
1836
+ const withDefaults: _withDefaults
1837
+ }