@infinite-canvas-tutorial/webcomponents
Version:
WebComponents UI implementation
86 lines (84 loc) • 2.86 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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LayerName = void 0;
const lit_1 = require("lit");
const context_1 = require("@lit/context");
const decorators_js_1 = require("lit/decorators.js");
const when_js_1 = require("lit/directives/when.js");
const query_js_1 = require("lit/decorators/query.js");
const context_2 = require("../context");
let LayerName = class LayerName extends lit_1.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 (0, lit_1.html) `
${(0, when_js_1.when)(this.editing, () => (0, lit_1.html) `<sp-textfield
quiet
size="m"
@blur=${this.handleBlur}
@keydown=${this.handleKeydown}
value=${name}
></sp-textfield>`, () => (0, lit_1.html) `<span @dblclick=${this.handleDoubleClick}>${name}</span>`)}
`;
}
};
exports.LayerName = LayerName;
LayerName.styles = (0, lit_1.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([
(0, decorators_js_1.property)()
], LayerName.prototype, "node", void 0);
__decorate([
(0, decorators_js_1.state)()
], LayerName.prototype, "editing", void 0);
__decorate([
(0, query_js_1.query)('sp-textfield')
], LayerName.prototype, "textfield", void 0);
__decorate([
(0, context_1.consume)({ context: context_2.apiContext, subscribe: true })
], LayerName.prototype, "api", void 0);
exports.LayerName = LayerName = __decorate([
(0, decorators_js_1.customElement)('ic-spectrum-layer-name')
], LayerName);
//# sourceMappingURL=layer-name.js.map
;