@bobfrankston/msgapidefs 0.1.2 → 0.1.3

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 CHANGED
@@ -10,47 +10,28 @@ npm install @bobfrankston/msgapidefs
10
10
 
11
11
  ## Usage
12
12
 
13
- ### TypeScript
14
-
15
13
  ```typescript
16
- import type { MsgAPI } from '@bobfrankston/msgapidefs';
17
- import { isMsgAPI, getMsgAPI } from '@bobfrankston/msgapidefs';
18
-
19
- // Option 1: Type the global window.msgapi
20
- declare global {
21
- interface Window {
22
- msgapi?: MsgAPI;
23
- }
24
- }
25
-
26
- // Check if running in msgview/msger
27
- if (isMsgAPI()) {
28
- window.msgapi!.setTitle('My Application');
29
- window.msgapi!.saveData('lastOpened', new Date().toISOString());
30
- }
31
-
32
- // Option 2: Use getMsgAPI() for cross-platform compatibility
33
- const msgapi = getMsgAPI();
34
- msgapi.saveData('userPrefs', { theme: 'dark' }); // Works in both msgview/msger and browser!
35
- msgapi.setTitle('My App'); // Only works in msgview/msger, no-op in browser
36
- ```
37
-
38
- ### JavaScript
14
+ // Import to register global window.msgapi type
15
+ import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
16
+ // Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
39
17
 
40
- ```javascript
41
- import { isMsgAPI, getMsgAPI } from '@bobfrankston/msgapidefs';
18
+ // Or import types explicitly
19
+ import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
42
20
 
43
- const msgapi = getMsgAPI();
21
+ // msgapi provides APIs not available in browsers/webviews
22
+ if (window.msgapi) {
23
+ // Window control beyond browser capabilities
24
+ window.msgapi.setFullscreen(true);
25
+ window.msgapi.setAlwaysOnTop(true);
44
26
 
45
- // Data persistence (works in both msgview/msger and browser)
46
- msgapi.saveData('userSettings', { fontSize: 14, theme: 'dark' });
47
- const settings = msgapi.loadData('userSettings', { fontSize: 12 });
48
-
49
- // Window control (msgview/msger only, gracefully degrades in browser)
50
- if (isMsgAPI()) {
51
- msgapi.toggleFullscreen();
52
- msgapi.setAlwaysOnTop(true);
27
+ // File system access (requires allowFs flag)
28
+ const file = await window.msgapi.fs?.selectFile();
53
29
  }
30
+
31
+ // For standard browser APIs, use native methods:
32
+ document.title = 'My App'; // Instead of msgapi.setTitle()
33
+ localStorage.setItem('key', 'value'); // Instead of msgapi.saveData()
34
+ window.close(); // Instead of msgapi.close() if not passing result
54
35
  ```
55
36
 
56
37
  ## API Reference
