Merge pull request #78 from MaTeMaTuK/dev

Dev
This commit is contained in:
MaTeMaTuK 2022-06-28 20:22:07 +02:00 committed by GitHub
commit b785b92e30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 13702 additions and 36034 deletions

View File

@ -1,13 +1,6 @@
{ {
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"extends": [ "extends": ["react-app", "react-app/jest"],
"standard",
"standard-react",
"plugin:prettier/recommended",
"prettier/standard",
"prettier/react",
"plugin:@typescript-eslint/eslint-recommended"
],
"plugins": ["@typescript-eslint"], "plugins": ["@typescript-eslint"],
"env": { "env": {
"node": true "node": true

15
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}

View File

@ -44,6 +44,7 @@ You may handle actions
onTaskDelete={onTaskDelete} onTaskDelete={onTaskDelete}
onProgressChange={onProgressChange} onProgressChange={onProgressChange}
onDoubleClick={onDblClick} onDoubleClick={onDblClick}
onClick={onClick}
/> />
``` ```
@ -72,6 +73,7 @@ npm start
| :----------------- | :---------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------- | | :----------------- | :---------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------- |
| onSelect | (task: Task, isSelected: boolean) => void | Specifies the function to be executed on the taskbar select or unselect event. | | onSelect | (task: Task, isSelected: boolean) => void | Specifies the function to be executed on the taskbar select or unselect event. |
| onDoubleClick | (task: Task) => void | Specifies the function to be executed on the taskbar onDoubleClick event. | | onDoubleClick | (task: Task) => void | Specifies the function to be executed on the taskbar onDoubleClick event. |
| onClick | (task: Task) => void | Specifies the function to be executed on the taskbar onClick event. |
| 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. |

28723
example/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,6 @@
"react-scripts": "file:../node_modules/react-scripts" "react-scripts": "file:../node_modules/react-scripts"
}, },
"devDependencies": { "devDependencies": {
"@babel/plugin-syntax-object-rest-spread": "^7.8.3"
}, },
"browserslist": { "browserslist": {
"production": [ "production": [

View File

@ -1,9 +1,9 @@
import React from 'react' import React from "react";
import ReactDOM from 'react-dom' import { createRoot } from "react-dom/client";
import App from './App' import App from "./App";
it('renders without crashing', () => { it("renders without crashing", () => {
const div = document.createElement('div') const div = document.createElement("div");
ReactDOM.render(<App />, div) const root = createRoot(div);
ReactDOM.unmountComponentAtNode(div) root.render(<App />);
}) });

View File

@ -52,6 +52,10 @@ const App = () => {
alert("On Double Click event Id:" + task.id); alert("On Double Click event Id:" + task.id);
}; };
const handleClick = (task: Task) => {
console.log("On Click event Id:" + task.id);
};
const handleSelect = (task: Task, isSelected: boolean) => { const handleSelect = (task: Task, isSelected: boolean) => {
console.log(task.name + " has " + (isSelected ? "selected" : "unselected")); console.log(task.name + " has " + (isSelected ? "selected" : "unselected"));
}; };
@ -76,6 +80,7 @@ const App = () => {
onDelete={handleTaskDelete} onDelete={handleTaskDelete}
onProgressChange={handleProgressChange} onProgressChange={handleProgressChange}
onDoubleClick={handleDblClick} onDoubleClick={handleDblClick}
onClick={handleClick}
onSelect={handleSelect} onSelect={handleSelect}
onExpanderClick={handleExpanderClick} onExpanderClick={handleExpanderClick}
listCellWidth={isChecked ? "155px" : ""} listCellWidth={isChecked ? "155px" : ""}
@ -89,6 +94,7 @@ const App = () => {
onDelete={handleTaskDelete} onDelete={handleTaskDelete}
onProgressChange={handleProgressChange} onProgressChange={handleProgressChange}
onDoubleClick={handleDblClick} onDoubleClick={handleDblClick}
onClick={handleClick}
onSelect={handleSelect} onSelect={handleSelect}
onExpanderClick={handleExpanderClick} onExpanderClick={handleExpanderClick}
listCellWidth={isChecked ? "155px" : ""} listCellWidth={isChecked ? "155px" : ""}

View File

@ -6,7 +6,7 @@ type ViewSwitcherProps = {
onViewListChange: (isChecked: boolean) => void; onViewListChange: (isChecked: boolean) => void;
onViewModeChange: (viewMode: ViewMode) => void; onViewModeChange: (viewMode: ViewMode) => void;
}; };
export const ViewSwitcher: React.SFC<ViewSwitcherProps> = ({ export const ViewSwitcher: React.FC<ViewSwitcherProps> = ({
onViewModeChange, onViewModeChange,
onViewListChange, onViewListChange,
isChecked, isChecked,

View File

@ -1,7 +1,9 @@
import "./index.css"; import "./index.css";
import React from "react"; import React from "react";
import ReactDOM from "react-dom"; import { createRoot } from "react-dom/client";
import App from "./App"; import App from "./App";
ReactDOM.render(<App />, document.getElementById("root")); const container = document.getElementById("root");
const root = createRoot(container!);
root.render(<App />);

20787
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -36,41 +36,29 @@
"deploy": "gh-pages -d example/build" "deploy": "gh-pages -d example/build"
}, },
"peerDependencies": { "peerDependencies": {
"react": "^17.0.2" "react": "^18.0.0"
}, },
"devDependencies": { "devDependencies": {
"@testing-library/jest-dom": "^5.12.0", "@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^11.2.6", "@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.1.8", "@testing-library/user-event": "^14.2.1",
"@types/jest": "^26.0.23", "@types/jest": "^27.5.1",
"@types/node": "^15.0.1", "@types/node": "^15.0.1",
"@types/react": "^17.0.38", "@types/react": "^18.0.5",
"@types/react-dom": "^17.0.11", "@types/react-dom": "^18.0.5",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.9.1",
"babel-eslint": "^10.0.3",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"eslint-config-prettier": "^6.15.0",
"eslint-config-standard": "^16.0.3",
"eslint-config-standard-react": "^9.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^5.2.0",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-standard": "^4.1.0",
"gh-pages": "^3.1.0", "gh-pages": "^3.1.0",
"microbundle-crl": "^0.13.11", "microbundle-crl": "^0.13.11",
"mini-css-extract-plugin": "^2.5.1", "mini-css-extract-plugin": "^2.5.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"postcss-flexbugs-fixes": "^5.0.2", "postcss-flexbugs-fixes": "^5.0.2",
"postcss-normalize": "^10.0.1", "postcss-normalize": "^10.0.1",
"postcss-preset-env": "^7.2.3", "postcss-preset-env": "^7.6.0",
"prettier": "^2.5.1", "prettier": "^2.7.1",
"react": "^17.0.2", "react": "^18.2.0",
"react-dom": "^17.0.2", "react-dom": "^18.2.0",
"react-scripts": "^5.0.0", "react-scripts": "^5.0.1",
"typescript": "^4.5.4" "typescript": "^4.7.4"
}, },
"files": [ "files": [
"dist" "dist"

View File

@ -241,16 +241,17 @@ export const Calendar: React.FC<CalendarProps> = ({
{bottomValue} {bottomValue}
</text> </text>
); );
if (i === 0 || date.getDate() !== dates[i - 1].getDate()) { if (i !== 0 && date.getDate() !== dates[i - 1].getDate()) {
const displayDate = dates[i - 1];
const topValue = `${getLocalDayOfWeek( const topValue = `${getLocalDayOfWeek(
date, displayDate,
locale, locale,
"long" "long"
)}, ${date.getDate()} ${getLocaleMonth(date, locale)}`; )}, ${displayDate.getDate()} ${getLocaleMonth(displayDate, locale)}`;
const topPosition = (date.getHours() - 24) / 2; const topPosition = (date.getHours() - 24) / 2;
topValues.push( topValues.push(
<TopPartOfCalendar <TopPartOfCalendar
key={topValue + date.getFullYear()} key={topValue + displayDate.getFullYear()}
value={topValue} value={topValue}
x1Line={columnWidth * i} x1Line={columnWidth * i}
y1Line={0} y1Line={0}

View File

@ -60,6 +60,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
onDateChange, onDateChange,
onProgressChange, onProgressChange,
onDoubleClick, onDoubleClick,
onClick,
onDelete, onDelete,
onSelect, onSelect,
onExpanderClick, onExpanderClick,
@ -182,6 +183,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
viewDate, viewDate,
columnWidth, columnWidth,
dateSetup.dates, dateSetup.dates,
dateSetup.viewMode,
viewMode, viewMode,
currentViewDate, currentViewDate,
setCurrentViewDate, setCurrentViewDate,
@ -244,7 +246,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
} else { } else {
setSvgContainerHeight(tasks.length * rowHeight + headerHeight); setSvgContainerHeight(tasks.length * rowHeight + headerHeight);
} }
}, [ganttHeight, tasks]); }, [ganttHeight, tasks, headerHeight, rowHeight]);
// scroll events // scroll events
useEffect(() => { useEffect(() => {
@ -276,30 +278,38 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
}; };
// subscribe if scroll is necessary // subscribe if scroll is necessary
if (wrapperRef.current) { wrapperRef.current?.addEventListener("wheel", handleWheel, {
wrapperRef.current.addEventListener("wheel", handleWheel, { passive: false,
passive: false, });
});
}
return () => { return () => {
if (wrapperRef.current) { wrapperRef.current?.removeEventListener("wheel", handleWheel);
wrapperRef.current.removeEventListener("wheel", handleWheel);
}
}; };
}, [wrapperRef.current, scrollY, scrollX, ganttHeight, svgWidth, rtl]); }, [
wrapperRef,
scrollY,
scrollX,
ganttHeight,
svgWidth,
rtl,
ganttFullHeight,
]);
const handleScrollY = (event: SyntheticEvent<HTMLDivElement>) => { const handleScrollY = (event: SyntheticEvent<HTMLDivElement>) => {
if (scrollY !== event.currentTarget.scrollTop && !ignoreScrollEvent) { if (scrollY !== event.currentTarget.scrollTop && !ignoreScrollEvent) {
setScrollY(event.currentTarget.scrollTop); setScrollY(event.currentTarget.scrollTop);
setIgnoreScrollEvent(true);
} else {
setIgnoreScrollEvent(false);
} }
setIgnoreScrollEvent(false);
}; };
const handleScrollX = (event: SyntheticEvent<HTMLDivElement>) => { const handleScrollX = (event: SyntheticEvent<HTMLDivElement>) => {
if (scrollX !== event.currentTarget.scrollLeft && !ignoreScrollEvent) { if (scrollX !== event.currentTarget.scrollLeft && !ignoreScrollEvent) {
setScrollX(event.currentTarget.scrollLeft); setScrollX(event.currentTarget.scrollLeft);
setIgnoreScrollEvent(true);
} else {
setIgnoreScrollEvent(false);
} }
setIgnoreScrollEvent(false);
}; };
/** /**
@ -411,6 +421,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
onDateChange, onDateChange,
onProgressChange, onProgressChange,
onDoubleClick, onDoubleClick,
onClick,
onDelete, onDelete,
}; };

View File

@ -53,6 +53,7 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
onDateChange, onDateChange,
onProgressChange, onProgressChange,
onDoubleClick, onDoubleClick,
onClick,
onDelete, onDelete,
}) => { }) => {
const point = svg?.current?.createSVGPoint(); const point = svg?.current?.createSVGPoint();
@ -185,6 +186,10 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
onDateChange, onDateChange,
svg, svg,
isMoving, isMoving,
point,
rtl,
setFailedTask,
setGanttEvent,
]); ]);
/** /**
@ -230,6 +235,8 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
} }
} else if (action === "dblclick") { } else if (action === "dblclick") {
!!onDoubleClick && onDoubleClick(task); !!onDoubleClick && onDoubleClick(task);
} else if (action === "click") {
!!onClick && onClick(task);
} }
// Change task event start // Change task event start
else if (action === "move") { else if (action === "move") {

View File

@ -1,4 +1,36 @@
.scroll { .scrollWrapper {
overflow: auto; overflow: auto;
max-width: 100%; max-width: 100%;
/*firefox*/
scrollbar-width: thin;
/*iPad*/
height: 1.1rem;
}
.scrollWrapper::-webkit-scrollbar {
width: 1.1rem;
height: 1.1rem;
}
.scrollWrapper::-webkit-scrollbar-corner {
background: transparent;
}
.scrollWrapper::-webkit-scrollbar-thumb {
border: 6px solid transparent;
background: rgba(0, 0, 0, 0.2);
background: var(--palette-black-alpha-20, rgba(0, 0, 0, 0.2));
border-radius: 10px;
background-clip: padding-box;
}
.scrollWrapper::-webkit-scrollbar-thumb:hover {
border: 4px solid transparent;
background: rgba(0, 0, 0, 0.3);
background: var(--palette-black-alpha-30, rgba(0, 0, 0, 0.3));
background-clip: padding-box;
}
@media only screen and (max-device-width: 1024px) and (-webkit-min-device-pixel-ratio: 2) {
.scrollWrapper {
-webkit-overflow-scrolling: touch;
}
}
.scroll {
height: 1px;
} }

View File

@ -24,11 +24,11 @@ export const HorizontalScroll: React.FC<{
? `0px ${taskListWidth}px 0px 0px` ? `0px ${taskListWidth}px 0px 0px`
: `0px 0px 0px ${taskListWidth}px`, : `0px 0px 0px ${taskListWidth}px`,
}} }}
className={styles.scroll} className={styles.scrollWrapper}
onScroll={onScroll} onScroll={onScroll}
ref={scrollRef} ref={scrollRef}
> >
<div style={{ width: svgWidth, height: 1 }} /> <div style={{ width: svgWidth }} className={styles.scroll} />
</div> </div>
); );
}; };

