react-timelane 0.0.0

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.
Files changed (72) hide show
  1. package/.github/workflows/static.yml +55 -0
  2. package/README.md +54 -0
  3. package/docs/README.md +54 -0
  4. package/docs/eslint.config.js +28 -0
  5. package/docs/index.html +12 -0
  6. package/docs/package-lock.json +5101 -0
  7. package/docs/package.json +35 -0
  8. package/docs/src/App.css +5 -0
  9. package/docs/src/App.tsx +59 -0
  10. package/docs/src/assets/react.svg +1 -0
  11. package/docs/src/components/AllocationComponent.tsx +82 -0
  12. package/docs/src/components/Timeline.tsx +183 -0
  13. package/docs/src/constants.ts +42 -0
  14. package/docs/src/hooks/useLocalStorage.ts +21 -0
  15. package/docs/src/main.tsx +9 -0
  16. package/docs/src/models/Allocation.ts +11 -0
  17. package/docs/src/models/AllocationId.ts +1 -0
  18. package/docs/src/models/Resource.ts +8 -0
  19. package/docs/src/models/ResourceId.ts +1 -0
  20. package/docs/src/vite-env.d.ts +1 -0
  21. package/docs/tsconfig.json +27 -0
  22. package/docs/vite.config.ts +8 -0
  23. package/eslint.config.js +28 -0
  24. package/index.html +13 -0
  25. package/package.json +43 -0
  26. package/src/components/Timeline.scss +297 -0
  27. package/src/components/TimelineAside.tsx +81 -0
  28. package/src/components/TimelineBackground.tsx +53 -0
  29. package/src/components/TimelineBody.tsx +54 -0
  30. package/src/components/TimelineHeader/DaysHeader.tsx +44 -0
  31. package/src/components/TimelineHeader/MonthsHeader.tsx +62 -0
  32. package/src/components/TimelineHeader/TimelineHeader.tsx +64 -0
  33. package/src/components/TimelineHeader/WeeksHeader.tsx +63 -0
  34. package/src/components/TimelineHeader/index.ts +9 -0
  35. package/src/components/TimelineHeader/renderingUtils.tsx +57 -0
  36. package/src/components/TimelineSelectionLayer.tsx +179 -0
  37. package/src/components/TimelineSettingsContext.tsx +27 -0
  38. package/src/components/TimelineSettingsProvider.tsx +24 -0
  39. package/src/components/TimelineWrapper.tsx +51 -0
  40. package/src/components/core/CoreItem/CoreItemComponent.tsx +69 -0
  41. package/src/components/core/CoreItem/DragResizeComponent.tsx +180 -0
  42. package/src/components/core/CoreSwimlane/AvailableSpaceIndicator.tsx +156 -0
  43. package/src/components/core/CoreSwimlane/CoreSwimlane.tsx +245 -0
  44. package/src/components/core/CoreSwimlane/DropPreview.tsx +30 -0
  45. package/src/components/core/CoreSwimlane/DropTarget.tsx +83 -0
  46. package/src/components/core/CoreSwimlane/OverlapIndicator.tsx +22 -0
  47. package/src/components/core/CoreSwimlane/utils.ts +375 -0
  48. package/src/components/core/utils.ts +154 -0
  49. package/src/components/layout/TimelineLayout.tsx +93 -0
  50. package/src/components/layout/layout.scss +107 -0
  51. package/src/global.d.ts +9 -0
  52. package/src/hooks/useScroll.tsx +71 -0
  53. package/src/hooks/useTimelineContext.tsx +6 -0
  54. package/src/index.ts +15 -0
  55. package/src/types/AvailableSpace.ts +6 -0
  56. package/src/types/CoreItem.ts +23 -0
  57. package/src/types/DateBounds.ts +4 -0
  58. package/src/types/Dimensions.ts +4 -0
  59. package/src/types/GrabInfo.ts +6 -0
  60. package/src/types/Grid.ts +6 -0
  61. package/src/types/ItemId.ts +1 -0
  62. package/src/types/OffsetBounds.ts +4 -0
  63. package/src/types/Pixels.ts +4 -0
  64. package/src/types/Position.ts +4 -0
  65. package/src/types/Rectangle.ts +6 -0
  66. package/src/types/SwimlaneId.ts +1 -0
  67. package/src/types/SwimlaneT.ts +6 -0
  68. package/src/types/TimeRange.ts +4 -0
  69. package/src/types/TimelineSettings.ts +11 -0
  70. package/src/types/index.ts +15 -0
  71. package/tsconfig.json +32 -0
  72. package/vite.config.ts +32 -0
