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

<link rel="import" href="../../bower_components/app-route/app-location.html">

<link rel="import" href="../../bower_components/iron-pages/iron-pages.html">

<link rel="import" href="../dtile-shell/dtile-shell.html">
<link rel="import" href="./projects-view.html">
<link rel="import" href="./project-view.html">
<link rel="import" href="./tileset-importer.html">
<link rel="import" href="./new-map-page.html">
<link rel="import" href="../dtile-map-editor/dtile-map-editor.html">
<link rel="import" href="../dtile-tileset-editor/dtile-tileset-editor.html">
<link rel="import" href="../dtile-meta-editor/dtile-meta-editor.html">
<link rel="import" href="../generic-elements/rename-dialog.html">

<link rel="import" href="../status.html">
<link rel="import" href="../storage.html">

<dom-module id="dtile-app">
    <template>
        <style>
            :host, dtile-shell, iron-pages, iron-pages > * {
                display: block;
                width: 100%;
                height: 100%;
            }

            #file-drop-zone {
                position: fixed;
                top: 0; right: 0; bottom: 0; left: 0;
                width: 100vw;
                height: 100vh;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                background: rgba(255, 255, 255, 0.8);
                opacity: 0;
                transition: opacity 0.2s;
            }

            #file-drop-zone > iron-icon {
                --iron-icon-height: 72px;
                --iron-icon-width: 72px;
                margin: 30px;
            }
        </style>

        <div id="file-drop-zone">
            <iron-icon icon="file-upload"></iron-icon>
            Drop file to import it
        </div>

        <app-location id="location" route="{{route}}"></app-location>

        <paper-dialog id="meta-editor-dialog" modal>
            <h2>Edit meta data</h2>
            <dtile-meta-editor id="meta-editor"></dtile-meta-editor>
            <div class="buttons">
                <paper-button dialog-dismiss on-tap="_metaDialogClose">Cancel</paper-button>
                <paper-button dialog-confirm on-tap="_metaDialogClose">Apply</paper-button>
            </div>
        </paper-dialog>

        <rename-dialog></rename-dialog>

        <dtile-shell>
            <iron-pages id="pages" selected="[[pageView]]" attr-for-selected="page">
                <dtile-projects-view page="projects"></dtile-projects-view>
                <dtile-project-view page="project"></dtile-project-view>
                <dtile-tileset-editor page="edit-tileset"></dtile-tileset-editor>
                <dtile-map-editor page="edit-map"></dtile-map-editor>
                <dtile-tileset-importer page="import-tileset"></dtile-tileset-importer>
                <dtile-new-map-page page="new-map"></dtile-new-map-page>
            </iron-pages>
        </dtile-shell>
    </template>
</dom-module>

