Skip to content
Snippets Groups Projects
Select Git revision
  • 724d624b23cd2a3b22f57ba5bf12d9630364d411
  • main default protected
  • demo protected
  • master
  • icon-set-mapping
  • production protected
  • revert-62666d1a
  • favorites-and-recent-files
  • lit2
  • wc-part
  • mark-downloaded-files
  • feature/annotpdf-test
  • fix-zip-upload
  • config-cleanup
  • wip
  • app-shell-update
16 results

utils.js

Blame
  • dbp-lit-element.js 5.09 KiB
    import {AdapterLitElement} from './src/adapter-lit-element';
    
    export default class DBPLitElement extends AdapterLitElement {
        constructor() {
            super();
            this.htmlOverrides = '';
            this._localTemplateSlotsImported = false;
            this._globalSlotsContainer = null;
            this._globalTemplateSlotsImported = false;
            this._renderDone = false;
        }
    
        static get properties() {
            return {
                ...super.properties,
                htmlOverrides: {type: String, attribute: 'html-overrides'},
            };
        }
    
        disconnectedCallback() {
            super.disconnectedCallback();
    
            if (this._globalSlotsContainer !== null) {
                this._globalSlotsContainer.remove();
            }
        }
    
        _(selector) {
            return this.shadowRoot === null
                ? this.querySelector(selector)
                : this.shadowRoot.querySelector(selector);
        }
    
        firstUpdated() {
            super.firstUpdated();
            this._renderDone = true;
            this._importTemplateSlots();
        }
    
        update(changedProperties) {
            changedProperties.forEach((oldValue, propName) => {
                switch (propName) {
                    case 'html-overrides':
                        this._importTemplateSlots();
                        break;
                }
            });
    
            super.update(changedProperties);
        }
    
        /**
         * Transforms all global override templates or named template slots in the light DOM to named div slots
         * on the first render.
         *
         * Global overrides will replace all existing slotted elements with the same slot name.
         */
        _importTemplateSlots() {
            if (!this._renderDone) {
                return;
            }
            this._importLocalTemplateSlots();
            this._importGlobalTemplateSlots();
        }
    
        _importLocalTemplateSlots() {
            if (this._localTemplateSlotsImported) {
                return;
            }