@sprucelabs/spruce-calendar-components 22.3.16 → 22.3.19

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.
@@ -2,7 +2,7 @@ import { AbstractSkillViewController, SkillViewControllerLoadOptions, SpruceSche
2
2
  import { RemoteViewControllerFactory } from '@sprucelabs/spruce-heartwood-utils';
3
3
  import RemotePreferencesStore from '../stores/RemotePreferencesStore';
4
4
  import { CalendarToolBeltStateMachine } from '../types/calendar.types';
5
- import { CalendarEventManager } from '../utilities/CalendarEventManager';
5
+ import CalendarEventManager from '../utilities/CalendarEventManager';
6
6
  import CalendarPeopleManager from '../utilities/CalendarPeopleManager';
7
7
  import CalendarViewController from '../viewControllers/Calendar.vc';
8
8
  export default class RootSkillViewController extends AbstractSkillViewController<Args> {
@@ -13,7 +13,7 @@ import RemoteEventStoreImpl from '../stores/RemoteEventStore.js';
13
13
  import RemotePreferencesStore from '../stores/RemotePreferencesStore.js';
14
14
  import { PrerequisitesToolBeltState } from '../toolBelt/states/PrerequisitesToolBeltState.js';
15
15
  import { RootToolBeltState } from '../toolBelt/states/RootToolBeltState.js';
16
- import { CalendarEventManager } from '../utilities/CalendarEventManager.js';
16
+ import CalendarEventManager from '../utilities/CalendarEventManager.js';
17
17
  import CalendarPeopleManager from '../utilities/CalendarPeopleManager.js';
18
18
  export default class RootSkillViewController extends AbstractSkillViewController {
19
19
  constructor(options) {
@@ -249,6 +249,7 @@ export default class RootSkillViewController extends AbstractSkillViewController
249
249
  }
250
250
  handleDraftEventAdded(event) {
251
251
  return __awaiter(this, void 0, void 0, function* () {
252
+ console.log('handle draft event added');
252
253
  yield this.events.addDraftEvent(event, !event.eventTypeSlug);
253
254
  if (!event.eventTypeSlug) {
254
255
  this.toolBeltVc.open({ shouldStayOpen: true });
@@ -256,9 +257,9 @@ export default class RootSkillViewController extends AbstractSkillViewController
256
257
  }
257
258
  });
258
259
  }
259
- handleEventSwapped(event) {
260
+ handleEventSwapped(draft, event) {
260
261
  return __awaiter(this, void 0, void 0, function* () {
261
- yield this.events.silentlySwapEvent(this.sm.getContext().event.id, event);
262
+ yield this.events.silentlySwapEvent(draft.id, event);
262
263
  });
263
264
  }
264
265
  handleDropEvent(id, updates) {
@@ -12,8 +12,10 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
12
12
  private vcs;
13
13
  private pendingContextUpdates;
14
14
  private controlsVc;
15
- private _isLoaded;
15
+ private isLoaded;
16
+ private events;
16
17
  load(sm: CalendarToolBeltStateMachine): Promise<void>;
18
+ getIsLoaded(): boolean;
17
19
  protected loadRemoteCards(): Promise<void>;
18
20
  protected handleClickSave(): Promise<void>;
19
21
  private deselectEvent;
@@ -14,15 +14,20 @@ export default class AbstractCalendarEventToolBeltState {
14
14
  constructor() {
15
15
  this.vcs = [];
16
16
  this.pendingContextUpdates = {};
17
- //@ts-ignore
18
- this._isLoaded = false;
17
+ this.isLoaded = false;
19
18
  }
20
19
  load(sm) {
21
20
  return __awaiter(this, void 0, void 0, function* () {
22
21
  this.sm = sm;
23
22
  this.toolBeltVc = sm.getToolBeltVc();
24
- this._isLoaded = true;
23
+ this.isLoaded = true;
25
24
  this.controlsVc = sm.Controller('calendar.event-controls-card', Object.assign(Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')), { onCancelEvent: this.sm.getContext().cancelEvent }));
25
+ this.events = sm.getContext().events;
26
+ this.events.setUpdateContextHandler((updates) => __awaiter(this, void 0, void 0, function* () {
27
+ return this.handleUpdateContextFromTool(updates, 'eventManager', {
28
+ shouldPersistContextChangesImmediately: true,
29
+ });
30
+ }));
26
31
  this.toolBeltVc.clearTools();
27
32
  this.toolBeltVc.setStickyTool({
28
33
  card: this.controlsVc.render(),
@@ -33,6 +38,9 @@ export default class AbstractCalendarEventToolBeltState {
33
38
  yield this.sm.on('did-update-context', this.handleDidUpdateContext);
34
39
  });
35
40
  }
41
+ getIsLoaded() {
42
+ return this.isLoaded;
43
+ }
36
44
  loadRemoteCards() {
37
45
  return __awaiter(this, void 0, void 0, function* () {
38
46
  const registrar = new CalendarToolRegistrar(this.sm, (vc) => {
@@ -173,6 +181,7 @@ export default class AbstractCalendarEventToolBeltState {
173
181
  destroy() {
174
182
  return __awaiter(this, void 0, void 0, function* () {
175
183
  yield this.sm.off('did-update-context', this.handleDidUpdateContext);
184
+ this.events.clearUpdateContextHandler();
176
185
  });
177
186
  }
178
187
  }
@@ -1,6 +1,6 @@
1
1
  import { SpruceSchemas, ToolBeltState } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { CalendarToolBeltStateMachine } from '../../types/calendar.types';
3
- import { CalendarEventManager } from '../../utilities/CalendarEventManager';
3
+ import CalendarEventManager from '../../utilities/CalendarEventManager';
4
4
  import CalendarPeopleManager from '../../utilities/CalendarPeopleManager';
5
5
  import CalendarSelectCardViewController from '../../viewControllers/CalendarSelectTool.vc';
6
6
  import DateSelectCardViewController from '../../viewControllers/DateSelectCard.vc';
@@ -2,7 +2,7 @@ import { AbstractViewController, LineIcon, SkillViewControllerLoadOptions, ToolB
2
2
  import { SpruceSchemas } from '@sprucelabs/mercury-types';
3
3
  import { EventTarget } from '@sprucelabs/spruce-event-utils';
4
4
  import { UpdateRepeatingStrategy } from '../constants';
5
- import { CalendarEventManager } from '../utilities/CalendarEventManager';
5
+ import CalendarEventManager from '../utilities/CalendarEventManager';
6
6
  import CalendarPeopleManager from '../utilities/CalendarPeopleManager';
7
7
  import CalendarViewController from '../viewControllers/Calendar.vc';
8
8
  export interface Schedule {
@@ -1,11 +1,11 @@
1
- import { DateUtils } from '@sprucelabs/calendar-utils';
1
+ import { DateUtil } from '@sprucelabs/calendar-utils';
2
2
  import { CalendarEvent } from '@sprucelabs/heartwood-view-controllers';
3
3
  import { RemoteViewControllerFactory } from '@sprucelabs/spruce-heartwood-utils';
4
4
  import { RemoteEventStore } from '../stores/RemoteEventStore';
5
5
  import RemotePreferencesStore from '../stores/RemotePreferencesStore';
6
- import { CalendarToolBeltStateMachine, UpdateEvent, UpdateRepeatingStrategyWithCancel } from '../types/calendar.types';
6
+ import { CalendarToolBeltContext, CalendarToolBeltStateMachine, UpdateCalendarToolBeltContextHandler, UpdateEvent, UpdateRepeatingStrategyWithCancel } from '../types/calendar.types';
7
7
  import CalendarViewController from '../viewControllers/Calendar.vc';
8
- export declare class CalendarEventManager {
8
+ export default class CalendarEventManager {
9
9
  private calendarVc;
10
10
  protected allEvents: CalendarEvent[];
11
11
  private inclusiveCalendarIds;
@@ -23,6 +23,7 @@ export declare class CalendarEventManager {
23
23
  private calendars;
24
24
  private shouldUpdateContextOnNextSave;
25
25
  private isLoaded;
26
+ protected updateContext?: UpdateCalendarToolBeltContextHandler<CalendarToolBeltContext>;
26
27
  protected get calendarIds(): string[];
27
28
  protected get visibleCalendarIds(): string[];
28
29
  constructor(options: CalendarEventManagerOptions);
@@ -54,8 +55,35 @@ export declare class CalendarEventManager {
54
55
  setCalendarVisibility(calendarId: string, shouldBeVisible: boolean): Promise<void>;
55
56
  setupVcForEventType(vcId: string, typeSlug: string): Promise<void>;
56
57
  private assertValidCalendarId;
57
- private updateEventInContext;
58
+ protected updateEventInContext(updates: Partial<CalendarEvent>): Promise<{
59
+ isBusy: boolean;
60
+ id: string;
61
+ target: import("@sprucelabs/calendar-utils").SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventTarget;
62
+ calendarId: string;
63
+ eventTypeSlug?: string | null | undefined;
64
+ startDateTimeMs: number;
65
+ isResizeable?: boolean | null | undefined;
66
+ style?: "active" | "blocked" | "draft" | "tentative" | "upcoming" | "unavailable" | "past" | "warn" | "critical" | null | undefined;
67
+ groupId?: string | null | undefined;
68
+ timeBlocks: import("@sprucelabs/calendar-utils").SpruceSchemas.CalendarUtils.v2021_05_19.EventTimeBlock[];
69
+ repeats?: "weekly" | "monthly" | "daily" | null | undefined;
70
+ daysOfWeek?: ("sun" | "mon" | "tue" | "wed" | "thur" | "fri" | "sat")[] | null | undefined;
71
+ daysOfMonth?: ("1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" | "18" | "19" | "20" | "21" | "22" | "23" | "24" | "25" | "26" | "27" | "28" | "29" | "30" | "31")[] | null | undefined;
72
+ repeatsUntil?: number | null | undefined;
73
+ occurrences?: number | null | undefined;
74
+ interval?: number | null | undefined;
75
+ nthOccurrences?: number[] | null | undefined;
76
+ activeUntilDate?: number | null | undefined;
77
+ exclusionDates?: import("@sprucelabs/calendar-utils").SpruceSchemas.CalendarUtils.v2021_05_19.EventExclusionDate[] | null | undefined;
78
+ nthInRepeating?: number | null | undefined;
79
+ totalInRepeating?: number | null | undefined;
80
+ error?: Error | null | undefined;
81
+ isSelected?: boolean | null | undefined;
82
+ controller?: import("@sprucelabs/heartwood-view-controllers").CalendarEventViewController | null | undefined;
83
+ }>;
58
84
  private setEventInContext;
85
+ setUpdateContextHandler(handler: UpdateCalendarToolBeltContextHandler<CalendarToolBeltContext>): void;
86
+ clearUpdateContextHandler(): void;
59
87
  selectEvent(eventId: string): Promise<void>;
60
88
  load(): Promise<void>;
61
89
  getEvent(id: string): CalendarEvent;
@@ -75,7 +103,7 @@ export interface CalendarEventManagerOptions {
75
103
  events: RemoteEventStore;
76
104
  remoteVc: EventManagerRemoteViewControllerFactory;
77
105
  sm: CalendarToolBeltStateMachine;
78
- dates: DateUtils;
106
+ dates: DateUtil;
79
107
  preferences: RemotePreferencesStore;
80
108
  askForUpdateStrategy: (event: UpdateEvent) => Promise<UpdateRepeatingStrategyWithCancel>;
81
109
  }
@@ -12,7 +12,7 @@ import { assertOptions, normalizeSchemaValues } from '@sprucelabs/schema';
12
12
  import SpruceError from '../errors/SpruceError.js';
13
13
  import calendarShiftGenerator from './calendarShiftGenerator.js';
14
14
  import draftEventGenerator from './draftGenerator.js';
15
- export class CalendarEventManager {
15
+ export default class CalendarEventManager {
16
16
  constructor(options) {
17
17
  this.allEvents = [];
18
18
  this.inclusiveCalendarIds = [];
@@ -235,14 +235,21 @@ export class CalendarEventManager {
235
235
  });
236
236
  }
237
237
  setEventInContext(newEvent, options) {
238
+ var _a;
238
239
  return __awaiter(this, void 0, void 0, function* () {
239
240
  this.shouldIgnoreNextContextUpdate =
240
241
  (options === null || options === void 0 ? void 0 : options.shouldHandleDidUpdateContext) !== false;
241
- yield this.sm.updateContext({
242
+ yield ((_a = this.updateContext) !== null && _a !== void 0 ? _a : this.sm.updateContext.bind(this.sm))({
242
243
  event: newEvent,
243
244
  });
244
245
  });
245
246
  }
247
+ setUpdateContextHandler(handler) {
248
+ this.updateContext = handler;
249
+ }
250
+ clearUpdateContextHandler() {
251
+ delete this.updateContext;
252
+ }
246
253
  selectEvent(eventId) {
247
254
  return __awaiter(this, void 0, void 0, function* () {
248
255
  const lastSelected = this.calendarVc.getSelectedEvent();
@@ -4,7 +4,7 @@ import { UpdateEvent } from '../types/calendar.types';
4
4
  declare type Calendar = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Calendar;
5
5
  declare type Event = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
6
6
  declare type DraftAddedHandler = (event: Event) => void | Promise<void>;
7
- declare type EventSwappedHandler = (event: Event) => void | Promise<void>;
7
+ declare type EventSwappedHandler = (draft: Event, saved: Event) => void | Promise<void>;
8
8
  declare type EventDroppedHandler = (id: string, updates: Partial<Event>) => boolean | Promise<boolean>;
9
9
  declare type DraftRemovedHandler = () => void | Promise<void>;
10
10
  declare type ClickEventHandler = (options: ClickEventOptions) => void | Promise<void>;
@@ -28,14 +28,14 @@ export default class CalendarViewController extends CoreCalendarViewController {
28
28
  super(Object.assign(Object.assign({ view: 'day' }, rest), { onDropEvent: (options) => {
29
29
  return this.handleDropEvent(options);
30
30
  } }));
31
- this.activelyPersisting = 0;
31
+ this.activelyPersisting = {};
32
32
  this.isSwapping = false;
33
33
  assertOptions(options, ['onAddDraftEvent']);
34
- const { onAddDraftEvent, onRemoveDraftEvent, onEventSwapped: onDraftEventSaved, } = rest;
34
+ const { onAddDraftEvent, onRemoveDraftEvent, onEventSwapped } = rest;
35
35
  this.sorter = new PeopleSorter();
36
36
  this.draftAddedHandler = onAddDraftEvent;
37
37
  this.draftRemovedHandler = onRemoveDraftEvent;
38
- this.eventSwappedHandler = onDraftEventSaved;
38
+ this.eventSwappedHandler = onEventSwapped;
39
39
  this.dropEventHandler = onDropEvent;
40
40
  this.remoteEventStore = remoteEventStore;
41
41
  this.model.onClick = this.handleClick.bind(this);
@@ -189,9 +189,14 @@ export default class CalendarViewController extends CoreCalendarViewController {
189
189
  const id = event.id;
190
190
  const isBusy = (options === null || options === void 0 ? void 0 : options.isBusy) === true;
191
191
  try {
192
- this.activelyPersisting++;
192
+ if (!this.activelyPersisting[id]) {
193
+ this.activelyPersisting[id] = 1;
194
+ }
195
+ else {
196
+ this.activelyPersisting[id]++;
197
+ }
193
198
  const saved = yield ((_a = this.remoteEventStore) === null || _a === void 0 ? void 0 : _a.persist(Object.assign(Object.assign({}, event), { isBusy })));
194
- this.activelyPersisting--;
199
+ this.activelyPersisting[id]--;
195
200
  if (!saved) {
196
201
  return;
197
202
  }
@@ -203,8 +208,8 @@ export default class CalendarViewController extends CoreCalendarViewController {
203
208
  this.lastSwappedId = id;
204
209
  yield this.swapEvent(event, saved);
205
210
  }
206
- if (this.activelyPersisting === 0) {
207
- yield ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, saved));
211
+ if (this.activelyPersisting[id] === 0) {
212
+ yield ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, event, saved));
208
213
  }
209
214
  }
210
215
  else {
@@ -1,5 +1,5 @@
1
1
  import { AbstractViewController, ActiveRecordCardViewController, Scope, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
- import { CalendarEventManager } from '../utilities/CalendarEventManager';
2
+ import CalendarEventManager from '../utilities/CalendarEventManager';
3
3
  export default class CalendarSelectCardViewController extends AbstractViewController<Card> {
4
4
  static id: string;
5
5
  private isLoaded;
@@ -2,7 +2,7 @@ import { AbstractSkillViewController, SkillViewControllerLoadOptions, SpruceSche
2
2
  import { RemoteViewControllerFactory } from '@sprucelabs/spruce-heartwood-utils';
3
3
  import RemotePreferencesStore from '../stores/RemotePreferencesStore';
4
4
  import { CalendarToolBeltStateMachine } from '../types/calendar.types';
5
- import { CalendarEventManager } from '../utilities/CalendarEventManager';
5
+ import CalendarEventManager from '../utilities/CalendarEventManager';
6
6
  import CalendarPeopleManager from '../utilities/CalendarPeopleManager';
7
7
  import CalendarViewController from '../viewControllers/Calendar.vc';
8
8
  export default class RootSkillViewController extends AbstractSkillViewController<Args> {
@@ -9,7 +9,7 @@ const RemoteEventStore_1 = __importDefault(require("../stores/RemoteEventStore")
9
9
  const RemotePreferencesStore_1 = __importDefault(require("../stores/RemotePreferencesStore"));
10
10
  const PrerequisitesToolBeltState_1 = require("../toolBelt/states/PrerequisitesToolBeltState");
11
11
  const RootToolBeltState_1 = require("../toolBelt/states/RootToolBeltState");
12
- const CalendarEventManager_1 = require("../utilities/CalendarEventManager");
12
+ const CalendarEventManager_1 = __importDefault(require("../utilities/CalendarEventManager"));
13
13
  const CalendarPeopleManager_1 = __importDefault(require("../utilities/CalendarPeopleManager"));
14
14
  class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkillViewController {
15
15
  constructor(options) {
@@ -34,7 +34,7 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
34
34
  calendarVc: this.calendarVc,
35
35
  getVisibleEvents: this.getVisibleEvents.bind(this),
36
36
  });
37
- this.events = new CalendarEventManager_1.CalendarEventManager({
37
+ this.events = new CalendarEventManager_1.default({
38
38
  calendarVc: this.calendarVc,
39
39
  events: this.remoteEventStore,
40
40
  remoteVc: this.remoteVc,
@@ -220,14 +220,15 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
220
220
  }
221
221
  }
222
222
  async handleDraftEventAdded(event) {
223
+ console.log('handle draft event added');
223
224
  await this.events.addDraftEvent(event, !event.eventTypeSlug);
224
225
  if (!event.eventTypeSlug) {
225
226
  this.toolBeltVc.open({ shouldStayOpen: true });
226
227
  await this.sm.transitionTo(this.toolBeltStates.prerequisites);
227
228
  }
228
229
  }
229
- async handleEventSwapped(event) {
230
- await this.events.silentlySwapEvent(this.sm.getContext().event.id, event);
230
+ async handleEventSwapped(draft, event) {
231
+ await this.events.silentlySwapEvent(draft.id, event);
231
232
  }
232
233
  async handleDropEvent(id, updates) {
233
234
  return this.events.handleDropEvent(id, updates);
@@ -12,8 +12,10 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
12
12
  private vcs;
13
13
  private pendingContextUpdates;
14
14
  private controlsVc;
15
- private _isLoaded;
15
+ private isLoaded;
16
+ private events;
16
17
  load(sm: CalendarToolBeltStateMachine): Promise<void>;
18
+ getIsLoaded(): boolean;
17
19
  protected loadRemoteCards(): Promise<void>;
18
20
  protected handleClickSave(): Promise<void>;
19
21
  private deselectEvent;
@@ -10,14 +10,19 @@ class AbstractCalendarEventToolBeltState {
10
10
  constructor() {
11
11
  this.vcs = [];
12
12
  this.pendingContextUpdates = {};
13
- //@ts-ignore
14
- this._isLoaded = false;
13
+ this.isLoaded = false;
15
14
  }
16
15
  async load(sm) {
17
16
  this.sm = sm;
18
17
  this.toolBeltVc = sm.getToolBeltVc();
19
- this._isLoaded = true;
18
+ this.isLoaded = true;
20
19
  this.controlsVc = sm.Controller('calendar.event-controls-card', Object.assign(Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')), { onCancelEvent: this.sm.getContext().cancelEvent }));
20
+ this.events = sm.getContext().events;
21
+ this.events.setUpdateContextHandler(async (updates) => {
22
+ return this.handleUpdateContextFromTool(updates, 'eventManager', {
23
+ shouldPersistContextChangesImmediately: true,
24
+ });
25
+ });
21
26
  this.toolBeltVc.clearTools();
22
27
  this.toolBeltVc.setStickyTool({
23
28
  card: this.controlsVc.render(),
@@ -27,6 +32,9 @@ class AbstractCalendarEventToolBeltState {
27
32
  this.handleDidUpdateContext = this.handleDidUpdateContext.bind(this);
28
33
  await this.sm.on('did-update-context', this.handleDidUpdateContext);
29
34
  }
35
+ getIsLoaded() {
36
+ return this.isLoaded;
37
+ }
30
38
  async loadRemoteCards() {
31
39
  const registrar = new CalendarToolRegistrar_1.default(this.sm, (vc) => {
32
40
  //@ts-ignore
@@ -148,6 +156,7 @@ class AbstractCalendarEventToolBeltState {
148
156
  }
149
157
  async destroy() {
150
158
  await this.sm.off('did-update-context', this.handleDidUpdateContext);
159
+ this.events.clearUpdateContextHandler();
151
160
  }
152
161
  }
153
162
  exports.default = AbstractCalendarEventToolBeltState;
@@ -1,6 +1,6 @@
1
1
  import { SpruceSchemas, ToolBeltState } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { CalendarToolBeltStateMachine } from '../../types/calendar.types';
3
- import { CalendarEventManager } from '../../utilities/CalendarEventManager';
3
+ import CalendarEventManager from '../../utilities/CalendarEventManager';
4
4
  import CalendarPeopleManager from '../../utilities/CalendarPeopleManager';
5
5
  import CalendarSelectCardViewController from '../../viewControllers/CalendarSelectTool.vc';
6
6
  import DateSelectCardViewController from '../../viewControllers/DateSelectCard.vc';
@@ -2,7 +2,7 @@ import { AbstractViewController, LineIcon, SkillViewControllerLoadOptions, ToolB
2
2
  import { SpruceSchemas } from '@sprucelabs/mercury-types';
3
3
  import { EventTarget } from '@sprucelabs/spruce-event-utils';
4
4
  import { UpdateRepeatingStrategy } from '../constants';
5
- import { CalendarEventManager } from '../utilities/CalendarEventManager';
5
+ import CalendarEventManager from '../utilities/CalendarEventManager';
6
6
  import CalendarPeopleManager from '../utilities/CalendarPeopleManager';
7
7
  import CalendarViewController from '../viewControllers/Calendar.vc';
8
8
  export interface Schedule {
@@ -1,11 +1,11 @@
1
- import { DateUtils } from '@sprucelabs/calendar-utils';
1
+ import { DateUtil } from '@sprucelabs/calendar-utils';
2
2
  import { CalendarEvent } from '@sprucelabs/heartwood-view-controllers';
3
3
  import { RemoteViewControllerFactory } from '@sprucelabs/spruce-heartwood-utils';
4
4
  import { RemoteEventStore } from '../stores/RemoteEventStore';
5
5
  import RemotePreferencesStore from '../stores/RemotePreferencesStore';
6
- import { CalendarToolBeltStateMachine, UpdateEvent, UpdateRepeatingStrategyWithCancel } from '../types/calendar.types';
6
+ import { CalendarToolBeltContext, CalendarToolBeltStateMachine, UpdateCalendarToolBeltContextHandler, UpdateEvent, UpdateRepeatingStrategyWithCancel } from '../types/calendar.types';
7
7
  import CalendarViewController from '../viewControllers/Calendar.vc';
8
- export declare class CalendarEventManager {
8
+ export default class CalendarEventManager {
9
9
  private calendarVc;
10
10
  protected allEvents: CalendarEvent[];
11
11
  private inclusiveCalendarIds;
@@ -23,6 +23,7 @@ export declare class CalendarEventManager {
23
23
  private calendars;
24
24
  private shouldUpdateContextOnNextSave;
25
25
  private isLoaded;
26
+ protected updateContext?: UpdateCalendarToolBeltContextHandler<CalendarToolBeltContext>;
26
27
  protected get calendarIds(): string[];
27
28
  protected get visibleCalendarIds(): string[];
28
29
  constructor(options: CalendarEventManagerOptions);
@@ -54,8 +55,35 @@ export declare class CalendarEventManager {
54
55
  setCalendarVisibility(calendarId: string, shouldBeVisible: boolean): Promise<void>;
55
56
  setupVcForEventType(vcId: string, typeSlug: string): Promise<void>;
56
57
  private assertValidCalendarId;
57
- private updateEventInContext;
58
+ protected updateEventInContext(updates: Partial<CalendarEvent>): Promise<{
59
+ isBusy: boolean;
60
+ id: string;
61
+ target: import("@sprucelabs/calendar-utils").SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventTarget;
62
+ calendarId: string;
63
+ eventTypeSlug?: string | null | undefined;
64
+ startDateTimeMs: number;
65
+ isResizeable?: boolean | null | undefined;
66
+ style?: "active" | "blocked" | "draft" | "tentative" | "upcoming" | "unavailable" | "past" | "warn" | "critical" | null | undefined;
67
+ groupId?: string | null | undefined;
68
+ timeBlocks: import("@sprucelabs/calendar-utils").SpruceSchemas.CalendarUtils.v2021_05_19.EventTimeBlock[];
69
+ repeats?: "weekly" | "monthly" | "daily" | null | undefined;
70
+ daysOfWeek?: ("sun" | "mon" | "tue" | "wed" | "thur" | "fri" | "sat")[] | null | undefined;
71
+ daysOfMonth?: ("1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" | "18" | "19" | "20" | "21" | "22" | "23" | "24" | "25" | "26" | "27" | "28" | "29" | "30" | "31")[] | null | undefined;
72
+ repeatsUntil?: number | null | undefined;
73
+ occurrences?: number | null | undefined;
74
+ interval?: number | null | undefined;
75
+ nthOccurrences?: number[] | null | undefined;
76
+ activeUntilDate?: number | null | undefined;
77
+ exclusionDates?: import("@sprucelabs/calendar-utils").SpruceSchemas.CalendarUtils.v2021_05_19.EventExclusionDate[] | null | undefined;
78
+ nthInRepeating?: number | null | undefined;
79
+ totalInRepeating?: number | null | undefined;
80
+ error?: Error | null | undefined;
81
+ isSelected?: boolean | null | undefined;
82
+ controller?: import("@sprucelabs/heartwood-view-controllers").CalendarEventViewController | null | undefined;
83
+ }>;
58
84
  private setEventInContext;
85
+ setUpdateContextHandler(handler: UpdateCalendarToolBeltContextHandler<CalendarToolBeltContext>): void;
86
+ clearUpdateContextHandler(): void;
59
87
  selectEvent(eventId: string): Promise<void>;
60
88
  load(): Promise<void>;
61
89
  getEvent(id: string): CalendarEvent;
@@ -75,7 +103,7 @@ export interface CalendarEventManagerOptions {
75
103
  events: RemoteEventStore;
76
104
  remoteVc: EventManagerRemoteViewControllerFactory;
77
105
  sm: CalendarToolBeltStateMachine;
78
- dates: DateUtils;
106
+ dates: DateUtil;
79
107
  preferences: RemotePreferencesStore;
80
108
  askForUpdateStrategy: (event: UpdateEvent) => Promise<UpdateRepeatingStrategyWithCancel>;
81
109
  }
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CalendarEventManager = void 0;
7
6
  const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
8
7
  const schema_1 = require("@sprucelabs/schema");
9
8
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
@@ -208,12 +207,19 @@ class CalendarEventManager {
208
207
  return updated;
209
208
  }
210
209
  async setEventInContext(newEvent, options) {
210
+ var _a;
211
211
  this.shouldIgnoreNextContextUpdate =
212
212
  (options === null || options === void 0 ? void 0 : options.shouldHandleDidUpdateContext) !== false;
213
- await this.sm.updateContext({
213
+ await ((_a = this.updateContext) !== null && _a !== void 0 ? _a : this.sm.updateContext.bind(this.sm))({
214
214
  event: newEvent,
215
215
  });
216
216
  }
217
+ setUpdateContextHandler(handler) {
218
+ this.updateContext = handler;
219
+ }
220
+ clearUpdateContextHandler() {
221
+ delete this.updateContext;
222
+ }
217
223
  async selectEvent(eventId) {
218
224
  const lastSelected = this.calendarVc.getSelectedEvent();
219
225
  const event = this.calendarVc.getEvent(eventId);
@@ -310,4 +316,4 @@ class CalendarEventManager {
310
316
  return true;
311
317
  }
312
318
  }
313
- exports.CalendarEventManager = CalendarEventManager;
319
+ exports.default = CalendarEventManager;
@@ -4,7 +4,7 @@ import { UpdateEvent } from '../types/calendar.types';
4
4
  declare type Calendar = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Calendar;
5
5
  declare type Event = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
6
6
  declare type DraftAddedHandler = (event: Event) => void | Promise<void>;
7
- declare type EventSwappedHandler = (event: Event) => void | Promise<void>;
7
+ declare type EventSwappedHandler = (draft: Event, saved: Event) => void | Promise<void>;
8
8
  declare type EventDroppedHandler = (id: string, updates: Partial<Event>) => boolean | Promise<boolean>;
9
9
  declare type DraftRemovedHandler = () => void | Promise<void>;
10
10
  declare type ClickEventHandler = (options: ClickEventOptions) => void | Promise<void>;
@@ -24,14 +24,14 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
24
24
  super(Object.assign(Object.assign({ view: 'day' }, rest), { onDropEvent: (options) => {
25
25
  return this.handleDropEvent(options);
26
26
  } }));
27
- this.activelyPersisting = 0;
27
+ this.activelyPersisting = {};
28
28
  this.isSwapping = false;
29
29
  (0, schema_1.assertOptions)(options, ['onAddDraftEvent']);
30
- const { onAddDraftEvent, onRemoveDraftEvent, onEventSwapped: onDraftEventSaved, } = rest;
30
+ const { onAddDraftEvent, onRemoveDraftEvent, onEventSwapped } = rest;
31
31
  this.sorter = new calendar_utils_1.PeopleSorter();
32
32
  this.draftAddedHandler = onAddDraftEvent;
33
33
  this.draftRemovedHandler = onRemoveDraftEvent;
34
- this.eventSwappedHandler = onDraftEventSaved;
34
+ this.eventSwappedHandler = onEventSwapped;
35
35
  this.dropEventHandler = onDropEvent;
36
36
  this.remoteEventStore = remoteEventStore;
37
37
  this.model.onClick = this.handleClick.bind(this);
@@ -166,9 +166,14 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
166
166
  const id = event.id;
167
167
  const isBusy = (options === null || options === void 0 ? void 0 : options.isBusy) === true;
168
168
  try {
169
- this.activelyPersisting++;
169
+ if (!this.activelyPersisting[id]) {
170
+ this.activelyPersisting[id] = 1;
171
+ }
172
+ else {
173
+ this.activelyPersisting[id]++;
174
+ }
170
175
  const saved = await ((_a = this.remoteEventStore) === null || _a === void 0 ? void 0 : _a.persist(Object.assign(Object.assign({}, event), { isBusy })));
171
- this.activelyPersisting--;
176
+ this.activelyPersisting[id]--;
172
177
  if (!saved) {
173
178
  return;
174
179
  }
@@ -180,8 +185,8 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
180
185
  this.lastSwappedId = id;
181
186
  await this.swapEvent(event, saved);
182
187
  }
183
- if (this.activelyPersisting === 0) {
184
- await ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, saved));
188
+ if (this.activelyPersisting[id] === 0) {
189
+ await ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, event, saved));
185
190
  }
186
191
  }
187
192
  else {
@@ -1,5 +1,5 @@
1
1
  import { AbstractViewController, ActiveRecordCardViewController, Scope, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
- import { CalendarEventManager } from '../utilities/CalendarEventManager';
2
+ import CalendarEventManager from '../utilities/CalendarEventManager';
3
3
  export default class CalendarSelectCardViewController extends AbstractViewController<Card> {
4
4
  static id: string;
5
5
  private isLoaded;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-calendar-components",
3
3
  "description": "Calendar components for working with calendars and Sprucebot.",
4
- "version": "22.3.16",
4
+ "version": "22.3.19",
5
5
  "skill": {
6
6
  "namespace": "calendar"
7
7
  },