@chaaanito/event-resource-calendar 1.0.1 → 1.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/README.md +64 -25
- package/jsconfig.json +12 -0
- package/package.json +17 -2
- package/src/event-resource.types.js +98 -0
- package/src/index.js +155 -524
- package/src/styles.css +171 -0
package/README.md
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
# EventResource
|
|
2
2
|
|
|
3
|
-
A lightweight, high-performance vanilla JavaScript resource calendar library. Features O(1) internal event mapping, extensible rich HTML layout renderers, holiday detection, and scroll freezing.
|
|
3
|
+
A lightweight, high-performance vanilla JavaScript resource calendar library. Features skeleton-first asynchronous rendering, O(1) internal event mapping, extensible rich HTML layout renderers, holiday detection, and scroll freezing.
|
|
4
4
|
|
|
5
5
|
# Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install event-resource-calendar
|
|
8
|
+
npm install @chaaanito/event-resource-calendar
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
# Quick Start
|
|
12
12
|
|
|
13
13
|
```javascript
|
|
14
|
-
import EventResource from "event-resource-calendar";
|
|
14
|
+
import EventResource from "@chaaanito/event-resource-calendar";
|
|
15
|
+
import "@chaaanito/event-resource-calendar/style.css"; // Required for grid structural styling
|
|
15
16
|
|
|
16
17
|
const calendar = new EventResource({
|
|
17
18
|
container: "#calendar-root",
|
|
@@ -50,27 +51,32 @@ Pass these properties into the `EventResource` constructor to customize your cal
|
|
|
50
51
|
|
|
51
52
|
| Property | Type | Default | Description |
|
|
52
53
|
| :---------------- | :------------- | :----------- | :-------------------------------------------------------------------- |
|
|
53
|
-
| **container** | `string\|Node` | _Required_ | CSS selector or DOM pointer mount node.
|
|
54
|
+
| **container** | `string\|Node` | _Required_ | CSS selector or explicit DOM pointer mount node. |
|
|
54
55
|
| **rooms** | `Array` | `[]` | Master source list establishing rows along the vertical plane. |
|
|
55
56
|
| **timeSlots** | `Array` | `[]` | Master source list defining columns mapped along the horizontal path. |
|
|
56
57
|
| **initialEvents** | `Array` | `[]` | In-memory event array populating coordinates on load. |
|
|
57
58
|
| **holidays** | `Array` | `[]` | Configuration identifying structural exceptions and global days. |
|
|
58
59
|
| **customButtons** | `Array` | `[]` | Extensible collections rendering specialized tool structures. |
|
|
59
|
-
| **showControls** | `boolean` | `false` | Visibility of structural management toolbars.
|
|
60
|
-
| **stickyHeaders** | `boolean` | `true` | Toggles CSS sticky double-axis tracking logic.
|
|
61
|
-
| **defaultView** | `string` | `'daily'` | Default presentation layout. Must be 'daily' or 'weekly'.
|
|
60
|
+
| **showControls** | `boolean` | `false` | Visibility of structural management toolbars (Datepicker, arrows). |
|
|
61
|
+
| **stickyHeaders** | `boolean` | `true` | Toggles CSS sticky double-axis tracking logic across layout headers. |
|
|
62
|
+
| **defaultView** | `string` | `'daily'` | Default presentation layout mode. Must be 'daily' or 'weekly'. |
|
|
62
63
|
| **defaultDate** | `Date\|string` | `new Date()` | Frame configuration locking starting lifecycle boundaries. |
|
|
63
64
|
|
|
64
65
|
### Callbacks & Renderers
|
|
65
66
|
|
|
66
|
-
| Property | Type | Description
|
|
67
|
-
| :----------------------- | :--------- |
|
|
68
|
-
| **onCellClick** | `Function` | Callback capturing clicks targeting empty coordinates.
|
|
69
|
-
| **onEventClick** | `Function` | Callback targeting allocated calendar card coordinates.
|
|
70
|
-
| **fetchEvents** | `Function` | Async method
|
|
71
|
-
| **
|
|
72
|
-
| **
|
|
73
|
-
| **
|
|
67
|
+
| Property | Type | Description |
|
|
68
|
+
| :----------------------- | :--------- | :--------------------------------------------------------------------------- |
|
|
69
|
+
| **onCellClick** | `Function` | Callback capturing clicks targeting empty coordinates. |
|
|
70
|
+
| **onEventClick** | `Function` | Callback targeting allocated calendar card coordinates. |
|
|
71
|
+
| **fetchEvents** | `Function` | Async method resolving to an array of `CalendarEvent` objects. |
|
|
72
|
+
| **fetchRooms** | `Function` | Async method resolving to an array of `CalendarRoom` objects dynamically. |
|
|
73
|
+
| **fetchTimeSlots** | `Function` | Async method resolving to an array of `TimeSlot` objects dynamically. |
|
|
74
|
+
| **fetchHolidays** | `Function` | Async method resolving to an array of `CalendarHoliday` objects dynamically. |
|
|
75
|
+
| **renderRoomHeader** | `Function` | HTML generator returning structural formatting strings for row slots. |
|
|
76
|
+
| **renderTimeSlotHeader** | `Function` | HTML generator returning structural formatting strings for column slots. |
|
|
77
|
+
| **renderEvent** | `Function` | HTML generator returning custom markup for individual event cards. |
|
|
78
|
+
|
|
79
|
+
---
|
|
74
80
|
|
|
75
81
|
## Data Models
|
|
76
82
|
|
|
@@ -92,7 +98,7 @@ Defines a timeline column structure partitioning the matrix grid workspace.
|
|
|
92
98
|
| :-------- | :--------------- | :---------------------------------------------------------- |
|
|
93
99
|
| **id** | `string\|number` | **Required.** Unique identifier for the chronological slot. |
|
|
94
100
|
| **label** | `string` | **Required.** Fallback timeline display text. |
|
|
95
|
-
| **[key]** | `any` | Optional
|
|
101
|
+
| **[key]** | `any` | Optional extensible properties (e.g., isLunchHour). |
|
|
96
102
|
|
|
97
103
|
### CalendarEvent
|
|
98
104
|
|
|
@@ -105,28 +111,61 @@ Represents an allocated timeline event mapped directly into a specific intersect
|
|
|
105
111
|
| **timeId** | `string\|number` | **Required.** Foreign key binding the item to a valid TimeSlot ID. |
|
|
106
112
|
| **title** | `string` | **Required.** Plain-text title injected inside the card element. |
|
|
107
113
|
| **color** | `string` | Optional CSS color value for the background card. Default: `#3b82f6`. |
|
|
108
|
-
| **[key]** | `any` | Optional custom meta data attributes.
|
|
114
|
+
| **[key]** | `any` | Optional custom meta data attributes parsed down to click payloads. |
|
|
115
|
+
|
|
116
|
+
### CalendarHoliday
|
|
117
|
+
|
|
118
|
+
Maps specific dates to holiday statuses, shifting backgrounds and appending context data.
|
|
119
|
+
|
|
120
|
+
| Property | Type | Description |
|
|
121
|
+
| :-------- | :--------------------- | :--------------------------------------------------------------------- |
|
|
122
|
+
| **date** | `string\|Date\|number` | **Required.** Parsable temporal timestamp mapping the milestone. |
|
|
123
|
+
| **name** | `string` | **Required.** Human-readable label injected into global notice badges. |
|
|
124
|
+
| **[key]** | `any` | Optional open-ended customer specific holiday data. |
|
|
125
|
+
|
|
126
|
+
---
|
|
109
127
|
|
|
110
128
|
## Interaction Payloads
|
|
111
129
|
|
|
112
|
-
When interacting with the grid, the library fires callbacks with contextual payloads.
|
|
130
|
+
When interacting with the grid, the library fires callbacks with comprehensive contextual payloads.
|
|
113
131
|
|
|
114
132
|
### ClickContextPayload (Empty Cell Click)
|
|
115
133
|
|
|
134
|
+
Shared universally across grid click response lifecycles.
|
|
135
|
+
|
|
116
136
|
| Property | Type | Description |
|
|
117
137
|
| :---------- | :------------- | :----------------------------------------------------------------- |
|
|
118
138
|
| **date** | `Date` | Chronological state baseline actively mounted inside the viewport. |
|
|
119
|
-
| **view** | `string` | Current structural mode index ('daily' or 'weekly').
|
|
120
|
-
| **holiday** | `Object\|null` | Associated holiday data object if applicable.
|
|
121
|
-
| **row** | `Object` | Track metadata coordinates (`index` and `data`).
|
|
122
|
-
| **col** | `Object` | Timeline metadata coordinates (`index` and `data`).
|
|
139
|
+
| **view** | `string` | Current structural mode index configuration ('daily' or 'weekly'). |
|
|
140
|
+
| **holiday** | `Object\|null` | Associated holiday data object if applicable to current date. |
|
|
141
|
+
| **row** | `Object` | Track metadata coordinates (`index` and `data` objects). |
|
|
142
|
+
| **col** | `Object` | Timeline metadata coordinates (`index` and `data` objects). |
|
|
123
143
|
| **cell** | `Object` | Target cell contents (`roomId`, `timeId`, and `events` array). |
|
|
124
144
|
|
|
125
145
|
### EventClickPayload (Event Card Click)
|
|
126
146
|
|
|
127
|
-
Inherits
|
|
147
|
+
Inherits all properties from `ClickContextPayload` and adds:
|
|
128
148
|
|
|
129
149
|
| Property | Type | Description |
|
|
130
150
|
| :-------------- | :----------- | :-------------------------------------------------------------------------- |
|
|
131
|
-
| **event** | `Object` | **Required.** The unique target event parameters
|
|
132
|
-
| **nativeEvent** | `MouseEvent` | **Required.** Raw browser click interaction data.
|
|
151
|
+
| **event** | `Object` | **Required.** The explicit, unique target event parameters clicked. |
|
|
152
|
+
| **nativeEvent** | `MouseEvent` | **Required.** Raw browser click interaction data used for element tracking. |
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Public API Methods
|
|
157
|
+
|
|
158
|
+
Once instantiated, the calendar instance exposes methods to control the grid programmatically.
|
|
159
|
+
|
|
160
|
+
| Method | Description |
|
|
161
|
+
| :------------------------- | :---------------------------------------------------------------------------------------------- |
|
|
162
|
+
| **`addEvent(event)`** | Injects a new event and performs an isolated, high-speed DOM append without layout thrashing. |
|
|
163
|
+
| **`removeEvent(eventId)`** | Purges a specific event by ID from memory and removes it from the UI instantly. |
|
|
164
|
+
| **`clearAllEvents()`** | Wipes all events from the board while preserving the layout skeleton rules. |
|
|
165
|
+
| **`setDate(newDate)`** | Jumps the calendar to a specific date. Automatically triggers `fetch` hooks if configured. |
|
|
166
|
+
| **`setView(newView)`** | Mutates the layout granularity between daily and weekly modes. |
|
|
167
|
+
| **`Maps(direction)`** | Steps the timeline forward or backward based on the current view multiplier. |
|
|
168
|
+
| **`forceRender()`** | Triggers a manual full data replenishment cycle, drawing the skeleton and resolving all asyncs. |
|
|
169
|
+
| **`destroy()`** | Unmounts the DOM, clears memory caches, and drops listener closures to prevent leaks. |
|
|
170
|
+
|
|
171
|
+
---
|
package/jsconfig.json
ADDED
package/package.json
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chaaanito/event-resource-calendar",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/chaaanito/event-resource-calendar.git"
|
|
7
|
+
},
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/chaaanito/event-resource-calendar/issues"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/chaaanito/event-resource-calendar#readme",
|
|
4
12
|
"type": "module",
|
|
5
13
|
"main": "src/index.js",
|
|
14
|
+
"types": "dist/types/index.d.ts",
|
|
15
|
+
"style": "src/styles.css",
|
|
6
16
|
"exports": {
|
|
7
|
-
".":
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/types/index.d.ts",
|
|
19
|
+
"import": "./src/index.js",
|
|
20
|
+
"default": "./src/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./style.css": "./src/styles.css"
|
|
8
23
|
}
|
|
9
24
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} CalendarRoom
|
|
3
|
+
* @description Defines a resource row within the calendar matrix grid layout.
|
|
4
|
+
* @property {string|number} id - REQUIRED: Unique identifier for the room or resource. Must be absolutely unique across all room rows.
|
|
5
|
+
* @property {string} name - REQUIRED: Fallback display title of the room/resource used if `renderRoomHeader` is omitted.
|
|
6
|
+
* @property {*} [key: string] - OPTIONAL: Any additional open-ended properties used for custom filtering or rich rendering templates.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {Object} TimeSlot
|
|
11
|
+
* @description Defines a timeline column structure partitioning the matrix grid workspace.
|
|
12
|
+
* @property {string|number} id - REQUIRED: Unique identifier for the chronological slot. Must be unique across all columns.
|
|
13
|
+
* @property {string} label - REQUIRED: Fallback timeline display text used if `renderTimeSlotHeader` is omitted.
|
|
14
|
+
* @property {*} [key: string] - OPTIONAL: Any additional extensible properties used for custom filtering or rich rendering templates.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {Object} CalendarEvent
|
|
19
|
+
* @description Represents an allocated timeline event mapped directly into a specific intersection cell.
|
|
20
|
+
* @property {string|number} id - REQUIRED: Unique identifier for the scheduled event element.
|
|
21
|
+
* @property {string|number} roomId - REQUIRED: Relational foreign key binding the item to a valid {@link CalendarRoom.id}.
|
|
22
|
+
* @property {string|number} timeId - REQUIRED: Relational foreign key binding the item to a valid {@link TimeSlot.id}.
|
|
23
|
+
* @property {string} title - REQUIRED: Plain-text title injected inside the DOM node element card.
|
|
24
|
+
* @property {string} [color='#3b82f6'] - OPTIONAL: Valid CSS color value (hex, rgb, hsl, keyword) for the background tracking card.
|
|
25
|
+
* @property {*} [key: string] - OPTIONAL: Custom meta data attributes parsed down to click event callback streams.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {Object} CalendarHoliday
|
|
30
|
+
* @description Maps specific dates to holiday statuses, shifting backgrounds and appending context data to interaction payloads.
|
|
31
|
+
* @property {string|Date|number} date - REQUIRED: Parsable temporal timestamp mapping the holiday milestone. Must be resolvable by `new Date()`.
|
|
32
|
+
* @property {string} name - REQUIRED: The human-readable label injected into global notice badges and cell descriptors.
|
|
33
|
+
* @property {*} [key: string] - OPTIONAL: Open-ended customer specific holiday data.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {Object} CustomButton
|
|
38
|
+
* @description Injectable client control appended directly onto the right-hand toolbar grouping matrix.
|
|
39
|
+
* @property {string} label - REQUIRED: Text descriptor rendered inside the interactive control button element frame.
|
|
40
|
+
* @property {function(MouseEvent): void} onClick - REQUIRED: Action handler fired immediately upon client interactions.
|
|
41
|
+
* @property {string} [className] - OPTIONAL: Space-delimited functional CSS style modifiers for custom visual overrides.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @typedef {Object} ClickContextPayload
|
|
46
|
+
* @description Consolidated operational telemetry shared universally across grid click response lifecycles.
|
|
47
|
+
* @property {Date} date - Chronological state baseline actively mounted inside the viewport template frame.
|
|
48
|
+
* @property {'daily'|'weekly'} view - Current structural mode index configuration.
|
|
49
|
+
* @property {CalendarHoliday|null} holiday - Associated holiday data object if the current frame falls on a configured day milestone.
|
|
50
|
+
* @property {Object} row - Track metadata coordinates.
|
|
51
|
+
* @property {number} row.index - Vertical index array placement coordinate.
|
|
52
|
+
* @property {CalendarRoom} row.data - Complete root object data context passed down from initialization.
|
|
53
|
+
* @property {Object} col - Timeline metadata coordinates.
|
|
54
|
+
* @property {number} col.index - Horizontal layout coordinate tracking indexes.
|
|
55
|
+
* @property {TimeSlot} col.data - Complete root chronological object parameters.
|
|
56
|
+
* @property {Object} cell - Operational target cell contents.
|
|
57
|
+
* @property {string|number} cell.roomId - Unique cell row lookup index.
|
|
58
|
+
* @property {string|number} cell.timeId - Unique cell column chronological coordinate index.
|
|
59
|
+
* @property {CalendarEvent[]} cell.events - Contextual array containing all events currently occupying this grid location.
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @typedef {Object} EventClickPayload
|
|
64
|
+
* @description Multi-layered payload shared exclusively with the `onEventClick` subscriber method.
|
|
65
|
+
* @extends ClickContextPayload
|
|
66
|
+
* @property {CalendarEvent} event - REQUIRED: The explicit, unique target event parameters bound to the clicked card element.
|
|
67
|
+
* @property {MouseEvent} nativeEvent - REQUIRED: Raw browser click interaction data used for analytical intercept positioning or element tracking.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @typedef {Object} EventResourceOptions
|
|
72
|
+
* @description Input operational context map parsing standard parameters through class factories.
|
|
73
|
+
* @property {string|HTMLElement|Node} container - REQUIRED: CSS selector engine target or explicit DOM pointer mount node.
|
|
74
|
+
* @property {CalendarRoom[]} [rooms=[]] - OPTIONAL: Master source list establishing rows along the vertical plane matrix mapping layout.
|
|
75
|
+
* @property {TimeSlot[]} [timeSlots=[]] - OPTIONAL: Master source list defining columns mapped along the horizontal path lane.
|
|
76
|
+
* @property {CalendarEvent[]} [initialEvents=[]] - OPTIONAL: In-memory event array populating coordinates during setup initialization workflows.
|
|
77
|
+
* @property {CalendarHoliday[]} [holidays=[]] - OPTIONAL: Array configuration identifying structural exceptions and specialized global days.
|
|
78
|
+
* @property {CustomButton[]} [customButtons=[]] - OPTIONAL: Extensible collections rendering specialized tool structures within toolbars.
|
|
79
|
+
* @property {boolean} [showControls=false] - OPTIONAL: Flag managing initialization visibility of structural management toolbars.
|
|
80
|
+
* @property {boolean} [stickyHeaders=true] - OPTIONAL: Toggles CSS sticky double-axis tracking logic across layout headers on load.
|
|
81
|
+
* @property {'daily'|'weekly'} [defaultView='daily'] - OPTIONAL: Default presentation structure layout selection state. Must be 'daily' or 'weekly'.
|
|
82
|
+
* @property {Date|string|number} [defaultDate=new Date()] - OPTIONAL: Frame configuration locking starting lifecycle boundaries.
|
|
83
|
+
* @property {function(ClickContextPayload): void} [onCellClick] - OPTIONAL: Interaction callback capturing clicks targeting empty coordinates.
|
|
84
|
+
* @property {function(EventClickPayload): void} [onEventClick] - OPTIONAL: Interaction callback targeting allocated calendar card coordinates.
|
|
85
|
+
* @property {function(Date, 'daily'|'weekly'): Promise<CalendarEvent[]>} [fetchEvents] - OPTIONAL: Data fetching intercept. Async method returning structural item sets.
|
|
86
|
+
* @property {function(CalendarRoom): string} [renderRoomHeader] - OPTIONAL: HTML generator intercept returning structural formatting strings for row slots.
|
|
87
|
+
* @property {function(TimeSlot): string} [renderTimeSlotHeader] - OPTIONAL: HTML generator intercept returning structural formatting strings for column slots.
|
|
88
|
+
* @property {function(CalendarEvent): string} [renderEvent] - OPTIONAL: HTML generator intercept returning custom markup for individual event cards. Overrides default title text.
|
|
89
|
+
* @property {function(Date, 'daily'|'weekly'): Promise<CalendarEvent[]>} [fetchEvents] - OPTIONAL: Async method returning events.
|
|
90
|
+
* @property {function(Date, 'daily'|'weekly'): Promise<CalendarRoom[]>} [fetchRooms] - OPTIONAL: Async method returning rooms dynamically.
|
|
91
|
+
* @property {function(Date, 'daily'|'weekly'): Promise<TimeSlot[]>} [fetchTimeSlots] - OPTIONAL: Async method returning timeline columns dynamically.
|
|
92
|
+
* @property {function(Date, 'daily'|'weekly'): Promise<CalendarHoliday[]>} [fetchHolidays] - OPTIONAL: Async method returning holidays dynamically.
|
|
93
|
+
* * @property {function(CalendarRoom): string} [renderRoomHeader] - OPTIONAL: HTML generator intercept.
|
|
94
|
+
* @property {function(TimeSlot): string} [renderTimeSlotHeader] - OPTIONAL: HTML generator intercept.
|
|
95
|
+
* @property {function(CalendarEvent): string} [renderEvent] - OPTIONAL: HTML generator intercept.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
export {};
|