green-screen-react 0.3.0 → 1.0.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/dist/index.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
+ import { ScreenData, ConnectionStatus, ConnectConfig, ProtocolType } from 'green-screen-types';
4
+ export { ConnectConfig, ConnectionStatus, Field, ScreenData, ProtocolType as TerminalProtocol } from 'green-screen-types';
3
5
 
4
- /**
5
- * Supported terminal protocol types.
6
- */
7
- type TerminalProtocol = 'tn5250' | 'tn3270' | 'vt' | 'hp6530';
8
6
  /**
9
7
  * Protocol-specific color/rendering conventions.
10
8
  */
@@ -22,7 +20,7 @@ interface ProtocolColorProfile {
22
20
  */
23
21
  interface ProtocolProfile {
24
22
  /** Protocol identifier */
25
- protocol: TerminalProtocol;
23
+ protocol: string;
26
24
  /** Human-readable name */
27
25
  displayName: string;
28
26
  /** Default terminal dimensions */
@@ -35,65 +33,6 @@ interface ProtocolProfile {
35
33
  /** Boot loader default text */
36
34
  bootText: string;
37
35
  }
38
- /**
39
- * Field definition from the terminal data stream.
40
- * Describes an input or protected field on the terminal screen.
41
- */
42
- interface Field {
43
- /** 0-based row index */
44
- row: number;
45
- /** 0-based column index */
46
- col: number;
47
- /** Field length in characters */
48
- length: number;
49
- /** Whether the field accepts user input */
50
- is_input: boolean;
51
- /** Whether the field is protected (read-only) */
52
- is_protected: boolean;
53
- /** Whether the field is displayed with high intensity (bright/white) */
54
- is_highlighted?: boolean;
55
- /** Whether the field is displayed in reverse video */
56
- is_reverse?: boolean;
57
- }
58
- /**
59
- * Screen data returned by the adapter.
60
- * Represents the current state of the terminal screen.
61
- */
62
- interface ScreenData {
63
- /** Screen content as newline-separated text (e.g. 24 lines of 80 chars) */
64
- content: string;
65
- /** 0-based cursor row */
66
- cursor_row: number;
67
- /** 0-based cursor column */
68
- cursor_col: number;
69
- /** Number of rows (default 24) */
70
- rows?: number;
71
- /** Number of columns (default 80) */
72
- cols?: number;
73
- /** Field definitions on the current screen */
74
- fields?: Field[];
75
- /** Unique identifier for the current screen state */
76
- screen_signature?: string;
77
- /** ISO timestamp of when this screen was captured */
78
- timestamp?: string;
79
- }
80
- /**
81
- * Connection status information.
82
- */
83
- interface ConnectionStatus {
84
- /** Whether a TCP connection is established */
85
- connected: boolean;
86
- /** Current connection state */
87
- status: 'disconnected' | 'connecting' | 'connected' | 'authenticated' | 'error';
88
- /** Terminal protocol in use */
89
- protocol?: TerminalProtocol;
90
- /** Host address */
91
- host?: string;
92
- /** Authenticated username */
93
- username?: string;
94
- /** Error message if status is 'error' */
95
- error?: string;
96
- }
97
36
  /**
98
37
  * Result from a send operation (text or key).
99
38
  */
@@ -133,29 +72,16 @@ interface TerminalAdapter {
133
72
  /** Reconnect to the host */
134
73
  reconnect(): Promise<SendResult>;
135
74
  }
136
- /**
137
- * Configuration passed from the inline sign-in form to adapter.connect().
138
- */
139
- interface ConnectConfig {
140
- /** Target host address */
141
- host: string;
142
- /** Target port (optional, adapter/server can default per protocol) */
143
- port?: number;
144
- /** Terminal protocol */
145
- protocol: TerminalProtocol;
146
- /** Username for authentication */
147
- username: string;
148
- /** Password for authentication */
149
- password: string;
150
- }
151
- /** @deprecated Use `TerminalAdapter` instead */
152
- type TN5250Adapter = TerminalAdapter;
153
75
 
154
76
  interface GreenScreenTerminalProps {
155
- /** Adapter for communicating with the terminal backend */
156
- adapter: TerminalAdapter;
77
+ /** Adapter for communicating with the terminal backend (optional — auto-created from sign-in form or baseUrl) */
78
+ adapter?: TerminalAdapter;
79
+ /** Base URL for the terminal API — convenience shorthand that auto-creates a RestAdapter */
80
+ baseUrl?: string;
81
+ /** Worker/proxy WebSocket URL — convenience shorthand that auto-creates a WebSocketAdapter */
82
+ workerUrl?: string;
157
83
  /** Terminal protocol (determines color conventions, header label, etc.) */
158
- protocol?: TerminalProtocol;
84
+ protocol?: ProtocolType;
159
85
  /** Custom protocol profile (overrides protocol param) */
160
86
  protocolProfile?: ProtocolProfile;
161
87
  /** Direct screen data injection (bypasses polling) */
@@ -178,12 +104,16 @@ interface GreenScreenTerminalProps {
178
104
  typingAnimation?: boolean;
179
105
  /** Typing animation budget in ms (default 60) */
180
106
  typingBudgetMs?: number;
181
- /** Show inline sign-in form when disconnected (default false) */
107
+ /** Show inline sign-in form when disconnected (default true) */
182
108
  inlineSignIn?: boolean;
183
109
  /** Default protocol for the sign-in form dropdown (default 'tn5250') */
184
- defaultProtocol?: TerminalProtocol;
110
+ defaultProtocol?: ProtocolType;
185
111
  /** Callback when sign-in form is submitted */
186
112
  onSignIn?: (config: ConnectConfig) => void;
113
+ /** Show "press Enter to continue" hint after auto sign-in (for external adapter flows) */
114
+ autoSignedIn?: boolean;
115
+ /** Disable auto-focus on the terminal after connecting (default false) */
116
+ autoFocusDisabled?: boolean;
187
117
  /** Custom boot loader element, or false to disable */
188
118
  bootLoader?: React.ReactNode | false;
189
119
  /** Content for the right side of the header */
@@ -201,8 +131,6 @@ interface GreenScreenTerminalProps {
201
131
  /** Inline styles */
202
132
  style?: React.CSSProperties;
203
133
  }
204
- /** @deprecated Use GreenScreenTerminalProps instead */
205
- type TN5250TerminalProps = GreenScreenTerminalProps;
206
134
  /**
207
135
  * GreenScreenTerminal — Multi-protocol legacy terminal emulator component.
208
136
  *
@@ -216,9 +144,7 @@ type TN5250TerminalProps = GreenScreenTerminalProps;
216
144
  *
217
145
  * Supports: TN5250 (IBM i), TN3270 (z/OS), VT (OpenVMS/Pick), HP 6530 (NonStop)
218
146
  */
219
- declare function GreenScreenTerminal({ adapter, protocol, protocolProfile: customProfile, screenData: externalScreenData, connectionStatus: externalStatus, readOnly, pollInterval, autoReconnect: autoReconnectEnabled, maxReconnectAttempts: maxAttempts, embedded, showHeader, typingAnimation, typingBudgetMs, inlineSignIn, defaultProtocol: signInDefaultProtocol, onSignIn, bootLoader, headerRight, overlay, onNotification, onScreenChange, onMinimize, className, style, }: GreenScreenTerminalProps): react_jsx_runtime.JSX.Element;
220
- /** @deprecated Use GreenScreenTerminal instead */
221
- declare const TN5250Terminal: typeof GreenScreenTerminal;
147
+ declare function GreenScreenTerminal({ adapter: externalAdapter, baseUrl, workerUrl, protocol, protocolProfile: customProfile, screenData: externalScreenData, connectionStatus: externalStatus, readOnly, pollInterval, autoReconnect: autoReconnectEnabled, maxReconnectAttempts: maxAttempts, embedded, showHeader, typingAnimation, typingBudgetMs, inlineSignIn, defaultProtocol: signInDefaultProtocol, onSignIn, autoSignedIn, autoFocusDisabled, bootLoader, headerRight, overlay, onNotification, onScreenChange, onMinimize, className, style, }: GreenScreenTerminalProps): react_jsx_runtime.JSX.Element;
222
148
 
223
149
  interface TerminalBootLoaderProps {
224
150
  /** Text to display during boot animation */
@@ -236,6 +162,40 @@ interface TerminalBootLoaderProps {
236
162
  */
237
163
  declare function TerminalBootLoader({ brandText, charSpeed, logo, height, }: TerminalBootLoaderProps): react_jsx_runtime.JSX.Element;
238
164
 
165
+ interface InlineSignInProps {
166
+ defaultProtocol: ProtocolType;
167
+ loading: boolean;
168
+ error: string | null;
169
+ onConnect: (config: ConnectConfig) => void;
170
+ }
171
+ declare function InlineSignIn({ defaultProtocol, loading: externalLoading, error, onConnect }: InlineSignInProps): react_jsx_runtime.JSX.Element;
172
+
173
+ declare const TerminalIcon: ({ size }: {
174
+ size?: number;
175
+ }) => react_jsx_runtime.JSX.Element;
176
+ declare const WifiIcon: ({ size, className, style: s }: {
177
+ size?: number;
178
+ className?: string;
179
+ style?: React.CSSProperties;
180
+ }) => react_jsx_runtime.JSX.Element;
181
+ declare const WifiOffIcon: ({ size, className, style: s }: {
182
+ size?: number;
183
+ className?: string;
184
+ style?: React.CSSProperties;
185
+ }) => react_jsx_runtime.JSX.Element;
186
+ declare const AlertTriangleIcon: ({ size }: {
187
+ size?: number;
188
+ }) => react_jsx_runtime.JSX.Element;
189
+ declare const RefreshIcon: ({ size, className }: {
190
+ size?: number;
191
+ className?: string;
192
+ }) => react_jsx_runtime.JSX.Element;
193
+ declare const KeyIcon: ({ size, style: s }: {
194
+ size?: number;
195
+ style?: React.CSSProperties;
196
+ }) => react_jsx_runtime.JSX.Element;
197
+ declare const MinimizeIcon: () => react_jsx_runtime.JSX.Element;
198
+
239
199
  interface RestAdapterOptions {
240
200
  /** Base URL for the terminal API (e.g. "https://myhost.com/api/terminal") */
241
201
  baseUrl: string;
@@ -272,6 +232,65 @@ declare class RestAdapter implements TerminalAdapter {
272
232
  reconnect(): Promise<SendResult>;
273
233
  }
274
234
 
235
+ interface WebSocketAdapterOptions {
236
+ /** URL of the green-screen proxy or worker. Auto-detected from env vars, defaults to http://localhost:3001 */
237
+ workerUrl?: string;
238
+ }
239
+ /**
240
+ * WebSocket adapter that connects to a green-screen proxy or Cloudflare Worker.
241
+ * The backend holds the TCP connection to the legacy host and relays protocol data.
242
+ *
243
+ * Unlike RestAdapter (which polls over HTTP), this adapter receives real-time
244
+ * screen updates via WebSocket push.
245
+ *
246
+ * workerUrl resolution order:
247
+ * 1. Explicit `workerUrl` option
248
+ * 2. VITE_GREEN_SCREEN_URL / VITE_WORKER_URL (Vite)
249
+ * 3. NEXT_PUBLIC_GREEN_SCREEN_URL (Next.js)
250
+ * 4. REACT_APP_GREEN_SCREEN_URL (CRA)
251
+ * 5. http://localhost:3001
252
+ */
253
+ declare class WebSocketAdapter implements TerminalAdapter {
254
+ private workerUrl;
255
+ private ws;
256
+ private screen;
257
+ private status;
258
+ private pendingScreenResolver;
259
+ private pendingConnectResolver;
260
+ private connectingPromise;
261
+ private screenListeners;
262
+ private statusListeners;
263
+ private _sessionId;
264
+ constructor(options?: WebSocketAdapterOptions);
265
+ private static detectEnvUrl;
266
+ /** The proxy-side session ID (available after connect or reattach) */
267
+ get sessionId(): string | null;
268
+ /** Subscribe to real-time screen updates */
269
+ onScreen(listener: (screen: ScreenData) => void): () => void;
270
+ /** Subscribe to status changes */
271
+ onStatus(listener: (status: ConnectionStatus) => void): () => void;
272
+ getScreen(): Promise<ScreenData | null>;
273
+ getStatus(): Promise<ConnectionStatus>;
274
+ sendText(text: string): Promise<SendResult>;
275
+ sendKey(key: string): Promise<SendResult>;
276
+ connect(config?: ConnectConfig): Promise<SendResult>;
277
+ /**
278
+ * Reattach to an existing proxy session (e.g. after page reload).
279
+ * The proxy keeps the TCP connection alive; this just reconnects the
280
+ * WebSocket and receives the current screen.
281
+ */
282
+ reattach(sessionId: string): Promise<SendResult>;
283
+ disconnect(): Promise<SendResult>;
284
+ reconnect(): Promise<SendResult>;
285
+ /** Close the WebSocket without sending disconnect (session stays alive on proxy) */
286
+ dispose(): void;
287
+ private ensureWebSocket;
288
+ private handleMessage;
289
+ private sendAndWaitForScreen;
290
+ private screenToResult;
291
+ private wsSend;
292
+ }
293
+
275
294
  /**
276
295
  * Hook for typing animation effect on terminal screen content.
277
296
  * Reveals characters progressively when screen content changes.
@@ -342,17 +361,11 @@ declare function useTerminalInput(adapter: TerminalAdapter): {
342
361
  sendText: (text: string) => Promise<SendResult>;
343
362
  sendKey: (key: string) => Promise<SendResult>;
344
363
  };
345
- /** @deprecated Use `useTerminalConnection` instead */
346
- declare const useTN5250Connection: typeof useTerminalConnection;
347
- /** @deprecated Use `useTerminalScreen` instead */
348
- declare const useTN5250Screen: typeof useTerminalScreen;
349
- /** @deprecated Use `useTerminalInput` instead */
350
- declare const useTN5250Terminal: typeof useTerminalInput;
351
364
 
352
365
  /**
353
366
  * Get a protocol profile by type. Defaults to TN5250 for backward compatibility.
354
367
  */
355
- declare function getProtocolProfile(protocol?: TerminalProtocol): ProtocolProfile;
368
+ declare function getProtocolProfile(protocol?: ProtocolType): ProtocolProfile;
356
369
 
357
370
  declare const tn5250Profile: ProtocolProfile;
358
371
 
@@ -397,4 +410,4 @@ declare function parseHeaderRow(line: string): {
397
410
  colorClass: string;
398
411
  }[] | null;
399
412
 
400
- export { type ConnectConfig, type ConnectionStatus, type Field, GreenScreenTerminal, type GreenScreenTerminalProps, type ProtocolColorProfile, type ProtocolProfile, RestAdapter, type RestAdapterOptions, type ScreenData, type SendResult, type TN5250Adapter, TN5250Terminal, type TN5250TerminalProps, type TerminalAdapter, TerminalBootLoader, type TerminalBootLoaderProps, type TerminalProtocol, getProtocolProfile, getRowColorClass, hp6530Profile, isFieldEntry, parseHeaderRow, positionToRowCol, tn3270Profile, tn5250Profile, useTN5250Connection, useTN5250Screen, useTN5250Terminal, useTerminalConnection, useTerminalInput, useTerminalScreen, useTypingAnimation, vtProfile };
413
+ export { AlertTriangleIcon, GreenScreenTerminal, type GreenScreenTerminalProps, InlineSignIn, type InlineSignInProps, KeyIcon, MinimizeIcon, type ProtocolColorProfile, type ProtocolProfile, RefreshIcon, RestAdapter, type RestAdapterOptions, type SendResult, type TerminalAdapter, TerminalBootLoader, type TerminalBootLoaderProps, TerminalIcon, WebSocketAdapter, type WebSocketAdapterOptions, WifiIcon, WifiOffIcon, getProtocolProfile, getRowColorClass, hp6530Profile, isFieldEntry, parseHeaderRow, positionToRowCol, tn3270Profile, tn5250Profile, useTerminalConnection, useTerminalInput, useTerminalScreen, useTypingAnimation, vtProfile };