@svar-ui/gantt-store 2.2.1

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.
@@ -0,0 +1,133 @@
1
+ import { Store, EventBus } from "@wx/lib-state";
2
+ import type { TDataConfig, TWritableCreator, TID } from "@wx/lib-state";
3
+ import type { IData, IDataConfig, ITask, TMethodsConfig, ILink, IVisibleArea, IParsedTask, TScrollTask } from "./types";
4
+ export default class DataStore extends Store<IData> {
5
+ in: EventBus<TMethodsConfig, keyof TMethodsConfig>;
6
+ private _router;
7
+ constructor(w: TWritableCreator);
8
+ init(state: Partial<IDataConfig>): void;
9
+ setState(state: Partial<IData>, ctx?: TDataConfig): {
10
+ [key: string]: () => void;
11
+ };
12
+ setStateAsync(state: Partial<IData>): void;
13
+ getTask(id: TID): IParsedTask;
14
+ serialize(): Partial<ITask>[];
15
+ private changeScale;
16
+ private isScheduled;
17
+ private resetSummaryDates;
18
+ private moveSummaryKids;
19
+ private calcScaleDate;
20
+ getNextRow(id: TID): IParsedTask;
21
+ getPrevRow(id: TID): IParsedTask;
22
+ }
23
+ type CombineTypes<T, N> = {
24
+ [P in keyof T]: T[P] & N;
25
+ };
26
+ export type IDataMethodsConfig = CombineTypes<{
27
+ ["add-task"]: {
28
+ id?: TID;
29
+ task: Partial<ITask>;
30
+ target?: TID;
31
+ mode?: "before" | "after" | "child";
32
+ show?: TScrollTask["mode"];
33
+ };
34
+ ["update-task"]: {
35
+ id: TID;
36
+ task: Partial<ITask>;
37
+ diff?: number;
38
+ inProgress?: boolean;
39
+ eventSource?: string;
40
+ };
41
+ ["delete-task"]: {
42
+ id: TID;
43
+ source?: TID;
44
+ };
45
+ ["open-task"]: {
46
+ id: TID;
47
+ mode: boolean;
48
+ };
49
+ ["select-task"]: {
50
+ id: TID;
51
+ toggle?: boolean;
52
+ range?: boolean;
53
+ show?: TScrollTask["mode"];
54
+ };
55
+ ["drag-task"]: {
56
+ id: TID;
57
+ width?: number;
58
+ left?: number;
59
+ top?: number;
60
+ inProgress?: boolean;
61
+ };
62
+ ["copy-task"]: {
63
+ id: TID;
64
+ target?: TID;
65
+ mode?: "before" | "after" | "child";
66
+ source?: TID;
67
+ lazy?: boolean;
68
+ eventSource?: string;
69
+ };
70
+ ["move-task"]: {
71
+ id: TID;
72
+ target?: TID;
73
+ mode?: "before" | "after" | "up" | "down" | "child";
74
+ inProgress?: boolean;
75
+ source?: TID;
76
+ };
77
+ ["indent-task"]: {
78
+ id: TID;
79
+ mode: boolean;
80
+ };
81
+ ["show-editor"]: {
82
+ id: TID;
83
+ };
84
+ ["add-link"]: {
85
+ id?: TID;
86
+ link: Partial<ILink>;
87
+ };
88
+ ["update-link"]: {
89
+ id: TID;
90
+ link: Partial<ILink>;
91
+ };
92
+ ["delete-link"]: {
93
+ id: TID;
94
+ };
95
+ ["scroll-chart"]: {
96
+ left?: number;
97
+ top?: number;
98
+ };
99
+ ["render-data"]: IVisibleArea;
100
+ ["request-data"]: {
101
+ id: TID;
102
+ };
103
+ ["provide-data"]: {
104
+ id: TID;
105
+ data: {
106
+ tasks?: Array<ITask>;
107
+ links?: Array<ILink>;
108
+ };
109
+ };
110
+ ["zoom-scale"]: {
111
+ dir: number;
112
+ date: Date;
113
+ offset?: number;
114
+ };
115
+ ["expand-scale"]: {
116
+ minWidth: number;
117
+ date?: Date;
118
+ offset?: number;
119
+ };
120
+ ["sort-tasks"]: {
121
+ key: string;
122
+ order: "asc" | "desc";
123
+ add?: boolean;
124
+ };
125
+ ["hotkey"]: {
126
+ key: string;
127
+ event: any;
128
+ eventSource?: string;
129
+ };
130
+ }, {
131
+ skipProvider?: boolean;
132
+ }>;
133
+ export {};
@@ -0,0 +1,17 @@
1
+ import { DataTree, TID } from "@wx/lib-state";
2
+ import type { ITask, IParsedTask, TSort } from "./types";
3
+ export default class GanttDataTree extends DataTree<IParsedTask> {
4
+ private _sort;
5
+ constructor(tasks?: Partial<ITask>[]);
6
+ parse(tasks: Partial<ITask>[], parent: TID): void;
7
+ getBranch(id: TID): IParsedTask[];
8
+ contains(id: TID, target: TID): boolean;
9
+ getIndexById(id: TID): number;
10
+ add(task: Partial<ITask>, index: number): IParsedTask;
11
+ copy(taskObj: ITask, parent: TID, ind: number): TID[][];
12
+ normalizeTask(task: Partial<ITask>, tasks?: Partial<ITask>[]): ITask;
13
+ getSummaryId(id: TID): TID | null;
14
+ sort(conf: TSort[]): void;
15
+ sortBranch(conf: TSort[], parent?: TID): void;
16
+ serialize(): Partial<ITask>[];
17
+ }
@@ -0,0 +1,3 @@
1
+ import type { GanttColumn } from "./types";
2
+ export declare function normalizeColumns(columns: GanttColumn[]): GanttColumn[];
3
+ export declare const defaultColumns: GanttColumn[];
@@ -0,0 +1 @@
1
+ export declare function grid(width: number, height: number, color: string, mode?: "full"): string;
@@ -0,0 +1,2 @@
1
+ import type { TEditorShape } from "./types";
2
+ export declare const defaultEditorItems: TEditorShape[];
@@ -0,0 +1,5 @@
1
+ import type { TID } from "@wx/lib-state";
2
+ import { IOptionConfig } from "./menuOptions";
3
+ import { IButtonConfig } from "./toolbarButtons";
4
+ export declare function handleAction(api: any, action: string, target: TID | null, _: any): void;
5
+ export declare function isHandledAction(options: IOptionConfig[] | IButtonConfig[], id: TID): boolean;
@@ -0,0 +1,15 @@
1
+ import type { TID } from "@wx/lib-state";
2
+ import type { ITask, IGanttTask } from "../types";
3
+ export interface IOptionConfig {
4
+ id?: TID;
5
+ separator?: boolean;
6
+ text?: string;
7
+ icon?: string;
8
+ data?: IOptionConfig[];
9
+ type?: string;
10
+ check?: (task: ITask, _tasks?: IGanttTask[]) => boolean | TID;
11
+ dataFactory?: (obj: any) => IOptionConfig;
12
+ subtext?: string;
13
+ }
14
+ export declare function assignChecks<T extends IOptionConfig>(items: T[]): T[];
15
+ export declare const defaultMenuOptions: IOptionConfig[];
@@ -0,0 +1,2 @@
1
+ import type { IParsedTask, TSort } from "../types";
2
+ export declare function sort(data: IParsedTask[], conf: TSort[]): IParsedTask[];
@@ -0,0 +1,10 @@
1
+ export interface IButtonConfig {
2
+ id?: string;
3
+ comp: string;
4
+ text?: string;
5
+ icon?: string;
6
+ type?: string;
7
+ menuText?: string;
8
+ check?: (params: any) => boolean;
9
+ }
10
+ export declare const defaultToolbarButtons: IButtonConfig[];
@@ -0,0 +1,12 @@
1
+ export { default as DataStore } from "./DataStore";
2
+ export { grid } from "./dom/scales";
3
+ export { placeLink } from "./links";
4
+ export { getDiffer, getAdder, getUnitStart, format, registerScaleUnit, } from "./time";
5
+ export { handleAction, isHandledAction } from "./helpers/actionHandlers";
6
+ export { defaultToolbarButtons } from "./helpers/toolbarButtons";
7
+ export { defaultMenuOptions } from "./helpers/menuOptions";
8
+ export { defaultEditorItems } from "./editorItems";
9
+ export { defaultColumns } from "./columns";
10
+ export { defaultTaskTypes } from "./taskTypes";
11
+ export { normalizeDates } from "./normalizeDates";
12
+ export type { TID, ITask, ILink, IZoomConfig, GanttColumn, TMethodsConfig, } from "./types";
@@ -0,0 +1,18 @@
1
+ import type { IGanttTask, IGanttLink } from "./types";
2
+ export declare const updateLink: (link: IGanttLink, startTask: IGanttTask, endTask: IGanttTask, height: number, baselines: boolean) => IGanttLink;
3
+ export declare function placeLink(box: {
4
+ left: number;
5
+ top: number;
6
+ }, start: {
7
+ x: number;
8
+ y: number;
9
+ }, end: {
10
+ x: number;
11
+ y: number;
12
+ }): {
13
+ width: number;
14
+ height: number;
15
+ left: number;
16
+ top: number;
17
+ p: string;
18
+ };
@@ -0,0 +1,4 @@
1
+ import type { ITask } from "./types";
2
+ export declare function prepareTask(currentTask: Partial<ITask>, task: Partial<ITask>, unit: "day" | "hour"): void;
3
+ export declare function normalizeDates(task: Partial<ITask>, unit: "day" | "hour", edit?: boolean, key?: string): void;
4
+ export declare function getFields(isBaseline: boolean): string[];
@@ -0,0 +1,7 @@
1
+ export declare function isValid(): boolean;
2
+ export declare function isExpired(): boolean;
3
+ export declare function isBadLuck(): boolean;
4
+ export declare function getStamp(): {
5
+ gen: number;
6
+ };
7
+ export declare function isCommunity(): boolean;
@@ -0,0 +1,20 @@
1
+ import type { GanttScale, GanttScaleData, IZoomConfig } from "./types";
2
+ import type GanttDataTree from "./GanttDataTree";
3
+ export declare function getMinUnit(scales: GanttScale[]): GanttScale;
4
+ export declare const units: string[];
5
+ export declare function calcScales(prevStart: Date, prevEnd: Date, autoScale: boolean, minUnit?: string, tasks?: GanttDataTree): {
6
+ _start: Date;
7
+ _end: Date;
8
+ };
9
+ export declare function resetScales(start: Date, end: Date, lengthUnit: string, width: number, height: number, scales: GanttScale[]): GanttScaleData | null;
10
+ export declare function normalizeZoom(zoom: boolean | IZoomConfig, scales: GanttScale[], cellWidth: number): {
11
+ _zoom: IZoomConfig;
12
+ scales: GanttScale[];
13
+ cellWidth: number;
14
+ };
15
+ export declare function zoomScale(zoom: IZoomConfig, step: number, level: number, nextUnit: any, lengthUnit: string, scales: GanttScale[], cellWidth: number): {
16
+ scales: GanttScale[];
17
+ cellWidth: number;
18
+ lengthUnit: string;
19
+ zoom: IZoomConfig;
20
+ };
@@ -0,0 +1,2 @@
1
+ import { ITaskType } from "./types";
2
+ export declare const defaultTaskTypes: ITaskType[];
@@ -0,0 +1,5 @@
1
+ import type { IGanttTask, GanttScaleData, IParsedTask, GanttDataTree, ITask } from "./types";
2
+ export declare function dragSummaryKids(task: IParsedTask, dx: number): void;
3
+ export declare function dragSummary(tasks: GanttDataTree, task: IParsedTask, _scales: GanttScaleData, cellWidth: number): void;
4
+ export declare function setSummaryDates(task: IParsedTask, tasks?: Partial<ITask>[]): IParsedTask;
5
+ export declare function updateTask(t: IGanttTask, i: number, cellWidth: number, cellHeight: number, scales: GanttScaleData, baselines: boolean): IGanttTask;
@@ -0,0 +1,16 @@
1
+ import { format } from "date-fns";
2
+ export declare function getSmallerUnitCount(unit: string, lengthUnit: string, date?: Date): number;
3
+ export declare function isCorrectLengthUnit(minUnit: string, lengthUnit: string): boolean;
4
+ export declare function getDiffer(unit: string): {
5
+ (start: Date, end: Date, lengthUnit?: string, unitSize?: boolean): number;
6
+ };
7
+ export declare function getAdder(unit: string): {
8
+ (start: number | Date, step: number): Date;
9
+ };
10
+ export declare function getUnitStart(unit: string, date: Date): Date;
11
+ export declare function getUnitEnd(unit: string, date: Date): Date;
12
+ export declare function isSameUnit(unit: string, a: Date, b: Date): boolean;
13
+ export declare function registerScaleUnit(unit: string, config: {
14
+ [name: string]: any;
15
+ }): void;
16
+ export { format };
@@ -0,0 +1,275 @@
1
+ import type { IDataMethodsConfig } from "./DataStore";
2
+ import type { DataArray, TID } from "@wx/lib-state";
3
+ import type GanttDataTree from "./GanttDataTree";
4
+ export type TMethodsConfig = IDataMethodsConfig;
5
+ export type { GanttDataTree, TID };
6
+ export interface IActionConfig<T = any> {
7
+ data?: T;
8
+ noSave?: boolean;
9
+ }
10
+ export type TLinkType = "s2s" | "s2e" | "e2s" | "e2e";
11
+ export type TTaskType = "task" | "summary" | "milestone";
12
+ export type TEditorType = "text" | "combo" | "datepicker" | "richselect";
13
+ export interface IColumnEditor {
14
+ type: TEditorType;
15
+ config?: {
16
+ template?: (v: any) => string;
17
+ cell?: any;
18
+ options?: any[];
19
+ buttons?: boolean | string[];
20
+ };
21
+ }
22
+ export type TEditorHandler = (row?: ITask, column?: any) => TEditorType | IColumnEditor | null;
23
+ export interface ILink {
24
+ id: TID;
25
+ type: TLinkType;
26
+ source: TID;
27
+ target: TID;
28
+ }
29
+ export interface ITask {
30
+ start?: Date;
31
+ id: TID;
32
+ end?: Date;
33
+ duration?: number;
34
+ data?: ITask[];
35
+ base_start?: Date;
36
+ base_end?: Date;
37
+ base_duration?: number;
38
+ open?: boolean;
39
+ text?: string;
40
+ details?: string;
41
+ progress?: number;
42
+ type?: TTaskType;
43
+ parent?: TID;
44
+ unscheduled?: boolean;
45
+ [key: string]: any;
46
+ }
47
+ export interface IParsedTask extends ITask {
48
+ parent: TID;
49
+ data: IParsedTask[];
50
+ $level: number;
51
+ }
52
+ export type TDispatch = <A extends keyof TMethodsConfig>(action: A, data: TMethodsConfig[A]) => void;
53
+ export interface IMethodsHash {
54
+ [key: string]: any;
55
+ }
56
+ export type TSortConfig = {
57
+ key: string;
58
+ order: string;
59
+ index?: number;
60
+ };
61
+ export interface IVisibleArea {
62
+ from: number;
63
+ start: number;
64
+ end: number;
65
+ }
66
+ export interface IZoomConfig {
67
+ level: number;
68
+ minCellWidth?: number;
69
+ maxCellWidth?: number;
70
+ levels?: Array<IScaleLevel>;
71
+ }
72
+ export interface IScaleLevel {
73
+ minCellWidth: number;
74
+ maxCellWidth: number;
75
+ scales: GanttScale[];
76
+ }
77
+ export interface IMarker {
78
+ start: Date;
79
+ text?: string;
80
+ css?: string;
81
+ left?: number;
82
+ }
83
+ export interface IDataConfig {
84
+ selected?: TID[];
85
+ activeTask?: TID;
86
+ tasks: ITask[];
87
+ links: ILink[];
88
+ start: Date;
89
+ end: Date;
90
+ lengthUnit: string;
91
+ cellWidth: number;
92
+ cellHeight: number;
93
+ scaleHeight: number;
94
+ scales: any[];
95
+ columns: GanttColumn[];
96
+ scrollLeft: number;
97
+ scrollTop: number;
98
+ area: IVisibleArea;
99
+ taskTypes?: ITaskType[];
100
+ baselines?: boolean;
101
+ zoom: boolean | IZoomConfig;
102
+ highlightTime?: (date: Date, unit: "day" | "hour") => string;
103
+ _cellWidth?: number;
104
+ _sort?: TSort[];
105
+ autoScale?: boolean;
106
+ unscheduledTasks?: boolean;
107
+ markers?: IMarker[];
108
+ durationUnit: "day" | "hour";
109
+ _scrollTask?: TScrollTask;
110
+ }
111
+ export interface IData {
112
+ selected: TID[];
113
+ _selected: ITask[];
114
+ activeTask: TID;
115
+ _activeTask: ITask;
116
+ tasks: GanttDataTree;
117
+ _tasks: IParsedTask[];
118
+ links: DataArray<ILink>;
119
+ _links: IGanttLink[];
120
+ start: Date;
121
+ _start: Date;
122
+ end: Date;
123
+ _end: Date;
124
+ lengthUnit: string;
125
+ cellWidth: number;
126
+ cellHeight: number;
127
+ scaleHeight: number;
128
+ scales: GanttScale[];
129
+ _scales: GanttScaleData;
130
+ columns: GanttColumn[];
131
+ scrollTop: number;
132
+ scrollLeft: number;
133
+ area: IVisibleArea;
134
+ taskTypes?: ITaskType[];
135
+ baselines?: boolean;
136
+ zoom: IZoomConfig;
137
+ highlightTime?: (date: Date, unit: "day" | "hour") => string;
138
+ _cellWidth?: number;
139
+ _sort?: TSort[];
140
+ _scaleDate?: Date;
141
+ _zoomOffset?: number;
142
+ autoScale?: boolean;
143
+ markers?: IMarker[];
144
+ _markers?: IMarker[];
145
+ unscheduledTasks?: boolean;
146
+ durationUnit: "day" | "hour";
147
+ _scrollTask?: TScrollTask;
148
+ }
149
+ export interface DataHash {
150
+ [key: string]: any;
151
+ }
152
+ export type GanttScale = {
153
+ unit: string;
154
+ step: number;
155
+ format?: {
156
+ (date: Date, next?: Date): string;
157
+ } | string;
158
+ css?: {
159
+ (date: Date): string;
160
+ };
161
+ };
162
+ export type GanttScaleCell = {
163
+ width: number;
164
+ value: string;
165
+ css: string;
166
+ };
167
+ export type GanttScaleRow = {
168
+ cells: GanttScaleCell[];
169
+ height: number;
170
+ add: any;
171
+ };
172
+ export type GanttScaleData = {
173
+ rows: GanttScaleRow[];
174
+ width: number;
175
+ height: number;
176
+ start: Date;
177
+ end: Date;
178
+ lengthUnit: string;
179
+ minUnit: string;
180
+ lengthUnitWidth: number;
181
+ diff: {
182
+ (a: Date, b: Date, lengthUnit?: string, unitSize?: boolean): number;
183
+ };
184
+ };
185
+ export type GanttColumn = {
186
+ width?: number;
187
+ align?: "left" | "right" | "center";
188
+ flexgrow?: number;
189
+ resize?: boolean;
190
+ header: string | {
191
+ cell?: string;
192
+ css?: string;
193
+ text: string;
194
+ };
195
+ id: string;
196
+ action?: string;
197
+ template?: {
198
+ (b: any, row: any): string;
199
+ };
200
+ sort?: boolean;
201
+ cell?: any;
202
+ editor?: TEditorType | IColumnEditor | TEditorHandler;
203
+ options?: DataHash[];
204
+ };
205
+ export interface IGanttTask extends IParsedTask {
206
+ end: Date;
207
+ duration: number;
208
+ unscheduled?: boolean;
209
+ $x: number;
210
+ $y: number;
211
+ $h: number;
212
+ $w: number;
213
+ $x_base?: number;
214
+ $w_base?: number;
215
+ $reorder?: boolean;
216
+ }
217
+ export interface IGanttLink extends ILink {
218
+ id: TID;
219
+ $p: string;
220
+ }
221
+ export type TCommonShape = {
222
+ id?: TID;
223
+ key: string;
224
+ label?: string;
225
+ labelTemplate?: (value: any) => string;
226
+ config?: Record<string, any>;
227
+ [key: string]: any;
228
+ };
229
+ export type TTextFieldShape = TCommonShape & {
230
+ comp: "text" | "textarea";
231
+ };
232
+ export type TCounterShape = TCommonShape & {
233
+ comp: "counter";
234
+ };
235
+ export type TRadioShape = TCommonShape & {
236
+ comp: "radio";
237
+ options: {
238
+ id: TID;
239
+ label: string;
240
+ }[];
241
+ };
242
+ export type TComboFieldShape = TCommonShape & {
243
+ comp: "combo" | "select" | "multiselect";
244
+ options?: {
245
+ id: any;
246
+ label: string;
247
+ }[];
248
+ };
249
+ export type TSliderShape = TCommonShape & {
250
+ comp: "slider";
251
+ };
252
+ export type TDateFieldShape = TCommonShape & {
253
+ comp: "date";
254
+ time?: boolean;
255
+ };
256
+ export type ILinksShape = TCommonShape & {
257
+ comp: "links";
258
+ };
259
+ export type ITwoStateShape = TCommonShape & {
260
+ comp: "twostate";
261
+ };
262
+ export type TEditorShape = TTextFieldShape | TCounterShape | TComboFieldShape | TSliderShape | TDateFieldShape | TRadioShape | ILinksShape | ITwoStateShape;
263
+ export type ITaskType = {
264
+ id: TID;
265
+ label: string;
266
+ };
267
+ export type TSort = {
268
+ key: string;
269
+ order?: "asc" | "desc";
270
+ };
271
+ export type TSortValue = string | number | Date;
272
+ export type TScrollTask = {
273
+ id: TID;
274
+ mode?: "x" | "y" | "xy" | boolean;
275
+ };
package/license.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 XB Software Sp. z o.o.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@svar-ui/gantt-store",
3
+ "version": "2.2.1",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "license": "MIT",
9
+ "scripts": {
10
+ "build": "vite build",
11
+ "watch": "vite build --mode development -w",
12
+ "lint": "yarn eslint ./src",
13
+ "test": "vitest --run",
14
+ "coverage": "vitest --run --coverage"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "license.txt"
19
+ ],
20
+ "dependencies": {
21
+ "@svar-ui/lib-state": "1.9.6",
22
+ "date-fns": "3.6.0"
23
+ }
24
+ }