@table-js/core 0.0.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/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # @tablejs/core
2
+
3
+ Core runtime for Table.js - the Smart TV application framework.
4
+
5
+ ## Features
6
+
7
+ - **File-based Router** - Next.js-style app router with dynamic routes
8
+ - **Focus Engine** - Spatial navigation for TV remotes
9
+ - **Platform Support** - Works on Tizen, webOS, and Android TV
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @tablejs/core react react-dom
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```tsx
20
+ import { TableApp, defineRoutes } from '@tablejs/core'
21
+
22
+ const routes = defineRoutes([
23
+ { path: '/', component: () => import('./app/page') },
24
+ { path: '/movie/[id]', component: () => import('./app/movie/[id]/page') },
25
+ ])
26
+
27
+ function App() {
28
+ return <TableApp routes={routes} />
29
+ }
30
+ ```
31
+
32
+ ## Documentation
33
+
34
+ Visit [tablejs.dev](https://tablejs.dev) for full documentation.
35
+
36
+ ## License
37
+
38
+ MIT
@@ -0,0 +1,178 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React$1 from 'react';
3
+ import React__default from 'react';
4
+
5
+ interface RouteParams {
6
+ [key: string]: string;
7
+ }
8
+ interface RouteQuery {
9
+ [key: string]: string | string[] | undefined;
10
+ }
11
+ interface Route {
12
+ path: string;
13
+ params: RouteParams;
14
+ query: RouteQuery;
15
+ }
16
+ interface RouteSegment {
17
+ type: 'static' | 'dynamic' | 'catch-all';
18
+ value: string;
19
+ }
20
+ interface RouteDefinition {
21
+ filePath: string;
22
+ segments: RouteSegment[];
23
+ component: React__default.LazyExoticComponent<React__default.ComponentType>;
24
+ }
25
+ type NavigateOptions = {
26
+ replace?: boolean;
27
+ query?: RouteQuery;
28
+ };
29
+
30
+ type FocusDirection = 'up' | 'down' | 'left' | 'right';
31
+ type FocusableId = string;
32
+ interface FocusableNode {
33
+ id: FocusableId;
34
+ el: HTMLElement;
35
+ groupId: FocusableId | null;
36
+ disabled: boolean;
37
+ onFocus?: () => void;
38
+ onBlur?: () => void;
39
+ onSelect?: () => void;
40
+ }
41
+ interface FocusGroup$1 {
42
+ id: FocusableId;
43
+ parentId: FocusableId | null;
44
+ orientation: 'horizontal' | 'vertical' | 'grid';
45
+ loop: boolean;
46
+ rememberFocus: boolean;
47
+ lastFocusedId: FocusableId | null;
48
+ }
49
+ interface FocusState {
50
+ focusedId: FocusableId | null;
51
+ nodes: Map<FocusableId, FocusableNode>;
52
+ groups: Map<FocusableId, FocusGroup$1>;
53
+ }
54
+ interface FocusManagerOptions {
55
+ initialFocusId?: FocusableId;
56
+ onFocusChange?: (id: FocusableId | null) => void;
57
+ }
58
+
59
+ interface TableAppProps {
60
+ routes: RouteDefinition[];
61
+ initialPath?: string;
62
+ focus?: FocusManagerOptions;
63
+ }
64
+ declare function TableApp({ routes, initialPath, focus }: TableAppProps): react_jsx_runtime.JSX.Element;
65
+
66
+ interface RouterProps {
67
+ routes: RouteDefinition[];
68
+ initialPath?: string;
69
+ }
70
+ declare function Router({ routes, initialPath }: RouterProps): react_jsx_runtime.JSX.Element;
71
+
72
+ interface RouterContextValue {
73
+ route: Route;
74
+ navigate: (path: string, options?: NavigateOptions) => void;
75
+ back: () => void;
76
+ prefetch: (path: string) => void;
77
+ }
78
+ declare const RouterContext: React$1.Context<RouterContextValue | null>;
79
+ declare function useRouter(): RouterContextValue;
80
+ declare function useParams<T extends Record<string, string>>(): T;
81
+ declare function useQuery<T extends Record<string, string | string[] | undefined>>(): T;
82
+
83
+ type RouteInput = {
84
+ path: string;
85
+ component: () => Promise<{
86
+ default: React__default.ComponentType;
87
+ }>;
88
+ };
89
+ declare function defineRoutes(routes: RouteInput[]): RouteDefinition[];
90
+
91
+ declare class FocusManager {
92
+ private state;
93
+ private options;
94
+ constructor(options?: FocusManagerOptions);
95
+ registerNode(node: FocusableNode): void;
96
+ unregisterNode(id: FocusableId): void;
97
+ registerGroup(group: FocusGroup$1): void;
98
+ unregisterGroup(id: FocusableId): void;
99
+ setFocus(id: FocusableId): void;
100
+ move(direction: FocusDirection): void;
101
+ select(): void;
102
+ focusFirst(): void;
103
+ getFocusedId(): FocusableId | null;
104
+ private findNextInGroup;
105
+ private findNextSpatial;
106
+ }
107
+
108
+ interface FocusProviderProps {
109
+ children: React__default.ReactNode;
110
+ options?: FocusManagerOptions;
111
+ }
112
+ declare function FocusProvider({ children, options }: FocusProviderProps): react_jsx_runtime.JSX.Element;
113
+
114
+ type KeyAction = {
115
+ type: 'move';
116
+ direction: FocusDirection;
117
+ } | {
118
+ type: 'select';
119
+ } | {
120
+ type: 'back';
121
+ } | {
122
+ type: 'unknown';
123
+ };
124
+ declare function resolveKeyAction(event: KeyboardEvent): KeyAction;
125
+ declare class KeyHandler {
126
+ private listeners;
127
+ private bound;
128
+ mount(): void;
129
+ unmount(): void;
130
+ subscribe(fn: (action: KeyAction) => void): () => void;
131
+ }
132
+
133
+ interface FocusContextValue {
134
+ manager: FocusManager;
135
+ keyHandler: KeyHandler;
136
+ }
137
+ declare const FocusContext: React$1.Context<FocusContextValue | null>;
138
+ declare function useFocusContext(): FocusContextValue;
139
+
140
+ interface UseFocusableOptions {
141
+ groupId?: string;
142
+ disabled?: boolean;
143
+ onFocus?: () => void;
144
+ onBlur?: () => void;
145
+ onSelect?: () => void;
146
+ autoFocus?: boolean;
147
+ }
148
+ interface UseFocusableResult {
149
+ ref: React.RefObject<HTMLElement>;
150
+ focused: boolean;
151
+ focusableProps: {
152
+ 'data-focusable': string;
153
+ 'data-focused': boolean;
154
+ tabIndex: number;
155
+ };
156
+ }
157
+ declare function useFocusable(options?: UseFocusableOptions): UseFocusableResult;
158
+ type UseFocusGroupOptions = Omit<FocusGroup$1, 'id' | 'lastFocusedId' | 'parentId'>;
159
+ declare function useFocusGroup(options: UseFocusGroupOptions): {
160
+ groupId: string;
161
+ };
162
+
163
+ interface FocusableProps extends UseFocusableOptions {
164
+ children: React__default.ReactNode | ((focused: boolean) => React__default.ReactNode);
165
+ as?: React__default.ElementType;
166
+ className?: string;
167
+ style?: React__default.CSSProperties;
168
+ }
169
+ declare const Focusable: React__default.ForwardRefExoticComponent<FocusableProps & React__default.RefAttributes<HTMLElement>>;
170
+ interface FocusGroupProps extends UseFocusGroupOptions {
171
+ children: React__default.ReactNode;
172
+ as?: React__default.ElementType;
173
+ className?: string;
174
+ style?: React__default.CSSProperties;
175
+ }
176
+ declare function FocusGroup({ children, as: Tag, className, style, ...options }: FocusGroupProps): react_jsx_runtime.JSX.Element;
177
+
178
+ export { FocusContext, type FocusDirection, FocusGroup, type FocusGroup$1 as FocusGroupType, FocusManager, type FocusManagerOptions, FocusProvider, type FocusState, Focusable, type FocusableId, type FocusableNode, KeyHandler, type NavigateOptions, type Route, type RouteDefinition, type RouteParams, type RouteQuery, type RouteSegment, Router, RouterContext, TableApp, type UseFocusGroupOptions, type UseFocusableOptions, type UseFocusableResult, defineRoutes, resolveKeyAction, useFocusContext, useFocusGroup, useFocusable, useParams, useQuery, useRouter };
@@ -0,0 +1,178 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React$1 from 'react';
3
+ import React__default from 'react';
4
+
5
+ interface RouteParams {
6
+ [key: string]: string;
7
+ }
8
+ interface RouteQuery {
9
+ [key: string]: string | string[] | undefined;
10
+ }
11
+ interface Route {
12
+ path: string;
13
+ params: RouteParams;
14
+ query: RouteQuery;
15
+ }
16
+ interface RouteSegment {
17
+ type: 'static' | 'dynamic' | 'catch-all';
18
+ value: string;
19
+ }
20
+ interface RouteDefinition {
21
+ filePath: string;
22
+ segments: RouteSegment[];
23
+ component: React__default.LazyExoticComponent<React__default.ComponentType>;
24
+ }
25
+ type NavigateOptions = {
26
+ replace?: boolean;
27
+ query?: RouteQuery;
28
+ };
29
+
30
+ type FocusDirection = 'up' | 'down' | 'left' | 'right';
31
+ type FocusableId = string;
32
+ interface FocusableNode {
33
+ id: FocusableId;
34
+ el: HTMLElement;
35
+ groupId: FocusableId | null;
36
+ disabled: boolean;
37
+ onFocus?: () => void;
38
+ onBlur?: () => void;
39
+ onSelect?: () => void;
40
+ }
41
+ interface FocusGroup$1 {
42
+ id: FocusableId;
43
+ parentId: FocusableId | null;
44
+ orientation: 'horizontal' | 'vertical' | 'grid';
45
+ loop: boolean;
46
+ rememberFocus: boolean;
47
+ lastFocusedId: FocusableId | null;
48
+ }
49
+ interface FocusState {
50
+ focusedId: FocusableId | null;
51
+ nodes: Map<FocusableId, FocusableNode>;
52
+ groups: Map<FocusableId, FocusGroup$1>;
53
+ }
54
+ interface FocusManagerOptions {
55
+ initialFocusId?: FocusableId;
56
+ onFocusChange?: (id: FocusableId | null) => void;
57
+ }
58
+
59
+ interface TableAppProps {
60
+ routes: RouteDefinition[];
61
+ initialPath?: string;
62
+ focus?: FocusManagerOptions;
63
+ }
64
+ declare function TableApp({ routes, initialPath, focus }: TableAppProps): react_jsx_runtime.JSX.Element;
65
+
66
+ interface RouterProps {
67
+ routes: RouteDefinition[];
68
+ initialPath?: string;
69
+ }
70
+ declare function Router({ routes, initialPath }: RouterProps): react_jsx_runtime.JSX.Element;
71
+
72
+ interface RouterContextValue {
73
+ route: Route;
74
+ navigate: (path: string, options?: NavigateOptions) => void;
75
+ back: () => void;
76
+ prefetch: (path: string) => void;
77
+ }
78
+ declare const RouterContext: React$1.Context<RouterContextValue | null>;
79
+ declare function useRouter(): RouterContextValue;
80
+ declare function useParams<T extends Record<string, string>>(): T;
81
+ declare function useQuery<T extends Record<string, string | string[] | undefined>>(): T;
82
+
83
+ type RouteInput = {
84
+ path: string;
85
+ component: () => Promise<{
86
+ default: React__default.ComponentType;
87
+ }>;
88
+ };
89
+ declare function defineRoutes(routes: RouteInput[]): RouteDefinition[];
90
+
91
+ declare class FocusManager {
92
+ private state;
93
+ private options;
94
+ constructor(options?: FocusManagerOptions);
95
+ registerNode(node: FocusableNode): void;
96
+ unregisterNode(id: FocusableId): void;
97
+ registerGroup(group: FocusGroup$1): void;
98
+ unregisterGroup(id: FocusableId): void;
99
+ setFocus(id: FocusableId): void;
100
+ move(direction: FocusDirection): void;
101
+ select(): void;
102
+ focusFirst(): void;
103
+ getFocusedId(): FocusableId | null;
104
+ private findNextInGroup;
105
+ private findNextSpatial;
106
+ }
107
+
108
+ interface FocusProviderProps {
109
+ children: React__default.ReactNode;
110
+ options?: FocusManagerOptions;
111
+ }
112
+ declare function FocusProvider({ children, options }: FocusProviderProps): react_jsx_runtime.JSX.Element;
113
+
114
+ type KeyAction = {
115
+ type: 'move';
116
+ direction: FocusDirection;
117
+ } | {
118
+ type: 'select';
119
+ } | {
120
+ type: 'back';
121
+ } | {
122
+ type: 'unknown';
123
+ };
124
+ declare function resolveKeyAction(event: KeyboardEvent): KeyAction;
125
+ declare class KeyHandler {
126
+ private listeners;
127
+ private bound;
128
+ mount(): void;
129
+ unmount(): void;
130
+ subscribe(fn: (action: KeyAction) => void): () => void;
131
+ }
132
+
133
+ interface FocusContextValue {
134
+ manager: FocusManager;
135
+ keyHandler: KeyHandler;
136
+ }
137
+ declare const FocusContext: React$1.Context<FocusContextValue | null>;
138
+ declare function useFocusContext(): FocusContextValue;
139
+
140
+ interface UseFocusableOptions {
141
+ groupId?: string;
142
+ disabled?: boolean;
143
+ onFocus?: () => void;
144
+ onBlur?: () => void;
145
+ onSelect?: () => void;
146
+ autoFocus?: boolean;
147
+ }
148
+ interface UseFocusableResult {
149
+ ref: React.RefObject<HTMLElement>;
150
+ focused: boolean;
151
+ focusableProps: {
152
+ 'data-focusable': string;
153
+ 'data-focused': boolean;
154
+ tabIndex: number;
155
+ };
156
+ }
157
+ declare function useFocusable(options?: UseFocusableOptions): UseFocusableResult;
158
+ type UseFocusGroupOptions = Omit<FocusGroup$1, 'id' | 'lastFocusedId' | 'parentId'>;
159
+ declare function useFocusGroup(options: UseFocusGroupOptions): {
160
+ groupId: string;
161
+ };
162
+
163
+ interface FocusableProps extends UseFocusableOptions {
164
+ children: React__default.ReactNode | ((focused: boolean) => React__default.ReactNode);
165
+ as?: React__default.ElementType;
166
+ className?: string;
167
+ style?: React__default.CSSProperties;
168
+ }
169
+ declare const Focusable: React__default.ForwardRefExoticComponent<FocusableProps & React__default.RefAttributes<HTMLElement>>;
170
+ interface FocusGroupProps extends UseFocusGroupOptions {
171
+ children: React__default.ReactNode;
172
+ as?: React__default.ElementType;
173
+ className?: string;
174
+ style?: React__default.CSSProperties;
175
+ }
176
+ declare function FocusGroup({ children, as: Tag, className, style, ...options }: FocusGroupProps): react_jsx_runtime.JSX.Element;
177
+
178
+ export { FocusContext, type FocusDirection, FocusGroup, type FocusGroup$1 as FocusGroupType, FocusManager, type FocusManagerOptions, FocusProvider, type FocusState, Focusable, type FocusableId, type FocusableNode, KeyHandler, type NavigateOptions, type Route, type RouteDefinition, type RouteParams, type RouteQuery, type RouteSegment, Router, RouterContext, TableApp, type UseFocusGroupOptions, type UseFocusableOptions, type UseFocusableResult, defineRoutes, resolveKeyAction, useFocusContext, useFocusGroup, useFocusable, useParams, useQuery, useRouter };