@hopara/iframe 0.3.50 → 0.3.52
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
CHANGED
|
@@ -115,9 +115,6 @@ hopara.update({accessToken: 'newAccessToken'})
|
|
|
115
115
|
// Overwrites data at rendering time
|
|
116
116
|
dataLoaders: DataLoader[] | undefined
|
|
117
117
|
|
|
118
|
-
// Provides a custom ways to update data
|
|
119
|
-
dataUpdaters: DataUpdaters[] | undefined
|
|
120
|
-
|
|
121
118
|
// The initial position to load the visualization
|
|
122
119
|
initialPosition: InitialPosition | undefined
|
|
123
120
|
|
|
@@ -190,43 +187,6 @@ Hopara.init({
|
|
|
190
187
|
})
|
|
191
188
|
```
|
|
192
189
|
|
|
193
|
-
### Data Updater
|
|
194
|
-
By default Hopara will update the visualization in the same database configured in [hopara.app](https://hopara.app). You can use the data updater prop to provide a custom way to update the data.
|
|
195
|
-
|
|
196
|
-
The data updater is called when placing objetcs in a visualization and when resizing images.
|
|
197
|
-
|
|
198
|
-
```typescript
|
|
199
|
-
type DataUpdater = {
|
|
200
|
-
// query name
|
|
201
|
-
name: string
|
|
202
|
-
|
|
203
|
-
// data source name
|
|
204
|
-
source: string
|
|
205
|
-
|
|
206
|
-
// callback to be used on data update
|
|
207
|
-
updater: (updatedRow: Record<string, any>, originalRow: Record<string, any>, diff: Partial<Record<string, any>>) => Promise<void>
|
|
208
|
-
}
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
```jsx
|
|
212
|
-
const customDataUpdaters = [{
|
|
213
|
-
name: 'queryName',
|
|
214
|
-
source: 'dataSourceName',
|
|
215
|
-
updater: (newRow) => {
|
|
216
|
-
const rowIndex = dataInMemory.findIndex((row) => row.id === newRow.id)
|
|
217
|
-
dataInMemory[rowIndex] = newRow
|
|
218
|
-
}
|
|
219
|
-
}]
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
Hopara.init({
|
|
223
|
-
visualizationId: 'my-hopara-viz',
|
|
224
|
-
accessToken: 'my-hopara-token',
|
|
225
|
-
targetElementId: 'my-target-element',
|
|
226
|
-
dataUpdaters: customDataUpdaters,
|
|
227
|
-
})
|
|
228
|
-
```
|
|
229
|
-
|
|
230
190
|
### Initial Position
|
|
231
191
|
The initial position prop overrides the initial position of the visualization.
|
|
232
192
|
|
package/build/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function webpackUniversalModuleDefinition(root,factory){if(typeof exports==="object"&&typeof module==="object")module.exports=factory();else if(typeof define==="function"&&define.amd)define([],factory);else{var a=factory();for(var i in a)(typeof exports==="object"?exports:root)[i]=a[i]}})(this,(function(){return function(){"use strict";var __webpack_require__={};!function(){__webpack_require__.d=function(exports,definition){for(var key in definition){if(__webpack_require__.o(definition,key)&&!__webpack_require__.o(exports,key)){Object.defineProperty(exports,key,{enumerable:true,get:definition[key]})}}}}();!function(){__webpack_require__.o=function(obj,prop){return Object.prototype.hasOwnProperty.call(obj,prop)}}();!function(){__webpack_require__.r=function(exports){if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(exports,"__esModule",{value:true})}}();var __webpack_exports__={};__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{Hopara:function(){return Hopara},default:function(){return client}});let EventType=function(EventType){EventType["INIT"]="init";EventType["READY"]="ready";EventType["UPDATE"]="update";EventType["LOAD_DATA"]="loadData";EventType["LOAD_DATA_RESPONSE"]="loadDataResponse";EventType["UPDATE_DATA"]="updateData";EventType["UPDATE_DATA_RESPONSE"]="updateDataResponse";EventType["REFRESH"]="refresh";EventType["FUNCTION_CALLBACK"]="functionCallback";return EventType}({});const HOPARA_EVENT_TYPE="__hopara__eventType__";const isReadyEvent=event=>event.data[HOPARA_EVENT_TYPE]===EventType.READY;const isLoadDataEvent=event=>event.data[HOPARA_EVENT_TYPE]===EventType.LOAD_DATA;const
|
|
1
|
+
(function webpackUniversalModuleDefinition(root,factory){if(typeof exports==="object"&&typeof module==="object")module.exports=factory();else if(typeof define==="function"&&define.amd)define([],factory);else{var a=factory();for(var i in a)(typeof exports==="object"?exports:root)[i]=a[i]}})(this,(function(){return function(){"use strict";var __webpack_require__={};!function(){__webpack_require__.d=function(exports,definition){for(var key in definition){if(__webpack_require__.o(definition,key)&&!__webpack_require__.o(exports,key)){Object.defineProperty(exports,key,{enumerable:true,get:definition[key]})}}}}();!function(){__webpack_require__.o=function(obj,prop){return Object.prototype.hasOwnProperty.call(obj,prop)}}();!function(){__webpack_require__.r=function(exports){if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(exports,"__esModule",{value:true})}}();var __webpack_exports__={};__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,{Hopara:function(){return Hopara},default:function(){return client}});let EventType=function(EventType){EventType["INIT"]="init";EventType["READY"]="ready";EventType["UPDATE"]="update";EventType["LOAD_DATA"]="loadData";EventType["LOAD_DATA_RESPONSE"]="loadDataResponse";EventType["UPDATE_DATA"]="updateData";EventType["UPDATE_DATA_RESPONSE"]="updateDataResponse";EventType["REFRESH"]="refresh";EventType["FUNCTION_CALLBACK"]="functionCallback";return EventType}({});const HOPARA_EVENT_TYPE="__hopara__eventType__";const isReadyEvent=event=>event.data[HOPARA_EVENT_TYPE]===EventType.READY;const isLoadDataEvent=event=>event.data[HOPARA_EVENT_TYPE]===EventType.LOAD_DATA;const isCallbackFunctionEvent=event=>event.data[HOPARA_EVENT_TYPE]===EventType.FUNCTION_CALLBACK;class EventEmitter{static sendMessage(data,targetWindow){const target=targetWindow||window.parent||window.top;if(!window||window===target)return;target.postMessage(data,"*")}static ready(){this.sendMessage({[HOPARA_EVENT_TYPE]:EventType.READY})}static init(config,targetWindow){this.sendMessage(Object.assign(config,{[HOPARA_EVENT_TYPE]:EventType.INIT}),targetWindow)}static loadDataRequest(dataLoader,filterSet){this.sendMessage({[HOPARA_EVENT_TYPE]:EventType.LOAD_DATA,data:{name:dataLoader.name,source:dataLoader.source},filterSet})}static loadDataResponse(config,dataLoader,rows,targetWindow){this.sendMessage(Object.assign(config,{[HOPARA_EVENT_TYPE]:EventType.LOAD_DATA_RESPONSE},{data:{name:dataLoader.name,source:dataLoader.source},rows}),targetWindow)}static refresh(config,targetWindow){this.sendMessage({...config,[HOPARA_EVENT_TYPE]:EventType.REFRESH},targetWindow)}static update(config,targetWindow){this.sendMessage({...config,[HOPARA_EVENT_TYPE]:EventType.UPDATE},targetWindow)}static callback(name,row){this.sendMessage({[HOPARA_EVENT_TYPE]:EventType.FUNCTION_CALLBACK,name,row})}}class EventReceiver{static isHoparaMessage(event){return event.data[HOPARA_EVENT_TYPE]!==undefined}static loadDataResponse(dataLoader){return new Promise((resolve=>{const callback=event=>{if(event.data[HOPARA_EVENT_TYPE]===EventType.LOAD_DATA_RESPONSE&&event.data.data.name===dataLoader.name&&event.data.data.source===dataLoader.source){window.removeEventListener("message",callback,false);resolve(event.data.rows)}};window.addEventListener("message",callback,false)}))}}var package_namespaceObject={i8:"0.3.52"};const embeddedEnvUrl={test:"https://statics.test.hopara.app/embedded",production:"https://statics.hopara.app/embedded"};class Hopara{constructor(config){this.config=void 0;this.iframe=void 0;this.cachedListenerFunction=void 0;this.doInit=()=>{const targetElement=this.config.targetElementId?document.getElementById(this.config.targetElementId):this.config.targetElement;if(!targetElement){console&&console.warn("Hopara: targetElement not found");return this}const iframe=this.createIframe();targetElement.appendChild(iframe);this.iframe=iframe;this.createListeners();return this};this.config=config}getIframeSrc(){var _embeddedEnvUrl,_this$config$env;const envUrl=(_embeddedEnvUrl=embeddedEnvUrl[(_this$config$env=this.config.env)!==null&&_this$config$env!==void 0?_this$config$env:"production"])!==null&&_embeddedEnvUrl!==void 0?_embeddedEnvUrl:embeddedEnvUrl.production;const url=this.config.embeddedUrl?this.config.embeddedUrl:`${envUrl}/${this.config.version?this.config.version:"latest"}`;return`${url}${this.config.debug?"?debug=true":""}`}getIframeStyle(){return"background-color: transparent; border: 0px none transparent; padding: 0px; overflow: hidden; width: 100%; height: 100%;"}createIframe(){const iframe=document.createElement("iframe");iframe.src=this.getIframeSrc();iframe.allow="geolocation";iframe.style=this.getIframeStyle();return iframe}getEventData(){var _ref,_this$config$visualiz,_this$config$dataLoad,_this$config$callback;return{accessToken:this.config.accessToken,visualizationId:(_ref=(_this$config$visualiz=this.config.visualizationId)!==null&&_this$config$visualiz!==void 0?_this$config$visualiz:this.config.visualization)!==null&&_ref!==void 0?_ref:this.config.app,fallbackVisualizationId:this.config.fallbackVisualizationId,env:this.config.env,tenant:this.config.tenant,initialPosition:this.config.initialPosition,initialRow:this.config.initialRow,dataLoaders:(_this$config$dataLoad=this.config.dataLoaders)===null||_this$config$dataLoad===void 0?void 0:_this$config$dataLoad.map((dataLoader=>({name:dataLoader.name,source:dataLoader.source}))),darkMode:this.config.darkMode,toolbar:this.config.toolbar,mapStyle:this.config.mapStyle,callbackNames:(_this$config$callback=this.config.callbacks)===null||_this$config$callback===void 0?void 0:_this$config$callback.map((callback=>callback.name)),filters:this.config.filters}}listenerFunction(event){var _this$iframe$contentW,_this$iframe;const targetWindow=(_this$iframe$contentW=(_this$iframe=this.iframe)===null||_this$iframe===void 0?void 0:_this$iframe.contentWindow)!==null&&_this$iframe$contentW!==void 0?_this$iframe$contentW:event.source;if(!targetWindow&&EventReceiver.isHoparaMessage(event)){throw new Error("Hopara: targetWindow is not available")}if(isReadyEvent(event)){return EventEmitter.init(this.getEventData(),targetWindow)}if(isLoadDataEvent(event)){var _this$config$dataLoad2;const dataLoader=(_this$config$dataLoad2=this.config.dataLoaders)===null||_this$config$dataLoad2===void 0?void 0:_this$config$dataLoad2.find((dataLoader=>dataLoader.name===event.data.data.name&&dataLoader.source===event.data.data.source));if(dataLoader)return dataLoader.loader(event.data.filterSet).then((data=>EventEmitter.loadDataResponse(this.getEventData(),dataLoader,data,targetWindow)))}if(isCallbackFunctionEvent(event)){var _this$config$callback2;const callbackFunc=(_this$config$callback2=this.config.callbacks)===null||_this$config$callback2===void 0?void 0:_this$config$callback2.find((callback=>callback.name===event.data.name));if(callbackFunc)callbackFunc===null||callbackFunc===void 0?void 0:callbackFunc.callback(event.data.row)}}createListeners(){this.cachedListenerFunction=this.listenerFunction.bind(this);window.addEventListener("message",this.cachedListenerFunction,true)}removeListeners(){window.removeEventListener("message",this.cachedListenerFunction,true)}refresh(){if(!this.iframe)throw new Error("Hopara: iframe is not available");if(this.iframe.contentWindow){EventEmitter.refresh(this.getEventData(),this.iframe.contentWindow)}}update(config){var _this$iframe2;this.config=Object.assign({},this.config,config);if((_this$iframe2=this.iframe)!==null&&_this$iframe2!==void 0&&_this$iframe2.contentWindow){EventEmitter.update(this.getEventData(),this.iframe.contentWindow)}}destroy(){if(!this.iframe)throw new Error("Hopara: iframe is not available");this.iframe.remove();this.iframe=undefined;this.removeListeners()}static init(config){if(!config&&console){console.warn("Hopara: init config not present");return}if((!window||!window.document)&&console){console.warn("Hopara: window is not available");return}const client=new Hopara(config);return client.doInit()}static moduleVersion(){return this._version}moduleVersion(){return Hopara._version}}Hopara._version=package_namespaceObject.i8;var client=Hopara;return __webpack_exports__}()}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hopara/iframe",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.52",
|
|
4
4
|
"main": "build/client.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "REACT_APP_IS_EMBEDDED=true ESLINT_NO_DEV_ERRORS=true react-app-rewired start",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@babel/register": "^7.15.3",
|
|
33
33
|
"@datadog/browser-rum": "^4.24.0",
|
|
34
|
-
"@hopara/components": "
|
|
35
|
-
"@hopara/config": "
|
|
36
|
-
"@hopara/design-system": "
|
|
37
|
-
"@hopara/system-test": "
|
|
34
|
+
"@hopara/components": "0.3.52",
|
|
35
|
+
"@hopara/config": "0.3.52",
|
|
36
|
+
"@hopara/design-system": "0.3.52",
|
|
37
|
+
"@hopara/system-test": "0.3.52",
|
|
38
38
|
"babel-loader": "8.1.0",
|
|
39
39
|
"customize-cra": "^1.0.0",
|
|
40
40
|
"react": "^18.2.0",
|
|
Binary file
|
|
Binary file
|