@iyotsuba/schedule-react 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 yotsuba-kit contributors
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/dist/index.cjs ADDED
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ YsSchedule: () => YsSchedule,
24
+ YsToday: () => YsToday
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/YsSchedule.tsx
29
+ var import_schedule_elements = require("@iyotsuba/schedule-elements");
30
+ var import_react2 = require("react");
31
+
32
+ // src/useElement.ts
33
+ var import_react = require("react");
34
+ function useElementBridge(properties, events) {
35
+ const ref = (0, import_react.useRef)(null);
36
+ (0, import_react.useLayoutEffect)(() => {
37
+ const el = ref.current;
38
+ if (!el) {
39
+ return;
40
+ }
41
+ for (const [key, value] of Object.entries(properties)) {
42
+ if (value !== void 0) {
43
+ el[key] = value;
44
+ }
45
+ }
46
+ });
47
+ (0, import_react.useLayoutEffect)(() => {
48
+ const el = ref.current;
49
+ if (!el) {
50
+ return;
51
+ }
52
+ const disposers = [];
53
+ for (const [name, handler] of Object.entries(events)) {
54
+ if (!handler) {
55
+ continue;
56
+ }
57
+ const listener = (event) => {
58
+ const detail = event.detail;
59
+ handler(...Array.isArray(detail) ? detail : [detail]);
60
+ };
61
+ const hyphenated = name.replace(/([A-Z])/g, "-$1").toLowerCase();
62
+ el.addEventListener(name, listener);
63
+ disposers.push(() => el.removeEventListener(name, listener));
64
+ if (hyphenated !== name) {
65
+ el.addEventListener(hyphenated, listener);
66
+ disposers.push(() => el.removeEventListener(hyphenated, listener));
67
+ }
68
+ }
69
+ return () => disposers.forEach((dispose) => dispose());
70
+ });
71
+ return ref;
72
+ }
73
+
74
+ // src/YsSchedule.tsx
75
+ (0, import_schedule_elements.register)();
76
+ function YsSchedule(props) {
77
+ const {
78
+ className,
79
+ style,
80
+ onWeekChange,
81
+ onUpdateWeek,
82
+ onCourseTap,
83
+ onDayTap,
84
+ onSwipe,
85
+ onWeekPickerOpen,
86
+ onGuideStep,
87
+ onGuideFinish,
88
+ ...properties
89
+ } = props;
90
+ const ref = useElementBridge(properties, {
91
+ "weekChange": onWeekChange,
92
+ "update:week": onUpdateWeek,
93
+ "courseTap": onCourseTap,
94
+ "dayTap": onDayTap,
95
+ "swipe": onSwipe,
96
+ "weekPickerOpen": onWeekPickerOpen,
97
+ "guideStep": onGuideStep,
98
+ "guideFinish": onGuideFinish
99
+ });
100
+ return (0, import_react2.createElement)("ys-schedule", { "ref": ref, "class": className, style });
101
+ }
102
+
103
+ // src/YsToday.tsx
104
+ var import_schedule_elements2 = require("@iyotsuba/schedule-elements");
105
+ var import_react3 = require("react");
106
+ (0, import_schedule_elements2.register)();
107
+ function YsToday(props) {
108
+ const { className, style, onCourseTap, onWidgetTap, ...properties } = props;
109
+ const ref = useElementBridge(properties, {
110
+ courseTap: onCourseTap,
111
+ widgetTap: onWidgetTap
112
+ });
113
+ return (0, import_react3.createElement)("ys-today", { "ref": ref, "class": className, style });
114
+ }
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ YsSchedule,
118
+ YsToday
119
+ });
@@ -0,0 +1,71 @@
1
+ import * as react from 'react';
2
+ import { CSSProperties } from 'react';
3
+ import { Course, DayOverride, CourseTime, BuiltinTransitionName, TransitionSpec, ThemeTokens, WeatherSnapshot, GuideConfig, DisplayCourse, GuideStep } from '@iyotsuba/schedule-core';
4
+ export { BuiltinTransitionName, Course, CourseTime, DayOverride, DisplayCourse, GuideConfig, GuideStep, ThemeTokens, TransitionSpec, WeatherProvider, WeatherSnapshot } from '@iyotsuba/schedule-core';
5
+
6
+ interface YsScheduleProps {
7
+ courses: Course[];
8
+ week?: number;
9
+ totalWeeks?: number;
10
+ termStart?: Date;
11
+ overrides?: DayOverride[];
12
+ courseTimes?: CourseTime[] | 'standard';
13
+ visibleDays?: 5 | 6 | 7;
14
+ rowHeight?: number;
15
+ breakAfterSection?: number;
16
+ topBar?: 'compact' | 'standard' | 'expanded' | 'none';
17
+ topBarTitle?: string;
18
+ weekdayBar?: boolean;
19
+ transition?: BuiltinTransitionName | TransitionSpec;
20
+ theme?: 'light' | 'dark' | Partial<ThemeTokens>;
21
+ weather?: WeatherSnapshot | null;
22
+ reduceMotion?: boolean | 'auto';
23
+ swipeable?: boolean;
24
+ weekPicker?: 'builtin' | 'none';
25
+ courseDetail?: 'builtin' | 'none';
26
+ guide?: GuideConfig | false;
27
+ locale?: Record<string, unknown>;
28
+ onWeekChange?: (week: number, previous: number) => void;
29
+ /** 受控用法:配合 week 使用 */
30
+ onUpdateWeek?: (week: number) => void;
31
+ onCourseTap?: (course: DisplayCourse, stack: DisplayCourse[]) => void;
32
+ onDayTap?: (weekday: number, date: Date | null) => void;
33
+ onSwipe?: (direction: 1 | -1) => void;
34
+ onWeekPickerOpen?: () => void;
35
+ onGuideStep?: (step: GuideStep, index: number) => void;
36
+ onGuideFinish?: () => void;
37
+ className?: string;
38
+ style?: CSSProperties;
39
+ }
40
+ declare function YsSchedule(props: YsScheduleProps): react.ReactElement<{
41
+ ref: react.RefObject<HTMLElement | null>;
42
+ class: string | undefined;
43
+ style: CSSProperties | undefined;
44
+ }, string | react.JSXElementConstructor<any>>;
45
+
46
+ interface YsTodayProps {
47
+ courses: Course[];
48
+ termStart: Date;
49
+ totalWeeks?: number;
50
+ overrides?: DayOverride[];
51
+ courseTimes?: CourseTime[] | 'standard';
52
+ widgets?: Array<{
53
+ id: string;
54
+ enabled?: boolean;
55
+ }>;
56
+ theme?: 'light' | 'dark' | Partial<ThemeTokens>;
57
+ weather?: WeatherSnapshot | null;
58
+ now?: Date;
59
+ title?: string;
60
+ onCourseTap?: (course: DisplayCourse) => void;
61
+ onWidgetTap?: (id: string) => void;
62
+ className?: string;
63
+ style?: CSSProperties;
64
+ }
65
+ declare function YsToday(props: YsTodayProps): react.ReactElement<{
66
+ ref: react.RefObject<HTMLElement | null>;
67
+ class: string | undefined;
68
+ style: CSSProperties | undefined;
69
+ }, string | react.JSXElementConstructor<any>>;
70
+
71
+ export { YsSchedule, type YsScheduleProps, YsToday, type YsTodayProps };
@@ -0,0 +1,71 @@
1
+ import * as react from 'react';
2
+ import { CSSProperties } from 'react';
3
+ import { Course, DayOverride, CourseTime, BuiltinTransitionName, TransitionSpec, ThemeTokens, WeatherSnapshot, GuideConfig, DisplayCourse, GuideStep } from '@iyotsuba/schedule-core';
4
+ export { BuiltinTransitionName, Course, CourseTime, DayOverride, DisplayCourse, GuideConfig, GuideStep, ThemeTokens, TransitionSpec, WeatherProvider, WeatherSnapshot } from '@iyotsuba/schedule-core';
5
+
6
+ interface YsScheduleProps {
7
+ courses: Course[];
8
+ week?: number;
9
+ totalWeeks?: number;
10
+ termStart?: Date;
11
+ overrides?: DayOverride[];
12
+ courseTimes?: CourseTime[] | 'standard';
13
+ visibleDays?: 5 | 6 | 7;
14
+ rowHeight?: number;
15
+ breakAfterSection?: number;
16
+ topBar?: 'compact' | 'standard' | 'expanded' | 'none';
17
+ topBarTitle?: string;
18
+ weekdayBar?: boolean;
19
+ transition?: BuiltinTransitionName | TransitionSpec;
20
+ theme?: 'light' | 'dark' | Partial<ThemeTokens>;
21
+ weather?: WeatherSnapshot | null;
22
+ reduceMotion?: boolean | 'auto';
23
+ swipeable?: boolean;
24
+ weekPicker?: 'builtin' | 'none';
25
+ courseDetail?: 'builtin' | 'none';
26
+ guide?: GuideConfig | false;
27
+ locale?: Record<string, unknown>;
28
+ onWeekChange?: (week: number, previous: number) => void;
29
+ /** 受控用法:配合 week 使用 */
30
+ onUpdateWeek?: (week: number) => void;
31
+ onCourseTap?: (course: DisplayCourse, stack: DisplayCourse[]) => void;
32
+ onDayTap?: (weekday: number, date: Date | null) => void;
33
+ onSwipe?: (direction: 1 | -1) => void;
34
+ onWeekPickerOpen?: () => void;
35
+ onGuideStep?: (step: GuideStep, index: number) => void;
36
+ onGuideFinish?: () => void;
37
+ className?: string;
38
+ style?: CSSProperties;
39
+ }
40
+ declare function YsSchedule(props: YsScheduleProps): react.ReactElement<{
41
+ ref: react.RefObject<HTMLElement | null>;
42
+ class: string | undefined;
43
+ style: CSSProperties | undefined;
44
+ }, string | react.JSXElementConstructor<any>>;
45
+
46
+ interface YsTodayProps {
47
+ courses: Course[];
48
+ termStart: Date;
49
+ totalWeeks?: number;
50
+ overrides?: DayOverride[];
51
+ courseTimes?: CourseTime[] | 'standard';
52
+ widgets?: Array<{
53
+ id: string;
54
+ enabled?: boolean;
55
+ }>;
56
+ theme?: 'light' | 'dark' | Partial<ThemeTokens>;
57
+ weather?: WeatherSnapshot | null;
58
+ now?: Date;
59
+ title?: string;
60
+ onCourseTap?: (course: DisplayCourse) => void;
61
+ onWidgetTap?: (id: string) => void;
62
+ className?: string;
63
+ style?: CSSProperties;
64
+ }
65
+ declare function YsToday(props: YsTodayProps): react.ReactElement<{
66
+ ref: react.RefObject<HTMLElement | null>;
67
+ class: string | undefined;
68
+ style: CSSProperties | undefined;
69
+ }, string | react.JSXElementConstructor<any>>;
70
+
71
+ export { YsSchedule, type YsScheduleProps, YsToday, type YsTodayProps };
package/dist/index.js ADDED
@@ -0,0 +1,91 @@
1
+ // src/YsSchedule.tsx
2
+ import { register } from "@iyotsuba/schedule-elements";
3
+ import { createElement } from "react";
4
+
5
+ // src/useElement.ts
6
+ import { useLayoutEffect, useRef } from "react";
7
+ function useElementBridge(properties, events) {
8
+ const ref = useRef(null);
9
+ useLayoutEffect(() => {
10
+ const el = ref.current;
11
+ if (!el) {
12
+ return;
13
+ }
14
+ for (const [key, value] of Object.entries(properties)) {
15
+ if (value !== void 0) {
16
+ el[key] = value;
17
+ }
18
+ }
19
+ });
20
+ useLayoutEffect(() => {
21
+ const el = ref.current;
22
+ if (!el) {
23
+ return;
24
+ }
25
+ const disposers = [];
26
+ for (const [name, handler] of Object.entries(events)) {
27
+ if (!handler) {
28
+ continue;
29
+ }
30
+ const listener = (event) => {
31
+ const detail = event.detail;
32
+ handler(...Array.isArray(detail) ? detail : [detail]);
33
+ };
34
+ const hyphenated = name.replace(/([A-Z])/g, "-$1").toLowerCase();
35
+ el.addEventListener(name, listener);
36
+ disposers.push(() => el.removeEventListener(name, listener));
37
+ if (hyphenated !== name) {
38
+ el.addEventListener(hyphenated, listener);
39
+ disposers.push(() => el.removeEventListener(hyphenated, listener));
40
+ }
41
+ }
42
+ return () => disposers.forEach((dispose) => dispose());
43
+ });
44
+ return ref;
45
+ }
46
+
47
+ // src/YsSchedule.tsx
48
+ register();
49
+ function YsSchedule(props) {
50
+ const {
51
+ className,
52
+ style,
53
+ onWeekChange,
54
+ onUpdateWeek,
55
+ onCourseTap,
56
+ onDayTap,
57
+ onSwipe,
58
+ onWeekPickerOpen,
59
+ onGuideStep,
60
+ onGuideFinish,
61
+ ...properties
62
+ } = props;
63
+ const ref = useElementBridge(properties, {
64
+ "weekChange": onWeekChange,
65
+ "update:week": onUpdateWeek,
66
+ "courseTap": onCourseTap,
67
+ "dayTap": onDayTap,
68
+ "swipe": onSwipe,
69
+ "weekPickerOpen": onWeekPickerOpen,
70
+ "guideStep": onGuideStep,
71
+ "guideFinish": onGuideFinish
72
+ });
73
+ return createElement("ys-schedule", { "ref": ref, "class": className, style });
74
+ }
75
+
76
+ // src/YsToday.tsx
77
+ import { register as register2 } from "@iyotsuba/schedule-elements";
78
+ import { createElement as createElement2 } from "react";
79
+ register2();
80
+ function YsToday(props) {
81
+ const { className, style, onCourseTap, onWidgetTap, ...properties } = props;
82
+ const ref = useElementBridge(properties, {
83
+ courseTap: onCourseTap,
84
+ widgetTap: onWidgetTap
85
+ });
86
+ return createElement2("ys-today", { "ref": ref, "class": className, style });
87
+ }
88
+ export {
89
+ YsSchedule,
90
+ YsToday
91
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@iyotsuba/schedule-react",
3
+ "version": "0.3.0",
4
+ "description": "Typed React bindings for the yotsuba schedule kit (<YsSchedule> / <YsToday> over custom elements).",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "peerDependencies": {
22
+ "react": ">=18"
23
+ },
24
+ "dependencies": {
25
+ "@iyotsuba/schedule-core": "0.3.0",
26
+ "@iyotsuba/schedule-elements": "0.3.0"
27
+ },
28
+ "devDependencies": {
29
+ "@testing-library/react": "^16.1.0",
30
+ "@types/react": "^19.0.0",
31
+ "jsdom": "^25.0.1",
32
+ "react": "^19.0.0",
33
+ "react-dom": "^19.0.0",
34
+ "tsup": "^8.3.5",
35
+ "typescript": "^5.6.3",
36
+ "vitest": "^2.1.8"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/isla4ever/yotsuba-kit"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "scripts": {
46
+ "build": "tsup",
47
+ "test": "vitest run",
48
+ "typecheck": "tsc --noEmit"
49
+ }
50
+ }