【问题标题】:Using the Wiris editor within a Web Component在 Web 组件中使用 Wiris 编辑器
【发布时间】:2017-08-15 14:48:51
【问题描述】:

我创建了一个托管 Wiris 的 Web 组件。但是,当呈现组件时,Wiris 编辑器的格式(非常)错误:

您可以实时查看问题here

代码如下:

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 组件。

知道问题是什么吗?问题是否与this issue 中的样式问题有关?

【问题讨论】:

    标签: javascript web-component wiris


    【解决方案1】:

    不要使用 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>

    【讨论】:

    • 不幸的是,我需要使用影子 DOM 来封装来自主机的 Web 组件的 DOM 和 CSS(Web 组件将不仅包含 Wiris)。奇怪的是,最新版本的 Chrome 完全支持 Web 组件,所以我希望 Wiris 和它的样式能够与 Web 组件“很好地配合”。
    • 那你应该试试这样的方法:stackoverflow.com/a/42758748/4600982 但我不认为它可以用 wiris 工作
    • 感谢@Supersharp。我认为你是对的,Wiris “运送”他们的编辑器的方式不是很灵活,即必须引用 URL 而不是能够导入模块和其他组成部分,例如样式。看看 Wiris 说什么会很有趣。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多