@visactor/vtable-calendar 1.7.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.
Files changed (52) hide show
  1. package/README.md +67 -0
  2. package/cjs/custom/custom-handler.d.ts +46 -0
  3. package/cjs/custom/custom-handler.js +147 -0
  4. package/cjs/custom/custom-handler.js.map +1 -0
  5. package/cjs/custom/custom-layout.d.ts +6 -0
  6. package/cjs/custom/custom-layout.js +112 -0
  7. package/cjs/custom/custom-layout.js.map +1 -0
  8. package/cjs/date-util.d.ts +10 -0
  9. package/cjs/date-util.js +99 -0
  10. package/cjs/date-util.js.map +1 -0
  11. package/cjs/event/type.d.ts +39 -0
  12. package/cjs/event/type.js +12 -0
  13. package/cjs/event/type.js.map +1 -0
  14. package/cjs/index.d.ts +3 -0
  15. package/cjs/index.js +30 -0
  16. package/cjs/index.js.map +1 -0
  17. package/cjs/month-calendar.d.ts +65 -0
  18. package/cjs/month-calendar.js +177 -0
  19. package/cjs/month-calendar.js.map +1 -0
  20. package/cjs/style.d.ts +13 -0
  21. package/cjs/style.js +54 -0
  22. package/cjs/style.js.map +1 -0
  23. package/cjs/table/table-option.d.ts +7 -0
  24. package/cjs/table/table-option.js +61 -0
  25. package/cjs/table/table-option.js.map +1 -0
  26. package/dist/vtable-calendar.js +54526 -0
  27. package/dist/vtable-calendar.min.js +1 -0
  28. package/es/custom/custom-handler.d.ts +46 -0
  29. package/es/custom/custom-handler.js +140 -0
  30. package/es/custom/custom-handler.js.map +1 -0
  31. package/es/custom/custom-layout.d.ts +6 -0
  32. package/es/custom/custom-layout.js +105 -0
  33. package/es/custom/custom-layout.js.map +1 -0
  34. package/es/date-util.d.ts +10 -0
  35. package/es/date-util.js +88 -0
  36. package/es/date-util.js.map +1 -0
  37. package/es/event/type.d.ts +39 -0
  38. package/es/event/type.js +8 -0
  39. package/es/event/type.js.map +1 -0
  40. package/es/index.d.ts +3 -0
  41. package/es/index.js +4 -0
  42. package/es/index.js.map +1 -0
  43. package/es/month-calendar.d.ts +65 -0
  44. package/es/month-calendar.js +181 -0
  45. package/es/month-calendar.js.map +1 -0
  46. package/es/style.d.ts +13 -0
  47. package/es/style.js +45 -0
  48. package/es/style.js.map +1 -0
  49. package/es/table/table-option.d.ts +7 -0
  50. package/es/table/table-option.js +58 -0
  51. package/es/table/table-option.js.map +1 -0
  52. package/package.json +87 -0
