You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
11 KiB
1 line
11 KiB
{"ast":null,"code":"import { computed } from 'vue';\nimport dayjs from 'dayjs';\nimport localeData from 'dayjs/plugin/localeData.js';\nimport '../../../hooks/index.mjs';\nimport '../../time-picker/index.mjs';\nimport '../../../constants/index.mjs';\nimport { getPrevMonthLastDays, getMonthDays, toNestedArr } from './date-table.mjs';\nimport { useLocale } from '../../../hooks/use-locale/index.mjs';\nimport { rangeArr } from '../../time-picker/src/utils.mjs';\nimport { WEEK_DAYS } from '../../../constants/date.mjs';\nconst useDateTable = (props, emit) => {\n dayjs.extend(localeData);\n const firstDayOfWeek = dayjs.localeData().firstDayOfWeek();\n const {\n t,\n lang\n } = useLocale();\n const now = dayjs().locale(lang.value);\n const isInRange = computed(() => !!props.range && !!props.range.length);\n const rows = computed(() => {\n let days = [];\n if (isInRange.value) {\n const [start, end] = props.range;\n const currentMonthRange = rangeArr(end.date() - start.date() + 1).map(index => ({\n text: start.date() + index,\n type: \"current\"\n }));\n let remaining = currentMonthRange.length % 7;\n remaining = remaining === 0 ? 0 : 7 - remaining;\n const nextMonthRange = rangeArr(remaining).map((_, index) => ({\n text: index + 1,\n type: \"next\"\n }));\n days = currentMonthRange.concat(nextMonthRange);\n } else {\n const firstDay = props.date.startOf(\"month\").day();\n const prevMonthDays = getPrevMonthLastDays(props.date, (firstDay - firstDayOfWeek + 7) % 7).map(day => ({\n text: day,\n type: \"prev\"\n }));\n const currentMonthDays = getMonthDays(props.date).map(day => ({\n text: day,\n type: \"current\"\n }));\n days = [...prevMonthDays, ...currentMonthDays];\n const remaining = 7 - (days.length % 7 || 7);\n const nextMonthDays = rangeArr(remaining).map((_, index) => ({\n text: index + 1,\n type: \"next\"\n }));\n days = days.concat(nextMonthDays);\n }\n return toNestedArr(days);\n });\n const weekDays = computed(() => {\n const start = firstDayOfWeek;\n if (start === 0) {\n return WEEK_DAYS.map(_ => t(`el.datepicker.weeks.${_}`));\n } else {\n return WEEK_DAYS.slice(start).concat(WEEK_DAYS.slice(0, start)).map(_ => t(`el.datepicker.weeks.${_}`));\n }\n });\n const getFormattedDate = (day, type) => {\n switch (type) {\n case \"prev\":\n return props.date.startOf(\"month\").subtract(1, \"month\").date(day);\n case \"next\":\n return props.date.startOf(\"month\").add(1, \"month\").date(day);\n case \"current\":\n return props.date.date(day);\n }\n };\n const handlePickDay = ({\n text,\n type\n }) => {\n const date = getFormattedDate(text, type);\n emit(\"pick\", date);\n };\n const getSlotData = ({\n text,\n type\n }) => {\n const day = getFormattedDate(text, type);\n return {\n isSelected: day.isSame(props.selectedDay),\n type: `${type}-month`,\n day: day.format(\"YYYY-MM-DD\"),\n date: day.toDate()\n };\n };\n return {\n now,\n isInRange,\n rows,\n weekDays,\n getFormattedDate,\n handlePickDay,\n getSlotData\n };\n};\nexport { useDateTable };","map":{"version":3,"names":["useDateTable","props","emit","dayjs","extend","localeData","firstDayOfWeek","t","lang","useLocale","now","locale","value","isInRange","computed","range","length","rows","days","start","end","currentMonthRange","rangeArr","date","map","index","text","type","remaining","nextMonthRange","_","concat","firstDay","startOf","day","prevMonthDays","getPrevMonthLastDays","currentMonthDays","getMonthDays","nextMonthDays","toNestedArr","weekDays","WEEK_DAYS","slice","getFormattedDate","subtract","add","handlePickDay","getSlotData","isSelected","isSame","selectedDay","format","toDate"],"sources":["../../../../../../packages/components/calendar/src/use-date-table.ts"],"sourcesContent":["import { computed } from 'vue'\nimport dayjs from 'dayjs'\nimport localeData from 'dayjs/plugin/localeData.js'\nimport { useLocale } from '@element-plus/hooks'\nimport { rangeArr } from '@element-plus/components/time-picker'\nimport { WEEK_DAYS } from '@element-plus/constants'\nimport { getMonthDays, getPrevMonthLastDays, toNestedArr } from './date-table'\n\nimport type { SetupContext } from 'vue'\nimport type { Dayjs } from 'dayjs'\nimport type {\n CalendarDateCell,\n CalendarDateCellType,\n DateTableEmits,\n DateTableProps,\n} from './date-table'\n\nexport const useDateTable = (\n props: DateTableProps,\n emit: SetupContext<DateTableEmits>['emit']\n) => {\n dayjs.extend(localeData)\n // https://day.js.org/docs/en/i18n/locale-data\n const firstDayOfWeek: number = dayjs.localeData().firstDayOfWeek()\n\n const { t, lang } = useLocale()\n const now = dayjs().locale(lang.value)\n\n const isInRange = computed(() => !!props.range && !!props.range.length)\n\n const rows = computed(() => {\n let days: CalendarDateCell[] = []\n if (isInRange.value) {\n const [start, end] = props.range!\n const currentMonthRange: CalendarDateCell[] = rangeArr(\n end.date() - start.date() + 1\n ).map((index) => ({\n text: start.date() + index,\n type: 'current',\n }))\n\n let remaining = currentMonthRange.length % 7\n remaining = remaining === 0 ? 0 : 7 - remaining\n const nextMonthRange: CalendarDateCell[] = rangeArr(remaining).map(\n (_, index) => ({\n text: index + 1,\n type: 'next',\n })\n )\n days = currentMonthRange.concat(nextMonthRange)\n } else {\n const firstDay = props.date.startOf('month').day()\n const prevMonthDays: CalendarDateCell[] = getPrevMonthLastDays(\n props.date,\n (firstDay - firstDayOfWeek + 7) % 7\n ).map((day) => ({\n text: day,\n type: 'prev',\n }))\n const currentMonthDays: CalendarDateCell[] = getMonthDays(props.date).map(\n (day) => ({\n text: day,\n type: 'current',\n })\n )\n days = [...prevMonthDays, ...currentMonthDays]\n const remaining = 7 - (days.length % 7 || 7)\n const nextMonthDays: CalendarDateCell[] = rangeArr(remaining).map(\n (_, index) => ({\n text: index + 1,\n type: 'next',\n })\n )\n days = days.concat(nextMonthDays)\n }\n return toNestedArr(days)\n })\n\n const weekDays = computed(() => {\n const start = firstDayOfWeek\n if (start === 0) {\n return WEEK_DAYS.map((_) => t(`el.datepicker.weeks.${_}`))\n } else {\n return WEEK_DAYS.slice(start)\n .concat(WEEK_DAYS.slice(0, start))\n .map((_) => t(`el.datepicker.weeks.${_}`))\n }\n })\n\n const getFormattedDate = (day: number, type: CalendarDateCellType): Dayjs => {\n switch (type) {\n case 'prev':\n return props.date.startOf('month').subtract(1, 'month').date(day)\n case 'next':\n return props.date.startOf('month').add(1, 'month').date(day)\n case 'current':\n return props.date.date(day)\n }\n }\n\n const handlePickDay = ({ text, type }: CalendarDateCell) => {\n const date = getFormattedDate(text, type)\n emit('pick', date)\n }\n\n const getSlotData = ({ text, type }: CalendarDateCell) => {\n const day = getFormattedDate(text, type)\n return {\n isSelected: day.isSame(props.selectedDay),\n type: `${type}-month`,\n day: day.format('YYYY-MM-DD'),\n date: day.toDate(),\n }\n }\n\n return {\n now,\n isInRange,\n rows,\n weekDays,\n getFormattedDate,\n handlePickDay,\n getSlotData,\n }\n}\n"],"mappings":";;;;;;;;;;AAOY,MAACA,YAAY,GAAGA,CAACC,KAAK,EAAEC,IAAI,KAAK;EAC3CC,KAAK,CAACC,MAAM,CAACC,UAAU,CAAC;EACxB,MAAMC,cAAc,GAAGH,KAAK,CAACE,UAAU,EAAE,CAACC,cAAc,EAAE;EAC1D,MAAM;IAAEC,CAAC;IAAEC;EAAI,CAAE,GAAGC,SAAS,EAAE;EAC/B,MAAMC,GAAG,GAAGP,KAAK,EAAE,CAACQ,MAAM,CAACH,IAAI,CAACI,KAAK,CAAC;EACtC,MAAMC,SAAS,GAAGC,QAAQ,CAAC,MAAM,CAAC,CAACb,KAAK,CAACc,KAAK,IAAI,CAAC,CAACd,KAAK,CAACc,KAAK,CAACC,MAAM,CAAC;EACvE,MAAMC,IAAI,GAAGH,QAAQ,CAAC,MAAM;IAC1B,IAAII,IAAI,GAAG,EAAE;IACb,IAAIL,SAAS,CAACD,KAAK,EAAE;MACnB,MAAM,CAACO,KAAK,EAAEC,GAAG,CAAC,GAAGnB,KAAK,CAACc,KAAK;MAChC,MAAMM,iBAAiB,GAAGC,QAAQ,CAACF,GAAG,CAACG,IAAI,EAAE,GAAGJ,KAAK,CAACI,IAAI,EAAE,GAAG,CAAC,CAAC,CAACC,GAAG,CAAEC,KAAK,KAAM;QAChFC,IAAI,EAAEP,KAAK,CAACI,IAAI,EAAE,GAAGE,KAAK;QAC1BE,IAAI,EAAE;MACd,CAAO,CA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