updates from main

This commit is contained in:
MaTeMaTuK 2022-01-20 08:54:30 +01:00
commit 15427084d7
7 changed files with 50 additions and 37667 deletions

View File

@ -75,6 +75,7 @@ npm start
| onDelete\* | (task: Task) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed on the taskbar on Delete button press event. | | onDelete\* | (task: Task) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed on the taskbar on Delete button press event. |
| onDateChange\* | (task: Task, children: Task[]) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed when drag taskbar event on timeline has finished. | | onDateChange\* | (task: Task, children: Task[]) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed when drag taskbar event on timeline has finished. |
| onProgressChange\* | (task: Task, children: Task[]) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed when drag taskbar progress event has finished. | | onProgressChange\* | (task: Task, children: Task[]) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed when drag taskbar progress event has finished. |
| onExpanderClick\* | onExpanderClick: (task: Task) => void; | Specifies the function to be executed on the table expander click |
| timeStep | (task: Task) => number | A time step value for onDateChange. Specify in milliseconds. | | timeStep | (task: Task) => number | A time step value for onDateChange. Specify in milliseconds. |
\* Chart undoes operation if method return false or error. Parameter children returns one level deep records. \* Chart undoes operation if method return false or error. Parameter children returns one level deep records.

1776
example/package-lock.json generated

File diff suppressed because it is too large Load Diff

35878
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "gantt-task-react", "name": "gantt-task-react",
"version": "0.3.5", "version": "0.3.7",
"description": "Interactive Gantt Chart for React with TypeScript.", "description": "Interactive Gantt Chart for React with TypeScript.",
"author": "MaTeMaTuK <maksym.vikarii@gmail.com>", "author": "MaTeMaTuK <maksym.vikarii@gmail.com>",
"homepage": "https://github.com/MaTeMaTuK/gantt-task-react", "homepage": "https://github.com/MaTeMaTuK/gantt-task-react",

View File

@ -2,6 +2,7 @@ import React, { ReactChild } from "react";
import { ViewMode } from "../../types/public-types"; import { ViewMode } from "../../types/public-types";
import { TopPartOfCalendar } from "./top-part-of-calendar"; import { TopPartOfCalendar } from "./top-part-of-calendar";
import { import {
getCachedDateTimeFormat,
getDaysInMonth, getDaysInMonth,
getLocaleMonth, getLocaleMonth,
getWeekNumberISO8601, getWeekNumberISO8601,
@ -177,7 +178,7 @@ export const Calendar: React.FC<CalendarProps> = ({
const dates = dateSetup.dates; const dates = dateSetup.dates;
for (let i = 0; i < dates.length; i++) { for (let i = 0; i < dates.length; i++) {
const date = dates[i]; const date = dates[i];
const bottomValue = Intl.DateTimeFormat(locale, { const bottomValue = getCachedDateTimeFormat(locale, {
hour: "numeric", hour: "numeric",
}).format(date); }).format(date);

View File

@ -1,7 +1,27 @@
import React from "react"; import React, { useMemo } from "react";
import styles from "./task-list-table.module.css"; import styles from "./task-list-table.module.css";
import { Task } from "../../types/public-types"; import { Task } from "../../types/public-types";
const localeDateStringCache = {};
const toLocaleDateStringFactory = (locale: string) => (
date: Date,
dateTimeOptions: Intl.DateTimeFormatOptions
) => {
const key = date.toString();
let lds = localeDateStringCache[key];
if (!lds) {
lds = date.toLocaleDateString(locale, dateTimeOptions);
localeDateStringCache[key] = lds;
}
return lds;
};
const dateTimeOptions: Intl.DateTimeFormatOptions = {
weekday: "short",
year: "numeric",
month: "long",
day: "numeric",
};
export const TaskListTableDefault: React.FC<{ export const TaskListTableDefault: React.FC<{
rowHeight: number; rowHeight: number;
rowWidth: string; rowWidth: string;
@ -21,12 +41,10 @@ export const TaskListTableDefault: React.FC<{
locale, locale,
onExpanderClick, onExpanderClick,
}) => { }) => {
const dateTimeOptions: Intl.DateTimeFormatOptions = { const toLocaleDateString = useMemo(() => toLocaleDateStringFactory(locale), [
weekday: "short", locale,
year: "numeric", ]);
month: "long",
day: "numeric",
};
return ( return (
<div <div
className={styles.taskListWrapper} className={styles.taskListWrapper}
@ -78,7 +96,7 @@ export const TaskListTableDefault: React.FC<{
maxWidth: rowWidth, maxWidth: rowWidth,
}} }}
> >
&nbsp;{t.start.toLocaleDateString(locale, dateTimeOptions)} &nbsp;{toLocaleDateString(t.start, dateTimeOptions)}
</div> </div>
<div <div
className={styles.taskListCell} className={styles.taskListCell}
@ -87,8 +105,7 @@ export const TaskListTableDefault: React.FC<{
maxWidth: rowWidth, maxWidth: rowWidth,
}} }}
> >
&nbsp; &nbsp;{toLocaleDateString(t.end, dateTimeOptions)}
{t.end.toLocaleDateString(locale, dateTimeOptions)}
</div> </div>
</div> </div>
); );

View File

@ -1,4 +1,6 @@
import { Task, ViewMode } from "../types/public-types"; import { Task, ViewMode } from "../types/public-types";
import DateTimeFormatOptions = Intl.DateTimeFormatOptions;
import DateTimeFormat = Intl.DateTimeFormat;
type DateHelperScales = type DateHelperScales =
| "year" | "year"
@ -9,6 +11,21 @@ type DateHelperScales =
| "second" | "second"
| "millisecond"; | "millisecond";
const intlDTCache = {};
export const getCachedDateTimeFormat = (
locString: string | string[],
opts: DateTimeFormatOptions = {}
): DateTimeFormat => {
const key = JSON.stringify([locString, opts]);
let dtf = intlDTCache[key];
if (!dtf) {
dtf = new Intl.DateTimeFormat(locString, opts);
intlDTCache[key] = dtf;
}
return dtf;
};
export const addToDate = ( export const addToDate = (
date: Date, date: Date,
quantity: number, quantity: number,
@ -130,7 +147,7 @@ export const seedDates = (
}; };
export const getLocaleMonth = (date: Date, locale: string) => { export const getLocaleMonth = (date: Date, locale: string) => {
let bottomValue = new Intl.DateTimeFormat(locale, { let bottomValue = getCachedDateTimeFormat(locale, {
month: "long", month: "long",
}).format(date); }).format(date);
bottomValue = bottomValue.replace( bottomValue = bottomValue.replace(
@ -173,3 +190,4 @@ export const getWeekNumberISO8601 = (date: Date) => {
export const getDaysInMonth = (month: number, year: number) => { export const getDaysInMonth = (month: number, year: number) => {
return new Date(year, month + 1, 0).getDate(); return new Date(year, month + 1, 0).getDate();
}; };