package/cjs/index.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
4
+ void 0 === k2 && (k2 = k);
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
7
+ enumerable: !0,
8
+ get: function() {
9
+ return m[k];
10
+ }
11
+ }), Object.defineProperty(o, k2, desc);
12
+ } : function(o, m, k, k2) {
13
+ void 0 === k2 && (k2 = k), o[k2] = m[k];
14
+ }), __exportStar = this && this.__exportStar || function(m, exports) {
15
+ for (var p in m) "default" === p || Object.prototype.hasOwnProperty.call(exports, p) || __createBinding(exports, m, p);
16
+ };
17
+
18
+ Object.defineProperty(exports, "__esModule", {
19
+ value: !0
20
+ }), exports.CALENDAR_EVENT_TYPE = void 0, __exportStar(require("./month-calendar"), exports);
21
+
22
+ var type_1 = require("./event/type");
23
+
24
+ Object.defineProperty(exports, "CALENDAR_EVENT_TYPE", {
25
+ enumerable: !0,
26
+ get: function() {
27
+ return type_1.CALENDAR_EVENT_TYPE;
28
+ }
29
+ });
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAiC;AAEjC,qCAAmD;AAA1C,2GAAA,mBAAmB,OAAA","file":"index.js","sourcesContent":["export * from './month-calendar';\nexport type { ICustomEvent } from './custom/custom-handler';\nexport { CALENDAR_EVENT_TYPE } from './event/type';\n"]}
@@ -0,0 +1,65 @@
1
+ import { ListTable, EventTarget } from '@visactor/vtable';
2
+ import type { DateRecord } from './date-util';
3
+ import type { TYPES, ListTableConstructorOptions } from '@visactor/vtable';
4
+ import type { ICustomEvent, ICustomEventOptions, IEventData } from './custom/custom-handler';
5
+ import { CustomEventHandler } from './custom/custom-handler';
6
+ import type { CalendarEventHandlersEventArgumentMap, CalendarEventHandlersReturnMap, CalendarEventListener } from './event/type';
7
+ import type { EventListenerId } from '@visactor/vtable/src/ts-types';
8
+ export interface CalendarConstructorOptions {
9
+ startDate?: Date;
10
+ endDate?: Date;
11
+ currentDate?: Date;
12
+ rangeDays?: number;
13
+ dayTitles?: [string, string, string, string, string, string, string];
14
+ tableOptions?: ListTableConstructorOptions;
15
+ customEvents?: ICustomEvent[];
16
+ customEventOptions?: ICustomEventOptions;
17
+ }
18
+ export declare class Calendar extends EventTarget {
19
+ container: HTMLElement;
20
+ options: CalendarConstructorOptions;
21
+ table: ListTable;
22
+ startDate: Date;
23
+ endDate: Date;
24
+ currentDate: Date;
25
+ rangeDays: number;
26
+ tableStartDate: Date;
27
+ records: DateRecord[];
28
+ currentMonthCellRanges: {
29
+ range: TYPES.CellRange;
30
+ }[];
31
+ currentMonth: number;
32
+ currentYear: number;
33
+ titleClickHandler: () => void;
34
+ maxCol: number;
35
+ minCol: number;
36
+ customHandler: CustomEventHandler;
37
+ constructor(container: HTMLElement, options?: CalendarConstructorOptions);
38
+ _createTable(): void;
39
+ getYearAndMonth(): any;
40
+ jumpToDate(date: Date, animation?: boolean | TYPES.ITableAnimationOption): void;
41
+ jumpToCurrentMonth(animation?: boolean | TYPES.ITableAnimationOption): void;
42
+ _updateMonthCustomStyle(year: number, month: number): void;
43
+ fireListeners<TYPE extends keyof CalendarEventHandlersEventArgumentMap>(type: TYPE, event: CalendarEventHandlersEventArgumentMap[TYPE]): CalendarEventHandlersReturnMap[TYPE][];
44
+ on<TYPE extends keyof CalendarEventHandlersEventArgumentMap>(type: TYPE, listener: CalendarEventListener<TYPE>): EventListenerId;
45
+ _bindEvent(): void;
46
+ release(): void;
47
+ getCellLocation(date: Date): {
48
+ row: number;
49
+ col: number;
50
+ };
51
+ getCellDate(col: number, row: number): Date;
52
+ get selectedDate(): {
53
+ date: Date;
54
+ col: number;
55
+ row: number;
56
+ }[];
57
+ addCustomEvent(event: ICustomEvent): void;
58
+ removeCustomEvent(id: string): void;
59
+ updateCustomEvent(event: ICustomEvent): void;
60
+ addCustomEvents(events: ICustomEvent[]): void;
61
+ removeCustomEvents(ids: string[]): void;
62
+ updateCustomEvents(events: ICustomEvent[]): void;
63
+ getCellCustomEventByDate(date: Date): IEventData[];
64
+ getCellCustomEventByLocation(col: number, row: number): IEventData[];
65
+ }
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.Calendar = void 0;
6
+
7
+ const vtable_1 = require("@visactor/vtable"), date_util_1 = require("./date-util"), date_fns_1 = require("date-fns"), style_1 = require("./style"), table_option_1 = require("./table/table-option"), custom_handler_1 = require("./custom/custom-handler"), type_1 = require("./event/type"), vutils_1 = require("@visactor/vutils");
8
+
9
+ class Calendar extends vtable_1.EventTarget {
10
+ constructor(container, options) {
11
+ super(), this.minCol = 0, this.container = container, this.options = null != options ? options : {};
12
+ const {startDate: startDate, endDate: endDate, currentDate: currentDate, rangeDays: rangeDays} = this.options;
13
+ if (this.currentDate = null != currentDate ? currentDate : new Date, this.rangeDays = null != rangeDays ? rangeDays : 90,
14
+ startDate && endDate) this.startDate = startDate, this.endDate = endDate; else {
15
+ const {startDate: computedStartDate, endDate: computedEndDate} = (0, date_util_1.getStartAndEndDate)(this.currentDate, this.rangeDays);
16
+ this.startDate = null != startDate ? startDate : computedStartDate, this.endDate = null != endDate ? endDate : computedEndDate;
17
+ }
18
+ this.tableStartDate = 0 === this.startDate.getDay() ? this.startDate : (0, date_fns_1.previousSunday)(this.startDate),
19
+ this.customHandler = new custom_handler_1.CustomEventHandler(this, null == options ? void 0 : options.customEventOptions),
20
+ this._createTable(), this._bindEvent(), this.options.customEvents && this.addCustomEvents(this.options.customEvents);
21
+ }
22
+ _createTable() {
23
+ const {dayTitles: dayTitles} = this.options, records = (0, date_util_1.getRecords)(this.startDate, this.endDate);
24
+ this.records = records;
25
+ const week = null != dayTitles ? dayTitles : date_util_1.defaultDayTitles;
26
+ this.maxCol = week.length - 1;
27
+ const option = (0, table_option_1.createTableOption)(week, this.currentDate, {
28
+ tableOptions: this.options.tableOptions,
29
+ containerWidth: this.container.clientWidth,
30
+ containerHeight: this.container.clientHeight
31
+ });
32
+ option.records = records, option.container = this.container, option._calendar = this;
33
+ const tableInstance = new vtable_1.ListTable(option);
34
+ this.table = tableInstance, tableInstance.addEventListener("scroll", (() => {
35
+ const record = this.getYearAndMonth();
36
+ if (!record.Sun) return void this._updateMonthCustomStyle(this.startDate.getFullYear(), this.startDate.getMonth());
37
+ const firstDateInWeek = new Date(record.year, record.month, record.Sun), lastDateInNextWeek = (0,
38
+ date_fns_1.add)(firstDateInWeek, {
39
+ days: 13
40
+ });
41
+ this._updateMonthCustomStyle(lastDateInNextWeek.getFullYear(), lastDateInNextWeek.getMonth());
42
+ })), tableInstance.addEventListener("scroll_vertical_end", (() => {
43
+ this._updateMonthCustomStyle(this.endDate.getFullYear(), this.endDate.getMonth());
44
+ })), this.jumpToCurrentMonth();
45
+ }
46
+ getYearAndMonth() {
47
+ const x = this.table.tableX + 10, y = this.table.tableY + this.table.getFrozenRowsHeight() + 10, topRow = this.table.getCellAtRelativePosition(x, y), {row: row} = topRow;
48
+ return this.table.getCellRawRecord(0, row);
49
+ }
50
+ jumpToDate(date, animation) {
51
+ date = (0, date_fns_1.startOfDay)(date);
52
+ const dataIndex = Math.floor(((0, date_fns_1.differenceInDays)(date, this.tableStartDate) + 1) / 7);
53
+ this.table.scrollToCell({
54
+ col: 0,
55
+ row: dataIndex + 1
56
+ }, animation), this._updateMonthCustomStyle(date.getFullYear(), date.getMonth());
57
+ }
58
+ jumpToCurrentMonth(animation) {
59
+ const topDate = new Date(this.currentDate.getTime());
60
+ topDate.setDate(1), this.jumpToDate(topDate, animation);
61
+ }
62
+ _updateMonthCustomStyle(year, month) {
63
+ var _a;
64
+ this.currentMonth === month && this.currentYear === year || (null === (_a = this.currentMonthCellRanges) || void 0 === _a || _a.forEach((range => {
65
+ this.table.arrangeCustomCellStyle(range, null);
66
+ })), this.currentMonth = month, this.currentYear = year, this.currentMonthCellRanges = (0,
67
+ style_1.getMonthCustomStyleRange)(year, month, this.tableStartDate, this.records),
68
+ this.currentMonthCellRanges.forEach((range => {
69
+ this.table.arrangeCustomCellStyle(range, "current-month");
70
+ })));
71
+ }
72
+ fireListeners(type, event) {
73
+ return super.fireListeners(type, event);
74
+ }
75
+ on(type, listener) {
76
+ return super.on(type, listener);
77
+ }
78
+ _bindEvent() {
79
+ const titleComponent = this.table.internalProps.title.getComponentGraphic();
80
+ titleComponent.setAttributes({
81
+ cursor: "pointer",
82
+ childrenPickable: !1
83
+ }), this.titleClickHandler = (() => {
84
+ this.jumpToCurrentMonth({
85
+ duration: 500
86
+ });
87
+ }).bind(this), titleComponent.addEventListener("click", this.titleClickHandler),
88
+ this.table.on("click_cell", (e => {
89
+ const {target: target} = e;
90
+ "calendar-custom-event" === target._role ? this.fireListeners(type_1.CALENDAR_EVENT_TYPE.CALENDAR_CUSTOM_EVENT_CLICK, {
91
+ tableEvent: e,
92
+ date: this.getCellDate(e.col, e.row),
93
+ customEvent: target._customEvent
94
+ }) : this.table.isHeader(e.col, e.row) || this.fireListeners(type_1.CALENDAR_EVENT_TYPE.CALENDAR_DATE_CLICK, {
95
+ tableEvent: e,
96
+ date: this.getCellDate(e.col, e.row)
97
+ });
98
+ })), this.table.on("selected_cell", (e => {
99
+ this.table.isHeader(e.col, e.row) || this.fireListeners(type_1.CALENDAR_EVENT_TYPE.SELECTED_DATE, {
100
+ tableEvent: e,
101
+ date: this.getCellDate(e.col, e.row)
102
+ });
103
+ })), this.table.on("selected_clear", (() => {
104
+ this.fireListeners(type_1.CALENDAR_EVENT_TYPE.SELECTED_DATE_CLEAR, void 0);
105
+ })), this.table.on("drag_select_end", (e => {
106
+ const {cells: cells} = e, dates = [];
107
+ cells.map((row => {
108
+ row.map((cell => {
109
+ this.table.isHeader(cell.col, cell.row) || dates.push(this.getCellDate(cell.col, cell.row));
110
+ }));
111
+ })), this.fireListeners(type_1.CALENDAR_EVENT_TYPE.DRAG_SELECT_DATE_END, {
112
+ tableEvent: e,
113
+ dates: dates
114
+ });
115
+ }));
116
+ }
117
+ release() {
118
+ this.table.release();
119
+ }
120
+ getCellLocation(date) {
121
+ date = (0, date_fns_1.startOfDay)(date);
122
+ return {
123
+ row: Math.floor(((0, date_fns_1.differenceInDays)(date, this.tableStartDate) + 1) / 7) + 1,
124
+ col: date.getDay()
125
+ };
126
+ }
127
+ getCellDate(col, row) {
128
+ return (0, date_fns_1.add)(this.tableStartDate, {
129
+ days: 7 * (row - 1) + col
130
+ });
131
+ }
132
+ get selectedDate() {
133
+ const cells = this.table.getSelectedCellInfos();
134
+ if (!(0, vutils_1.isArray)(cells) || 0 === cells.length) return [];
135
+ const dates = [];
136
+ return cells.map((row => {
137
+ row.map((cell => {
138
+ this.table.isHeader(cell.col, cell.row) || dates.push({
139
+ date: this.getCellDate(cell.col, cell.row),
140
+ col: cell.col,
141
+ row: cell.row
142
+ });
143
+ }));
144
+ })), dates;
145
+ }
146
+ addCustomEvent(event) {
147
+ this.customHandler.addEvent(event), this.table.scenegraph.updateNextFrame();
148
+ }
149
+ removeCustomEvent(id) {
150
+ this.customHandler.removeEvents([ id ]), this.table.scenegraph.updateNextFrame();
151
+ }
152
+ updateCustomEvent(event) {
153
+ this.customHandler.updateEvents([ event ]), this.table.scenegraph.updateNextFrame();
154
+ }
155
+ addCustomEvents(events) {
156
+ this.customHandler.addEvents(events), this.table.scenegraph.updateNextFrame();
157
+ }
158
+ removeCustomEvents(ids) {
159
+ this.customHandler.removeEvents(ids), this.table.scenegraph.updateNextFrame();
160
+ }
161
+ updateCustomEvents(events) {
162
+ this.customHandler.updateEvents(events), this.table.scenegraph.updateNextFrame();
163
+ }
164
+ getCellCustomEventByDate(date) {
165
+ const location = this.getCellLocation(date);
166
+ return this.getCellCustomEventByLocation(location.col, location.row);
167
+ }
168
+ getCellCustomEventByLocation(col, row) {
169
+ const cellEvent = this.customHandler.getCellCustomEvent(col, row), events = [];
170
+ return null == cellEvent || cellEvent.keys.forEach((key => {
171
+ events.push(cellEvent.values[key]);
172
+ })), events;
173
+ }
174
+ }
175
+
176
+ exports.Calendar = Calendar;
177
+ //# sourceMappingURL=month-calendar.js.map
@@ -0,0 +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;a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G,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAClE,MAAM,MAAM,GAAiB,EAAE,CAAC;QAChC,SAAS,aAAT,SAAS,uBAAT,SAAS,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;AAvTD,4BAuTC","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/src/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.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"]}
package/cjs/style.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { DateRecord } from './date-util';
2
+ export declare function getMonthCustomStyleRange(year: number, month: number, tableStartDate: Date, records: DateRecord[]): {
3
+ range: {
4
+ start: {
5
+ col: number;
6
+ row: number;
7
+ };
8
+ end: {
9
+ col: number;
10
+ row: number;
11
+ };
12
+ };
13
+ }[];
package/cjs/style.js ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.getMonthCustomStyleRange = void 0;
6
+
7
+ const date_fns_1 = require("date-fns");
8
+
9
+ function getMonthCustomStyleRange(year, month, tableStartDate, records) {
10
+ const startDate = new Date(year, month, 1), startDataIndex = Math.floor(((0, date_fns_1.differenceInDays)(startDate, tableStartDate) + 1) / 7), startRecord = records[startDataIndex], endDate = (0,
11
+ date_fns_1.lastDayOfMonth)(startDate), endDataIndex = Math.floor(((0, date_fns_1.differenceInDays)(endDate, tableStartDate) + 1) / 7), endRecord = records[endDataIndex], customCellRanges = [ {
12
+ range: {
13
+ start: {
14
+ col: 0,
15
+ row: startDataIndex + 1 + 1
16
+ },
17
+ end: {
18
+ col: 6,
19
+ row: endDataIndex
20
+ }
21
+ }
22
+ } ];
23
+ let startIndex, endIndex;
24
+ 1 === startRecord.Sun ? startIndex = 0 : 1 === startRecord.Mon ? startIndex = 1 : 1 === startRecord.Tue ? startIndex = 2 : 1 === startRecord.Wed ? startIndex = 3 : 1 === startRecord.Thu ? startIndex = 4 : 1 === startRecord.Fri ? startIndex = 5 : 1 === startRecord.Sat && (startIndex = 6),
25
+ customCellRanges.push({
26
+ range: {
27
+ start: {
28
+ col: startIndex,
29
+ row: startDataIndex + 1
30
+ },
31
+ end: {
32
+ col: 6,
33
+ row: startDataIndex + 1
34
+ }
35
+ }
36
+ });
37
+ const monthEndDate = endDate.getDate();
38
+ return endRecord.Sun === monthEndDate ? endIndex = 0 : endRecord.Mon === monthEndDate ? endIndex = 1 : endRecord.Tue === monthEndDate ? endIndex = 2 : endRecord.Wed === monthEndDate ? endIndex = 3 : endRecord.Thu === monthEndDate ? endIndex = 4 : endRecord.Fri === monthEndDate ? endIndex = 5 : endRecord.Sat === monthEndDate && (endIndex = 6),
39
+ customCellRanges.push({
40
+ range: {
41
+ start: {
42
+ col: 0,
43
+ row: endDataIndex + 1
44
+ },
45
+ end: {
46
+ col: endIndex,
47
+ row: endDataIndex + 1
48
+ }
49
+ }
50
+ }), customCellRanges;
51
+ }
52
+
53
+ exports.getMonthCustomStyleRange = getMonthCustomStyleRange;
54
+ //# sourceMappingURL=style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["style.ts"],"names":[],"mappings":";;;AAAA,uCAA4D;AAG5D,SAAgB,wBAAwB,CAAC,IAAY,EAAE,KAAa,EAAE,cAAoB,EAAE,OAAqB;IAC/G,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAC3C,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAA,2BAAgB,EAAC,SAAS,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACzF,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAE5C,MAAM,OAAO,GAAG,IAAA,yBAAc,EAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAA,2BAAgB,EAAC,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACrF,MAAM,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAExC,MAAM,gBAAgB,GAAG;QACvB;YACE,KAAK,EAAE;gBACL,KAAK,EAAE;oBACL,GAAG,EAAE,CAAC;oBACN,GAAG,EAAE,cAAc,GAAG,CAAC,GAAG,CAAC;iBAC5B;gBACD,GAAG,EAAE;oBACH,GAAG,EAAE,CAAC;oBACN,GAAG,EAAE,YAAY;iBAClB;aACF;SACF;KACF,CAAC;IAEF,IAAI,UAAU,CAAC;IACf,IAAI,WAAW,CAAC,GAAG,KAAK,CAAC,EAAE;QACzB,UAAU,GAAG,CAAC,CAAC;KAChB;SAAM,IAAI,WAAW,CAAC,GAAG,KAAK,CAAC,EAAE;QAChC,UAAU,GAAG,CAAC,CAAC;KAChB;SAAM,IAAI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AAM,IAAI,SAAS,CAAC,GAAG,KAAK,YAAY,EAAE;QACzC,QAAQ,GAAG,CAAC,CAAC;KACd;IAED,gBAAgB,CAAC,IAAI,CAAC;QACpB,KAAK,EAAE;YACL,KAAK,EAAE;gBACL,GAAG,EAAE,CAAC;gBACN,GAAG,EAAE,YAAY,GAAG,CAAC;aACtB;YACD,GAAG,EAAE;gBACH,GAAG,EAAE,QAAQ;gBACb,GAAG,EAAE,YAAY,GAAG,CAAC;aACtB;SACF;KACF,CAAC,CAAC;IAEH,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AArFD,4DAqFC","file":"style.js","sourcesContent":["import { differenceInDays, lastDayOfMonth } from 'date-fns';\nimport type { DateRecord } from './date-util';\n\nexport function getMonthCustomStyleRange(year: number, month: number, tableStartDate: Date, records: DateRecord[]) {\n const startDate = new Date(year, month, 1);\n const startDataIndex = Math.floor((differenceInDays(startDate, tableStartDate) + 1) / 7);\n const startRecord = records[startDataIndex];\n\n const endDate = lastDayOfMonth(startDate);\n const endDataIndex = Math.floor((differenceInDays(endDate, tableStartDate) + 1) / 7);\n const endRecord = records[endDataIndex];\n\n const customCellRanges = [\n {\n range: {\n start: {\n col: 0,\n row: startDataIndex + 1 + 1\n },\n end: {\n col: 6,\n row: endDataIndex\n }\n }\n }\n ];\n\n let startIndex;\n if (startRecord.Sun === 1) {\n startIndex = 0;\n } else if (startRecord.Mon === 1) {\n startIndex = 1;\n } else if (startRecord.Tue === 1) {\n startIndex = 2;\n } else if (startRecord.Wed === 1) {\n startIndex = 3;\n } else if (startRecord.Thu === 1) {\n startIndex = 4;\n } else if (startRecord.Fri === 1) {\n startIndex = 5;\n } else if (startRecord.Sat === 1) {\n startIndex = 6;\n }\n customCellRanges.push({\n range: {\n start: {\n col: startIndex,\n row: startDataIndex + 1\n },\n end: {\n col: 6,\n row: startDataIndex + 1\n }\n }\n });\n\n let endIndex;\n const monthEndDate = endDate.getDate();\n if (endRecord.Sun === monthEndDate) {\n endIndex = 0;\n } else if (endRecord.Mon === monthEndDate) {\n endIndex = 1;\n } else if (endRecord.Tue === monthEndDate) {\n endIndex = 2;\n } else if (endRecord.Wed === monthEndDate) {\n endIndex = 3;\n } else if (endRecord.Thu === monthEndDate) {\n endIndex = 4;\n } else if (endRecord.Fri === monthEndDate) {\n endIndex = 5;\n } else if (endRecord.Sat === monthEndDate) {\n endIndex = 6;\n }\n\n customCellRanges.push({\n range: {\n start: {\n col: 0,\n row: endDataIndex + 1\n },\n end: {\n col: endIndex,\n row: endDataIndex + 1\n }\n }\n });\n\n return customCellRanges;\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import type { ListTableConstructorOptions } from '@visactor/vtable';
2
+ import type { DateRecordKeys } from '../date-util';
3
+ export declare function createTableOption(week: DateRecordKeys[], currentDate: Date, config: {
4
+ tableOptions?: ListTableConstructorOptions;
5
+ containerWidth: number;
6
+ containerHeight: number;
7
+ }): ListTableConstructorOptions;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.createTableOption = void 0;
6
+
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");
8
+
9
+ function createTableOption(week, currentDate, config) {
10
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
11
+ const columns = week.map(((item, index) => ({
12
+ field: date_util_1.defaultDayTitles[index],
13
+ title: item,
14
+ fieldFormat: record => {
15
+ if (record.year === currentDate.getFullYear() && record.month === currentDate.getMonth() && record[item] === currentDate.getDate()) return `${record[item]}\nToday`;
16
+ if (1 === record[item]) {
17
+ const monthIndex = "Sun" === item ? record.month : record.month + 1, mouthStr = (0,
18
+ date_util_1.getMonthString)(monthIndex);
19
+ return `${record[item]}\n${mouthStr}`;
20
+ }
21
+ return record[item];
22
+ },
23
+ customLayout: custom_layout_1.calendarCustomLayout
24
+ }))), rowHeight = Math.floor((config.containerHeight - ((null !== (_d = null === (_c = null === (_b = null === (_a = config.tableOptions) || void 0 === _a ? void 0 : _a.title) || void 0 === _b ? void 0 : _b.textStyle) || void 0 === _c ? void 0 : _c.fontSize) && void 0 !== _d ? _d : 20) + (null !== (_h = null === (_g = null === (_f = null === (_e = config.tableOptions) || void 0 === _e ? void 0 : _e.title) || void 0 === _f ? void 0 : _f.subtextStyle) || void 0 === _g ? void 0 : _g.fontSize) && void 0 !== _h ? _h : 16) + 1) - (null !== (_k = null === (_j = config.tableOptions) || void 0 === _j ? void 0 : _j.defaultHeaderRowHeight) && void 0 !== _k ? _k : 40)) / 5);
25
+ return Object.assign(Object.assign({}, null !== (_l = config.tableOptions) && void 0 !== _l ? _l : {}), {
26
+ columns: columns,
27
+ defaultRowHeight: null != rowHeight ? rowHeight : 120,
28
+ defaultHeaderRowHeight: null !== (_o = null === (_m = config.tableOptions) || void 0 === _m ? void 0 : _m.defaultHeaderRowHeight) && void 0 !== _o ? _o : 40,
29
+ widthMode: "adaptive",
30
+ columnResizeMode: "none",
31
+ theme: vtable_1.themes.DEFAULT.extends((0, vutils_1.merge)({
32
+ headerStyle: {
33
+ textAlign: "center"
34
+ },
35
+ bodyStyle: {
36
+ bgColor: args => {
37
+ const {col: col, row: row, dataValue: dataValue, table: table} = args, record = table.getCellRawRecord(col, row), date = dataValue, month = record.Sun > dataValue ? record.month + 1 : record.month;
38
+ return (11 === record.month && record.Sun > dataValue ? record.year + 1 : record.year) === currentDate.getFullYear() && month === currentDate.getMonth() && date === currentDate.getDate() ? "#f0f0f0" : "#fff";
39
+ },
40
+ textAlign: "right",
41
+ textBaseline: "top",
42
+ color: "#999"
43
+ }
44
+ }, null === (_p = config.tableOptions) || void 0 === _p ? void 0 : _p.theme)),
45
+ title: Object.assign(Object.assign({}, null !== (_r = null === (_q = config.tableOptions) || void 0 === _q ? void 0 : _q.title) && void 0 !== _r ? _r : {}), {
46
+ orient: "top",
47
+ text: `${(0, date_util_1.getWeekdayString)(currentDate.getDay())}, ${(0, date_util_1.getMonthString)(currentDate.getMonth())} ${currentDate.getDate()}`,
48
+ subtext: currentDate.getFullYear()
49
+ }),
50
+ enableLineBreak: !0,
51
+ customCellStyle: [ {
52
+ id: "current-month",
53
+ style: {
54
+ color: "#000"
55
+ }
56
+ } ]
57
+ });
58
+ }
59
+
60
+ exports.createTableOption = createTableOption;
61
+ //# sourceMappingURL=table-option.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["table/table-option.ts"],"names":[],"mappings":";;;AACA,6CAA0C;AAE1C,4CAAkF;AAClF,2DAA+D;AAC/D,6CAAyC;AAEzC,SAAgB,iBAAiB,CAC/B,IAAsB,EACtB,WAAiB,EACjB,MAAuG;;IAEvG,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAoB,EAAE,KAAa,EAAE,EAAE;QAC/D,OAAO;YACL,KAAK,EAAE,4BAAgB,CAAC,KAAK,CAAC;YAC9B,KAAK,EAAE,IAAI;YAEX,WAAW,EAAE,CAAC,MAAkB,EAAE,EAAE;gBAClC,IACE,MAAM,CAAC,IAAI,KAAK,WAAW,CAAC,WAAW,EAAE;oBACzC,MAAM,CAAC,KAAK,KAAK,WAAW,CAAC,QAAQ,EAAE;oBACvC,MAAM,CAAC,IAAI,CAAC,KAAK,WAAW,CAAC,OAAO,EAAE,EACtC;oBACA,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;iBACjC;qBAAM,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;oBAC7B,MAAM,UAAU,GAAG,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;oBACpE,MAAM,QAAQ,GAAG,IAAA,0BAAc,EAAC,UAAU,CAAC,CAAC;oBAC5C,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,QAAQ,EAAE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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 { merge } from '@visactor/vutils';\n\nexport function createTableOption(\n week: DateRecordKeys[],\n currentDate: Date,\n config: { tableOptions?: ListTableConstructorOptions; containerWidth: number; containerHeight: number }\n) {\n const columns = week.map((item: DateRecordKeys, index: number) => {\n return {\n field: defaultDayTitles[index],\n title: item,\n // width: columnWidth ?? 140,\n fieldFormat: (record: DateRecord) => {\n if (\n record.year === currentDate.getFullYear() &&\n record.month === currentDate.getMonth() &&\n record[item] === currentDate.getDate()\n ) {\n return `${record[item]}\\nToday`;\n } else if (record[item] === 1) {\n const monthIndex = item === 'Sun' ? record.month : record.month + 1;\n const mouthStr = getMonthString(monthIndex);\n return `${record[item]}\\n${mouthStr}`;\n }\n return record[item];\n },\n 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 => {\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 ) {\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: {\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 enableLineBreak: true,\n customCellStyle: [\n {\n id: 'current-month',\n style: {\n color: '#000'\n }\n }\n ]\n };\n\n return option;\n}\n"]}