@3dsource/metabox-front-api 0.0.13 → 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 +30 -37
- package/dist/actions/ApiAction.d.ts +20 -2
- package/dist/actions/GetFastRender.d.ts +5 -20
- package/dist/actions/GetPdf.d.ts +5 -19
- package/dist/actions/SendCommandToUnreal.d.ts +1 -0
- package/dist/actions/SetEnvironment.d.ts +3 -11
- package/dist/actions/SetEnvironmentMaterial.d.ts +11 -31
- package/dist/actions/SetMaterial.d.ts +7 -27
- package/dist/actions/SetProduct.d.ts +10 -0
- package/dist/actions/ShowEmbeddedMenu.d.ts +9 -1
- package/dist/actions/WatchCallbacks.d.ts +2 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.esm.js +129 -154
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +129 -154
- package/dist/index.umd.js.map +1 -1
- package/dist/interfaces/FromMetaboxMessagePayloads.d.ts +1 -1
- package/dist/interfaces/UniversalConfigurator.d.ts +21 -2
- package/dist/lib/EventDispatcher.d.ts +39 -0
- package/dist/lib/initializeCommunicator.d.ts +2 -26
- package/package.json +26 -22
package/dist/index.umd.js
CHANGED
|
@@ -10,8 +10,26 @@
|
|
|
10
10
|
* All Rights Reserved
|
|
11
11
|
*/
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* To integrate the MetaBox configurator into an HTML element, use the following example:
|
|
14
|
+
*
|
|
15
|
+
* **We strongly recommend using the option with npm and locking it to the latest version at the time of integration, as the option with cdn can change rapidly and may cause unexpected behavior in your existing code. See root documentation.**
|
|
16
|
+
*
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { integrateMetaBox } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
19
|
+
*
|
|
20
|
+
* integrateMetaBox(
|
|
21
|
+
* 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
|
|
22
|
+
* 'embed3DSource'
|
|
23
|
+
* );
|
|
24
|
+
*
|
|
25
|
+
* // Set up the global API environment
|
|
26
|
+
* window.env3DSource = window.env3DSource || {};
|
|
27
|
+
*
|
|
28
|
+
* //Listen for the API ready event
|
|
29
|
+
* window.env3DSource.apiReady = (api) => {
|
|
30
|
+
* // Use the API actions here
|
|
31
|
+
* };
|
|
32
|
+
* ```
|
|
15
33
|
*/
|
|
16
34
|
class ApiAction {
|
|
17
35
|
constructor() {
|
|
@@ -49,10 +67,18 @@
|
|
|
49
67
|
* All Rights Reserved
|
|
50
68
|
*/
|
|
51
69
|
/**
|
|
52
|
-
*
|
|
70
|
+
* {@inheritDoc ApiAction}
|
|
71
|
+
*
|
|
72
|
+
* Represents an action to toggle the Embedded MetaBox Menu.
|
|
53
73
|
*
|
|
54
74
|
* @remarks
|
|
55
75
|
* This action sends a message to the MetaBox API to toggle the visibility of the embedded menu.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* import { ShowEmbeddedMenu } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
79
|
+
* window.env3DSource.apiReady = (api) => {
|
|
80
|
+
* new ShowEmbeddedMenu(true);
|
|
81
|
+
* };
|
|
56
82
|
*/
|
|
57
83
|
class ShowEmbeddedMenu extends ApiAction {
|
|
58
84
|
/**
|
|
@@ -77,22 +103,14 @@
|
|
|
77
103
|
* All Rights Reserved
|
|
78
104
|
*/
|
|
79
105
|
/**
|
|
106
|
+
* {@inheritDoc ApiAction}
|
|
107
|
+
*
|
|
80
108
|
* Represents an action to set the environment by its ID.
|
|
81
109
|
* @remarks
|
|
82
110
|
* This action sends a message to the MetaBox API to load the environment level using the specified environment ID.
|
|
83
|
-
* It requires the MetaBox API to be properly initialized and an event listener to be registered.
|
|
84
111
|
*
|
|
85
112
|
* @example
|
|
86
|
-
* import {
|
|
87
|
-
*
|
|
88
|
-
* // Integrate the MetaBox configurator into an HTML element with the ID 'embed3DSource'
|
|
89
|
-
* integrateMetaBox(
|
|
90
|
-
* 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
|
|
91
|
-
* 'embed3DSource'
|
|
92
|
-
* );
|
|
93
|
-
*
|
|
94
|
-
* // Setup API ready callback
|
|
95
|
-
* window.env3DSource = window.env3DSource || {};
|
|
113
|
+
* import { SetEnvironment } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
96
114
|
* window.env3DSource.apiReady = (api) => {
|
|
97
115
|
* // Change the environment to '55555555-1234-1234-1234-01234567890'
|
|
98
116
|
* new SetEnvironment('55555555-1234-1234-1234-01234567890');
|
|
@@ -121,10 +139,20 @@
|
|
|
121
139
|
* All Rights Reserved
|
|
122
140
|
*/
|
|
123
141
|
/**
|
|
142
|
+
* {@inheritDoc ApiAction}
|
|
143
|
+
*
|
|
124
144
|
* Represents an action to set a product by its ID.
|
|
125
145
|
*
|
|
126
146
|
* @remarks
|
|
127
147
|
* This action sends a message to the MetaBox API to set a product using the provided product ID.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* import { SetProduct } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
151
|
+
* window.env3DSource.apiReady = (api) => {
|
|
152
|
+
* new SetProduct(
|
|
153
|
+
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3'
|
|
154
|
+
* );
|
|
155
|
+
* };
|
|
128
156
|
*/
|
|
129
157
|
class SetProduct extends ApiAction {
|
|
130
158
|
/**
|
|
@@ -149,33 +177,19 @@
|
|
|
149
177
|
* All Rights Reserved
|
|
150
178
|
*/
|
|
151
179
|
/**
|
|
180
|
+
* {@inheritDoc ApiAction}
|
|
181
|
+
*
|
|
152
182
|
* Represents an action to get a PDF from Metabox.
|
|
153
183
|
* @remarks
|
|
154
184
|
* This class sends a message to the MetaBox API to generate a PDF based on the current configuration.
|
|
155
185
|
* This action does not require any parameters.
|
|
156
186
|
*
|
|
157
|
-
* **Important
|
|
158
|
-
*```javascript
|
|
159
|
-
* data.eventType === 'viewportReady' && data.payload === true.
|
|
160
|
-
* ```
|
|
161
|
-
* Only then request be processed.
|
|
187
|
+
* **Important**: Invoking this action will buffer it until the viewport is ready. Only then will the request be processed.
|
|
162
188
|
*
|
|
163
189
|
* @example
|
|
164
|
-
* import {
|
|
165
|
-
*
|
|
166
|
-
* integrateMetaBox(
|
|
167
|
-
* 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
|
|
168
|
-
* 'embed3DSource'
|
|
169
|
-
* );
|
|
170
|
-
*
|
|
171
|
-
* window.env3DSource = window.env3DSource || {};
|
|
190
|
+
* import { GetPdf } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
172
191
|
* window.env3DSource.apiReady = (api) => {
|
|
173
|
-
*
|
|
174
|
-
* if (data.eventType === 'viewportReady' && data.payload === true) {
|
|
175
|
-
* // Request a PDF of the current configuration
|
|
176
|
-
* new GetPdf();
|
|
177
|
-
* }
|
|
178
|
-
* });
|
|
192
|
+
* new GetPdf();
|
|
179
193
|
* };
|
|
180
194
|
*/
|
|
181
195
|
class GetPdf extends ApiAction {
|
|
@@ -199,41 +213,21 @@
|
|
|
199
213
|
* All Rights Reserved
|
|
200
214
|
*/
|
|
201
215
|
/**
|
|
216
|
+
* {@inheritDoc ApiAction}
|
|
217
|
+
*
|
|
202
218
|
* Represents an action to set a material by its ID.
|
|
203
219
|
*
|
|
204
220
|
* @remarks
|
|
205
221
|
* This action sends a message to the MetaBox API to update the material on a specific product slot using the provided identifiers.
|
|
206
|
-
|
|
207
|
-
* **Important:** Before invoking this action, ensure that the MetaBox already dispatched
|
|
208
|
-
* as minimum one eventType:"basicConfiguratorDataWithState":
|
|
209
|
-
* ```javascript
|
|
210
|
-
* data.eventType === 'basicConfiguratorDataWithState'.
|
|
211
|
-
* ```
|
|
212
|
-
* Only then request be processed.
|
|
213
222
|
*
|
|
214
223
|
* @example
|
|
215
224
|
* import { SetMaterial } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
216
|
-
*
|
|
217
|
-
* // Integrate the MetaBox configurator into an HTML element with the ID 'embed3DSource'
|
|
218
|
-
* integrateMetaBox(
|
|
219
|
-
* 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
|
|
220
|
-
* 'embed3DSource'
|
|
221
|
-
* );
|
|
222
|
-
*
|
|
223
|
-
* // Set up the global API environment
|
|
224
|
-
* window.env3DSource = window.env3DSource || {};
|
|
225
225
|
* window.env3DSource.apiReady = (api) => {
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
|
|
232
|
-
* 'carpaint',
|
|
233
|
-
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
234
|
-
* );
|
|
235
|
-
* }
|
|
236
|
-
* });
|
|
226
|
+
* new SetMaterial(
|
|
227
|
+
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
|
|
228
|
+
* 'carpaint',
|
|
229
|
+
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
230
|
+
* );
|
|
237
231
|
* };
|
|
238
232
|
*/
|
|
239
233
|
class SetMaterial extends ApiAction {
|
|
@@ -263,46 +257,26 @@
|
|
|
263
257
|
* All Rights Reserved
|
|
264
258
|
*/
|
|
265
259
|
/**
|
|
266
|
-
*
|
|
260
|
+
* {@inheritDoc ApiAction}
|
|
261
|
+
*
|
|
262
|
+
* Represents an action to set a environment material by its ID.
|
|
267
263
|
*
|
|
268
264
|
* @remarks
|
|
269
|
-
* This action sends a message to the MetaBox API to update the material on a specific
|
|
270
|
-
|
|
271
|
-
* **Important:** Before invoking this action, ensure that the MetaBox already dispatched
|
|
272
|
-
* as minimum one eventType:"basicConfiguratorDataWithState":
|
|
273
|
-
* ```javascript
|
|
274
|
-
* data.eventType === 'basicConfiguratorDataWithState'.
|
|
275
|
-
* ```
|
|
276
|
-
* Only then request be processed.
|
|
265
|
+
* This action sends a message to the MetaBox API to update the material on a specific environment slot using the provided identifiers.
|
|
277
266
|
*
|
|
278
267
|
* @example
|
|
279
|
-
* import {
|
|
280
|
-
*
|
|
281
|
-
* // Integrate the MetaBox configurator into an HTML element with the ID 'embed3DSource'
|
|
282
|
-
* integrateMetaBox(
|
|
283
|
-
* 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
|
|
284
|
-
* 'embed3DSource'
|
|
285
|
-
* );
|
|
286
|
-
*
|
|
287
|
-
* // Set up the global API environment
|
|
288
|
-
* window.env3DSource = window.env3DSource || {};
|
|
268
|
+
* import { SetEnvironmentMaterial } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
289
269
|
* window.env3DSource.apiReady = (api) => {
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
|
|
296
|
-
* 'carpaint',
|
|
297
|
-
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
298
|
-
* );
|
|
299
|
-
* }
|
|
300
|
-
* });
|
|
270
|
+
* new SetEnvironmentMaterial(
|
|
271
|
+
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
|
|
272
|
+
* 'carpaint',
|
|
273
|
+
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
274
|
+
* );
|
|
301
275
|
* };
|
|
302
276
|
*/
|
|
303
277
|
class SetEnvironmentMaterial extends ApiAction {
|
|
304
278
|
/**
|
|
305
|
-
* Creates an instance of
|
|
279
|
+
* Creates an instance of SetEnvironmentMaterial.
|
|
306
280
|
*
|
|
307
281
|
* @param productId - The product ID.
|
|
308
282
|
* @param slotId - The slot ID.
|
|
@@ -327,40 +301,25 @@
|
|
|
327
301
|
* All Rights Reserved
|
|
328
302
|
*/
|
|
329
303
|
/**
|
|
304
|
+
* {@inheritDoc ApiAction}
|
|
305
|
+
*
|
|
330
306
|
* Represents a fast render action.
|
|
331
307
|
* @remarks
|
|
332
308
|
* This class sends a message to the MetaBox API to obtain a fast render based on the provided format and optional size.
|
|
333
309
|
*
|
|
334
|
-
* **Important
|
|
335
|
-
* ```javascript
|
|
336
|
-
* data.eventType === 'viewportReady' && data.payload === true.
|
|
337
|
-
* ```
|
|
338
|
-
* Only then request be processed.
|
|
310
|
+
* **Important**: Invoking this action will buffer it until the viewport is ready. Only then will the request be processed.
|
|
339
311
|
*
|
|
340
312
|
* @example
|
|
341
|
-
* import {
|
|
342
|
-
*
|
|
343
|
-
* // Integrate the MetaBox configurator into an HTML element with the ID 'embed3DSource'
|
|
344
|
-
* integrateMetaBox(
|
|
345
|
-
* 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
|
|
346
|
-
* 'embed3DSource'
|
|
347
|
-
* );
|
|
348
|
-
*
|
|
349
|
-
* // Set up the global API environment
|
|
350
|
-
* window.env3DSource = window.env3DSource || {};
|
|
313
|
+
* import { GetFastRender,saveImage } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
351
314
|
* window.env3DSource.apiReady = (api) => {
|
|
352
315
|
* // Listen for events from the MetaBox API
|
|
353
316
|
* api.addEventListener('metaboxData', (data) => {
|
|
354
|
-
* // Ensure the viewport is ready before sending render requests
|
|
355
|
-
* if (data.eventType === 'viewportReady' && data.payload === true) {
|
|
356
|
-
* // Request a fast render (PNG image with 1024x1024 dimensions)
|
|
357
|
-
* new GetFastRender('image/png', { x: 1024, y: 1024 });
|
|
358
|
-
* }
|
|
359
317
|
* // Process the fast render response
|
|
360
318
|
* if (data.eventType === 'fastRender') {
|
|
361
319
|
* saveImage(data.payload, 'Render.png');
|
|
362
320
|
* }
|
|
363
321
|
* });
|
|
322
|
+
* new GetFastRender('image/png', { x: 1024, y: 1024 });
|
|
364
323
|
* };
|
|
365
324
|
*/
|
|
366
325
|
class GetFastRender extends ApiAction {
|
|
@@ -387,6 +346,7 @@
|
|
|
387
346
|
* All Rights Reserved
|
|
388
347
|
*/
|
|
389
348
|
/**
|
|
349
|
+
* {@inheritDoc ApiAction}
|
|
390
350
|
* @internal
|
|
391
351
|
* @hidden
|
|
392
352
|
* Represents an action to send Unreal command.
|
|
@@ -408,6 +368,8 @@
|
|
|
408
368
|
*/
|
|
409
369
|
/**
|
|
410
370
|
* @experimental
|
|
371
|
+
* @internal
|
|
372
|
+
* @hidden
|
|
411
373
|
* @remarks
|
|
412
374
|
* Represents an action to watch Unreal callbacks from Unreal engine.
|
|
413
375
|
* Can be useful for custom solutions.
|
|
@@ -432,7 +394,56 @@
|
|
|
432
394
|
* 3DSource.com, Sergii Karanda steve@3dsource.com
|
|
433
395
|
* All Rights Reserved
|
|
434
396
|
*/
|
|
435
|
-
|
|
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';
|
|
436
447
|
/**
|
|
437
448
|
* API class to handle communication with the embedded content.
|
|
438
449
|
* @internal Do not Create an instance of this class directly.
|
|
@@ -442,7 +453,7 @@
|
|
|
442
453
|
* This class sets up a communication channel with the embedded content via window messages.
|
|
443
454
|
* @hidden
|
|
444
455
|
*/
|
|
445
|
-
class Communicator {
|
|
456
|
+
class Communicator extends EventDispatcher {
|
|
446
457
|
/**
|
|
447
458
|
* Creates an instance of Communicator.
|
|
448
459
|
* @internal
|
|
@@ -452,14 +463,11 @@
|
|
|
452
463
|
*/
|
|
453
464
|
constructor() {
|
|
454
465
|
var _a;
|
|
455
|
-
|
|
456
|
-
* Storage for callback listeners by message type.
|
|
457
|
-
*/
|
|
458
|
-
this.listeners = [];
|
|
466
|
+
super();
|
|
459
467
|
/**
|
|
460
468
|
* Binder function for handling incoming messages.
|
|
461
469
|
*/
|
|
462
|
-
this.binder = this.handleMessageReceived.bind(this,
|
|
470
|
+
this.binder = this.handleMessageReceived.bind(this, binderMessageType);
|
|
463
471
|
(_a = Communicator.instance) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
464
472
|
Communicator.instance = this;
|
|
465
473
|
window.addEventListener('message', this.binder);
|
|
@@ -468,7 +476,7 @@
|
|
|
468
476
|
* Destroys the communicator instance by clearing listeners and removing event listeners.
|
|
469
477
|
*/
|
|
470
478
|
destroy() {
|
|
471
|
-
|
|
479
|
+
super.destroy();
|
|
472
480
|
window.removeEventListener('message', this.binder);
|
|
473
481
|
}
|
|
474
482
|
/**
|
|
@@ -486,26 +494,6 @@
|
|
|
486
494
|
// In production, replace "*" with the actual origin for added security.
|
|
487
495
|
(_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(dataToSend, '*');
|
|
488
496
|
}
|
|
489
|
-
/**
|
|
490
|
-
* Adds an event listener for receiving specific types of messages.
|
|
491
|
-
*
|
|
492
|
-
* @param messageType - The message type to listen for.
|
|
493
|
-
* @param callback - The callback function to execute when a message is received.
|
|
494
|
-
*/
|
|
495
|
-
addEventListener(messageType, callback) {
|
|
496
|
-
this.listeners.push({ messageType, callback });
|
|
497
|
-
}
|
|
498
|
-
/**
|
|
499
|
-
* Dispatches an event to all listeners of a specific message type.
|
|
500
|
-
*
|
|
501
|
-
* @param messageType - The message type.
|
|
502
|
-
* @param data - The data associated with the event.
|
|
503
|
-
*/
|
|
504
|
-
dispatchEvent(messageType, data) {
|
|
505
|
-
this.listeners
|
|
506
|
-
.filter((listener) => listener.messageType === messageType)
|
|
507
|
-
.forEach((listener) => listener.callback(data));
|
|
508
|
-
}
|
|
509
497
|
/**
|
|
510
498
|
* Handles incoming messages by invoking the appropriate callbacks.
|
|
511
499
|
*
|
|
@@ -522,20 +510,7 @@
|
|
|
522
510
|
if (((_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.host) !== 'metabox') {
|
|
523
511
|
return;
|
|
524
512
|
}
|
|
525
|
-
this.
|
|
526
|
-
.filter((listener) => listener.messageType === messageType)
|
|
527
|
-
.forEach((listener) => {
|
|
528
|
-
listener.callback(event.data.payload);
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
/**
|
|
532
|
-
* Removes an event listener for a specific type of message.
|
|
533
|
-
*
|
|
534
|
-
* @param messageType - The message type.
|
|
535
|
-
* @param callback - The callback function to remove.
|
|
536
|
-
*/
|
|
537
|
-
removeEventListener(messageType, callback) {
|
|
538
|
-
this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
|
|
513
|
+
this.dispatchEvent(messageType, event.data.payload);
|
|
539
514
|
}
|
|
540
515
|
/**
|
|
541
516
|
* Initializes the communicator when the embedded content is ready.
|
|
@@ -544,7 +519,7 @@
|
|
|
544
519
|
* This function sets up a listener that waits for the 'appLoaded' action and then initializes the Communicator.
|
|
545
520
|
*/
|
|
546
521
|
static createInstance() {
|
|
547
|
-
window.env3DSource = window.env3DSource
|
|
522
|
+
window.env3DSource = Object.assign({}, window.env3DSource);
|
|
548
523
|
const startHandler = (event) => {
|
|
549
524
|
var _a, _b;
|
|
550
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -82,7 +82,7 @@ export interface FromMetaboxMessagePayloads {
|
|
|
82
82
|
/**
|
|
83
83
|
* Dispatches Every when user toggle fullscreen button in internal menu.
|
|
84
84
|
*/
|
|
85
|
-
|
|
85
|
+
isFullScreen: boolean;
|
|
86
86
|
/**
|
|
87
87
|
* Dispatches at the moment while configurator loads. Shows status information.
|
|
88
88
|
*/
|
|
@@ -6,7 +6,7 @@ export interface ConfiguratorEnvelope {
|
|
|
6
6
|
/**
|
|
7
7
|
* A reference to the universal configurator.
|
|
8
8
|
*/
|
|
9
|
-
configurator: UniversalConfigurator
|
|
9
|
+
configurator: UniversalConfigurator;
|
|
10
10
|
/**
|
|
11
11
|
* The unique product identifier.
|
|
12
12
|
*/
|
|
@@ -16,7 +16,9 @@ export interface ConfiguratorEnvelope {
|
|
|
16
16
|
*/
|
|
17
17
|
productMaterialsIds: SelectedIds;
|
|
18
18
|
/**
|
|
19
|
-
* @deprecated,
|
|
19
|
+
* @deprecated,
|
|
20
|
+
* use `productMaterialsIds` instead.
|
|
21
|
+
* @hidden
|
|
20
22
|
*/
|
|
21
23
|
selectedMaterials: SelectedIds;
|
|
22
24
|
/**
|
|
@@ -74,6 +76,8 @@ export interface Product {
|
|
|
74
76
|
thumbnailList: Thumbnail[];
|
|
75
77
|
/** Available slots for the product. */
|
|
76
78
|
slots: Slot[];
|
|
79
|
+
/** List of metaProperties for the product (optional). */
|
|
80
|
+
metaProperties: MetaProperty[];
|
|
77
81
|
/** The model information associated with the product. */
|
|
78
82
|
/** Unique identifier for the product. */
|
|
79
83
|
id: string;
|
|
@@ -107,6 +111,21 @@ export interface Slot {
|
|
|
107
111
|
/** GraphQL typename for the slot. */
|
|
108
112
|
__typename: 'Slot';
|
|
109
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Represents a metaProperty within a product that may allow business logic customization.
|
|
116
|
+
*/
|
|
117
|
+
export interface MetaProperty {
|
|
118
|
+
/** Unique identifier for the metaProperty. */
|
|
119
|
+
id: string;
|
|
120
|
+
/** Display name for the metaProperty. */
|
|
121
|
+
name: string;
|
|
122
|
+
/** Value for the metaProperty. */
|
|
123
|
+
value: string;
|
|
124
|
+
/** Type for the metaProperty. */
|
|
125
|
+
type: string;
|
|
126
|
+
/** GraphQL typename for the metaProperty. */
|
|
127
|
+
__typename: 'MetaProperty';
|
|
128
|
+
}
|
|
110
129
|
/**
|
|
111
130
|
* Represents a material that can be applied to a product slot.
|
|
112
131
|
*/
|
|
@@ -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,37 +1,41 @@
|
|
|
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
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"type": "module",
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "rollup -c",
|
|
12
|
-
"clean": "rimraf dist",
|
|
13
|
-
"packAll": "npm run clean && npm run build && npm pack",
|
|
14
|
-
"publishApi": "npm run packAll && npm publish --access public",
|
|
15
|
-
"apiDoc": "typedoc --entryPointStrategy Expand src/index.ts --tsconfig ./../../../tsconfig.typedoc.json --out ./../../../dist/browser/apiDocBasic"
|
|
16
|
-
},
|
|
17
|
-
"files": [
|
|
18
|
-
"dist/**/*"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"metabox",
|
|
7
|
+
"api",
|
|
8
|
+
"configurator"
|
|
19
9
|
],
|
|
20
10
|
"repository": {
|
|
21
11
|
"type": "git",
|
|
22
12
|
"url": "git@bitbucket.org:dreamsoft/ams_vps-frontend.git"
|
|
23
13
|
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "3dsource.com",
|
|
16
|
+
"type": "module",
|
|
24
17
|
"exports": {
|
|
25
|
-
".":
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"require": "./dist/index.umd.js",
|
|
21
|
+
"import": "./dist/index.esm.js"
|
|
22
|
+
}
|
|
26
23
|
},
|
|
24
|
+
"main": "dist/index.umd.js",
|
|
25
|
+
"jsdelivr": "dist/index.esm.js",
|
|
26
|
+
"unpkg": "dist/index.esm.js",
|
|
27
|
+
"module": "dist/index.esm.js",
|
|
27
28
|
"types": "dist/index.d.ts",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"api",
|
|
31
|
-
"configurator"
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/**/*"
|
|
32
31
|
],
|
|
33
|
-
"
|
|
34
|
-
|
|
32
|
+
"scripts": {
|
|
33
|
+
"apiDoc": "typedoc --entryPointStrategy Expand src/index.ts --tsconfig ./../../../tsconfig.typedoc.json --out ./../../../dist/browser/apiDocBasic",
|
|
34
|
+
"build": "rollup -c",
|
|
35
|
+
"clean": "rimraf dist",
|
|
36
|
+
"packAll": "npm run clean && npm run build && npm pack",
|
|
37
|
+
"publishApi": "npm run packAll && npm publish --access public"
|
|
38
|
+
},
|
|
35
39
|
"devDependencies": {
|
|
36
40
|
"rimraf": "^3.0.2",
|
|
37
41
|
"rollup": "^4.39.0",
|