@kkkarsss/ui 1.1.4 → 1.1.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.
@@ -1,7 +1,7 @@
1
1
  import { type FC, type DragEvent, ReactNode } from 'react';
2
2
  export type TCalendarHourSlotProps = {
3
3
  hour: number;
4
- onDrop?: (e: DragEvent<HTMLDivElement>, hour: number) => void;
4
+ onDrop?: (e: DragEvent<HTMLDivElement>, hour: number, minutes: number) => void;
5
5
  onCreateTask?: (hour: number, minutes: number, estimatedTime: number) => void;
6
6
  children?: ReactNode;
7
7
  };
@@ -3,8 +3,25 @@ import { useState } from 'react';
3
3
  import { Typo } from '../text/typo';
4
4
  export const CalendarHourSlot = ({ hour, onDrop, onCreateTask, children }) => {
5
5
  const [selection, setSelection] = useState(null);
6
+ const [dragOverMinutes, setDragOverMinutes] = useState(null);
6
7
  const handleDragOver = (e) => {
7
8
  e.preventDefault();
9
+ const rect = e.currentTarget.getBoundingClientRect();
10
+ const offsetY = e.clientY - rect.top;
11
+ const minutes = Math.floor(offsetY / 20) * 15;
12
+ if (minutes !== dragOverMinutes) {
13
+ setDragOverMinutes(minutes);
14
+ }
15
+ };
16
+ const handleDragLeave = () => {
17
+ setDragOverMinutes(null);
18
+ };
19
+ const handleInternalDrop = (e) => {
20
+ setDragOverMinutes(null);
21
+ const rect = e.currentTarget.getBoundingClientRect();
22
+ const offsetY = e.clientY - rect.top;
23
+ const minutes = Math.floor(offsetY / 20) * 15;
24
+ onDrop?.(e, hour, minutes);
8
25
  };
9
26
  const handleMouseDown = (e) => {
10
27
  if (e.button !== 0 || !onCreateTask)
@@ -37,10 +54,10 @@ export const CalendarHourSlot = ({ hour, onDrop, onCreateTask, children }) => {
37
54
  document.addEventListener('mousemove', onMouseMove);
38
55
  document.addEventListener('mouseup', onMouseUp);
39
56
  };
40
- return (_jsxs("div", { onDragOver: handleDragOver, onDrop: (e) => onDrop?.(e, hour), onMouseDown: handleMouseDown, className: "relative h-20 border-b border-secondary-foreground group hover:z-10 has-[.calendar-item:hover]:z-30 has-[.calendar-item:active]:z-30", children: [_jsx("div", { className: "absolute -left-12 top-0 -translate-y-1/2 w-10 text-right", children: _jsxs(Typo, { size: "xs", color: "secondary", children: [String(hour).padStart(2, '0'), ":00"] }) }), _jsxs("div", { className: "pl-4 py-1 relative h-full", children: [(() => {
41
- console.log(`CalendarHourSlot: rendering hour ${hour}, children count: ${Array.isArray(children) ? children.length : children ? 1 : 0}`);
42
- return null;
43
- })(), children, selection && (_jsx("div", { className: "absolute left-4 right-1 bg-accent/30 border border-accent rounded-sm z-[40] pointer-events-none", style: {
57
+ return (_jsxs("div", { onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: handleInternalDrop, onMouseDown: handleMouseDown, className: "relative h-20 border-b border-secondary-foreground group hover:z-10 has-[.calendar-item:hover]:z-30 has-[.calendar-item:active]:z-30", children: [_jsx("div", { className: "absolute -left-12 top-0 -translate-y-1/2 w-10 text-right", children: _jsxs(Typo, { size: "xs", color: "secondary", children: [String(hour).padStart(2, '0'), ":00"] }) }), _jsxs("div", { className: "pl-4 py-1 relative h-full", children: [children, dragOverMinutes !== null && (_jsx("div", { className: "absolute left-4 right-1 bg-accent/10 border border-dashed border-accent/50 rounded-sm z-[40] pointer-events-none", style: {
58
+ top: `${(dragOverMinutes / 60) * 80}px`,
59
+ height: '20px',
60
+ } })), selection && (_jsx("div", { className: "absolute left-4 right-1 bg-accent/30 border border-accent rounded-sm z-[40] pointer-events-none", style: {
44
61
  top: `${(selection.startMinutes / 60) * 80}px`,
45
62
  height: `${(selection.currentEstimatedTime / 60) * 80}px`,
46
63
  }, children: _jsxs("div", { className: "p-1", children: [_jsx(Typo, { size: "xs", weight: "500", children: "\u041D\u043E\u0432\u0430\u044F \u0437\u0430\u0434\u0430\u0447\u0430" }), _jsxs(Typo, { size: "xs", color: "secondary", children: [selection.currentEstimatedTime, " \u043C\u0438\u043D"] })] }) }))] })] }));
@@ -2,7 +2,6 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
3
  import { jc } from '../../../utils';
4
4
  export const CalendarItemWrapper = ({ task, position, onDragStart, onResize, renderTask, }) => {
5
- console.log(`CalendarItemWrapper: task ${task.id} (${task.title}), position:`, position);
6
5
  const [previewEstimatedTime, setPreviewEstimatedTime] = useState(null);
7
6
  const handleMouseDown = (e) => {
8
7
  if (onResize) {
@@ -39,15 +38,15 @@ export const CalendarItemWrapper = ({ task, position, onDragStart, onResize, ren
39
38
  const displayHeight = previewEstimatedTime ? `${(previewEstimatedTime / 60) * 80}px` : position.height;
40
39
  return (_jsx("div", { draggable: !!onDragStart, onDragStart: (e) => {
41
40
  onDragStart?.(e, task.id);
42
- setTimeout(() => {
43
- const el = e.currentTarget;
44
- if (el)
45
- el.style.pointerEvents = 'none';
46
- }, 0);
41
+ const el = e.currentTarget;
42
+ if (el) {
43
+ el.style.opacity = '0.4';
44
+ }
47
45
  }, onDragEnd: (e) => {
48
46
  const el = e.currentTarget;
49
- if (el)
50
- el.style.pointerEvents = '';
47
+ if (el) {
48
+ el.style.opacity = '';
49
+ }
51
50
  }, style: {
52
51
  height: displayHeight,
53
52
  width: position.width,
@@ -4,7 +4,6 @@ import { jc } from '../../../utils';
4
4
  import { Flex } from '../../layout';
5
5
  import { Typo } from '../text/typo';
6
6
  export const CalendarItem = ({ title, description, isCompleted, isInWork, onClick, icon, estimatedTime = 30, color, className, }) => {
7
- console.log(`CalendarItem: rendering ${title}, color: ${color}`);
8
7
  return (_jsxs("div", { className: jc('w-full h-full p-1 rounded-sm border flex flex-col transition-colors relative', !color && (isCompleted ? 'opacity-50 border-secondary bg-accent/50' : 'border-accent bg-accent'), color && (isCompleted ? 'opacity-50' : ''), className), style: {
9
8
  backgroundColor: color ? `${color}80` : undefined,
10
9
  borderColor: color ? color : undefined,
@@ -8,32 +8,19 @@ export * from './calendar-item-wrapper';
8
8
  export * from './calendar-item';
9
9
  const DEFAULT_HOURS = Array.from({ length: 24 }, (_, i) => i);
10
10
  export const CalendarLike = ({ tasks, hours = DEFAULT_HOURS, renderTask, onTaskDrop, onTaskResize, onCreateTask, }) => {
11
- console.log('CalendarLike: render, tasks count:', tasks.length);
12
- if (tasks.length > 0) {
13
- console.log('CalendarLike: first task title:', tasks[0].title);
14
- }
15
- const tasksWithPosition = useMemo(() => {
16
- const result = calculateTaskPositions(tasks);
17
- console.log('CalendarLike: calculateTaskPositions result count:', result.length);
18
- return result;
19
- }, [tasks]);
20
- const tasksByHour = useMemo(() => {
21
- const result = groupTasksByHour(tasksWithPosition);
22
- console.log('CalendarLike: groupTasksByHour result keys:', Object.keys(result));
23
- return result;
24
- }, [tasksWithPosition]);
11
+ const tasksWithPosition = useMemo(() => calculateTaskPositions(tasks), [tasks]);
12
+ const tasksByHour = useMemo(() => groupTasksByHour(tasksWithPosition), [tasksWithPosition]);
25
13
  const handleDragStart = (e, taskId) => {
26
14
  e.dataTransfer.setData('taskId', taskId);
27
15
  };
28
- const handleDrop = (e, hour) => {
16
+ const handleDrop = (e, hour, minutes) => {
29
17
  const taskId = e.dataTransfer.getData('taskId');
30
18
  if (taskId && onTaskDrop) {
31
- onTaskDrop(taskId, hour);
19
+ onTaskDrop(taskId, hour, minutes);
32
20
  }
33
21
  };
34
22
  return (_jsx("div", { className: "relative border-l border-secondary/20 ml-12 select-none", children: hours.map((hour) => {
35
23
  const tasksForHour = tasksByHour[hour];
36
- console.log(`CalendarLike: hour ${hour} has ${tasksForHour?.length || 0} tasks`);
37
24
  return (_jsx(CalendarHourSlot, { hour: hour, onDrop: handleDrop, onCreateTask: onCreateTask, children: tasksForHour?.map((task) => (_jsx(CalendarItemWrapper, { task: task, position: task.position, onDragStart: handleDragStart, onResize: onTaskResize, renderTask: renderTask }, task.id))) }, hour));
38
25
  }) }));
39
26
  };
@@ -17,7 +17,7 @@ export type TCalendarLikeProps = {
17
17
  tasks: TCalendarTask[];
18
18
  hours?: number[];
19
19
  renderTask: (task: TCalendarTask) => ReactNode;
20
- onTaskDrop?: (taskId: string, hour: number) => void;
20
+ onTaskDrop?: (taskId: string, hour: number, minutes: number) => void;
21
21
  onTaskResize?: (taskId: string, newEstimatedTime: number) => void;
22
22
  onTaskClick?: (taskId: string) => void;
23
23
  onCreateTask?: (hour: number, minutes: number, estimatedTime: number) => void;
@@ -1,18 +1,11 @@
1
1
  export const calculateTaskPositions = (tasks) => {
2
- console.log('calculateTaskPositions: input:', tasks);
3
2
  const tasksToRender = [...tasks]
4
3
  .map((t) => ({
5
4
  ...t,
6
5
  dueDate: t.dueDate instanceof Date ? t.dueDate : new Date(t.dueDate),
7
6
  }))
8
- .filter((t) => {
9
- const isValid = t.dueDate && !isNaN(t.dueDate.getTime());
10
- if (!isValid)
11
- console.warn('calculateTaskPositions: invalid date for task:', t.id, t.dueDate);
12
- return isValid;
13
- })
7
+ .filter((t) => t.dueDate && !isNaN(t.dueDate.getTime()))
14
8
  .sort((a, b) => a.dueDate.getTime() - b.dueDate.getTime());
15
- console.log('calculateTaskPositions: tasksToRender:', tasksToRender);
16
9
  const columns = [];
17
10
  tasksToRender.forEach((task) => {
18
11
  const startTime = task.dueDate.getTime();
@@ -63,7 +56,6 @@ export const calculateTaskPositions = (tasks) => {
63
56
  const left = clusterColumnsCount > 1 ? `${(colIndex * 100) / clusterColumnsCount}%` : '0%';
64
57
  const top = `${(task.dueDate.getMinutes() / 60) * 80}px`;
65
58
  const height = `${(Math.max(15, task.estimatedTime || 15) / 60) * 80}px`;
66
- console.log(`calculateTaskPositions: task ${task.id} position:`, { width, left, top, height });
67
59
  result.push({
68
60
  ...task,
69
61
  position: { width, left, top, height },
@@ -74,14 +66,12 @@ export const calculateTaskPositions = (tasks) => {
74
66
  return result;
75
67
  };
76
68
  export const groupTasksByHour = (tasksWithPosition) => {
77
- console.log('groupTasksByHour: input count:', tasksWithPosition.length);
78
69
  const map = {};
79
70
  tasksWithPosition.forEach((task) => {
80
71
  const hour = task.dueDate.getHours();
81
72
  if (!map[hour])
82
73
  map[hour] = [];
83
74
  map[hour].push(task);
84
- console.log(`groupTasksByHour: task ${task.id} (${task.title}) assigned to hour ${hour}`);
85
75
  });
86
76
  return map;
87
77
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kkkarsss/ui",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "UI Kit for kkkarsss projects",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",