| 317 | } |
| 318 | |
| 319 | class DataView extends ToolboxFeature<ToolboxDataViewFeatureOption> { |
| 320 | |
| 321 | private _dom: HTMLDivElement; |
| 322 | |
| 323 | onclick(ecModel: GlobalModel, api: ExtensionAPI) { |
| 324 | // FIXME: better way? |
| 325 | setTimeout(() => { |
| 326 | api.dispatchAction({ |
| 327 | type: 'hideTip' |
| 328 | }); |
| 329 | }); |
| 330 | |
| 331 | const container = api.getDom(); |
| 332 | const model = this.model; |
| 333 | if (this._dom) { |
| 334 | container.removeChild(this._dom); |
| 335 | } |
| 336 | const root = document.createElement('div'); |
| 337 | // use padding to avoid 5px whitespace |
| 338 | root.style.cssText = 'position:absolute;top:0;bottom:0;left:0;right:0;padding:5px'; |
| 339 | root.style.backgroundColor = model.get('backgroundColor') || tokens.color.neutral00; |
| 340 | |
| 341 | // Create elements |
| 342 | const header = document.createElement('h4'); |
| 343 | const lang = model.get('lang') || []; |
| 344 | header.innerHTML = lang[0] || model.get('title'); |
| 345 | header.style.cssText = 'margin:10px 20px'; |
| 346 | header.style.color = model.get('textColor'); |
| 347 | |
| 348 | const viewMain = document.createElement('div'); |
| 349 | const textarea = document.createElement('textarea'); |
| 350 | viewMain.style.cssText = 'overflow:auto'; |
| 351 | |
| 352 | const optionToContent = model.get('optionToContent'); |
| 353 | const contentToOption = model.get('contentToOption'); |
| 354 | const result = getContentFromModel(ecModel); |
| 355 | if (zrUtil.isFunction(optionToContent)) { |
| 356 | const htmlOrDom = optionToContent(api.getOption()); |
| 357 | if (zrUtil.isString(htmlOrDom)) { |
| 358 | viewMain.innerHTML = htmlOrDom; |
| 359 | } |
| 360 | else if (zrUtil.isDom(htmlOrDom)) { |
| 361 | viewMain.appendChild(htmlOrDom); |
| 362 | } |
| 363 | } |
| 364 | else { |
| 365 | // Use default textarea |
| 366 | textarea.readOnly = model.get('readOnly'); |
| 367 | const style = textarea.style; |
| 368 | // eslint-disable-next-line max-len |
| 369 | style.cssText = 'display:block;width:100%;height:100%;font-family:monospace;font-size:14px;line-height:1.6rem;resize:none;box-sizing:border-box;outline:none'; |
| 370 | style.color = model.get('textColor'); |
| 371 | style.borderColor = model.get('textareaBorderColor'); |
| 372 | style.backgroundColor = model.get('textareaColor'); |
| 373 | textarea.value = result.value; |
| 374 | viewMain.appendChild(textarea); |
| 375 | } |
| 376 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…