chore(editor): merge clamp functions (#10577)
Closes: [BS-2625](https://linear.app/affine-design/issue/BS-2625/合并clamp函数)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import { clamp, WithDisposable } from '@blocksuite/global/utils';
|
||||
import { isSameDay, isSameMonth, isToday } from 'date-fns';
|
||||
import {
|
||||
html,
|
||||
@@ -13,7 +13,7 @@ import { styleMap } from 'lit/directives/style-map.js';
|
||||
|
||||
import { arrowLeftIcon } from './icons.js';
|
||||
import { datePickerStyle } from './style.js';
|
||||
import { clamp, getMonthMatrix, toDate } from './utils.js';
|
||||
import { getMonthMatrix, toDate } from './utils.js';
|
||||
|
||||
const days = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
|
||||
const months = [
|
||||
@@ -522,7 +522,7 @@ export class DatePicker extends WithDisposable(LitElement) {
|
||||
}
|
||||
|
||||
openYearSelector() {
|
||||
this._yearCursor = clamp(this._minYear, this._maxYear, this.year);
|
||||
this._yearCursor = clamp(this.year, this._minYear, this._maxYear);
|
||||
this._mode = 'year';
|
||||
this._getYearMatrix();
|
||||
}
|
||||
|
||||
@@ -66,8 +66,3 @@ export function getMonthMatrix(maybeDate: MaybeDate) {
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
export function clamp(num1: number, num2: number, value: number) {
|
||||
const [min, max] = [num1, num2].sort((a, b) => a - b);
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user