<script>
    window.DTile = window.DTile || {};

    class DTileApp extends DTile.ReduxMixin(Polymer.Element) {
        static get is() { return "dtile-app"; }

        static get properties() {
            return {
                route: String,
                page: { type: String, statePath: "ui.currentPage" },
                pageView: String,
                uiState: { type: Object, statePath: "ui" },
                pageId: { type: String, computed: "_getIdForPage(page, uiState)" },

                isReady: Boolean
            };
        }

        static get observers() {
            return [
                "_pageStateUpdated(page, pageId)",
                "_pathUpdated(route.path)"
            ];
        }

        ready() {
            super.ready();

            const setDropHintVisibility = (visible, preventEvent) => {
                if (preventEvent) {
                    preventEvent.stopPropagation();
                    preventEvent.preventDefault();
                    preventEvent.dataTransfer.dropEffect = "copy";
                }
                this.$["file-drop-zone"].style.opacity = visible ? 1 : 0;
            };

            this.addEventListener("dragover", e => setDropHintVisibility(true, e));
            this.addEventListener("dragleave", e => setDropHintVisibility(false, e));

            this.addEventListener("drop", e => {
                e.stopPropagation();
                e.preventDefault();

                setDropHintVisibility(false);

                const currentPage = this.shadowRoot.querySelector(".iron-selected");
                currentPage.dispatchEvent(new CustomEvent("dtile-file-import", {
                    bubbles: true,
                    detail: {
                        files: [...e.dataTransfer.files]
                    }
                }));
            });

            this.addEventListener("dtile-open-meta", e => {
                const metaEditorDialog = this.$["meta-editor-dialog"];

                this._metaCallback = e.detail.callback;
                this.$["meta-editor"].context = e.detail.context;
                this.$["meta-editor"].metaType = e.detail.metaType;
                this.$["meta-editor"].meta = e.detail.meta;
                this.$["meta-editor"].prepare();
                metaEditorDialog.open();
            });

            if (location.hash === "#r") {
                window.history.back();
            }
        }

        _metaDialogClose(e) {
            if (e.target.hasAttribute("dialog-confirm")) {
                this._metaCallback(this.$["meta-editor"].buildMeta());
            } else {
                this._metaCallback();
            }
        }

        _pageStateUpdated(page, pageId) {
            if (!page) return;

            let pageUpdated;
            if (this._previousPage !== page) {
                this._previousPage = page;
                pageUpdated = true;
            } else if (this._previousPageId !== pageId) {
                this._previousPageId = pageId;
            } else return;

            if (pageUpdated) {
                if (this._previousView) {
                    this._previousView.dispatchEvent(new CustomEvent("dtile-page-away"));
                }

                const animationOptions = {
                    iterations: 1,
                    duration: 200
                };

                this.$.pages.animate([
                    { opacity: 1, transform: "translate(0, 0)" },
                    { opacity: 0, transform: "translate(0, 40px)" }
                ], animationOptions).onfinish = () => {
                    this.pageView = page;
                    this.$.pages.animate([
                        { opacity: 0, transform: "translate(0, -40px)" },
                        { opacity: 1, transform: "translate(0, 0)" }
                    ], animationOptions);

                    requestAnimationFrame(() => {
                        const currentView = this.shadowRoot.querySelector(".iron-selected");
                        if (!currentView) return;
                        currentView.dispatchEvent(new CustomEvent("dtile-page-to"));

                        this._previousView = currentView;
                    });
                };
            }

            const newPath = `/${page}${pageId !== null ? `/${pageId}` : ""}`;

            if (newPath !== location.pathname) {
                history.pushState(null, null, newPath);
                window.dispatchEvent(new CustomEvent("location-changed"));
            }
        }

        _pathUpdated(pathname) {
            const prefixedRoot = !DTile.disablePrefix && pathname === "/DTile";
            if (pathname === "/" || prefixedRoot) {
                history.replaceState(null, null, (prefixedRoot ? "/DTile" : "") + "/projects");
                window.dispatchEvent(new CustomEvent("location-changed"));
                return;
            }

            if (this._previousPathname === pathname) return;

            const pathRegex = new RegExp(
                (DTile.disablePrefix ? "" : "(?:\\/DTile)?") +
                "\\/([\\w-]+)(?:\\/(\\d+))?"
            );
            const [_, page, pageId] = pathname.match(pathRegex);

            // eslint-disable-next-line eqeqeq
            if (this.page != page || this._getIdForPage(page) != pageId) {
                const pagePayload = { page };
                if (pageId) {
                    const idKey = (page === "edit-map" ? "map" : page) + "Id";
                    pagePayload[idKey] = pageId;
                }
                this.dispatch("setCurrentPage", pagePayload);
            }

            this._previousPathname = pathname;
        }

        _getIdForPage(page) {
            if (page === "project") return this.getState().ui.currentProjectId;
            else if (page === "edit-map") return this.getState().ui.currentMapId;
            else if (page === "edit-tileset") return this.getState().ui.currentTilesetId;
            return null;
        }
    }

    customElements.define(DTileApp.is, DTileApp);

    /* Reload function for easy debug reloading (not quite HMR though) */
    // eslint-disable-next-line no-unused-vars
    function r() {
        window.location.href = "/#r";
    }
</script>
<commit_msg>Remove modal from meta editor dialog<commit_after><link rel="import" href="../../bower_components/polymer/polymer.html">

<link rel="import" href="../../bower_components/app-route/app-location.html">

<link rel="import" href="../../bower_components/iron-pages/iron-pages.html">

