@3dsource/metabox-front-api 0.0.14 → 0.0.15
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 +1 -1
- package/dist/index.esm.js +56 -43
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +56 -43
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/EventDispatcher.d.ts +39 -0
- package/dist/lib/initializeCommunicator.d.ts +2 -26
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ Insert this code into your HTML file just before the closing `</body>` tag:
|
|
|
45
45
|
|
|
46
46
|
```html
|
|
47
47
|
<script type="module">
|
|
48
|
-
import { integrateMetaBox, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage, FromMetaboxApiAction } from '
|
|
48
|
+
import { integrateMetaBox, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage, FromMetaboxApiAction } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
49
49
|
// Expose API
|
|
50
50
|
window.env3DSource.apiReady = (api) => {
|
|
51
51
|
api.addEventListener('metaboxData', (data) => {
|
package/dist/index.esm.js
CHANGED
|
@@ -388,7 +388,56 @@ class WatchCallbacks extends ApiAction {
|
|
|
388
388
|
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
389
389
|
* All Rights Reserved
|
|
390
390
|
*/
|
|
391
|
-
|
|
391
|
+
/**
|
|
392
|
+
* EventDispatcher is a class that manages event listeners and dispatches events to them.
|
|
393
|
+
*/
|
|
394
|
+
class EventDispatcher {
|
|
395
|
+
constructor() {
|
|
396
|
+
/**
|
|
397
|
+
* Storage for callback listeners by message type.
|
|
398
|
+
*/
|
|
399
|
+
this.listeners = [];
|
|
400
|
+
}
|
|
401
|
+
destroy() {
|
|
402
|
+
this.listeners = [];
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Adds an event listener for receiving specific types of messages.
|
|
406
|
+
*
|
|
407
|
+
* @param messageType - The message type to listen for.
|
|
408
|
+
* @param callback - The callback function to execute when a message is received.
|
|
409
|
+
*/
|
|
410
|
+
addEventListener(messageType, callback) {
|
|
411
|
+
this.listeners.push({ messageType, callback });
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Dispatches an event to all listeners of a specific message type.
|
|
415
|
+
*
|
|
416
|
+
* @param messageType - The message type.
|
|
417
|
+
* @param data - The data associated with the event.
|
|
418
|
+
*/
|
|
419
|
+
dispatchEvent(messageType, data) {
|
|
420
|
+
this.listeners
|
|
421
|
+
.filter((listener) => listener.messageType === messageType)
|
|
422
|
+
.forEach((listener) => listener.callback(data));
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Removes an event listener for a specific type of message.
|
|
426
|
+
*
|
|
427
|
+
* @param messageType - The message type.
|
|
428
|
+
* @param callback - The callback function to remove.
|
|
429
|
+
*/
|
|
430
|
+
removeEventListener(messageType, callback) {
|
|
431
|
+
this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/*
|
|
436
|
+
* Copyright (c) 2025.
|
|
437
|
+
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
438
|
+
* All Rights Reserved
|
|
439
|
+
*/
|
|
440
|
+
const binderMessageType = 'metaboxData';
|
|
392
441
|
/**
|
|
393
442
|
* API class to handle communication with the embedded content.
|
|
394
443
|
* @internal Do not Create an instance of this class directly.
|
|
@@ -398,7 +447,7 @@ const messageType = 'metaboxData';
|
|
|
398
447
|
* This class sets up a communication channel with the embedded content via window messages.
|
|
399
448
|
* @hidden
|
|
400
449
|
*/
|
|
401
|
-
class Communicator {
|
|
450
|
+
class Communicator extends EventDispatcher {
|
|
402
451
|
/**
|
|
403
452
|
* Creates an instance of Communicator.
|
|
404
453
|
* @internal
|
|
@@ -408,14 +457,11 @@ class Communicator {
|
|
|
408
457
|
*/
|
|
409
458
|
constructor() {
|
|
410
459
|
var _a;
|
|
411
|
-
|
|
412
|
-
* Storage for callback listeners by message type.
|
|
413
|
-
*/
|
|
414
|
-
this.listeners = [];
|
|
460
|
+
super();
|
|
415
461
|
/**
|
|
416
462
|
* Binder function for handling incoming messages.
|
|
417
463
|
*/
|
|
418
|
-
this.binder = this.handleMessageReceived.bind(this,
|
|
464
|
+
this.binder = this.handleMessageReceived.bind(this, binderMessageType);
|
|
419
465
|
(_a = Communicator.instance) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
420
466
|
Communicator.instance = this;
|
|
421
467
|
window.addEventListener('message', this.binder);
|
|
@@ -424,7 +470,7 @@ class Communicator {
|
|
|
424
470
|
* Destroys the communicator instance by clearing listeners and removing event listeners.
|
|
425
471
|
*/
|
|
426
472
|
destroy() {
|
|
427
|
-
|
|
473
|
+
super.destroy();
|
|
428
474
|
window.removeEventListener('message', this.binder);
|
|
429
475
|
}
|
|
430
476
|
/**
|
|
@@ -442,26 +488,6 @@ class Communicator {
|
|
|
442
488
|
// In production, replace "*" with the actual origin for added security.
|
|
443
489
|
(_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(dataToSend, '*');
|
|
444
490
|
}
|
|
445
|
-
/**
|
|
446
|
-
* Adds an event listener for receiving specific types of messages.
|
|
447
|
-
*
|
|
448
|
-
* @param messageType - The message type to listen for.
|
|
449
|
-
* @param callback - The callback function to execute when a message is received.
|
|
450
|
-
*/
|
|
451
|
-
addEventListener(messageType, callback) {
|
|
452
|
-
this.listeners.push({ messageType, callback });
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Dispatches an event to all listeners of a specific message type.
|
|
456
|
-
*
|
|
457
|
-
* @param messageType - The message type.
|
|
458
|
-
* @param data - The data associated with the event.
|
|
459
|
-
*/
|
|
460
|
-
dispatchEvent(messageType, data) {
|
|
461
|
-
this.listeners
|
|
462
|
-
.filter((listener) => listener.messageType === messageType)
|
|
463
|
-
.forEach((listener) => listener.callback(data));
|
|
464
|
-
}
|
|
465
491
|
/**
|
|
466
492
|
* Handles incoming messages by invoking the appropriate callbacks.
|
|
467
493
|
*
|
|
@@ -478,20 +504,7 @@ class Communicator {
|
|
|
478
504
|
if (((_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.host) !== 'metabox') {
|
|
479
505
|
return;
|
|
480
506
|
}
|
|
481
|
-
this.
|
|
482
|
-
.filter((listener) => listener.messageType === messageType)
|
|
483
|
-
.forEach((listener) => {
|
|
484
|
-
listener.callback(event.data.payload);
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* Removes an event listener for a specific type of message.
|
|
489
|
-
*
|
|
490
|
-
* @param messageType - The message type.
|
|
491
|
-
* @param callback - The callback function to remove.
|
|
492
|
-
*/
|
|
493
|
-
removeEventListener(messageType, callback) {
|
|
494
|
-
this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
|
|
507
|
+
this.dispatchEvent(messageType, event.data.payload);
|
|
495
508
|
}
|
|
496
509
|
/**
|
|
497
510
|
* Initializes the communicator when the embedded content is ready.
|
|
@@ -500,7 +513,7 @@ class Communicator {
|
|
|
500
513
|
* This function sets up a listener that waits for the 'appLoaded' action and then initializes the Communicator.
|
|
501
514
|
*/
|
|
502
515
|
static createInstance() {
|
|
503
|
-
window.env3DSource = window.env3DSource
|
|
516
|
+
window.env3DSource = Object.assign({}, window.env3DSource);
|
|
504
517
|
const startHandler = (event) => {
|
|
505
518
|
var _a, _b;
|
|
506
519
|
if (((_b = (_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.action) === 'appLoaded' &&
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.umd.js
CHANGED
|
@@ -394,7 +394,56 @@
|
|
|
394
394
|
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
395
395
|
* All Rights Reserved
|
|
396
396
|
*/
|
|
397
|
-
|
|
397
|
+
/**
|
|
398
|
+
* EventDispatcher is a class that manages event listeners and dispatches events to them.
|
|
399
|
+
*/
|
|
400
|
+
class EventDispatcher {
|
|
401
|
+
constructor() {
|
|
402
|
+
/**
|
|
403
|
+
* Storage for callback listeners by message type.
|
|
404
|
+
*/
|
|
405
|
+
this.listeners = [];
|
|
406
|
+
}
|
|
407
|
+
destroy() {
|
|
408
|
+
this.listeners = [];
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Adds an event listener for receiving specific types of messages.
|
|
412
|
+
*
|
|
413
|
+
* @param messageType - The message type to listen for.
|
|
414
|
+
* @param callback - The callback function to execute when a message is received.
|
|
415
|
+
*/
|
|
416
|
+
addEventListener(messageType, callback) {
|
|
417
|
+
this.listeners.push({ messageType, callback });
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Dispatches an event to all listeners of a specific message type.
|
|
421
|
+
*
|
|
422
|
+
* @param messageType - The message type.
|
|
423
|
+
* @param data - The data associated with the event.
|
|
424
|
+
*/
|
|
425
|
+
dispatchEvent(messageType, data) {
|
|
426
|
+
this.listeners
|
|
427
|
+
.filter((listener) => listener.messageType === messageType)
|
|
428
|
+
.forEach((listener) => listener.callback(data));
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Removes an event listener for a specific type of message.
|
|
432
|
+
*
|
|
433
|
+
* @param messageType - The message type.
|
|
434
|
+
* @param callback - The callback function to remove.
|
|
435
|
+
*/
|
|
436
|
+
removeEventListener(messageType, callback) {
|
|
437
|
+
this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/*
|
|
442
|
+
* Copyright (c) 2025.
|
|
443
|
+
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
444
|
+
* All Rights Reserved
|
|
445
|
+
*/
|
|
446
|
+
const binderMessageType = 'metaboxData';
|
|
398
447
|
/**
|
|
399
448
|
* API class to handle communication with the embedded content.
|
|
400
449
|
* @internal Do not Create an instance of this class directly.
|
|
@@ -404,7 +453,7 @@
|
|
|
404
453
|
* This class sets up a communication channel with the embedded content via window messages.
|
|
405
454
|
* @hidden
|
|
406
455
|
*/
|
|
407
|
-
class Communicator {
|
|
456
|
+
class Communicator extends EventDispatcher {
|
|
408
457
|
/**
|
|
409
458
|
* Creates an instance of Communicator.
|
|
410
459
|
* @internal
|
|
@@ -414,14 +463,11 @@
|
|
|
414
463
|
*/
|
|
415
464
|
constructor() {
|
|
416
465
|
var _a;
|
|
417
|
-
|
|
418
|
-
* Storage for callback listeners by message type.
|
|
419
|
-
*/
|
|
420
|
-
this.listeners = [];
|
|
466
|
+
super();
|
|
421
467
|
/**
|
|
422
468
|
* Binder function for handling incoming messages.
|
|
423
469
|
*/
|
|
424
|
-
this.binder = this.handleMessageReceived.bind(this,
|
|
470
|
+
this.binder = this.handleMessageReceived.bind(this, binderMessageType);
|
|
425
471
|
(_a = Communicator.instance) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
426
472
|
Communicator.instance = this;
|
|
427
473
|
window.addEventListener('message', this.binder);
|
|
@@ -430,7 +476,7 @@
|
|
|
430
476
|
* Destroys the communicator instance by clearing listeners and removing event listeners.
|
|
431
477
|
*/
|
|
432
478
|
destroy() {
|
|
433
|
-
|
|
479
|
+
super.destroy();
|
|
434
480
|
window.removeEventListener('message', this.binder);
|
|
435
481
|
}
|
|
436
482
|
/**
|
|
@@ -448,26 +494,6 @@
|
|
|
448
494
|
// In production, replace "*" with the actual origin for added security.
|
|
449
495
|
(_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(dataToSend, '*');
|
|
450
496
|
}
|
|
451
|
-
/**
|
|
452
|
-
* Adds an event listener for receiving specific types of messages.
|
|
453
|
-
*
|
|
454
|
-
* @param messageType - The message type to listen for.
|
|
455
|
-
* @param callback - The callback function to execute when a message is received.
|
|
456
|
-
*/
|
|
457
|
-
addEventListener(messageType, callback) {
|
|
458
|
-
this.listeners.push({ messageType, callback });
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* Dispatches an event to all listeners of a specific message type.
|
|
462
|
-
*
|
|
463
|
-
* @param messageType - The message type.
|
|
464
|
-
* @param data - The data associated with the event.
|
|
465
|
-
*/
|
|
466
|
-
dispatchEvent(messageType, data) {
|
|
467
|
-
this.listeners
|
|
468
|
-
.filter((listener) => listener.messageType === messageType)
|
|
469
|
-
.forEach((listener) => listener.callback(data));
|
|
470
|
-
}
|
|
471
497
|
/**
|
|
472
498
|
* Handles incoming messages by invoking the appropriate callbacks.
|
|
473
499
|
*
|
|
@@ -484,20 +510,7 @@
|
|
|
484
510
|
if (((_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.host) !== 'metabox') {
|
|
485
511
|
return;
|
|
486
512
|
}
|
|
487
|
-
this.
|
|
488
|
-
.filter((listener) => listener.messageType === messageType)
|
|
489
|
-
.forEach((listener) => {
|
|
490
|
-
listener.callback(event.data.payload);
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
/**
|
|
494
|
-
* Removes an event listener for a specific type of message.
|
|
495
|
-
*
|
|
496
|
-
* @param messageType - The message type.
|
|
497
|
-
* @param callback - The callback function to remove.
|
|
498
|
-
*/
|
|
499
|
-
removeEventListener(messageType, callback) {
|
|
500
|
-
this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
|
|
513
|
+
this.dispatchEvent(messageType, event.data.payload);
|
|
501
514
|
}
|
|
502
515
|
/**
|
|
503
516
|
* Initializes the communicator when the embedded content is ready.
|
|
@@ -506,7 +519,7 @@
|
|
|
506
519
|
* This function sets up a listener that waits for the 'appLoaded' action and then initializes the Communicator.
|
|
507
520
|
*/
|
|
508
521
|
static createInstance() {
|
|
509
|
-
window.env3DSource = window.env3DSource
|
|
522
|
+
window.env3DSource = Object.assign({}, window.env3DSource);
|
|
510
523
|
const startHandler = (event) => {
|
|
511
524
|
var _a, _b;
|
|
512
525
|
if (((_b = (_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.action) === 'appLoaded' &&
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a callback listener for specific message types.
|
|
3
|
+
*/
|
|
4
|
+
interface Listener {
|
|
5
|
+
messageType: string;
|
|
6
|
+
callback: (data: unknown) => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* EventDispatcher is a class that manages event listeners and dispatches events to them.
|
|
10
|
+
*/
|
|
11
|
+
export declare class EventDispatcher {
|
|
12
|
+
/**
|
|
13
|
+
* Storage for callback listeners by message type.
|
|
14
|
+
*/
|
|
15
|
+
listeners: Listener[];
|
|
16
|
+
destroy(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Adds an event listener for receiving specific types of messages.
|
|
19
|
+
*
|
|
20
|
+
* @param messageType - The message type to listen for.
|
|
21
|
+
* @param callback - The callback function to execute when a message is received.
|
|
22
|
+
*/
|
|
23
|
+
addEventListener(messageType: string, callback: (data: unknown) => void): void;
|
|
24
|
+
/**
|
|
25
|
+
* Dispatches an event to all listeners of a specific message type.
|
|
26
|
+
*
|
|
27
|
+
* @param messageType - The message type.
|
|
28
|
+
* @param data - The data associated with the event.
|
|
29
|
+
*/
|
|
30
|
+
dispatchEvent(messageType: string, data: unknown): void;
|
|
31
|
+
/**
|
|
32
|
+
* Removes an event listener for a specific type of message.
|
|
33
|
+
*
|
|
34
|
+
* @param messageType - The message type.
|
|
35
|
+
* @param callback - The callback function to remove.
|
|
36
|
+
*/
|
|
37
|
+
removeEventListener(messageType: string, callback: (data: unknown) => void): void;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ToMetaBoxMessageEnvelope } from '../interfaces/ToMetaboxMessagePayloads';
|
|
2
|
+
import { EventDispatcher } from './EventDispatcher';
|
|
2
3
|
declare global {
|
|
3
4
|
interface Window {
|
|
4
5
|
env3DSource: {
|
|
@@ -16,11 +17,7 @@ declare global {
|
|
|
16
17
|
* This class sets up a communication channel with the embedded content via window messages.
|
|
17
18
|
* @hidden
|
|
18
19
|
*/
|
|
19
|
-
export declare class Communicator {
|
|
20
|
-
/**
|
|
21
|
-
* Storage for callback listeners by message type.
|
|
22
|
-
*/
|
|
23
|
-
private listeners;
|
|
20
|
+
export declare class Communicator extends EventDispatcher {
|
|
24
21
|
/**
|
|
25
22
|
* Binder function for handling incoming messages.
|
|
26
23
|
*/
|
|
@@ -47,20 +44,6 @@ export declare class Communicator {
|
|
|
47
44
|
* @param data - The data to send.
|
|
48
45
|
*/
|
|
49
46
|
sendMessageToMetaBox(data: ToMetaBoxMessageEnvelope): void;
|
|
50
|
-
/**
|
|
51
|
-
* Adds an event listener for receiving specific types of messages.
|
|
52
|
-
*
|
|
53
|
-
* @param messageType - The message type to listen for.
|
|
54
|
-
* @param callback - The callback function to execute when a message is received.
|
|
55
|
-
*/
|
|
56
|
-
addEventListener(messageType: string, callback: (data: unknown) => void): void;
|
|
57
|
-
/**
|
|
58
|
-
* Dispatches an event to all listeners of a specific message type.
|
|
59
|
-
*
|
|
60
|
-
* @param messageType - The message type.
|
|
61
|
-
* @param data - The data associated with the event.
|
|
62
|
-
*/
|
|
63
|
-
dispatchEvent(messageType: string, data: unknown): void;
|
|
64
47
|
/**
|
|
65
48
|
* Handles incoming messages by invoking the appropriate callbacks.
|
|
66
49
|
*
|
|
@@ -71,13 +54,6 @@ export declare class Communicator {
|
|
|
71
54
|
* Optionally, you can perform an origin check for added security.
|
|
72
55
|
*/
|
|
73
56
|
private handleMessageReceived;
|
|
74
|
-
/**
|
|
75
|
-
* Removes an event listener for a specific type of message.
|
|
76
|
-
*
|
|
77
|
-
* @param messageType - The message type.
|
|
78
|
-
* @param callback - The callback function to remove.
|
|
79
|
-
*/
|
|
80
|
-
removeEventListener(messageType: string, callback: (data: unknown) => void): void;
|
|
81
57
|
/**
|
|
82
58
|
* Initializes the communicator when the embedded content is ready.
|
|
83
59
|
* @internal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@3dsource/metabox-front-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "API for MetaBox BASIC configurator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"metabox",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"type": "module",
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
|
-
"
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
20
|
"require": "./dist/index.umd.js",
|
|
21
|
-
"
|
|
21
|
+
"import": "./dist/index.esm.js"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"main": "dist/index.umd.js",
|