@sprucelabs/spruce-calendar-components 20.0.1 → 20.1.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.d.ts +2 -0
- package/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.js +4 -1
- package/build/esm/types/calendar.types.d.ts +2 -0
- package/build/esm/viewControllers/Calendar.vc.d.ts +1 -0
- package/build/esm/viewControllers/Calendar.vc.js +9 -4
- package/build/esm/viewControllers/EventControlsCard.vc.d.ts +5 -1
- package/build/esm/viewControllers/EventControlsCard.vc.js +13 -3
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.d.ts +2 -0
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.js +4 -1
- package/build/types/calendar.types.d.ts +2 -0
- package/build/viewControllers/Calendar.vc.d.ts +1 -0
- package/build/viewControllers/Calendar.vc.js +9 -4
- package/build/viewControllers/EventControlsCard.vc.d.ts +5 -1
- package/build/viewControllers/EventControlsCard.vc.js +13 -3
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SpruceSchemas, ToolBeltState, ViewControllerId } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { CalendarTool, CalendarToolBeltContext, CalendarToolBeltStateMachine, GetPersonFromEventHandler } from '../../types/calendar.types';
|
|
3
|
+
import EventControlsCardViewController from '../../viewControllers/EventControlsCard.vc';
|
|
3
4
|
declare type Tool = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.ToolBeltTool;
|
|
4
5
|
export declare type AddToolOptions = Omit<Tool, 'card'> & {
|
|
5
6
|
cardVcId: ViewControllerId;
|
|
@@ -26,6 +27,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
|
|
|
26
27
|
removeTool(id: string): void;
|
|
27
28
|
getPendingContextChanges(): Partial<CalendarToolBeltContext>;
|
|
28
29
|
getVcForTool(toolId: string): CalendarTool | undefined;
|
|
30
|
+
getControlsVc(): EventControlsCardViewController;
|
|
29
31
|
destroy(): Promise<void>;
|
|
30
32
|
}
|
|
31
33
|
export {};
|
|
@@ -22,7 +22,7 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
22
22
|
this.sm = sm;
|
|
23
23
|
this.toolBeltVc = sm.getToolBeltVc();
|
|
24
24
|
this._isLoaded = true;
|
|
25
|
-
this.controlsVc = sm.Controller('calendar.event-controls-card', Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')));
|
|
25
|
+
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 }));
|
|
26
26
|
this.toolBeltVc.clearTools();
|
|
27
27
|
this.toolBeltVc.setStickyTool({
|
|
28
28
|
card: this.controlsVc.render(),
|
|
@@ -152,6 +152,9 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
152
152
|
var _a;
|
|
153
153
|
return (_a = this.vcs.find((v) => v.toolId === toolId)) === null || _a === void 0 ? void 0 : _a.vc;
|
|
154
154
|
}
|
|
155
|
+
getControlsVc() {
|
|
156
|
+
return this.controlsVc;
|
|
157
|
+
}
|
|
155
158
|
destroy() {
|
|
156
159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
160
|
yield this.sm.off('did-update-context', this.handleDidUpdateContext);
|
|
@@ -18,6 +18,7 @@ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
|
18
18
|
export declare type CalendarToolBeltContext = SkillViewControllerLoadOptions & {
|
|
19
19
|
event: CalendarEvent;
|
|
20
20
|
calendarVc: CalendarViewController;
|
|
21
|
+
cancelEvent: CancelEventHandler;
|
|
21
22
|
};
|
|
22
23
|
export declare type CalendarToolBeltStateMachine = ToolBeltStateMachine<CalendarToolBeltContext>;
|
|
23
24
|
export interface RemoteCalendarTool extends CalendarTool {
|
|
@@ -35,6 +36,7 @@ export declare type UpdateCalendarToolBeltContextHandler = (context: Partial<Cal
|
|
|
35
36
|
export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltContext;
|
|
36
37
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
37
38
|
export declare type GetHasPendingContextChangesHandler = () => boolean;
|
|
39
|
+
export declare type CancelEventHandler = (eventId: string) => boolean | Promise<boolean | void> | void;
|
|
38
40
|
export interface CalendarToolOptions {
|
|
39
41
|
updateContext: UpdateCalendarToolBeltContextHandler;
|
|
40
42
|
getContext: GetCalendarToolBeltContextHandler;
|
|
@@ -30,6 +30,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
30
30
|
private eventSwappedHandler?;
|
|
31
31
|
private dropEventHandler?;
|
|
32
32
|
private isSwapping;
|
|
33
|
+
private lastSwappedId?;
|
|
33
34
|
constructor(options: ViewControllerOptions & CalendarViewControllerOptions);
|
|
34
35
|
private handleDropEvent;
|
|
35
36
|
getCalendarVc(): this;
|
|
@@ -186,10 +186,15 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
186
186
|
if (!saved) {
|
|
187
187
|
return;
|
|
188
188
|
}
|
|
189
|
-
if (
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
189
|
+
if (id !== saved.id) {
|
|
190
|
+
if (this.lastSwappedId === id) {
|
|
191
|
+
this.updateEvent(saved.id, saved);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
this.lastSwappedId = id;
|
|
195
|
+
yield this.swapEvent(event, saved);
|
|
196
|
+
yield ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, saved));
|
|
197
|
+
}
|
|
193
198
|
}
|
|
194
199
|
else {
|
|
195
200
|
_super.updateEvent.call(this, saved.id, { isBusy, error: undefined });
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import { CalendarTool, CalendarToolOptions } from '../types/calendar.types';
|
|
2
|
+
import { CalendarTool, CalendarToolOptions, CancelEventHandler } from '../types/calendar.types';
|
|
3
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
4
|
export interface EventControlsCardOptions extends CalendarToolOptions {
|
|
5
5
|
onCancel: () => Promise<void | boolean> | void | boolean;
|
|
6
|
+
onCancelEvent: CancelEventHandler;
|
|
6
7
|
onSave: () => Promise<void | boolean> | void | boolean;
|
|
7
8
|
}
|
|
8
9
|
export default class EventControlsCardViewController extends AbstractViewController<Card> implements CalendarTool {
|
|
@@ -12,10 +13,13 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
12
13
|
private cancelHandler;
|
|
13
14
|
private getHasPendingContextChangesHandler;
|
|
14
15
|
private getContext;
|
|
16
|
+
private cancelEventHandler;
|
|
15
17
|
constructor(options: ViewControllerOptions & EventControlsCardOptions);
|
|
18
|
+
private CardVc;
|
|
16
19
|
private handleClickCancel;
|
|
17
20
|
private handleClickSave;
|
|
18
21
|
handleUpdateContext(): void;
|
|
22
|
+
private optionallyDropInCancelButton;
|
|
19
23
|
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
20
24
|
}
|
|
21
25
|
export {};
|
|
@@ -13,17 +13,23 @@ import draftEventGenerator from '../utilities/draftGenerator.js';
|
|
|
13
13
|
export default class EventControlsCardViewController extends AbstractViewController {
|
|
14
14
|
constructor(options) {
|
|
15
15
|
super(options);
|
|
16
|
-
const { onSave, onCancel, getHasPendingContextChanges, getContext } = assertOptions(options, [
|
|
16
|
+
const { onSave, onCancel, getHasPendingContextChanges, getContext, onCancelEvent, } = assertOptions(options, [
|
|
17
17
|
'onCancel',
|
|
18
18
|
'onSave',
|
|
19
|
+
'onCancelEvent',
|
|
19
20
|
'getHasPendingContextChanges',
|
|
20
21
|
'getContext',
|
|
21
22
|
]);
|
|
22
23
|
this.saveHandler = onSave;
|
|
23
24
|
this.cancelHandler = onCancel;
|
|
25
|
+
this.cancelEventHandler = onCancelEvent;
|
|
24
26
|
this.getHasPendingContextChangesHandler = getHasPendingContextChanges;
|
|
25
27
|
this.getContext = getContext;
|
|
26
|
-
this.cardVc = this.
|
|
28
|
+
this.cardVc = this.CardVc();
|
|
29
|
+
this.optionallyDropInCancelButton();
|
|
30
|
+
}
|
|
31
|
+
CardVc() {
|
|
32
|
+
return this.Controller('card', {
|
|
27
33
|
footer: {
|
|
28
34
|
isEnabled: false,
|
|
29
35
|
isBusy: false,
|
|
@@ -58,13 +64,16 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
58
64
|
});
|
|
59
65
|
}
|
|
60
66
|
handleUpdateContext() {
|
|
61
|
-
var _a;
|
|
62
67
|
if (this.getHasPendingContextChangesHandler()) {
|
|
63
68
|
this.cardVc.enableFooter();
|
|
64
69
|
}
|
|
65
70
|
else {
|
|
66
71
|
this.cardVc.disableFooter();
|
|
67
72
|
}
|
|
73
|
+
this.optionallyDropInCancelButton();
|
|
74
|
+
}
|
|
75
|
+
optionallyDropInCancelButton() {
|
|
76
|
+
var _a;
|
|
68
77
|
const { event } = this.getContext();
|
|
69
78
|
if ((event === null || event === void 0 ? void 0 : event.id) && !draftEventGenerator.isDraftId(event.id)) {
|
|
70
79
|
this.cardVc.setBody({
|
|
@@ -75,6 +84,7 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
75
84
|
id: 'cancel-event',
|
|
76
85
|
label: `Cancel ${(_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'event'}`,
|
|
77
86
|
type: 'destructive',
|
|
87
|
+
onClick: () => this.cancelEventHandler(this.getContext().event.id),
|
|
78
88
|
},
|
|
79
89
|
],
|
|
80
90
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SpruceSchemas, ToolBeltState, ViewControllerId } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { CalendarTool, CalendarToolBeltContext, CalendarToolBeltStateMachine, GetPersonFromEventHandler } from '../../types/calendar.types';
|
|
3
|
+
import EventControlsCardViewController from '../../viewControllers/EventControlsCard.vc';
|
|
3
4
|
declare type Tool = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.ToolBeltTool;
|
|
4
5
|
export declare type AddToolOptions = Omit<Tool, 'card'> & {
|
|
5
6
|
cardVcId: ViewControllerId;
|
|
@@ -26,6 +27,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
|
|
|
26
27
|
removeTool(id: string): void;
|
|
27
28
|
getPendingContextChanges(): Partial<CalendarToolBeltContext>;
|
|
28
29
|
getVcForTool(toolId: string): CalendarTool | undefined;
|
|
30
|
+
getControlsVc(): EventControlsCardViewController;
|
|
29
31
|
destroy(): Promise<void>;
|
|
30
32
|
}
|
|
31
33
|
export {};
|
|
@@ -17,7 +17,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
17
17
|
this.sm = sm;
|
|
18
18
|
this.toolBeltVc = sm.getToolBeltVc();
|
|
19
19
|
this._isLoaded = true;
|
|
20
|
-
this.controlsVc = sm.Controller('calendar.event-controls-card', Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')));
|
|
20
|
+
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 }));
|
|
21
21
|
this.toolBeltVc.clearTools();
|
|
22
22
|
this.toolBeltVc.setStickyTool({
|
|
23
23
|
card: this.controlsVc.render(),
|
|
@@ -130,6 +130,9 @@ class AbstractCalendarEventToolBeltState {
|
|
|
130
130
|
var _a;
|
|
131
131
|
return (_a = this.vcs.find((v) => v.toolId === toolId)) === null || _a === void 0 ? void 0 : _a.vc;
|
|
132
132
|
}
|
|
133
|
+
getControlsVc() {
|
|
134
|
+
return this.controlsVc;
|
|
135
|
+
}
|
|
133
136
|
async destroy() {
|
|
134
137
|
await this.sm.off('did-update-context', this.handleDidUpdateContext);
|
|
135
138
|
}
|
|
@@ -18,6 +18,7 @@ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
|
18
18
|
export declare type CalendarToolBeltContext = SkillViewControllerLoadOptions & {
|
|
19
19
|
event: CalendarEvent;
|
|
20
20
|
calendarVc: CalendarViewController;
|
|
21
|
+
cancelEvent: CancelEventHandler;
|
|
21
22
|
};
|
|
22
23
|
export declare type CalendarToolBeltStateMachine = ToolBeltStateMachine<CalendarToolBeltContext>;
|
|
23
24
|
export interface RemoteCalendarTool extends CalendarTool {
|
|
@@ -35,6 +36,7 @@ export declare type UpdateCalendarToolBeltContextHandler = (context: Partial<Cal
|
|
|
35
36
|
export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltContext;
|
|
36
37
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
37
38
|
export declare type GetHasPendingContextChangesHandler = () => boolean;
|
|
39
|
+
export declare type CancelEventHandler = (eventId: string) => boolean | Promise<boolean | void> | void;
|
|
38
40
|
export interface CalendarToolOptions {
|
|
39
41
|
updateContext: UpdateCalendarToolBeltContextHandler;
|
|
40
42
|
getContext: GetCalendarToolBeltContextHandler;
|
|
@@ -30,6 +30,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
30
30
|
private eventSwappedHandler?;
|
|
31
31
|
private dropEventHandler?;
|
|
32
32
|
private isSwapping;
|
|
33
|
+
private lastSwappedId?;
|
|
33
34
|
constructor(options: ViewControllerOptions & CalendarViewControllerOptions);
|
|
34
35
|
private handleDropEvent;
|
|
35
36
|
getCalendarVc(): this;
|
|
@@ -163,10 +163,15 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
163
163
|
if (!saved) {
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
if (id !== saved.id) {
|
|
167
|
+
if (this.lastSwappedId === id) {
|
|
168
|
+
this.updateEvent(saved.id, saved);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
this.lastSwappedId = id;
|
|
172
|
+
await this.swapEvent(event, saved);
|
|
173
|
+
await ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, saved));
|
|
174
|
+
}
|
|
170
175
|
}
|
|
171
176
|
else {
|
|
172
177
|
super.updateEvent(saved.id, { isBusy, error: undefined });
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import { CalendarTool, CalendarToolOptions } from '../types/calendar.types';
|
|
2
|
+
import { CalendarTool, CalendarToolOptions, CancelEventHandler } from '../types/calendar.types';
|
|
3
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
4
|
export interface EventControlsCardOptions extends CalendarToolOptions {
|
|
5
5
|
onCancel: () => Promise<void | boolean> | void | boolean;
|
|
6
|
+
onCancelEvent: CancelEventHandler;
|
|
6
7
|
onSave: () => Promise<void | boolean> | void | boolean;
|
|
7
8
|
}
|
|
8
9
|
export default class EventControlsCardViewController extends AbstractViewController<Card> implements CalendarTool {
|
|
@@ -12,10 +13,13 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
12
13
|
private cancelHandler;
|
|
13
14
|
private getHasPendingContextChangesHandler;
|
|
14
15
|
private getContext;
|
|
16
|
+
private cancelEventHandler;
|
|
15
17
|
constructor(options: ViewControllerOptions & EventControlsCardOptions);
|
|
18
|
+
private CardVc;
|
|
16
19
|
private handleClickCancel;
|
|
17
20
|
private handleClickSave;
|
|
18
21
|
handleUpdateContext(): void;
|
|
22
|
+
private optionallyDropInCancelButton;
|
|
19
23
|
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
20
24
|
}
|
|
21
25
|
export {};
|
|
@@ -9,17 +9,23 @@ const draftGenerator_1 = __importDefault(require("../utilities/draftGenerator"))
|
|
|
9
9
|
class EventControlsCardViewController extends heartwood_view_controllers_1.AbstractViewController {
|
|
10
10
|
constructor(options) {
|
|
11
11
|
super(options);
|
|
12
|
-
const { onSave, onCancel, getHasPendingContextChanges, getContext } = (0, schema_1.assertOptions)(options, [
|
|
12
|
+
const { onSave, onCancel, getHasPendingContextChanges, getContext, onCancelEvent, } = (0, schema_1.assertOptions)(options, [
|
|
13
13
|
'onCancel',
|
|
14
14
|
'onSave',
|
|
15
|
+
'onCancelEvent',
|
|
15
16
|
'getHasPendingContextChanges',
|
|
16
17
|
'getContext',
|
|
17
18
|
]);
|
|
18
19
|
this.saveHandler = onSave;
|
|
19
20
|
this.cancelHandler = onCancel;
|
|
21
|
+
this.cancelEventHandler = onCancelEvent;
|
|
20
22
|
this.getHasPendingContextChangesHandler = getHasPendingContextChanges;
|
|
21
23
|
this.getContext = getContext;
|
|
22
|
-
this.cardVc = this.
|
|
24
|
+
this.cardVc = this.CardVc();
|
|
25
|
+
this.optionallyDropInCancelButton();
|
|
26
|
+
}
|
|
27
|
+
CardVc() {
|
|
28
|
+
return this.Controller('card', {
|
|
23
29
|
footer: {
|
|
24
30
|
isEnabled: false,
|
|
25
31
|
isBusy: false,
|
|
@@ -50,13 +56,16 @@ class EventControlsCardViewController extends heartwood_view_controllers_1.Abstr
|
|
|
50
56
|
this.cardVc.disableFooter();
|
|
51
57
|
}
|
|
52
58
|
handleUpdateContext() {
|
|
53
|
-
var _a;
|
|
54
59
|
if (this.getHasPendingContextChangesHandler()) {
|
|
55
60
|
this.cardVc.enableFooter();
|
|
56
61
|
}
|
|
57
62
|
else {
|
|
58
63
|
this.cardVc.disableFooter();
|
|
59
64
|
}
|
|
65
|
+
this.optionallyDropInCancelButton();
|
|
66
|
+
}
|
|
67
|
+
optionallyDropInCancelButton() {
|
|
68
|
+
var _a;
|
|
60
69
|
const { event } = this.getContext();
|
|
61
70
|
if ((event === null || event === void 0 ? void 0 : event.id) && !draftGenerator_1.default.isDraftId(event.id)) {
|
|
62
71
|
this.cardVc.setBody({
|
|
@@ -67,6 +76,7 @@ class EventControlsCardViewController extends heartwood_view_controllers_1.Abstr
|
|
|
67
76
|
id: 'cancel-event',
|
|
68
77
|
label: `Cancel ${(_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'event'}`,
|
|
69
78
|
type: 'destructive',
|
|
79
|
+
onClick: () => this.cancelEventHandler(this.getContext().event.id),
|
|
70
80
|
},
|
|
71
81
|
],
|
|
72
82
|
},
|