<commit_before><link rel="import" href="../../bower_components/polymer/polymer.html">

<link rel="import" href="../../bower_components/paper-input/paper-input.html">
<link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../../bower_components/paper-expansion-panel/paper-expansion-panel.html">

<link rel="import" href="../../bower_components/vaadin-grid/vaadin-grid.html">

<link rel="import" href="../standard-plugins/import.html">

<dom-module id="dtile-meta-editor">
    <template>
        <style>
            :host {
                display: block;
                min-width: 50vw;
            }

            vaadin-grid, vaadin-grid * {
                background: var(--primary-background-color);
                color: white;
                border: none !important;

                --vaadin-grid-cell: {
                    padding: 8px 16px;
                };
            }

            paper-expansion-panel[hidden] {
                display: none;
            }

            paper-expansion-panel > * {
                height: 50vh;
                display: block;
            }
        </style>

        <paper-expansion-panel header="Public properties" opened>
            <vaadin-grid id="public-meta-grid" items="[[_publicMeta]]">
                <vaadin-grid-column>
                    <template class="header">Key</template>
                    <template>
                        <paper-input value="{{item.key}}" no-label-float></paper-input>
                    </template>
                    <template class="footer">
                        <paper-input id="new-key" no-label-float label="Key"
                            on-keydown="_checkEntryEnter">
                        </paper-input>
                    </template>
                </vaadin-grid-column>

                <vaadin-grid-column>
                    <template class="header">Value</template>
                    <template>
                        <paper-input value="{{item.value}}" no-label-float></paper-input>
                    </template>
                    <template class="footer">
                        <paper-input id="new-value" no-label-float label="Value"
                            on-keydown="_checkEntryEnter">
                        </paper-input>
                    </template>
                </vaadin-grid-column>

                <vaadin-grid-column width="72px" flex-grow="0">
                    <template>
                        <paper-icon-button icon="clear" on-tap="_removeTapped"></paper-icon-button>
                    </template>
                    <template class="footer">
                        <paper-icon-button icon="add" on-tap="_addPublicEntry"></paper-icon-button>
                    </template>
                </vaadin-grid-column>
            </vaadin-grid>
        </paper-expansion-panel>

        <div id="plugin-meta"></div>
    </template>
</dom-module>

