@svar-ui/calendar-store 2.6.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.
@@ -0,0 +1,416 @@
1
+ import { EventBus, Store, TDataConfig, TWritableCreator } from "@svar-ui/lib-state";
2
+
3
+ //#region src/models/model.d.ts
4
+ interface EventChunk {
5
+ id: EventID;
6
+ event: CalendarEvent;
7
+ start: Date;
8
+ end: Date;
9
+ }
10
+ declare abstract class ViewModel {
11
+ render?: string;
12
+ weekStartDay: number;
13
+ fmt: FormatFactory;
14
+ protected startDate: Date;
15
+ protected endDate: Date;
16
+ private cachedSections;
17
+ private _sectionOverrides?;
18
+ configure(sections: Record<string, any>): void;
19
+ abstract getSections(): Section[];
20
+ abstract rangeStart(date: Date): Date;
21
+ abstract addRange(date: Date, n: number): Date;
22
+ abstract getRangeLabel(): string;
23
+ setRange(date: Date): [Date, Date];
24
+ process(events: CalendarEvent[]): SectionResult[];
25
+ toPositionStart(sectionName: string, x: number, y: number, ev?: Partial<CalendarEvent>, snap?: boolean): Partial<CalendarEvent>;
26
+ toPositionEnd(sectionName: string, x: number, y: number, ev?: Partial<CalendarEvent>, snap?: boolean): Partial<CalendarEvent>;
27
+ private resolvePosition;
28
+ private processSection;
29
+ protected buildCells(_xScale: Scale, _yScale: Scale): GridCell[];
30
+ protected sortBeforeLayout(primitives: Primitive[], mode: string): void;
31
+ private getPrimaryAxis;
32
+ private splitEvent;
33
+ protected findUnitIndex(scale: Scale, event: CalendarEvent): number;
34
+ private findUnitForPosition;
35
+ protected mapToPrimitive(chunk: EventChunk, primaryUnit: {
36
+ position: number;
37
+ size: number;
38
+ }, secondaryScale: Scale, primaryAxis: "x" | "y"): Primitive | null;
39
+ }
40
+ //#endregion
41
+ //#region src/events_store.d.ts
42
+ declare class EventsStore implements IEventStore {
43
+ protected events: CalendarEvent[];
44
+ constructor(initialEvents?: CalendarEvent[]);
45
+ addEvent(event: Partial<CalendarEvent>): CalendarEvent;
46
+ updateEvent(id: EventID, updates: Partial<CalendarEvent>, _mode?: "single" | "following", _originalDate?: string): CalendarEvent | null;
47
+ removeEvent(id: EventID): boolean;
48
+ getEvent(id: EventID): CalendarEvent | undefined;
49
+ getEvents(start?: Date, end?: Date): CalendarEvent[];
50
+ clear(): void;
51
+ getCount(): number;
52
+ }
53
+ //#endregion
54
+ //#region src/types.d.ts
55
+ type Brandmark = {
56
+ text: string;
57
+ link?: string;
58
+ style: string;
59
+ };
60
+ type State = {
61
+ currentDate: Date;
62
+ currentView: string;
63
+ rangeLabel: string;
64
+ visibleDateRange: {
65
+ start: Date;
66
+ end: Date;
67
+ };
68
+ events: EventsStore;
69
+ viewData: any;
70
+ filters: Map<string, (obj: any) => boolean>;
71
+ editorData: CalendarEvent | null;
72
+ _view: ViewModel;
73
+ };
74
+ interface StoreActions {
75
+ ["navigate-to"]: {
76
+ date?: Date;
77
+ view?: string;
78
+ };
79
+ ["navigate-time"]: {
80
+ direction: "next" | "previous" | "now";
81
+ };
82
+ ["add-event"]: {
83
+ event: Partial<CalendarEvent>;
84
+ edit?: boolean;
85
+ id?: EventID;
86
+ };
87
+ ["update-event"]: {
88
+ id: EventID;
89
+ event: Partial<CalendarEvent>;
90
+ mode?: "single" | "following";
91
+ originalDate?: string;
92
+ };
93
+ ["delete-event"]: {
94
+ id: EventID;
95
+ };
96
+ ["select-event"]: {
97
+ id: EventID | null;
98
+ };
99
+ ["move-event"]: {
100
+ id: EventID;
101
+ x: number;
102
+ y: number;
103
+ };
104
+ ["filter-events"]: {
105
+ filter?: ((obj: any) => boolean) | null;
106
+ tag?: string;
107
+ };
108
+ }
109
+ type EventID = string | number;
110
+ interface CalendarEvent {
111
+ id: EventID;
112
+ start: Date;
113
+ end: Date;
114
+ allDay?: boolean;
115
+ [key: string]: any;
116
+ }
117
+ interface ScaleUnit {
118
+ id: string | number;
119
+ label: string;
120
+ position: number;
121
+ size: number;
122
+ weekend?: boolean;
123
+ ui?: Record<string, any>;
124
+ }
125
+ interface Scale {
126
+ units: ScaleUnit[];
127
+ eventToPosition(event: CalendarEvent): {
128
+ start: number;
129
+ end: number;
130
+ };
131
+ contains(date: Date): boolean;
132
+ readonly count: number;
133
+ getHeaders(): ScaleUnit[][];
134
+ positionToValue(position: number): Date | string | number;
135
+ }
136
+ interface DateScaleConfig {
137
+ type: "date";
138
+ length: number;
139
+ step?: number;
140
+ snapStep?: number | false;
141
+ discrete?: boolean;
142
+ visible?: boolean;
143
+ format?: string;
144
+ ui?: Record<string, any>;
145
+ }
146
+ interface TimeScaleConfig {
147
+ type: "time";
148
+ startHour?: number;
149
+ endHour?: number;
150
+ step?: number;
151
+ snapStep?: number | false;
152
+ segments?: {
153
+ start: string;
154
+ end: string;
155
+ size?: number;
156
+ label?: string;
157
+ ui?: Record<string, any>;
158
+ }[];
159
+ visible?: boolean;
160
+ format?: string;
161
+ ui?: Record<string, any>;
162
+ }
163
+ type FormatFactory = (pattern: string) => (date: Date) => string;
164
+ interface UnitScaleConfig {
165
+ type: "unit";
166
+ items: {
167
+ id: string | number;
168
+ label: string;
169
+ }[];
170
+ accessor: string | {
171
+ get: (event: CalendarEvent) => string | number;
172
+ set: (event: Partial<CalendarEvent>, id: string | number) => Partial<CalendarEvent>;
173
+ };
174
+ visible?: boolean;
175
+ ui?: Record<string, any>;
176
+ }
177
+ interface CombinedScaleConfig {
178
+ type: "combined";
179
+ outer: ScaleConfig;
180
+ inner: ScaleConfig;
181
+ visible?: boolean;
182
+ }
183
+ interface StackedScaleConfig {
184
+ type: "stacked";
185
+ levels: ScaleConfig[];
186
+ visible?: boolean;
187
+ }
188
+ type ScaleConfig = DateScaleConfig | TimeScaleConfig | UnitScaleConfig | CombinedScaleConfig | StackedScaleConfig;
189
+ interface Primitive {
190
+ id: EventID;
191
+ event: CalendarEvent;
192
+ x: number;
193
+ y: number;
194
+ width: number;
195
+ height: number;
196
+ isMultiDay?: boolean;
197
+ lane?: number;
198
+ totalLanes?: number;
199
+ slot?: number;
200
+ maxConcurrency?: number;
201
+ }
202
+ interface GridCell {
203
+ date: Date;
204
+ day: number;
205
+ inMonth: boolean;
206
+ today: boolean;
207
+ weekend: boolean;
208
+ x: number;
209
+ y: number;
210
+ width: number;
211
+ height: number;
212
+ }
213
+ type SectionMode = "bars" | "boxes" | "grid" | "list" | "year";
214
+ type BoxLayoutMode = "split" | "overlap";
215
+ interface Section {
216
+ name: string;
217
+ mode: SectionMode;
218
+ xScale: ScaleConfig;
219
+ yScale: ScaleConfig;
220
+ primaryScale?: "x" | "y";
221
+ boxLayout?: BoxLayoutMode;
222
+ filter?: (event: CalendarEvent) => boolean;
223
+ size?: number | "content" | "content-optional";
224
+ ui?: Record<string, any>;
225
+ }
226
+ interface SectionResult {
227
+ name: string;
228
+ mode: SectionMode;
229
+ size: number | "content" | "content-optional";
230
+ primitives: Primitive[];
231
+ xHeaders: ScaleUnit[][] | null;
232
+ yHeaders: ScaleUnit[][] | null;
233
+ xVisible?: boolean;
234
+ yVisible?: boolean;
235
+ cells?: GridCell[];
236
+ ui?: Record<string, any>;
237
+ }
238
+ interface CellContext {
239
+ view: string;
240
+ section: string;
241
+ mode: SectionMode;
242
+ x: ScaleUnit | null;
243
+ y: ScaleUnit | null;
244
+ date: Date | null;
245
+ }
246
+ interface EventContext {
247
+ event: CalendarEvent;
248
+ view: string;
249
+ section: string;
250
+ mode: SectionMode;
251
+ }
252
+ type EventContentMode = "grid" | "bars" | "boxes" | "list" | "year-tooltip";
253
+ type CellCss = (ctx: CellContext) => string;
254
+ type EventCss = (ctx: EventContext) => string;
255
+ interface IEventStore {
256
+ addEvent(event: Partial<CalendarEvent>): CalendarEvent;
257
+ updateEvent(id: EventID, updates: Partial<CalendarEvent>, mode?: "single" | "following", originalDate?: string): CalendarEvent | null;
258
+ removeEvent(id: EventID): boolean;
259
+ getEvent(id: EventID): CalendarEvent | undefined;
260
+ getEvents(start?: Date, end?: Date): CalendarEvent[];
261
+ clear(): void;
262
+ getCount(): number;
263
+ }
264
+ //#endregion
265
+ //#region src/models/helpers/scales.d.ts
266
+ declare class LinearScale implements Scale {
267
+ rangeStart: Date;
268
+ rangeEnd: Date;
269
+ stepMs: number;
270
+ snapStepMs: number | false;
271
+ unitCount: number;
272
+ units: ScaleUnit[];
273
+ discrete: boolean;
274
+ constructor(rangeStart: Date, rangeEnd: Date, unitCount: number, stepMs: number, format: (date: Date) => string, ui?: Record<string, any>, discrete?: boolean, snapStepMs?: number | false);
275
+ private formatId;
276
+ get count(): number;
277
+ eventToPosition(event: CalendarEvent): {
278
+ start: number;
279
+ end: number;
280
+ };
281
+ contains(date: Date): boolean;
282
+ positionToValue(position: number): Date;
283
+ getHeaders(): ScaleUnit[][];
284
+ }
285
+ declare class DiscreteScale implements Scale {
286
+ items: {
287
+ id: string | number;
288
+ label: string;
289
+ }[];
290
+ accessor: {
291
+ get: (event: CalendarEvent) => string | number;
292
+ set: (event: Partial<CalendarEvent>, id: string | number) => Partial<CalendarEvent>;
293
+ };
294
+ boxSize: number;
295
+ units: ScaleUnit[];
296
+ constructor(items: {
297
+ id: string | number;
298
+ label: string;
299
+ }[], accessor: {
300
+ get: (event: CalendarEvent) => string | number;
301
+ set: (event: Partial<CalendarEvent>, id: string | number) => Partial<CalendarEvent>;
302
+ }, ui?: Record<string, any>);
303
+ get count(): number;
304
+ eventToPosition(event: CalendarEvent): {
305
+ start: number;
306
+ end: number;
307
+ };
308
+ contains(): boolean;
309
+ positionToValue(position: number): string | number;
310
+ getHeaders(): ScaleUnit[][];
311
+ }
312
+ declare function createScale(config: ScaleConfig, startDate: Date, fmt?: FormatFactory): Scale;
313
+ //#endregion
314
+ //#region src/models/helpers/layout.d.ts
315
+ interface BarLayoutResult {
316
+ primitives: Primitive[];
317
+ totalLanes: number;
318
+ }
319
+ interface BoxLayoutResult {
320
+ primitives: Primitive[];
321
+ }
322
+ declare function layoutBars(primitives: Primitive[]): BarLayoutResult;
323
+ declare function layoutBoxes(primitives: Primitive[]): BoxLayoutResult;
324
+ //#endregion
325
+ //#region src/models/helpers/filters.d.ts
326
+ declare function isMultiDay(event: CalendarEvent): boolean;
327
+ //#endregion
328
+ //#region src/models/week_view.d.ts
329
+ declare class WeekViewModel extends ViewModel {
330
+ getSections(): Section[];
331
+ getRangeLabel(): string;
332
+ rangeStart(date: Date): Date;
333
+ addRange(date: Date, n: number): Date;
334
+ }
335
+ //#endregion
336
+ //#region src/models/day_view.d.ts
337
+ declare class DayViewModel extends ViewModel {
338
+ getSections(): Section[];
339
+ getRangeLabel(): string;
340
+ rangeStart(date: Date): Date;
341
+ addRange(date: Date, n: number): Date;
342
+ }
343
+ //#endregion
344
+ //#region src/models/month_view.d.ts
345
+ declare class MonthViewModel extends ViewModel {
346
+ snapToCell: boolean;
347
+ getSections(): Section[];
348
+ getRangeLabel(): string;
349
+ setRange(date: Date): [Date, Date];
350
+ rangeStart(date: Date): Date;
351
+ addRange(date: Date, n: number): Date;
352
+ protected sortBeforeLayout(primitives: Primitive[], _mode: string): void;
353
+ protected mapToPrimitive(chunk: EventChunk, primaryUnit: {
354
+ position: number;
355
+ size: number;
356
+ }, secondaryScale: Scale, primaryAxis: "x" | "y"): Primitive | null;
357
+ protected buildCells(xScale: Scale, yScale: Scale): GridCell[];
358
+ private getTargetMonth;
359
+ private getWeekCount;
360
+ }
361
+ //#endregion
362
+ //#region src/registry.d.ts
363
+ type ViewModelConstructor = new () => ViewModel;
364
+ type ViewConfig = string | {
365
+ id: string;
366
+ label?: string;
367
+ sections?: Record<string, any>;
368
+ };
369
+ declare function registerCalendarView(id: string, viewClass: ViewModelConstructor): void;
370
+ //#endregion
371
+ //#region src/constants.d.ts
372
+ declare function getMenuOptions(): {
373
+ id: string;
374
+ text: string;
375
+ icon: string;
376
+ }[];
377
+ type ToolbarItem = {
378
+ id?: string;
379
+ comp: string;
380
+ value?: any;
381
+ options?: {
382
+ id: string;
383
+ label: string;
384
+ }[];
385
+ [key: string]: any;
386
+ };
387
+ declare function getToolbarItems(): ToolbarItem[];
388
+ //#endregion
389
+ //#region src/calendar_store.d.ts
390
+ declare class CalendarStore extends Store<State> {
391
+ in: EventBus<StoreActions, keyof StoreActions>;
392
+ private _router;
393
+ private _views;
394
+ private _weekStartDay;
395
+ private _dateFormat;
396
+ constructor(w: TWritableCreator, options?: {
397
+ recurring?: boolean;
398
+ weekStart?: number;
399
+ dateFormat?: FormatFactory;
400
+ });
401
+ configureViews(views?: ViewConfig[]): void;
402
+ init(state: Partial<State>): void;
403
+ private applyViewConfig;
404
+ getView(name: string): any;
405
+ getEvents(start?: Date, end?: Date): CalendarEvent[];
406
+ getEvent(id: string | number): CalendarEvent | undefined;
407
+ getBrandmark(): Brandmark | null;
408
+ setState(state: Partial<State>, ctx?: TDataConfig): {
409
+ [key: string]: (() => void) | null;
410
+ };
411
+ }
412
+ //#endregion
413
+ //#region src/index.d.ts
414
+ declare const version: string;
415
+ //#endregion
416
+ export { type Brandmark, type CalendarEvent, CalendarStore, type CellContext, type CellCss, type CombinedScaleConfig, type DateScaleConfig, DayViewModel, DiscreteScale, type EventContentMode, type EventContext, type EventCss, type EventID, EventsStore, type FormatFactory, type GridCell, type IEventStore, LinearScale, MonthViewModel, type Primitive, type Scale, type ScaleConfig, type ScaleUnit, type Section, type SectionMode, type SectionResult, type StackedScaleConfig, type State, type StoreActions, type TimeScaleConfig, type ToolbarItem, type UnitScaleConfig, type ViewConfig, ViewModel, WeekViewModel, createScale, getMenuOptions, getToolbarItems, isMultiDay, layoutBars, layoutBoxes, registerCalendarView, version };