@schedule-x/react 1.4.0 → 1.5.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/CHANGELOG.md CHANGED
@@ -2,40 +2,42 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
4
4
 
5
- # [1.4.0](https://github.com/schedule-x/react/compare/v1.3.2...v1.4.0) (2024-01-13)
5
+ # [1.5.0](https://github.com/schedule-x/react/compare/v1.4.0...v1.5.0) (2024-01-15)
6
6
 
7
7
 
8
8
  ### Features
9
9
 
10
- * update schedule-x monorepo packages to v1.6.0 ([#29](https://github.com/schedule-x/react/issues/29)) ([02fb337](https://github.com/schedule-x/react/commit/02fb3378b9957abcd50f0f5e066bc2744620c53f))
10
+ * add useNextCalendarApp hook ([#32](https://github.com/schedule-x/react/issues/32)) ([2d3c561](https://github.com/schedule-x/react/commit/2d3c561c479eeea38011588842484e140416644c))
11
11
 
12
- ## [1.3.2](https://github.com/schedule-x/react/compare/v1.3.1...v1.3.2) (2024-01-11)
12
+ # [1.4.0](https://github.com/schedule-x/react/compare/v1.3.2...v1.4.0) (2024-01-13)
13
+
14
+ ### Features
13
15
 
16
+ - update schedule-x monorepo packages to v1.6.0 ([#29](https://github.com/schedule-x/react/issues/29)) ([02fb337](https://github.com/schedule-x/react/commit/02fb3378b9957abcd50f0f5e066bc2744620c53f))
17
+
18
+ ## [1.3.2](https://github.com/schedule-x/react/compare/v1.3.1...v1.3.2) (2024-01-11)
14
19
 
15
20
  ### Bug Fixes
16
21
 
17
- * **deps:** update schedule-x monorepo packages to v1.5.1 ([#27](https://github.com/schedule-x/react/issues/27)) ([437ec00](https://github.com/schedule-x/react/commit/437ec004959beb80cf482b60a5824bdc53258f69))
22
+ - **deps:** update schedule-x monorepo packages to v1.5.1 ([#27](https://github.com/schedule-x/react/issues/27)) ([437ec00](https://github.com/schedule-x/react/commit/437ec004959beb80cf482b60a5824bdc53258f69))
18
23
 
19
24
  ## [1.3.1](https://github.com/schedule-x/react/compare/v1.3.0...v1.3.1) (2024-01-08)
20
25
 
21
-
22
26
  ### Bug Fixes
23
27
 
24
- * **deps:** update schedule-x monorepo packages to v1.4.1 ([#25](https://github.com/schedule-x/react/issues/25)) ([f123728](https://github.com/schedule-x/react/commit/f1237289df77e0cbe2e632a9f9580275cca136f7))
28
+ - **deps:** update schedule-x monorepo packages to v1.4.1 ([#25](https://github.com/schedule-x/react/issues/25)) ([f123728](https://github.com/schedule-x/react/commit/f1237289df77e0cbe2e632a9f9580275cca136f7))
25
29
 
26
30
  # [1.3.0](https://github.com/schedule-x/react/compare/v1.2.1...v1.3.0) (2024-01-05)
27
31
 
28
-
29
32
  ### Features
30
33
 
31
- * **deps:** update schedule-x monorepo packages to v1.4.0 ([#18](https://github.com/schedule-x/react/issues/18)) ([6ac8ac4](https://github.com/schedule-x/react/commit/6ac8ac4db022e7e792a512e5db0f2f06d8373871))
34
+ - **deps:** update schedule-x monorepo packages to v1.4.0 ([#18](https://github.com/schedule-x/react/issues/18)) ([6ac8ac4](https://github.com/schedule-x/react/commit/6ac8ac4db022e7e792a512e5db0f2f06d8373871))
32
35
 
33
36
  ## [1.2.1](https://github.com/schedule-x/react/compare/v1.2.0...v1.2.1) (2024-01-04)
34
37
 
35
-
36
38
  ### Bug Fixes
37
39
 
38
- * usage in nextjs ([#22](https://github.com/schedule-x/react/issues/22)) ([70f81df](https://github.com/schedule-x/react/commit/70f81dff94c7c3334cf69ed5935aa4b0fdf6966d))
40
+ - usage in nextjs ([#22](https://github.com/schedule-x/react/issues/22)) ([70f81df](https://github.com/schedule-x/react/commit/70f81dff94c7c3334cf69ed5935aa4b0fdf6966d))
39
41
 
40
42
  # [1.2.0](https://github.com/schedule-x/react/compare/v1.1.1...v1.2.0) (2024-01-04)
41
43
 
@@ -1,7 +1,7 @@
1
1
  'use client'
2
2
  import styles from './page.module.css'
3
3
  // import { Calendar, useCalendarApp } from '../../../..'
4
- import { useCalendarApp, ScheduleXCalendar } from '../../..'
4
+ import { useNextCalendarApp, ScheduleXCalendar } from '../../..'
5
5
  import {
6
6
  viewDay,
7
7
  viewMonthAgenda,
@@ -12,7 +12,7 @@ import '@schedule-x/theme-default/dist/index.css'
12
12
  import { createDragAndDropPlugin } from '@schedule-x/drag-and-drop'
13
13
 
14
14
  export default function Home() {
15
- const calendarApp = useCalendarApp({
15
+ const calendarApp = useNextCalendarApp({
16
16
  views: [viewWeek, viewMonthGrid, viewDay, viewMonthAgenda],
17
17
  defaultView: viewWeek.name,
18
18
  events: [
@@ -25,6 +25,21 @@ export default function Home() {
25
25
  ],
26
26
  selectedDate: '2023-12-15',
27
27
  plugins: [createDragAndDropPlugin()],
28
+ calendars: {
29
+ school: {
30
+ colorName: 'school',
31
+ lightColors: {
32
+ main: '#1c7df9',
33
+ container: '#d2e7ff',
34
+ onContainer: '#002859',
35
+ },
36
+ darkColors: {
37
+ main: '#c0dfff',
38
+ onContainer: '#dee6ff',
39
+ container: '#426aa2',
40
+ },
41
+ },
42
+ },
28
43
  })
29
44
 
30
45
  return (
package/dist/index.cjs.js CHANGED
@@ -29,6 +29,8 @@ function ScheduleXCalendar({ calendarApp, customComponents }) {
29
29
  setRandomId('sx' + Math.random().toString(36).substring(2, 11));
30
30
  }, []);
31
31
  react.useEffect(() => {
32
+ if (!calendarApp)
33
+ return; // in SSR, calendarApp will be undefined
32
34
  for (const [componentName, Component] of Object.entries(customComponents || {})) {
33
35
  calendarApp._setCustomComponentFn(componentName, createCustomComponentFn(setComponent, Component));
34
36
  }
@@ -46,7 +48,17 @@ function useCalendarApp(config) {
46
48
  const [calendarApp] = react.useState(calendar.createCalendar(config));
47
49
  return calendarApp;
48
50
  }
51
+ function useNextCalendarApp(config) {
52
+ const [calendarApp, setCalendarApp] = react.useState();
53
+ react.useEffect(() => {
54
+ if (typeof window !== 'undefined') {
55
+ setCalendarApp(calendar.createCalendar(config));
56
+ }
57
+ }, []);
58
+ return calendarApp;
59
+ }
49
60
 
50
61
  exports.Calendar = ScheduleXCalendar;
51
62
  exports.ScheduleXCalendar = ScheduleXCalendar;
52
63
  exports.useCalendarApp = useCalendarApp;
64
+ exports.useNextCalendarApp = useNextCalendarApp;
package/dist/index.js CHANGED
@@ -27,6 +27,8 @@ function ScheduleXCalendar({ calendarApp, customComponents }) {
27
27
  setRandomId('sx' + Math.random().toString(36).substring(2, 11));
28
28
  }, []);
29
29
  useEffect(() => {
30
+ if (!calendarApp)
31
+ return; // in SSR, calendarApp will be undefined
30
32
  for (const [componentName, Component] of Object.entries(customComponents || {})) {
31
33
  calendarApp._setCustomComponentFn(componentName, createCustomComponentFn(setComponent, Component));
32
34
  }
@@ -44,5 +46,14 @@ function useCalendarApp(config) {
44
46
  const [calendarApp] = useState(createCalendar(config));
45
47
  return calendarApp;
46
48
  }
49
+ function useNextCalendarApp(config) {
50
+ const [calendarApp, setCalendarApp] = useState();
51
+ useEffect(() => {
52
+ if (typeof window !== 'undefined') {
53
+ setCalendarApp(createCalendar(config));
54
+ }
55
+ }, []);
56
+ return calendarApp;
57
+ }
47
58
 
48
- export { ScheduleXCalendar as Calendar, ScheduleXCalendar, useCalendarApp };
59
+ export { ScheduleXCalendar as Calendar, ScheduleXCalendar, useCalendarApp, useNextCalendarApp };
@@ -1,3 +1,3 @@
1
1
  export { ScheduleXCalendar as Calendar } from './schedule-x-calendar.tsx';
2
2
  export { ScheduleXCalendar } from './schedule-x-calendar.tsx';
3
- export { useCalendarApp } from './use-calendar-app.tsx';
3
+ export { useCalendarApp, useNextCalendarApp } from './use-calendar-app.tsx';
@@ -2,7 +2,7 @@ import { CalendarApp } from '@schedule-x/calendar';
2
2
  import React from 'react';
3
3
  type ReactComponent = React.ComponentType<any>;
4
4
  type props = {
5
- calendarApp: CalendarApp;
5
+ calendarApp: CalendarApp | undefined;
6
6
  customComponents?: {
7
7
  timeGridEvent?: ReactComponent;
8
8
  dateGridEvent?: ReactComponent;
@@ -1,2 +1,3 @@
1
- import { CalendarConfig } from '@schedule-x/calendar';
2
- export declare function useCalendarApp(config: CalendarConfig): import("@schedule-x/calendar").CalendarApp;
1
+ import { CalendarApp, CalendarConfig } from '@schedule-x/calendar';
2
+ export declare function useCalendarApp(config: CalendarConfig): CalendarApp;
3
+ export declare function useNextCalendarApp(config: CalendarConfig): CalendarApp | undefined;
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "main": "dist/index.cjs.js",
15
15
  "module": "dist/index.js",
16
16
  "types": "dist/types/index.d.ts",
17
- "version": "1.4.0",
17
+ "version": "1.5.0",
18
18
  "type": "module",
19
19
  "scripts": {
20
20
  "dev": "vite",
package/src/index.tsx CHANGED
@@ -2,4 +2,4 @@
2
2
  export { ScheduleXCalendar as Calendar } from './schedule-x-calendar.tsx'
3
3
 
4
4
  export { ScheduleXCalendar } from './schedule-x-calendar.tsx'
5
- export { useCalendarApp } from './use-calendar-app.tsx'
5
+ export { useCalendarApp, useNextCalendarApp } from './use-calendar-app.tsx'
@@ -10,7 +10,7 @@ import {
10
10
  type ReactComponent = React.ComponentType<any>
11
11
 
12
12
  type props = {
13
- calendarApp: CalendarApp
13
+ calendarApp: CalendarApp | undefined // undefined allowed to prevent errors in SSR
14
14
  customComponents?: {
15
15
  timeGridEvent?: ReactComponent
16
16
  dateGridEvent?: ReactComponent
@@ -57,6 +57,8 @@ export function ScheduleXCalendar({ calendarApp, customComponents }: props) {
57
57
  }, [])
58
58
 
59
59
  useEffect(() => {
60
+ if (!calendarApp) return // in SSR, calendarApp will be undefined
61
+
60
62
  for (const [componentName, Component] of Object.entries(
61
63
  customComponents || {}
62
64
  )) {
@@ -1,7 +1,23 @@
1
- import { CalendarConfig, createCalendar } from '@schedule-x/calendar'
2
- import { useState } from 'react'
1
+ import {
2
+ CalendarApp,
3
+ CalendarConfig,
4
+ createCalendar,
5
+ } from '@schedule-x/calendar'
6
+ import { useEffect, useState } from 'react'
3
7
 
4
8
  export function useCalendarApp(config: CalendarConfig) {
5
9
  const [calendarApp] = useState(createCalendar(config))
6
10
  return calendarApp
7
11
  }
12
+
13
+ export function useNextCalendarApp(config: CalendarConfig) {
14
+ const [calendarApp, setCalendarApp] = useState<CalendarApp>()
15
+
16
+ useEffect(() => {
17
+ if (typeof window !== 'undefined') {
18
+ setCalendarApp(createCalendar(config))
19
+ }
20
+ }, [])
21
+
22
+ return calendarApp
23
+ }