Skip to content

Commit

Permalink
feat: merge changes from production
Browse files Browse the repository at this point in the history
  • Loading branch information
florianbepunkt committed Aug 24, 2023
1 parent 81b931d commit 9ed8980
Show file tree
Hide file tree
Showing 30 changed files with 2,546 additions and 228 deletions.
7 changes: 0 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
## [1.0.6](https://github.com/florianbepunkt/timeline/compare/v1.0.5...v1.0.6) (2023-08-13)


### Bug Fixes

* **deps:** update dependency ts-pattern to v5 ([92ae091](https://github.com/florianbepunkt/timeline/commit/92ae0910e4ad085b6b1d69d68a3ae5c8152fb3f3))

## [1.0.5](https://github.com/florianbepunkt/timeline/compare/v1.0.4...v1.0.5) (2023-01-30)


Expand Down
7 changes: 1 addition & 6 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# Bugs

- css bug item title overflow [x]
- bug: items not visible initially (not in stories, but when importing / using package) []
- bug: stories in safari do not render timeline at correct position (defaultStart / defaultEnd), Chrome is ok []

# TODO

- css design []
- header... primary should be a flag not a unit, semantics matter []
- dissolve \_\_fixtures\_\_ folder []
- refactor timeline as functional ... end boss style []
- refactor timeline as functional ... end boss []
- refactor scroll/ScrollElement as functional (naah, we need to fix the test first) []
- add living documentation in form of typescript docs and stories []

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"additionalBranchPrefix": "{{parentDir}}-",
"automerge": true,
"automerge": false,
"automergeType": "branch",
"extends": ["config:base", "group:allNonMajor", "schedule:monthly", ":pinDependencies"],
"labels": ["chore", "dependencies"],
Expand Down
2 changes: 1 addition & 1 deletion src/headers/sidebar-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type SidebarHeaderChildrenFnProps<Data> = {
};

const defaultSidebarHeaderChildren = ({ getRootProps }: SidebarHeaderChildrenFnProps<unknown>) => (
<div data-testid="sidebarHeader" {...getRootProps({ style: {} })} />
<div className="rct-sidebar-header" data-testid="sidebarHeader" {...getRootProps({ style: {} })} />
);

export const SidebarHeader = <T,>(props: SidebarHeaderProps<T>): JSX.Element => {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export { CursorMarker, CustomMarker, NowMarker } from "./markers/index.js";
export { CustomHeader, DateHeader, SidebarHeader, TimelineHeaders } from "./headers/index.js";
export { defaultTimeSteps, defaultHeaderFormats } from "./default-config.js";
export { Timeline, TimelineContext } from "./timeline/index.js";
export type { Id, TimelineGroupBase, TimelineItemBase } from "./shared-model.js";
export type { Id, TimelineGroupBase, TimelineItemBase, TimelineItemEdge } from "./shared-model.js";
export type { ItemRendererProps } from "./items/index.js";
export type { TimelineProps } from "./timeline/index.js";
51 changes: 32 additions & 19 deletions src/items/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ export const Item = <TGroup extends TimelineGroupBase, TItem extends TimelineIte

const [interactMounted, setInteractMounted] = React.useState(false);
const [dragging, setDragging] = useRefState(false);
const [dragTime, setDragTime] = React.useState<number | null>(null);
const [dragGroupDelta, setDragGroupDelta] = useRefState<number | null>(null);
const [dragStart, setDragStart] = useRefState<{ x: number; y: number; offset: number } | null>(null);

// const [dragGroupDelta, setDragGroupDelta] = useRefState<number | null>(null);
// const [dragStart, setDragStart] = useRefState<{ x: number; y: number; offset: number } | null>(null);
const dragStart = React.useRef<{ x: number; y: number; offset: number } | null>(null);
const dragTime = React.useRef<number | null>(null);
const dragGroupDelta = React.useRef<number | null>(null);
// const [dragTime, setDragTime] = React.useState<number | null>(null);

const [resizing, setResizing] = useRefState(false);
const [resizeEdge, setResizeEdge] = useRefState<TimelineItemEdge | undefined>(undefined);
Expand All @@ -178,7 +182,7 @@ export const Item = <TGroup extends TimelineGroupBase, TItem extends TimelineIte
const offset = considerOffset ? new Date().getTimezoneOffset() * 60 * 1000 : 0;
return Math.round(dragTime / dragSnap) * dragSnap - (offset % dragSnap);
} else {
return dragTime;
return Math.round(dragTime);
}
};

Expand All @@ -187,7 +191,7 @@ export const Item = <TGroup extends TimelineGroupBase, TItem extends TimelineIte
const endTime = item.endTime % dragSnap;
return Math.round((dragTime - endTime) / dragSnap) * dragSnap + endTime;
} else {
return dragTime;
return Math.round(dragTime);
}
};