<link rel="import" href="../dtile-shell/dtile-shell.html">
<link rel="import" href="./projects-view.html">
<link rel="import" href="./project-view.html">
<link rel="import" href="./tileset-importer.html">
<link rel="import" href="./new-map-page.html">
<link rel="import" href="../dtile-map-editor/dtile-map-editor.html">
<link rel="import" href="../dtile-tileset-editor/dtile-tileset-editor.html">
<link rel="import" href="../dtile-meta-editor/dtile-meta-editor.html">
<link rel="import" href="../generic-elements/rename-dialog.html">

<link rel="import" href="../status.html">
<link rel="import" href="../storage.html">

<dom-module id="dtile-app">
    <template>
        <style>
            :host, dtile-shell, iron-pages, iron-pages > * {
                display: block;
                width: 100%;
                height: 100%;
            }

            #file-drop-zone {
                position: fixed;
                top: 0; right: 0; bottom: 0; left: 0;
                width: 100vw;
                height: 100vh;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                background: rgba(255, 255, 255, 0.8);
                opacity: 0;
                transition: opacity 0.2s;
            }

            #file-drop-zone > iron-icon {
                --iron-icon-height: 72px;
                --iron-icon-width: 72px;
                margin: 30px;
            }
        </style>

        <div id="file-drop-zone">
            <iron-icon icon="file-upload"></iron-icon>
            Drop file to import it
        </div>

        <app-location id="location" route="{{route}}"></app-location>

        <paper-dialog id="meta-editor-dialog" with-backdrop>
            <h2>Edit meta data</h2>
            <dtile-meta-editor id="meta-editor"></dtile-meta-editor>
            <div class="buttons">
                <paper-button dialog-dismiss on-tap="_metaDialogClose">Cancel</paper-button>
                <paper-button dialog-confirm on-tap="_metaDialogClose">Apply</paper-button>
            </div>
        </paper-dialog>

        <rename-dialog></rename-dialog>

        <dtile-shell>
            <iron-pages id="pages" selected="[[pageView]]" attr-for-selected="page">
                <dtile-projects-view page="projects"></dtile-projects-view>
                <dtile-project-view page="project"></dtile-project-view>
                <dtile-tileset-editor page="edit-tileset"></dtile-tileset-editor>
                <dtile-map-editor page="edit-map"></dtile-map-editor>
                <dtile-tileset-importer page="import-tileset"></dtile-tileset-importer>
                <dtile-new-map-page page="new-map"></dtile-new-map-page>
            </iron-pages>
        </dtile-shell>
    </template>
</dom-module>

