@visactor/vtable-calendar 1.19.4 → 1.19.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/date-util.js +1 -1
- package/cjs/date-util.js.map +1 -1
- package/cjs/month-calendar.d.ts +2 -0
- package/cjs/month-calendar.js +17 -12
- package/cjs/month-calendar.js.map +1 -1
- package/cjs/table/table-option.d.ts +1 -1
- package/cjs/table/table-option.js +23 -13
- package/cjs/table/table-option.js.map +1 -1
- package/dist/vtable-calendar.js +264 -64
- package/dist/vtable-calendar.min.js +1 -1
- package/es/date-util.js +1 -1
- package/es/date-util.js.map +1 -1
- package/es/month-calendar.d.ts +2 -0
- package/es/month-calendar.js +17 -12
- package/es/month-calendar.js.map +1 -1
- package/es/table/table-option.d.ts +1 -1
- package/es/table/table-option.js +20 -14
- package/es/table/table-option.js.map +1 -1
- package/package.json +4 -4
package/cjs/date-util.js
CHANGED
|
@@ -23,7 +23,7 @@ function getRecords(startDate, endDate) {
|
|
|
23
23
|
}
|
|
24
24
|
const startYear = startDate.getFullYear(), startMonth = startDate.getMonth(), endYear = endDate.getFullYear(), endMonth = endDate.getMonth();
|
|
25
25
|
let year = startYear, month = startMonth;
|
|
26
|
-
for (;year
|
|
26
|
+
for (;year < endYear || year === endYear && month <= endMonth; ) {
|
|
27
27
|
const monthStartDate = new Date(year, month, 1), daysInMonth = (0, date_fns_1.getDaysInMonth)(monthStartDate);
|
|
28
28
|
let record, week = monthStartDate.getDay();
|
|
29
29
|
0 === records.length ? 0 === week ? (record = {
|
package/cjs/date-util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["date-util.ts"],"names":[],"mappings":";;;AAAA,uCAA4E;AAE5E,SAAgB,kBAAkB,CAAC,KAAW,EAAE,SAAiB;IAC/D,MAAM,SAAS,GAAG,IAAA,kBAAO,EAAC,KAAK,EAAE,CAAC,SAAS,CAAC,CAAC;IAC7C,SAAS,CAAC,OA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,EAAE;QACX,KAAK,CAAC;YACJ,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC;YAClB,MAAM;QACR,KAAK,CAAC;YACJ,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC;YAClB,MAAM;QACR,KAAK,CAAC;YACJ,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC;YAClB,MAAM;QACR,KAAK,CAAC;YACJ,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC;YAClB,MAAM;QACR,KAAK,CAAC;YACJ,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC;YAClB,MAAM;QACR,KAAK,CAAC;YACJ,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC;YAClB,MAAM;QACR,KAAK,CAAC;YACJ,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC;YAClB,MAAM;KACT;AACH,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAC1G,SAAgB,cAAc,CAAC,UAAkB;IAC/C,OAAO,YAAY,CAAC,UAAU,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;AACxD,CAAC;AAFD,wCAEC;AAED,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AACzE,SAAgB,gBAAgB,CAAC,YAAoB;IACnD,OAAO,cAAc,CAAC,YAAY,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;AAC9D,CAAC;AAFD,4CAEC","file":"date-util.js","sourcesContent":["import { addDays, getDaysInMonth, isAfter, lastDayOfMonth } from 'date-fns';\n\nexport function getStartAndEndDate(today: Date, daltaDays: number) {\n const startDate = addDays(today, -daltaDays);\n startDate.setDate(1);\n const endDate = lastDayOfMonth(addDays(today, daltaDays));\n return { startDate, endDate };\n}\n\n// export const defaultDayTitles = ['year', 'month', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nexport const defaultDayTitles = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nexport type DateRecordKeys = 'year' | 'month' | 'Sun' | 'Mon' | 'Tue' | 'Wed' | 'Thu' | 'Fri' | 'Sat';\nexport type DateRecord = Record<DateRecordKeys, number>;\n\nexport function getRecords(startDate: Date, endDate: Date) {\n const records: DateRecord[] = [];\n\n if (isAfter(startDate, endDate)) {\n const temp = startDate;\n startDate = endDate;\n endDate = temp;\n }\n\n const startYear = startDate.getFullYear();\n const startMonth = startDate.getMonth();\n\n const endYear = endDate.getFullYear();\n const endMonth = endDate.getMonth();\n\n let year = startYear;\n let month = startMonth;\n while (year < endYear || (year === endYear && month <= endMonth)) {\n const monthStartDate = new Date(year, month, 1);\n const daysInMonth = getDaysInMonth(monthStartDate);\n let week = monthStartDate.getDay();\n let record: DateRecord;\n if (records.length === 0) {\n if (week === 0) {\n record = { year, month } as DateRecord;\n records.push(record);\n } else if (month === 0) {\n record = { year: year - 1, month: 11 } as DateRecord;\n records.push(record);\n } else {\n record = { year, month: month - 1 } as DateRecord;\n records.push(record);\n }\n } else if (week === 0) {\n record = { year, month } as DateRecord;\n records.push(record);\n } else {\n record = records[records.length - 1];\n }\n\n for (let day = 1; day <= daysInMonth; day++) {\n if (week === 7) {\n week = 0;\n record = { year, month } as DateRecord;\n records.push(record);\n }\n setDate(record, week, day);\n week += 1;\n }\n\n month += 1;\n if (month === 12) {\n month = 0;\n year += 1;\n }\n }\n\n return records;\n}\n\nfunction setDate(record: DateRecord, day: number, date: number) {\n switch (day) {\n case 0:\n record.Sun = date;\n break;\n case 1:\n record.Mon = date;\n break;\n case 2:\n record.Tue = date;\n break;\n case 3:\n record.Wed = date;\n break;\n case 4:\n record.Thu = date;\n break;\n case 5:\n record.Fri = date;\n break;\n case 6:\n record.Sat = date;\n break;\n }\n}\n\nconst monthStrings = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\nexport function getMonthString(monthIndex: number) {\n return monthStrings[monthIndex % monthStrings.length];\n}\n\nconst weekdayStrings = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nexport function getWeekdayString(weekdayIndex: number) {\n return weekdayStrings[weekdayIndex % weekdayStrings.length];\n}\n"]}
|
package/cjs/month-calendar.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface CalendarConstructorOptions {
|
|
|
14
14
|
tableOptions?: ListTableConstructorOptions;
|
|
15
15
|
customEvents?: ICustomEvent[];
|
|
16
16
|
customEventOptions?: ICustomEventOptions;
|
|
17
|
+
showTitle?: boolean;
|
|
17
18
|
}
|
|
18
19
|
export declare class Calendar extends EventTarget {
|
|
19
20
|
container: HTMLElement;
|
|
@@ -34,6 +35,7 @@ export declare class Calendar extends EventTarget {
|
|
|
34
35
|
maxCol: number;
|
|
35
36
|
minCol: number;
|
|
36
37
|
customHandler: CustomEventHandler;
|
|
38
|
+
showToday: boolean;
|
|
37
39
|
constructor(container: HTMLElement, options?: CalendarConstructorOptions);
|
|
38
40
|
_createTable(): void;
|
|
39
41
|
getYearAndMonth(): any;
|
package/cjs/month-calendar.js
CHANGED
|
@@ -8,10 +8,13 @@ const vtable_1 = require("@visactor/vtable"), date_util_1 = require("./date-util
|
|
|
8
8
|
|
|
9
9
|
class Calendar extends vtable_1.EventTarget {
|
|
10
10
|
constructor(container, options) {
|
|
11
|
-
|
|
11
|
+
var _a;
|
|
12
|
+
super(), this.minCol = 0, this.showToday = !0, this.container = container, this.options = null != options ? options : {};
|
|
12
13
|
const {startDate: startDate, endDate: endDate, currentDate: currentDate, rangeDays: rangeDays} = this.options;
|
|
13
14
|
if (this.currentDate = null != currentDate ? currentDate : new Date, this.rangeDays = null != rangeDays ? rangeDays : 90,
|
|
14
|
-
|
|
15
|
+
this.showToday = null === (_a = this.options.showTitle) || void 0 === _a || _a,
|
|
16
|
+
startDate && endDate) this.startDate = startDate, this.endDate = endDate, (this.currentDate < this.startDate || this.currentDate > this.endDate) && (this.currentDate = this.startDate,
|
|
17
|
+
this.showToday = !1); else {
|
|
15
18
|
const {startDate: computedStartDate, endDate: computedEndDate} = (0, date_util_1.getStartAndEndDate)(this.currentDate, this.rangeDays);
|
|
16
19
|
this.startDate = null != startDate ? startDate : computedStartDate, this.endDate = null != endDate ? endDate : computedEndDate;
|
|
17
20
|
}
|
|
@@ -24,7 +27,7 @@ class Calendar extends vtable_1.EventTarget {
|
|
|
24
27
|
this.records = records;
|
|
25
28
|
const week = null != dayTitles ? dayTitles : date_util_1.defaultDayTitles;
|
|
26
29
|
this.maxCol = week.length - 1;
|
|
27
|
-
const option = (0, table_option_1.createTableOption)(week, this.currentDate, {
|
|
30
|
+
const option = (0, table_option_1.createTableOption)(week, date_util_1.defaultDayTitles, this.showToday ? this.currentDate : void 0, {
|
|
28
31
|
tableOptions: this.options.tableOptions,
|
|
29
32
|
containerWidth: this.container.clientWidth,
|
|
30
33
|
containerHeight: this.container.clientHeight
|
|
@@ -77,15 +80,17 @@ class Calendar extends vtable_1.EventTarget {
|
|
|
77
80
|
return super.on(type, listener);
|
|
78
81
|
}
|
|
79
82
|
_bindEvent() {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
if (this.table.internalProps.title) {
|
|
84
|
+
const titleComponent = this.table.internalProps.title.getComponentGraphic();
|
|
85
|
+
titleComponent.setAttributes({
|
|
86
|
+
cursor: "pointer",
|
|
87
|
+
childrenPickable: !1
|
|
88
|
+
}), this.titleClickHandler = (() => {
|
|
89
|
+
this.jumpToCurrentMonth({
|
|
90
|
+
duration: 500
|
|
91
|
+
});
|
|
92
|
+
}).bind(this), titleComponent.addEventListener("click", this.titleClickHandler);
|
|
93
|
+
}
|
|
89
94
|
this.table.on("click_cell", (e => {
|
|
90
95
|
const {target: target} = e;
|
|
91
96
|
"calendar-custom-event" === target._role ? this.fireListeners(type_1.CALENDAR_EVENT_TYPE.CALENDAR_CUSTOM_EVENT_CLICK, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["month-calendar.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAE1D,2CAA+E;AAE/E,uCAA6E;AAC7E,mCAAmD;AAEnD,uDAAyD;AAEzD,4DAA6D;AAM7D,uCAAmD;AAEnD,6CAA2C;AAgB3C,MAAa,QAAS,SAAQ,oBAAW;IAoBvC,YAAY,SAAsB,EAAE,OAAoC;QACtE,KAAK,EAAE,CAAC;QAJV,WAAM,GAAW,CAAC,CAAC;QAKjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;QAC7B,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAEpE,IAAI,CAAC,WAAW,GAAG,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,IAAI,IAAI,EAAE,CAAC;QAC7C,IAAI,CAAC,SAAS,GAAG,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,EAAE,CAAC;QACjC,IAAI,SAAS,IAAI,OAAO,EAAE;YACxB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;YAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACxB;aAAM;YACL,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,IAAA,8BAAkB,EACnF,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,SAAS,CACf,CAAC;YACF,IAAI,CAAC,SAAS,GAAG,SAAS,a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AS,CAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YAC5B,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA1TD,4BA0TC","file":"month-calendar.js","sourcesContent":["import { ListTable, EventTarget } from '@visactor/vtable';\nimport type { DateRecord, DateRecordKeys } from './date-util';\nimport { defaultDayTitles, getRecords, getStartAndEndDate } from './date-util';\nimport { bindDebugTool } from '../../vtable/src/scenegraph/debug-tool';\nimport { add, differenceInDays, previousSunday, startOfDay } from 'date-fns';\nimport { getMonthCustomStyleRange } from './style';\nimport type { TYPES, ListTableConstructorOptions } from '@visactor/vtable';\nimport { createTableOption } from './table/table-option';\nimport type { ICustomEvent, ICustomEventOptions, IEventData } from './custom/custom-handler';\nimport { CustomEventHandler } from './custom/custom-handler';\nimport type {\n CalendarEventHandlersEventArgumentMap,\n CalendarEventHandlersReturnMap,\n CalendarEventListener\n} from './event/type';\nimport { CALENDAR_EVENT_TYPE } from './event/type';\nimport type { EventListenerId } from '@visactor/vtable/es/ts-types';\nimport { isArray } from '@visactor/vutils';\n\nexport interface CalendarConstructorOptions {\n startDate?: Date;\n endDate?: Date;\n currentDate?: Date;\n rangeDays?: number;\n\n dayTitles?: [string, string, string, string, string, string, string];\n\n tableOptions?: ListTableConstructorOptions;\n\n customEvents?: ICustomEvent[];\n customEventOptions?: ICustomEventOptions;\n}\n\nexport class Calendar extends EventTarget {\n container: HTMLElement;\n options: CalendarConstructorOptions;\n table: ListTable;\n startDate: Date;\n endDate: Date;\n currentDate: Date;\n rangeDays: number;\n tableStartDate: Date;\n records: DateRecord[];\n currentMonthCellRanges: { range: TYPES.CellRange }[];\n currentMonth: number;\n currentYear: number;\n\n titleClickHandler: () => void;\n\n maxCol: number;\n minCol: number = 0;\n customHandler: CustomEventHandler;\n\n constructor(container: HTMLElement, options?: CalendarConstructorOptions) {\n super();\n this.container = container;\n this.options = options ?? {};\n const { startDate, endDate, currentDate, rangeDays } = this.options;\n\n this.currentDate = currentDate ?? new Date();\n this.rangeDays = rangeDays ?? 90;\n if (startDate && endDate) {\n this.startDate = startDate;\n this.endDate = endDate;\n } else {\n const { startDate: computedStartDate, endDate: computedEndDate } = getStartAndEndDate(\n this.currentDate,\n this.rangeDays\n );\n this.startDate = startDate ?? computedStartDate;\n this.endDate = endDate ?? computedEndDate;\n }\n this.tableStartDate = this.startDate.getDay() === 0 ? this.startDate : previousSunday(this.startDate);\n\n this.customHandler = new CustomEventHandler(this, options?.customEventOptions);\n\n this._createTable();\n\n this._bindEvent();\n\n if (this.options.customEvents) {\n this.addCustomEvents(this.options.customEvents);\n }\n }\n\n _createTable() {\n const { dayTitles } = this.options;\n\n const records = getRecords(this.startDate, this.endDate);\n this.records = records;\n\n const week = (dayTitles ?? defaultDayTitles) as DateRecordKeys[];\n this.maxCol = week.length - 1;\n const option = createTableOption(week, this.currentDate, {\n tableOptions: this.options.tableOptions,\n containerWidth: this.container.clientWidth,\n containerHeight: this.container.clientHeight\n });\n option.records = records;\n option.container = this.container;\n (option as any)._calendar = this;\n\n const tableInstance = new ListTable(option);\n this.table = tableInstance;\n\n tableInstance.addEventListener('scroll', () => {\n const record: DateRecord = this.getYearAndMonth();\n if (!record) {\n return;\n }\n if (!record.Sun) {\n // top\n this._updateMonthCustomStyle(this.startDate.getFullYear(), this.startDate.getMonth());\n return;\n }\n const firstDateInWeek = new Date(record.year, record.month, record.Sun);\n const lastDateInNextWeek = add(firstDateInWeek, {\n days: 13\n });\n this._updateMonthCustomStyle(lastDateInNextWeek.getFullYear(), lastDateInNextWeek.getMonth());\n });\n\n tableInstance.addEventListener('scroll_vertical_end', () => {\n this._updateMonthCustomStyle(this.endDate.getFullYear(), this.endDate.getMonth());\n });\n\n this.jumpToCurrentMonth();\n\n // bindDebugTool(tableInstance.scenegraph.stage as any, {\n // customGrapicKeys: ['col', 'row']\n // });\n }\n\n getYearAndMonth() {\n const x = this.table.tableX + 10; // buffer\n const y = this.table.tableY + this.table.getFrozenRowsHeight() + 10; // buffer\n const topRow = this.table.getCellAtRelativePosition(x, y);\n const { row } = topRow;\n const record = this.table.getCellRawRecord(0, row);\n return record;\n }\n\n jumpToDate(date: Date, animation?: boolean | TYPES.ITableAnimationOption) {\n date = startOfDay(date);\n const dataIndex = Math.floor((differenceInDays(date, this.tableStartDate) + 1) / 7);\n this.table.scrollToCell(\n {\n col: 0,\n row: dataIndex + 1\n },\n animation\n );\n\n this._updateMonthCustomStyle(date.getFullYear(), date.getMonth());\n }\n\n jumpToCurrentMonth(animation?: boolean | TYPES.ITableAnimationOption) {\n // scroll to current month\n const topDate = new Date(this.currentDate.getTime());\n topDate.setDate(1);\n this.jumpToDate(topDate, animation);\n }\n\n _updateMonthCustomStyle(year: number, month: number) {\n if (this.currentMonth === month && this.currentYear === year) {\n return;\n }\n\n // clear current\n this.currentMonthCellRanges?.forEach(range => {\n this.table.arrangeCustomCellStyle(range, null);\n });\n\n this.currentMonth = month;\n this.currentYear = year;\n this.currentMonthCellRanges = getMonthCustomStyleRange(year, month, this.tableStartDate, this.records);\n this.currentMonthCellRanges.forEach(range => {\n this.table.arrangeCustomCellStyle(range, 'current-month');\n });\n }\n\n // @ts-ignore\n fireListeners<TYPE extends keyof CalendarEventHandlersEventArgumentMap>(\n type: TYPE,\n event: CalendarEventHandlersEventArgumentMap[TYPE]\n ): CalendarEventHandlersReturnMap[TYPE][] {\n // 调用父类的方法\n return super.fireListeners(type as any, event as any);\n }\n\n // @ts-ignore\n on<TYPE extends keyof CalendarEventHandlersEventArgumentMap>(\n type: TYPE,\n listener: CalendarEventListener<TYPE>\n ): EventListenerId {\n // 调用父类的方法\n return super.on(type as any, listener as any);\n }\n\n _bindEvent() {\n // click title jump to current month\n const titleComponent = this.table.internalProps.title.getComponentGraphic();\n titleComponent.setAttributes({\n cursor: 'pointer',\n // hack for cursor\n childrenPickable: false\n });\n this.titleClickHandler = (() => {\n this.jumpToCurrentMonth({\n duration: 500\n });\n }).bind(this);\n titleComponent.addEventListener('click', this.titleClickHandler);\n\n this.table.on('click_cell', e => {\n const { target } = e;\n if ((target as any)._role === 'calendar-custom-event') {\n this.fireListeners(CALENDAR_EVENT_TYPE.CALENDAR_CUSTOM_EVENT_CLICK, {\n tableEvent: e,\n date: this.getCellDate(e.col, e.row),\n customEvent: (target as any)._customEvent\n });\n } else if (!this.table.isHeader(e.col, e.row)) {\n this.fireListeners(CALENDAR_EVENT_TYPE.CALENDAR_DATE_CLICK, {\n tableEvent: e,\n date: this.getCellDate(e.col, e.row)\n });\n }\n });\n\n this.table.on('selected_cell', e => {\n if (!this.table.isHeader(e.col, e.row)) {\n this.fireListeners(CALENDAR_EVENT_TYPE.SELECTED_DATE, {\n tableEvent: e,\n date: this.getCellDate(e.col, e.row)\n });\n }\n });\n\n this.table.on('selected_clear', () => {\n this.fireListeners(CALENDAR_EVENT_TYPE.SELECTED_DATE_CLEAR, undefined);\n });\n\n this.table.on('drag_select_end', e => {\n const { cells } = e;\n const dates: Date[] = [];\n cells.map(row => {\n row.map(cell => {\n if (!this.table.isHeader(cell.col, cell.row)) {\n dates.push(this.getCellDate(cell.col, cell.row));\n }\n });\n });\n this.fireListeners(CALENDAR_EVENT_TYPE.DRAG_SELECT_DATE_END, {\n tableEvent: e,\n dates\n });\n });\n }\n\n release() {\n this.table.release();\n }\n\n getCellLocation(date: Date) {\n date = startOfDay(date);\n const dataIndex = Math.floor((differenceInDays(date, this.tableStartDate) + 1) / 7);\n const row = dataIndex + 1;\n const col = date.getDay();\n\n return {\n row,\n col\n };\n }\n\n getCellDate(col: number, row: number) {\n const startDate = add(this.tableStartDate, {\n days: (row - 1) * 7 + col\n });\n return startDate;\n }\n\n get selectedDate(): { date: Date; col: number; row: number }[] {\n const cells = this.table.getSelectedCellInfos();\n if (!isArray(cells) || cells.length === 0) {\n return [];\n }\n const dates: { date: Date; col: number; row: number }[] = [];\n cells.map(row => {\n row.map(cell => {\n if (!this.table.isHeader(cell.col, cell.row)) {\n dates.push({\n date: this.getCellDate(cell.col, cell.row),\n col: cell.col,\n row: cell.row\n });\n }\n });\n });\n\n return dates;\n }\n\n addCustomEvent(event: ICustomEvent) {\n this.customHandler.addEvent(event);\n this.table.scenegraph.updateNextFrame();\n }\n\n removeCustomEvent(id: string) {\n this.customHandler.removeEvents([id]);\n this.table.scenegraph.updateNextFrame();\n }\n\n updateCustomEvent(event: ICustomEvent) {\n this.customHandler.updateEvents([event]);\n this.table.scenegraph.updateNextFrame();\n }\n\n addCustomEvents(events: ICustomEvent[]) {\n this.customHandler.addEvents(events);\n this.table.scenegraph.updateNextFrame();\n }\n\n removeCustomEvents(ids: string[]) {\n this.customHandler.removeEvents(ids);\n this.table.scenegraph.updateNextFrame();\n }\n\n updateCustomEvents(events: ICustomEvent[]) {\n this.customHandler.updateEvents(events);\n this.table.scenegraph.updateNextFrame();\n }\n\n getCellCustomEventByDate(date: Date) {\n const location = this.getCellLocation(date);\n return this.getCellCustomEventByLocation(location.col, location.row);\n }\n\n getCellCustomEventByLocation(col: number, row: number) {\n const cellEvent = this.customHandler.getCellCustomEvent(col, row);\n const events: IEventData[] = [];\n cellEvent?.keys.forEach(key => {\n events.push(cellEvent.values[key]);\n });\n return events;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["month-calendar.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAE1D,2CAA+E;AAE/E,uCAA6E;AAC7E,mCAAmD;AAEnD,uDAAyD;AAEzD,4DAA6D;AAM7D,uCAAmD;AAEnD,6CAA2C;AAiB3C,MAAa,QAAS,SAAQ,oBAAW;IAqBvC,YAAY,SAAsB,EAAE,OAAoC;;QACtE,KAAK,EAAE,CAAC;QALV,WAAM,GAAW,CAAC,CAAC;QAEnB,cAAS,GAAY,IAAI,CAAC;QAIxB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OA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OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAxUD,4BAwUC","file":"month-calendar.js","sourcesContent":["import { ListTable, EventTarget } from '@visactor/vtable';\nimport type { DateRecord, DateRecordKeys } from './date-util';\nimport { defaultDayTitles, getRecords, getStartAndEndDate } from './date-util';\nimport { bindDebugTool } from '../../vtable/src/scenegraph/debug-tool';\nimport { add, differenceInDays, previousSunday, startOfDay } from 'date-fns';\nimport { getMonthCustomStyleRange } from './style';\nimport type { TYPES, ListTableConstructorOptions } from '@visactor/vtable';\nimport { createTableOption } from './table/table-option';\nimport type { ICustomEvent, ICustomEventOptions, IEventData } from './custom/custom-handler';\nimport { CustomEventHandler } from './custom/custom-handler';\nimport type {\n CalendarEventHandlersEventArgumentMap,\n CalendarEventHandlersReturnMap,\n CalendarEventListener\n} from './event/type';\nimport { CALENDAR_EVENT_TYPE } from './event/type';\nimport type { EventListenerId } from '@visactor/vtable/es/ts-types';\nimport { isArray } from '@visactor/vutils';\n\nexport interface CalendarConstructorOptions {\n startDate?: Date;\n endDate?: Date;\n currentDate?: Date;\n rangeDays?: number;\n\n dayTitles?: [string, string, string, string, string, string, string];\n\n tableOptions?: ListTableConstructorOptions;\n\n customEvents?: ICustomEvent[];\n customEventOptions?: ICustomEventOptions;\n showTitle?: boolean;\n}\n\nexport class Calendar extends EventTarget {\n container: HTMLElement;\n options: CalendarConstructorOptions;\n table: ListTable;\n startDate: Date;\n endDate: Date;\n currentDate: Date;\n rangeDays: number;\n tableStartDate: Date;\n records: DateRecord[];\n currentMonthCellRanges: { range: TYPES.CellRange }[];\n currentMonth: number;\n currentYear: number;\n\n titleClickHandler: () => void;\n\n maxCol: number;\n minCol: number = 0;\n customHandler: CustomEventHandler;\n showToday: boolean = true;\n\n constructor(container: HTMLElement, options?: CalendarConstructorOptions) {\n super();\n this.container = container;\n this.options = options ?? {};\n const { startDate, endDate, currentDate, rangeDays } = this.options;\n\n this.currentDate = currentDate ?? new Date();\n this.rangeDays = rangeDays ?? 90;\n this.showToday = this.options.showTitle ?? true;\n if (startDate && endDate) {\n this.startDate = startDate;\n this.endDate = endDate;\n // if currentDate is not in the range, set it to the startDate\n if (this.currentDate < this.startDate || this.currentDate > this.endDate) {\n this.currentDate = this.startDate;\n this.showToday = false;\n }\n } else {\n const { startDate: computedStartDate, endDate: computedEndDate } = getStartAndEndDate(\n this.currentDate,\n this.rangeDays\n );\n this.startDate = startDate ?? computedStartDate;\n this.endDate = endDate ?? computedEndDate;\n }\n this.tableStartDate = this.startDate.getDay() === 0 ? this.startDate : previousSunday(this.startDate);\n\n this.customHandler = new CustomEventHandler(this, options?.customEventOptions);\n\n this._createTable();\n\n this._bindEvent();\n\n if (this.options.customEvents) {\n this.addCustomEvents(this.options.customEvents);\n }\n }\n\n _createTable() {\n const { dayTitles } = this.options;\n\n const records = getRecords(this.startDate, this.endDate);\n this.records = records;\n\n const week = (dayTitles ?? defaultDayTitles) as DateRecordKeys[];\n this.maxCol = week.length - 1;\n const option = createTableOption(\n week,\n defaultDayTitles as DateRecordKeys[],\n this.showToday ? this.currentDate : undefined,\n {\n tableOptions: this.options.tableOptions,\n containerWidth: this.container.clientWidth,\n containerHeight: this.container.clientHeight\n }\n );\n option.records = records;\n option.container = this.container;\n (option as any)._calendar = this;\n\n const tableInstance = new ListTable(option);\n this.table = tableInstance;\n\n tableInstance.addEventListener('scroll', () => {\n const record: DateRecord = this.getYearAndMonth();\n if (!record) {\n return;\n }\n if (!record.Sun) {\n // top\n this._updateMonthCustomStyle(this.startDate.getFullYear(), this.startDate.getMonth());\n return;\n }\n const firstDateInWeek = new Date(record.year, record.month, record.Sun);\n const lastDateInNextWeek = add(firstDateInWeek, {\n days: 13\n });\n this._updateMonthCustomStyle(lastDateInNextWeek.getFullYear(), lastDateInNextWeek.getMonth());\n });\n\n tableInstance.addEventListener('scroll_vertical_end', () => {\n this._updateMonthCustomStyle(this.endDate.getFullYear(), this.endDate.getMonth());\n });\n\n this.jumpToCurrentMonth();\n\n // bindDebugTool(tableInstance.scenegraph.stage as any, {\n // customGrapicKeys: ['col', 'row']\n // });\n }\n\n getYearAndMonth() {\n const x = this.table.tableX + 10; // buffer\n const y = this.table.tableY + this.table.getFrozenRowsHeight() + 10; // buffer\n const topRow = this.table.getCellAtRelativePosition(x, y);\n const { row } = topRow;\n const record = this.table.getCellRawRecord(0, row);\n return record;\n }\n\n jumpToDate(date: Date, animation?: boolean | TYPES.ITableAnimationOption) {\n date = startOfDay(date);\n const dataIndex = Math.floor((differenceInDays(date, this.tableStartDate) + 1) / 7);\n this.table.scrollToCell(\n {\n col: 0,\n row: dataIndex + 1\n },\n animation\n );\n\n this._updateMonthCustomStyle(date.getFullYear(), date.getMonth());\n }\n\n jumpToCurrentMonth(animation?: boolean | TYPES.ITableAnimationOption) {\n // scroll to current month\n const topDate = new Date(this.currentDate.getTime());\n topDate.setDate(1);\n this.jumpToDate(topDate, animation);\n }\n\n _updateMonthCustomStyle(year: number, month: number) {\n if (this.currentMonth === month && this.currentYear === year) {\n return;\n }\n\n // clear current\n this.currentMonthCellRanges?.forEach(range => {\n this.table.arrangeCustomCellStyle(range, null);\n });\n\n this.currentMonth = month;\n this.currentYear = year;\n this.currentMonthCellRanges = getMonthCustomStyleRange(year, month, this.tableStartDate, this.records);\n this.currentMonthCellRanges.forEach(range => {\n this.table.arrangeCustomCellStyle(range, 'current-month');\n });\n }\n\n // @ts-ignore\n fireListeners<TYPE extends keyof CalendarEventHandlersEventArgumentMap>(\n type: TYPE,\n event: CalendarEventHandlersEventArgumentMap[TYPE]\n ): CalendarEventHandlersReturnMap[TYPE][] {\n // 调用父类的方法\n return super.fireListeners(type as any, event as any);\n }\n\n // @ts-ignore\n on<TYPE extends keyof CalendarEventHandlersEventArgumentMap>(\n type: TYPE,\n listener: CalendarEventListener<TYPE>\n ): EventListenerId {\n // 调用父类的方法\n return super.on(type as any, listener as any);\n }\n\n _bindEvent() {\n if (this.table.internalProps.title) {\n // click title jump to current month\n const titleComponent = this.table.internalProps.title.getComponentGraphic();\n titleComponent.setAttributes({\n cursor: 'pointer',\n // hack for cursor\n childrenPickable: false\n });\n this.titleClickHandler = (() => {\n this.jumpToCurrentMonth({\n duration: 500\n });\n }).bind(this);\n titleComponent.addEventListener('click', this.titleClickHandler);\n }\n\n this.table.on('click_cell', e => {\n const { target } = e;\n if ((target as any)._role === 'calendar-custom-event') {\n this.fireListeners(CALENDAR_EVENT_TYPE.CALENDAR_CUSTOM_EVENT_CLICK, {\n tableEvent: e,\n date: this.getCellDate(e.col, e.row),\n customEvent: (target as any)._customEvent\n });\n } else if (!this.table.isHeader(e.col, e.row)) {\n this.fireListeners(CALENDAR_EVENT_TYPE.CALENDAR_DATE_CLICK, {\n tableEvent: e,\n date: this.getCellDate(e.col, e.row)\n });\n }\n });\n\n this.table.on('selected_cell', e => {\n if (!this.table.isHeader(e.col, e.row)) {\n this.fireListeners(CALENDAR_EVENT_TYPE.SELECTED_DATE, {\n tableEvent: e,\n date: this.getCellDate(e.col, e.row)\n });\n }\n });\n\n this.table.on('selected_clear', () => {\n this.fireListeners(CALENDAR_EVENT_TYPE.SELECTED_DATE_CLEAR, undefined);\n });\n\n this.table.on('drag_select_end', e => {\n const { cells } = e;\n const dates: Date[] = [];\n cells.map(row => {\n row.map(cell => {\n if (!this.table.isHeader(cell.col, cell.row)) {\n dates.push(this.getCellDate(cell.col, cell.row));\n }\n });\n });\n this.fireListeners(CALENDAR_EVENT_TYPE.DRAG_SELECT_DATE_END, {\n tableEvent: e,\n dates\n });\n });\n }\n\n release() {\n this.table.release();\n }\n\n getCellLocation(date: Date) {\n date = startOfDay(date);\n const dataIndex = Math.floor((differenceInDays(date, this.tableStartDate) + 1) / 7);\n const row = dataIndex + 1;\n const col = date.getDay();\n\n return {\n row,\n col\n };\n }\n\n getCellDate(col: number, row: number) {\n const startDate = add(this.tableStartDate, {\n days: (row - 1) * 7 + col\n });\n return startDate;\n }\n\n get selectedDate(): { date: Date; col: number; row: number }[] {\n const cells = this.table.getSelectedCellInfos();\n if (!isArray(cells) || cells.length === 0) {\n return [];\n }\n const dates: { date: Date; col: number; row: number }[] = [];\n cells.map(row => {\n row.map(cell => {\n if (!this.table.isHeader(cell.col, cell.row)) {\n dates.push({\n date: this.getCellDate(cell.col, cell.row),\n col: cell.col,\n row: cell.row\n });\n }\n });\n });\n\n return dates;\n }\n\n addCustomEvent(event: ICustomEvent) {\n this.customHandler.addEvent(event);\n this.table.scenegraph.updateNextFrame();\n }\n\n removeCustomEvent(id: string) {\n this.customHandler.removeEvents([id]);\n this.table.scenegraph.updateNextFrame();\n }\n\n updateCustomEvent(event: ICustomEvent) {\n this.customHandler.updateEvents([event]);\n this.table.scenegraph.updateNextFrame();\n }\n\n addCustomEvents(events: ICustomEvent[]) {\n this.customHandler.addEvents(events);\n this.table.scenegraph.updateNextFrame();\n }\n\n removeCustomEvents(ids: string[]) {\n this.customHandler.removeEvents(ids);\n this.table.scenegraph.updateNextFrame();\n }\n\n updateCustomEvents(events: ICustomEvent[]) {\n this.customHandler.updateEvents(events);\n this.table.scenegraph.updateNextFrame();\n }\n\n getCellCustomEventByDate(date: Date) {\n const location = this.getCellLocation(date);\n return this.getCellCustomEventByLocation(location.col, location.row);\n }\n\n getCellCustomEventByLocation(col: number, row: number) {\n const cellEvent = this.customHandler.getCellCustomEvent(col, row);\n const events: IEventData[] = [];\n cellEvent?.keys.forEach(key => {\n events.push(cellEvent.values[key]);\n });\n return events;\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ListTableConstructorOptions } from '@visactor/vtable';
|
|
2
2
|
import type { DateRecordKeys } from '../date-util';
|
|
3
|
-
export declare function createTableOption(week: DateRecordKeys[], currentDate: Date, config: {
|
|
3
|
+
export declare function createTableOption(dayTitles: string[], week: DateRecordKeys[], currentDate: Date | undefined, config: {
|
|
4
4
|
tableOptions?: ListTableConstructorOptions;
|
|
5
5
|
containerWidth: number;
|
|
6
6
|
containerHeight: number;
|
|
@@ -6,21 +6,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
|
|
7
7
|
const vtable_1 = require("@visactor/vtable"), date_util_1 = require("../date-util"), custom_layout_1 = require("../custom/custom-layout"), vutils_1 = require("@visactor/vutils"), date_fns_1 = require("date-fns");
|
|
8
8
|
|
|
9
|
-
function createTableOption(week, currentDate, config) {
|
|
9
|
+
function createTableOption(dayTitles, week, currentDate, config) {
|
|
10
10
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
11
|
-
const columns =
|
|
11
|
+
const columns = dayTitles.map(((item, index) => {
|
|
12
12
|
var _a, _b;
|
|
13
13
|
return {
|
|
14
|
-
field:
|
|
14
|
+
field: week[index],
|
|
15
15
|
title: item,
|
|
16
16
|
fieldFormat: record => {
|
|
17
|
-
if ((0, date_fns_1.isSameDay)((0, date_fns_1.addDays)(
|
|
18
|
-
if (1 === record[
|
|
19
|
-
const monthIndex = "Sun" ===
|
|
17
|
+
if (currentDate && (0, date_fns_1.isSameDay)((0, date_fns_1.addDays)(getSundayDate(record), index), currentDate)) return `${record[week[index]]}\nToday`;
|
|
18
|
+
if (1 === record[week[index]]) {
|
|
19
|
+
const monthIndex = "Sun" === week[index] ? record.month : record.month + 1, mouthStr = (0,
|
|
20
20
|
date_util_1.getMonthString)(monthIndex);
|
|
21
|
-
return `${record[
|
|
21
|
+
return `${record[week[index]]}\n${mouthStr}`;
|
|
22
22
|
}
|
|
23
|
-
return record[
|
|
23
|
+
return record[week[index]];
|
|
24
24
|
},
|
|
25
25
|
customLayout: null !== (_b = null === (_a = config.tableOptions) || void 0 === _a ? void 0 : _a.customLayout) && void 0 !== _b ? _b : custom_layout_1.calendarCustomLayout
|
|
26
26
|
};
|
|
@@ -39,18 +39,18 @@ function createTableOption(week, currentDate, config) {
|
|
|
39
39
|
bgColor: args => {
|
|
40
40
|
const {col: col, row: row, dataValue: dataValue, table: table} = args, record = table.getCellRawRecord(col, row);
|
|
41
41
|
record.Sun, record.month, 11 === record.month && record.Sun, record.year;
|
|
42
|
-
return (0, date_fns_1.isSameDay)((0, date_fns_1.addDays)(
|
|
42
|
+
return currentDate && (0, date_fns_1.isSameDay)((0, date_fns_1.addDays)(getSundayDate(record), col), currentDate) ? "#f0f0f0" : "#fff";
|
|
43
43
|
},
|
|
44
44
|
textAlign: "right",
|
|
45
45
|
textBaseline: "top",
|
|
46
46
|
color: "#999"
|
|
47
47
|
}
|
|
48
48
|
}, null === (_p = config.tableOptions) || void 0 === _p ? void 0 : _p.theme)),
|
|
49
|
-
title: Object.assign(Object.assign({}, null !== (_r = null === (_q = config.tableOptions) || void 0 === _q ? void 0 : _q.title) && void 0 !== _r ? _r : {}), {
|
|
49
|
+
title: currentDate ? Object.assign(Object.assign({}, null !== (_r = null === (_q = config.tableOptions) || void 0 === _q ? void 0 : _q.title) && void 0 !== _r ? _r : {}), {
|
|
50
50
|
orient: "top",
|
|
51
51
|
text: `${(0, date_util_1.getWeekdayString)(currentDate.getDay())}, ${(0, date_util_1.getMonthString)(currentDate.getMonth())} ${currentDate.getDate()}`,
|
|
52
52
|
subtext: currentDate.getFullYear()
|
|
53
|
-
}),
|
|
53
|
+
}) : void 0,
|
|
54
54
|
enableLineBreak: !0,
|
|
55
55
|
customCellStyle: [ {
|
|
56
56
|
id: "current-month",
|
|
@@ -61,5 +61,15 @@ function createTableOption(week, currentDate, config) {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
function getSundayDate(record) {
|
|
65
|
+
if ((0, vutils_1.isValid)(record.Sun)) return new Date(record.year, record.month, record.Sun);
|
|
66
|
+
const lastDay = (0, date_fns_1.lastDayOfMonth)(new Date(record.year, record.month, 1));
|
|
67
|
+
return (0, vutils_1.isValid)(record.Mon) ? (0, date_fns_1.addDays)(lastDay, -0) : (0,
|
|
68
|
+
vutils_1.isValid)(record.Tue) ? (0, date_fns_1.addDays)(lastDay, -1) : (0, vutils_1.isValid)(record.Wed) ? (0,
|
|
69
|
+
date_fns_1.addDays)(lastDay, -2) : (0, vutils_1.isValid)(record.Thu) ? (0, date_fns_1.addDays)(lastDay, -3) : (0,
|
|
70
|
+
vutils_1.isValid)(record.Fri) ? (0, date_fns_1.addDays)(lastDay, -4) : (0, vutils_1.isValid)(record.Sat) ? (0,
|
|
71
|
+
date_fns_1.addDays)(lastDay, -5) : void 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=table-option.js.map
|
|
75
|
+
exports.createTableOption = createTableOption;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["table/table-option.ts"],"names":[],"mappings":";;;AACA,6CAA0C;AAE1C,4CAAkF;AAClF,2DAA+D;AAC/D,
|
|
1
|
+
{"version":3,"sources":["table/table-option.ts"],"names":[],"mappings":";;;AACA,6CAA0C;AAE1C,4CAAkF;AAClF,2DAA+D;AAC/D,6CAAkD;AAClD,uCAA8D;AAE9D,SAAgB,iBAAiB,CAC/B,SAAmB,EACnB,IAAsB,EACtB,WAA6B,EAC7B,MAAuG;;IAEvG,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,KAAa,EAAE,EAAE;;QAC5D,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC;YAClB,KAAK,EAAE,IAAI;YAEX,WAAW,EAAE,CAAC,MAAkB,EAAE,EAAE;gBAClC,IAAI,WAAW,IAAI,IAAA,oBAAS,EAAC,IAAA,kBAAO,EAAC,aAAa,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,EAAE,WAAW,CAAC,EAAE;oBAChF,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC;iBACxC;qBAAM,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE;oBACpC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,CAAC,CAA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,OAAO,IAAA,kBAAO,EAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;KAC7B;IACD,IAAI,IAAA,gBAAO,EAAC,MAAM,CAAC,GAAG,CAAC,EAAE;QAEvB,OAAO,IAAA,kBAAO,EAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;KAC7B;AACH,CAAC","file":"table-option.js","sourcesContent":["import type { ListTableConstructorOptions, TYPES } from '@visactor/vtable';\nimport { themes } from '@visactor/vtable';\nimport type { DateRecord, DateRecordKeys } from '../date-util';\nimport { defaultDayTitles, getMonthString, getWeekdayString } from '../date-util';\nimport { calendarCustomLayout } from '../custom/custom-layout';\nimport { isValid, merge } from '@visactor/vutils';\nimport { addDays, isSameDay, lastDayOfMonth } from 'date-fns';\n\nexport function createTableOption(\n dayTitles: string[],\n week: DateRecordKeys[],\n currentDate: Date | undefined,\n config: { tableOptions?: ListTableConstructorOptions; containerWidth: number; containerHeight: number }\n) {\n const columns = dayTitles.map((item: string, index: number) => {\n return {\n field: week[index],\n title: item,\n // width: columnWidth ?? 140,\n fieldFormat: (record: DateRecord) => {\n if (currentDate && isSameDay(addDays(getSundayDate(record), index), currentDate)) {\n return `${record[week[index]]}\\nToday`;\n } else if (record[week[index]] === 1) {\n const monthIndex = week[index] === 'Sun' ? record.month : record.month + 1;\n const mouthStr = getMonthString(monthIndex);\n return `${record[week[index]]}\\n${mouthStr}`;\n }\n return record[week[index]];\n },\n customLayout: (config.tableOptions as any)?.customLayout ?? calendarCustomLayout\n };\n });\n\n const rowHeight = Math.floor(\n (config.containerHeight -\n ((config.tableOptions?.title?.textStyle?.fontSize ?? 20) +\n (config.tableOptions?.title?.subtextStyle?.fontSize ?? 16) +\n 1) -\n ((config.tableOptions?.defaultHeaderRowHeight as number) ?? 40)) /\n 5\n ); // height - title - header\n const option: TYPES.ListTableConstructorOptions = {\n ...(config.tableOptions ?? {}),\n\n columns,\n defaultRowHeight: rowHeight ?? 120,\n defaultHeaderRowHeight: config.tableOptions?.defaultHeaderRowHeight ?? 40,\n widthMode: 'adaptive',\n columnResizeMode: 'none',\n theme: themes.DEFAULT.extends(\n merge(\n {\n headerStyle: {\n textAlign: 'center'\n },\n bodyStyle: {\n bgColor: (args: any) => {\n const { col, row, dataValue, table } = args;\n const record = table.getCellRawRecord(col, row);\n const date = dataValue;\n const month = record.Sun > dataValue ? record.month + 1 : record.month;\n const year = record.month === 11 && record.Sun > dataValue ? record.year + 1 : record.year;\n if (\n // year === currentDate.getFullYear() &&\n // month === currentDate.getMonth() &&\n // date === currentDate.getDate()\n currentDate &&\n isSameDay(addDays(getSundayDate(record), col), currentDate)\n ) {\n return '#f0f0f0';\n }\n return '#fff';\n },\n textAlign: 'right',\n textBaseline: 'top',\n color: '#999'\n }\n },\n config.tableOptions?.theme\n )\n ),\n title: currentDate\n ? {\n ...(config.tableOptions?.title ?? {}),\n\n orient: 'top',\n // text: 'Thu, Aug 22',\n text: `${getWeekdayString(currentDate.getDay())}, ${getMonthString(\n currentDate.getMonth()\n )} ${currentDate.getDate()}`,\n subtext: currentDate.getFullYear()\n }\n : undefined,\n enableLineBreak: true,\n customCellStyle: [\n {\n id: 'current-month',\n style: {\n color: '#000'\n }\n }\n ]\n };\n\n return option;\n}\n\nfunction getSundayDate(record: DateRecord) {\n if (isValid(record.Sun)) {\n return new Date(record.year, record.month, record.Sun);\n }\n\n // last day of month\n const lastDay = lastDayOfMonth(new Date(record.year, record.month, 1));\n if (isValid(record.Mon)) {\n // delete 1 day\n return addDays(lastDay, -0);\n }\n if (isValid(record.Tue)) {\n // delete 2 day\n return addDays(lastDay, -1);\n }\n if (isValid(record.Wed)) {\n // delete 3 day\n return addDays(lastDay, -2);\n }\n if (isValid(record.Thu)) {\n // delete 4 day\n return addDays(lastDay, -3);\n }\n if (isValid(record.Fri)) {\n // delete 5 day\n return addDays(lastDay, -4);\n }\n if (isValid(record.Sat)) {\n // delete 6 day\n return addDays(lastDay, -5);\n }\n}\n"]}
|