@event-calendar/angular 0.0.0-stage → 5.22.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/README.md +80 -2
- package/dist/index.d.ts +43 -0
- package/dist/index.js +172 -0
- package/index.css +1 -0
- package/package.json +41 -3
package/README.md
CHANGED
|
@@ -1,3 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# EventCalendar for Angular
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Angular component of [EventCalendar](https://github.com/vkurko/calendar), a full-sized drag & drop JavaScript event calendar with resource & timeline views.
|
|
4
|
+
|
|
5
|
+
See the [demo](https://vkurko.github.io/calendar/) and the [documentation](https://github.com/vkurko/calendar#readme) of all options and methods.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
The first step is to install the EventCalendar `angular` package:
|
|
9
|
+
```bash
|
|
10
|
+
npm install --save-dev @event-calendar/angular
|
|
11
|
+
```
|
|
12
|
+
This package provides the `EventCalendar` component and the `EcContent` directive, as well as plugins for various views. You must use at least one plugin that provides a view. The following plugins are currently available:
|
|
13
|
+
|
|
14
|
+
* `DayGrid`
|
|
15
|
+
* `List`
|
|
16
|
+
* `ResourceTimeline`
|
|
17
|
+
* `ResourceTimeGrid`
|
|
18
|
+
* `TimeGrid`
|
|
19
|
+
* `Interaction` (doesn't provide a view)
|
|
20
|
+
|
|
21
|
+
Then in your Angular component, use the calendar like this:
|
|
22
|
+
```ts
|
|
23
|
+
import {Component, signal} from '@angular/core';
|
|
24
|
+
import {EventCalendar, EcContent, TimeGrid, type Calendar} from '@event-calendar/angular';
|
|
25
|
+
|
|
26
|
+
@Component({
|
|
27
|
+
selector: 'app-root',
|
|
28
|
+
imports: [EventCalendar, EcContent],
|
|
29
|
+
template: `<event-calendar [plugins]="plugins" [options]="options()"/>`
|
|
30
|
+
})
|
|
31
|
+
export class App {
|
|
32
|
+
plugins = [TimeGrid];
|
|
33
|
+
options = signal<Calendar.Options>({
|
|
34
|
+
view: 'timeGridWeek',
|
|
35
|
+
events: [
|
|
36
|
+
// your list of events
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
And import the styles in the global stylesheet of your application:
|
|
42
|
+
```css
|
|
43
|
+
@import '@event-calendar/angular/index.css';
|
|
44
|
+
```
|
|
45
|
+
All [options](https://github.com/vkurko/calendar#options) are passed as one object. To change them, pass a new object: the calendar is updated with the options that are different in it.
|
|
46
|
+
|
|
47
|
+
The calendar is destroyed gracefully when the component containing it is destroyed.
|
|
48
|
+
|
|
49
|
+
### Rendering content with templates
|
|
50
|
+
The following options can be given as templates with the `ecContent` directive:
|
|
51
|
+
|
|
52
|
+
* [allDayContent](https://github.com/vkurko/calendar#alldaycontent)
|
|
53
|
+
* [dayCellContent](https://github.com/vkurko/calendar#daycellcontent)
|
|
54
|
+
* [eventContent](https://github.com/vkurko/calendar#eventcontent)
|
|
55
|
+
* [moreLinkContent](https://github.com/vkurko/calendar#morelinkcontent)
|
|
56
|
+
* [noEventsContent](https://github.com/vkurko/calendar#noeventscontent)
|
|
57
|
+
* [resourceLabelContent](https://github.com/vkurko/calendar#resourcelabelcontent)
|
|
58
|
+
* [weekNumberContent](https://github.com/vkurko/calendar#weeknumbercontent)
|
|
59
|
+
* the `content` property of [customButtons](https://github.com/vkurko/calendar#custombuttons): the template is named `customButton` followed by the name of the button with the first letter capitalized
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<event-calendar [plugins]="plugins" [options]="options()">
|
|
63
|
+
<ng-template ecContent="eventContent" let-event="event" let-timeText="timeText">
|
|
64
|
+
<app-event-body [event]="event" [time]="timeText"/>
|
|
65
|
+
</ng-template>
|
|
66
|
+
<ng-template ecContent="customButtonFilter">
|
|
67
|
+
<input [(ngModel)]="query">
|
|
68
|
+
</ng-template>
|
|
69
|
+
</event-calendar>
|
|
70
|
+
```
|
|
71
|
+
The variables of the template are described in the documentation of each option, as the argument of its function.
|
|
72
|
+
|
|
73
|
+
### Calling methods in Angular
|
|
74
|
+
The [methods](https://github.com/vkurko/calendar#methods) of the calendar are the methods of the component:
|
|
75
|
+
```html
|
|
76
|
+
<event-calendar #calendar [plugins]="plugins" [options]="options()"/>
|
|
77
|
+
<button (click)="calendar.next()">Next</button>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TemplateRef } from '@angular/core';
|
|
2
|
+
import { type Calendar } from '@event-calendar/core';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
export * from '@event-calendar/core';
|
|
5
|
+
/** The arguments of the options whose content can be rendered by a template */
|
|
6
|
+
export interface ContentContext {
|
|
7
|
+
allDayContent: Calendar.AllDayContentArg;
|
|
8
|
+
dayCellContent: Calendar.DayCellContentArg;
|
|
9
|
+
eventContent: Calendar.EventContentInfo;
|
|
10
|
+
moreLinkContent: Calendar.MoreLinkInfo;
|
|
11
|
+
noEventsContent: {};
|
|
12
|
+
resourceLabelContent: Calendar.ResourceLabelInfo;
|
|
13
|
+
weekNumberContent: Calendar.WeekNumberContentArg;
|
|
14
|
+
}
|
|
15
|
+
/** The name of a content option, or of a toolbar item: `customButton` followed by its name with the first letter capitalized */
|
|
16
|
+
export type ContentName = keyof ContentContext | `customButton${string}`;
|
|
17
|
+
type Context<K> = K extends keyof ContentContext ? ContentContext[K] & {
|
|
18
|
+
$implicit: ContentContext[K];
|
|
19
|
+
} : {};
|
|
20
|
+
/**
|
|
21
|
+
* A template that renders the content of the option with the given name, inside the same element:
|
|
22
|
+
*
|
|
23
|
+
* <ng-template ecContent="eventContent" let-event="event" let-timeText="timeText">...</ng-template>
|
|
24
|
+
*/
|
|
25
|
+
export declare class EcContent<K extends ContentName> {
|
|
26
|
+
readonly name: import("@angular/core").InputSignal<K>;
|
|
27
|
+
readonly template: TemplateRef<Context<K>>;
|
|
28
|
+
static ngTemplateContextGuard<K extends ContentName>(directive: EcContent<K>, context: unknown): context is Context<K>;
|
|
29
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<EcContent<any>, never>;
|
|
30
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<EcContent<any>, "ng-template[ecContent]", never, { "name": { "alias": "ecContent"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
31
|
+
}
|
|
32
|
+
/** The calendar. Its methods are available on the component after it is rendered. */
|
|
33
|
+
export declare class EventCalendar {
|
|
34
|
+
#private;
|
|
35
|
+
readonly plugins: import("@angular/core").InputSignal<object[]>;
|
|
36
|
+
readonly options: import("@angular/core").InputSignal<Calendar.Options>;
|
|
37
|
+
readonly templates: import("@angular/core").Signal<readonly EcContent<ContentName>[]>;
|
|
38
|
+
constructor();
|
|
39
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<EventCalendar, never>;
|
|
40
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<EventCalendar, "event-calendar", never, { "plugins": { "alias": "plugins"; "required": true; "isSignal": true; }; "options": { "alias": "options"; "required": false; "isSignal": true; }; }, {}, ["templates"], never, true, never>;
|
|
41
|
+
}
|
|
42
|
+
export interface EventCalendar extends Calendar {
|
|
43
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { afterNextRender, ChangeDetectionStrategy, Component, contentChildren, DestroyRef, Directive, effect, ElementRef, inject, input, NgZone, TemplateRef, untracked, ViewContainerRef } from '@angular/core';
|
|
2
|
+
import { createCalendar, destroyCalendar } from '@event-calendar/core';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
export * from '@event-calendar/core';
|
|
5
|
+
// Callbacks that the calendar only calls, they are run inside the Angular zone
|
|
6
|
+
const CALLBACKS = ('dateClick datesSet eventAllUpdated eventClick eventDidMount eventDragStart eventDragStop eventDrop ' +
|
|
7
|
+
'eventMouseEnter eventMouseLeave eventResize eventResizeStart eventResizeStop loading noEventsClick ' +
|
|
8
|
+
'resourceExpand resourceLabelDidMount select unselect viewDidMount').split(' ');
|
|
9
|
+
/**
|
|
10
|
+
* A template that renders the content of the option with the given name, inside the same element:
|
|
11
|
+
*
|
|
12
|
+
* <ng-template ecContent="eventContent" let-event="event" let-timeText="timeText">...</ng-template>
|
|
13
|
+
*/
|
|
14
|
+
export class EcContent {
|
|
15
|
+
name = input.required({ ...(ngDevMode ? { debugName: "name" } : /* istanbul ignore next */ {}), alias: 'ecContent' });
|
|
16
|
+
template = inject(TemplateRef);
|
|
17
|
+
static ngTemplateContextGuard(directive, context) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: EcContent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
21
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.3.0", type: EcContent, isStandalone: true, selector: "ng-template[ecContent]", inputs: { name: { classPropertyName: "name", publicName: "ecContent", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0 });
|
|
22
|
+
}
|
|
23
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: EcContent, decorators: [{
|
|
24
|
+
type: Directive,
|
|
25
|
+
args: [{ selector: 'ng-template[ecContent]' }]
|
|
26
|
+
}], propDecorators: { name: [{ type: i0.Input, args: [{ isSignal: true, alias: "ecContent", required: true }] }] } });
|
|
27
|
+
/** The calendar. Its methods are available on the component after it is rendered. */
|
|
28
|
+
export class EventCalendar {
|
|
29
|
+
plugins = input.required(/* @ts-ignore */
|
|
30
|
+
...(ngDevMode ? [{ debugName: "plugins" }] : /* istanbul ignore next */ []));
|
|
31
|
+
options = input({}, /* @ts-ignore */
|
|
32
|
+
...(ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []));
|
|
33
|
+
templates = contentChildren(EcContent, /* @ts-ignore */
|
|
34
|
+
...(ngDevMode ? [{ debugName: "templates" }] : /* istanbul ignore next */ []));
|
|
35
|
+
#el = inject(ElementRef).nativeElement;
|
|
36
|
+
#views = inject(ViewContainerRef);
|
|
37
|
+
#zone = inject(NgZone);
|
|
38
|
+
#calendar;
|
|
39
|
+
// The options given to the calendar and the functions among them, which stay the same when the options change
|
|
40
|
+
#current = {};
|
|
41
|
+
#stable = {};
|
|
42
|
+
#outlets = new Map();
|
|
43
|
+
#scheduled = false;
|
|
44
|
+
constructor() {
|
|
45
|
+
afterNextRender(() => {
|
|
46
|
+
this.#current = untracked(() => this.#collect());
|
|
47
|
+
this.#calendar = this.#zone.runOutsideAngular(() => createCalendar(this.#el, untracked(this.plugins), this.#current));
|
|
48
|
+
Object.assign(this, this.#calendar);
|
|
49
|
+
});
|
|
50
|
+
effect(() => {
|
|
51
|
+
let next = this.#collect();
|
|
52
|
+
let calendar = this.#calendar;
|
|
53
|
+
if (calendar) {
|
|
54
|
+
// Set the options that did change
|
|
55
|
+
let prev = this.#current;
|
|
56
|
+
this.#current = next;
|
|
57
|
+
this.#zone.runOutsideAngular(() => {
|
|
58
|
+
for (let name in { ...prev, ...next }) {
|
|
59
|
+
if (prev[name] !== next[name]) {
|
|
60
|
+
calendar.setOption(name, next[name]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
inject(DestroyRef).onDestroy(() => {
|
|
67
|
+
if (this.#calendar) {
|
|
68
|
+
destroyCalendar(this.#calendar);
|
|
69
|
+
this.#calendar = undefined;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** Create the options of the calendar from the given options and the templates */
|
|
74
|
+
#collect() {
|
|
75
|
+
let options = { ...this.options() };
|
|
76
|
+
for (let name of CALLBACKS) {
|
|
77
|
+
if (typeof options[name] == 'function') {
|
|
78
|
+
options[name] = this.#stable[name] ??= (...args) => this.#zone.run(() => this.options()[name]?.(...args));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (let directive of this.templates()) {
|
|
82
|
+
let name = directive.name();
|
|
83
|
+
if (name.startsWith('customButton')) {
|
|
84
|
+
// The template of a toolbar item
|
|
85
|
+
let button = name[12].toLowerCase() + name.slice(13);
|
|
86
|
+
let item = this.#stable[name] ??= {};
|
|
87
|
+
if (!item.to || item.from !== options['customButtons']) {
|
|
88
|
+
item.from = options['customButtons'];
|
|
89
|
+
item.to = { ...item.from, [button]: { ...item.from?.[button], content: this.#content(name) } };
|
|
90
|
+
}
|
|
91
|
+
options['customButtons'] = item.to;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
options[name] = this.#stable['content:' + name] ??= this.#content(name);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return options;
|
|
98
|
+
}
|
|
99
|
+
/** Create the content function for the calendar, which returns the function that receives the element */
|
|
100
|
+
#content(name) {
|
|
101
|
+
return (arg = {}) => (el) => {
|
|
102
|
+
let outlet = this.#outlets.get(el);
|
|
103
|
+
if (outlet) {
|
|
104
|
+
Object.assign(outlet, { name, arg, live: true, changed: true });
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
this.#outlets.set(el, outlet = { name, arg, live: true, changed: true });
|
|
108
|
+
}
|
|
109
|
+
this.#schedule();
|
|
110
|
+
let current = outlet;
|
|
111
|
+
return () => {
|
|
112
|
+
current.live = false;
|
|
113
|
+
this.#schedule();
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Render the templates in one go and inside the Angular zone, so that the events inside them are detected.
|
|
119
|
+
* It is done in a microtask, which is before the calendar measures the content.
|
|
120
|
+
*/
|
|
121
|
+
#schedule() {
|
|
122
|
+
if (!this.#scheduled) {
|
|
123
|
+
this.#scheduled = true;
|
|
124
|
+
queueMicrotask(() => {
|
|
125
|
+
this.#scheduled = false;
|
|
126
|
+
this.#zone.run(() => this.#render());
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
#render() {
|
|
131
|
+
let templates = untracked(this.templates);
|
|
132
|
+
for (let [el, outlet] of this.#outlets) {
|
|
133
|
+
let { name, arg, view } = outlet;
|
|
134
|
+
let template = outlet.live
|
|
135
|
+
? templates.find(directive => directive.name() == name)?.template
|
|
136
|
+
: undefined;
|
|
137
|
+
if (view && outlet.template != template) {
|
|
138
|
+
view.destroy();
|
|
139
|
+
view = undefined;
|
|
140
|
+
}
|
|
141
|
+
if (!template) {
|
|
142
|
+
// The element is no longer used for the content of a template
|
|
143
|
+
this.#outlets.delete(el);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
let context = { ...arg, $implicit: arg };
|
|
147
|
+
if (view) {
|
|
148
|
+
if (outlet.changed) {
|
|
149
|
+
Object.assign(view.context, context);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// The element can still hold the content rendered by the calendar
|
|
154
|
+
el.textContent = '';
|
|
155
|
+
view = this.#views.createEmbeddedView(template, context);
|
|
156
|
+
el.append(...view.rootNodes);
|
|
157
|
+
}
|
|
158
|
+
outlet.view = view;
|
|
159
|
+
outlet.template = template;
|
|
160
|
+
if (outlet.changed) {
|
|
161
|
+
outlet.changed = false;
|
|
162
|
+
view.detectChanges();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: EventCalendar, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
167
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.3.0", type: EventCalendar, isStandalone: true, selector: "event-calendar", inputs: { plugins: { classPropertyName: "plugins", publicName: "plugins", isSignal: true, isRequired: true, transformFunction: null }, options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: false, transformFunction: null } }, queries: [{ propertyName: "templates", predicate: EcContent, isSignal: true }], ngImport: i0, template: '', isInline: true, styles: [":host { display: block; }"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
168
|
+
}
|
|
169
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: EventCalendar, decorators: [{
|
|
170
|
+
type: Component,
|
|
171
|
+
args: [{ selector: 'event-calendar', template: '', changeDetection: ChangeDetectionStrategy.OnPush, styles: [":host { display: block; }"] }]
|
|
172
|
+
}], ctorParameters: () => [], propDecorators: { plugins: [{ type: i0.Input, args: [{ isSignal: true, alias: "plugins", required: true }] }], options: [{ type: i0.Input, args: [{ isSignal: true, alias: "options", required: false }] }], templates: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => EcContent), { isSignal: true }] }] } });
|
package/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import '@event-calendar/core/index.css';
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@event-calendar/angular",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "5.22.0",
|
|
4
|
+
"title": "Event Calendar Angular component",
|
|
5
|
+
"description": "Angular component of the full-sized drag & drop event calendar with resource & timeline views",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"calendar",
|
|
8
|
+
"event",
|
|
9
|
+
"resource",
|
|
10
|
+
"timeline",
|
|
11
|
+
"full-sized",
|
|
12
|
+
"angular"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://vkurko.github.io/calendar/",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/vkurko/calendar.git",
|
|
18
|
+
"directory": "packages/angular"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"index.css"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": [
|
|
27
|
+
"*.css"
|
|
28
|
+
],
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./index.css": "./index.css",
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@event-calendar/core": "~5.22.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@angular/core": ">=20"
|
|
43
|
+
}
|
|
6
44
|
}
|