View File

@ -84,7 +84,7 @@ export const Tooltip: React.FC<TooltipProps> = ({
setRelatedX(newRelatedX); setRelatedX(newRelatedX);
} }
}, [ }, [
tooltipRef.current, tooltipRef,
task, task,
arrowIndent, arrowIndent,
scrollX, scrollX,
@ -94,6 +94,7 @@ export const Tooltip: React.FC<TooltipProps> = ({
rowHeight, rowHeight,
svgContainerHeight, svgContainerHeight,
svgContainerWidth, svgContainerWidth,
rtl,
]); ]);
return ( return (

View File

@ -2,4 +2,26 @@
overflow: hidden auto; overflow: hidden auto;
width: 17px; width: 17px;
flex-shrink: 0; flex-shrink: 0;
/*firefox*/
scrollbar-width: thin;
}
.scroll::-webkit-scrollbar {
width: 1.1rem;
height: 1.1rem;
}
.scroll::-webkit-scrollbar-corner {
background: transparent;
}
.scroll::-webkit-scrollbar-thumb {
border: 6px solid transparent;
background: rgba(0, 0, 0, 0.2);
background: var(--palette-black-alpha-20, rgba(0, 0, 0, 0.2));
border-radius: 10px;
background-clip: padding-box;
}
.scroll::-webkit-scrollbar-thumb:hover {
border: 4px solid transparent;
background: rgba(0, 0, 0, 0.3);
background: var(--palette-black-alpha-30, rgba(0, 0, 0, 0.3));
background-clip: padding-box;
} }

