josdejong/jsoneditor

Code mode (Ace editor) not working inside shadow DOM

Open

#742 ouverte le 16 juil. 2019

Voir sur GitHub
 (3 commentaires) (0 réactions) (0 assignés)JavaScript (2 034 forks)batch import
bughelp wanted

Métriques du dépôt

Stars
 (10 781 stars)
Métriques de merge PR
 (Merge moyen 15h 36m) (3 PRs mergées en 30 j)

Description

Hi, I want to make a JSON editor custom element. But I meet some problems. Here is my code:

<!DOCTYPE HTML>
<html>
<head>
    <!-- when using the mode "code", it's important to specify charset utf-8 -->
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <script src="jsoneditor/jsoneditor.min.js"></script>
</head>
<body>
    <json-editor></json-editor>
</body>
<template id='custom-template'>
        <link href="jsoneditor/jsoneditor.min.css" rel="stylesheet" type="text/css">
        <div id="jsoneditor" style="width: 500px; height: 500px;"></div>
</template>
<script>
        var template = document.getElementById('custom-template')
        class CustomJsonEditor extends HTMLElement {
        constructor() {
          super();
          this._shadowRoot = this.attachShadow({mode: 'open'})
          this._shadowRoot.appendChild(template.content.cloneNode(true))
          var options = {
            mode: 'code',
            modes: ["code", "tree"],
          };
    
          this.container = this._shadowRoot.querySelector('div');
          this.editor = new JSONEditor(this.container, options);
        }
      }
      customElements.define('json-editor', CustomJsonEditor);
    </script>
</html>

And the Json editor will become this: image It seems that I need to load the ace theme somewhere, right? I am a beginner on JavaScript. Could you give me some helps? Thank you.

Guide contributeur