@svar-ui/gantt-store 2.2.1 → 2.4.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.
@@ -1,6 +1,9 @@
1
1
  import type { IDataMethodsConfig } from "./DataStore";
2
- import type { DataArray, TID } from "@wx/lib-state";
2
+ import type { DataArray, TID, IEventBus, IPublicWritable, IEventConfig } from "@wx/lib-state";
3
3
  import type GanttDataTree from "./GanttDataTree";
4
+ import { Day } from "date-fns";
5
+ import type DataStore from "./DataStore";
6
+ import type { IApi as ITableApi, IColumn } from "@wx/grid-store";
4
7
  export type TMethodsConfig = IDataMethodsConfig;
5
8
  export type { GanttDataTree, TID };
6
9
  export interface IActionConfig<T = any> {
@@ -8,27 +11,25 @@ export interface IActionConfig<T = any> {
8
11
  noSave?: boolean;
9
12
  }
10
13
  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;
14
+ export type TTaskType = "task" | "summary" | "milestone" | string;
15
+ export type TLengthUnit = "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year" | string;
16
+ export type TDurationUnit = "day" | "hour";
23
17
  export interface ILink {
24
- id: TID;
18
+ id?: TID;
25
19
  type: TLinkType;
26
20
  source: TID;
27
21
  target: TID;
22
+ lag?: number;
23
+ }
24
+ export interface IGanttLink extends ILink {
25
+ id: TID;
26
+ $p: string;
27
+ $pl: number;
28
+ $critical?: boolean;
28
29
  }
29
30
  export interface ITask {
30
31
  start?: Date;
31
- id: TID;
32
+ id?: TID;
32
33
  end?: Date;
33
34
  duration?: number;
34
35
  data?: ITask[];
@@ -42,13 +43,25 @@ export interface ITask {
42
43
  type?: TTaskType;
43
44
  parent?: TID;
44
45
  unscheduled?: boolean;
46
+ segments?: Partial<ITask>[];
45
47
  [key: string]: any;
46
48
  }
47
49
  export interface IParsedTask extends ITask {
48
- parent: TID;
49
- data: IParsedTask[];
50
+ id: TID;
51
+ parent?: TID;
52
+ data?: IParsedTask[];
50
53
  $level: number;
51
54
  }
55
+ export interface IGanttTask extends IParsedTask {
56
+ $x: number;
57
+ $y: number;
58
+ $h: number;
59
+ $w: number;
60
+ $x_base?: number;
61
+ $w_base?: number;
62
+ $reorder?: boolean;
63
+ $critical?: boolean;
64
+ }
52
65
  export type TDispatch = <A extends keyof TMethodsConfig>(action: A, data: TMethodsConfig[A]) => void;
53
66
  export interface IMethodsHash {
54
67
  [key: string]: any;
@@ -64,7 +77,7 @@ export interface IVisibleArea {
64
77
  end: number;
65
78
  }
66
79
  export interface IZoomConfig {
67
- level: number;
80
+ level?: number;
68
81
  minCellWidth?: number;
69
82
  maxCellWidth?: number;
70
83
  levels?: Array<IScaleLevel>;
@@ -72,7 +85,7 @@ export interface IZoomConfig {
72
85
  export interface IScaleLevel {
73
86
  minCellWidth: number;
74
87
  maxCellWidth: number;
75
- scales: GanttScale[];
88
+ scales: IScaleConfig[];
76
89
  }
77
90
  export interface IMarker {
78
91
  start: Date;
@@ -80,77 +93,112 @@ export interface IMarker {
80
93
  css?: string;
81
94
  left?: number;
82
95
  }
83
- export interface IDataConfig {
96
+ export interface IHistory {
97
+ undo: number;
98
+ redo: number;
99
+ }
100
+ export interface ICriticalPathConfig {
101
+ type: "strict" | "flexible";
102
+ }
103
+ export interface ICriticalTasks {
104
+ [key: TID]: boolean;
105
+ }
106
+ type UnitFormatter = (date: Date) => string;
107
+ export interface IUnitFormats {
108
+ [unit: string]: UnitFormatter | string;
109
+ }
110
+ export interface IScheduleConfig {
111
+ type?: "forward";
112
+ auto?: boolean;
113
+ }
114
+ export interface ICalendarConfig {
115
+ name?: string;
116
+ weekHours?: {
117
+ sunday?: number;
118
+ monday?: number;
119
+ tuesday?: number;
120
+ wednesday?: number;
121
+ thursday?: number;
122
+ friday?: number;
123
+ saturday?: number;
124
+ };
125
+ }
126
+ export interface Calendar {
127
+ isWorkingDay(date: Date): boolean;
128
+ addRule(rule: (date: Date) => number): void;
129
+ clone(config?: ICalendarConfig): Calendar;
130
+ addWorkingDays(start: Date, days: number, excludeEndDate?: boolean): Date | null;
131
+ addWorkingHours(start: Date, hours: number): Date | null;
132
+ getNextWorkingDay(date: Date): Date | null;
133
+ getPreviousWorkingDay(date: Date): Date | null;
134
+ getWorkingDays(start: Date, end: Date, excludeEndDate?: boolean): number;
135
+ getWorkingHours(start: Date, end?: Date, excludeEndDate?: boolean): number;
136
+ setDayHours(date: Date, hours: number): void;
137
+ setRangeHours(start: Date, end: Date, hours: number): void;
138
+ }
139
+ export interface IConfig {
140
+ tasks?: ITask[];
141
+ links?: any[];
142
+ taskTypes?: ITaskType[];
84
143
  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[];
144
+ activeTask?: TID | {
145
+ id: TID;
146
+ segmentIndex: number;
147
+ };
148
+ scales?: IScaleConfig[];
149
+ columns?: IGanttColumn[];
150
+ start?: Date;
151
+ end?: Date;
152
+ lengthUnit?: TLengthUnit;
153
+ durationUnit?: TDurationUnit;
154
+ cellWidth?: number;
155
+ cellHeight?: number;
156
+ scaleHeight?: number;
157
+ zoom?: boolean | IZoomConfig;
158
+ autoScale?: boolean;
159
+ schedule?: IScheduleConfig;
160
+ undo?: boolean;
161
+ unscheduledTasks?: boolean;
162
+ baselines?: boolean;
163
+ markers?: IMarker[];
164
+ criticalPath?: ICriticalPathConfig;
165
+ projectStart?: Date;
166
+ projectEnd?: Date;
167
+ calendar?: Calendar;
168
+ splitTasks?: boolean;
169
+ }
170
+ export interface IDataConfig extends IConfig {
96
171
  scrollLeft: number;
97
172
  scrollTop: number;
98
173
  area: IVisibleArea;
99
- taskTypes?: ITaskType[];
100
- baselines?: boolean;
101
- zoom: boolean | IZoomConfig;
102
- highlightTime?: (date: Date, unit: "day" | "hour") => string;
174
+ history?: IHistory;
103
175
  _cellWidth?: number;
104
176
  _sort?: TSort[];
105
- autoScale?: boolean;
106
- unscheduledTasks?: boolean;
107
- markers?: IMarker[];
108
- durationUnit: "day" | "hour";
109
177
  _scrollTask?: TScrollTask;
178
+ _weekStart?: Day;
110
179
  }
111
- export interface IData {
112
- selected: TID[];
113
- _selected: ITask[];
114
- activeTask: TID;
115
- _activeTask: ITask;
180
+ export interface IData extends Omit<IDataConfig, "tasks" | "links"> {
181
+ zoom?: IZoomConfig;
116
182
  tasks: GanttDataTree;
117
- _tasks: IParsedTask[];
118
183
  links: DataArray<ILink>;
184
+ _tasks: IParsedTask[];
119
185
  _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[];
186
+ _selected?: ITask[];
187
+ _activeTask?: ITask;
188
+ _start?: Date;
189
+ _end?: Date;
190
+ _scales?: GanttScaleData;
140
191
  _scaleDate?: Date;
141
192
  _zoomOffset?: number;
142
- autoScale?: boolean;
143
- markers?: IMarker[];
144
- _markers?: IMarker[];
145
- unscheduledTasks?: boolean;
146
- durationUnit: "day" | "hour";
193
+ _weekStart?: Day;
147
194
  _scrollTask?: TScrollTask;
195
+ _markers?: IMarker[];
148
196
  }
149
- export interface DataHash {
150
- [key: string]: any;
197
+ export interface IDataHash<T = any> {
198
+ [key: string]: T;
151
199
  }
152
- export type GanttScale = {
153
- unit: string;
200
+ export type IScaleConfig = {
201
+ unit: TLengthUnit;
154
202
  step: number;
155
203
  format?: {
156
204
  (date: Date, next?: Date): string;
@@ -175,49 +223,40 @@ export type GanttScaleData = {
175
223
  height: number;
176
224
  start: Date;
177
225
  end: Date;
178
- lengthUnit: string;
226
+ lengthUnit: TLengthUnit;
179
227
  minUnit: string;
180
228
  lengthUnitWidth: number;
181
229
  diff: {
182
- (a: Date, b: Date, lengthUnit?: string, unitSize?: boolean): number;
230
+ (a: Date, b: Date, lengthUnit?: TLengthUnit, unitSize?: boolean): number;
183
231
  };
184
232
  };
185
- export type GanttColumn = {
233
+ export type GanttScaleUnit = {
234
+ start: (date: Date) => Date;
235
+ end: (date: Date) => Date;
236
+ isSame: (date1: Date, date2: Date) => boolean;
237
+ add: (date: Date, num: number) => Date;
238
+ diff?: (date1: Date, date2: Date) => number;
239
+ smallerCount?: {
240
+ [key: TLengthUnit]: number | ((date: Date) => number);
241
+ };
242
+ biggerCount?: {
243
+ [key: TLengthUnit]: number | ((date: Date) => number);
244
+ };
245
+ };
246
+ export type IGanttColumn = {
186
247
  width?: number;
187
248
  align?: "left" | "right" | "center";
188
249
  flexgrow?: number;
189
250
  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
- };
251
+ header?: IColumn["header"];
252
+ id?: string;
253
+ template?: IColumn["template"];
254
+ _template?: IColumn["template"];
200
255
  sort?: boolean;
201
256
  cell?: any;
202
- editor?: TEditorType | IColumnEditor | TEditorHandler;
203
- options?: DataHash[];
257
+ editor?: IColumn["editor"];
258
+ options?: IColumn["options"];
204
259
  };
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
260
  export type TCommonShape = {
222
261
  id?: TID;
223
262
  key: string;
@@ -225,6 +264,8 @@ export type TCommonShape = {
225
264
  labelTemplate?: (value: any) => string;
226
265
  config?: Record<string, any>;
227
266
  [key: string]: any;
267
+ isHidden?: (task: Partial<ITask>) => boolean;
268
+ isDisabled?: (task: Partial<ITask>, state: IData) => boolean;
228
269
  };
229
270
  export type TTextFieldShape = TCommonShape & {
230
271
  comp: "text" | "textarea";
@@ -259,7 +300,7 @@ export type ILinksShape = TCommonShape & {
259
300
  export type ITwoStateShape = TCommonShape & {
260
301
  comp: "twostate";
261
302
  };
262
- export type TEditorShape = TTextFieldShape | TCounterShape | TComboFieldShape | TSliderShape | TDateFieldShape | TRadioShape | ILinksShape | ITwoStateShape;
303
+ export type TEditorItem = TTextFieldShape | TCounterShape | TComboFieldShape | TSliderShape | TDateFieldShape | TRadioShape | ILinksShape | ITwoStateShape;
263
304
  export type ITaskType = {
264
305
  id: TID;
265
306
  label: string;
@@ -273,3 +314,20 @@ export type TScrollTask = {
273
314
  id: TID;
274
315
  mode?: "x" | "y" | "xy" | boolean;
275
316
  };
317
+ export interface IApi {
318
+ exec: <A extends keyof TMethodsConfig | (string & {})>(action: A, params?: A extends keyof TMethodsConfig ? TMethodsConfig[A] : any) => Promise<any>;
319
+ on: <A extends keyof TMethodsConfig | (string & {})>(action: A, callback: (config: A extends keyof TMethodsConfig ? TMethodsConfig[A] : any) => any, config?: IEventConfig) => void;
320
+ intercept: <A extends keyof TMethodsConfig | (string & {})>(action: A, callback: (config: A extends keyof TMethodsConfig ? TMethodsConfig[A] : any) => any, config?: IEventConfig) => void;
321
+ detach: (tag: IEventConfig["tag"]) => void;
322
+ getState: () => IData;
323
+ getReactiveState: () => {
324
+ [Key in keyof IData]: IPublicWritable<IData[Key]>;
325
+ };
326
+ setNext: (ev: IEventBus<TMethodsConfig>) => void;
327
+ getStores: () => {
328
+ data: DataStore;
329
+ };
330
+ getTable: (waitRender?: boolean) => Promise<ITableApi> | ITableApi;
331
+ getTask: (id: TID) => ITask;
332
+ serialize: () => ITask[];
333
+ }
package/license.txt CHANGED
@@ -1,21 +1,9 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 XB Software Sp. z o.o.
3
+ Copyright (c) 2025 XB Software Sp. z o.o
4
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:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
6
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
8
 
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.
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json CHANGED
@@ -1,24 +1,26 @@
1
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
- }
2
+ "name": "@svar-ui/gantt-store",
3
+ "version": "2.4.0",
4
+ "description": "Internal state management used by SVAR Gantt component",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/types/index.d.ts",
9
+ "license": "MIT",
10
+ "scripts": {
11
+ "build": "vite build",
12
+ "watch": "vite build --mode development -w",
13
+ "lint": "yarn eslint ./src",
14
+ "test": "vitest --run",
15
+ "coverage": "vitest --run --coverage"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "licenses",
20
+ "license.txt"
21
+ ],
22
+ "dependencies": {
23
+ "date-fns": "3.6.0",
24
+ "@svar-ui/lib-state": "1.9.6"
25
+ }
24
26
  }
package/readme.md ADDED
@@ -0,0 +1,5 @@
1
+ # SVAR Gantt Store
2
+
3
+ This package is part of the **SVAR Gantt (Open-Source Edition)** functionality and is distributed under the MIT license.
4
+
5
+ The **gantt-store** package handles the internal state management used by the Gantt component.
@@ -1,2 +0,0 @@
1
- import type { TEditorShape } from "./types";
2
- export declare const defaultEditorItems: TEditorShape[];