<script>
    window.DTile = window.DTile || {};

    class DTileApp extends DTile.ReduxMixin(Polymer.Element) {
        static get is() { return "dtile-app"; }

        static get properties() {
            return {
                route: String,
                page: { type: String, statePath: "ui.currentPage" },
                pageView: String,
                uiState: { type: Object, statePath: "ui" },
                pageId: { type: String, computed: "_getIdForPage(page, uiState)" },

                isReady: Boolean
            };
        }

        static get observers() {
            return [
                "_pageStateUpdated(page, pageId)",
                "_pathUpdated(route.path)"
            ];
        }

        ready() {
            super.ready();

            const setDropHintVisibility = (visible, preventEvent) => {
                if (preventEvent) {
                    preventEvent.stopPropagation();
                    preventEvent.preventDefault();
                    preventEvent.dataTransfer.dropEffect = "copy";
                }
                this.$["file-drop-zone"].style.opacity = visible ? 1 : 0;
            };

            this.addEventListener("dragover", e => setDropHintVisibility(true, e));
            this.addEventListener("dragleave", e => setDropHintVisibility(false, e));

            this.addEventListener("drop", e => {
                e.stopPropagation();
                e.preventDefault();

                setDropHintVisibility(false);

                const currentPage = this.shadowRoot.querySelector(".iron-selected");
                currentPage.dispatchEvent(new CustomEvent("dtile-file-import", {
                    bubbles: true,
                    detail: {
                        files: [...e.dataTransfer.files]
                    }
                }));
            });

            this.addEventListener("dtile-open-meta", e => {
                const metaEditorDialog = this.$["meta-editor-dialog"];

                this._metaCallback = e.detail.callback;
                this.$["meta-editor"].context = e.detail.context;
                this.$["meta-editor"].metaType = e.detail.metaType;
                this.$["meta-editor"].meta = e.detail.meta;
                this.$["meta-editor"].prepare();
                metaEditorDialog.open();
            });

            if (location.hash === "#r") {
                window.history.back();
            }
        }

        _metaDialogClose(e) {
            if (e.target.hasAttribute("dialog-confirm")) {
                this._metaCallback(this.$["meta-editor"].buildMeta());
            } else {
                this._metaCallback();
            }
        }

        _pageStateUpdated(page, pageId) {
            if (!page) return;

            let pageUpdated;
            if (this._previousPage !== page) {
                this._previousPage = page;
                pageUpdated = true;
            } else if (this._previousPageId !== pageId) {
                this._previousPageId = pageId;
            } else return;

            if (pageUpdated) {
                if (this._previousView) {
                    this._previousView.dispatchEvent(new CustomEvent("dtile-page-away"));
                }

                const animationOptions = {
                    iterations: 1,
                    duration: 200
                };

                this.$.pages.animate([
                    { opacity: 1, transform: "translate(0, 0)" },
                    { opacity: 0, transform: "translate(0, 40px)" }
                ], animationOptions).onfinish = () => {
                    this.pageView = page;
                    this.$.pages.animate([
                        { opacity: 0, transform: "translate(0, -40px)" },
                        { opacity: 1, transform: "translate(0, 0)" }
                    ], animationOptions);

                    requestAnimationFrame(() => {
                        const currentView = this.shadowRoot.querySelector(".iron-selected");
                        if (!currentView) return;
                        currentView.dispatchEvent(new CustomEvent("dtile-page-to"));

                        this._previousView = currentView;
                    });
                };
            }

            const newPath = `/${page}${pageId !== null ? `/${pageId}` : ""}`;

            if (newPath !== location.pathname) {
                history.pushState(null, null, newPath);
                window.dispatchEvent(new CustomEvent("location-changed"));
            }
        }

        _pathUpdated(pathname) {
            const prefixedRoot = !DTile.disablePrefix && pathname === "/DTile";
            if (pathname === "/" || prefixedRoot) {
                history.replaceState(null, null, (prefixedRoot ? "/DTile" : "") + "/projects");
                window.dispatchEvent(new CustomEvent("location-changed"));
                return;
            }

            if (this._previousPathname === pathname) return;

            const pathRegex = new RegExp(
                (DTile.disablePrefix ? "" : "(?:\\/DTile)?") +
                "\\/([\\w-]+)(?:\\/(\\d+))?"
            );
            const [_, page, pageId] = pathname.match(pathRegex);

            // eslint-disable-next-line eqeqeq
            if (this.page != page || this._getIdForPage(page) != pageId) {
                const pagePayload = { page };
                if (pageId) {
                    const idKey = (page === "edit-map" ? "map" : page) + "Id";
                    pagePayload[idKey] = pageId;
                }
                this.dispatch("setCurrentPage", pagePayload);
            }

            this._previousPathname = pathname;
        }

        _getIdForPage(page) {
            if (page === "project") return this.getState().ui.currentProjectId;
            else if (page === "edit-map") return this.getState().ui.currentMapId;
            else if (page === "edit-tileset") return this.getState().ui.currentTilesetId;
            return null;
        }
    }

    customElements.define(DTileApp.is, DTileApp);

    /* Reload function for easy debug reloading (not quite HMR though) */
    // eslint-disable-next-line no-unused-vars
    function r() {
        window.location.href = "/#r";
    }
</script>

{'fraction_non_alphanumeric': 0.14482758620689656, 'fraction_numerical': 0.006201550387596899, 'mean_word_length': 1.5600109484056384, 'pattern_counts': {'":': 0, '<': 119, '<?xml version=': 0, '>': 137, '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': '6411051', 'n_tokens_mistral': 5271, 'n_tokens_neox': 4922, 'n_words': 885}