View File

@ -100,6 +100,9 @@ export const TaskItem: React.FC<TaskItemProps> = props => {
onDoubleClick={e => { onDoubleClick={e => {
onEventStart("dblclick", task, e); onEventStart("dblclick", task, e);
}} }}
onClick={e => {
onEventStart("click", task, e);
}}
onFocus={() => { onFocus={() => {
onEventStart("select", task); onEventStart("select", task);
}} }}

View File

@ -1,11 +1,12 @@
import React from "react"; import React from "react";
import ReactDOM from "react-dom"; import { createRoot } from "react-dom/client";
import { Gantt } from "../index"; import { Gantt } from "../index";
describe("gantt", () => { describe("gantt", () => {
it("renders without crashing", () => { it("renders without crashing", () => {
const div = document.createElement("div"); const div = document.createElement("div");
ReactDOM.render( const root = createRoot(div);
root.render(
<Gantt <Gantt
tasks={[ tasks={[
{ {
@ -17,9 +18,7 @@ describe("gantt", () => {
type: "task", type: "task",
}, },
]} ]}
/>, />
div
); );
ReactDOM.unmountComponentAtNode(div);
}); });
}); });

View File

@ -6,6 +6,7 @@ export type GanttContentMoveAction =
| "mouseleave" | "mouseleave"
| "delete" | "delete"
| "dblclick" | "dblclick"
| "click"
| "select" | "select"
| "" | ""
| BarMoveAction; | BarMoveAction;

View File

@ -44,6 +44,10 @@ export interface EventOption {
* Invokes on bar double click. * Invokes on bar double click.
*/ */
onDoubleClick?: (task: Task) => void; onDoubleClick?: (task: Task) => void;
/**
* Invokes on bar click.
*/
onClick?: (task: Task) => void;
/** /**
* Invokes on end and start time change. Chart undoes operation if method return false or error. * Invokes on end and start time change. Chart undoes operation if method return false or error.
*/ */