green-screen-react 0.4.0 → 1.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/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
75
 
152
76
  interface GreenScreenTerminalProps {
153
77
  /** Adapter for communicating with the terminal backend (optional — auto-created from sign-in form or baseUrl) */
154
78
  adapter?: TerminalAdapter;
155
79
  /** Base URL for the terminal API — convenience shorthand that auto-creates a RestAdapter */
156
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) */
@@ -181,9 +107,13 @@ interface GreenScreenTerminalProps {
181
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 */
@@ -214,7 +144,7 @@ interface GreenScreenTerminalProps {
214
144
  *
215
145
  * Supports: TN5250 (IBM i), TN3270 (z/OS), VT (OpenVMS/Pick), HP 6530 (NonStop)
216
146
  */
217
- declare function GreenScreenTerminal({ adapter: externalAdapter, baseUrl, 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;
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;
218
148
 
219
149
  interface TerminalBootLoaderProps {
220
150
  /** Text to display during boot animation */
@@ -233,12 +163,12 @@ interface TerminalBootLoaderProps {
233
163
  declare function TerminalBootLoader({ brandText, charSpeed, logo, height, }: TerminalBootLoaderProps): react_jsx_runtime.JSX.Element;
234
164
 
235
165
  interface InlineSignInProps {
236
- defaultProtocol: TerminalProtocol;
166
+ defaultProtocol: ProtocolType;
237
167
  loading: boolean;
238
168
  error: string | null;
239
169
  onConnect: (config: ConnectConfig) => void;
240
170
  }
241
- declare function InlineSignIn({ defaultProtocol, loading, error, onConnect }: InlineSignInProps): react_jsx_runtime.JSX.Element;
171
+ declare function InlineSignIn({ defaultProtocol, loading: externalLoading, error, onConnect }: InlineSignInProps): react_jsx_runtime.JSX.Element;
242
172
 
243
173
  declare const TerminalIcon: ({ size }: {
244
174
  size?: number;
@@ -303,25 +233,38 @@ declare class RestAdapter implements TerminalAdapter {
303
233
  }
304
234
 
305
235
  interface WebSocketAdapterOptions {
306
- /** URL of the green-screen proxy or worker. Defaults to http://localhost:3001 */
236
+ /** URL of the green-screen proxy or worker. Auto-detected from env vars, defaults to http://localhost:3001 */
307
237
  workerUrl?: string;
308
238
  }
309
239
  /**
310
- * WebSocket adapter that connects to a Cloudflare Worker running green-screen-worker.
311
- * The Worker holds the TCP connection to the legacy host and relays protocol data.
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.
312
242
  *
313
243
  * Unlike RestAdapter (which polls over HTTP), this adapter receives real-time
314
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
315
252
  */
316
253
  declare class WebSocketAdapter implements TerminalAdapter {
317
254
  private workerUrl;
318
255
  private ws;
319
256
  private screen;
320
257
  private status;
321
- private pendingResolvers;
258
+ private pendingScreenResolver;
259
+ private pendingConnectResolver;
260
+ private connectingPromise;
322
261
  private screenListeners;
323
262
  private statusListeners;
263
+ private _sessionId;
324
264
  constructor(options?: WebSocketAdapterOptions);
265
+ private static detectEnvUrl;
266
+ /** The proxy-side session ID (available after connect or reattach) */
267
+ get sessionId(): string | null;
325
268
  /** Subscribe to real-time screen updates */
326
269
  onScreen(listener: (screen: ScreenData) => void): () => void;
327
270
  /** Subscribe to status changes */
@@ -331,9 +274,15 @@ declare class WebSocketAdapter implements TerminalAdapter {
331
274
  sendText(text: string): Promise<SendResult>;
332
275
  sendKey(key: string): Promise<SendResult>;
333
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>;
334
283
  disconnect(): Promise<SendResult>;
335
284
  reconnect(): Promise<SendResult>;
336
- /** Close the WebSocket without sending disconnect */
285
+ /** Close the WebSocket without sending disconnect (session stays alive on proxy) */
337
286
  dispose(): void;
338
287
  private ensureWebSocket;
339
288
  private handleMessage;
@@ -416,7 +365,7 @@ declare function useTerminalInput(adapter: TerminalAdapter): {
416
365
  /**
417
366
  * Get a protocol profile by type. Defaults to TN5250 for backward compatibility.
418
367
  */
419
- declare function getProtocolProfile(protocol?: TerminalProtocol): ProtocolProfile;
368
+ declare function getProtocolProfile(protocol?: ProtocolType): ProtocolProfile;
420
369
 
421
370
  declare const tn5250Profile: ProtocolProfile;
422
371
 
@@ -461,4 +410,4 @@ declare function parseHeaderRow(line: string): {
461
410
  colorClass: string;
462
411
  }[] | null;
463
412
 
464
- export { AlertTriangleIcon, type ConnectConfig, type ConnectionStatus, type Field, GreenScreenTerminal, type GreenScreenTerminalProps, InlineSignIn, type InlineSignInProps, KeyIcon, MinimizeIcon, type ProtocolColorProfile, type ProtocolProfile, RefreshIcon, RestAdapter, type RestAdapterOptions, type ScreenData, type SendResult, type TerminalAdapter, TerminalBootLoader, type TerminalBootLoaderProps, TerminalIcon, type TerminalProtocol, WebSocketAdapter, type WebSocketAdapterOptions, WifiIcon, WifiOffIcon, getProtocolProfile, getRowColorClass, hp6530Profile, isFieldEntry, parseHeaderRow, positionToRowCol, tn3270Profile, tn5250Profile, 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 };