Expand Down Expand Up @@ -243,20 +247,25 @@ export const Item = <TGroup extends TimelineGroupBase, TItem extends TimelineIte
if (!props.selected) return false;
const clickTime = timeFor(e);
setDragging(true);
setDragStart({ x: e.pageX, y: e.pageY, offset: item.startTime - clickTime });
setDragTime(item.startTime);
setDragGroupDelta(0);
// setDragStart({ x: e.pageX, y: e.pageY, offset: item.startTime - clickTime });
dragStart.current = { x: e.pageX, y: e.pageY, offset: item.startTime - clickTime };
dragTime.current = item.startTime;
// setDragTime(item.startTime);
dragGroupDelta.current = 0;
// setDragGroupDelta(0);
return;
};

const handleDragMove = (e: DragEvent) => {
if (!dragging.current) return;
let newDragTime = getDragTime(e);
const dragGroupDelta = getDragGroupDelta(e);
const newDragGroupDelta = getDragGroupDelta(e);
if (props.moveResizeValidator) newDragTime = props.moveResizeValidator("move", item, newDragTime);
if (props.onDrag) props.onDrag(item.id, newDragTime, props.order.index + dragGroupDelta);
setDragTime(newDragTime);
setDragGroupDelta(dragGroupDelta);
if (props.onDrag) props.onDrag(item.id, newDragTime, props.order.index + newDragGroupDelta);
// setDragTime(newDragTime);
dragTime.current = newDragTime;
// setDragGroupDelta(newDragGroupDelta);
dragGroupDelta.current = newDragGroupDelta;
};

const handleDragEnd = (e: DragEvent) => {
Expand All @@ -267,9 +276,12 @@ export const Item = <TGroup extends TimelineGroupBase, TItem extends TimelineIte
props.onDrop(item.id, dragTime, props.order.index + getDragGroupDelta(e));
}
setDragging(false);
setDragStart(null);
setDragTime(null);
setDragGroupDelta(null);
// setDragStart(null);
dragStart.current = null;
// setDragTime(null);
dragTime.current = null;
// setDragGroupDelta(null);
dragGroupDelta.current = null;
};

// resize handlers
Expand All @@ -279,6 +291,7 @@ export const Item = <TGroup extends TimelineGroupBase, TItem extends TimelineIte
setResizeEdge(undefined);
setResizeStart(e.pageX);
setResizeTime(0);
return;
};

