@withalleo/ewidget-utils 1.0.9 → 1.0.12

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.
Files changed (2) hide show
  1. package/README.md +171 -199
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -26,7 +26,7 @@ This package ships a browser bundle at `@withalleo/ewidget-utils/browser` (UMD).
26
26
  <script src="https://unpkg.com/@withalleo/ewidget-utils/dist/ewidget-utils.umd.cjs"></script>
27
27
  <script>
28
28
  const alleo = AlleoEWidget.getEmbedWidgetMessenger({ debug: true })
29
-
29
+
30
30
  document.getElementById('button').onclick = () =>
31
31
  alleo.addContent({ type: 'notepad', textFormat: 'markdown', text: '# Status\n\nAll systems go.' })
32
32
  </script>
@@ -34,6 +34,176 @@ This package ships a browser bundle at `@withalleo/ewidget-utils/browser` (UMD).
34
34
  </html>
35
35
  ```
36
36
 
37
+ #### Commands
38
+
39
+ **Outgoing (iframe -> widget)**
40
+
41
+ - `EmbedWidgetCommandMap` defines the `command` names and their `params` shapes:
42
+ - `triggerAction`, `addContent`, `requestSyncedStatus`, `setSyncedStatus`.
43
+ - `EmbedWidgetCommandEnvelope` is the outbound `postMessage` payload shape:
44
+ - `{ type: 'EmbedWidgetCommand', command, params }`.
45
+
46
+ **Outgoing examples**
47
+
48
+ ```js
49
+ messenger.triggerAction('demo', {
50
+ 'demo-param': 'Hello from iframe',
51
+ })
52
+ ```
53
+
54
+ ```js
55
+ messenger.addContent({
56
+ type: 'notepad',
57
+ textFormat: 'markdown',
58
+ text: '# Status\n\nAll systems go.',
59
+ })
60
+ ```
61
+
62
+ ```js
63
+ messenger.requestSyncedStatus()
64
+ ```
65
+
66
+ ```js
67
+ messenger.setSyncedStatus({
68
+ color: '#FFAA33',
69
+ })
70
+ ```
71
+
72
+ #### Message envelopes
73
+
74
+ **Incoming (widget -> iframe)**
75
+
76
+ - `EmbedWidgetMessageMap` defines inbound `command` names and `params` shapes:
77
+ - `syncedStatusUpdate`, `incomingAction`.
78
+ - `EmbedWidgetMessageEnvelope` is the inbound message shape:
79
+ - `{ type: 'EmbedWidgetMessage', command, params }`.
80
+ - `EmbedWidgetMessageEvent` is the normalized event passed to `onMessage` handlers:
81
+ - `{ command, params, raw }`.
82
+
83
+ **Incoming examples (one per event)**
84
+
85
+ ```js
86
+ messenger.onSyncedStatusUpdate((status) => {
87
+ console.log('synced status', status)
88
+ })
89
+ ```
90
+
91
+ ```js
92
+ messenger.onIncomingAction(({ actionId, data }) => {
93
+ console.log('incoming action', actionId, data)
94
+ })
95
+ ```
96
+
97
+ ## API Reference
98
+
99
+ ### Exported helpers
100
+
101
+ #### `getAlleoEwidgetUtils(options?: AlleoEwidgetUtilsOptions): AlleoEwidgetUtils`
102
+
103
+ Returns a singleton instance of `AlleoEwidgetUtils`. If a browser global singleton already exists, the existing instance is reused.
104
+
105
+ #### `getEmbedWidgetMessenger(options?: EmbedWidgetMessengerOptions): EmbedWidgetMessenger`
106
+
107
+ Convenience helper that returns `getAlleoEwidgetUtils().createEmbedWidgetMessenger(options)`.
108
+
109
+ ### `EmbedWidgetMessenger`
110
+
111
+ #### Constructor
112
+
113
+ - `new EmbedWidgetMessenger(options?: EmbedWidgetMessengerOptions)`
114
+ - Initializes message handling and, by default, calls `startListening()`.
115
+
116
+ #### Options (`EmbedWidgetMessengerOptions`)
117
+
118
+ - `targetOrigin?: string` (default: `'*'`) - Passed to `postMessage` for outbound commands.
119
+ - `parentWindow?: Window` (default: `window.parent`) - The window that receives outbound commands.
120
+ - `autoListen?: boolean` (default: `true`) - Auto-register the `message` event listener.
121
+ - `debug?: boolean` (default: `false`) - Enables debug logging via `console.debug`.
122
+
123
+ #### Properties
124
+
125
+ - `isListening: boolean` - Whether the instance is currently listening for `message` events.
126
+
127
+ #### Methods (commands)
128
+
129
+ - `triggerAction(actionId: string, data?: Record<string, unknown>): void`
130
+ - Sends a `triggerAction` command. If `actionId` is missing, logs a debug message and skips sending.
131
+ - `addContent(params: AddContentParams): void`
132
+ - Sends an `addContent` command with the provided content payload.
133
+ - `requestSyncedStatus(): void`
134
+ - Sends a `requestSyncedStatus` command.
135
+ - `setSyncedStatus(status: Record<string, unknown>): void`
136
+ - Sends a `setSyncedStatus` command with a `status` object.
137
+
138
+ #### Methods (events)
139
+
140
+ - `onSyncedStatusUpdate(handler: (status: Record<string, unknown>) => void): () => void`
141
+ - Registers a handler for `syncedStatusUpdate` and returns an unsubscribe function.
142
+ - `onIncomingAction(handler: (payload: { actionId: string; data: Record<string, unknown> }) => void): () => void`
143
+ - Registers a handler for `incomingAction` and returns an unsubscribe function.
144
+ - `onMessage(handler: (event: EmbedWidgetMessageEvent) => void): () => void`
145
+ - Registers a handler for all widget messages and returns an unsubscribe function.
146
+
147
+ #### Methods (lifecycle)
148
+
149
+ - `startListening(): void`
150
+ - Adds a `message` event listener if running in a browser.
151
+ - `stopListening(): void`
152
+ - Removes the `message` event listener.
153
+ - `destroy(): void`
154
+ - Stops listening and clears all registered handlers.
155
+
156
+ ### `AlleoEwidgetUtils`
157
+
158
+ #### Constructor
159
+
160
+ - `new AlleoEwidgetUtils(options?: AlleoEwidgetUtilsOptions)`
161
+ - Creates an instance and calls `initialize()`.
162
+ - In the browser, a global singleton is stored so multiple bundle loads reuse a single instance.
163
+
164
+ #### Options (`AlleoEwidgetUtilsOptions`)
165
+
166
+ - `autoDestroy?: boolean` (default: `true`) - When `true`, attaches a `beforeunload` listener to call `destroy()`.
167
+ - `debug?: boolean` (default: `false`) - Enables debug logging via `console.debug`.
168
+
169
+ #### Properties
170
+
171
+ - `isInitialized: boolean` - `true` when initialized and not destroyed.
172
+
173
+ #### Methods
174
+
175
+ - `static getInstance(options?: AlleoEwidgetUtilsOptions): AlleoEwidgetUtils`
176
+ - Returns a singleton instance, creating one if needed.
177
+ - `createEmbedWidgetMessenger(options?: EmbedWidgetMessengerOptions): EmbedWidgetMessenger`
178
+ - Creates a new `EmbedWidgetMessenger` configured with the provided options.
179
+ - `initialize(): void`
180
+ - Idempotent; sets initialized state and attaches listeners when `autoDestroy` is enabled.
181
+ - `destroy(): void`
182
+ - Detaches listeners, clears the global singleton reference, and marks the instance destroyed.
183
+ - `log(message: string, data?: unknown): void`
184
+ - Debug logger gated by the `debug` option.
185
+
186
+ ### Types
187
+
188
+ #### `AddContentParams`
189
+
190
+ Union of the following shapes for `addContent`:
191
+
192
+ - `AddContentHtmlParams`
193
+ - `{ type: 'html', html: string }`
194
+ - `AddContentNotepadParams`
195
+ - `{ type: 'notepad', text?: string | string[], textFormat?: 'text' | 'markdown' | 'html' }`
196
+ - `AddContentStickyNoteParams`
197
+ - `{ type: 'sticky-note', text?: string, color?: string, outlineColor?: string, shape?: string }`
198
+ - `AddContentImageParams`
199
+ - `{ type: 'image', url: string }`
200
+ - `AddContentVideoParams`
201
+ - `{ type: 'video', fileId: string }`
202
+
203
+ ### Notes
204
+
205
+ - The `targetOrigin` option in `EmbedWidgetMessenger` should generally remain as `'*'` to allow communication with the widget.
206
+
37
207
  ## Samples
38
208
 
39
209
  Below are the exact sample files from `samples/`, included verbatim as quoted blocks.
@@ -230,201 +400,3 @@ Below are the exact sample files from `samples/`, included verbatim as quoted bl
230
400
  > </body>
231
401
  > </html>
232
402
  > ```
