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.

215 lines (214 loc) 5.71 kB
/*! * NENT 2022 */ import { Component, Element, h, Host, Method, Prop, State, } from '@stencil/core'; import { ActionService } from '../../services/actions/service'; import { debugIf } from '../../services/common/logging'; import { AudioType, AUDIO_TOPIC, } from '../n-audio/services/interfaces'; import { audioState, onAudioStateChange, } from '../n-audio/services/state'; /** * This element represents an action to be fired. This * specialized action encapsulates required parameters * needed for audio-based actions, for music. * * @system audio * @system actions */ export class AudioMusicAction { constructor() { this.valid = true; /** * Readonly topic * */ this.topic = AUDIO_TOPIC; this.actionService = new ActionService(this, 'n-audio-action-music'); } get childScript() { return this.el.querySelector('script'); } get childInputs() { return this.el.querySelectorAll('input,select,textarea'); } getData() { return { type: AudioType.music, trackId: this.trackId, value: this.value, }; } /** * Get the underlying actionEvent instance. Used by the n-action-activator element. */ async getAction() { const action = await this.actionService.getAction(); if (action == null) return null; Object.assign(action.data, this.getData()); return action; } /** * Send this action to the the action messaging system. */ async sendAction(data) { if (audioState.hasAudioComponent) { Object.assign(data, this.getData()); this.actionService.sendAction(data); } else { this.dispose = onAudioStateChange('hasAudioComponent', async (loaded) => { var _a; if (loaded) { this.actionService.sendAction(data); debugIf(audioState.debug, `n-audio-action-music: load-action sent for ${this.trackId}`); } (_a = this.dispose) === null || _a === void 0 ? void 0 : _a.call(this); }); } } render() { return h(Host, null); } disconnectedCallback() { var _a; (_a = this.dispose) === null || _a === void 0 ? void 0 : _a.call(this); } static get is() { return "n-audio-action-music"; } static get encapsulation() { return "shadow"; } static get properties() { return { "topic": { "type": "string", "mutable": false, "complexType": { "original": "\"audio\"", "resolved": "\"audio\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Readonly topic" }, "attribute": "topic", "reflect": false, "defaultValue": "AUDIO_TOPIC" }, "command": { "type": "string", "mutable": false, "complexType": { "original": "| 'start'\n | 'pause'\n | 'resume'\n | 'mute'\n | 'volume'\n | 'seek'", "resolved": "\"mute\" | \"pause\" | \"resume\" | \"seek\" | \"start\" | \"volume\"", "references": {} }, "required": true, "optional": false, "docs": { "tags": [], "text": "The command to execute." }, "attribute": "command", "reflect": false }, "trackId": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The track to target." }, "attribute": "track-id", "reflect": false }, "value": { "type": "any", "mutable": false, "complexType": { "original": "string | boolean | number", "resolved": "boolean | number | string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The value payload for the command." }, "attribute": "value", "reflect": false }, "when": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "A predicate to evaluate prior to sending the action." }, "attribute": "when", "reflect": false } }; } static get states() { return { "valid": {} }; } static get methods() { return { "getAction": { "complexType": { "signature": "() => Promise<EventAction<any> | null>", "parameters": [], "references": { "Promise": { "location": "global" }, "EventAction": { "location": "import", "path": "../../services/actions" } }, "return": "Promise<EventAction<any> | null>" }, "docs": { "text": "Get the underlying actionEvent instance. Used by the n-action-activator element.", "tags": [] } }, "sendAction": { "complexType": { "signature": "(data?: Record<string, any> | undefined) => Promise<void>", "parameters": [{ "tags": [], "text": "" }], "references": { "Promise": { "location": "global" }, "Record": { "location": "global" } }, "return": "Promise<void>" }, "docs": { "text": "Send this action to the the action messaging system.", "tags": [] } } }; } static get elementRef() { return "el"; } }