@forcecalendar/react 0.2.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Nirmala Rao Dhanawada
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @forcecalendar/react
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
4
+
5
+ Thin React adapter for [forceCalendar](https://forcecalendar.org) — enterprise calendar Web Components that run under Salesforce Locker Service and strict CSP.
6
+
7
+ Maps props to the `<forcecal-main>` element's attributes and its DOM events to React callbacks. SSR-safe (custom elements register client-side only), so it works in Next.js out of the box.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @forcecalendar/react @forcecalendar/core @forcecalendar/interface
13
+ ```
14
+
15
+ ## Use
16
+
17
+ ```tsx
18
+ import { ForceCalendar } from '@forcecalendar/react';
19
+
20
+ export default function Scheduling() {
21
+ return (
22
+ <ForceCalendar
23
+ view="month"
24
+ timezone="America/New_York"
25
+ height="600px"
26
+ onDateSelect={({ date }) => console.log('selected', date)}
27
+ onEventAdded={detail => console.log('added', detail)}
28
+ />
29
+ );
30
+ }
31
+ ```
32
+
33
+ Props: `view`, `date`, `locale`, `timezone`, `weekStartsOn`, `height`, `className`, `style`, plus callbacks `onEventAdded`, `onEventUpdated`, `onEventDeleted`, `onDateSelect`, `onViewChange`, `onNavigate`.
34
+
35
+ Docs: [docs.forcecalendar.org](https://docs.forcecalendar.org) · License: [MIT](LICENSE)
@@ -0,0 +1,21 @@
1
+ export interface CalendarEventDetail {
2
+ [key: string]: unknown;
3
+ }
4
+ export interface ForceCalendarProps {
5
+ view?: 'month' | 'week' | 'day';
6
+ date?: Date | string;
7
+ locale?: string;
8
+ timezone?: string;
9
+ weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
10
+ height?: string;
11
+ className?: string;
12
+ style?: React.CSSProperties;
13
+ onEventAdded?: (detail: CalendarEventDetail) => void;
14
+ onEventUpdated?: (detail: CalendarEventDetail) => void;
15
+ onEventDeleted?: (detail: CalendarEventDetail) => void;
16
+ onDateSelect?: (detail: CalendarEventDetail) => void;
17
+ onViewChange?: (detail: CalendarEventDetail) => void;
18
+ onNavigate?: (detail: CalendarEventDetail) => void;
19
+ }
20
+ export declare function ForceCalendar(props: ForceCalendarProps): import("react").JSX.Element;
21
+ export default ForceCalendar;
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * @forcecalendar/react — thin React adapter for the forceCalendar
4
+ * Web Component. Maps props to attributes and DOM events to callbacks.
5
+ * No dependencies beyond the peer React and forceCalendar packages.
6
+ */
7
+ import { useEffect, useRef } from 'react';
8
+ const EVENT_MAP = [
9
+ ['calendar-event-added', 'onEventAdded'],
10
+ ['calendar-event-updated', 'onEventUpdated'],
11
+ ['calendar-event-deleted', 'onEventDeleted'],
12
+ ['calendar-date-select', 'onDateSelect'],
13
+ ['calendar-view-change', 'onViewChange'],
14
+ ['calendar-navigate', 'onNavigate'],
15
+ ];
16
+ export function ForceCalendar(props) {
17
+ const ref = useRef(null);
18
+ const handlers = useRef(props);
19
+ handlers.current = props;
20
+ useEffect(() => {
21
+ // Register the custom elements client-side only — safe under SSR
22
+ import('@forcecalendar/interface');
23
+ const el = ref.current;
24
+ if (!el)
25
+ return;
26
+ const listeners = EVENT_MAP.map(([eventName, propName]) => {
27
+ const listener = (e) => {
28
+ const fn = handlers.current[propName];
29
+ fn?.(e.detail ?? {});
30
+ };
31
+ el.addEventListener(eventName, listener);
32
+ return [eventName, listener];
33
+ });
34
+ return () => {
35
+ for (const [eventName, listener] of listeners) {
36
+ el.removeEventListener(eventName, listener);
37
+ }
38
+ };
39
+ }, []);
40
+ const dateAttr = props.date instanceof Date ? props.date.toISOString() : props.date;
41
+ // React 19 passes unknown props on custom elements as attributes
42
+ return (
43
+ // @ts-expect-error custom element is not in JSX.IntrinsicElements
44
+ _jsx("forcecal-main", { ref: ref, class: props.className, style: props.style, view: props.view, date: dateAttr, locale: props.locale, timezone: props.timezone, "week-starts-on": props.weekStartsOn, height: props.height }));
45
+ }
46
+ export default ForceCalendar;
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@forcecalendar/react",
3
+ "version": "0.2.1",
4
+ "description": "React adapter for forceCalendar - enterprise calendar Web Components",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "test": "npm run build && node test/smoke.mjs"
22
+ },
23
+ "peerDependencies": {
24
+ "@forcecalendar/core": ">=2.0.0",
25
+ "@forcecalendar/interface": ">=1.1.0",
26
+ "react": ">=18"
27
+ },
28
+ "devDependencies": {
29
+ "@forcecalendar/core": "^2.3.0",
30
+ "@forcecalendar/interface": "^1.1.0",
31
+ "@types/react": "^19",
32
+ "react": "^19",
33
+ "react-dom": "^19",
34
+ "typescript": "^5"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/forceCalendar/react.git"
39
+ },
40
+ "license": "MIT",
41
+ "publishConfig": {
42
+ "access": "public"
43
+ }
44
+ }