@roomle/embedding-lib 4.44.0 → 5.1.0-alpha.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.
Files changed (234) hide show
  1. package/.releaserc.json +4 -7
  2. package/README.md +5 -6
  3. package/docs/md/web/embedding/CHANGELOG.md +28 -0
  4. package/drag-in-CXLxdfa-.mjs +265 -0
  5. package/drag-in-gOPgOymI.mjs +7 -0
  6. package/index.d.ts +114 -0
  7. package/package.json +27 -13
  8. package/roomle-embedding-lib.es.js +472 -0
  9. package/roomle-embedding-lib.es.min.js +8 -0
  10. package/roomle-embedding-lib.umd.js +14 -0
  11. package/roomle-embedding-lib.umd.min.js +14 -0
  12. package/docs/__sidebar__.json +0 -14
  13. package/docs/api/.nojekyll +0 -1
  14. package/docs/api/README.md +0 -9
  15. package/docs/api/classes/exposed_analytics_callbacks.ExposedAnalyticsCallbacks.md +0 -47
  16. package/docs/api/classes/exposed_api.ExposedApi.md +0 -255
  17. package/docs/api/classes/exposed_callbacks.ExposedCallbacks.md +0 -195
  18. package/docs/api/classes/roomle_configurator_api.default.md +0 -211
  19. package/docs/api/enums/types.UI_BUTTON.md +0 -263
  20. package/docs/api/interfaces/exposed_callbacks.Labels.md +0 -32
  21. package/docs/api/interfaces/exposed_callbacks.Price.md +0 -32
  22. package/docs/api/interfaces/roomle_configurator_api.RoomleEmbeddingApiKeys.md +0 -58
  23. package/docs/api/interfaces/types.ConfiguratorSettings.md +0 -150
  24. package/docs/api/interfaces/types.EmbeddingSkin.md +0 -65
  25. package/docs/api/interfaces/types.UiInitData.md +0 -1199
  26. package/docs/api/interfaces/types.VariantsMap.md +0 -9
  27. package/docs/api/modules/exposed_analytics_callbacks.md +0 -9
  28. package/docs/api/modules/exposed_api.md +0 -9
  29. package/docs/api/modules/exposed_callbacks.md +0 -14
  30. package/docs/api/modules/roomle_configurator_api.md +0 -49
  31. package/docs/api/modules/types.md +0 -16
  32. package/docs/api/modules.md +0 -13
  33. package/docs/examples/00_init.html +0 -38
  34. package/docs/examples/01_small_screen.html +0 -37
  35. package/docs/examples/02_resize_callback.html +0 -46
  36. package/docs/examples/03_instant_start.html +0 -38
  37. package/docs/examples/04_price.html +0 -48
  38. package/docs/examples/05_analytics.html +0 -38
  39. package/docs/examples/06_skinning.html +0 -39
  40. package/docs/examples/07_request_product.html +0 -41
  41. package/docs/examples/08_variants.html +0 -36
  42. package/docs/examples/09_different_products.html +0 -63
  43. package/docs/examples/10_landing_page.html +0 -38
  44. package/docs/examples/11_light_settings.html +0 -126
  45. package/docs/examples/12_email.html +0 -36
  46. package/docs/examples/13_parameters.html +0 -67
  47. package/docs/examples/14_ga_consent.html +0 -39
  48. package/docs/examples/roomle-configurator-api.es.min.js +0 -586
  49. package/docs/hsp.md +0 -61
  50. package/docs/images/parts.png +0 -0
  51. package/docs/images/usm-frames.png +0 -0
  52. package/docs/integration.md +0 -1101
  53. package/docs/md/web/ui/EMBEDDING-CHANGELOG.md +0 -17
  54. package/docs/migration-guides/v2-to-v3.md +0 -135
  55. package/docs/moc/index.md +0 -86
  56. package/docs/simple.md +0 -25
  57. package/roomle-configurator-api.cjs.js +0 -585
  58. package/roomle-configurator-api.cjs.min.js +0 -1
  59. package/roomle-configurator-api.es.js +0 -583
  60. package/roomle-configurator-api.es.min.js +0 -1
  61. package/roomle-configurator-api.js +0 -583
  62. package/types/index.d.ts +0 -1504
  63. package/types/src/common/business-logic/connector.d.ts +0 -8
  64. package/types/src/common/business-logic/event-bus.d.ts +0 -5
  65. package/types/src/common/components/collection-view/-utils/types.d.ts +0 -10
  66. package/types/src/common/plugins/analytics.d.ts +0 -11
  67. package/types/src/common/plugins/localize.d.ts +0 -8
  68. package/types/src/common/store/collection-view-state.d.ts +0 -40
  69. package/types/src/common/store/common-ui-state.d.ts +0 -16
  70. package/types/src/common/store/index.d.ts +0 -111
  71. package/types/src/common/translations/local-translation-source.d.ts +0 -8
  72. package/types/src/common/utils/access-restriction.d.ts +0 -7
  73. package/types/src/common/utils/ar-service.d.ts +0 -14
  74. package/types/src/common/utils/bezier.d.ts +0 -2
  75. package/types/src/common/utils/browser.d.ts +0 -3
  76. package/types/src/common/utils/color.d.ts +0 -2
  77. package/types/src/common/utils/compatibility.d.ts +0 -3
  78. package/types/src/common/utils/dom.d.ts +0 -15
  79. package/types/src/common/utils/font-size-detector.d.ts +0 -1
  80. package/types/src/common/utils/google-analytics.d.ts +0 -67
  81. package/types/src/common/utils/helper.d.ts +0 -43
  82. package/types/src/common/utils/iframe.d.ts +0 -3
  83. package/types/src/common/utils/init-data.d.ts +0 -34
  84. package/types/src/common/utils/merge.d.ts +0 -16
  85. package/types/src/common/utils/parameters.d.ts +0 -18
  86. package/types/src/common/utils/performance.d.ts +0 -2
  87. package/types/src/common/utils/plan.d.ts +0 -1
  88. package/types/src/common/utils/script-loader.d.ts +0 -5
  89. package/types/src/common/utils/share.d.ts +0 -1
  90. package/types/src/common/utils/touch-drag.d.ts +0 -24
  91. package/types/src/common/utils/types.d.ts +0 -19
  92. package/types/src/common/utils/user-agent.d.ts +0 -6
  93. package/types/src/common/utils/variants.d.ts +0 -3
  94. package/types/src/configurator/ar/main.d.ts +0 -1
  95. package/types/src/configurator/business-logic/roomle-sdk-wrapper.d.ts +0 -27
  96. package/types/src/configurator/business-logic/sdk-connector-configurator.d.ts +0 -29
  97. package/types/src/configurator/business-logic/sdk-connector.d.ts +0 -119
  98. package/types/src/configurator/business-logic/ui-callback.d.ts +0 -5
  99. package/types/src/configurator/components/-utils/overlays.d.ts +0 -43
  100. package/types/src/configurator/components/grid-view/-utils/GridViewHelper.d.ts +0 -16
  101. package/types/src/configurator/components/utils/-utils/SceneOffsetResizer.d.ts +0 -23
  102. package/types/src/configurator/embedding/example/main.d.ts +0 -1
  103. package/types/src/configurator/embedding/exposed-analytics-callbacks.d.ts +0 -10
  104. package/types/src/configurator/embedding/exposed-api.d.ts +0 -90
  105. package/types/src/configurator/embedding/exposed-callbacks.d.ts +0 -46
  106. package/types/src/configurator/embedding/helper.d.ts +0 -8
  107. package/types/src/configurator/embedding/message-handler.d.ts +0 -31
  108. package/types/src/configurator/embedding/roomle-configurator-api.d.ts +0 -64
  109. package/types/src/configurator/embedding/types.d.ts +0 -159
  110. package/types/src/configurator/embedding/utils.d.ts +0 -15
  111. package/types/src/configurator/plugins/embedding-callbacks-plugin.d.ts +0 -4
  112. package/types/src/configurator/plugins/libs-plugin.d.ts +0 -11
  113. package/types/src/configurator/plugins/sdk-connector-plugin.d.ts +0 -14
  114. package/types/src/configurator/store/core-data.d.ts +0 -34
  115. package/types/src/configurator/store/core-state.d.ts +0 -26
  116. package/types/src/configurator/store/ui-state.d.ts +0 -118
  117. package/types/src/main.d.ts +0 -14
  118. package/types/src/planner/business-logic/general-room-parameters.d.ts +0 -17
  119. package/types/src/planner/business-logic/pre-defined-rooms.d.ts +0 -2
  120. package/types/src/planner/business-logic/rooms.d.ts +0 -37
  121. package/types/src/planner/business-logic/sdk-connector-planner.d.ts +0 -28
  122. package/types/src/planner/store/planner-core-data.d.ts +0 -21
  123. package/types/src/planner/store/planner-ui-state.d.ts +0 -65
  124. package/types/src/planner/utils/interaction.d.ts +0 -3
  125. package/types/src/planner/utils/planner-sidebar.d.ts +0 -19
  126. package/types/src/viewer/business-logic/sdk-connector-viewer.d.ts +0 -18
  127. package/types/tests/helpers/data/base-64-images.d.ts +0 -1
  128. package/types/tests/helpers/data/configurator.d.ts +0 -7
  129. package/types/tests/helpers/data/items.d.ts +0 -208
  130. package/types/tests/helpers/data/materials.d.ts +0 -32
  131. package/types/tests/helpers/data/parameter-groups.d.ts +0 -242
  132. package/types/tests/helpers/data/parameters.d.ts +0 -399
  133. package/types/tests/helpers/data/part-list.d.ts +0 -126
  134. package/types/tests/helpers/data/plan.d.ts +0 -224
  135. package/types/tests/helpers/data/planObject.d.ts +0 -134
  136. package/types/tests/helpers/data/possible-children-tags.d.ts +0 -208
  137. package/types/tests/helpers/data/variants.d.ts +0 -60
  138. package/types/tests/helpers/data/wall-dimensions.d.ts +0 -41
  139. package/types/tests/helpers/dom.d.ts +0 -1
  140. package/types/tests/helpers/mocks/analytics.d.ts +0 -7
  141. package/types/tests/helpers/mocks/data/biohort-parameter.d.ts +0 -32
  142. package/types/tests/helpers/mocks/data/koinor-formia.d.ts +0 -289
  143. package/types/tests/helpers/mocks/embedding-callbacks.d.ts +0 -4
  144. package/types/tests/helpers/mocks/icon.d.ts +0 -3
  145. package/types/tests/helpers/mocks/localize.d.ts +0 -8
  146. package/types/tests/helpers/mocks/message.d.ts +0 -11
  147. package/types/tests/helpers/mocks/parameters.d.ts +0 -47
  148. package/types/tests/helpers/mocks/possible-children.d.ts +0 -596
  149. package/types/tests/helpers/mocks/roomle-sdk-wrapper.d.ts +0 -177
  150. package/types/tests/helpers/mocks/sdk-connector-configurator.d.ts +0 -13
  151. package/types/tests/helpers/mocks/sdk-connector-planner.d.ts +0 -13
  152. package/types/tests/helpers/mocks/sdk-connector.d.ts +0 -35
  153. package/types/tests/helpers/mocks/store.d.ts +0 -11
  154. package/types/tests/helpers/mocks/tag.d.ts +0 -148
  155. package/types/tests/helpers/utils.d.ts +0 -13
  156. package/types/tests/integration/common/components/ActionButtons.spec.d.ts +0 -1
  157. package/types/tests/integration/common/components/BottomBar.spec.d.ts +0 -1
  158. package/types/tests/integration/common/components/BottomButtons.spec.d.ts +0 -1
  159. package/types/tests/integration/common/components/IconButton.spec.d.ts +0 -1
  160. package/types/tests/integration/common/components/SelectionButtons.spec.d.ts +0 -1
  161. package/types/tests/integration/common/components/part-list/part-list/PartListPrint.spec.d.ts +0 -1
  162. package/types/tests/integration/common/components/part-list/part-list/PartListRow.spec.d.ts +0 -1
  163. package/types/tests/integration/configurator/App.spec.d.ts +0 -1
  164. package/types/tests/integration/configurator/components/ARButton.spec.d.ts +0 -1
  165. package/types/tests/integration/configurator/components/ConfiguratorMain.spec.d.ts +0 -9
  166. package/types/tests/integration/configurator/components/CookieBanner.spec.d.ts +0 -1
  167. package/types/tests/integration/configurator/components/Overlays.spec.d.ts +0 -1
  168. package/types/tests/integration/configurator/components/TopBar.spec.d.ts +0 -1
  169. package/types/tests/integration/configurator/components/ViewerMain.spec.d.ts +0 -1
  170. package/types/tests/integration/configurator/components/addons/AddonsTrigger.spec.d.ts +0 -1
  171. package/types/tests/integration/configurator/components/addons/PossibleChildren.spec.d.ts +0 -1
  172. package/types/tests/integration/configurator/components/collection-view/-utils/TabbedNav.spec.d.ts +0 -1
  173. package/types/tests/integration/configurator/components/collection-view/CollectionView.spec.d.ts +0 -1
  174. package/types/tests/integration/configurator/components/grid-view/-utils/CollapsedView.spec.d.ts +0 -1
  175. package/types/tests/integration/configurator/components/grid-view/-utils/ExpandedView.spec.d.ts +0 -1
  176. package/types/tests/integration/configurator/components/grid-view/-utils/GridViewElement.spec.d.ts +0 -1
  177. package/types/tests/integration/configurator/components/grid-view/-utils/GridViewHelper.spec.d.ts +0 -1
  178. package/types/tests/integration/configurator/components/grid-view/GridView.spec.d.ts +0 -1
  179. package/types/tests/integration/configurator/components/overlays/Export3D.spec.d.ts +0 -1
  180. package/types/tests/integration/configurator/components/overlays/NoDocking.spec.d.ts +0 -1
  181. package/types/tests/integration/configurator/components/overlays/PartList.spec.d.ts +0 -1
  182. package/types/tests/integration/configurator/components/overlays/SaveDraft.spec.d.ts +0 -1
  183. package/types/tests/integration/configurator/components/overlays/VariantWarning.spec.d.ts +0 -1
  184. package/types/tests/integration/configurator/components/overlays/ar/OpenARView.spec.d.ts +0 -1
  185. package/types/tests/integration/configurator/components/parameters/BackParameterGroupButton.spec.d.ts +0 -1
  186. package/types/tests/integration/configurator/components/parameters/NextParameterGroupButton.spec.d.ts +0 -1
  187. package/types/tests/integration/configurator/components/parameters/ParameterGroupButton.spec.d.ts +0 -1
  188. package/types/tests/integration/configurator/components/parameters/ParameterGroups.spec.d.ts +0 -1
  189. package/types/tests/integration/configurator/components/parameters/types/MaterialParameter.spec.d.ts +0 -1
  190. package/types/tests/integration/configurator/components/parameters/types/OptionsParameter.spec.d.ts +0 -1
  191. package/types/tests/integration/configurator/components/parameters/types/OptionsParameterValue.spec.d.ts +0 -1
  192. package/types/tests/integration/configurator/components/parameters/types/ProductVariant.spec.d.ts +0 -1
  193. package/types/tests/integration/configurator/components/parameters/types/RangeParameter.spec.d.ts +0 -1
  194. package/types/tests/integration/configurator/components/parameters/types/ThumbnailsParameter.spec.d.ts +0 -1
  195. package/types/tests/integration/configurator/components/utils/BackToWebsite.spec.d.ts +0 -1
  196. package/types/tests/integration/configurator/components/utils/CheckBox.spec.d.ts +0 -1
  197. package/types/tests/integration/configurator/components/utils/FullscreenContainer.spec.d.ts +0 -1
  198. package/types/tests/integration/configurator/components/utils/GdprEmailInput.spec.d.ts +0 -1
  199. package/types/tests/integration/configurator/components/utils/HeightToggle.spec.d.ts +0 -1
  200. package/types/tests/integration/configurator/components/utils/ImageWithFallback.spec.d.ts +0 -1
  201. package/types/tests/integration/configurator/components/utils/InteractionContainer.spec.d.ts +0 -1
  202. package/types/tests/integration/configurator/components/utils/PopUp.spec.d.ts +0 -1
  203. package/types/tests/integration/configurator/components/utils/ScrollHint.spec.d.ts +0 -1
  204. package/types/tests/integration/helper.spec.d.ts +0 -1
  205. package/types/tests/integration/planner/components/CatalogTrigger.spec.d.ts +0 -1
  206. package/types/tests/integration/planner/components/PlannerMain.spec.d.ts +0 -1
  207. package/types/tests/integration/planner/components/PlannerSidebar.spec.d.ts +0 -1
  208. package/types/tests/integration/planner/components/ProductListButton.spec.d.ts +0 -1
  209. package/types/tests/integration/planner/components/SampleRooms.spec.d.ts +0 -1
  210. package/types/tests/integration/planner/components/ShowWallMeasurements.spec.d.ts +0 -1
  211. package/types/tests/integration/planner/components/overlays/product-list/ProductListEntry.spec.d.ts +0 -1
  212. package/types/tests/integration/planner/components/overlays/rooms/RoomGeneralSettings.spec.d.ts +0 -1
  213. package/types/tests/integration/planner/components/overlays/rooms/RoomRangeParameter.spec.d.ts +0 -1
  214. package/types/tests/integration/planner/components/utils/InteractionHeader.spec.d.ts +0 -1
  215. package/types/tests/integration/planner/components/utils/sidebar-nav/SidebarNav.spec.d.ts +0 -1
  216. package/types/tests/unit/common/business-logic/event-bus.spec.d.ts +0 -1
  217. package/types/tests/unit/common/helper.spec.d.ts +0 -1
  218. package/types/tests/unit/common/translations/local-translation-source.spec.d.ts +0 -1
  219. package/types/tests/unit/common/utils/ar-service.spec.d.ts +0 -1
  220. package/types/tests/unit/common/utils/bezier.spec.d.ts +0 -1
  221. package/types/tests/unit/common/utils/color.spec.d.ts +0 -1
  222. package/types/tests/unit/common/utils/dom.spec.d.ts +0 -1
  223. package/types/tests/unit/common/utils/helper.spec.d.ts +0 -1
  224. package/types/tests/unit/common/utils/init-data.spec.d.ts +0 -1
  225. package/types/tests/unit/common/utils/parameters.spec.d.ts +0 -1
  226. package/types/tests/unit/common/utils/touch-drag.spec.d.ts +0 -1
  227. package/types/tests/unit/configurator/business-logic/sdk-connector-configurator.spec.d.ts +0 -1
  228. package/types/tests/unit/configurator/business-logic/sdk-connector.spec.d.ts +0 -1
  229. package/types/tests/unit/configurator/components/utils/-utils/ConfiguratorResizer.spec.d.ts +0 -1
  230. package/types/tests/unit/configurator/components/utils/WordWrap.spec.d.ts +0 -1
  231. package/types/tests/unit/configurator/embedding/exposed-api.spec.d.ts +0 -1
  232. package/types/tests/unit/configurator/embedding/utils.spec.d.ts +0 -1
  233. package/types/tests/unit/configurator/store/index.spec.d.ts +0 -1
  234. package/types/tests/unit/planner/business-logic/sdk-connector-planner.spec.d.ts +0 -1