@@ -0,0 +1,9 @@
1
+ declare module "*.scss" {
2
+ const content: Record<string, string>;
3
+ export default content;
4
+ }
5
+
6
+ declare module "*.css" {
7
+ const content: Record<string, string>;
8
+ export default content;
9
+ }
@@ -0,0 +1,71 @@
1
+ import { ItemId, SwimlaneId } from "../types";
2
+ import { useTimelineContext } from "./useTimelineContext";
3
+ import { dateToPixel } from "../components/core/utils";
4
+
5
+ export const useScroll = () => {
6
+ const { settings } = useTimelineContext();
7
+
8
+ function scrollTo(destination: { horz?: Date; vert?: SwimlaneId } | ItemId) {
9
+ if (destination instanceof Object) {
10
+ if (destination.horz !== undefined) {
11
+ scrollToDate(destination.horz);
12
+ }
13
+
14
+ if (destination.vert !== undefined) {
15
+ scrollToLane(destination.vert);
16
+ }
17
+ } else {
18
+ scrollToItem(destination);
19
+ }
20
+ }
21
+
22
+ function scrollToDate(date: Date) {
23
+ window.requestAnimationFrame(() => {
24
+ const el: HTMLElement | null = document.getElementById(
25
+ "timeline-background-date-anchor"
26
+ );
27
+
28
+ if (el) {
29
+ const offsetLeft: number = dateToPixel(date, settings.start, settings);
30
+
31
+ el.style.setProperty("left", `${offsetLeft}px`);
32
+
33
+ el.scrollIntoView({
34
+ block: "nearest",
35
+ inline: "center",
36
+ behavior: "smooth",
37
+ });
38
+ }
39
+ });
40
+ }
41
+
42
+ function scrollToLane(laneId: SwimlaneId) {
43
+ window.requestAnimationFrame(() => {
44
+ const el: HTMLElement | null = document.getElementById(
45
+ `timeline-swimlane-${laneId}`
46
+ );
47
+
48
+ if (el) {
49
+ el.scrollIntoView({ block: "center", behavior: "smooth" });
50
+ }
51
+ });
52
+ }
53
+
54
+ function scrollToItem(itemId: ItemId) {
55
+ window.requestAnimationFrame(() => {
56
+ const el: HTMLElement | null = document.getElementById(
57
+ `timeline-item-${itemId}`
58
+ );
59
+
60
+ if (el) {
61
+ el.scrollIntoView({
62
+ block: "center",
63
+ inline: "center",
64
+ behavior: "smooth",
65
+ });
66
+ }
67
+ });
68
+ }
69
+
70
+ return { scrollTo, scrollToDate, scrollToItem, scrollToLane };
71
+ };
@@ -0,0 +1,6 @@
1
+ import { useContext } from "react";
2
+ import { TimelineSettingsContext } from "../components/TimelineSettingsContext";
3
+
4
+ export const useTimelineContext = () => {
5
+ return useContext(TimelineSettingsContext);
6
+ };
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ export { default as TimelineLayout } from "./components/layout/TimelineLayout";
2
+ export { default as TimelineAside } from "./components/TimelineAside";
3
+ export { default as TimelineBackground } from "./components/TimelineBackground";
4
+ export * from "./components/TimelineHeader";
5
+ export { default as TimelineWrapper } from "./components/TimelineWrapper";
6
+ export { default as CoreSwimlane } from "./components/core/CoreSwimlane/CoreSwimlane";
7
+ export { TimelineBody } from "./components/TimelineBody";
8
+ export { TimelineSelectionLayer } from "./components/TimelineSelectionLayer";
9
+
10
+ export * from "./types";
11
+ export * from "./components/core/utils";
12
+ export * from "./components/core/CoreSwimlane/utils";
13
+
14
+ export { useScroll } from "./hooks/useScroll";
15
+ export { useTimelineContext } from "./hooks/useTimelineContext";
@@ -0,0 +1,6 @@
1
+ export interface AvailableSpace {
2
+ start: Date;
3
+ end: Date;
4
+ minOffset: number;
5
+ maxOffset: number;
6
+ }
@@ -0,0 +1,23 @@
1
+ import { ItemId } from "./ItemId";
2
+ import { SwimlaneId } from "./SwimlaneId";
3
+
4
+ export type CoreItem<T = void> = {
5
+ id: ItemId;
6
+ swimlaneId: SwimlaneId;
7
+ start: Date;
8
+ end: Date;
9
+ size: number;
10
+ offset: number;
11
+ payload: T;
12
+ };
13
+
14
+ export function isCoreItem(a: object): a is CoreItem {
15
+ return (
16
+ "id" in a &&
17
+ "swimlaneId" in a &&
18
+ "start" in a &&
19
+ "end" in a &&
20
+ "size" in a &&
21
+ "offset" in a
22
+ );
23
+ }
@@ -0,0 +1,4 @@
1
+ export interface DateBounds {
2
+ lower: Date;
3
+ upper: Date;
4
+ }
@@ -0,0 +1,4 @@
1
+ export interface Dimensions {
2
+ width: number;
3
+ height: number;
4
+ }
@@ -0,0 +1,6 @@
1
+ import { Position } from "./Position";
2
+
3
+ export interface GrabInfo {
4
+ absolute: Position;
5
+ relative: Position;
6
+ }
@@ -0,0 +1,6 @@
1
+ export interface Grid {
2
+ x?: number;
3
+ y?: number;
4
+ offsetX?: number;
5
+ offsetY?: number;
6
+ }
@@ -0,0 +1 @@
1
+ export type ItemId = number;
@@ -0,0 +1,4 @@
1
+ export interface OffsetBounds {
2
+ lower: number;
3
+ upper: number;
4
+ }
@@ -0,0 +1,4 @@
1
+ export interface Pixels {
2
+ pixelsPerDay: number;
3
+ pixelsPerResource: number;
4
+ }
@@ -0,0 +1,4 @@
1
+ export interface Position {
2
+ x: number;
3
+ y: number;
4
+ }
@@ -0,0 +1,6 @@
1
+ export interface Rectangle {
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ height: number;
6
+ }
@@ -0,0 +1 @@
1
+ export type SwimlaneId = number;
@@ -0,0 +1,6 @@
1
+ import { SwimlaneId } from "./SwimlaneId";
2
+
3
+ export interface SwimlaneT {
4
+ id: SwimlaneId;
5
+ capacity: number;
6
+ }
@@ -0,0 +1,4 @@
1
+ export interface TimeRange {
2
+ start: Date;
3
+ end: Date;
4
+ }
@@ -0,0 +1,11 @@
1
+ export interface TimelineSettings {
2
+ start: Date;
3
+ end: Date;
4
+ pixelsPerDay: number;
5
+ pixelsPerResource: number;
6
+ showMonths: boolean;
7
+ showWeeks: boolean;
8
+ showDays: boolean;
9
+ allowOverlaps: boolean;
10
+ focusedDate: Date | null;
11
+ }
@@ -0,0 +1,15 @@
1
+ export { type TimeRange } from "./TimeRange";
2
+ export { type Pixels } from "./Pixels";
3
+ export { type Rectangle } from "./Rectangle";
4
+ export { type Position } from "./Position";
5
+ export { type Grid } from "./Grid";
6
+ export { type ItemId } from "./ItemId";
7
+ export { type AvailableSpace } from "./AvailableSpace";
8
+ export { type CoreItem, isCoreItem } from "./CoreItem";
9
+ export { type Dimensions } from "./Dimensions";
10
+ export { type GrabInfo } from "./GrabInfo";
11
+ export { type SwimlaneId } from "./SwimlaneId";
12
+ export { type SwimlaneT } from "./SwimlaneT";
13
+ export { type DateBounds } from "./DateBounds";
14
+ export { type OffsetBounds } from "./OffsetBounds";
15
+ export { type TimelineSettings } from "./TimelineSettings";
package/tsconfig.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "compilerOptions": {
3
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
4
+ "target": "ES2020",
5
+ "useDefineForClassFields": true,
6
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
+ "module": "ESNext",
8
+ "skipLibCheck": true,
9
+
10
+ /* Bundler mode */
11
+ "moduleResolution": "bundler",
12
+ "allowImportingTsExtensions": true,
13
+ "verbatimModuleSyntax": false,
14
+ "moduleDetection": "force",
15
+ "noEmit": true,
16
+ "jsx": "react-jsx",
17
+ "allowSyntheticDefaultImports": true,
18
+ "allowArbitraryExtensions": true,
19
+ "allowJs": true,
20
+ "isolatedModules": true,
21
+
22
+ /* Linting */
23
+ "strict": true,
24
+ "noUnusedLocals": true,
25
+ "noUnusedParameters": false,
26
+ "erasableSyntaxOnly": true,
27
+ "noFallthroughCasesInSwitch": true,
28
+ "noUncheckedSideEffectImports": true
29
+ },
30
+ "include": ["src"],
31
+ "exclude": ["docs"]
32
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { defineConfig } from "vite";
2
+ import { resolve } from "path";
3
+ import react from "@vitejs/plugin-react";
4
+ import dts from "vite-plugin-dts";
5
+ // import vitePluginSass from "vite-plugin-sass";
6
+
7
+ // https://vite.dev/config/
8
+ export default defineConfig({
9
+ plugins: [
10
+ react(),
11
+ // vitePluginSass(),
12
+ dts({ include: ["src"] }),
13
+ ],
14
+ build: {
15
+ lib: {
16
+ entry: resolve(__dirname, "src/index.ts"),
17
+ formats: ["es"],
18
+ },
19
+ rollupOptions: {
20
+ external: ["react", "react/jsx-runtime"],
21
+ },
22
+ },
23
+ // css: {
24
+ // preprocessorOptions: {
25
+ // scss: {
26
+ // additionalData: `
27
+ // @import "TimelineV3/layout/layout.scss";
28
+ // `,
29
+ // },
30
+ // },
31
+ // },
32
+ });