Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript Convertion - WIP #150

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
]
}
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

24 changes: 0 additions & 24 deletions .eslintrc.json

This file was deleted.

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

# Fork Warning

This is a fork used internally by Muzz and is currently only used to visualize data. We can assure that the scheduler visualization is working. However, editing and modification of events are not used by us and have not been tested. Use at your own risk.

# React Big Schedule (react-big-schedule)

[![NPM version][npm-image]][npm-url] [![MIT License][mit-image]][mit-url] [![CodeQL][codeql-image]][codeql-url] [![CodeFactor][codeFactor-badge]][codeFactor-link]
Expand Down
9 changes: 9 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import baseConfig from "@repo/eslint-config/base";

/** @type {import('typescript-eslint').Config} */
export default [
{
ignores: [".nitro/**", ".output/**"],
},
...baseConfig,
];
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@
},
"dependencies": {
"@ant-design/icons": "^5.3.0",
"@babel/preset-typescript": "^7.24.7",
"antd": "^5.14.1",
"dayjs": "^1.11.10",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react": "catalog:react19",
"react-dom": "catalog:react19",
"react-dnd": "^14.0.5",
"react-dnd-html5-backend": "^14.1.0",
"react-dom": "^18.2.0",
"rrule": "^2.8.1"
"rrule": "^2.8.1",
"ts-loader": "^9.5.1",
"typescript": "^5.6.2"
},
"devDependencies": {
"@babel/cli": "^7.23.9",
Expand All @@ -85,6 +88,9 @@
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-webpack-plugin": "^4.0.1",
"@types/node": "catalog:",
"@types/react": "catalog:react19",
"@types/react-dom": "catalog:react19",
"fs-extra": "^11.2.0",
"html-webpack-plugin": "^5.6.0",
"style-loader": "^4.0.0",
Expand Down
4 changes: 0 additions & 4 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ async function build() {
const root = path.resolve(__dirname, '..');
const sourceDir = path.resolve(root, 'src');
const targetDir = path.resolve(root, 'dist');
const typingDir = path.resolve(root, 'typing');
const jsTarget = targetDir;
const cssTarget = path.resolve(targetDir, 'css');
const excludedFolders = ['examples', 'main.jsx'];
Expand All @@ -36,9 +35,6 @@ async function build() {
process.stdout.write('Copying CSS Files... \n');
await fs.copy(`${sourceDir}/css/`, cssTarget);

process.stdout.write('Copying Typescript Files... \n');
await fs.copy(`${typingDir}/`, targetDir);

process.stdout.write('Success! \n');
} catch (e) {
console.log(e);
Expand Down
241 changes: 241 additions & 0 deletions src/classComponents/DnDContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
// @ts-nocheck

import { DropTarget, DropTargetMonitor, DropTargetConnector } from "react-dnd";
import {
DnDTypes,
CellUnit,
DATETIME_FORMAT,
ViewType,
} from "../config/default";
import { getPos } from "../helper/utility";
import dayjs, { Dayjs } from "dayjs";
import { SchedulerData } from "../components/Scheduler";
import {
EventItemType,
RenderDataItem,
ResourceEvent,
} from "../types/baseType";
import { DnDSource } from "./DnDSource";
// Types in this in this file have been generated by AI and are not accurate. Please replace them with the correct types.

interface DnDContextProps {
schedulerData: SchedulerData;
resourceEvents: RenderDataItem;
movingEvent?: (
schedulerData: SchedulerData,
slotId: string,
slotName: string,
newStart: Dayjs,
newEnd: Dayjs,
action: string,
type: DnDTypes,
item: EventItemType
) => void;
}

export class DnDContext {
private sourceMap: Map<string, DnDSource>;
private DecoratedComponent: React.ComponentType<any>;
private config: any;

constructor(
sources: DnDSource[],
DecoratedComponent: React.ComponentType<any>
) {
this.sourceMap = new Map();
sources.forEach((item) => {
this.sourceMap.set(item.dndType, item);
});
this.DecoratedComponent = DecoratedComponent;
}

extractInitialTimes = (
monitor: DropTargetMonitor,
pos: { x: number; y: number },
cellWidth: number,
resourceEvents: RenderDataItem,
cellUnit: CellUnit,
localeDayjs: typeof dayjs
) => {
const initialPoint = monitor.getInitialClientOffset();
let initialStart = localeDayjs();
let initialEnd = localeDayjs();
if (!initialPoint) return { initialStart, initialEnd };
const initialLeftIndex = Math.floor((initialPoint.x - pos.x) / cellWidth);

if (resourceEvents.headerItems[initialLeftIndex]?.start) {
initialStart = resourceEvents.headerItems[initialLeftIndex].start;
}
if (resourceEvents.headerItems[initialLeftIndex]?.end) {
let initialEnd = resourceEvents.headerItems[initialLeftIndex]?.end;
if (cellUnit !== CellUnit.Hour) {
var end = initialStart.hour(23).minute(59).second(59);
initialEnd = end;
}
}
return { initialStart, initialEnd };
};

getDropSpec = () => ({
drop: (
props: DnDContextProps,
monitor: DropTargetMonitor,
component: any
) => {
const { schedulerData, resourceEvents } = props;
const { cellUnit, localeDayjs } = schedulerData;
const type = monitor.getItemType();
const pos = getPos(component.eventContainer);
const cellWidth = schedulerData.getContentCellWidth();
let initialStartTime = null;
let initialEndTime = null;
if (type === DnDTypes.EVENT) {
const { initialStart, initialEnd } = this.extractInitialTimes(
monitor,
pos,
cellWidth,
resourceEvents,
cellUnit,
localeDayjs
);
initialStartTime = initialStart;
initialEndTime = initialEnd;
}
const point = monitor.getClientOffset();
if (!point) return null;
const leftIndex = Math.floor((point.x - pos.x) / cellWidth);
const startTime =
resourceEvents.headerItems[leftIndex]?.start || localeDayjs();
let endTime = resourceEvents.headerItems[leftIndex]?.end || localeDayjs();
if (cellUnit !== CellUnit.Hour) {
endTime = (
resourceEvents.headerItems[leftIndex]?.start || localeDayjs()
)
.hour(23)
.minute(59)
.second(59);
}

return {
slotId: resourceEvents.slotId,
slotName: resourceEvents.slotName,
start: startTime,
end: endTime,
initialStart: initialStartTime,
initialEnd: initialEndTime,
};
},

hover: (
props: DnDContextProps,
monitor: DropTargetMonitor,
component: any
) => {
const { schedulerData, resourceEvents, movingEvent } = props;
const { cellUnit, config, viewType, localeDayjs } = schedulerData;
this.config = config;
const item: EventItemType = monitor.getItem();
const type = monitor.getItemType() as DnDTypes;
const pos = getPos(component.eventContainer);
const cellWidth = schedulerData.getContentCellWidth();
let initialStart = null;
if (type === DnDTypes.EVENT) {
const { initialStart: iStart } = this.extractInitialTimes(
monitor,
pos,
cellWidth,
resourceEvents,
cellUnit,
localeDayjs
);
initialStart = iStart;
}

const point = monitor.getClientOffset();
if (!point) return;
const leftIndex = Math.floor((point.x - pos.x) / cellWidth);
if (!resourceEvents.headerItems[leftIndex]) {
return;
}
let newStart = resourceEvents.headerItems[leftIndex].start;
let newEnd = resourceEvents.headerItems[leftIndex].end;
if (cellUnit !== CellUnit.Hour) {
newEnd = (resourceEvents.headerItems[leftIndex].start || localeDayjs())
.hour(23)
.minute(59)
.second(59);
}
let { slotId, slotName } = resourceEvents;
let action = "New";
const isEvent = type === DnDTypes.EVENT;
if (isEvent) {
const event = item;
if (config.relativeMove) {
newStart = event.start.add(newStart.diff(initialStart), "ms");
} else if (viewType !== ViewType.Day) {
const tmpDayjs = localeDayjs(newStart);
newStart = event.start
.year(tmpDayjs.year())
.month(tmpDayjs.month())
.date(tmpDayjs.date());
}
newEnd = localeDayjs(newStart).add(event.end.diff(event.start), "ms");

if (config.crossResourceMove === false) {
slotId = schedulerData._getEventSlotId(item);
// @ts-ignore TODO: Fix this type
slotName = undefined;
const slot = schedulerData.getSlotById(slotId);
if (slot) slotName = slot.name;
}

action = "Move";
}

if (movingEvent) {
movingEvent(
schedulerData,
slotId,
slotName,
newStart,
newEnd,
action,
type,
item
);
}
},

canDrop: (props: DnDContextProps, monitor: DropTargetMonitor) => {
const { schedulerData, resourceEvents } = props;
const item: EventItemType = monitor.getItem();
if (schedulerData._isResizing()) return false;
const { config } = schedulerData;
return (
config.movable &&
!resourceEvents.groupOnly &&
(item.movable === undefined || item.movable !== false)
);
},
});

getDropCollect = (
connect: DropTargetConnector,
monitor: DropTargetMonitor
) => ({
connectDropTarget: connect.dropTarget(),
isOver: monitor.isOver(),
});

getDropTarget = (dragAndDropEnabled: boolean) =>
dragAndDropEnabled
? DropTarget(
[...this.sourceMap.keys()],
this.getDropSpec(),
this.getDropCollect
)(this.DecoratedComponent)
: this.DecoratedComponent;

getDndSource = (dndType: string = DnDTypes.EVENT) =>
this.sourceMap.get(dndType);
}
Loading