@sprucelabs/spruce-calendar-components 19.1.3 → 19.2.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.
- package/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.js +4 -3
- package/build/esm/types/calendar.types.d.ts +4 -1
- package/build/esm/viewControllers/Calendar.vc.d.ts +2 -1
- package/build/esm/viewControllers/Calendar.vc.js +26 -10
- package/build/esm/viewControllers/RepeatingControlsList.vc.js +2 -2
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.js +4 -3
- package/build/types/calendar.types.d.ts +4 -1
- package/build/viewControllers/Calendar.vc.d.ts +2 -1
- package/build/viewControllers/Calendar.vc.js +23 -9
- package/build/viewControllers/RepeatingControlsList.vc.js +2 -2
- package/package.json +1 -1
|
@@ -83,7 +83,7 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
83
83
|
}
|
|
84
84
|
buildVcConstructorOptions(id) {
|
|
85
85
|
return {
|
|
86
|
-
updateContext: (updates) => this.handleUpdateContextFromTool(updates, id),
|
|
86
|
+
updateContext: (updates, options) => this.handleUpdateContextFromTool(updates, id, options),
|
|
87
87
|
getContext: () => this.getContext(),
|
|
88
88
|
getPersonFromEvent: () => this.getPersonFromEvent(),
|
|
89
89
|
};
|
|
@@ -122,7 +122,7 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
122
122
|
return null;
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
|
-
handleUpdateContextFromTool(updates, fromToolId) {
|
|
125
|
+
handleUpdateContextFromTool(updates, fromToolId, options) {
|
|
126
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127
127
|
const pendingUpdates = Object.assign(Object.assign({}, this.pendingContextUpdates), updates);
|
|
128
128
|
if (equalDeep(this.pendingContextUpdates, pendingUpdates)) {
|
|
@@ -131,7 +131,8 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
131
131
|
this.pendingContextUpdates = pendingUpdates;
|
|
132
132
|
yield this.handleDidUpdateContext(fromToolId);
|
|
133
133
|
const vc = this.getVcForTool(fromToolId);
|
|
134
|
-
if (vc === null || vc === void 0 ? void 0 : vc.shouldPersistContextChangesImmediately)
|
|
134
|
+
if ((vc === null || vc === void 0 ? void 0 : vc.shouldPersistContextChangesImmediately) ||
|
|
135
|
+
(options === null || options === void 0 ? void 0 : options.shouldPersistContextChangesImmediately)) {
|
|
135
136
|
yield this.sm.updateContext(Object.assign({}, updates));
|
|
136
137
|
}
|
|
137
138
|
});
|
|
@@ -28,7 +28,10 @@ export interface CalendarTool extends AbstractViewController<Card> {
|
|
|
28
28
|
handleUpdateContext(context: CalendarToolBeltContext): Promise<void> | void;
|
|
29
29
|
load?: () => Promise<void> | void;
|
|
30
30
|
}
|
|
31
|
-
export
|
|
31
|
+
export interface UpdateCalendarContextOptions {
|
|
32
|
+
shouldPersistContextChangesImmediately?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare type UpdateCalendarToolBeltContextHandler = (context: Partial<CalendarToolBeltContext>, options?: UpdateCalendarContextOptions) => Promise<void>;
|
|
32
35
|
export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltContext;
|
|
33
36
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
34
37
|
export interface CalendarToolOptions {
|
|
@@ -38,7 +38,8 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
38
38
|
private handleClick;
|
|
39
39
|
private getDraftEvent;
|
|
40
40
|
private removeDraftEvent;
|
|
41
|
-
private
|
|
41
|
+
private addDraftEventFromClick;
|
|
42
|
+
addDraftEvent(event: Event): Promise<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent | UpdateEvent | undefined>;
|
|
42
43
|
getIsSwappingEvent(): boolean;
|
|
43
44
|
private swapEvent;
|
|
44
45
|
updateEvent(id: string, updates: Partial<UpdateEvent>): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
|
|
@@ -20,7 +20,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
};
|
|
21
21
|
import { PeopleSorter } from '@sprucelabs/calendar-utils';
|
|
22
22
|
import { CalendarViewController as CoreCalendarViewController, } from '@sprucelabs/heartwood-view-controllers';
|
|
23
|
-
import { assertOptions } from '@sprucelabs/schema';
|
|
23
|
+
import { assertOptions, SchemaError } from '@sprucelabs/schema';
|
|
24
24
|
import draftEventGenerator from '../utilities/draftGenerator.js';
|
|
25
25
|
export default class CalendarViewController extends CoreCalendarViewController {
|
|
26
26
|
constructor(options) {
|
|
@@ -43,13 +43,13 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
43
43
|
handleDropEvent(options) {
|
|
44
44
|
var _a;
|
|
45
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
const { event, blockUpdates,
|
|
46
|
+
const { event, blockUpdates, newPersonId, newStartDateTimeMs } = options;
|
|
47
47
|
const updates = {};
|
|
48
48
|
if (newStartDateTimeMs) {
|
|
49
49
|
updates.startDateTimeMs = newStartDateTimeMs;
|
|
50
50
|
}
|
|
51
|
-
if (
|
|
52
|
-
updates.target = Object.assign(Object.assign({}, event.target), { personId:
|
|
51
|
+
if (newPersonId) {
|
|
52
|
+
updates.target = Object.assign(Object.assign({}, event.target), { personId: newPersonId });
|
|
53
53
|
}
|
|
54
54
|
if (blockUpdates) {
|
|
55
55
|
updates.timeBlocks = [...event.timeBlocks];
|
|
@@ -84,7 +84,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
84
84
|
}
|
|
85
85
|
const draft = this.getDraftEvent();
|
|
86
86
|
if (!draft) {
|
|
87
|
-
yield this.
|
|
87
|
+
yield this.addDraftEventFromClick(options);
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
90
90
|
yield this.removeDraftEvent(draft.id);
|
|
@@ -108,16 +108,30 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
108
108
|
catch (_c) { }
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
addDraftEventFromClick(options) {
|
|
112
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const {
|
|
114
|
-
const
|
|
115
|
-
|
|
113
|
+
const { personId, dateTimeMs } = options;
|
|
114
|
+
const event = Object.assign({}, draftEventGenerator.generate(dateTimeMs !== null && dateTimeMs !== void 0 ? dateTimeMs : 0, personId !== null && personId !== void 0 ? personId : '**missing**'));
|
|
115
|
+
//@ts-ignore
|
|
116
|
+
delete event.id;
|
|
117
|
+
return yield this.addDraftEvent(event);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
addDraftEvent(event) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
if (event.id) {
|
|
123
|
+
throw new SchemaError({
|
|
124
|
+
code: 'UNEXPECTED_PARAMETERS',
|
|
125
|
+
parameters: ['id'],
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
event.id = draftEventGenerator.generateId();
|
|
116
129
|
this.addEvent(event);
|
|
117
130
|
this.selectEvent(event.id);
|
|
118
131
|
const draftAddedPromise = this.draftAddedHandler(event);
|
|
119
|
-
yield this.persist(event);
|
|
132
|
+
const saved = yield this.persist(event);
|
|
120
133
|
yield draftAddedPromise;
|
|
134
|
+
return saved;
|
|
121
135
|
});
|
|
122
136
|
}
|
|
123
137
|
getIsSwappingEvent() {
|
|
@@ -180,12 +194,14 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
180
194
|
else {
|
|
181
195
|
_super.updateEvent.call(this, saved.id, { isBusy, error: undefined });
|
|
182
196
|
}
|
|
197
|
+
return saved;
|
|
183
198
|
}
|
|
184
199
|
catch (err) {
|
|
185
200
|
if (this.hasEvent(id)) {
|
|
186
201
|
_super.updateEvent.call(this, id, { error: err, isBusy: false });
|
|
187
202
|
}
|
|
188
203
|
}
|
|
204
|
+
return event;
|
|
189
205
|
});
|
|
190
206
|
}
|
|
191
207
|
getPeople() {
|
|
@@ -336,8 +336,8 @@ export default class RepeatingControlsListViewController extends AbstractViewCon
|
|
|
336
336
|
return this.Controller('calendar', {
|
|
337
337
|
onClick: (options) => __awaiter(this, void 0, void 0, function* () {
|
|
338
338
|
var _b;
|
|
339
|
-
if (options.
|
|
340
|
-
this.changeCalendarSelectedDate(options.
|
|
339
|
+
if (options.dateTimeMs) {
|
|
340
|
+
this.changeCalendarSelectedDate(options.dateTimeMs);
|
|
341
341
|
(_b = this.didChangeRepeating) === null || _b === void 0 ? void 0 : _b.call(this, this.repeating);
|
|
342
342
|
}
|
|
343
343
|
}),
|
|
@@ -67,7 +67,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
67
67
|
}
|
|
68
68
|
buildVcConstructorOptions(id) {
|
|
69
69
|
return {
|
|
70
|
-
updateContext: (updates) => this.handleUpdateContextFromTool(updates, id),
|
|
70
|
+
updateContext: (updates, options) => this.handleUpdateContextFromTool(updates, id, options),
|
|
71
71
|
getContext: () => this.getContext(),
|
|
72
72
|
getPersonFromEvent: () => this.getPersonFromEvent(),
|
|
73
73
|
};
|
|
@@ -102,7 +102,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
102
102
|
}
|
|
103
103
|
return null;
|
|
104
104
|
}
|
|
105
|
-
async handleUpdateContextFromTool(updates, fromToolId) {
|
|
105
|
+
async handleUpdateContextFromTool(updates, fromToolId, options) {
|
|
106
106
|
const pendingUpdates = Object.assign(Object.assign({}, this.pendingContextUpdates), updates);
|
|
107
107
|
if ((0, isEqual_1.default)(this.pendingContextUpdates, pendingUpdates)) {
|
|
108
108
|
return;
|
|
@@ -110,7 +110,8 @@ class AbstractCalendarEventToolBeltState {
|
|
|
110
110
|
this.pendingContextUpdates = pendingUpdates;
|
|
111
111
|
await this.handleDidUpdateContext(fromToolId);
|
|
112
112
|
const vc = this.getVcForTool(fromToolId);
|
|
113
|
-
if (vc === null || vc === void 0 ? void 0 : vc.shouldPersistContextChangesImmediately)
|
|
113
|
+
if ((vc === null || vc === void 0 ? void 0 : vc.shouldPersistContextChangesImmediately) ||
|
|
114
|
+
(options === null || options === void 0 ? void 0 : options.shouldPersistContextChangesImmediately)) {
|
|
114
115
|
await this.sm.updateContext(Object.assign({}, updates));
|
|
115
116
|
}
|
|
116
117
|
}
|
|
@@ -28,7 +28,10 @@ export interface CalendarTool extends AbstractViewController<Card> {
|
|
|
28
28
|
handleUpdateContext(context: CalendarToolBeltContext): Promise<void> | void;
|
|
29
29
|
load?: () => Promise<void> | void;
|
|
30
30
|
}
|
|
31
|
-
export
|
|
31
|
+
export interface UpdateCalendarContextOptions {
|
|
32
|
+
shouldPersistContextChangesImmediately?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare type UpdateCalendarToolBeltContextHandler = (context: Partial<CalendarToolBeltContext>, options?: UpdateCalendarContextOptions) => Promise<void>;
|
|
32
35
|
export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltContext;
|
|
33
36
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
34
37
|
export interface CalendarToolOptions {
|
|
@@ -38,7 +38,8 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
38
38
|
private handleClick;
|
|
39
39
|
private getDraftEvent;
|
|
40
40
|
private removeDraftEvent;
|
|
41
|
-
private
|
|
41
|
+
private addDraftEventFromClick;
|
|
42
|
+
addDraftEvent(event: Event): Promise<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent | UpdateEvent | undefined>;
|
|
42
43
|
getIsSwappingEvent(): boolean;
|
|
43
44
|
private swapEvent;
|
|
44
45
|
updateEvent(id: string, updates: Partial<UpdateEvent>): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
|
|
@@ -38,13 +38,13 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
38
38
|
}
|
|
39
39
|
async handleDropEvent(options) {
|
|
40
40
|
var _a;
|
|
41
|
-
const { event, blockUpdates,
|
|
41
|
+
const { event, blockUpdates, newPersonId, newStartDateTimeMs } = options;
|
|
42
42
|
const updates = {};
|
|
43
43
|
if (newStartDateTimeMs) {
|
|
44
44
|
updates.startDateTimeMs = newStartDateTimeMs;
|
|
45
45
|
}
|
|
46
|
-
if (
|
|
47
|
-
updates.target = Object.assign(Object.assign({}, event.target), { personId:
|
|
46
|
+
if (newPersonId) {
|
|
47
|
+
updates.target = Object.assign(Object.assign({}, event.target), { personId: newPersonId });
|
|
48
48
|
}
|
|
49
49
|
if (blockUpdates) {
|
|
50
50
|
updates.timeBlocks = [...event.timeBlocks];
|
|
@@ -77,7 +77,7 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
77
77
|
}
|
|
78
78
|
const draft = this.getDraftEvent();
|
|
79
79
|
if (!draft) {
|
|
80
|
-
await this.
|
|
80
|
+
await this.addDraftEventFromClick(options);
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
83
|
await this.removeDraftEvent(draft.id);
|
|
@@ -98,15 +98,27 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
98
98
|
}
|
|
99
99
|
catch (_c) { }
|
|
100
100
|
}
|
|
101
|
-
async
|
|
102
|
-
const {
|
|
103
|
-
const
|
|
104
|
-
|
|
101
|
+
async addDraftEventFromClick(options) {
|
|
102
|
+
const { personId, dateTimeMs } = options;
|
|
103
|
+
const event = Object.assign({}, draftGenerator_1.default.generate(dateTimeMs !== null && dateTimeMs !== void 0 ? dateTimeMs : 0, personId !== null && personId !== void 0 ? personId : '**missing**'));
|
|
104
|
+
//@ts-ignore
|
|
105
|
+
delete event.id;
|
|
106
|
+
return await this.addDraftEvent(event);
|
|
107
|
+
}
|
|
108
|
+
async addDraftEvent(event) {
|
|
109
|
+
if (event.id) {
|
|
110
|
+
throw new schema_1.SchemaError({
|
|
111
|
+
code: 'UNEXPECTED_PARAMETERS',
|
|
112
|
+
parameters: ['id'],
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
event.id = draftGenerator_1.default.generateId();
|
|
105
116
|
this.addEvent(event);
|
|
106
117
|
this.selectEvent(event.id);
|
|
107
118
|
const draftAddedPromise = this.draftAddedHandler(event);
|
|
108
|
-
await this.persist(event);
|
|
119
|
+
const saved = await this.persist(event);
|
|
109
120
|
await draftAddedPromise;
|
|
121
|
+
return saved;
|
|
110
122
|
}
|
|
111
123
|
getIsSwappingEvent() {
|
|
112
124
|
return this.isSwapping;
|
|
@@ -159,12 +171,14 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
159
171
|
else {
|
|
160
172
|
super.updateEvent(saved.id, { isBusy, error: undefined });
|
|
161
173
|
}
|
|
174
|
+
return saved;
|
|
162
175
|
}
|
|
163
176
|
catch (err) {
|
|
164
177
|
if (this.hasEvent(id)) {
|
|
165
178
|
super.updateEvent(id, { error: err, isBusy: false });
|
|
166
179
|
}
|
|
167
180
|
}
|
|
181
|
+
return event;
|
|
168
182
|
}
|
|
169
183
|
getPeople() {
|
|
170
184
|
const people = super.getPeople();
|
|
@@ -329,8 +329,8 @@ class RepeatingControlsListViewController extends heartwood_view_controllers_1.A
|
|
|
329
329
|
return this.Controller('calendar', {
|
|
330
330
|
onClick: async (options) => {
|
|
331
331
|
var _a;
|
|
332
|
-
if (options.
|
|
333
|
-
this.changeCalendarSelectedDate(options.
|
|
332
|
+
if (options.dateTimeMs) {
|
|
333
|
+
this.changeCalendarSelectedDate(options.dateTimeMs);
|
|
334
334
|
(_a = this.didChangeRepeating) === null || _a === void 0 ? void 0 : _a.call(this, this.repeating);
|
|
335
335
|
}
|
|
336
336
|
},
|