@@ -64,17 +45,9 @@ if (isMsgAPI()) {
64
45
  - `setSize(width, height)` - Set window size
65
46
  - `setPosition(x, y)` - Set window position
66
47
  - `setAlwaysOnTop(enabled: boolean)` - Keep window on top
67
- - `setTitle(title: string)` - Set window title
68
- - `close(result?)` - Close window with optional result
69
-
70
- ### Data Persistence
71
-
72
- - `saveData(key, value)` - Save data to localStorage
73
- - `loadData(key, defaultValue?)` - Load data from localStorage
74
- - `removeData(key)` - Remove data
75
- - `clearData()` - Clear all msgapi data
48
+ - `close(result?)` - Close window and return result to parent process
76
49
 
77
- ### File System (Coming Soon)
50
+ ### File System
78
51
 
79
52
  - `fs.selectFile(options?)` - Open file picker
80
53
  - `fs.selectFiles(options?)` - Open multi-file picker
@@ -112,15 +85,6 @@ The samples demonstrate:
112
85
  - Session management
113
86
  - And more!
114
87
 
115
- ## Browser Compatibility
116
-
117
- The `getMsgAPI()` function returns a browser-compatible implementation:
118
-
119
- - **Data persistence**: Uses localStorage in both msgview/msger and browser
120
- - **Window control**: No-op in browser (except `setTitle` updates document.title)
121
- - **File system**: Not available in browser (`fs` is undefined)
122
-
123
- This allows you to write code once that works in both environments!
124
88
 
125
89
  ## Related Packages
126
90
 
package/msgapidefs.d.ts CHANGED
@@ -4,20 +4,7 @@
4
4
  * This module provides type-safe access to msgapi's window control,
5
5
  * data persistence, and file system features (used by msgview and msger).
6
6
  *
7
- * Usage:
8
- * ```typescript
9
- * // Import to register global window.msgapi type (browser direct import)
10
- * import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
11
- * // Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
12
- *
13
- * // Or import types explicitly
14
- * import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
15
- *
16
- * // window.msgapi is now typed automatically
17
- * if (window.msgapi) {
18
- * window.msgapi.setTitle('My App');
19
- * }
20
- * ```
7
+ * See README.md for complete usage documentation and examples.
21
8
  */
22
9
  /**
23
10
  * Result object returned when the window closes
@@ -133,14 +120,7 @@ export interface MsgAPI {
133
120
  */
134
121
  setAlwaysOnTop(enabled: boolean): void;
135
122
  /**
136
- * Set window title
137
- * @param title - New window title
138
- * @example
139
- * msgapi.setTitle("My Application");
140
- */
141
- setTitle(title: string): void;
142
- /**
143
- * Close the window
123
+ * Close the window and return result to parent process
144
124
  * @param result - Optional result to return to parent process
145
125
  * @example
146
126
  * // Close with default dismissed result
@@ -150,48 +130,6 @@ export interface MsgAPI {
150
130
  * msgapi.close({button: 'OK', value: 'user data'});
151
131
  */
152
132
  close(result?: Partial<MsgResult>): void;
153
- /**
154
- * Send result and close window (legacy compatibility)
155
- * @param result - Result to return to parent process
156
- * @example
157
- * msgapi.sendResult({button: 'Submit', value: 'form data'});
158
- */
159
- sendResult(result: Partial<MsgResult>): void;
160
- /**
161
- * Save data to persistent storage
162
- * Data is stored with 'msgapi_' prefix in localStorage
163
- * @param key - Storage key
164
- * @param value - Value to store (will be JSON.stringify'd)
165
- * @returns true on success, false on failure
166
- * @example
167
- * msgapi.saveData('userPrefs', {theme: 'dark', fontSize: 14});
168
- */
169
- saveData(key: string, value: any): boolean;
170
- /**
171
- * Load data from persistent storage
172
- * @param key - Storage key
173
- * @param defaultValue - Default value if key not found
174
- * @returns Stored value or defaultValue
175
- * @example
176
- * const prefs = msgapi.loadData('userPrefs', {theme: 'light'});
177
- */
178
- loadData<T = any>(key: string, defaultValue?: T): T;
179
- /**
180
- * Remove data from persistent storage
181
- * @param key - Storage key to remove
182
- * @returns true on success, false on failure
183
- * @example
184
- * msgapi.removeData('tempData');
185
- */
186
- removeData(key: string): boolean;
187
- /**
188
- * Clear all msgapi data from persistent storage
189
- * Only removes items with 'msgapi_' prefix
190
- * @returns true on success, false on failure
191
- * @example
192
- * msgapi.clearData();
193
- */
194
- clearData(): boolean;
195
133
  /**
196
134
  * File system operations namespace
197
135
  */
package/msgapidefs.js CHANGED
@@ -4,19 +4,6 @@
4
4
  * This module provides type-safe access to msgapi's window control,
5
5
  * data persistence, and file system features (used by msgview and msger).
6
6
  *
7
- * Usage:
8
- * ```typescript
9
- * // Import to register global window.msgapi type (browser direct import)
10
- * import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
11
- * // Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
12
- *
13
- * // Or import types explicitly
14
- * import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
15
- *
16
- * // window.msgapi is now typed automatically
17
- * if (window.msgapi) {
18
- * window.msgapi.setTitle('My App');
19
- * }
20
- * ```
7
+ * See README.md for complete usage documentation and examples.
21
8
  */
22
9
  export {};
package/msgapidefs.ts CHANGED
@@ -4,20 +4,7 @@
4
4
  * This module provides type-safe access to msgapi's window control,
5
5
  * data persistence, and file system features (used by msgview and msger).
6
6
  *
7
- * Usage:
8
- * ```typescript
9
- * // Import to register global window.msgapi type (browser direct import)
10
- * import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
11
- * // Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
12
- *
13
- * // Or import types explicitly
14
- * import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
15
- *
16
- * // window.msgapi is now typed automatically
17
- * if (window.msgapi) {
18
- * window.msgapi.setTitle('My App');
19
- * }
20
- * ```
7
+ * See README.md for complete usage documentation and examples.
21
8
  */
22
9
 
23
10
  /**
@@ -146,15 +133,7 @@ export interface MsgAPI {
146
133
  setAlwaysOnTop(enabled: boolean): void;
147
134
 
148
135
  /**
149
- * Set window title
150
- * @param title - New window title
151
- * @example
152
- * msgapi.setTitle("My Application");
153
- */
154
- setTitle(title: string): void;
155
-
156
- /**
157
- * Close the window
136
+ * Close the window and return result to parent process
158
137
  * @param result - Optional result to return to parent process
159
138
  * @example
160
139
  * // Close with default dismissed result
@@ -165,59 +144,8 @@ export interface MsgAPI {
165
144
  */
166
145
  close(result?: Partial<MsgResult>): void;
167
146
 
168
- /**
169
- * Send result and close window (legacy compatibility)
170
- * @param result - Result to return to parent process
171
- * @example
172
- * msgapi.sendResult({button: 'Submit', value: 'form data'});
173
- */
174
- sendResult(result: Partial<MsgResult>): void;
175
-
176
- // ========================================
177
- // Data Persistence (localStorage wrapper)
178
- // ========================================
179
-
180
- /**
181
- * Save data to persistent storage
182
- * Data is stored with 'msgapi_' prefix in localStorage
183
- * @param key - Storage key
184
- * @param value - Value to store (will be JSON.stringify'd)
185
- * @returns true on success, false on failure
186
- * @example
187
- * msgapi.saveData('userPrefs', {theme: 'dark', fontSize: 14});
188
- */
189
- saveData(key: string, value: any): boolean;
190
-
191
- /**
192
- * Load data from persistent storage
193
- * @param key - Storage key
194
- * @param defaultValue - Default value if key not found
195
- * @returns Stored value or defaultValue
196
- * @example
197
- * const prefs = msgapi.loadData('userPrefs', {theme: 'light'});
198
- */
199
- loadData<T = any>(key: string, defaultValue?: T): T;
200
-
201
- /**
202
- * Remove data from persistent storage
203
- * @param key - Storage key to remove
204
- * @returns true on success, false on failure
205
- * @example
206
- * msgapi.removeData('tempData');
207
- */
208
- removeData(key: string): boolean;
209
-
210
- /**
211
- * Clear all msgapi data from persistent storage
212
- * Only removes items with 'msgapi_' prefix
213
- * @returns true on success, false on failure
214
- * @example
215
- * msgapi.clearData();
216
- */
217
- clearData(): boolean;
218
-
219
147
  // ========================================
220
- // File System Access (to be implemented)
148
+ // File System Access
221
149
  // ========================================
222
150
 
223
151
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/msgapidefs",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "TypeScript definitions for msgapi JavaScript API (msgview/msger)",
5
5
  "type": "module",
6
6
  "main": "./msgapidefs.js",