<commit_before>import '/resources/polymer/@polymer/polymer/polymer-legacy.js';

import '/resources/polymer/@polymer/iron-flex-layout/iron-flex-layout.js';
import '/resources/polymer/@polymer/iron-flex-layout/iron-flex-layout-classes.js';

import '/resources/polymer/@polymer/app-route/app-location.js';
import '/resources/polymer/@polymer/app-route/app-route.js';

import '/resources/polymer/@polymer/neon-animation/neon-animated-pages.js';

import '/resources/views/tg-app-menu.js';
import '/resources/views/tg-app-view.js';
import '/resources/master/tg-entity-master.js';
import '/resources/actions/tg-ui-action.js';
import '/resources/components/tg-message-panel.js';

import { Polymer } from '/resources/polymer/@polymer/polymer/lib/legacy/polymer-fn.js';
import { html } from '/resources/polymer/@polymer/polymer/lib/utils/html-tag.js';
import { IronOverlayManager } from '/resources/polymer/@polymer/iron-overlay-behavior/iron-overlay-manager.js';
import { IronA11yKeysBehavior } from '/resources/polymer/@polymer/iron-a11y-keys-behavior/iron-a11y-keys-behavior.js';
import { IronResizableBehavior } from '/resources/polymer/@polymer/iron-resizable-behavior/iron-resizable-behavior.js';

import { TgEntityMasterBehavior } from '/resources/master/tg-entity-master-behavior.js';
import { TgFocusRestorationBehavior } from '/resources/actions/tg-focus-restoration-behavior.js'
import {TgTooltipBehavior} from '/resources/components/tg-tooltip-behavior.js';
import { tearDownEvent, deepestActiveElement, generateUUID, isMobileApp, containsRestictedTags } from '/resources/reflection/tg-polymer-utils.js';
import { _timeZoneHeader } from '/resources/reflection/tg-date-utils.js';

const template = html`
    <style>
        :host {
            overflow: hidden;
        }
    </style>
    <style include="iron-flex iron-flex-reverse iron-flex-alignment iron-flex-factors iron-positioning"></style>
    <app-location id="location" no-decode dwell-time="-1" route="{{_route}}" url-space-regex="^/#/" use-hash-as-path></app-location>
    <app-route route="{{_route}}" pattern="/:moduleName" data="{{_routeData}}" tail="{{_subroute}}"></app-route>
    <tg-message-panel></tg-message-panel>
    <div class="relative flex">
        <neon-animated-pages id="pages" class="fit" attr-for-selected="name" on-neon-animation-finish="_animationFinished" animate-initial-selection>
            <tg-app-menu class="fit" name="menu" menu-config="[[menuConfig]]" app-title="[[appTitle]]">
                <!--menu action dom-->
            </tg-app-menu>
            <template is="dom-repeat" items="[[menuConfig.menu]]" on-dom-change="_modulesRendered">
                <tg-app-view class="fit hero-animatable" name$="[[item.key]]" menu="[[menuConfig.menu]]" menu-item="[[item]]" can-edit="[[menuConfig.canEdit]]" menu-save-callback="[[_saveMenuVisibilityChanges]]" selected-module="[[_selectedModule]]" submodule="{{_selectedSubmodule}}"></tg-app-view>
            </template>
        </neon-animated-pages>
    </div>
    <iron-ajax id="errorSender" headers="[[_headers]]" url="/error" method="PUT" content-type="text/plain" handle-as="text" on-response="_processErrorResponse"></iron-ajax>
    <tg-entity-master
        id="masterDom"
        entity-type="[[entityType]]"
        entity-id="new"
        hidden
        _post-validated-default="[[_postValidatedDefault]]"
        _post-validated-default-error="[[_postValidatedDefaultError]]"
        _process-response="[[_processResponse]]"
        _process-error="[[_processError]]"
        _process-retriever-response="[[_processRetrieverResponse]]"
        _process-retriever-error="[[_processRetrieverError]]"
        _process-saver-response="[[_processSaverResponse]]"
        _process-saver-error="[[_processSaverError]]"
        _saver-loading="{{_saverLoading}}">
        <tg-ui-action
            id="menuSaveAction"
            ui-role='ICON'
            component-uri='/master_ui/ua.com.fielden.platform.menu.MenuSaveAction'
            element-name='tg-MenuSaveAction-master'
            show-dialog='[[_showDialog]]'
            toaster='[[toaster]]'
            create-context-holder='[[_createContextHolder]]'
            attrs='[[_attrs]]'
            require-selection-criteria='false'
            require-selected-entities='NONE'
            require-master-entity='false'>
        </tg-ui-action>
        <tg-ui-action
            id="openMasterAction"
            ui-role='ICON'
            show-dialog='[[_showDialog]]'
            toaster='[[toaster]]'
            create-context-holder='[[_createContextHolder]]'
            dynamic-action
            attrs='[[_openMasterAttrs]]'
            require-selection-criteria='false'
            require-selected-entities='ONE'
            require-master-entity='false'>
        </tg-ui-action>
    </tg-entity-master>`;