<script>
    class DTileMetaEditor extends Polymer.Element {
        static get is() { return "dtile-meta-editor"; }

        static get properties() {
            return {
                meta: Object,
                metaType: String,
                context: Object,

                _publicMeta: Array,
                _metaPlugins: Array
            };
        }

        static get observers() {
            return [
                "_setPublicMeta(meta)",
                "_setPluginMeta(meta)"
            ];
        }

        ready() {
            super.ready();

            const PaperExpansionPanel = customElements.get("paper-expansion-panel");

            this._metaPlugins = DTile.metaPlugins.map(Plugin => {
                const panel = new PaperExpansionPanel();
                panel.header = Plugin.pluginName;

                const plugin = new Plugin();
                panel.appendChild(plugin);
                this.$["plugin-meta"].appendChild(panel);
                return plugin;
            });

            this.addEventListener("toggle", e => {
                if (e.detail.tagName === "PAPER-EXPANSION-PANEL" && e.detail.opened) {
                    const panels = [...this.shadowRoot.querySelectorAll("paper-expansion-panel")];
                    panels.forEach(panel => {
                        if (panel !== e.detail) {
                            panel.opened = false;
                        }
                    });
                }
            });
        }

        prepare() {
            this._metaPlugins.forEach(plugin => {
                if (plugin.typeMatch) {
                    const show = plugin.typeMatch(this.metaType);
                    if (show) plugin.parentElement.removeAttribute("hidden");
                    else plugin.parentElement.setAttribute("hidden", true);
                }
            });
        }

        _setPublicMeta(meta = {}) {
            this._publicMeta = Object.keys(meta)<commit_msg>Fix bug when opening meta on undefined<commit_after><link rel="import" href="../../bower_components/polymer/polymer.html">

<link rel="import" href="../../bower_components/paper-input/paper-input.html">
<link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../../bower_components/paper-expansion-panel/paper-expansion-panel.html">

<link rel="import" href="../../bower_components/vaadin-grid/vaadin-grid.html">

<link rel="import" href="../standard-plugins/import.html">

<dom-module id="dtile-meta-editor">
    <template>
        <style>
            :host {
                display: block;
                min-width: 50vw;
            }

            vaadin-grid, vaadin-grid * {
                background: var(--primary-background-color);
                color: white;
                border: none !important;

                --vaadin-grid-cell: {
                    padding: 8px 16px;
                };
            }

            paper-expansion-panel[hidden] {
                display: none;
            }

            paper-expansion-panel > * {
                height: 50vh;
                display: block;
            }
        </style>

        <paper-expansion-panel header="Public properties" opened>
            <vaadin-grid id="public-meta-grid" items="[[_publicMeta]]">
                <vaadin-grid-column>
                    <template class="header">Key</template>
                    <template>
                        <paper-input value="{{item.key}}" no-label-float></paper-input>
                    </template>
                    <template class="footer">
                        <paper-input id="new-key" no-label-float label="Key"
                            on-keydown="_checkEntryEnter">
                        </paper-input>
                    </template>
                </vaadin-grid-column>

                <vaadin-grid-column>
                    <template class="header">Value</template>
                    <template>
                        <paper-input value="{{item.value}}" no-label-float></paper-input>
                    </template>
                    <template class="footer">
                        <paper-input id="new-value" no-label-float label="Value"
                            on-keydown="_checkEntryEnter">
                        </paper-input>
                    </template>
                </vaadin-grid-column>

                <vaadin-grid-column width="72px" flex-grow="0">
                    <template>
                        <paper-icon-button icon="clear" on-tap="_removeTapped"></paper-icon-button>
                    </template>
                    <template class="footer">
                        <paper-icon-button icon="add" on-tap="_addPublicEntry"></paper-icon-button>
                    </template>
                </vaadin-grid-column>
            </vaadin-grid>
        </paper-expansion-panel>

        <div id="plugin-meta"></div>
    </template>
</dom-module>

<script>
    class DTileMetaEditor extends Polymer.Element {
        static get is() { return "dtile-meta-editor"; }

        static get properties() {
            return {
                meta: Object,
                metaType: String,
                context: Object,

                _publicMeta: Array,
                _metaPlugins: Array
            };
        }

        static get observers() {
            return [
                "_setPublicMeta(meta)",
                "_setPluginMeta(meta)"
            ];
        }

        ready() {
            super.ready();

            const PaperExpansionPanel = customElements.get("paper-expansion-panel");

            this._metaPlugins = DTile.metaPlugins.map(Plugin => {
                const panel = new PaperExpansionPanel();
                panel.header = Plugin.pluginName;

                const plugin = new Plugin();
                panel.appendChild(plugin);
                this.$["plugin-meta"].appendChild(panel);
                return plugin;
            });

            this.addEventListener("toggle", e => {
                if (e.detail.tagName === "PAPER-EXPANSION-PANEL" && e.detail.opened) {
                    const panels = [...this.shadowRoot.querySelectorAll("paper-expansion-panel")];
                    panels.forEach(panel => {
                        if (panel !== e.detail) {
                            panel.opened = false;
                        }
                    });
                }
            });
        }

        prepare() {
            if (typeof this.meta === "undefined") {
                this._setPublicMeta();
                this._setPluginMeta();
            }

            this._metaPlugins.forEach(plugin => {
                if (plugin.typeMatch) {
                    const show = plugin.typeMatch(this.metaType);
                    if (show) plugin.parentElement.removeAttribute("hidden");
                    else plugin.parentElement.setAttribute("hidden", true);
                }
            });
        }

        _setPublicMeta(meta = {}) {
            this._publicMeta = Object.keys(meta)
{'fraction_non_alphanumeric': 0.12914762567057422, 'fraction_numerical': 0.001986886548778065, 'mean_word_length': 1.2889949977262392, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 119, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5704498', 'n_tokens_mistral': 2648, 'n_tokens_neox': 2421, 'n_words': 401}