UNPKG

@nent/core

Version:

Functional elements to add routing, data-binding, dynamic HTML, declarative actions, audio, video, and so much more. Supercharge static HTML files into web apps without script or builds.

181 lines (180 loc) 5.09 kB
/*! * NENT 2022 */ import { Component, Element, Event, h, Host, Listen, Prop, } from '@stencil/core'; import { actionBus, eventBus, } from '../../services/actions'; import { debugIf, log } from '../../services/common/logging'; import { commonState } from '../../services/common/state'; import { AppActionListener } from './services/actions'; /** * This component enables app services. These are console logging, * theming and event-delegation. As well as a plugin system to * manage a UI kit to add components like Modals, Drawers, * menus, etc. * * @system app * @extension actions * @extension custom * @extension elements */ export class App { constructor() { /** * Turn on debugging to get helpful messages from the * app, routing, data and action systems. */ this.debug = false; } /** * Listen for outside command-requests. These events are delegated into * the internal action-bus. */ delegateActionEventFromDOM(ev) { const action = ev.detail; actionBus.emit(action.topic, action); } componentWillLoad() { commonState.debug = this.debug; if (this.debug) { log('n-app: initializing <debug>'); } else { log(`n-app: initializing`); } this.listener = new AppActionListener(); this.listener.initialize(window, actionBus, eventBus); debugIf(commonState.debug, `n-app: services and listener registered`); this.actionsSubscription = actionBus.on('*', (...args) => { this.actions.emit(...args); }); this.eventSubscription = eventBus.on('*', (...args) => { this.events.emit(...args); }); } render() { return h(Host, { style: { display: 'block' } }); } componentDidLoad() { log('n-app: initialized'); } disconnectedCallback() { var _a, _b; this.listener.destroy(); (_a = this.actionsSubscription) === null || _a === void 0 ? void 0 : _a.call(this); (_b = this.eventSubscription) === null || _b === void 0 ? void 0 : _b.call(this); eventBus.removeAllListeners(); actionBus.removeAllListeners(); } static get is() { return "n-app"; } static get styles() { return "[n-cloak] { display: inherit; }"; } static get properties() { return { "appTitle": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "This is the application / site title.\nIf the views have titles,\nthis is added as a suffix." }, "attribute": "app-title", "reflect": false }, "appDescription": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "This is the application default page description." }, "attribute": "app-description", "reflect": false }, "appKeywords": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "This is the application default page keywords." }, "attribute": "app-keywords", "reflect": false }, "debug": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Turn on debugging to get helpful messages from the\napp, routing, data and action systems." }, "attribute": "debug", "reflect": false, "defaultValue": "false" } }; } static get events() { return [{ "method": "events", "name": "nent:events", "bubbles": true, "cancelable": false, "composed": true, "docs": { "tags": [], "text": "Listen for events that occurred within the nent event system." }, "complexType": { "original": "any", "resolved": "any", "references": {} } }, { "method": "actions", "name": "nent:actions", "bubbles": false, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "These events are command-requests for action handlers to perform tasks.\nAny outside handlers should cancel the event." }, "complexType": { "original": "any", "resolved": "any", "references": {} } }]; } static get elementRef() { return "el"; } static get listeners() { return [{ "name": "nent:actions", "method": "delegateActionEventFromDOM", "target": "body", "capture": false, "passive": true }]; } }