@sprucelabs/spruce-calendar-components 20.3.1 → 20.3.2

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.
@@ -31,6 +31,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
31
31
  private dropEventHandler?;
32
32
  private isSwapping;
33
33
  private lastSwappedId?;
34
+ private activelyPersisting;
34
35
  constructor(options: ViewControllerOptions & CalendarViewControllerOptions);
35
36
  private handleDropEvent;
36
37
  getCalendarVc(): this;
@@ -40,7 +41,32 @@ export default class CalendarViewController extends CoreCalendarViewController {
40
41
  private getDraftEvent;
41
42
  private removeDraftEvent;
42
43
  private addDraftEventFromClick;
43
- addDraftEvent(event: Event): Promise<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent | SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent>;
44
+ addDraftEvent(e: Omit<Event, 'id'>): Promise<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent | {
45
+ id: string;
46
+ interval?: number | null | undefined;
47
+ error?: Error | null | undefined;
48
+ style?: "active" | "blocked" | "tentative" | "upcoming" | "unavailable" | "past" | "warn" | "critical" | "draft" | null | undefined;
49
+ target: SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventTarget;
50
+ isBusy?: boolean | null | undefined;
51
+ calendarId: string;
52
+ eventTypeSlug?: string | null | undefined;
53
+ startDateTimeMs: number;
54
+ isResizeable?: boolean | null | undefined;
55
+ groupId?: string | null | undefined;
56
+ timeBlocks: SpruceSchemas.CalendarUtils.v2021_05_19.EventTimeBlock[];
57
+ repeats?: "weekly" | "monthly" | "daily" | null | undefined;
58
+ daysOfWeek?: ("sun" | "mon" | "tue" | "wed" | "thur" | "fri" | "sat")[] | null | undefined;
59
+ 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;
60
+ repeatsUntil?: number | null | undefined;
61
+ occurrences?: number | null | undefined;
62
+ nthOccurrences?: number[] | null | undefined;
63
+ activeUntilDate?: number | null | undefined;
64
+ exclusionDates?: SpruceSchemas.CalendarUtils.v2021_05_19.EventExclusionDate[] | null | undefined;
65
+ nthInRepeating?: number | null | undefined;
66
+ totalInRepeating?: number | null | undefined;
67
+ controller?: import("@sprucelabs/heartwood-view-controllers").CalendarEventViewController | null | undefined;
68
+ isSelected?: boolean | null | undefined;
69
+ }>;
44
70
  getIsSwappingEvent(): boolean;
45
71
  private swapEvent;
46
72
  updateEvent(id: string, updates: Partial<UpdateEvent>): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
@@ -28,6 +28,7 @@ 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
32
  this.isSwapping = false;
32
33
  assertOptions(options, ['onAddDraftEvent']);
33
34
  const { onAddDraftEvent, onRemoveDraftEvent, onEventSwapped: onDraftEventSaved, } = rest;
@@ -117,17 +118,17 @@ export default class CalendarViewController extends CoreCalendarViewController {
117
118
  return yield this.addDraftEvent(event);
118
119
  });
119
120
  }
