UNPKG

@infinite-canvas-tutorial/webcomponents

Version:
83 lines (81 loc) 2.57 kB
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; }; import { css, html, LitElement } from 'lit'; import { consume } from '@lit/context'; import { customElement, property, state } from 'lit/decorators.js'; import { when } from 'lit/directives/when.js'; import { query } from 'lit/decorators/query.js'; import { apiContext } from '../context'; let LayerName = class LayerName extends LitElement { constructor() { super(...arguments); this.editing = false; } handleDoubleClick() { this.editing = true; setTimeout(() => { this.textfield.focus(); }, 0); } handleKeydown(event) { if (event.key === 'Enter') { this.textfield.blur(); } } handleBlur() { this.editing = false; this.api.updateNode(this.node, { name: this.textfield.value, }); } render() { const { name } = this.node; return html ` ${when(this.editing, () => html `<sp-textfield quiet size="m" @blur=${this.handleBlur} @keydown=${this.handleKeydown} value=${name} ></sp-textfield>`, () => html `<span @dblclick=${this.handleDoubleClick}>${name}</span>`)} `; } }; LayerName.styles = css ` :host { display: flex; align-items: center; } sp-textfield { width: 100%; margin-top: 4px; } span { width: 100%; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; } `; __decorate([ property() ], LayerName.prototype, "node", void 0); __decorate([ state() ], LayerName.prototype, "editing", void 0); __decorate([ query('sp-textfield') ], LayerName.prototype, "textfield", void 0); __decorate([ consume({ context: apiContext, subscribe: true }) ], LayerName.prototype, "api", void 0); LayerName = __decorate([ customElement('ic-spectrum-layer-name') ], LayerName); export { LayerName }; //# sourceMappingURL=layer-name.js.map