@3dsource/metabox-front-api 0.0.18 → 0.0.19-beta.1
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 +218 -202
- package/dist/actions/CommandBase.d.ts +7 -0
- package/dist/actions/GetFastRender.d.ts +10 -14
- package/dist/actions/GetPdf.d.ts +8 -8
- package/dist/actions/SendCommandToUnreal.d.ts +4 -4
- package/dist/actions/SetEnvironment.d.ts +7 -9
- package/dist/actions/SetEnvironmentMaterial.d.ts +8 -11
- package/dist/actions/SetMaterial.d.ts +8 -11
- package/dist/actions/SetProduct.d.ts +8 -8
- package/dist/actions/ShowEmbeddedMenu.d.ts +7 -10
- package/dist/actions/ShowOverlayInterface.d.ts +7 -7
- package/dist/actions/WatchCallbacks.d.ts +3 -3
- package/dist/const/FromMetaboxApiAction.d.ts +52 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.esm.js +126 -236
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +126 -239
- package/dist/index.umd.js.map +1 -1
- package/dist/interfaces/FromMetaboxMessagePayloads.d.ts +21 -73
- package/dist/interfaces/ToMetaboxMessagePayloads.d.ts +7 -23
- package/dist/interfaces/UniversalConfigurator.d.ts +42 -2
- package/dist/interfaces/application-device-types.d.ts +1 -10
- package/dist/lib/{initializeCommunicator.d.ts → Communicator.d.ts} +7 -13
- package/dist/lib/EventDispatcher.d.ts +3 -3
- package/dist/lib/integrateMetaBox.d.ts +4 -3
- package/dist/lib/test/Communicator.spec.d.ts +1 -0
- package/dist/lib/test/integrateMetabox.spec.d.ts +9 -0
- package/package.json +51 -48
- package/dist/actions/ApiAction.d.ts +0 -26
package/dist/index.esm.js
CHANGED
|
@@ -1,67 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* **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.**
|
|
5
|
-
*
|
|
6
|
-
* ```typescript
|
|
7
|
-
* import { integrateMetaBox } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
8
|
-
*
|
|
9
|
-
* integrateMetaBox(
|
|
10
|
-
* 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
|
|
11
|
-
* 'embed3DSource'
|
|
12
|
-
* );
|
|
13
|
-
*
|
|
14
|
-
* // Set up the global API environment
|
|
15
|
-
* window.env3DSource = window.env3DSource || {};
|
|
16
|
-
*
|
|
17
|
-
* //Listen for the API ready event
|
|
18
|
-
* window.env3DSource.apiReady = (api) => {
|
|
19
|
-
* // Use the API actions here
|
|
20
|
-
* };
|
|
21
|
-
* ```
|
|
2
|
+
* Base class for commands sent to the MetaBox.
|
|
22
3
|
*/
|
|
23
|
-
class
|
|
24
|
-
constructor() {
|
|
25
|
-
this.api = window.env3DSource.api;
|
|
26
|
-
}
|
|
4
|
+
class CommandBase {
|
|
27
5
|
}
|
|
28
6
|
|
|
29
|
-
const ToMetaBoxApiAction = {
|
|
30
|
-
getPdf: 'getPdf',
|
|
31
|
-
loadLevel: 'loadLevel',
|
|
32
|
-
setProduct: 'setProduct',
|
|
33
|
-
/**
|
|
34
|
-
* @deprecated, use 'watchCallbacks'"
|
|
35
|
-
* use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
36
|
-
* @hidden
|
|
37
|
-
*/
|
|
38
|
-
addResponse: 'addResponse',
|
|
39
|
-
getFastRender: 'getFastRender',
|
|
40
|
-
watchCallbacks: 'watchCallbacks',
|
|
41
|
-
setMaterialById: 'setMaterialById',
|
|
42
|
-
showEmbeddedMenu: 'showEmbeddedMenu',
|
|
43
|
-
forceSetDeviceType: 'forceSetDeviceType',
|
|
44
|
-
sendCommandToUnreal: 'sendCommandToUnreal',
|
|
45
|
-
showOverlayInterface: 'showOverlayInterface',
|
|
46
|
-
setEnvironmentMaterialById: 'setEnvironmentMaterialById',
|
|
47
|
-
resetCamera: 'resetCamera',
|
|
48
|
-
};
|
|
49
|
-
|
|
50
7
|
/**
|
|
51
|
-
* {@inheritDoc
|
|
8
|
+
* {@inheritDoc CommandBase}
|
|
52
9
|
*
|
|
53
|
-
* Represents
|
|
10
|
+
* Represents a command to toggle the Unreal Overlay Interface Menu.
|
|
54
11
|
*
|
|
55
12
|
* @remarks
|
|
56
13
|
* This action sends a message to the MetaBox API to toggle the visibility of the Unreal overlay UI.
|
|
57
14
|
*
|
|
58
15
|
* @example
|
|
59
|
-
* import { ShowOverlayInterface } from '
|
|
60
|
-
* window.env3DSource.apiReady = (api) => {
|
|
61
|
-
* new ShowOverlayInterface(true);
|
|
16
|
+
* import { ShowOverlayInterface,Communicator } from '@3dsource/metabox-front-api';
|
|
17
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
18
|
+
* api.setCommandToMetaBox(new ShowOverlayInterface(true));
|
|
62
19
|
* };
|
|
63
20
|
*/
|
|
64
|
-
class ShowOverlayInterface extends
|
|
21
|
+
class ShowOverlayInterface extends CommandBase {
|
|
65
22
|
/**
|
|
66
23
|
* Creates an instance of ShowOverlayInterface.
|
|
67
24
|
*
|
|
@@ -69,30 +26,27 @@ class ShowOverlayInterface extends ApiAction {
|
|
|
69
26
|
*/
|
|
70
27
|
constructor(visible) {
|
|
71
28
|
super();
|
|
72
|
-
this.
|
|
73
|
-
action:
|
|
29
|
+
this.data = {
|
|
30
|
+
action: 'showOverlayInterface',
|
|
74
31
|
payload: {
|
|
75
32
|
visible,
|
|
76
33
|
},
|
|
77
|
-
}
|
|
34
|
+
};
|
|
78
35
|
}
|
|
79
36
|
}
|
|
80
37
|
|
|
81
38
|
/**
|
|
82
|
-
* {@inheritDoc
|
|
83
|
-
*
|
|
84
|
-
* Represents an action to toggle the Embedded MetaBox Menu.
|
|
39
|
+
* {@inheritDoc CommandBase}
|
|
85
40
|
*
|
|
86
|
-
*
|
|
87
|
-
* This action sends a message to the MetaBox API to toggle the visibility of the embedded menu.
|
|
41
|
+
* Represents a command to toggle the Embedded MetaBox Menu.
|
|
88
42
|
*
|
|
89
43
|
* @example
|
|
90
|
-
* import { ShowEmbeddedMenu } from '
|
|
91
|
-
* window.env3DSource.apiReady = (api) => {
|
|
92
|
-
* new ShowEmbeddedMenu(true);
|
|
44
|
+
* import { ShowEmbeddedMenu,Communicator } from '@3dsource/metabox-front-api';
|
|
45
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
46
|
+
* api.setCommandToMetaBox(new ShowEmbeddedMenu(true));
|
|
93
47
|
* };
|
|
94
48
|
*/
|
|
95
|
-
class ShowEmbeddedMenu extends
|
|
49
|
+
class ShowEmbeddedMenu extends CommandBase {
|
|
96
50
|
/**
|
|
97
51
|
* Creates an instance of ShowEmbeddedMenu.
|
|
98
52
|
*
|
|
@@ -100,30 +54,28 @@ class ShowEmbeddedMenu extends ApiAction {
|
|
|
100
54
|
*/
|
|
101
55
|
constructor(visible) {
|
|
102
56
|
super();
|
|
103
|
-
this.
|
|
104
|
-
action:
|
|
57
|
+
this.data = {
|
|
58
|
+
action: 'showEmbeddedMenu',
|
|
105
59
|
payload: {
|
|
106
60
|
visible,
|
|
107
61
|
},
|
|
108
|
-
}
|
|
62
|
+
};
|
|
109
63
|
}
|
|
110
64
|
}
|
|
111
65
|
|
|
112
66
|
/**
|
|
113
|
-
* {@inheritDoc
|
|
67
|
+
* {@inheritDoc CommandBase}
|
|
114
68
|
*
|
|
115
|
-
* Represents
|
|
116
|
-
* @remarks
|
|
117
|
-
* This action sends a message to the MetaBox API to load the environment level using the specified environment ID.
|
|
69
|
+
* Represents a command to set the environment by its ID.
|
|
118
70
|
*
|
|
119
71
|
* @example
|
|
120
|
-
* import { SetEnvironment } from '
|
|
121
|
-
* window.env3DSource.apiReady = (api) => {
|
|
72
|
+
* import { SetEnvironment,Communicator } from '@3dsource/metabox-front-api';
|
|
73
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
122
74
|
* // Change the environment to '55555555-1234-1234-1234-01234567890'
|
|
123
|
-
* new SetEnvironment('55555555-1234-1234-1234-01234567890');
|
|
75
|
+
* api.sendCommandToMetaBox(new SetEnvironment('55555555-1234-1234-1234-01234567890'));
|
|
124
76
|
* };
|
|
125
77
|
*/
|
|
126
|
-
class SetEnvironment extends
|
|
78
|
+
class SetEnvironment extends CommandBase {
|
|
127
79
|
/**
|
|
128
80
|
* Creates an instance of SetEnvironment.
|
|
129
81
|
*
|
|
@@ -131,32 +83,32 @@ class SetEnvironment extends ApiAction {
|
|
|
131
83
|
*/
|
|
132
84
|
constructor(environmentId) {
|
|
133
85
|
super();
|
|
134
|
-
this.
|
|
86
|
+
this.data = {
|
|
135
87
|
payload: {
|
|
136
88
|
id: environmentId,
|
|
137
89
|
},
|
|
138
|
-
action:
|
|
139
|
-
}
|
|
90
|
+
action: 'loadLevel',
|
|
91
|
+
};
|
|
140
92
|
}
|
|
141
93
|
}
|
|
142
94
|
|
|
143
95
|
/**
|
|
144
|
-
* {@inheritDoc
|
|
96
|
+
* {@inheritDoc CommandBase}
|
|
145
97
|
*
|
|
146
|
-
* Represents
|
|
98
|
+
* Represents a command to set a product by its ID.
|
|
147
99
|
*
|
|
148
100
|
* @remarks
|
|
149
101
|
* This action sends a message to the MetaBox API to set a product using the provided product ID.
|
|
150
102
|
*
|
|
151
103
|
* @example
|
|
152
|
-
* import { SetProduct } from '
|
|
153
|
-
* window.env3DSource.apiReady = (api) => {
|
|
154
|
-
* new SetProduct(
|
|
104
|
+
* import { SetProduct,Communicator } from '@3dsource/metabox-front-api';
|
|
105
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
106
|
+
* api.setCommandToMetaBox(new SetProduct(
|
|
155
107
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3'
|
|
156
|
-
* );
|
|
108
|
+
* ));
|
|
157
109
|
* };
|
|
158
110
|
*/
|
|
159
|
-
class SetProduct extends
|
|
111
|
+
class SetProduct extends CommandBase {
|
|
160
112
|
/**
|
|
161
113
|
* Creates an instance of SetProduct.
|
|
162
114
|
*
|
|
@@ -164,32 +116,32 @@ class SetProduct extends ApiAction {
|
|
|
164
116
|
*/
|
|
165
117
|
constructor(productId) {
|
|
166
118
|
super();
|
|
167
|
-
this.
|
|
119
|
+
this.data = {
|
|
168
120
|
payload: {
|
|
169
121
|
productId,
|
|
170
122
|
},
|
|
171
|
-
action:
|
|
172
|
-
}
|
|
123
|
+
action: 'setProduct',
|
|
124
|
+
};
|
|
173
125
|
}
|
|
174
126
|
}
|
|
175
127
|
|
|
176
128
|
/**
|
|
177
|
-
* {@inheritDoc
|
|
129
|
+
* {@inheritDoc CommandBase}
|
|
178
130
|
*
|
|
179
|
-
* Represents
|
|
131
|
+
* Represents a command to get a PDF from Metabox.
|
|
180
132
|
* @remarks
|
|
181
133
|
* This class sends a message to the MetaBox API to generate a PDF based on the current configuration.
|
|
182
134
|
* This action does not require any parameters.
|
|
183
135
|
*
|
|
184
|
-
* **Important**: Invoking this
|
|
136
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
185
137
|
*
|
|
186
138
|
* @example
|
|
187
|
-
* import { GetPdf } from '
|
|
188
|
-
* window.env3DSource.apiReady = (api) => {
|
|
189
|
-
* new GetPdf();
|
|
139
|
+
* import { GetPdf,Communicator } from '@3dsource/metabox-front-api';
|
|
140
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
141
|
+
* api.sendCommandToMetaBox(new GetPdf());
|
|
190
142
|
* };
|
|
191
143
|
*/
|
|
192
|
-
class GetPdf extends
|
|
144
|
+
class GetPdf extends CommandBase {
|
|
193
145
|
/**
|
|
194
146
|
* Creates an instance of GetPdf.
|
|
195
147
|
*
|
|
@@ -198,31 +150,28 @@ class GetPdf extends ApiAction {
|
|
|
198
150
|
*/
|
|
199
151
|
constructor() {
|
|
200
152
|
super();
|
|
201
|
-
this.
|
|
202
|
-
action:
|
|
203
|
-
}
|
|
153
|
+
this.data = {
|
|
154
|
+
action: 'getPdf',
|
|
155
|
+
};
|
|
204
156
|
}
|
|
205
157
|
}
|
|
206
158
|
|
|
207
159
|
/**
|
|
208
|
-
* {@inheritDoc
|
|
160
|
+
* {@inheritDoc CommandBase}
|
|
209
161
|
*
|
|
210
|
-
* Represents
|
|
211
|
-
*
|
|
212
|
-
* @remarks
|
|
213
|
-
* This action sends a message to the MetaBox API to update the material on a specific product slot using the provided identifiers.
|
|
162
|
+
* Represents a command to set a material by its ID.
|
|
214
163
|
*
|
|
215
164
|
* @example
|
|
216
|
-
* import { SetMaterial } from '
|
|
217
|
-
* window.env3DSource.apiReady = (api) => {
|
|
218
|
-
* new SetMaterial(
|
|
165
|
+
* import { SetMaterial,Communicator } from '@3dsource/metabox-front-api';
|
|
166
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
167
|
+
* api.sendCommandToMetaBox(new SetMaterial(
|
|
219
168
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
|
|
220
169
|
* 'carpaint',
|
|
221
170
|
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
222
|
-
* );
|
|
171
|
+
* ));
|
|
223
172
|
* };
|
|
224
173
|
*/
|
|
225
|
-
class SetMaterial extends
|
|
174
|
+
class SetMaterial extends CommandBase {
|
|
226
175
|
/**
|
|
227
176
|
* Creates an instance of SetMaterial.
|
|
228
177
|
*
|
|
@@ -232,36 +181,33 @@ class SetMaterial extends ApiAction {
|
|
|
232
181
|
*/
|
|
233
182
|
constructor(productId, slotId, materialId) {
|
|
234
183
|
super();
|
|
235
|
-
this.
|
|
184
|
+
this.data = {
|
|
236
185
|
payload: {
|
|
237
186
|
productId,
|
|
238
187
|
slotId,
|
|
239
188
|
materialId,
|
|
240
189
|
},
|
|
241
|
-
action:
|
|
242
|
-
}
|
|
190
|
+
action: 'setMaterialById',
|
|
191
|
+
};
|
|
243
192
|
}
|
|
244
193
|
}
|
|
245
194
|
|
|
246
195
|
/**
|
|
247
|
-
* {@inheritDoc
|
|
248
|
-
*
|
|
249
|
-
* Represents an action to set a environment material by its ID.
|
|
196
|
+
* {@inheritDoc CommandBase}
|
|
250
197
|
*
|
|
251
|
-
*
|
|
252
|
-
* This action sends a message to the MetaBox API to update the material on a specific environment slot using the provided identifiers.
|
|
198
|
+
* Represents a command to set an environment material by its ID.
|
|
253
199
|
*
|
|
254
200
|
* @example
|
|
255
|
-
* import { SetEnvironmentMaterial } from '
|
|
256
|
-
* window.env3DSource.apiReady = (api) => {
|
|
257
|
-
* new SetEnvironmentMaterial(
|
|
201
|
+
* import { SetEnvironmentMaterial,Communicator } from '@3dsource/metabox-front-api';
|
|
202
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
203
|
+
* api.sendCommandToMetaBox(new SetEnvironmentMaterial(
|
|
258
204
|
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
|
|
259
205
|
* 'carpaint',
|
|
260
206
|
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
261
|
-
* );
|
|
207
|
+
* ));
|
|
262
208
|
* };
|
|
263
209
|
*/
|
|
264
|
-
class SetEnvironmentMaterial extends
|
|
210
|
+
class SetEnvironmentMaterial extends CommandBase {
|
|
265
211
|
/**
|
|
266
212
|
* Creates an instance of SetEnvironmentMaterial.
|
|
267
213
|
*
|
|
@@ -271,40 +217,36 @@ class SetEnvironmentMaterial extends ApiAction {
|
|
|
271
217
|
*/
|
|
272
218
|
constructor(productId, slotId, materialId) {
|
|
273
219
|
super();
|
|
274
|
-
this.
|
|
220
|
+
this.data = {
|
|
275
221
|
payload: {
|
|
276
222
|
productId,
|
|
277
223
|
slotId,
|
|
278
224
|
materialId,
|
|
279
225
|
},
|
|
280
|
-
action:
|
|
281
|
-
}
|
|
226
|
+
action: 'setEnvironmentMaterialById',
|
|
227
|
+
};
|
|
282
228
|
}
|
|
283
229
|
}
|
|
284
230
|
|
|
285
231
|
/**
|
|
286
|
-
* {@inheritDoc
|
|
232
|
+
* {@inheritDoc CommandBase}
|
|
287
233
|
*
|
|
288
|
-
* Represents a fast render
|
|
289
|
-
* @remarks
|
|
290
|
-
* This class sends a message to the MetaBox API to obtain a fast render based on the provided format and optional size.
|
|
234
|
+
* Represents a command to get fast render.
|
|
291
235
|
*
|
|
292
|
-
* **Important**: Invoking this
|
|
236
|
+
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
293
237
|
*
|
|
294
238
|
* @example
|
|
295
|
-
* import { GetFastRender,saveImage } from '
|
|
296
|
-
* window.env3DSource.apiReady = (api) => {
|
|
239
|
+
* import { GetFastRender,Communicator,saveImage } from '@3dsource/metabox-front-api';
|
|
240
|
+
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
297
241
|
* // Listen for events from the MetaBox API
|
|
298
|
-
* api.addEventListener('
|
|
242
|
+
* api.addEventListener('fastRender', (data) => {
|
|
299
243
|
* // Process the fast render response
|
|
300
|
-
*
|
|
301
|
-
* saveImage(data.payload, 'Render.png');
|
|
302
|
-
* }
|
|
244
|
+
* saveImage(data, 'Render.png');
|
|
303
245
|
* });
|
|
304
|
-
* new GetFastRender('image/png', { x: 1024, y: 1024 });
|
|
246
|
+
* api.sendCommandToMetaBox(new GetFastRender('image/png', { x: 1024, y: 1024 }));
|
|
305
247
|
* };
|
|
306
248
|
*/
|
|
307
|
-
class GetFastRender extends
|
|
249
|
+
class GetFastRender extends CommandBase {
|
|
308
250
|
/**
|
|
309
251
|
* Constructs an instance of GetFastRender.
|
|
310
252
|
* @param mimeType - The output format.
|
|
@@ -312,29 +254,29 @@ class GetFastRender extends ApiAction {
|
|
|
312
254
|
*/
|
|
313
255
|
constructor(mimeType, size) {
|
|
314
256
|
super();
|
|
315
|
-
this.
|
|
257
|
+
this.data = {
|
|
316
258
|
payload: {
|
|
317
259
|
format: mimeType,
|
|
318
260
|
size,
|
|
319
261
|
},
|
|
320
|
-
action:
|
|
321
|
-
}
|
|
262
|
+
action: 'getFastRender',
|
|
263
|
+
};
|
|
322
264
|
}
|
|
323
265
|
}
|
|
324
266
|
|
|
325
267
|
/**
|
|
326
|
-
* {@inheritDoc
|
|
268
|
+
* {@inheritDoc CommandBase}
|
|
327
269
|
* @internal
|
|
328
270
|
* @hidden
|
|
329
|
-
* Represents
|
|
271
|
+
* Represents a command to send Unreal command.
|
|
330
272
|
*/
|
|
331
|
-
class SendCommandToUnreal extends
|
|
273
|
+
class SendCommandToUnreal extends CommandBase {
|
|
332
274
|
constructor(payload) {
|
|
333
275
|
super();
|
|
334
|
-
this.
|
|
276
|
+
this.data = {
|
|
335
277
|
payload,
|
|
336
|
-
action:
|
|
337
|
-
}
|
|
278
|
+
action: 'sendCommandToUnreal',
|
|
279
|
+
};
|
|
338
280
|
}
|
|
339
281
|
}
|
|
340
282
|
|
|
@@ -343,10 +285,10 @@ class SendCommandToUnreal extends ApiAction {
|
|
|
343
285
|
* @internal
|
|
344
286
|
* @hidden
|
|
345
287
|
* @remarks
|
|
346
|
-
* Represents
|
|
288
|
+
* Represents a command to watch Unreal callbacks from Unreal engine.
|
|
347
289
|
* Can be useful for custom solutions.
|
|
348
290
|
*/
|
|
349
|
-
class WatchCallbacks extends
|
|
291
|
+
class WatchCallbacks extends CommandBase {
|
|
350
292
|
/**
|
|
351
293
|
* Creates an instance of WatchCallbacks.
|
|
352
294
|
*
|
|
@@ -355,9 +297,9 @@ class WatchCallbacks extends ApiAction {
|
|
|
355
297
|
*/
|
|
356
298
|
constructor() {
|
|
357
299
|
super();
|
|
358
|
-
this.
|
|
359
|
-
action:
|
|
360
|
-
}
|
|
300
|
+
this.data = {
|
|
301
|
+
action: 'watchCallbacks',
|
|
302
|
+
};
|
|
361
303
|
}
|
|
362
304
|
}
|
|
363
305
|
|
|
@@ -382,6 +324,7 @@ class EventDispatcher {
|
|
|
382
324
|
*/
|
|
383
325
|
addEventListener(messageType, callback) {
|
|
384
326
|
this.listeners.push({ messageType, callback });
|
|
327
|
+
return this;
|
|
385
328
|
}
|
|
386
329
|
/**
|
|
387
330
|
* Dispatches an event to all listeners of a specific message type.
|
|
@@ -393,6 +336,7 @@ class EventDispatcher {
|
|
|
393
336
|
this.listeners
|
|
394
337
|
.filter((listener) => listener.messageType === messageType)
|
|
395
338
|
.forEach((listener) => listener.callback(data));
|
|
339
|
+
return this;
|
|
396
340
|
}
|
|
397
341
|
/**
|
|
398
342
|
* Removes an event listener for a specific type of message.
|
|
@@ -402,10 +346,10 @@ class EventDispatcher {
|
|
|
402
346
|
*/
|
|
403
347
|
removeEventListener(messageType, callback) {
|
|
404
348
|
this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
|
|
349
|
+
return this;
|
|
405
350
|
}
|
|
406
351
|
}
|
|
407
352
|
|
|
408
|
-
const binderMessageType = 'metaboxData';
|
|
409
353
|
/**
|
|
410
354
|
* API class to handle communication with the embedded content.
|
|
411
355
|
* @internal Do not Create an instance of this class directly.
|
|
@@ -429,7 +373,7 @@ class Communicator extends EventDispatcher {
|
|
|
429
373
|
/**
|
|
430
374
|
* Binder function for handling incoming messages.
|
|
431
375
|
*/
|
|
432
|
-
this.binder = this.handleMessageReceived.bind(this,
|
|
376
|
+
this.binder = this.handleMessageReceived.bind(this, 'metaboxData');
|
|
433
377
|
(_a = Communicator.instance) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
434
378
|
Communicator.instance = this;
|
|
435
379
|
window.addEventListener('message', this.binder);
|
|
@@ -443,12 +387,16 @@ class Communicator extends EventDispatcher {
|
|
|
443
387
|
}
|
|
444
388
|
/**
|
|
445
389
|
* Sends a message to the embedded content (MetaBox).
|
|
446
|
-
*
|
|
447
|
-
* @param data - The data to send.
|
|
390
|
+
* @param command
|
|
448
391
|
*/
|
|
449
|
-
|
|
392
|
+
sendCommandToMetaBox(command) {
|
|
450
393
|
var _a;
|
|
394
|
+
const data = command.data;
|
|
451
395
|
const iframe = document.getElementById('embeddedContent');
|
|
396
|
+
if (!(iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow)) {
|
|
397
|
+
console.warn('Iframe not found or not ready');
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
452
400
|
const dataToSend = {
|
|
453
401
|
host: 'metaBoxHost',
|
|
454
402
|
payload: Object.assign({}, data),
|
|
@@ -480,19 +428,23 @@ class Communicator extends EventDispatcher {
|
|
|
480
428
|
* @remarks
|
|
481
429
|
* This function sets up a listener that waits for the 'appLoaded' action and then initializes the Communicator.
|
|
482
430
|
*/
|
|
483
|
-
static createInstance() {
|
|
484
|
-
window.env3DSource = Object.assign({}, window.env3DSource);
|
|
431
|
+
static createInstance(apiReadyCallback) {
|
|
485
432
|
const startHandler = (event) => {
|
|
486
|
-
var _a
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
window.env3DSource.apiReady(window.env3DSource.api);
|
|
433
|
+
var _a;
|
|
434
|
+
const message = event.data;
|
|
435
|
+
if (((_a = message === null || message === void 0 ? void 0 : message.payload) === null || _a === void 0 ? void 0 : _a.action) === 'appLoaded') {
|
|
436
|
+
apiReadyCallback(new Communicator());
|
|
491
437
|
window.removeEventListener('message', startHandler);
|
|
492
438
|
}
|
|
493
439
|
};
|
|
494
440
|
window.addEventListener('message', startHandler);
|
|
495
441
|
}
|
|
442
|
+
addEventListener(eventName, callback) {
|
|
443
|
+
return super.addEventListener(eventName, callback);
|
|
444
|
+
}
|
|
445
|
+
dispatchEvent(eventType, data) {
|
|
446
|
+
return super.dispatchEvent(eventType, data);
|
|
447
|
+
}
|
|
496
448
|
}
|
|
497
449
|
/**
|
|
498
450
|
* The singleton instance of the communicator.
|
|
@@ -515,33 +467,33 @@ Communicator.instance = null;
|
|
|
515
467
|
* i.e. final link will look like https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false&introImage=https://example.com/image.png
|
|
516
468
|
*
|
|
517
469
|
* @param containerId - The ID of the layout element. Defaults to 'embed3DSource'.
|
|
518
|
-
*
|
|
470
|
+
* @param apiReadyCallback
|
|
519
471
|
* @throws Error if the container element with the specified ID is not found.
|
|
520
472
|
*
|
|
521
473
|
* @example
|
|
522
474
|
* import {
|
|
523
475
|
* integrateMetaBox,
|
|
524
|
-
* } from '
|
|
476
|
+
* } from '@3dsource/metabox-front-api';
|
|
525
477
|
*
|
|
526
478
|
* integrateMetaBox(
|
|
527
479
|
* 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
|
|
528
480
|
* 'embed3DSource'
|
|
529
481
|
* );
|
|
530
482
|
*/
|
|
531
|
-
function integrateMetaBox(iframeSrc, containerId = 'embed3DSource') {
|
|
483
|
+
function integrateMetaBox(iframeSrc, containerId = 'embed3DSource', apiReadyCallback) {
|
|
532
484
|
const container = document.getElementById(containerId);
|
|
533
485
|
if (!container) {
|
|
534
486
|
throw new Error(`Container element with id ${containerId} not found`);
|
|
535
487
|
}
|
|
536
|
-
Communicator.createInstance();
|
|
488
|
+
Communicator.createInstance(apiReadyCallback);
|
|
537
489
|
const style = document.createElement('style');
|
|
538
|
-
style.innerHTML = `
|
|
539
|
-
#${containerId} {
|
|
540
|
-
width: 100%;
|
|
541
|
-
height: 100%;
|
|
542
|
-
overflow: hidden;
|
|
543
|
-
position: relative;
|
|
544
|
-
}
|
|
490
|
+
style.innerHTML = `
|
|
491
|
+
#${containerId} {
|
|
492
|
+
width: 100%;
|
|
493
|
+
height: 100%;
|
|
494
|
+
overflow: hidden;
|
|
495
|
+
position: relative;
|
|
496
|
+
}
|
|
545
497
|
`;
|
|
546
498
|
document.head.appendChild(style);
|
|
547
499
|
const iframe = document.createElement('iframe');
|
|
@@ -620,67 +572,5 @@ function getUrlParams() {
|
|
|
620
572
|
return selections;
|
|
621
573
|
}
|
|
622
574
|
|
|
623
|
-
|
|
624
|
-
bridge: 'bridge',
|
|
625
|
-
appLoaded: 'appLoaded',
|
|
626
|
-
/**
|
|
627
|
-
* @hidden
|
|
628
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "unrealFeature"
|
|
629
|
-
*/
|
|
630
|
-
unrealFeatureBridge: 'unrealFeatureBridge',
|
|
631
|
-
/**
|
|
632
|
-
* @hidden
|
|
633
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "unrealCallback"
|
|
634
|
-
*/
|
|
635
|
-
unrealCallback: 'unrealCallback',
|
|
636
|
-
/**
|
|
637
|
-
* @hidden
|
|
638
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
639
|
-
*/
|
|
640
|
-
configuratorDataWithStateBridge: 'configuratorDataWithStateBridge',
|
|
641
|
-
/**
|
|
642
|
-
* @hidden
|
|
643
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
644
|
-
*/
|
|
645
|
-
configuratorDataBridge: 'configuratorDataBridge',
|
|
646
|
-
/**
|
|
647
|
-
* @hidden
|
|
648
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
649
|
-
*/
|
|
650
|
-
menuDataBridge: 'menuDataBridge',
|
|
651
|
-
/**
|
|
652
|
-
* @hidden
|
|
653
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
654
|
-
*/
|
|
655
|
-
flatMenuDataBridge: 'flatMenuDataBridge',
|
|
656
|
-
/**
|
|
657
|
-
* @hidden
|
|
658
|
-
* @deprecated, use Bridge with isFullscreen
|
|
659
|
-
*/
|
|
660
|
-
fullScreenBridge: 'fullScreenBridge',
|
|
661
|
-
/**
|
|
662
|
-
* @hidden
|
|
663
|
-
* @deprecated, use Bridge with streamResolution
|
|
664
|
-
*/
|
|
665
|
-
videoSize: 'videoSize',
|
|
666
|
-
/**
|
|
667
|
-
* @hidden
|
|
668
|
-
* Used in a platform, must be removed in future
|
|
669
|
-
* @deprecated
|
|
670
|
-
*/
|
|
671
|
-
unrealResponse: 'unrealResponse',
|
|
672
|
-
/**
|
|
673
|
-
* @hidden
|
|
674
|
-
* @deprecated\
|
|
675
|
-
*/
|
|
676
|
-
getFastRender: 'getFastRender',
|
|
677
|
-
};
|
|
678
|
-
|
|
679
|
-
const APPLICATION_DEVICE_TYPES = {
|
|
680
|
-
deviceTypeAuto: 'deviceTypeAuto',
|
|
681
|
-
deviceTypeMobile: 'deviceTypeMobile',
|
|
682
|
-
deviceTypeDesktop: 'deviceTypeDesktop',
|
|
683
|
-
};
|
|
684
|
-
|
|
685
|
-
export { APPLICATION_DEVICE_TYPES, ApiAction, Communicator, FromMetaboxApiAction, GetFastRender, GetPdf, SendCommandToUnreal, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, ToMetaBoxApiAction, WatchCallbacks, getUrlParams, integrateMetaBox, saveImage, setUrlParams, sleep };
|
|
575
|
+
export { CommandBase, Communicator, GetFastRender, GetPdf, SendCommandToUnreal, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, WatchCallbacks, getUrlParams, integrateMetaBox, saveImage, setUrlParams, sleep };
|
|
686
576
|
//# sourceMappingURL=index.esm.js.map
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|