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 lines
13 KiB

{"ast":null,"code":"import { defineComponent, ref, computed, openBlock, createBlock, unref, withCtx, normalizeClass, resolveDynamicComponent, createCommentVNode, createElementBlock, Fragment, renderList } from 'vue';\nimport dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat.js';\nimport { ElSelect } from '../../select/index.mjs';\nimport { ElIcon } from '../../icon/index.mjs';\nimport { timeSelectProps } from './time-select.mjs';\nimport { parseTime, formatTime, compareTime, nextTime } from './utils.mjs';\nimport _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';\nimport { useNamespace } from '../../../hooks/use-namespace/index.mjs';\nimport { useFormDisabled } from '../../form/src/hooks/use-form-common-props.mjs';\nimport { useLocale } from '../../../hooks/use-locale/index.mjs';\nconst __default__ = defineComponent({\n name: \"ElTimeSelect\"\n});\nconst _sfc_main = /* @__PURE__ */defineComponent({\n ...__default__,\n props: timeSelectProps,\n emits: [\"change\", \"blur\", \"focus\", \"clear\", \"update:modelValue\"],\n setup(__props, {\n expose\n }) {\n const props = __props;\n dayjs.extend(customParseFormat);\n const {\n Option: ElOption\n } = ElSelect;\n const nsInput = useNamespace(\"input\");\n const select = ref();\n const _disabled = useFormDisabled();\n const {\n lang\n } = useLocale();\n const value = computed(() => props.modelValue);\n const start = computed(() => {\n const time = parseTime(props.start);\n return time ? formatTime(time) : null;\n });\n const end = computed(() => {\n const time = parseTime(props.end);\n return time ? formatTime(time) : null;\n });\n const step = computed(() => {\n const time = parseTime(props.step);\n return time ? formatTime(time) : null;\n });\n const minTime = computed(() => {\n const time = parseTime(props.minTime || \"\");\n return time ? formatTime(time) : null;\n });\n const maxTime = computed(() => {\n const time = parseTime(props.maxTime || \"\");\n return time ? formatTime(time) : null;\n });\n const items = computed(() => {\n var _a;\n const result = [];\n const push = (formattedValue, rawValue) => {\n result.push({\n value: formattedValue,\n disabled: compareTime(rawValue, minTime.value || \"-1:-1\") <= 0 || compareTime(rawValue, maxTime.value || \"100:100\") >= 0\n });\n };\n if (props.start && props.end && props.step) {\n let current = start.value;\n let currentTime;\n while (current && end.value && compareTime(current, end.value) <= 0) {\n currentTime = dayjs(current, \"HH:mm\").locale(lang.value).format(props.format);\n push(currentTime, current);\n current = nextTime(current, step.value);\n }\n if (props.includeEndTime && end.value && ((_a = result[result.length - 1]) == null ? void 0 : _a.value) !== end.value) {\n const formattedValue = dayjs(end.value, \"HH:mm\").locale(lang.value).format(props.format);\n push(formattedValue, end.value);\n }\n }\n return result;\n });\n const blur = () => {\n var _a, _b;\n (_b = (_a = select.value) == null ? void 0 : _a.blur) == null ? void 0 : _b.call(_a);\n };\n const focus = () => {\n var _a, _b;\n (_b = (_a = select.value) == null ? void 0 : _a.focus) == null ? void 0 : _b.call(_a);\n };\n expose({\n blur,\n focus\n });\n return (_ctx, _cache) => {\n return openBlock(), createBlock(unref(ElSelect), {\n ref_key: \"select\",\n ref: select,\n \"model-value\": unref(value),\n disabled: unref(_disabled),\n clearable: _ctx.clearable,\n \"clear-icon\": _ctx.clearIcon,\n size: _ctx.size,\n effect: _ctx.effect,\n placeholder: _ctx.placeholder,\n \"default-first-option\": \"\",\n filterable: _ctx.editable,\n \"empty-values\": _ctx.emptyValues,\n \"value-on-clear\": _ctx.valueOnClear,\n \"onUpdate:modelValue\": event => _ctx.$emit(\"update:modelValue\", event),\n onChange: event => _ctx.$emit(\"change\", event),\n onBlur: event => _ctx.$emit(\"blur\", event),\n onFocus: event => _ctx.$emit(\"focus\", event),\n onClear: () => _ctx.$emit(\"clear\")\n }, {\n prefix: withCtx(() => [_ctx.prefixIcon ? (openBlock(), createBlock(unref(ElIcon), {\n key: 0,\n class: normalizeClass(unref(nsInput).e(\"prefix-icon\"))\n }, {\n default: withCtx(() => [(openBlock(), createBlock(resolveDynamicComponent(_ctx.prefixIcon)))]),\n _: 1\n }, 8, [\"class\"])) : createCommentVNode(\"v-if\", true)]),\n default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(unref(items), item => {\n return openBlock(), createBlock(unref(ElOption), {\n key: item.value,\n label: item.value,\n value: item.value,\n disabled: item.disabled\n }, null, 8, [\"label\", \"value\", \"disabled\"]);\n }), 128))]),\n _: 1\n }, 8, [\"model-value\", \"disabled\", \"clearable\", \"clear-icon\", \"size\", \"effect\", \"placeholder\", \"filterable\", \"empty-values\", \"value-on-clear\", \"onUpdate:modelValue\", \"onChange\", \"onBlur\", \"onFocus\", \"onClear\"]);\n };\n }\n});\nvar TimeSelect = /* @__PURE__ */_export_sfc(_sfc_main, [[\"__file\", \"time-select.vue\"]]);\nexport { TimeSelect as default };","map":{"version":3,"names":["name","dayjs","extend","customParseFormat","Option","ElOption","ElSelect","nsInput","useNamespace","select","ref","_disabled","useFormDisabled","lang","useLocale","value","computed","props","modelValue","start","time","parseTime","formatTime","end","step","minTime","maxTime","items","_a","result","push","formattedValue","rawValue","disabled","compareTime","current","currentTime","locale","format","nextTime","includeEndTime","length","blur","_b","call","focus","expose","_ctx","_cache","openBlock","createBlock","unref","ref_key"],"sources":["../../../../../../packages/components/time-select/src/time-select.vue"],"sourcesContent":["<template>\n <el-select\n ref=\"select\"\n :model-value=\"value\"\n :disabled=\"_disabled\"\n :clearable=\"clearable\"\n :clear-icon=\"clearIcon\"\n :size=\"size\"\n :effect=\"effect\"\n :placeholder=\"placeholder\"\n default-first-option\n :filterable=\"editable\"\n :empty-values=\"emptyValues\"\n :value-on-clear=\"valueOnClear\"\n @update:model-value=\"(event) => $emit('update:modelValue', event)\"\n @change=\"(event) => $emit('change', event)\"\n @blur=\"(event) => $emit('blur', event)\"\n @focus=\"(event) => $emit('focus', event)\"\n @clear=\"() => $emit('clear')\"\n >\n <el-option\n v-for=\"item in items\"\n :key=\"item.value\"\n :label=\"item.value\"\n :value=\"item.value\"\n :disabled=\"item.disabled\"\n />\n <template #prefix>\n <el-icon v-if=\"prefixIcon\" :class=\"nsInput.e('prefix-icon')\">\n <component :is=\"prefixIcon\" />\n </el-icon>\n </template>\n </el-select>\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed, ref } from 'vue'\nimport dayjs from 'dayjs'\nimport customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport ElSelect from '@element-plus/components/select'\nimport { useFormDisabled } from '@element-plus/components/form'\nimport ElIcon from '@element-plus/components/icon'\nimport { useLocale, useNamespace } from '@element-plus/hooks'\nimport { timeSelectProps } from './time-select'\nimport { compareTime, formatTime, nextTime, parseTime } from './utils'\n\ndayjs.extend(customParseFormat)\n\nconst { Option: ElOption } = ElSelect\n\ndefineOptions({\n name: 'ElTimeSelect',\n})\n\ndefineEmits(['change', 'blur', 'focus', 'clear', 'update:modelValue'])\n\nconst props = defineProps(timeSelectProps)\n\nconst nsInput = useNamespace('input')\nconst select = ref<typeof ElSelect>()\n\nconst _disabled = useFormDisabled()\nconst { lang } = useLocale()\n\nconst value = computed(() => props.modelValue)\nconst start = computed(() => {\n const time = parseTime(props.start)\n return time ? formatTime(time) : null\n})\n\nconst end = computed(() => {\n const time = parseTime(props.end)\n return time ? formatTime(time) : null\n})\n\nconst step = computed(() => {\n const time = parseTime(props.step)\n return time ? formatTime(time) : null\n})\n\nconst minTime = computed(() => {\n const time = parseTime(props.minTime || '')\n return time ? formatTime(time) : null\n})\n\nconst maxTime = computed(() => {\n const time = parseTime(props.maxTime || '')\n return time ? formatTime(time) : null\n})\n\nconst items = computed(() => {\n const result: { value: string; disabled: boolean }[] = []\n const push = (formattedValue: string, rawValue: string) => {\n result.push({\n value: formattedValue,\n disabled:\n compareTime(rawValue, minTime.value || '-1:-1') <= 0 ||\n compareTime(rawValue, maxTime.value || '100:100') >= 0,\n })\n }\n\n if (props.start && props.end && props.step) {\n let current = start.value\n let currentTime: string\n while (current && end.value && compareTime(current, end.value) <= 0) {\n currentTime = dayjs(current, 'HH:mm')\n .locale(lang.value)\n .format(props.format)\n push(currentTime, current)\n current = nextTime(current, step.value!)\n }\n if (\n props.includeEndTime &&\n end.value &&\n result[result.length - 1]?.value !== end.value\n ) {\n const formattedValue = dayjs(end.value, 'HH:mm')\n .locale(lang.value)\n .format(props.format)\n push(formattedValue, end.value)\n }\n }\n return result\n})\n\nconst blur = () => {\n select.value?.blur?.()\n}\n\nconst focus = () => {\n select.value?.focus?.()\n}\n\ndefineExpose({\n /**\n * @description focus the Input component\n */\n blur,\n /**\n * @description blur the Input component\n */\n focus,\n})\n</script>\n"],"mappings":";;;;;;;;;;;mCAkDc;EACZA,IAAM;AACR;;;;;;;;;IANAC,KAAA,CAAMC,MAAA,CAAOC,iBAAiB;IAExB;MAAEC,MAAQ,EAAAC;IAAA,CAAa,GAAAC,QAAA;IAUvB,MAAAC,OAAA,GAAUC,YAAA,CAAa,OAAO;IACpC,MAAMC,MAAA,GAASC,GAAqB;IAEpC,MAAMC,SAAA,GAAYC,eAAgB;IAC5B;MAAEC;IAAK,IAAIC,SAAU;IAE3B,MAAMC,KAAQ,GAAAC,QAAA,CAAS,MAAMC,KAAA,CAAMC,UAAU;IACvC,MAAAC,KAAA,GAAQH,QAAA,CAAS,MAAM;MACrB,MAAAI,IAAA,GAAOC,SAAU,CAAAJ,KAAA,CAAME,KAAK;MAC3B,OAAAC,IAAA,GAAOE,UAAW,CAAAF,IAAI,CAAI;IAAA,CAClC;IAEK,MAAAG,GAAA,GAAMP,QAAA,CAAS,MAAM;MACnB,MAAAI,IAAA,GAAOC,SAAU,CAAAJ,KAAA,CAAMM,GAAG;MACzB,OAAAH,IAAA,GAAOE,UAAW,CAAAF,IAAI,CAAI;IAAA,CAClC;IAEK,MAAAI,IAAA,GAAOR,QAAA,CAAS,MAAM;MACpB,MAAAI,IAAA,GAAOC,SAAU,CAAAJ,KAAA,CAAMO,IAAI;MAC1B,OAAAJ,IAAA,GAAOE,UAAW,CAAAF,IAAI,CAAI;IAAA,CAClC;IAEK,MAAAK,OAAA,GAAUT,QAAA,CAAS,MAAM;MAC7B,MAAMI,IAAO,GAAAC,SAAA,CAAUJ,KAAM,CAAA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