UNPKG

@infinite-canvas-tutorial/webcomponents

Version:
228 lines (220 loc) 8.22 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 { html, css, LitElement } from 'lit'; import { customElement, property } from 'lit/decorators.js'; import { when } from 'lit/directives/when.js'; import { consume } from '@lit/context'; import { Task, } from '@infinite-canvas-tutorial/ecs'; import { trigger, } from '@spectrum-web-components/overlay'; import { apiContext, appStateContext } from '../context'; import { msg, str, localized } from '@lit/localize'; let LayersPanelItem = class LayersPanelItem extends LitElement { constructor() { super(...arguments); this.depth = 0; this.selected = false; this.highlighted = false; this.hasChildren = false; this.renderOverlayContent = () => { return 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>${msg(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(Task.SHOW_PROPERTIES_PANEL); return html ` <sp-action-button quiet size="s" @click=${this.handleToggleVisibility}> ${when(isVisible, () => html `<sp-icon-visibility slot="icon"></sp-icon-visibility>`, () => html `<sp-icon-visibility-off slot="icon" ></sp-icon-visibility-off>`)} <sp-tooltip self-managed placement="bottom"> ${isVisible ? msg(str `Hide layer`) : msg(str `Show layer`)} </sp-tooltip> </sp-action-button> <sp-action-button quiet size="s" @click=${this.handleToggleLocked}> ${when(isLocked, () => html `<sp-icon-lock-closed slot="icon"></sp-icon-lock-closed>`, () => html `<sp-icon-lock-open slot="icon" ></sp-icon-lock-open>`)} <sp-tooltip self-managed placement="bottom"> ${isLocked ? msg(str `Unlock layer`) : msg(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} ${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"> ${msg(str `Layer properties`)}</sp-tooltip > </sp-action-button> </div> <span> ${when(this.hasChildren, () => html ` <sp-action-button quiet size="s" @click=${this.handleToggleExpand}> ${when(isExpanded, () => html `<sp-icon-chevron-down slot="icon"></sp-icon-chevron-down>`, () => html `<sp-icon-chevron-right slot="icon" ></sp-icon-chevron-right>`)} <sp-tooltip self-managed placement="left"> ${isExpanded ? msg(str `Collapse`) : msg(str `Expand`)} </sp-tooltip> </sp-action-button> `, () => html ``)} </span> </span>`; } }; LayersPanelItem.styles = 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([ property() ], LayersPanelItem.prototype, "node", void 0); __decorate([ property({ type: Number }) ], LayersPanelItem.prototype, "depth", void 0); __decorate([ property({ type: Boolean }) ], LayersPanelItem.prototype, "selected", void 0); __decorate([ property({ type: Boolean }) ], LayersPanelItem.prototype, "highlighted", void 0); __decorate([ property({ type: Boolean }) ], LayersPanelItem.prototype, "hasChildren", void 0); __decorate([ consume({ context: apiContext, subscribe: true }) ], LayersPanelItem.prototype, "api", void 0); __decorate([ consume({ context: appStateContext, subscribe: true }) ], LayersPanelItem.prototype, "appState", void 0); LayersPanelItem = __decorate([ customElement('ic-spectrum-layers-panel-item'), localized() ], LayersPanelItem); export { LayersPanelItem }; //# sourceMappingURL=layers-panel-item.js.map