const handleResizeMove = (e: ResizeEvent) => {
Expand Down Expand Up @@ -409,7 +422,7 @@ export const Item = <TGroup extends TimelineGroupBase, TItem extends TimelineIte

const getItemProps = (props: Partial<Omit<TimelineItemProps, "key" | "ref">> = {}) => {
const classNames = "rct-item" + (item.className ? ` ${item.className}` : "");
const result: TimelineItemProps & { title: string | undefined } = {
const result: TimelineItemProps = {
className: classNames + ` ${props.className ? props.className : ""}`,
key: item.id,
onContextMenu: composeEvents(handleContextMenu, props.onContextMenu),
Expand All @@ -420,7 +433,7 @@ export const Item = <TGroup extends TimelineGroupBase, TItem extends TimelineIte
onTouchStart: composeEvents(onTouchStart, props.onTouchStart),
ref: _item,
style: Object.assign({}, getItemStyle(props)),
title: item.title,
// title: item.title,
};
return result;
};
Expand Down Expand Up @@ -456,7 +469,7 @@ export const Item = <TGroup extends TimelineGroupBase, TItem extends TimelineIte
width: `${dimensions.width}px`,
height: `${dimensions.height}px`,
lineHeight: `${dimensions.height}px`,
overflow: "hidden"
overflow: "hidden",
};

return Object.assign(
Expand Down Expand Up @@ -533,7 +546,7 @@ export const Item = <TGroup extends TimelineGroupBase, TItem extends TimelineIte
dragging: dragging.current,
dragGroupDelta: dragGroupDelta.current,
dragStart: dragStart.current,
dragTime: dragTime,
dragTime: dragTime.current,
resizeEdge: resizeEdge.current,
resizeStart: resizeStart.current,
resizeTime: resizeTime,
Expand Down
11 changes: 5 additions & 6 deletions src/items/styles.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { CSSProperties } from "react";

export const overridableStyles: CSSProperties = {
fontSize: 12,
fontSize: 14,
color: "white",
cursor: "pointer",
background: "#2196f3",
borderColor: "#1a6fb3",
background: "var(--mui-palette-primary-600)",
borderColor: "var(--mui-palette-primary-900)",
borderStyle: "solid",
borderTopWidth: "1px",
borderBottomWidth: "1px",
Expand All @@ -15,9 +15,8 @@ export const overridableStyles: CSSProperties = {
};

export const selectedStyle: CSSProperties = {
background: "#ffc107",
borderColor: "#ff9800",
// border: "1px solid #ff9800",
background: "var(--mui-palette-secondary-main)",
borderColor: "var(--mui-palette-secondary-dark)",
zIndex: 82,
};

Expand Down
2 changes: 1 addition & 1 deletion src/markers/implementations/cursor-marker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type CursorMarkerProps = { renderer?: MarkerRenderer };
* when the user mouseleaves the element
*/
export const CursorMarker: React.FC<CursorMarkerProps> = ({
renderer = createDefaultRenderer("default-cursor-marker"),
renderer = createDefaultRenderer("default-cursor-marker", "rct-cursor-marker"),
}) => {
const { subscribeToMouseOver } = React.useContext(MarkerCanvasContext);
const _unsubscribe = React.useRef<null | (() => void)>(null);
Expand Down
2 changes: 1 addition & 1 deletion src/markers/implementations/custom-marker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type CustomMarkerProps = {
export const CustomMarker: React.FC<CustomMarkerProps> = ({
date,
getLeftOffsetFromDate,
renderer = createDefaultRenderer("default-customer-marker-id"),
renderer = createDefaultRenderer("default-customer-marker-id", "rct-custom-marker"),
}) => {
const value = typeof date === "number" ? date : date.valueOf();
const leftOffset = getLeftOffsetFromDate(value);
Expand Down
2 changes: 1 addition & 1 deletion src/markers/implementations/now-marker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type NowMarkerProps = {
export const NowMarker: React.FC<NowMarkerProps> = ({
getLeftOffsetFromDate,
interval,
renderer = createDefaultRenderer("default-today-line"),
renderer = createDefaultRenderer("default-today-line", "rct-now-marker"),
}) => {
const _intervalToken = React.useRef<NodeJS.Timer | undefined>();
const [date, setDate] = React.useState(Date.now());
Expand Down
7 changes: 3 additions & 4 deletions src/markers/implementations/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import memoize from "memoize-one";
* Baseline styles to get the marker to render correctly
*/
const criticalStyles: React.CSSProperties = {
backgroundColor: "black",
bottom: 0,
position: "absolute",
top: 0,
width: "2px",
// width: "2px",

// by default, pointer events (specifically click) will
// "pass through". This is added so that CursorMarker
Expand All @@ -24,8 +23,8 @@ export const createMarkerStylesWithLeftOffset = memoize(
})
);

export const createDefaultRenderer = (dataTestidValue: string) => {
export const createDefaultRenderer = (dataTestidValue: string, className?: string) => {
return function DefaultMarkerRenderer({ styles }: { styles: React.CSSProperties }) {
return <div style={styles} data-testid={dataTestidValue} />;
return <div className={className} style={styles} data-testid={dataTestidValue} />;
};
};
4 changes: 1 addition & 3 deletions src/markers/markers-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export const MarkersProvider: React.FC<MarkersProviderProps> = ({ children }) =>
};

const updateMarker = (marker: Marker) => {
const ix = markers.findIndex(({ id }) => marker.id === id);
if (ix < 0) return;
setMarkers((curr) => [...curr.slice(0, ix), marker, ...curr.slice(ix + 1)]);
setMarkers((curr) => curr.map((m) => m.id == marker.id ? marker : m));
};

return (
Expand Down
1 change: 0 additions & 1 deletion src/markers/markers-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import React from "react";
export const MarkersRenderer: React.FC = () => {
const { getLeftOffsetFromDate } = React.useContext(TimelineContext);
const { markers } = React.useContext(MarkersContext);

return (
<React.Fragment>
{markers.map((marker) =>
Expand Down
Loading

0 comments on commit 9ed8980

Please sign in to comment.