@corti/dictation-web
Version:
Web component for Corti Dictation
94 lines • 4.96 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _DictationKeybindingInput_instances, _DictationKeybindingInput_handleKeybindingInputFocus, _DictationKeybindingInput_handleKeybindingInputBlur, _DictationKeybindingInput_handleKeybindingKeyDown;
import { consume } from "@lit/context";
import { html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { pushToTalkKeybindingContext, toggleToTalkKeybindingContext, } from "../contexts/dictation-context.js";
import KeybindingSelectorStyles from "../styles/keybinding-selector.js";
import { keybindingChangedEvent } from "../utils/events.js";
import { normalizeKeybinding } from "../utils/keybinding.js";
let DictationKeybindingInput = class DictationKeybindingInput extends LitElement {
constructor() {
super(...arguments);
_DictationKeybindingInput_instances.add(this);
this.keybindingType = "toggle-to-talk";
this.disabled = false;
this._isCapturingKeybinding = false;
}
render() {
const keybinding = this.keybindingType === "push-to-talk"
? this._pushToTalkKeybinding
: this._toggleToTalkKeybinding;
const label = this.keybindingType === "push-to-talk"
? "Push-to-Talk keybinding"
: "Toggle-to-Talk keybinding";
return html `
<div>
<label>${label}</label>
<div class="keybinding-selector-wrapper">
${keybinding && html `<div class="keybinding-key">${keybinding}</div>`}
<input
type="text"
class="keybinding-selector-input"
.value=""
placeholder="Click and press a key..."
readonly
@focusin=${__classPrivateFieldGet(this, _DictationKeybindingInput_instances, "m", _DictationKeybindingInput_handleKeybindingInputFocus)}
@focusout=${__classPrivateFieldGet(this, _DictationKeybindingInput_instances, "m", _DictationKeybindingInput_handleKeybindingInputBlur)}
@keydown=${__classPrivateFieldGet(this, _DictationKeybindingInput_instances, "m", _DictationKeybindingInput_handleKeybindingKeyDown)}
?disabled=${this.disabled}
/>
</div>
</div>
`;
}
};
_DictationKeybindingInput_instances = new WeakSet();
_DictationKeybindingInput_handleKeybindingInputFocus = function _DictationKeybindingInput_handleKeybindingInputFocus() {
this._isCapturingKeybinding = true;
};
_DictationKeybindingInput_handleKeybindingInputBlur = function _DictationKeybindingInput_handleKeybindingInputBlur() {
this._isCapturingKeybinding = false;
};
_DictationKeybindingInput_handleKeybindingKeyDown = function _DictationKeybindingInput_handleKeybindingKeyDown(event) {
if (!this._isCapturingKeybinding) {
return;
}
event.preventDefault();
event.stopPropagation();
const keybinding = normalizeKeybinding(event.key);
this.dispatchEvent(keybindingChangedEvent(event.key, event.code, keybinding, this.keybindingType));
};
DictationKeybindingInput.styles = KeybindingSelectorStyles;
__decorate([
property({ type: String })
], DictationKeybindingInput.prototype, "keybindingType", void 0);
__decorate([
consume({ context: pushToTalkKeybindingContext, subscribe: true }),
state()
], DictationKeybindingInput.prototype, "_pushToTalkKeybinding", void 0);
__decorate([
consume({ context: toggleToTalkKeybindingContext, subscribe: true }),
state()
], DictationKeybindingInput.prototype, "_toggleToTalkKeybinding", void 0);
__decorate([
property({ type: Boolean })
], DictationKeybindingInput.prototype, "disabled", void 0);
__decorate([
state()
], DictationKeybindingInput.prototype, "_isCapturingKeybinding", void 0);
DictationKeybindingInput = __decorate([
customElement("dictation-keybinding-input")
], DictationKeybindingInput);
export { DictationKeybindingInput };
//# sourceMappingURL=keybinding-input.js.map