120
- addDraftEvent(event) {
121
+ addDraftEvent(e) {
121
122
  return __awaiter(this, void 0, void 0, function* () {
122
- if (event.id) {
123
+ //@ts-ignore
124
+ if (e.id) {
123
125
  throw new SchemaError({
124
126
  code: 'UNEXPECTED_PARAMETERS',
125
127
  parameters: ['id'],
126
128
  });
127
129
  }
128
- event.id = draftEventGenerator.generateId();
130
+ const event = Object.assign(Object.assign({}, e), { id: draftEventGenerator.generateId() });
129
131
  this.addEvent(event);
130
- this.selectEvent(event.id);
131
132
  const draftAddedPromise = this.draftAddedHandler(event);
132
133
  const saved = yield this.persist(event);
133
134
  yield draftAddedPromise;
@@ -177,24 +178,27 @@ export default class CalendarViewController extends CoreCalendarViewController {
177
178
  const _super = Object.create(null, {
178
179
  updateEvent: { get: () => super.updateEvent }
179
180
  });
180
- var _a, _b, _c;
181
+ var _a, _b;
181
182
  return __awaiter(this, void 0, void 0, function* () {
182
183
  const id = event.id;
183
184
  const isBusy = (options === null || options === void 0 ? void 0 : options.isBusy) === true;
184
185
  try {
186
+ this.activelyPersisting++;
185
187
  const saved = yield ((_a = this.remoteEventStore) === null || _a === void 0 ? void 0 : _a.persist(Object.assign(Object.assign({}, event), { isBusy })));
188
+ this.activelyPersisting--;
186
189
  if (!saved) {
187
190
  return;
188
191
  }
189
192
  if (id !== saved.id) {
190
193
  if (this.lastSwappedId === id) {
191
194
  _super.updateEvent.call(this, saved.id, saved);
192
- yield ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, saved));
193
195
  }
194
196
  else {
195
197
  this.lastSwappedId = id;
196
198
  yield this.swapEvent(event, saved);
197
- yield ((_c = this.eventSwappedHandler) === null || _c === void 0 ? void 0 : _c.call(this, saved));
199
+ }
200
+ if (this.activelyPersisting === 0) {
201
+ yield ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, saved));
198
202
  }
199
203
  }
200
204
  else {
@@ -31,6 +31,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
31
31
  private dropEventHandler?;
32
32
  private isSwapping;
33
33
  private lastSwappedId?;
34
+ private activelyPersisting;
34
35
  constructor(options: ViewControllerOptions & CalendarViewControllerOptions);
35
36
  private handleDropEvent;
36
37
  getCalendarVc(): this;
@@ -40,7 +41,32 @@ export default class CalendarViewController extends CoreCalendarViewController {
40
41
  private getDraftEvent;
41
42
  private removeDraftEvent;
42
43
  private addDraftEventFromClick;
43
- addDraftEvent(event: Event): Promise<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent | SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent>;
44
+ addDraftEvent(e: Omit<Event, 'id'>): Promise<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent | {
45
+ id: string;
46
+ interval?: number | null | undefined;
47
+ error?: Error | null | undefined;
48
+ style?: "active" | "blocked" | "tentative" | "upcoming" | "unavailable" | "past" | "warn" | "critical" | "draft" | null | undefined;
49
+ target: SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventTarget;
50
+ isBusy?: boolean | null | undefined;
51
+ calendarId: string;
52
+ eventTypeSlug?: string | null | undefined;
53
+ startDateTimeMs: number;
54
+ isResizeable?: boolean | null | undefined;
55
+ groupId?: string | null | undefined;
56
+ timeBlocks: SpruceSchemas.CalendarUtils.v2021_05_19.EventTimeBlock[];
57
+ repeats?: "weekly" | "monthly" | "daily" | null | undefined;
58
+ daysOfWeek?: ("sun" | "mon" | "tue" | "wed" | "thur" | "fri" | "sat")[] | null | undefined;
59
+ 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;
60
+ repeatsUntil?: number | null | undefined;
61
+ occurrences?: number | null | undefined;
62
+ nthOccurrences?: number[] | null | undefined;
63
+ activeUntilDate?: number | null | undefined;
64
+ exclusionDates?: SpruceSchemas.CalendarUtils.v2021_05_19.EventExclusionDate[] | null | undefined;
65
+ nthInRepeating?: number | null | undefined;
66
+ totalInRepeating?: number | null | undefined;
67
+ controller?: import("@sprucelabs/heartwood-view-controllers").CalendarEventViewController | null | undefined;
68
+ isSelected?: boolean | null | undefined;
69
+ }>;
44
70
  getIsSwappingEvent(): boolean;
45
71
  private swapEvent;
46
72
  updateEvent(id: string, updates: Partial<UpdateEvent>): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
@@ -24,6 +24,7 @@ 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
28
  this.isSwapping = false;
28
29
  (0, schema_1.assertOptions)(options, ['onAddDraftEvent']);
29
30
  const { onAddDraftEvent, onRemoveDraftEvent, onEventSwapped: onDraftEventSaved, } = rest;
@@ -105,16 +106,16 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
105
106
  delete event.id;
106
107
  return await this.addDraftEvent(event);
107
108
  }
108
- async addDraftEvent(event) {
109
- if (event.id) {
109
+ async addDraftEvent(e) {
110
+ //@ts-ignore
111
+ if (e.id) {
110
112
  throw new schema_1.SchemaError({
111
113
  code: 'UNEXPECTED_PARAMETERS',
112
114
  parameters: ['id'],
113
115
  });
114
116
  }
115
- event.id = draftGenerator_1.default.generateId();
117
+ const event = Object.assign(Object.assign({}, e), { id: draftGenerator_1.default.generateId() });
116
118
  this.addEvent(event);
117
- this.selectEvent(event.id);
118
119
  const draftAddedPromise = this.draftAddedHandler(event);
119
120
  const saved = await this.persist(event);
120
121
  await draftAddedPromise;
@@ -155,23 +156,26 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
155
156
  return updated;
156
157
  }
157
158
  async persist(event, options) {
158
- var _a, _b, _c;
159
+ var _a, _b;
159
160
  const id = event.id;
160
161
  const isBusy = (options === null || options === void 0 ? void 0 : options.isBusy) === true;
161
162
  try {
163
+ this.activelyPersisting++;
162
164
  const saved = await ((_a = this.remoteEventStore) === null || _a === void 0 ? void 0 : _a.persist(Object.assign(Object.assign({}, event), { isBusy })));
165
+ this.activelyPersisting--;
163
166
  if (!saved) {
164
167
  return;
165
168
  }
166
169
  if (id !== saved.id) {
167
170
  if (this.lastSwappedId === id) {
168
171
  super.updateEvent(saved.id, saved);
169
- await ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, saved));
170
172
  }
171
173
  else {
172
174
  this.lastSwappedId = id;
173
175
  await this.swapEvent(event, saved);
174
- await ((_c = this.eventSwappedHandler) === null || _c === void 0 ? void 0 : _c.call(this, saved));
176
+ }
177
+ if (this.activelyPersisting === 0) {
178
+ await ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, saved));
175
179
  }
176
180
  }
177
181
  else {
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": "20.3.1",
4
+ "version": "20.3.2",
5
5
  "skill": {
6
6
  "namespace": "calendar"
7
7
  },