233
-
234
- ## API Reference
235
-
236
- ### Exported helpers
237
-
238
- #### `getAlleoEwidgetUtils(options?: AlleoEwidgetUtilsOptions): AlleoEwidgetUtils`
239
-
240
- Returns a singleton instance of `AlleoEwidgetUtils`. If a browser global singleton already exists, the existing instance is reused.
241
-
242
- #### `getEmbedWidgetMessenger(options?: EmbedWidgetMessengerOptions): EmbedWidgetMessenger`
243
-
244
- Convenience helper that returns `getAlleoEwidgetUtils().createEmbedWidgetMessenger(options)`.
245
-
246
- ### `EmbedWidgetMessenger`
247
-
248
- #### Constructor
249
-
250
- - `new EmbedWidgetMessenger(options?: EmbedWidgetMessengerOptions)`
251
- - Initializes message handling and, by default, calls `startListening()`.
252
-
253
- #### Options (`EmbedWidgetMessengerOptions`)
254
-
255
- - `targetOrigin?: string` (default: `'*'`) - Passed to `postMessage` for outbound commands.
256
- - `parentWindow?: Window` (default: `window.parent`) - The window that receives outbound commands.
257
- - `autoListen?: boolean` (default: `true`) - Auto-register the `message` event listener.
258
- - `debug?: boolean` (default: `false`) - Enables debug logging via `console.debug`.
259
-
260
- #### Properties
261
-
262
- - `isListening: boolean` - Whether the instance is currently listening for `message` events.
263
-
264
- #### Methods (commands)
265
-
266
- - `triggerAction(actionId: string, data?: Record<string, unknown>): void`
267
- - Sends a `triggerAction` command. If `actionId` is missing, logs a debug message and skips sending.
268
- - `addContent(params: AddContentParams): void`
269
- - Sends an `addContent` command with the provided content payload.
270
- - `requestSyncedStatus(): void`
271
- - Sends a `requestSyncedStatus` command.
272
- - `setSyncedStatus(status: Record<string, unknown>): void`
273
- - Sends a `setSyncedStatus` command with a `status` object.
274
-
275
- #### Methods (events)
276
-
277
- - `onSyncedStatusUpdate(handler: (status: Record<string, unknown>) => void): () => void`
278
- - Registers a handler for `syncedStatusUpdate` and returns an unsubscribe function.
279
- - `onIncomingAction(handler: (payload: { actionId: string; data: Record<string, unknown> }) => void): () => void`
280
- - Registers a handler for `incomingAction` and returns an unsubscribe function.
281
- - `onMessage(handler: (event: EmbedWidgetMessageEvent) => void): () => void`
282
- - Registers a handler for all widget messages and returns an unsubscribe function.
283
-
284
- #### Methods (lifecycle)
285
-
286
- - `startListening(): void`
287
- - Adds a `message` event listener if running in a browser.
288
- - `stopListening(): void`
289
- - Removes the `message` event listener.
290
- - `destroy(): void`
291
- - Stops listening and clears all registered handlers.
292
-
293
-
294
-
295
- ### `AlleoEwidgetUtils`
296
-
297
- #### Constructor
298
-
299
- - `new AlleoEwidgetUtils(options?: AlleoEwidgetUtilsOptions)`
300
- - Creates an instance and calls `initialize()`.
301
- - In the browser, a global singleton is stored so multiple bundle loads reuse a single instance.
302
-
303
- #### Options (`AlleoEwidgetUtilsOptions`)
304
-
305
- - `autoDestroy?: boolean` (default: `true`) - When `true`, attaches a `beforeunload` listener to call `destroy()`.
306
- - `debug?: boolean` (default: `false`) - Enables debug logging via `console.debug`.
307
-
308
- #### Properties
309
-
310
- - `isInitialized: boolean` - `true` when initialized and not destroyed.
311
-
312
- #### Methods
313
-
314
- - `static getInstance(options?: AlleoEwidgetUtilsOptions): AlleoEwidgetUtils`
315
- - Returns a singleton instance, creating one if needed.
316
- - `createEmbedWidgetMessenger(options?: EmbedWidgetMessengerOptions): EmbedWidgetMessenger`
317
- - Creates a new `EmbedWidgetMessenger` configured with the provided options.
318
- - `initialize(): void`
319
- - Idempotent; sets initialized state and attaches listeners when `autoDestroy` is enabled.
320
- - `destroy(): void`
321
- - Detaches listeners, clears the global singleton reference, and marks the instance destroyed.
322
- - `log(message: string, data?: unknown): void`
323
- - Debug logger gated by the `debug` option.
324
-
325
- ### Types
326
-
327
- #### `AddContentParams`
328
-
329
- Union of the following shapes for `addContent`:
330
-
331
- - `AddContentHtmlParams`
332
- - `{ type: 'html', html: string }`
333
- - `AddContentNotepadParams`
334
- - `{ type: 'notepad', text?: string | string[], textFormat?: 'text' | 'markdown' | 'html' }`
335
- - `AddContentStickyNoteParams`
336
- - `{ type: 'sticky-note', text?: string, color?: string, outlineColor?: string, shape?: string }`
337
- - `AddContentImageParams`
338
- - `{ type: 'image', url: string }`
339
- - `AddContentVideoParams`
340
- - `{ type: 'video', fileId: string }`
341
-
342
- #### Command envelopes
343
-
344
- **Outgoing (iframe -> widget)**
345
-
346
- - `EmbedWidgetCommandMap` defines the `command` names and their `params` shapes:
347
- - `triggerAction`, `addContent`, `requestSyncedStatus`, `setSyncedStatus`.
348
- - `EmbedWidgetCommandEnvelope` is the outbound `postMessage` payload shape:
349
- - `{ type: 'EmbedWidgetCommand', command, params }`.
350
-
351
- **Outgoing examples**
352
-
353
- ```json
354
- {
355
- "type": "EmbedWidgetCommand",
356
- "command": "triggerAction",
357
- "params": {
358
- "actionId": "demo",
359
- "data": { "demo-param": "Hello from iframe" }
360
- }
361
- }
362
- ```
363
-
364
- ```json
365
- {
366
- "type": "EmbedWidgetCommand",
367
- "command": "addContent",
368
- "params": {
369
- "type": "notepad",
370
- "textFormat": "markdown",
371
- "text": "# Status\n\nAll systems go."
372
- }
373
- }
374
- ```
375
-
376
- ```json
377
- {
378
- "type": "EmbedWidgetCommand",
379
- "command": "requestSyncedStatus",
380
- "params": {}
381
- }
382
- ```
383
-
384
- ```json
385
- {
386
- "type": "EmbedWidgetCommand",
387
- "command": "setSyncedStatus",
388
- "params": {
389
- "status": { "color": "#FFAA33" }
390
- }
391
- }
392
- ```
393
-
394
- #### Message envelopes
395
-
396
- **Incoming (widget -> iframe)**
397
-
398
- - `EmbedWidgetMessageMap` defines inbound `command` names and `params` shapes:
399
- - `syncedStatusUpdate`, `incomingAction`.
400
- - `EmbedWidgetMessageEnvelope` is the inbound message shape:
401
- - `{ type: 'EmbedWidgetMessage', command, params }`.
402
- - `EmbedWidgetMessageEvent` is the normalized event passed to `onMessage` handlers:
403
- - `{ command, params, raw }`.
404
-
405
- **Incoming examples (one per event)**
406
-
407
- ```json
408
- {
409
- "type": "EmbedWidgetMessage",
410
- "command": "syncedStatusUpdate",
411
- "params": {
412
- "syncedStatus": { "color": "#FFAA33" }
413
- }
414
- }
415
- ```
416
-
417
- ```json
418
- {
419
- "type": "EmbedWidgetMessage",
420
- "command": "incomingAction",
421
- "params": {
422
- "actionId": "demo",
423
- "data": { "demo-param": "Hello from widget" }
424
- }
425
- }
426
- ```
427
-
428
- ### Notes
429
-
430
- - The `targetOrigin` option in `EmbedWidgetMessenger` should generally remain as `'*'` to allow communication with the widget.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withalleo/ewidget-utils",
3
- "version": "1.0.9",
3
+ "version": "1.0.12",
4
4
  "description": "Alleo e-widget utility library.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -41,7 +41,7 @@
41
41
  "scripts": {
42
42
  "clean": "rimraf dist",
43
43
  "build": "vite build && tsc -p tsconfig.build.json",
44
- "publish": "npm run clean && npm run build && npm version patch && npm publish"
44
+ "full-publish": "npm run clean && npm run build && npm version patch && npm publish"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@eslint/js": "^9.22.0",