UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 3.94 kB
{"version":3,"file":"date-picker.mjs","sources":["../../../../../../packages/components/date-picker/src/date-picker.ts"],"sourcesContent":["import { defineComponent, h, provide, ref } from 'vue'\nimport dayjs from 'dayjs'\nimport customParseFormat from 'dayjs/plugin/customParseFormat'\nimport advancedFormat from 'dayjs/plugin/advancedFormat'\nimport localeData from 'dayjs/plugin/localeData'\nimport weekOfYear from 'dayjs/plugin/weekOfYear'\nimport weekYear from 'dayjs/plugin/weekYear'\nimport dayOfYear from 'dayjs/plugin/dayOfYear'\nimport isSameOrAfter from 'dayjs/plugin/isSameOrAfter'\nimport isSameOrBefore from 'dayjs/plugin/isSameOrBefore'\nimport {\n CommonPicker,\n DEFAULT_FORMATS_DATE,\n DEFAULT_FORMATS_DATEPICKER,\n timePickerDefaultProps,\n} from '@element-plus/components/time-picker'\nimport DatePickPanel from './date-picker-com/panel-date-pick.vue'\nimport DateRangePickPanel from './date-picker-com/panel-date-range.vue'\nimport MonthRangePickPanel from './date-picker-com/panel-month-range.vue'\nimport { ROOT_PICKER_INJECTION_KEY } from './date-picker.type'\nimport type { PropType } from 'vue'\nimport type { IDatePickerType } from './date-picker.type'\n\ndayjs.extend(localeData)\ndayjs.extend(advancedFormat)\ndayjs.extend(customParseFormat)\ndayjs.extend(weekOfYear)\ndayjs.extend(weekYear)\ndayjs.extend(dayOfYear)\ndayjs.extend(isSameOrAfter)\ndayjs.extend(isSameOrBefore)\n\nconst getPanel = function (type: IDatePickerType) {\n if (type === 'daterange' || type === 'datetimerange') {\n return DateRangePickPanel\n } else if (type === 'monthrange') {\n return MonthRangePickPanel\n }\n return DatePickPanel\n}\n\nexport default defineComponent({\n name: 'ElDatePicker',\n install: null,\n props: {\n ...timePickerDefaultProps,\n type: {\n type: String as PropType<IDatePickerType>,\n default: 'date',\n },\n },\n emits: ['update:modelValue'],\n setup(props, ctx) {\n provide('ElPopperOptions', props.popperOptions)\n provide(ROOT_PICKER_INJECTION_KEY, {\n ctx,\n })\n const commonPicker = ref(null)\n const refProps = {\n ...props,\n focus: () => {\n commonPicker.value?.handleFocus()\n },\n }\n ctx.expose(refProps)\n return () => {\n // since props always have all defined keys on it, {format, ...props} will always overwrite format\n // pick props.format or provide default value here before spreading\n const format =\n props.format ??\n (DEFAULT_FORMATS_DATEPICKER[props.type] || DEFAULT_FORMATS_DATE)\n return h(\n CommonPicker,\n {\n ...props,\n format,\n type: props.type,\n ref: commonPicker,\n 'onUpdate:modelValue': (value) =>\n ctx.emit('update:modelValue', value),\n },\n {\n default: (scopedProps) => h(getPanel(props.type), scopedProps),\n }\n )\n }\n },\n})\n"],"names":["DateRangePickPanel","MonthRangePickPanel","DatePickPanel","CommonPicker"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,OAAO;AAEb,MAAM,WAAW,SAAU,MAAuB;AAChD,MAAI,SAAS,eAAe,SAAS,iBAAiB;AACpD,WAAOA;AAAA,aACE,SAAS,cAAc;AAChC,WAAOC;AAAA;AAET,SAAOC;AAAA;AAGT,iBAAe,gBAAgB;AAAA,EAC7B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AAAA,OACF;AAAA,IACH,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,SAAS;AAAA;AAAA;AAAA,EAGb,OAAO,CAAC;AAAA,EACR,MAAM,OAAO,KAAK;AAChB,YAAQ,mBAAmB,MAAM;AACjC,YAAQ,2BAA2B;AAAA,MACjC;AAAA;AAEF,UAAM,eAAe,IAAI;AACzB,UAAM,WAAW;AAAA,SACZ;AAAA,MACH,OAAO,MAAM;AA5DnB;AA6DQ,2BAAa,UAAb,mBAAoB;AAAA;AAAA;AAGxB,QAAI,OAAO;AACX,WAAO,MAAM;AAjEjB;AAoEM,YAAM,SACJ,YAAM,WAAN,YACC,2BAA2B,MAAM,SAAS;AAC7C,aAAO,EACLC,UACA;AAAA,WACK;AAAA,QACH;AAAA,QACA,MAAM,MAAM;AAAA,QACZ,KAAK;AAAA,QACL,uBAAuB,CAAC,UACtB,IAAI,KAAK,qBAAqB;AAAA,SAElC;AAAA,QACE,SAAS,CAAC,gBAAgB,EAAE,SAAS,MAAM,OAAO;AAAA;AAAA;AAAA;AAAA;;;;"}