@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,16 +1,21 @@
1
1
  import { Store, EventBus } from "@wx/lib-state";
2
2
  import type { TDataConfig, TWritableCreator, TID } from "@wx/lib-state";
3
+ import { HistoryManager } from "./modules/HistoryManager.pro";
3
4
  import type { IData, IDataConfig, ITask, TMethodsConfig, ILink, IVisibleArea, IParsedTask, TScrollTask } from "./types";
4
5
  export default class DataStore extends Store<IData> {
5
6
  in: EventBus<TMethodsConfig, keyof TMethodsConfig>;
6
7
  private _router;
8
+ private _modules;
7
9
  constructor(w: TWritableCreator);
8
10
  init(state: Partial<IDataConfig>): void;
11
+ private enableModule;
12
+ private disableModule;
9
13
  setState(state: Partial<IData>, ctx?: TDataConfig): {
10
14
  [key: string]: () => void;
11
15
  };
12
16
  setStateAsync(state: Partial<IData>): void;
13
17
  getTask(id: TID): IParsedTask;
18
+ getHistory(): HistoryManager;
14
19
  serialize(): Partial<ITask>[];
15
20
  private changeScale;
16
21
  private isScheduled;
@@ -30,13 +35,17 @@ export type IDataMethodsConfig = CombineTypes<{
30
35
  target?: TID;
31
36
  mode?: "before" | "after" | "child";
32
37
  show?: TScrollTask["mode"];
38
+ select?: boolean;
39
+ eventSource?: string;
33
40
  };
34
41
  ["update-task"]: {
35
42
  id: TID;
43
+ segmentIndex?: number;
36
44
  task: Partial<ITask>;
37
45
  diff?: number;
38
46
  inProgress?: boolean;
39
47
  eventSource?: string;
48
+ skipUndo?: boolean;
40
49
  };
41
50
  ["delete-task"]: {
42
51
  id: TID;
@@ -54,6 +63,7 @@ export type IDataMethodsConfig = CombineTypes<{
54
63
  };
55
64
  ["drag-task"]: {
56
65
  id: TID;
66
+ segmentIndex?: number;
57
67
  width?: number;
58
68
  left?: number;
59
69
  top?: number;
@@ -66,11 +76,12 @@ export type IDataMethodsConfig = CombineTypes<{
66
76
  source?: TID;
67
77
  lazy?: boolean;
68
78
  eventSource?: string;
79
+ skipUndo?: boolean;
69
80
  };
70
81
  ["move-task"]: {
71
82
  id: TID;
72
83
  target?: TID;
73
- mode?: "before" | "after" | "up" | "down" | "child";
84
+ mode: "before" | "after" | "up" | "down" | "child";
74
85
  inProgress?: boolean;
75
86
  source?: TID;
76
87
  };
@@ -84,6 +95,8 @@ export type IDataMethodsConfig = CombineTypes<{
84
95
  ["add-link"]: {
85
96
  id?: TID;
86
97
  link: Partial<ILink>;
98
+ eventSource?: string;
99
+ skipUndo: boolean;
87
100
  };
88
101
  ["update-link"]: {
89
102
  id: TID;
@@ -127,7 +140,19 @@ export type IDataMethodsConfig = CombineTypes<{
127
140
  event: any;
128
141
  eventSource?: string;
129
142
  };
143
+ ["schedule-tasks"]: {
144
+ id?: TID;
145
+ task?: Partial<ITask>;
146
+ };
147
+ ["undo"]: void;
148
+ ["redo"]: void;
149
+ ["split-task"]: {
150
+ id: TID;
151
+ segmentIndex?: number;
152
+ };
130
153
  }, {
131
154
  skipProvider?: boolean;
155
+ spipUndo?: boolean;
156
+ [key: string]: any;
132
157
  }>;
133
158
  export {};
@@ -9,8 +9,9 @@ export default class GanttDataTree extends DataTree<IParsedTask> {
9
9
  getIndexById(id: TID): number;
10
10
  add(task: Partial<ITask>, index: number): IParsedTask;
11
11
  copy(taskObj: ITask, parent: TID, ind: number): TID[][];
12
- normalizeTask(task: Partial<ITask>, tasks?: Partial<ITask>[]): ITask;
12
+ normalizeTask(task: Partial<ITask>): ITask;
13
13
  getSummaryId(id: TID): TID | null;
14
+ getSummaryId(id: TID, all: true): TID[] | null;
14
15
  sort(conf: TSort[]): void;
15
16
  sortBranch(conf: TSort[], parent?: TID): void;
16
17
  serialize(): Partial<ITask>[];
@@ -1,3 +1,3 @@
1
- import type { GanttColumn } from "./types";
2
- export declare function normalizeColumns(columns: GanttColumn[]): GanttColumn[];
3
- export declare const defaultColumns: GanttColumn[];
1
+ import type { IGanttColumn } from "./types";
2
+ export declare function normalizeColumns(columns: IGanttColumn[]): IGanttColumn[];
3
+ export declare const defaultColumns: IGanttColumn[];
@@ -1,5 +1,8 @@
1
1
  import type { TID } from "@wx/lib-state";
2
+ import type { IDataHash } from "../types";
2
3
  import { IOptionConfig } from "./menuOptions";
3
4
  import { IButtonConfig } from "./toolbarButtons";
4
- export declare function handleAction(api: any, action: string, target: TID | null, _: any): void;
5
+ type TTarget = TID | IDataHash | null;
6
+ export declare function handleAction(api: any, action: string, target: TTarget, _: any): void;
5
7
  export declare function isHandledAction(options: IOptionConfig[] | IButtonConfig[], id: TID): boolean;
8
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { TEditorItem, IDataConfig } from "../types";
2
+ export declare function getEditorItems(config: IDataConfig): TEditorItem[];
3
+ export declare const defaultEditorItems: TEditorItem[];
@@ -0,0 +1,3 @@
1
+ import { TID } from "@wx/lib-state";
2
+ import { ILink } from "src/types";
3
+ export declare function getCircularLinks(links: ILink[]): Set<TID>;
@@ -1,5 +1,6 @@
1
1
  import type { TID } from "@wx/lib-state";
2
- import type { ITask, IGanttTask } from "../types";
2
+ import type { IParsedTask, IHistory, IData, IDataConfig, IDataHash } from "../types";
3
+ export declare function getMenuOptions(config: IDataConfig): IOptionConfig[];
3
4
  export interface IOptionConfig {
4
5
  id?: TID;
5
6
  separator?: boolean;
@@ -7,9 +8,10 @@ export interface IOptionConfig {
7
8
  icon?: string;
8
9
  data?: IOptionConfig[];
9
10
  type?: string;
10
- check?: (task: ITask, _tasks?: IGanttTask[]) => boolean | TID;
11
+ isDisabled?: ((task: IParsedTask, state: IData, target?: TID | IDataHash) => boolean) | ((history: IHistory) => boolean);
11
12
  dataFactory?: (obj: any) => IOptionConfig;
12
13
  subtext?: string;
14
+ isHidden?: (task: IParsedTask, state: IData, target?: TID | IDataHash) => boolean;
13
15
  }
14
16
  export declare function assignChecks<T extends IOptionConfig>(items: T[]): T[];
15
17
  export declare const defaultMenuOptions: IOptionConfig[];
@@ -1,3 +1,6 @@
1
+ import type { IData, IDataHash, IParsedTask, IHistory, IDataConfig } from "../types";
2
+ import type { TID } from "@wx/lib-state";
3
+ export declare function getToolbarButtons(config: IDataConfig): IButtonConfig[];
1
4
  export interface IButtonConfig {
2
5
  id?: string;
3
6
  comp: string;
@@ -5,6 +8,7 @@ export interface IButtonConfig {
5
8
  icon?: string;
6
9
  type?: string;
7
10
  menuText?: string;
8
- check?: (params: any) => boolean;
11
+ isDisabled?: ((task: IParsedTask, state: IData, target?: TID | IDataHash) => boolean) | ((history: IHistory) => boolean);
12
+ isHidden?: (task: IParsedTask, state: IData, target?: TID | IDataHash) => boolean;
9
13
  }
10
14
  export declare const defaultToolbarButtons: IButtonConfig[];
@@ -1,12 +1,16 @@
1
1
  export { default as DataStore } from "./DataStore";
2
2
  export { grid } from "./dom/scales";
3
- export { placeLink } from "./links";
3
+ export { placeLink, normalizeLinks } from "./links";
4
4
  export { getDiffer, getAdder, getUnitStart, format, registerScaleUnit, } from "./time";
5
5
  export { handleAction, isHandledAction } from "./helpers/actionHandlers";
6
- export { defaultToolbarButtons } from "./helpers/toolbarButtons";
7
- export { defaultMenuOptions } from "./helpers/menuOptions";
8
- export { defaultEditorItems } from "./editorItems";
6
+ export { defaultToolbarButtons, getToolbarButtons, } from "./helpers/toolbarButtons";
7
+ export { defaultMenuOptions, getMenuOptions } from "./helpers/menuOptions";
8
+ export { defaultEditorItems, getEditorItems } from "./helpers/editorItems";
9
9
  export { defaultColumns } from "./columns";
10
10
  export { defaultTaskTypes } from "./taskTypes";
11
- export { normalizeDates } from "./normalizeDates";
12
- export type { TID, ITask, ILink, IZoomConfig, GanttColumn, TMethodsConfig, } from "./types";
11
+ export { prepareEditTask, parseTaskDates } from "./normalizeDates";
12
+ export { normalizeZoom } from "./scales";
13
+ export { isSegmentMoveAllowed, extendDragOptions } from "./tasks";
14
+ import { Calendar as _Calendar } from "@wx/lib-schedule";
15
+ export declare const Calendar: typeof _Calendar;
16
+ export type { TID, IApi, ITask, ILink, IConfig, IZoomConfig, IGanttColumn, TMethodsConfig, IGanttTask, IMarker, IScheduleConfig, ICriticalPathConfig, IScaleConfig, } from "./types";
@@ -1,4 +1,4 @@
1
- import type { IGanttTask, IGanttLink } from "./types";
1
+ import type { IGanttTask, IGanttLink, ILink } from "./types";
2
2
  export declare const updateLink: (link: IGanttLink, startTask: IGanttTask, endTask: IGanttTask, height: number, baselines: boolean) => IGanttLink;
3
3
  export declare function placeLink(box: {
4
4
  left: number;
@@ -16,3 +16,10 @@ export declare function placeLink(box: {
16
16
  top: number;
17
17
  p: string;
18
18
  };
19
+ export declare function normalizeLinks(links: ILink[]): {
20
+ id: import("@wx/lib-state").TID;
21
+ type: import("./types").TLinkType;
22
+ source: import("@wx/lib-state").TID;
23
+ target: import("@wx/lib-state").TID;
24
+ lag?: number;
25
+ }[];
@@ -0,0 +1,15 @@
1
+ import { EventTracker } from "./EventTracker.pro";
2
+ import type { TID } from "../types";
3
+ export declare class AutoSchedulerModule extends EventTracker {
4
+ private taskTracker;
5
+ private linkTracker;
6
+ init(): void;
7
+ destroy(): void;
8
+ schedule(id?: TID, deleteInvalidLinks?: boolean): void;
9
+ protected getDefaultTag(): string;
10
+ private setupScheduleHandler;
11
+ private setupTaskHandlers;
12
+ private setupLinkHandlers;
13
+ private deleteInvalidLinks;
14
+ private getInvalidLinks;
15
+ }
@@ -0,0 +1,10 @@
1
+ import type { TID } from "../types";
2
+ export declare class ChangeTracker<T extends {
3
+ id?: TID;
4
+ }> {
5
+ private prevState;
6
+ track(id: TID, item: Partial<T>, properties: (keyof T)[]): void;
7
+ hasChanged(id: TID, item: Partial<T>, properties: (keyof T)[]): boolean;
8
+ clear(id?: TID): void;
9
+ getSnapshot(id: TID): Partial<T> | undefined;
10
+ }
@@ -0,0 +1,11 @@
1
+ import { EventTracker } from "./EventTracker.pro";
2
+ export declare class CriticalPathModule extends EventTracker {
3
+ private taskTracker;
4
+ private linkTracker;
5
+ init(): void;
6
+ destroy(): void;
7
+ calculate(): void;
8
+ protected getDefaultTag(): string;
9
+ private setupTaskHandlers;
10
+ private setupLinkHandlers;
11
+ }
@@ -0,0 +1,20 @@
1
+ import { EventBus } from "@wx/lib-state";
2
+ import type { TMethodsConfig, IData } from "../types";
3
+ export declare abstract class EventTracker {
4
+ protected in: EventBus<TMethodsConfig, keyof TMethodsConfig>;
5
+ protected getState: () => Partial<IData>;
6
+ protected setState: (state: Partial<IData>) => void;
7
+ protected getHistory: () => any;
8
+ private _timer;
9
+ private _tags;
10
+ constructor(eventBus: EventBus<TMethodsConfig, keyof TMethodsConfig>, stateGetter: () => Partial<IData>, stateSetter: (state: Partial<IData>) => void, historyGetter: () => any);
11
+ abstract init(): void;
12
+ abstract destroy(): void;
13
+ protected debounce(code: () => void, delay?: number): void;
14
+ protected shouldTrack(ev: any, noTrack?: Record<string, number>): boolean;
15
+ protected registerHandler<K extends keyof TMethodsConfig>(type: "on" | "intercept", event: K, handler: (ev: TMethodsConfig[K]) => void, tag?: string): void;
16
+ protected on<K extends keyof TMethodsConfig>(event: K, handler: (ev: TMethodsConfig[K]) => void, tag?: string): void;
17
+ protected intercept<K extends keyof TMethodsConfig>(event: K, handler: (ev: TMethodsConfig[K]) => void, tag?: string): void;
18
+ protected detachHandlers(): void;
19
+ protected abstract getDefaultTag(): string;
20
+ }
@@ -0,0 +1,48 @@
1
+ import { IDataHash, TMethodsConfig } from "../types";
2
+ import { EventTracker } from "./EventTracker.pro";
3
+ type TActionType = keyof TMethodsConfig;
4
+ type TBatchAction = "batch";
5
+ type TAllActionTypes = TActionType | TBatchAction;
6
+ type TSubActionData = IDataHash & {
7
+ action?: TActionType;
8
+ };
9
+ interface IActionData<T extends TAllActionTypes> {
10
+ action: T;
11
+ data: T extends TActionType ? TMethodsConfig[T] | TSubActionData : IHistoryEntry[];
12
+ }
13
+ interface IHistoryEntry extends IActionData<TAllActionTypes> {
14
+ source: IActionData<TAllActionTypes>;
15
+ }
16
+ interface IActionHandlers {
17
+ handler: (ev: any) => IHistoryEntry;
18
+ getSnapshot?: (ev: any) => IDataHash;
19
+ progress?: boolean;
20
+ }
21
+ export declare class HistoryManager extends EventTracker {
22
+ private undo;
23
+ private redo;
24
+ private progress;
25
+ private _dataSnapshot;
26
+ private _batch;
27
+ private _isBatching;
28
+ init(): void;
29
+ destroy(): void;
30
+ protected getDefaultTag(): string;
31
+ getHandlers(): {
32
+ [key: string]: IActionHandlers;
33
+ };
34
+ resetHistory(): void;
35
+ private setHandlers;
36
+ private setPrevData;
37
+ private getPrevData;
38
+ private addToHistory;
39
+ startBatch(): void;
40
+ endBatch(): void;
41
+ handleUndo(): void;
42
+ handleRedo(): void;
43
+ private executeHistoryEntry;
44
+ private resetStateHistory;
45
+ private setStateHistory;
46
+ private getOrder;
47
+ }
48
+ export {};
@@ -1,4 +1,6 @@
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;
1
+ import type { ITask, IData } from "./types";
2
+ export declare function parseTaskDates(tasks: ITask[], state: Partial<IData>): void;
3
+ export declare function normalizeDates(task: Partial<ITask>, state: Partial<IData>): void;
4
+ export declare function calcDates(task: Partial<ITask>, state: Partial<IData>, isBaseline?: boolean): void;
4
5
  export declare function getFields(isBaseline: boolean): string[];
6
+ export declare function prepareEditTask(task: Partial<ITask>, state: Partial<IData>, key: string): void;
@@ -1,20 +1,21 @@
1
- import type { GanttScale, GanttScaleData, IZoomConfig } from "./types";
1
+ import type { IScaleConfig, GanttScaleData, IUnitFormats, IZoomConfig, TLengthUnit } from "./types";
2
2
  import type GanttDataTree from "./GanttDataTree";
3
- export declare function getMinUnit(scales: GanttScale[]): GanttScale;
3
+ import { Day } from "date-fns";
4
+ export declare function getMinUnit(scales: IScaleConfig[]): IScaleConfig;
4
5
  export declare const units: string[];
5
6
  export declare function calcScales(prevStart: Date, prevEnd: Date, autoScale: boolean, minUnit?: string, tasks?: GanttDataTree): {
6
7
  _start: Date;
7
8
  _end: Date;
8
9
  };
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[];
10
+ export declare function resetScales(start: Date, end: Date, lengthUnit: TLengthUnit, width: number, height: number, _weekStart: Day, scales: IScaleConfig[]): GanttScaleData | null;
11
+ export declare function normalizeZoom(zoom: boolean | IZoomConfig, unitFormats: IUnitFormats, scales: IScaleConfig[], cellWidth: number): {
12
+ zoom: IZoomConfig;
13
+ scales: IScaleConfig[];
13
14
  cellWidth: number;
14
15
  };
15
- export declare function zoomScale(zoom: IZoomConfig, step: number, level: number, nextUnit: any, lengthUnit: string, scales: GanttScale[], cellWidth: number): {
16
- scales: GanttScale[];
16
+ export declare function zoomScale(zoom: IZoomConfig, step: number, level: number, nextUnit: any, lengthUnit: TLengthUnit, scales: IScaleConfig[], cellWidth: number): {
17
+ scales: IScaleConfig[];
17
18
  cellWidth: number;
18
- lengthUnit: string;
19
+ lengthUnit: TLengthUnit;
19
20
  zoom: IZoomConfig;
20
21
  };
@@ -0,0 +1,11 @@
1
+ import { ITask, IData, IParsedTask, IDataHash, Calendar } from "./types";
2
+ type TSegment = Partial<ITask>;
3
+ export declare function calcSplitDates(task: Partial<ITask>, stateOptions: Partial<IData>): void;
4
+ export declare function dragSplitTask(task: IParsedTask, ev: IDataHash): boolean;
5
+ export declare function updateSplitTask(task: IParsedTask, update: Partial<ITask | TSegment>, stateOptions: Partial<IData>, index?: number, diff?: number): Partial<ITask | Partial<ITask>>;
6
+ export declare function splitTask(task: IParsedTask, index: number | undefined, stateOptions: Partial<IData>): Partial<IParsedTask>;
7
+ export declare function isIndivisibleType(task: Partial<ITask>): boolean;
8
+ export declare function isIndivisible(task: IParsedTask, stateOptions: Partial<IData>, index?: number): boolean;
9
+ export declare function getEndAdder(unit: string, calendar: Calendar): (start: number | Date, step: number) => Date;
10
+ export declare function shiftNextSegments(segments: Partial<ITask>[], lengthUnit: string, index: number, calendar: Calendar, dir?: number): void;
11
+ export {};
@@ -1,5 +1,7 @@
1
- import type { IGanttTask, GanttScaleData, IParsedTask, GanttDataTree, ITask } from "./types";
2
- export declare function dragSummaryKids(task: IParsedTask, dx: number): void;
1
+ import { IGanttTask, GanttScaleData, IParsedTask, GanttDataTree, ITask, IData, IDataHash } from "./types";
2
+ export declare function dragSummaryKids(task: IParsedTask, dx: number, _scales: GanttScaleData, cellWidth: number): void;
3
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;
4
+ export declare function setSummaryDates(task: ITask, tasks?: Partial<ITask>[]): ITask;
5
+ export declare function updateTask(t: IGanttTask, i: number, state: Partial<IData>): IGanttTask;
6
+ export declare function isSegmentMoveAllowed(task: IGanttTask, moveOptions: IDataHash): boolean;
7
+ export declare function extendDragOptions(task: ITask, options: IDataHash): void;
@@ -1,16 +1,17 @@
1
- import { format } from "date-fns";
1
+ import { format, Day } from "date-fns";
2
+ import type { GanttScaleUnit, Calendar } from "./types";
2
3
  export declare function getSmallerUnitCount(unit: string, lengthUnit: string, date?: Date): number;
3
4
  export declare function isCorrectLengthUnit(minUnit: string, lengthUnit: string): boolean;
4
- export declare function getDiffer(unit: string): {
5
+ export declare function getDiffer(unit: string, calendar?: Calendar, _weekStart?: Day): {
5
6
  (start: Date, end: Date, lengthUnit?: string, unitSize?: boolean): number;
6
7
  };
7
- export declare function getAdder(unit: string): {
8
+ export declare function getAdder(unit: string, calendar?: Calendar): {
8
9
  (start: number | Date, step: number): Date;
9
10
  };
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;
11
+ export declare function getUnitStart(unit: string, date: Date, _weekStart?: Day): Date;
12
+ export declare function getUnitEnd(unit: string, date: Date, _weekStart?: Day): Date;
13
+ export declare function isSameUnit(unit: string, a: Date, b: Date, _weekStart?: Day): boolean;
14
+ export declare function registerScaleUnit(unit: string, config: GanttScaleUnit): void;
15
+ export declare function adjustToWorkingDay(start: Date, diff: number, calendar: Calendar): Date;
16
+ export declare function shiftByWorkingDays(calendar: Calendar): (date: Date, diff: number) => Date;
16
17
  export { format };