@opensig/opendesign
Version:
58 lines (57 loc) • 2.35 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const dayjs = require("dayjs");
const customParseFormat = require("dayjs/plugin/customParseFormat.js");
const is = require("../_utils/is.js");
function computeRangeState({ cell, unit, rangeStart, rangeEnd, anchorDate, hoverDate }) {
if (rangeStart && rangeEnd) {
return {
isRangeStart: cell.isSame(rangeStart, unit),
isRangeEnd: cell.isSame(rangeEnd, unit),
isInRange: cell.isAfter(rangeStart, unit) && cell.isBefore(rangeEnd, unit)
};
}
if (anchorDate) {
if (hoverDate) {
const [effStart, effEnd] = hoverDate.isBefore(anchorDate, unit) ? [hoverDate, anchorDate] : [anchorDate, hoverDate];
return {
isRangeStart: cell.isSame(effStart, unit),
isRangeEnd: cell.isSame(effEnd, unit),
isInRange: cell.isAfter(effStart, unit) && cell.isBefore(effEnd, unit)
};
}
return { isRangeStart: cell.isSame(anchorDate, unit), isRangeEnd: false, isInRange: false };
}
return { isRangeStart: false, isRangeEnd: false, isInRange: false };
}
dayjs.extend(customParseFormat);
const YEAR_VIEW_STEP = 10;
function parseValue(value) {
if (is.isNil(value) || value === "") return null;
if (typeof value === "number" || value instanceof Date) {
const _d = dayjs(value);
return _d.isValid() ? _d : null;
}
const d = dayjs(value);
return d.isValid() ? d : null;
}
function isMonthDisabled(year, month, options) {
const { disabledMonth, minDate, maxDate } = options;
const d = dayjs().year(year).month(month);
if (minDate && d.endOf("month").isBefore(minDate, "day")) return true;
if (maxDate && d.startOf("month").isAfter(maxDate, "day")) return true;
if (disabledMonth && disabledMonth({ date: d.toDate(), year, month })) return true;
return false;
}
function isYearDisabled(year, options) {
const { disabledYear, minDate, maxDate } = options;
if (minDate && year < minDate.year()) return true;
if (maxDate && year > maxDate.year()) return true;
if (disabledYear && disabledYear({ date: dayjs().year(year).toDate(), year })) return true;
return false;
}
exports.YEAR_VIEW_STEP = YEAR_VIEW_STEP;
exports.computeRangeState = computeRangeState;
exports.isMonthDisabled = isMonthDisabled;
exports.isYearDisabled = isYearDisabled;
exports.parseValue = parseValue;