@3dsource/metabox-modular-configurator-api 3.0.17 → 3.0.18
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.
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { fromEvent } from 'rxjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Base class for commands sent to the Metabox.
|
|
4
|
+
* Base class for commands sent to the Metabox API.
|
|
5
|
+
* @internal
|
|
6
|
+
* @hidden
|
|
5
7
|
*/
|
|
6
8
|
class CommandBase {
|
|
7
9
|
}
|
|
8
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Wrapper helper function to use it with rxJs the same as `fromEvent` to listen to events from the Communicator.
|
|
13
|
+
*
|
|
14
|
+
* @param {Communicator} target
|
|
15
|
+
* @param eventName
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
function fromCommunicatorEvent(target, eventName) {
|
|
19
|
+
return fromEvent(target, eventName);
|
|
20
|
+
}
|
|
21
|
+
|
|
9
22
|
const MetaboxModularConfiguratorActions = {
|
|
10
23
|
metaboxConfig: 'metaboxConfig',
|
|
11
24
|
setEnvironment: 'setEnvironment',
|
|
@@ -32,109 +45,122 @@ const MetaboxModularConfiguratorActions = {
|
|
|
32
45
|
};
|
|
33
46
|
|
|
34
47
|
/**
|
|
35
|
-
* Represents a command to
|
|
48
|
+
* Represents a command to send Metabox Config to Metabox Basic Configurator.
|
|
36
49
|
* @remarks
|
|
37
|
-
*
|
|
50
|
+
* **Important**: No need to listen to any events to see changes.
|
|
38
51
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* import { ApplyZoom, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
43
|
-
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
44
|
-
* api.sendCommandToMetabox(new ApplyZoom(10));
|
|
45
|
-
* api.sendCommandToMetabox(new ApplyZoom(-10));
|
|
46
|
-
* };
|
|
52
|
+
* @internal
|
|
53
|
+
* Automatically sent when the Communicator instance is ready.
|
|
47
54
|
*/
|
|
48
|
-
class
|
|
55
|
+
class MetaboxConfig extends CommandBase {
|
|
49
56
|
/**
|
|
50
|
-
* Creates an instance of
|
|
51
|
-
*
|
|
52
|
-
* @param {
|
|
57
|
+
* Creates an instance of MetaboxConfig.
|
|
58
|
+
* @param {string} appId - The unique identifier for the Communicator Instance
|
|
59
|
+
* @param {MetaboxCommandConfig} config - optional initial config: standalone - if true - disable metabox custom template and all logic
|
|
53
60
|
*/
|
|
54
|
-
constructor(
|
|
61
|
+
constructor(appId, config) {
|
|
55
62
|
super();
|
|
56
63
|
this.data = {
|
|
57
|
-
action: MetaboxModularConfiguratorActions.
|
|
58
|
-
payload: {
|
|
64
|
+
action: MetaboxModularConfiguratorActions.metaboxConfig,
|
|
65
|
+
payload: { appId, config },
|
|
59
66
|
};
|
|
60
67
|
}
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
/**
|
|
64
|
-
*
|
|
65
|
-
* @param {Communicator} target
|
|
66
|
-
* @param eventName
|
|
67
|
-
*/
|
|
68
|
-
function fromCommunicatorEvent(target, eventName) {
|
|
69
|
-
return fromEvent(target, eventName);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Represents a command to get a Call To Action Information from Metabox Modular Configurator.
|
|
71
|
+
* Represents a command to get a PDF from Metabox Basic Configurator.
|
|
74
72
|
* @remarks
|
|
75
|
-
* This class sends a message to the Metabox API to generate
|
|
76
|
-
*
|
|
77
|
-
*
|
|
73
|
+
* This class sends a message to the Metabox API to generate a PDF based on the current configuration.
|
|
74
|
+
* **Important**: No need to listen to any events to see changes.
|
|
78
75
|
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
79
76
|
*
|
|
80
77
|
* @example
|
|
81
|
-
* import {
|
|
78
|
+
* import { GetPdf, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
79
|
+
*
|
|
80
|
+
* @param {Communicator} api - communicator instance api
|
|
82
81
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
83
|
-
* api.sendCommandToMetabox(new
|
|
82
|
+
* api.sendCommandToMetabox(new GetPdf());
|
|
84
83
|
* };
|
|
85
84
|
*/
|
|
86
|
-
class
|
|
85
|
+
class GetPdf extends CommandBase {
|
|
87
86
|
/**
|
|
88
|
-
* Creates an instance of
|
|
87
|
+
* Creates an instance of GetPdf.
|
|
89
88
|
*
|
|
90
89
|
* @remarks
|
|
91
90
|
* This constructor does not require any parameters.
|
|
92
91
|
*/
|
|
93
92
|
constructor() {
|
|
94
93
|
super();
|
|
95
|
-
this.data = {
|
|
96
|
-
action: MetaboxModularConfiguratorActions.getCallToActionInformation,
|
|
97
|
-
};
|
|
94
|
+
this.data = { action: MetaboxModularConfiguratorActions.getPdf };
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
97
|
|
|
101
98
|
/**
|
|
102
|
-
* Represents a command to get a
|
|
99
|
+
* Represents a command to get a Call To Action Information from Metabox Basic Configurator.
|
|
103
100
|
* @remarks
|
|
104
|
-
* This class sends a message to the Metabox API to generate
|
|
105
|
-
*
|
|
101
|
+
* This class sends a message to the Metabox API to generate Call To Action information based on the current configuration and sends it to the endpoint URL from the CTA information.
|
|
102
|
+
*
|
|
103
|
+
* To listen for changes after sending this command, listen to the 'ecomConfiguratorDataUpdated' event.
|
|
104
|
+
* //...Assume that the integration is already implemented (only once)
|
|
105
|
+
* @example
|
|
106
|
+
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
107
|
+
*
|
|
108
|
+
* @param {Communicator} api - communicator instance api
|
|
109
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
110
|
+
* @param {EcomConfigurator} data - description for all ecom configurator params
|
|
111
|
+
* api.addEventListener('ecomConfiguratorDataUpdated', (data) => {
|
|
112
|
+
* console.log('Ecom configurator params:', data);
|
|
113
|
+
* });
|
|
114
|
+
* };
|
|
106
115
|
*
|
|
107
116
|
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
108
117
|
*
|
|
109
118
|
* @example
|
|
110
|
-
* import {
|
|
119
|
+
* import { GetCallToActionInformation, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
120
|
+
*
|
|
121
|
+
* @param {Communicator} api - communicator instance api
|
|
111
122
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
112
|
-
* api.sendCommandToMetabox(new
|
|
123
|
+
* api.sendCommandToMetabox(new GetCallToActionInformation());
|
|
113
124
|
* };
|
|
114
125
|
*/
|
|
115
|
-
class
|
|
126
|
+
class GetCallToActionInformation extends CommandBase {
|
|
116
127
|
/**
|
|
117
|
-
* Creates an instance of
|
|
128
|
+
* Creates an instance of GetCallToActionInformation.
|
|
118
129
|
*
|
|
119
130
|
* @remarks
|
|
120
131
|
* This constructor does not require any parameters.
|
|
121
132
|
*/
|
|
122
133
|
constructor() {
|
|
123
134
|
super();
|
|
124
|
-
this.data = {
|
|
135
|
+
this.data = {
|
|
136
|
+
action: MetaboxModularConfiguratorActions.getCallToActionInformation,
|
|
137
|
+
};
|
|
125
138
|
}
|
|
126
139
|
}
|
|
127
140
|
|
|
128
141
|
/**
|
|
129
|
-
* Represents a command to
|
|
142
|
+
* Represents a command to get the camera configuration from Unreal.
|
|
130
143
|
* @remarks
|
|
131
144
|
* This class sends a message to the Metabox API to get the camera from a scene.
|
|
132
|
-
*
|
|
145
|
+
*
|
|
146
|
+
* To listen for changes after sending this command, listen to the 'getCameraResult' event.
|
|
147
|
+
* //...Assume that the integration is already implemented (only once)
|
|
148
|
+
* @example
|
|
149
|
+
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
150
|
+
*
|
|
151
|
+
* @param {Communicator} api - communicator instance api
|
|
152
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
153
|
+
* @param {CameraCommandPayload} data - camera params
|
|
154
|
+
* api.addEventListener('getCameraResult', (data) => {
|
|
155
|
+
* console.log('Camera params after get camera command:', data);
|
|
156
|
+
* });
|
|
157
|
+
* };
|
|
133
158
|
*
|
|
134
159
|
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
135
160
|
*
|
|
136
161
|
* @example
|
|
137
162
|
* import { GetCamera, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
163
|
+
* @param {Communicator} api - communicator instance api
|
|
138
164
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
139
165
|
* api.sendCommandToMetabox(new GetCamera());
|
|
140
166
|
* };
|
|
@@ -153,14 +179,15 @@ class GetCamera extends CommandBase {
|
|
|
153
179
|
}
|
|
154
180
|
|
|
155
181
|
/**
|
|
156
|
-
* Represents a command to
|
|
182
|
+
* Represents a command to set the camera configuration.
|
|
157
183
|
* @remarks
|
|
158
184
|
* This class sends a message to the Metabox API to set the camera on a scene.
|
|
159
|
-
*
|
|
185
|
+
* **Important**: No need to listen to any events to see changes.
|
|
160
186
|
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
161
187
|
*
|
|
162
188
|
* @example
|
|
163
|
-
* import {
|
|
189
|
+
* import { SetCamera, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
190
|
+
* @param {Communicator} api - communicator instance api
|
|
164
191
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
165
192
|
* api.sendCommandToMetabox(new SetCamera({
|
|
166
193
|
* fov: 45,
|
|
@@ -184,8 +211,7 @@ class SetCamera extends CommandBase {
|
|
|
184
211
|
/**
|
|
185
212
|
* Creates an instance of SetCamera.
|
|
186
213
|
*
|
|
187
|
-
* @
|
|
188
|
-
* @param {CameraCommandPayload} camera - camera config
|
|
214
|
+
* @param {CameraCommandPayload} camera - The camera configuration.
|
|
189
215
|
*/
|
|
190
216
|
constructor(camera) {
|
|
191
217
|
super();
|
|
@@ -197,15 +223,15 @@ class SetCamera extends CommandBase {
|
|
|
197
223
|
}
|
|
198
224
|
|
|
199
225
|
/**
|
|
200
|
-
* Represents a command to
|
|
226
|
+
* Represents a command to reset the camera to its initial position.
|
|
201
227
|
* @remarks
|
|
202
228
|
* This class sends a message to the Metabox API to reset the camera on a scene.
|
|
203
|
-
*
|
|
204
|
-
*
|
|
229
|
+
* **Important**: No need to listen to any events to see changes.
|
|
205
230
|
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
206
231
|
*
|
|
207
232
|
* @example
|
|
208
233
|
* import { ResetCamera, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
234
|
+
* @param {Communicator} api - communicator instance api
|
|
209
235
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
210
236
|
* api.sendCommandToMetabox(new ResetCamera());
|
|
211
237
|
* };
|
|
@@ -224,61 +250,117 @@ class ResetCamera extends CommandBase {
|
|
|
224
250
|
}
|
|
225
251
|
|
|
226
252
|
/**
|
|
227
|
-
* Represents a command to
|
|
253
|
+
* Represents a command to apply zoom and change the camera zoom on a scene.
|
|
228
254
|
* @remarks
|
|
229
|
-
* This class sends a command to the Metabox API to
|
|
230
|
-
*
|
|
231
|
-
* If this property exists, you can send init showcase command
|
|
232
|
-
* You can send init showcase command only for root components; otherwise we will ignore this command
|
|
233
|
-
*
|
|
255
|
+
* This class sends a command to the Metabox API to change zoom on a scene.
|
|
256
|
+
* **Important**: No need to listen to any events to see changes.
|
|
234
257
|
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
235
258
|
*
|
|
236
259
|
* @example
|
|
237
|
-
*
|
|
238
|
-
*
|
|
260
|
+
* import { ApplyZoom, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
261
|
+
*
|
|
262
|
+
* @param {Communicator} api - communicator instance api
|
|
239
263
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
240
|
-
* api.sendCommandToMetabox(new
|
|
264
|
+
* api.sendCommandToMetabox(new ApplyZoom(10));
|
|
265
|
+
* api.sendCommandToMetabox(new ApplyZoom(-10));
|
|
241
266
|
* };
|
|
242
267
|
*/
|
|
243
|
-
class
|
|
268
|
+
class ApplyZoom extends CommandBase {
|
|
244
269
|
/**
|
|
245
|
-
* Creates an instance of
|
|
270
|
+
* Creates an instance of ApplyZoom.
|
|
246
271
|
*
|
|
247
|
-
* @
|
|
248
|
-
* This constructor does not require any parameters.
|
|
272
|
+
* @param {number} zoom - The zoom value to apply.
|
|
249
273
|
*/
|
|
250
|
-
constructor() {
|
|
274
|
+
constructor(zoom) {
|
|
251
275
|
super();
|
|
252
276
|
this.data = {
|
|
253
|
-
action: MetaboxModularConfiguratorActions.
|
|
277
|
+
action: MetaboxModularConfiguratorActions.applyZoom,
|
|
278
|
+
payload: { zoom },
|
|
254
279
|
};
|
|
255
280
|
}
|
|
256
281
|
}
|
|
257
282
|
|
|
258
283
|
/**
|
|
259
|
-
*
|
|
260
|
-
* @
|
|
261
|
-
*
|
|
284
|
+
* Represents a command to initialize Showcase for a product scene and start a sequence for the product.
|
|
285
|
+
* @remarks
|
|
286
|
+
* This class sends a command to the Metabox API to initialize showcase if the product has a sequence.
|
|
287
|
+
* To check this, find the showcase property in the current product and listen to the 'configuratorDataUpdated' event.
|
|
288
|
+
* //...Assume that the integration is already implemented (only once)
|
|
289
|
+
* @example
|
|
290
|
+
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
291
|
+
*
|
|
292
|
+
* @param {Communicator} api - communicator instance api
|
|
293
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
294
|
+
* @param {ConfiguratorEnvelope} data - configurator state after updated
|
|
295
|
+
* api.addEventListener('configuratorDataUpdated', (data) => {
|
|
296
|
+
* console.log('State updated after applied new environment:', data);
|
|
297
|
+
* });
|
|
298
|
+
* };
|
|
299
|
+
*
|
|
300
|
+
* If this property exists, you can send the init showcase command.
|
|
301
|
+
*
|
|
302
|
+
* To listen for changes after sending this command, listen to the 'showcaseStatusChanged' event.
|
|
303
|
+
* //...Assume that the integration is already implemented (only once)
|
|
304
|
+
* @example
|
|
305
|
+
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
306
|
+
*
|
|
307
|
+
* @param {Communicator} api - communicator instance api
|
|
308
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
309
|
+
* @param {ShowCaseStatus} data - showcase status value
|
|
310
|
+
* api.addEventListener('showcaseStatusChanged', (data) => {
|
|
311
|
+
* console.log('Showcase status value after changed:', data);
|
|
312
|
+
* });
|
|
313
|
+
* };
|
|
314
|
+
*
|
|
315
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* import { InitShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
319
|
+
*
|
|
320
|
+
* @param {Communicator} api - communicator instance api
|
|
321
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
322
|
+
* api.sendCommandToMetabox(new InitShowcase());
|
|
323
|
+
* };
|
|
262
324
|
*/
|
|
263
|
-
class
|
|
264
|
-
|
|
325
|
+
class InitShowcase extends CommandBase {
|
|
326
|
+
/**
|
|
327
|
+
* Creates an instance of InitShowcase.
|
|
328
|
+
*
|
|
329
|
+
* @remarks
|
|
330
|
+
* This constructor does not require any parameters.
|
|
331
|
+
*/
|
|
332
|
+
constructor() {
|
|
265
333
|
super();
|
|
266
334
|
this.data = {
|
|
267
|
-
|
|
268
|
-
action: MetaboxModularConfiguratorActions.sendCommandToUnreal,
|
|
335
|
+
action: MetaboxModularConfiguratorActions.initShowcase,
|
|
269
336
|
};
|
|
270
337
|
}
|
|
271
338
|
}
|
|
272
339
|
|
|
273
340
|
/**
|
|
274
|
-
* Represents a command to
|
|
341
|
+
* Represents a command to play Showcase for a product when it is already initialized and paused.
|
|
275
342
|
* @remarks
|
|
276
|
-
* This class sends a command to the Metabox API to play showcase for a product if it is already initialized and
|
|
343
|
+
* This class sends a command to the Metabox API to play showcase for a product if it is already initialized and paused.
|
|
344
|
+
*
|
|
345
|
+
* To listen for changes after sending this command, listen to the 'showcaseStatusChanged' event.
|
|
346
|
+
* //...Assume that the integration is already implemented (only once)
|
|
347
|
+
* @example
|
|
348
|
+
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
349
|
+
*
|
|
350
|
+
* @param {Communicator} api - communicator instance api
|
|
351
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
352
|
+
* @param {ShowCaseStatus} data - showcase status value
|
|
353
|
+
* api.addEventListener('showcaseStatusChanged', (data) => {
|
|
354
|
+
* console.log('Showcase status value after changed:', data);
|
|
355
|
+
* });
|
|
356
|
+
* };
|
|
277
357
|
*
|
|
278
358
|
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
279
359
|
*
|
|
280
360
|
* @example
|
|
281
361
|
* import { PlayShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
362
|
+
*
|
|
363
|
+
* @param {Communicator} api - communicator instance api
|
|
282
364
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
283
365
|
* api.sendCommandToMetabox(new PlayShowcase());
|
|
284
366
|
* };
|
|
@@ -297,14 +379,44 @@ class PlayShowcase extends CommandBase {
|
|
|
297
379
|
}
|
|
298
380
|
|
|
299
381
|
/**
|
|
300
|
-
*
|
|
382
|
+
* @internal
|
|
383
|
+
* @hidden
|
|
384
|
+
* Represents a command to send Unreal command.
|
|
385
|
+
*/
|
|
386
|
+
class UnrealCommand extends CommandBase {
|
|
387
|
+
constructor(payload) {
|
|
388
|
+
super();
|
|
389
|
+
this.data = {
|
|
390
|
+
action: MetaboxModularConfiguratorActions.sendCommandToUnreal,
|
|
391
|
+
payload,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Represents a command to pause Showcase for a product when it is already initialized and playing.
|
|
301
398
|
* @remarks
|
|
302
|
-
* This class sends a command to the Metabox API to pause showcase for a product if it is already initialized and
|
|
399
|
+
* This class sends a command to the Metabox API to pause showcase for a product if it is already initialized and playing.
|
|
400
|
+
*
|
|
401
|
+
* To listen for changes after sending this command, listen to the 'showcaseStatusChanged' event.
|
|
402
|
+
* //...Assume that the integration is already implemented (only once)
|
|
403
|
+
* @example
|
|
404
|
+
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
405
|
+
*
|
|
406
|
+
* @param {Communicator} api - communicator instance api
|
|
407
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
408
|
+
* @param {ShowCaseStatus} data - showcase status value
|
|
409
|
+
* api.addEventListener('showcaseStatusChanged', (data) => {
|
|
410
|
+
* console.log('Showcase status value after changed:', data);
|
|
411
|
+
* });
|
|
412
|
+
* };
|
|
303
413
|
*
|
|
304
414
|
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
305
415
|
*
|
|
306
416
|
* @example
|
|
307
417
|
* import { PauseShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
418
|
+
*
|
|
419
|
+
* @param {Communicator} api - communicator instance api
|
|
308
420
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
309
421
|
* api.sendCommandToMetabox(new PauseShowcase());
|
|
310
422
|
* };
|
|
@@ -323,14 +435,29 @@ class PauseShowcase extends CommandBase {
|
|
|
323
435
|
}
|
|
324
436
|
|
|
325
437
|
/**
|
|
326
|
-
* Represents a command to
|
|
438
|
+
* Represents a command to stop Showcase for a product when it is already initialized, and you want to destroy it.
|
|
327
439
|
* @remarks
|
|
328
|
-
* This class sends a command to the Metabox API to
|
|
440
|
+
* This class sends a command to the Metabox API to stop showcase for a product if it is already initialized.
|
|
441
|
+
*
|
|
442
|
+
* To listen for changes after sending this command, listen to the 'showcaseStatusChanged' event.
|
|
443
|
+
* //...Assume that the integration is already implemented (only once)
|
|
444
|
+
* @example
|
|
445
|
+
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
446
|
+
*
|
|
447
|
+
* @param {Communicator} api - communicator instance api
|
|
448
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
449
|
+
* @param {ShowCaseStatus} data - showcase status value
|
|
450
|
+
* api.addEventListener('showcaseStatusChanged', (data) => {
|
|
451
|
+
* console.log('Showcase status value after changed:', data);
|
|
452
|
+
* });
|
|
453
|
+
* };
|
|
329
454
|
*
|
|
330
455
|
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
331
456
|
*
|
|
332
457
|
* @example
|
|
333
458
|
* import { StopShowcase, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
459
|
+
*
|
|
460
|
+
* @param {Communicator} api - communicator instance api
|
|
334
461
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
335
462
|
* api.sendCommandToMetabox(new StopShowcase());
|
|
336
463
|
* };
|
|
@@ -350,17 +477,28 @@ class StopShowcase extends CommandBase {
|
|
|
350
477
|
|
|
351
478
|
/**
|
|
352
479
|
* Represents a command to get a screenshot.
|
|
353
|
-
*
|
|
354
480
|
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
355
481
|
*
|
|
482
|
+
* @remarks
|
|
483
|
+
* To listen for changes after sending this command, listen to the 'screenshot' event.
|
|
484
|
+
* //...Assume that the integration is already implemented (only once)
|
|
485
|
+
* @example
|
|
486
|
+
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
487
|
+
*
|
|
488
|
+
* @param {Communicator} api - communicator instance api
|
|
489
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
490
|
+
* @param {string} data - base64 string image
|
|
491
|
+
* api.addEventListener('screenshot', (data) => {
|
|
492
|
+
* console.log('Get screenshot here:', data);
|
|
493
|
+
* saveImage(data, 'Render.png');
|
|
494
|
+
* });
|
|
495
|
+
* };
|
|
496
|
+
*
|
|
356
497
|
* @example
|
|
357
498
|
* import { GetScreenshot, Communicator, saveImage } from '@3dsource/metabox-modular-configurator-api';
|
|
499
|
+
*
|
|
500
|
+
* @param {Communicator} api - communicator instance api
|
|
358
501
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
359
|
-
* // Listen for events from to the Metabox API
|
|
360
|
-
* api.addEventListener('screenshot', (data) => {
|
|
361
|
-
* // Process the get screenshot response
|
|
362
|
-
* saveImage(data, 'Render.png');
|
|
363
|
-
* });
|
|
364
502
|
* api.sendCommandToMetabox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
|
|
365
503
|
* };
|
|
366
504
|
*/
|
|
@@ -373,8 +511,8 @@ class GetScreenshot extends CommandBase {
|
|
|
373
511
|
constructor(mimeType, size) {
|
|
374
512
|
super();
|
|
375
513
|
this.data = {
|
|
376
|
-
payload: { format: mimeType, size },
|
|
377
514
|
action: MetaboxModularConfiguratorActions.getScreenshot,
|
|
515
|
+
payload: { format: mimeType, size },
|
|
378
516
|
};
|
|
379
517
|
}
|
|
380
518
|
}
|
|
@@ -383,14 +521,25 @@ class GetScreenshot extends CommandBase {
|
|
|
383
521
|
* Represents a command to set a component by its data (ID, typeId, isRoot).
|
|
384
522
|
*
|
|
385
523
|
* @remarks
|
|
386
|
-
*
|
|
524
|
+
* To listen for changes after sending this command, listen to the 'configuratorDataUpdated' event.
|
|
525
|
+
* //...Assume that the integration is already implemented (only once)
|
|
526
|
+
* @example
|
|
527
|
+
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
528
|
+
*
|
|
529
|
+
* @param {Communicator} api - communicator instance api
|
|
530
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
531
|
+
* @param {ConfiguratorEnvelope} data - configurator state after updated
|
|
532
|
+
* api.addEventListener('configuratorDataUpdated', (data) => {
|
|
533
|
+
* console.log('State updated after applied new component:', data);
|
|
534
|
+
* });
|
|
535
|
+
* };
|
|
387
536
|
*
|
|
388
537
|
* @example
|
|
389
538
|
* import { SetComponent, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
390
539
|
*
|
|
391
|
-
*
|
|
540
|
+
* @param {Communicator} api - communicator instance api
|
|
392
541
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
393
|
-
* api.
|
|
542
|
+
* api.sendCommandToMetabox(new SetComponent(
|
|
394
543
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3', 'typeId', true
|
|
395
544
|
* ));
|
|
396
545
|
* };
|
|
@@ -399,9 +548,9 @@ class SetComponent extends CommandBase {
|
|
|
399
548
|
/**
|
|
400
549
|
* Creates an instance of SetComponent.
|
|
401
550
|
*
|
|
402
|
-
* @param {string} id
|
|
403
|
-
* @param {string} typeId
|
|
404
|
-
* @param {boolean} isRoot
|
|
551
|
+
* @param {string} id - The component ID.
|
|
552
|
+
* @param {string} typeId - The component type ID.
|
|
553
|
+
* @param {boolean} isRoot - Whether this is a root component.
|
|
405
554
|
*/
|
|
406
555
|
constructor(id, typeId, isRoot) {
|
|
407
556
|
super();
|
|
@@ -415,10 +564,24 @@ class SetComponent extends CommandBase {
|
|
|
415
564
|
/**
|
|
416
565
|
* Represents a command to set component material by its slot ID and Material ID.
|
|
417
566
|
*
|
|
567
|
+
* @remarks
|
|
568
|
+
* To listen for changes after sending this command, listen to the 'configuratorDataUpdated' event.
|
|
569
|
+
* //...Assume that the integration is already implemented (only once)
|
|
570
|
+
* @example
|
|
571
|
+
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
572
|
+
*
|
|
573
|
+
* @param {Communicator} api - communicator instance api
|
|
574
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
575
|
+
* @param {ConfiguratorEnvelope} data - configurator state after updated
|
|
576
|
+
* api.addEventListener('configuratorDataUpdated', (data) => {
|
|
577
|
+
* console.log('State updated after applied new product:', data);
|
|
578
|
+
* });
|
|
579
|
+
* };
|
|
580
|
+
*
|
|
418
581
|
* @example
|
|
419
582
|
* import { SetComponentMaterial, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
420
583
|
*
|
|
421
|
-
*
|
|
584
|
+
* @param {Communicator} api - communicator instance api
|
|
422
585
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
423
586
|
* api.sendCommandToMetabox(new SetComponentMaterial(
|
|
424
587
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
|
|
@@ -447,12 +610,25 @@ class SetComponentMaterial extends CommandBase {
|
|
|
447
610
|
/**
|
|
448
611
|
* Represents a command to set the environment by its ID.
|
|
449
612
|
*
|
|
613
|
+
* @remarks
|
|
614
|
+
* To listen for changes after sending this command, listen to the 'configuratorDataUpdated' event.
|
|
615
|
+
* //...Assume that the integration is already implemented (only once)
|
|
616
|
+
* @example
|
|
617
|
+
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
618
|
+
*
|
|
619
|
+
* @param {Communicator} api - communicator instance api
|
|
620
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
621
|
+
* @param {ConfiguratorEnvelope} data - configurator state after updated
|
|
622
|
+
* api.addEventListener('configuratorDataUpdated', (data) => {
|
|
623
|
+
* console.log('State updated after applied new environment:', data);
|
|
624
|
+
* });
|
|
625
|
+
* };
|
|
626
|
+
*
|
|
450
627
|
* @example
|
|
451
628
|
* import { SetEnvironment, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
452
629
|
*
|
|
453
|
-
*
|
|
630
|
+
* @param {Communicator} api - communicator instance api
|
|
454
631
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
455
|
-
* // Change the environment to '55555555-1234-1234-1234-01234567890'
|
|
456
632
|
* api.sendCommandToMetabox(new SetEnvironment('55555555-1234-1234-1234-01234567890'));
|
|
457
633
|
* };
|
|
458
634
|
*/
|
|
@@ -465,8 +641,8 @@ class SetEnvironment extends CommandBase {
|
|
|
465
641
|
constructor(environmentId) {
|
|
466
642
|
super();
|
|
467
643
|
this.data = {
|
|
468
|
-
payload: { id: environmentId },
|
|
469
644
|
action: MetaboxModularConfiguratorActions.setEnvironment,
|
|
645
|
+
payload: { id: environmentId },
|
|
470
646
|
};
|
|
471
647
|
}
|
|
472
648
|
}
|
|
@@ -474,10 +650,24 @@ class SetEnvironment extends CommandBase {
|
|
|
474
650
|
/**
|
|
475
651
|
* Represents a command to set an environment material by its slot ID and Material ID.
|
|
476
652
|
*
|
|
653
|
+
* @remarks
|
|
654
|
+
* To listen for changes after sending this command, listen to the 'configuratorDataUpdated' event.
|
|
655
|
+
* //...Assume that the integration is already implemented (only once)
|
|
656
|
+
* @example
|
|
657
|
+
* import { Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
658
|
+
*
|
|
659
|
+
* @param {Communicator} api - communicator instance api
|
|
660
|
+
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
661
|
+
* @param {ConfiguratorEnvelope} data - configurator state after updated
|
|
662
|
+
* api.addEventListener('configuratorDataUpdated', (data) => {
|
|
663
|
+
* console.log('State updated after applied new environment material:', data);
|
|
664
|
+
* });
|
|
665
|
+
* };
|
|
666
|
+
*
|
|
477
667
|
* @example
|
|
478
668
|
* import { SetEnvironmentMaterial, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
479
669
|
*
|
|
480
|
-
*
|
|
670
|
+
* @param {Communicator} api - communicator instance api
|
|
481
671
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
482
672
|
* api.sendCommandToMetabox(new SetEnvironmentMaterial(
|
|
483
673
|
* 'carpaint',
|
|
@@ -495,21 +685,24 @@ class SetEnvironmentMaterial extends CommandBase {
|
|
|
495
685
|
constructor(slotId, materialId) {
|
|
496
686
|
super();
|
|
497
687
|
this.data = {
|
|
498
|
-
payload: { slotId, materialId },
|
|
499
688
|
action: MetaboxModularConfiguratorActions.setEnvironmentMaterialById,
|
|
689
|
+
payload: { slotId, materialId },
|
|
500
690
|
};
|
|
501
691
|
}
|
|
502
692
|
}
|
|
503
693
|
|
|
504
694
|
/**
|
|
505
|
-
* Represents a command to toggle the
|
|
695
|
+
* Represents a command to toggle the embedded Metabox menu.
|
|
696
|
+
* @remarks
|
|
697
|
+
* This command can only be used when using the metabox menu.
|
|
698
|
+
* **Important**: No need to listen to any events to see changes.
|
|
506
699
|
*
|
|
507
700
|
* @example
|
|
508
701
|
* import { ShowEmbeddedMenu, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
509
702
|
*
|
|
510
|
-
*
|
|
703
|
+
* @param {Communicator} api - communicator instance api
|
|
511
704
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
512
|
-
* api.
|
|
705
|
+
* api.sendCommandToMetabox(new ShowEmbeddedMenu(true));
|
|
513
706
|
* };
|
|
514
707
|
*/
|
|
515
708
|
class ShowEmbeddedMenu extends CommandBase {
|
|
@@ -532,11 +725,12 @@ class ShowEmbeddedMenu extends CommandBase {
|
|
|
532
725
|
*
|
|
533
726
|
* @remarks
|
|
534
727
|
* This action sends a message to the Metabox API to toggle the visibility of the Unreal overlay UI.
|
|
728
|
+
* **Important**: No need to listen to any events to see changes.
|
|
535
729
|
*
|
|
536
730
|
* @example
|
|
537
731
|
* import { ShowOverlayInterface, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
538
732
|
*
|
|
539
|
-
*
|
|
733
|
+
* @param {Communicator} api - communicator instance api
|
|
540
734
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
541
735
|
* api.setCommandToMetaBox(new ShowOverlayInterface(true));
|
|
542
736
|
* };
|
|
@@ -557,68 +751,49 @@ class ShowOverlayInterface extends CommandBase {
|
|
|
557
751
|
}
|
|
558
752
|
|
|
559
753
|
/**
|
|
560
|
-
* Represents a command to
|
|
561
|
-
*
|
|
754
|
+
* Represents a command to show measurement for a product when it is already loaded.
|
|
562
755
|
* @remarks
|
|
563
|
-
* This class sends a
|
|
756
|
+
* This class sends a command to the Metabox API to show measurement for a product if it is already initialized.
|
|
757
|
+
* **Important**: No need to listen to any events to see changes.
|
|
758
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
564
759
|
*
|
|
565
760
|
* @example
|
|
566
|
-
* import {
|
|
761
|
+
* import { ShowMeasurement, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
567
762
|
*
|
|
568
|
-
*
|
|
763
|
+
* @param {Communicator} api - communicator instance api
|
|
569
764
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
570
|
-
*
|
|
765
|
+
* api.sendCommandToMetabox(new ShowMeasurement());
|
|
571
766
|
* };
|
|
572
767
|
*/
|
|
573
|
-
class
|
|
768
|
+
class ShowMeasurement extends CommandBase {
|
|
574
769
|
/**
|
|
575
|
-
* Creates an instance of
|
|
770
|
+
* Creates an instance of ShowMeasurement.
|
|
576
771
|
*
|
|
577
|
-
* @
|
|
578
|
-
|
|
579
|
-
constructor(deviceType) {
|
|
580
|
-
super();
|
|
581
|
-
this.data = {
|
|
582
|
-
payload: { deviceType },
|
|
583
|
-
action: MetaboxModularConfiguratorActions.forceSetDeviceType,
|
|
584
|
-
};
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
/**
|
|
589
|
-
* Represents a command to send Metabox Config to Metabox Modular Configurator.
|
|
590
|
-
* @remarks
|
|
591
|
-
* Automatically sent when the Communicator instance is ready.
|
|
592
|
-
*/
|
|
593
|
-
class MetaboxConfig extends CommandBase {
|
|
594
|
-
/**
|
|
595
|
-
* Creates an instance of MetaboxConfig.
|
|
596
|
-
* @param {string} appId - The unique identifier for the Communicator Instance
|
|
597
|
-
* @param {MetaboxCommandConfig} config - optional initial config: standalone - if true - disable metabox custom template and all logic
|
|
772
|
+
* @remarks
|
|
773
|
+
* This constructor does not require any parameters.
|
|
598
774
|
*/
|
|
599
|
-
constructor(
|
|
775
|
+
constructor() {
|
|
600
776
|
super();
|
|
601
|
-
this.data = {
|
|
602
|
-
action: MetaboxModularConfiguratorActions.metaboxConfig,
|
|
603
|
-
payload: { appId, config },
|
|
604
|
-
};
|
|
777
|
+
this.data = { action: MetaboxModularConfiguratorActions.showMeasurement };
|
|
605
778
|
}
|
|
606
779
|
}
|
|
607
780
|
|
|
608
781
|
/**
|
|
609
|
-
* Represents a command to
|
|
782
|
+
* Represents a command to hide measurement for a product when it is already loaded.
|
|
610
783
|
* @remarks
|
|
611
|
-
* This class sends a command to the Metabox API to
|
|
612
|
-
*
|
|
784
|
+
* This class sends a command to the Metabox API to hide measurement for a product if it is already initialized.
|
|
785
|
+
* **Important**: No need to listen to any events to see changes.
|
|
613
786
|
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
614
787
|
*
|
|
615
788
|
* @example
|
|
616
|
-
* import {
|
|
789
|
+
* import { HideMeasurement, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
790
|
+
*
|
|
791
|
+
* @param {Communicator} api - communicator instance api
|
|
617
792
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
618
|
-
* api.sendCommandToMetabox(new
|
|
793
|
+
* api.sendCommandToMetabox(new HideMeasurement());
|
|
619
794
|
* };
|
|
620
795
|
*/
|
|
621
|
-
class
|
|
796
|
+
class HideMeasurement extends CommandBase {
|
|
622
797
|
/**
|
|
623
798
|
* Creates an instance of HideMeasurement.
|
|
624
799
|
*
|
|
@@ -627,33 +802,38 @@ class ShowMeasurement extends CommandBase {
|
|
|
627
802
|
*/
|
|
628
803
|
constructor() {
|
|
629
804
|
super();
|
|
630
|
-
this.data = { action: MetaboxModularConfiguratorActions.
|
|
805
|
+
this.data = { action: MetaboxModularConfiguratorActions.hideMeasurement };
|
|
631
806
|
}
|
|
632
807
|
}
|
|
633
808
|
|
|
634
809
|
/**
|
|
635
|
-
* Represents a command to
|
|
636
|
-
* @remarks
|
|
637
|
-
* This class sends a command to the Metabox API to Hide Measurement for a product if it is already initialized.
|
|
810
|
+
* Represents a command to force set the device type.
|
|
638
811
|
*
|
|
639
|
-
*
|
|
812
|
+
* @remarks
|
|
813
|
+
* This class sends a message to the Metabox API to force set the device type.
|
|
814
|
+
* **Important**: No need to listen to any events to see changes.
|
|
815
|
+
* //...Assume that the integration is already implemented (only once)
|
|
640
816
|
*
|
|
641
817
|
* @example
|
|
642
|
-
* import {
|
|
818
|
+
* import { ForceSetDeviceType, Communicator } from '@3dsource/metabox-modular-configurator-api';
|
|
819
|
+
*
|
|
820
|
+
* @param {Communicator} api - communicator instance api
|
|
643
821
|
* window.env3DSource.apiReady = (api: Communicator) => {
|
|
644
|
-
*
|
|
822
|
+
* api.sendCommandToMetabox(new ForceSetDeviceType('desktop'));
|
|
645
823
|
* };
|
|
646
824
|
*/
|
|
647
|
-
class
|
|
825
|
+
class ForceSetDeviceType extends CommandBase {
|
|
648
826
|
/**
|
|
649
|
-
* Creates an instance of
|
|
827
|
+
* Creates an instance of ForceSetDeviceType.
|
|
650
828
|
*
|
|
651
|
-
* @
|
|
652
|
-
* This constructor does not require any parameters.
|
|
829
|
+
* @param {ApplicationDeviceTypes} deviceType - The device type to force set.
|
|
653
830
|
*/
|
|
654
|
-
constructor() {
|
|
831
|
+
constructor(deviceType) {
|
|
655
832
|
super();
|
|
656
|
-
this.data = {
|
|
833
|
+
this.data = {
|
|
834
|
+
payload: { deviceType },
|
|
835
|
+
action: MetaboxModularConfiguratorActions.forceSetDeviceType,
|
|
836
|
+
};
|
|
657
837
|
}
|
|
658
838
|
}
|
|
659
839
|
|
|
@@ -705,6 +885,11 @@ class EventDispatcher {
|
|
|
705
885
|
}
|
|
706
886
|
}
|
|
707
887
|
|
|
888
|
+
/**
|
|
889
|
+
* @internal
|
|
890
|
+
* @hidden
|
|
891
|
+
* Represents main constants.
|
|
892
|
+
*/
|
|
708
893
|
const Metabox = 'metabox_v3';
|
|
709
894
|
const MetaboxHost = 'metaboxHost_v3';
|
|
710
895
|
const MetaboxData = 'metaboxData_v3';
|
|
@@ -712,7 +897,7 @@ const AppLoaded = 'appLoaded_v3';
|
|
|
712
897
|
const MetaboxDomain = 'metabox.3dsource.com';
|
|
713
898
|
const BasicRouteUrl = 'metabox-configurator/modular';
|
|
714
899
|
|
|
715
|
-
const VERSION = '3.0.
|
|
900
|
+
const VERSION = '3.0.18';
|
|
716
901
|
|
|
717
902
|
const communicatorMap = new Map();
|
|
718
903
|
/**
|
|
@@ -787,10 +972,11 @@ class Communicator extends EventDispatcher {
|
|
|
787
972
|
const iframe = document.getElementById('embeddedContent');
|
|
788
973
|
const message = {
|
|
789
974
|
host: MetaboxHost,
|
|
975
|
+
envelope: { ...data },
|
|
790
976
|
payload: { ...data },
|
|
791
977
|
};
|
|
792
978
|
if (!iframe?.contentWindow) {
|
|
793
|
-
console.warn('
|
|
979
|
+
console.warn('Metabox IFrame not found or not ready. Message sends to the same window');
|
|
794
980
|
window.postMessage({ ...message, target: 'metabox' }, '*');
|
|
795
981
|
return;
|
|
796
982
|
}
|
|
@@ -819,7 +1005,7 @@ class Communicator extends EventDispatcher {
|
|
|
819
1005
|
return super.removeEventListener(messageType, callback);
|
|
820
1006
|
}
|
|
821
1007
|
/**
|
|
822
|
-
* Filters and dispatches incoming messages from
|
|
1008
|
+
* Filters and dispatches incoming messages from the Metabox.
|
|
823
1009
|
* @param messageType - Expected message type for filtering (MetaboxData).
|
|
824
1010
|
* @param event - The postMessage event received on a window.
|
|
825
1011
|
*/
|
|
@@ -833,6 +1019,15 @@ class Communicator extends EventDispatcher {
|
|
|
833
1019
|
}
|
|
834
1020
|
}
|
|
835
1021
|
|
|
1022
|
+
/**
|
|
1023
|
+
*
|
|
1024
|
+
* @remarks
|
|
1025
|
+
* @internal
|
|
1026
|
+
* @hidden
|
|
1027
|
+
*
|
|
1028
|
+
* @param {string} configuratorId - An string identifier for the configurator.
|
|
1029
|
+
* @param {IntegrateMetaboxConfig} config - An object containing the configuration options.
|
|
1030
|
+
*/
|
|
836
1031
|
const prepareIframeSrc = (configuratorId, config) => {
|
|
837
1032
|
const base = `https://${config?.domain || MetaboxDomain}/${BasicRouteUrl}/${configuratorId}`;
|
|
838
1033
|
const params = new URLSearchParams();
|