@@ -1,586 +0,0 @@
1
- console.error('DO NOT USE THIS FILE FOR PRODUCTION CODE!');
2
- console.error('THIS FILE IS ONLY HERE TO SHOWCASE THE EXAMPLES!');
3
- console.error('ALWAYS USE THE LATES VERSION OF THIS LIB!');
4
- class MessageHandler {
5
- constructor(side, incomingMessageBus, outgoingMessageBus, messageExecution) {
6
- this._outgoingMessageBus = null;
7
- this._execMessage = null;
8
- this._side = side;
9
- this._incomingMessageBus = incomingMessageBus;
10
- this._outgoingMessageBus = outgoingMessageBus;
11
- this._execMessage = messageExecution;
12
- this._incomingMessageBus.addEventListener('message', this._handleMessage.bind(this));
13
- }
14
- setOutgoingMessageBus(outgoingMessageBus) {
15
- this._outgoingMessageBus = outgoingMessageBus;
16
- }
17
- setMessageExecution(fun) {
18
- this._execMessage = fun;
19
- }
20
- sendMessage(message, args = []) {
21
- return new Promise((resolve, reject) => {
22
- const messageChannel = new MessageChannel();
23
- messageChannel.port1.onmessage = (event) => {
24
- if (!event || !event.data) {
25
- messageChannel.port1.close();
26
- messageChannel.port2.close();
27
- return reject(new Error(this._side + ' received message but response can not be interpreted'));
28
- }
29
- let response;
30
- try {
31
- response = JSON.parse(event.data);
32
- }
33
- catch (e) {
34
- messageChannel.port1.close();
35
- messageChannel.port2.close();
36
- this._prepareError(e);
37
- return reject(e);
38
- }
39
- if (response.error) {
40
- reject(response.error);
41
- }
42
- else if (response.result !== undefined) {
43
- resolve(response.result);
44
- }
45
- else {
46
- resolve();
47
- }
48
- messageChannel.port1.close();
49
- messageChannel.port2.close();
50
- };
51
- let command = '';
52
- try {
53
- command = JSON.stringify({ message, args });
54
- }
55
- catch (e) {
56
- return reject(new Error(this._side + ': can not create command because it is not JSON.stringify able'));
57
- }
58
- if (!this._outgoingMessageBus) {
59
- return reject(new Error(this._side + ': outgoing bus not set yet'));
60
- }
61
- this._outgoingMessageBus.postMessage(command, '*', [messageChannel.port2]);
62
- });
63
- }
64
- _handleMessage(event) {
65
- // check if MessageEvent has a port set --> hope this clears confusion about https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API/Using_channel_messaging
66
- const receiver = (event.ports && Array.isArray(event.ports) && event.ports.length > 0) ? event.ports[0] : null;
67
- if (event.data && receiver) {
68
- try {
69
- const command = JSON.parse(event.data);
70
- if (!this._execMessage) {
71
- return receiver.postMessage(JSON.stringify({ error: this._side + ' is not ready to handle messages' }));
72
- }
73
- if (!Array.isArray(command.args)) {
74
- command.args = [command.args];
75
- }
76
- const execResult = this._execMessage(command, event);
77
- if (execResult === undefined) {
78
- return; // do nothing because execMessage did not know what to do. Probably a message from another iframe was intercepted
79
- }
80
- execResult.then((data = {}) => {
81
- // tslint:disable-next-line:no-unnecessary-initializer
82
- let error = undefined;
83
- // tslint:disable-next-line:no-unnecessary-initializer
84
- let result = undefined;
85
- if (typeof data === 'object' && data !== null) {
86
- error = data.error;
87
- result = data.result;
88
- }
89
- if (error) {
90
- receiver.postMessage(JSON.stringify({ error }));
91
- }
92
- else if (result !== undefined) {
93
- receiver.postMessage(JSON.stringify({ result }));
94
- }
95
- else {
96
- receiver.postMessage(JSON.stringify({ result: data }));
97
- }
98
- }, (error) => {
99
- receiver.postMessage(JSON.stringify({ error: this._prepareError(error) }));
100
- });
101
- }
102
- catch (error) {
103
- receiver.postMessage(JSON.stringify({ error: this._prepareError(error) }));
104
- }
105
- }
106
- }
107
- _prepareError(e) {
108
- if (typeof e === 'string') {
109
- const error = this._side + ': ' + e;
110
- console.error(error);
111
- return error;
112
- }
113
- e.message = this._side + ': ' + e.message;
114
- console.error(e);
115
- return e.message;
116
- }
117
- }
118
-
119
- const NAMESPACE_SEPARATOR = '.';
120
- const HANDSHAKE_MESSAGES = {
121
- REQUEST_BOOT: 'requestBoot',
122
- SETUP: 'setup',
123
- WEBSITE_READY: 'websiteReady',
124
- };
125
- const getConfiguratorSettings = async (configuratorId, initData) => {
126
- if (typeof configuratorId !== 'string') {
127
- throw new Error('Configurator ID is not a string type: "' + (typeof configuratorId) + '"');
128
- }
129
- const server = initData.customApiUrl ? initData.customApiUrl : 'https://api.roomle.com/v2';
130
- const currentTenant = initData.overrideTenant || 9;
131
- const url = server + '/configurators/' + configuratorId;
132
- const apiKey = 'roomle_portal_v2';
133
- const token = '03-' + window.btoa((new Date()).toISOString() + ';anonymous;' + apiKey);
134
- const createHeaders = () => {
135
- const headers = {
136
- apiKey,
137
- currentTenant,
138
- locale: 'en',
139
- language: 'en',
140
- device: 1,
141
- token,
142
- platform: 'web',
143
- };
144
- return new Headers(headers);
145
- };
146
- const request = new Request(url, {
147
- method: 'GET',
148
- headers: createHeaders(),
149
- mode: 'cors',
150
- cache: 'default',
151
- });
152
- const response = await fetch(request);
153
- const { configurator } = await response.json();
154
- return configurator;
155
- };
156
-
157
- const isInIframe = () => {
158
- try {
159
- return window.self !== window.top;
160
- }
161
- catch (e) {
162
- return true;
163
- }
164
- };
165
-
166
- const NAMES_FOR_LOCALHOST = [
167
- '127.0.0.1',
168
- 'localhost',
169
- '0.0.0.0',
170
- ];
171
- const getHostname = () => {
172
- const isIframe = isInIframe();
173
- let url = window.location.href;
174
- if (isIframe) {
175
- if (!document.referrer) {
176
- return null;
177
- }
178
- url = document.referrer;
179
- }
180
- const { hostname } = new URL(url);
181
- return hostname;
182
- };
183
- const isDemoHostname = (hostname) => {
184
- if (NAMES_FOR_LOCALHOST.includes(hostname)) {
185
- return true;
186
- }
187
- if (hostname.endsWith('roomle.com')) {
188
- return true;
189
- }
190
- // exception for CI builds
191
- if (hostname.endsWith('gitlab.io') || hostname.endsWith('gitlab.com')) {
192
- return true;
193
- }
194
- return false;
195
- };
196
-
197
- /**
198
- * Recursively merge properties of two objects.
199
- * If a property exists in both it, property of obj2 is used.
200
- * Returns a new object (copy)
201
- * @param obj1
202
- * @param obj2
203
- */
204
- const deepMergeCopy = (obj1, obj2) => {
205
- const result = JSON.parse(JSON.stringify(obj1));
206
- return deepMerge(result, obj2);
207
- };
208
- /**
209
- * Recursively merge properties of two objects.
210
- * If a property exists in both it, property of obj2 is used.
211
- * Warning: This returns obj1 and not a copy!
212
- * @param obj1
213
- * @param obj2
214
- */
215
- const deepMerge = (obj1, obj2) => {
216
- // tslint:disable-next-line
217
- for (const p in obj2) {
218
- try {
219
- // Property in destination object set; update its value.
220
- if (obj2[p].constructor === Object) {
221
- obj1[p] = deepMerge(obj1[p], obj2[p]);
222
- }
223
- else {
224
- obj1[p] = obj2[p];
225
- }
226
- }
227
- catch (e) {
228
- // Property in destination object not set; create it and set its value.
229
- obj1[p] = obj2[p];
230
- }
231
- }
232
- return obj1;
233
- };
234
-
235
- const BROWSER_LANGUAGE_PROPERTY_KEYS_KNOWN = ['language', 'browserLanguage', 'userLanguage', 'systemLanguage'];
236
- const getLanguage = (lang = null) => {
237
- const navigator = window.navigator;
238
- if (lang) {
239
- return lang.substr(0, 2);
240
- }
241
- if (Array.isArray(navigator.languages) && navigator.languages.length > 0) {
242
- return navigator.languages[0].substr(0, 2);
243
- }
244
- for (let i = 0, length = BROWSER_LANGUAGE_PROPERTY_KEYS_KNOWN.length; i < length; i++) {
245
- const language = navigator[BROWSER_LANGUAGE_PROPERTY_KEYS_KNOWN[i]];
246
- if (language) {
247
- return language.substr(0, 2);
248
- }
249
- }
250
- return 'en';
251
- };
252
-
253
- const CONFIGURATOR_IDLE = '(idle)';
254
- const castAndFixInitData = (initData) => {
255
- castInitData(initData);
256
- if (initData === null || initData === void 0 ? void 0 : initData.customApiUrl) {
257
- initData.customApiUrl = decodeURIComponent(initData.customApiUrl);
258
- }
259
- if (initData.shareUrl) {
260
- initData.deeplink = initData.shareUrl.replace(LEGACY_SHARE_PLACEHOLDER, SHARE_PLACEHOLDER);
261
- }
262
- return initData;
263
- };
264
- const castInitData = (obj) => {
265
- if (!obj) {
266
- return;
267
- }
268
- const keys = Object.keys(obj);
269
- for (const key of keys) {
270
- const value = obj[key];
271
- // need to type-check for null because typeof null evaluates to object
272
- // see here why this is like it is: https://2ality.com/2013/10/typeof-null.html
273
- if (!Array.isArray(value) && typeof value === 'object' && value !== null) {
274
- return castInitData(value);
275
- }
276
- if (Array.isArray(value)) {
277
- for (const entry of value) {
278
- castInitData(entry);
279
- }
280
- return;
281
- }
282
- if (value === 'true' || value === 'false') {
283
- obj[key] = value === 'true';
284
- }
285
- }
286
- };
287
- const mergeInitData = (configuratorSettings, currentInitData) => {
288
- currentInitData.configuratorId = configuratorSettings.id;
289
- const remoteInitData = configuratorSettings.settings || {};
290
- // This is a performance optimization so we do not need to fetch
291
- // configurator settings twice
292
- if (!currentInitData.overrideTenant && configuratorSettings.tenant) {
293
- // use as any because we send tenant id as string but SDK requires to send a number
294
- // casting to number could become a problem when we change tenant IDs to something
295
- // random instead of a integer which is incremented
296
- currentInitData.overrideTenant = configuratorSettings.tenant;
297
- }
298
- return deepMergeCopy(remoteInitData, currentInitData);
299
- };
300
- const getFallbackInitData = () => {
301
- const fallbackInitData = {};
302
- if (!fallbackInitData.locale) {
303
- fallbackInitData.locale = getLanguage();
304
- }
305
- if (fallbackInitData.id === CONFIGURATOR_IDLE) {
306
- delete fallbackInitData.id;
307
- }
308
- const hostname = getHostname();
309
- if (hostname && isDemoHostname(hostname)) {
310
- fallbackInitData.configuratorId = 'demoConfigurator';
311
- }
312
- fallbackInitData.customApiUrl = 'https://www.roomle.com/api/v2';
313
- fallbackInitData.emails = false;
314
- return fallbackInitData;
315
- };
316
- const LEGACY_SHARE_PLACEHOLDER = '<CONF_ID>';
317
- const SHARE_PLACEHOLDER = '#CONFIGURATIONID#';
318
-
319
- // see why: so#/58065241/10800831
320
- const isAndroid = () => /(android)/i.test(navigator.userAgent);
321
-
322
- const setDefaultBehaviour = (object, callbackName, defaultBehaviour) => {
323
- let customBehaviour = null;
324
- Object.defineProperty(object, callbackName, {
325
- get() {
326
- return customBehaviour || defaultBehaviour;
327
- },
328
- set(data) {
329
- if (!(data === null || data === void 0 ? void 0 : data.mute)) {
330
- console.warn('You override Roomle defined behaviour. To disalbe this warning pass in an object with the following properties');
331
- console.warn('{ mute: true, value: () => void }');
332
- customBehaviour = data;
333
- }
334
- else {
335
- customBehaviour = data.value;
336
- }
337
- },
338
- });
339
- };
340
- const calcVh = () => (window.innerHeight * 0.01) + 'px'; // needed because of URL bar in android, inspired by: https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
341
- const setCustomProp = (element) => {
342
- if (!element) {
343
- return;
344
- }
345
- // Needed to wait for the next run loop otherwise data is wrong
346
- setTimeout(() => element.style.setProperty(RML_CUSTOM_PROPERTY_HEIGHT, calcVh()), 0);
347
- };
348
- const RML_STYLES_ID = 'rml-styles';
349
- const RML_ANIMATION_DELAY = 450;
350
- const RML_CUSTOM_PROPERTY_HEIGHT = '--rml-full-height';
351
- const RML_CSS_CLASSES = {
352
- CONTAINER: 'rml-container',
353
- FILL: 'rml-fill',
354
- POSITION: 'rml-pos',
355
- TRANSITION: 'rml-transition',
356
- ANDROID_HEIGHT: 'rml-android-height',
357
- OVERFLOW_HIDDEN: 'rml-overflow-hidden',
358
- };
359
- const globalSetupDone = new Map();
360
- class RoomleEmbeddingApi {
361
- constructor(settings, container, initData, waitForIframe) {
362
- this.ui = {
363
- callbacks: null,
364
- };
365
- this.extended = {
366
- callbacks: null,
367
- };
368
- this.analytics = {
369
- callbacks: {},
370
- };
371
- this.global = {
372
- callbacks: {},
373
- };
374
- this._initData = {};
375
- if (!settings || typeof settings.id !== 'string') {
376
- throw new Error('Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person');
377
- }
378
- if (globalSetupDone.has(container)) {
379
- throw new Error('There is already an instance on this DOM element');
380
- }
381
- const stylesAlreadyAdded = !!document.getElementById(RML_STYLES_ID);
382
- if (!stylesAlreadyAdded) {
383
- const zIndex = initData.zIndex || 9999999;
384
- const styles = document.createElement('style');
385
- styles.type = 'text/css';
386
- styles.id = RML_STYLES_ID;
387
- const cssTransition = 'transition:all ease-in-out ' + RML_ANIMATION_DELAY + 'ms;';
388
- const cssTransitionForAllBrowsers = ['-webkit-', '-o-'].reduce((acc, browser) => acc += browser + cssTransition, '') + cssTransition;
389
- const vh = calcVh();
390
- styles.innerHTML = `
391
- .${RML_CSS_CLASSES.CONTAINER}{${RML_CUSTOM_PROPERTY_HEIGHT}:${vh};}
392
- .${RML_CSS_CLASSES.POSITION}{position:fixed;top:0;left:0;z-index:${zIndex};opacity:0}
393
- .${RML_CSS_CLASSES.TRANSITION}{${cssTransitionForAllBrowsers}}
394
- .${RML_CSS_CLASSES.FILL}{width:100%;height:100%;opacity:1}
395
- .${RML_CSS_CLASSES.ANDROID_HEIGHT}{height:calc(var(${RML_CUSTOM_PROPERTY_HEIGHT},1vh)*100)}
396
- .${RML_CSS_CLASSES.OVERFLOW_HIDDEN}{overflow:hidden}
397
- `;
398
- document.head.appendChild(styles);
399
- }
400
- this._onResize = this._onResize.bind(this);
401
- if (isAndroid()) {
402
- window.addEventListener('resize', this._onResize);
403
- }
404
- this._container = container;
405
- this._initData = initData;
406
- this._configuratorSettings = settings;
407
- const iframe = this._createIframe();
408
- this._onUseFullPage = this._onUseFullPage.bind(this);
409
- this._executeMessage = this._executeMessage.bind(this);
410
- this._onBackToWebsite = this._onBackToWebsite.bind(this);
411
- this._messageHandler = new MessageHandler('website', window, null, this._executeMessage);
412
- this._waitForIframe = waitForIframe;
413
- this._container.appendChild(iframe);
414
- this._iframe = iframe;
415
- globalSetupDone.set(container, true);
416
- }
417
- static createPlanner(configuratorId, container, initData) {
418
- return this._create(configuratorId, container, initData);
419
- }
420
- /**
421
- * Method to create a new instance of a Roomle Configurator
422
- * @param configuratorId the id which identifies your configurator, you will get this ID from your Roomle Contact Person
423
- * @param container DOM container in which the configurator should be placed
424
- * @param initData settings with which the configurator should be started
425
- */
426
- static createConfigurator(configuratorId, container, initData) {
427
- return this._create(configuratorId, container, initData);
428
- }
429
- /**
430
- * Method to create a new instance of a Roomle Configurator
431
- * @deprecated please use "createConfigurator"
432
- * @param configuratorId the id which identifies your configurator, you will get this ID from your Roomle Contact Person
433
- * @param container DOM container in which the configurator should be placed
434
- * @param initData settings with which the configurator should be started
435
- */
436
- static create(configuratorId, container, initData) {
437
- return this._create(configuratorId, container, initData);
438
- }
439
- /**
440
- * Method to create a new instance of a Roomle Viewer
441
- * @param configuratorId the id which identifies your configurator, you will get this ID from your Roomle Contact Person
442
- * @param container DOM container in which the configurator should be placed
443
- * @param initData settings with which the configurator should be started
444
- */
445
- static createViewer(configuratorId, container, initData) {
446
- return this._create(configuratorId, container, initData);
447
- }
448
- static _create(configuratorId, container, initData) {
449
- return new Promise(async (resolve, reject) => {
450
- try {
451
- const fallbackInitData = deepMerge(getFallbackInitData(), castAndFixInitData(initData));
452
- if (!fallbackInitData.featureFlags) {
453
- fallbackInitData.featureFlags = {};
454
- }
455
- if (typeof fallbackInitData.featureFlags.realPartList !== 'boolean') {
456
- fallbackInitData.featureFlags.realPartList = true;
457
- }
458
- if (typeof fallbackInitData.featureFlags.globalCallbacks !== 'boolean') {
459
- fallbackInitData.featureFlags.globalCallbacks = true;
460
- }
461
- const configuratorSettings = await getConfiguratorSettings(configuratorId, fallbackInitData);
462
- initData = mergeInitData(configuratorSettings, fallbackInitData);
463
- return new this(configuratorSettings, container, initData, resolve);
464
- }
465
- catch (e) {
466
- return reject(e);
467
- }
468
- });
469
- }
470
- teardown() {
471
- if (this._container) {
472
- globalSetupDone.delete(this._container);
473
- }
474
- const iframe = this._container.querySelector('iframe');
475
- if (iframe) {
476
- this._container.removeChild(iframe);
477
- }
478
- window.removeEventListener('resize', this._onResize);
479
- }
480
- _createIframe() {
481
- var _a;
482
- const iframe = document.createElement('iframe');
483
- let url = ((_a = this._configuratorSettings) === null || _a === void 0 ? void 0 : _a.url) || 'https://www.roomle.com/t/cp/';
484
- if (this._initData.useLocalRoomle) {
485
- url = location.href.replace('embedding.html', '');
486
- }
487
- if (location.href.includes('roomle.gitlab.io')) {
488
- url = location.href.replace('embedding.html', 'index.html');
489
- }
490
- if (this._initData.overrideServerUrl) {
491
- url = this._initData.overrideServerUrl;
492
- }
493
- iframe.src = url;
494
- iframe.classList.add(RML_CSS_CLASSES.CONTAINER);
495
- iframe.classList.add(RML_CSS_CLASSES.FILL);
496
- return iframe;
497
- }
498
- _onResize() {
499
- setCustomProp(this._iframe);
500
- }
501
- _onUseFullPage() {
502
- this._iframe.classList.add(RML_CSS_CLASSES.POSITION);
503
- document.documentElement.classList.add(RML_CSS_CLASSES.OVERFLOW_HIDDEN);
504
- window.document.body.classList.add(RML_CSS_CLASSES.OVERFLOW_HIDDEN);
505
- if (isAndroid()) {
506
- setCustomProp(this._iframe);
507
- this._iframe.classList.add(RML_CSS_CLASSES.ANDROID_HEIGHT);
508
- }
509
- }
510
- _onBackToWebsite() {
511
- this._iframe.classList.remove(RML_CSS_CLASSES.POSITION);
512
- this._iframe.classList.remove(RML_CSS_CLASSES.ANDROID_HEIGHT);
513
- document.documentElement.classList.remove(RML_CSS_CLASSES.OVERFLOW_HIDDEN);
514
- window.document.body.classList.remove(RML_CSS_CLASSES.OVERFLOW_HIDDEN);
515
- }
516
- _executeMessage({ message, args }, event) {
517
- var _a;
518
- if (!event.source) {
519
- // @ts-ignore
520
- return; // no source? just wait ;-)
521
- }
522
- if (event.source !== ((_a = this._iframe) === null || _a === void 0 ? void 0 : _a.contentWindow)) {
523
- // @ts-ignore
524
- return; // need to wait since response is not for the current iframe;
525
- }
526
- if (message === HANDSHAKE_MESSAGES.REQUEST_BOOT) {
527
- this._messageHandler.setOutgoingMessageBus(event.source);
528
- return Promise.resolve({ result: this._initData });
529
- }
530
- if (message === HANDSHAKE_MESSAGES.SETUP) {
531
- const { methods, callbacks } = args[0];
532
- methods.forEach((method) => {
533
- const namespaces = method.split(NAMESPACE_SEPARATOR);
534
- const object = namespaces[0];
535
- const methodName = namespaces[1];
536
- if (!this[object]) {
537
- this[object] = {};
538
- }
539
- this[object][methodName] = function () {
540
- // @todo -- this was the fix that values are passed to caller, e.g.: interface.extended.getParametersOfRootComponent
541
- // most of the things we need for a meaningful test are not available in JEST (since it runs in node). We should
542
- // write a Cypress test for it
543
- return this._messageHandler.sendMessage(method, [...arguments]);
544
- }.bind(this);
545
- });
546
- callbacks.forEach((callback) => {
547
- const namespaces = callback.split(NAMESPACE_SEPARATOR);
548
- const object = namespaces[0];
549
- const callbacksName = namespaces[1];
550
- const eventName = namespaces[2];
551
- if (!this[object]) {
552
- this[object] = {};
553
- }
554
- if (!this[object][callbacksName]) {
555
- this[object][callbacksName] = {};
556
- }
557
- // @ts-ignore
558
- this[object][callbacksName][eventName] = () => undefined;
559
- });
560
- setDefaultBehaviour(this.ui.callbacks, 'onUseFullPage', this._onUseFullPage);
561
- setDefaultBehaviour(this.ui.callbacks, 'onBackToWebsite', this._onBackToWebsite);
562
- this._waitForIframe(this);
563
- setTimeout(() => this._messageHandler.sendMessage(HANDSHAKE_MESSAGES.WEBSITE_READY), 0); // Run it after the promise is resolved so everyone can subscribe
564
- return Promise.resolve({ result: null });
565
- }
566
- const messageNamespaces = message.split(NAMESPACE_SEPARATOR);
567
- const namespace = messageNamespaces[0];
568
- const objectOfAction = messageNamespaces[1];
569
- const methodOfAction = (messageNamespaces.length === 3) ? messageNamespaces[2] : null;
570
- if (methodOfAction) {
571
- if (this[namespace][objectOfAction][methodOfAction]) {
572
- const result = this[namespace][objectOfAction][methodOfAction](...args);
573
- if (result instanceof Promise) {
574
- return result.then((data) => ({ result: data }));
575
- }
576
- else if (result !== undefined) {
577
- return Promise.resolve({ result });
578
- }
579
- return Promise.resolve({ result: null });
580
- }
581
- }
582
- return Promise.reject('Message "' + message + '" is unkown');
583
- }
584
- }
585
-
586
- export { RoomleEmbeddingApi as default };
package/docs/hsp.md DELETED
@@ -1,61 +0,0 @@
1
- # Api for embedding the Roomle Planner
2
-
3
- This README outlines the details of including the Roomle Planner to your website.
4
-
5
- ## How to add the embedding API to your project
6
-
7
- You only need to add the code which sits in `dist/roomle-embedding-api.js` to your project. We recommend doing this
8
- by a package manager like [npm](https://www.npmjs.com/), [yarn](https://yarnpkg.com/lang/en/) or similar tools and a build pipe.
9
- Common tools to setup a build pipe for example are [gulp](https://gulpjs.com/), [webpack](https://webpack.js.org/),
10
- [grunt](https://gruntjs.com/) and many more. Every release gets a git tag so that you can specify an exact version in your
11
- package manager. Locking to a certain version helps you to deliver a stable product with the features you need.
12
-
13
- ## API description
14
-
15
- There is an auto generated API description which is available here: [doc/api.md](doc/api.md) But no one likes to read
16
- documentation so maybe it's enough to checkout the "help your self section".
17
-
18
- ### Give me some code to copy&paste
19
-
20
- This is only a snipped to get you started! Please adjust to your needs and don't use it in production! Also this code will
21
- only work in the newest browser. So use the ES version you need for your users. e.g. replace `async/await` with `Promise.then`.
22
- Never use the direct link to the Roomle JS library since it is always the latest one you have no chance to rely on a certain
23
- version.
24
-
25
- ```html
26
- <!DOCTYPE html>
27
- <html>
28
- <head>
29
- <meta charset="utf-8">
30
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
31
- <title>Roomle Planner</title>
32
- <meta name="description" content="">
33
- <meta name="viewport" content="width=device-width, initial-scale=1">
34
- <style>
35
- body {
36
- margin: 0;
37
- padding: 0;
38
- overflow: hidden;
39
- }
40
- #planner-container {
41
- width:100%;
42
- height:100vh;
43
- }
44
- </style>
45
- </head>
46
-
47
- <body>
48
- <div id="planner-container"></div>
49
- <script src="https://www.roomle.com/t/embedding/roomle-embedding-api.js"></script>
50
- <script>
51
- document.addEventListener('DOMContentLoaded', async function () {
52
- try {
53
- await RoomleEmbedding.initPlanner('8a701c314b4ae57f014b539159a01517');
54
- } catch(error) {
55
- console.error(error);
56
- }
57
- });
58
- </script>
59
- </body>
60
- </html>
61
- ```
Binary file
Binary file