@sprucelabs/spruce-calendar-components 22.3.17 → 22.3.18

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.
@@ -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
  }
@@ -3,7 +3,7 @@ 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
8
  export declare class CalendarEventManager {
9
9
  private calendarVc;
@@ -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;
@@ -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();
@@ -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;
@@ -3,7 +3,7 @@ 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
8
  export declare class CalendarEventManager {
9
9
  private calendarVc;
@@ -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;
@@ -208,12 +208,19 @@ class CalendarEventManager {
208
208
  return updated;
209
209
  }
210
210
  async setEventInContext(newEvent, options) {
211
+ var _a;
211
212
  this.shouldIgnoreNextContextUpdate =
212
213
  (options === null || options === void 0 ? void 0 : options.shouldHandleDidUpdateContext) !== false;
213
- await this.sm.updateContext({
214
+ await ((_a = this.updateContext) !== null && _a !== void 0 ? _a : this.sm.updateContext.bind(this.sm))({
214
215
  event: newEvent,
215
216
  });
216
217
  }
218
+ setUpdateContextHandler(handler) {
219
+ this.updateContext = handler;
220
+ }
221
+ clearUpdateContextHandler() {
222
+ delete this.updateContext;
223
+ }
217
224
  async selectEvent(eventId) {
218
225
  const lastSelected = this.calendarVc.getSelectedEvent();
219
226
  const event = this.calendarVc.getEvent(eventId);
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.17",
4
+ "version": "22.3.18",
5
5
  "skill": {
6
6
  "namespace": "calendar"
7
7
  },