import { html, css, LitElement, unsafeCSS } from 'https://unpkg.com/lit-element/lit-element.js?module'; import { GridLetter } from './gridBoxes.js'; export class SolutionLetter extends LitElement { static get styles() { return GridLetter.styles; } static get properties() { return { solutionIndex: { type: Number }, grid_id: { type: String } }; } constructor() { super(); this._letter = ""; this.solutionIndex = 0; this.grid_id = ""; this.grid = null; this.revealed = false; } update(props) { if (props.has("grid_id")) { this.grid = document.getElementById(this.grid_id); } super.update(props); } reveal(letter) { var el = this.shadowRoot.getElementById("solution" + this.solutionIndex); this.letter = letter; el.readOnly = true; this.revealed = true; } set letter(letter) { this._letter = letter var e = this.shadowRoot.getElementById("solution" + this.solutionIndex); if (e.value != this.letter) e.value = this.letter } get letter(){ return this._letter; } onFocus(e) { e.target.select(); } onInput(e) { if (this.revealed) { e.handled = true; return; } var val = e.target.value; var el = this.shadowRoot.getElementById("solution" + this.solutionIndex); if (val.length > 1) { val = val[0]; } if (e.target.value != this.letter){ this.letter = val; this.grid.setSolutionLetter(this.solutionIndex, this.letter); } e.target.select(); e.handled = true; } render() { console.log("render solution letter"); return html`