package.lib.util.defineComponent.mjs.map Maven / Gradle / Ivy
{"version":3,"file":"defineComponent.mjs","names":["injectDefaults","internalUseDefaults","defineComponent","_defineComponent","consoleWarn","pick","propsFactory","options","_setup","setup","name","props","propKeys","Object","keys","filter","key","filterProps","_as","String","ctx","defaults","value","_props","provideSubDefaults","setupBindings","genericComponent","exposeDefaults","arguments","length","undefined","defineFunctionalComponent","render"],"sources":["../../src/util/defineComponent.tsx"],"sourcesContent":["// Composables\nimport { injectDefaults, internalUseDefaults } from '@/composables/defaults'\n\n// Utilities\nimport {\n defineComponent as _defineComponent, // eslint-disable-line no-restricted-imports\n} from 'vue'\nimport { consoleWarn } from '@/util/console'\nimport { pick } from '@/util/helpers'\nimport { propsFactory } from '@/util/propsFactory'\n\n// Types\nimport type {\n AllowedComponentProps,\n Component,\n ComponentCustomProps,\n ComponentInjectOptions,\n ComponentObjectPropsOptions,\n ComponentOptions,\n ComponentOptionsMixin,\n ComponentOptionsWithObjectProps,\n ComponentOptionsWithoutProps,\n ComponentPropsOptions,\n ComponentPublicInstance,\n ComputedOptions,\n DefineComponent,\n EmitsOptions,\n ExtractDefaultPropTypes,\n ExtractPropTypes,\n FunctionalComponent,\n MethodOptions,\n ObjectEmitsOptions,\n SlotsType,\n VNode,\n VNodeChild,\n VNodeProps,\n} from 'vue'\n\n// No props\nexport function defineComponent<\n Props = {},\n RawBindings = {},\n D = {},\n C extends ComputedOptions = {},\n M extends MethodOptions = {},\n Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,\n Extends extends ComponentOptionsMixin = ComponentOptionsMixin,\n E extends EmitsOptions = {},\n EE extends string = string,\n I extends {} = {},\n II extends string = string,\n S extends SlotsType = {},\n>(\n options: ComponentOptionsWithoutProps<\n Props,\n RawBindings,\n D,\n C,\n M,\n Mixin,\n Extends,\n E,\n EE,\n I,\n II,\n S\n >\n): DefineComponent\n\n// Object Props\nexport function defineComponent<\n PropsOptions extends Readonly,\n RawBindings,\n D,\n C extends ComputedOptions = {},\n M extends MethodOptions = {},\n Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,\n Extends extends ComponentOptionsMixin = ComponentOptionsMixin,\n E extends EmitsOptions = {},\n EE extends string = string,\n I extends {} = {},\n II extends string = string,\n S extends SlotsType = {},\n>(\n options: ComponentOptionsWithObjectProps<\n PropsOptions,\n RawBindings,\n D,\n C,\n M,\n Mixin,\n Extends,\n E,\n EE,\n I,\n II,\n S\n >\n): DefineComponent & FilterPropsOptions\n\n// Implementation\nexport function defineComponent (options: ComponentOptions) {\n options._setup = options._setup ?? options.setup\n\n if (!options.name) {\n consoleWarn('The component is missing an explicit name, unable to generate default prop value')\n\n return options\n }\n\n if (options._setup) {\n options.props = propsFactory(options.props ?? {}, options.name)()\n const propKeys = Object.keys(options.props).filter(key => key !== 'class' && key !== 'style')\n options.filterProps = function filterProps (props: Record) {\n return pick(props, propKeys)\n }\n\n options.props._as = String\n options.setup = function setup (props: Record, ctx) {\n const defaults = injectDefaults()\n\n // Skip props proxy if defaults are not provided\n if (!defaults.value) return options._setup(props, ctx)\n\n const { props: _props, provideSubDefaults } = internalUseDefaults(props, props._as ?? options.name, defaults)\n\n const setupBindings = options._setup(_props, ctx)\n\n provideSubDefaults()\n\n return setupBindings\n }\n }\n\n return options\n}\n\ntype ToListeners = { [K in T]: K extends `on${infer U}` ? Uncapitalize : K }[T]\n\nexport type SlotsToProps<\n U extends RawSlots,\n T = MakeInternalSlots\n> = {\n $children?: (\n | VNodeChild\n | (T extends { default: infer V } ? V : {})\n | { [K in keyof T]?: T[K] }\n )\n 'v-slots'?: { [K in keyof T]?: T[K] | false }\n} & {\n [K in keyof T as `v-slot:${K & string}`]?: T[K] | false\n}\n\ntype RawSlots = Record\ntype Slot = [T] extends [never] ? () => VNodeChild : (arg: T) => VNodeChild\ntype VueSlot = [T] extends [never] ? () => VNode[] : (arg: T) => VNode[]\ntype MakeInternalSlots = {\n [K in keyof T]: Slot\n}\ntype MakeSlots = {\n [K in keyof T]: VueSlot\n}\n\nexport type GenericProps> = {\n $props: Props & SlotsToProps\n $slots: MakeSlots\n}\n\ntype DefineComponentWithGenericProps, slots: RawSlots) => {\n $props?: Record\n})> = <\n PropsOptions extends Readonly,\n RawBindings,\n D,\n C extends ComputedOptions = {},\n M extends MethodOptions = {},\n Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,\n Extends extends ComponentOptionsMixin = ComponentOptionsMixin,\n E extends EmitsOptions = Record,\n EE extends string = string,\n I extends ComponentInjectOptions = {},\n II extends string = string,\n // Slots extends RawSlots = ConstructorParameters extends [any, infer SS extends RawSlots | undefined] ? Exclude : {},\n Slots extends RawSlots = ConstructorParameters[1],\n S extends SlotsType = SlotsType>>,\n III = InstanceType,\n P = III extends Record<'$props', any>\n ? Omit\n : PropsOptions,\n EEE extends EmitsOptions = E extends any[]\n ? E\n : III extends Record<'$props', any>\n ? Omit>\n : E,\n Base = DefineComponent<\n P,\n RawBindings,\n D,\n C,\n M,\n Mixin,\n Extends,\n EEE,\n EE,\n PublicProps,\n ExtractPropTypes & ({} extends E ? {} : EmitsToProps),\n ExtractDefaultPropTypes,\n S\n >\n>(\n options: ComponentOptionsWithObjectProps\n) => Base & T & FilterPropsOptions\n\ntype DefineComponentWithSlots = <\n PropsOptions extends Readonly,\n RawBindings,\n D,\n C extends ComputedOptions = {},\n M extends MethodOptions = {},\n Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,\n Extends extends ComponentOptionsMixin = ComponentOptionsMixin,\n E extends EmitsOptions = Record,\n EE extends string = string,\n I extends ComponentInjectOptions = {},\n II extends string = string,\n S extends SlotsType = SlotsType>>,\n>(\n options: ComponentOptionsWithObjectProps\n) => DefineComponent<\n ExtractPropTypes & SlotsToProps,\n RawBindings,\n D,\n C,\n M,\n Mixin,\n Extends,\n E,\n EE,\n PublicProps,\n ExtractPropTypes & SlotsToProps & ({} extends E ? {} : EmitsToProps),\n ExtractDefaultPropTypes,\n S\n> & FilterPropsOptions\n\n// No argument - simple default slot\nexport function genericComponent (exposeDefaults?: boolean): DefineComponentWithSlots<{ default: never }>\n\n// Generic constructor argument - generic props and slots\nexport function genericComponent, slots: any) => {\n $props?: Record\n})> (exposeDefaults?: boolean): DefineComponentWithGenericProps\n\n// Slots argument - simple slots\nexport function genericComponent<\n Slots extends RawSlots\n> (exposeDefaults?: boolean): DefineComponentWithSlots\n\n// Implementation\nexport function genericComponent (exposeDefaults = true) {\n return (options: any) => ((exposeDefaults ? defineComponent : _defineComponent) as any)(options)\n}\n\nexport function defineFunctionalComponent<\n T extends FunctionalComponent,\n PropsOptions = ComponentObjectPropsOptions,\n Defaults = ExtractDefaultPropTypes,\n Props = Readonly>,\n> (props: PropsOptions, render: T): FunctionalComponent & Omit> {\n render.props = props as any\n return render as any\n}\n\ntype EmitsToProps = T extends string[]\n ? {\n [K in string & `on${Capitalize}`]?: (...args: any[]) => any\n }\n : T extends ObjectEmitsOptions\n ? {\n [K in string &\n `on${Capitalize}`]?: K extends `on${infer C}`\n ? T[Uncapitalize] extends null\n ? (...args: any[]) => any\n : (\n ...args: T[Uncapitalize] extends (...args: infer P) => any\n ? P\n : never\n ) => any\n : never\n }\n : {}\n\ntype PublicProps =\n & VNodeProps\n & AllowedComponentProps\n & ComponentCustomProps\n\n// Adds a filterProps method to the component options\nexport interface FilterPropsOptions, Props = ExtractPropTypes> {\n filterProps<\n T extends Partial,\n U extends Exclude>\n > (props: T): Partial>\n}\n\n// https://github.com/vuejs/core/pull/10557\nexport type ComponentInstance = T extends { new (): ComponentPublicInstance }\n ? InstanceType\n : T extends FunctionalComponent\n ? ComponentPublicInstance>\n : T extends Component<\n infer Props,\n infer RawBindings,\n infer D,\n infer C,\n infer M\n >\n ? // NOTE we override Props/RawBindings/D to make sure is not `unknown`\n ComponentPublicInstance<\n unknown extends Props ? {} : Props,\n unknown extends RawBindings ? {} : RawBindings,\n unknown extends D ? {} : D,\n C,\n M\n >\n : never // not a vue Component\n\ntype ShortEmitsToObject = E extends Record ? {\n [K in keyof E]: (...args: E[K]) =>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