UNPKG

@infinite-canvas-tutorial/webcomponents

Version:
231 lines (223 loc) 9 kB
"use strict"; 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.LayersPanelItem = void 0; const lit_1 = require("lit"); const decorators_js_1 = require("lit/decorators.js"); const when_js_1 = require("lit/directives/when.js"); const context_1 = require("@lit/context"); const ecs_1 = require("@infinite-canvas-tutorial/ecs"); const overlay_1 = require("@spectrum-web-components/overlay"); const context_2 = require("../context"); const localize_1 = require("@lit/localize"); let LayersPanelItem = class LayersPanelItem extends lit_1.LitElement { constructor() { super(...arguments); this.depth = 0; this.selected = false; this.highlighted = false; this.hasChildren = false; this.renderOverlayContent = () => { return (0, lit_1.html) ` <sp-popover @sp-opened=${(event) => { if (event.target !== event.currentTarget) { return; } if (!this.api.getAppState().propertiesOpened.includes(this.node.id)) { this.api.setAppState({ propertiesOpened: [ ...this.api.getAppState().propertiesOpened, this.node.id, ], }); } }} @sp-closed=${(event) => { if (event.target !== event.currentTarget) { return; } this.api.setAppState({ propertiesOpened: this.api .getAppState() .propertiesOpened.filter((id) => id !== this.node.id), }); }} > <h4>${(0, localize_1.msg)((0, localize_1.str) `Properties`)}</h4> <ic-spectrum-properties-panel-content .node=${this.node} ></ic-spectrum-properties-panel-content> </sp-popover> `; }; } handleToggleExpand(e) { e.stopPropagation(); const { layersExpanded } = this.api.getAppState(); const isExpanded = layersExpanded.includes(this.node.id); if (isExpanded) { this.api.setAppState({ layersExpanded: layersExpanded.filter((id) => id !== this.node.id), }); } else { this.api.setAppState({ layersExpanded: [...layersExpanded, this.node.id], }); } } handleToggleVisibility() { const isVisible = this.node.visibility !== 'hidden'; this.api.updateNode(this.node, { visibility: isVisible ? 'hidden' : 'visible', }); this.api.record(); } handleToggleLocked() { const isLocked = !!this.node.locked; this.api.updateNode(this.node, { locked: !isLocked, }); this.api.record(); } render() { const isVisible = this.node.visibility !== 'hidden'; const isLocked = !!this.node.locked; const isOpen = this.api .getAppState() .propertiesOpened.includes(this.node.id); const isExpanded = this.api .getAppState() .layersExpanded.includes(this.node.id); const showProperties = this.selected && !this.appState.taskbarSelected.includes(ecs_1.Task.SHOW_PROPERTIES_PANEL); return (0, lit_1.html) ` <sp-action-button quiet size="s" @click=${this.handleToggleVisibility}> ${(0, when_js_1.when)(isVisible, () => (0, lit_1.html) `<sp-icon-visibility slot="icon"></sp-icon-visibility>`, () => (0, lit_1.html) `<sp-icon-visibility-off slot="icon" ></sp-icon-visibility-off>`)} <sp-tooltip self-managed placement="bottom"> ${isVisible ? (0, localize_1.msg)((0, localize_1.str) `Hide layer`) : (0, localize_1.msg)((0, localize_1.str) `Show layer`)} </sp-tooltip> </sp-action-button> <sp-action-button quiet size="s" @click=${this.handleToggleLocked}> ${(0, when_js_1.when)(isLocked, () => (0, lit_1.html) `<sp-icon-lock-closed slot="icon"></sp-icon-lock-closed>`, () => (0, lit_1.html) `<sp-icon-lock-open slot="icon" ></sp-icon-lock-open>`)} <sp-tooltip self-managed placement="bottom"> ${isLocked ? (0, localize_1.msg)((0, localize_1.str) `Unlock layer`) : (0, localize_1.msg)((0, localize_1.str) `Lock layer`)} </sp-tooltip> </sp-action-button> <span style="padding-left: calc(24px * ${this.depth});"></span> <ic-spectrum-layer-thumbnail .node=${this.node} ?selected=${this.selected} ></ic-spectrum-layer-thumbnail> <ic-spectrum-layer-name .node=${this.node}></ic-spectrum-layer-name> <div class="layer-actions" style="visibility: ${showProperties ? 'visible' : 'hidden'};"> <sp-action-button quiet size="m" .selected=${isOpen} ${(0, overlay_1.trigger)(this.renderOverlayContent, { open: isOpen, triggerInteraction: 'click', overlayOptions: { placement: 'bottom', offset: 6, }, })}> <sp-icon-properties slot="icon"></sp-icon-properties> <sp-tooltip self-managed placement="bottom"> ${(0, localize_1.msg)((0, localize_1.str) `Layer properties`)}</sp-tooltip > </sp-action-button> </div> <span> ${(0, when_js_1.when)(this.hasChildren, () => (0, lit_1.html) ` <sp-action-button quiet size="s" @click=${this.handleToggleExpand}> ${(0, when_js_1.when)(isExpanded, () => (0, lit_1.html) `<sp-icon-chevron-down slot="icon"></sp-icon-chevron-down>`, () => (0, lit_1.html) `<sp-icon-chevron-right slot="icon" ></sp-icon-chevron-right>`)} <sp-tooltip self-managed placement="left"> ${isExpanded ? (0, localize_1.msg)((0, localize_1.str) `Collapse`) : (0, localize_1.msg)((0, localize_1.str) `Expand`)} </sp-tooltip> </sp-action-button> `, () => (0, lit_1.html) ``)} </span> </span>`; } }; exports.LayersPanelItem = LayersPanelItem; LayersPanelItem.styles = (0, lit_1.css) ` :host { width: 320px; height: 64px; display: flex; align-items: center; gap: 4px; padding: 0 4px; cursor: pointer; } :host > span { display: flex; align-items: center; justify-content: space-between; gap: 8px; } ic-spectrum-layer-name { flex: 1; } :host([selected]) { background: var(--spectrum-blue-100); } :host(:not([selected]):not([disabled]):hover) { background-color: var( --spectrum-treeview-item-background-color-hover, var(--spectrum-alias-background-color-hover-overlay) ); } :host([highlighted]) { background-color: var( --spectrum-treeview-item-background-color-hover, var(--spectrum-alias-background-color-hover-overlay) ); } h4 { padding: var(--spectrum-global-dimension-size-100); display: flex; align-items: center; justify-content: space-between; margin: 0; } `; __decorate([ (0, decorators_js_1.property)() ], LayersPanelItem.prototype, "node", void 0); __decorate([ (0, decorators_js_1.property)({ type: Number }) ], LayersPanelItem.prototype, "depth", void 0); __decorate([ (0, decorators_js_1.property)({ type: Boolean }) ], LayersPanelItem.prototype, "selected", void 0); __decorate([ (0, decorators_js_1.property)({ type: Boolean }) ], LayersPanelItem.prototype, "highlighted", void 0); __decorate([ (0, decorators_js_1.property)({ type: Boolean }) ], LayersPanelItem.prototype, "hasChildren", void 0); __decorate([ (0, context_1.consume)({ context: context_2.apiContext, subscribe: true }) ], LayersPanelItem.prototype, "api", void 0); __decorate([ (0, context_1.consume)({ context: context_2.appStateContext, subscribe: true }) ], LayersPanelItem.prototype, "appState", void 0); exports.LayersPanelItem = LayersPanelItem = __decorate([ (0, decorators_js_1.customElement)('ic-spectrum-layers-panel-item'), (0, localize_1.localized)() ], LayersPanelItem); //# sourceMappingURL=layers-panel-item.js.map