0

我创建了一个托管 Wiris 的 Web 组件。然而,当组件被渲染时,Wiris 编辑器的格式(非常)很糟糕:

在此处输入图像描述

你可以在这里看到这个问题。

代码如下:

class WirisComponent extends HTMLElement {
 constructor() {
  // Always call super first in constructor
  super();

  // Create a shadow root
  var shadow = this.attachShadow( { mode: 'open' } );

  // Create a div to host the Wiris editor
  var div = document.createElement('div');
  div.id = 'editorContainer';

  var wirisDefaultConfig = {
    'language': 'en'
  };

  var editor = com.wiris.jsEditor.JsEditor.newInstance(wirisDefaultConfig);

  // Insert the Wiris instance into the div
  editor.insertInto(div);      

  // Append it to the shadow route
  shadow.appendChild(div);
 }
}

// Define the new element
customElements.define('wiris-component', WirisComponent);

HTML标记是:

<wiris-component></wiris-component>

请注意,我已经在 Chrome 中尝试过这个,它完全支持 Web 组件。

知道问题是什么吗?问题是否与此问题中发现的样式问题有关?

4

1 回答 1

0

不要使用 Shadow DOM:与您的库一起导入的样式不适用于它。

class WirisComponent extends HTMLElement {
  connectedCallback() {
    var wirisDefaultConfig = {
      'language': 'en'
    };

    var editor = com.wiris.jsEditor.JsEditor.newInstance(wirisDefaultConfig);
    editor.insertInto(this);
  }
}

// Define the new element
customElements.define('wiris-component', WirisComponent);
<script src="https://www.wiris.net/demo/editor/editor"></script>
<wiris-component></wiris-component>

于 2017-08-15T16:29:20.077 回答