template.setAttribute('strip-whitespace', '');

function findModule (moduleName, menuConfig) {
    var itemIndex;
    for (itemIndex = 0; itemIndex < menuConfig.menu.length; itemIndex++) {
        if (menuConfig.menu[itemIndex].key === moduleName) {
            return moduleName;
        }
    }
    return "menu";
};
function addAllElements (elementsToAdd, addToArray, removeFromArray) {
    addToArray = addToArray || [];
    if (elementsToAdd) {
        elementsToAdd.forEach(function(element) {
            if (addToArray.indexOf(element) < 0) {
                var indexInInvisible = removeFromArray ? removeFromArray.indexOf(element) : -1;
                if (indexInInvisible >= 0) {
                    removeFromArray.splice(indexInInvisible, 1);
                }
                addToArray.push(element);
            }
        });
    }
    return addToArray;
};
function replaceNewline (input) {
    const newline = "\r\n";
    new RegExp('<html|<body|<script|<img|<a', 'mi');
    return input.replace(/\n/gi, containsRestictedTags(input) ? newline : '<br>');
};
Polymer({

    _template: template,

    is: "tg-app-template",

    properties: {
        /**
         * The property which indicates whether entity master is 'UI-less'.
         */
        noUI: {
            type: Boolean,
            value: true
        },
        /**
         * This property governs master behavior upon its activation for the first time (i.e. when master element was instantiated and bound to an entity instance).
         * If saveOnActivation is true then entity saving occurs automatically just before the master UI gets displayed.
         * It most conveniently used for masters that represent functional entities (i.e. actions).
         **/
        saveOnActivation: {
            type: Boolean,
            value: true
        },
        
        keyEventTarget: {
            type: Object,<commit_msg>#1554 Removed unnecessary RegExp instantiation.<commit_after>import '/resources/polymer/@polymer/polymer/polymer-legacy.js';

import '/resources/polymer/@polymer/iron-flex-layout/iron-flex-layout.js';
import '/resources/polymer/@polymer/iron-flex-layout/iron-flex-layout-classes.js';

import '/resources/polymer/@polymer/app-route/app-location.js';
import '/resources/polymer/@polymer/app-route/app-route.js';

import '/resources/polymer/@polymer/neon-animation/neon-animated-pages.js';

import '/resources/views/tg-app-menu.js';
import '/resources/views/tg-app-view.js';
import '/resources/master/tg-entity-master.js';
import '/resources/actions/tg-ui-action.js';
import '/resources/components/tg-message-panel.js';

import { Polymer } from '/resources/polymer/@polymer/polymer/lib/legacy/polymer-fn.js';
import { html } from '/resources/polymer/@polymer/polymer/lib/utils/html-tag.js';
import { IronOverlayManager } from '/resources/polymer/@polymer/iron-overlay-behavior/iron-overlay-manager.js';
import { IronA11yKeysBehavior } from '/resources/polymer/@polymer/iron-a11y-keys-behavior/iron-a11y-keys-behavior.js';
import { IronResizableBehavior } from '/resources/polymer/@polymer/iron-resizable-behavior/iron-resizable-behavior.js';

import { TgEntityMasterBehavior } from '/resources/master/tg-entity-master-behavior.js';
import { TgFocusRestorationBehavior } from '/resources/actions/tg-focus-restoration-behavior.js'
import {TgTooltipBehavior} from '/resources/components/tg-tooltip-behavior.js';
import { tearDownEvent, deepestActiveElement, generateUUID, isMobileApp, containsRestictedTags } from '/resources/reflection/tg-polymer-utils.js';
import { _timeZoneHeader } from '/resources/reflection/tg-date-utils.js';

const template = html`
    <style>
        :host {
            overflow: hidden;
        }
    </style>
    <style include="iron-flex iron-flex-reverse iron-flex-alignment iron-flex-factors iron-positioning"></style>
    <app-location id="location" no-decode dwell-time="-1" route="{{_route}}" url-space-regex="^/#/" use-hash-as-path></app-location>
    <app-route route="{{_route}}" pattern="/:moduleName" data="{{_routeData}}" tail="{{_subroute}}"></app-route>
    <tg-message-panel></tg-message-panel>
    <div class="relative flex">
        <neon-animated-pages id="pages" class="fit" attr-for-selected="name" on-neon-animation-finish="_animationFinished" animate-initial-selection>
            <tg-app-menu class="fit" name="menu" menu-config="[[menuConfig]]" app-title="[[appTitle]]">
                <!--menu action dom-->
            </tg-app-menu>
            <template is="dom-repeat" items="[[menuConfig.menu]]" on-dom-change="_modulesRendered">
                <tg-app-view class="fit hero-animatable" name$="[[item.key]]" menu="[[menuConfig.menu]]" menu-item="[[item]]" can-edit="[[menuConfig.canEdit]]" menu-save-callback="[[_saveMenuVisibilityChanges]]" selected-module="[[_selectedModule]]" submodule="{{_selectedSubmodule}}"></tg-app-view>
            </template>
        </neon-animated-pages>
    </div>
    <iron-ajax id="errorSender" headers="[[_headers]]" url="/error" method="PUT" content-type="text/plain" handle-as="text" on-response="_processErrorResponse"></iron-ajax>
    <tg-entity-master
        id="masterDom"
        entity-type="[[entityType]]"
        entity-id="new"
        hidden
        _post-validated-default="[[_postValidatedDefault]]"
        _post-validated-default-error="[[_postValidatedDefaultError]]"
        _process-response="[[_processResponse]]"
        _process-error="[[_processError]]"
        _process-retriever-response="[[_processRetrieverResponse]]"
        _process-retriever-error="[[_processRetrieverError]]"
        _process-saver-response="[[_processSaverResponse]]"
        _process-saver-error="[[_processSaverError]]"
        _saver-loading="{{_saverLoading}}">
        <tg-ui-action
            id="menuSaveAction"
            ui-role='ICON'
            component-uri='/master_ui/ua.com.fielden.platform.menu.MenuSaveAction'
            element-name='tg-MenuSaveAction-master'
            show-dialog='[[_showDialog]]'
            toaster='[[toaster]]'
            create-context-holder='[[_createContextHolder]]'
            attrs='[[_attrs]]'
            require-selection-criteria='false'
            require-selected-entities='NONE'
            require-master-entity='false'>
        </tg-ui-action>
        <tg-ui-action
            id="openMasterAction"
            ui-role='ICON'
            show-dialog='[[_showDialog]]'
            toaster='[[toaster]]'
            create-context-holder='[[_createContextHolder]]'
            dynamic-action
            attrs='[[_openMasterAttrs]]'
            require-selection-criteria='false'
            require-selected-entities='ONE'
            require-master-entity='false'>
        </tg-ui-action>
    </tg-entity-master>`;

template.setAttribute('strip-whitespace', '');

function findModule (moduleName, menuConfig) {
    var itemIndex;
    for (itemIndex = 0; itemIndex < menuConfig.menu.length; itemIndex++) {
        if (menuConfig.menu[itemIndex].key === moduleName) {
            return moduleName;
        }
    }
    return "menu";
};
function addAllElements (elementsToAdd, addToArray, removeFromArray) {
    addToArray = addToArray || [];
    if (elementsToAdd) {
        elementsToAdd.forEach(function(element) {
            if (addToArray.indexOf(element) < 0) {
                var indexInInvisible = removeFromArray ? removeFromArray.indexOf(element) : -1;
                if (indexInInvisible >= 0) {
                    removeFromArray.splice(indexInInvisible, 1);
                }
                addToArray.push(element);
            }
        });
    }
    return addToArray;
};
function replaceNewline (input) {
    const newline = "\r\n";
    return input.replace(/\n/gi, containsRestictedTags(input) ? newline : '<br>');
};
Polymer({

    _template: template,

    is: "tg-app-template",

    properties: {
        /**
         * The property which indicates whether entity master is 'UI-less'.
         */
        noUI: {
            type: Boolean,
            value: true
        },
        /**
         * This property governs master behavior upon its activation for the first time (i.e. when master element was instantiated and bound to an entity instance).
         * If saveOnActivation is true then entity saving occurs automatically just before the master UI gets displayed.
         * It most conveniently used for masters that represent functional entities (i.e. actions).
         **/
        saveOnActivation: {
            type: Boolean,
            value: true
        },
        
        keyEventTarget: {
            type: Object,
{'fraction_non_alphanumeric': 0.15141604103174014, 'fraction_numerical': 0.0020813201516390397, 'mean_word_length': 2.995841995841996, 'pattern_counts': {'":': 0, '<': 72, '<?xml version=': 0, '>': 65, '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': '422040', 'n_tokens_mistral': 4013, 'n_tokens_neox': 3866, 'n_words': 632}