@molecule/app-layer-panel-angular
Angular Photoshop / Figma–style reorderable layer panel.
Exports:
<LayerPanel> (ul[mol-layer-panel]) — the panel component
(drag-to-reorder via pointer events, visibility / lock toggles,
double-click inline rename, click-to-select, optional thumbnail +
opacity + blend-mode metadata).
- Types:
LayerPanelProps, Layer, LayerBlendMode.
- Helpers:
moveLayer(), formatOpacityPercent().
It is the Angular counterpart of @molecule/app-layer-panel-react: the same
props (React names), the same ClassMap tokens and the same DOM for the same
input. The host element IS React's root <ul>, so an app places it on a
<ul> in its template.
The panel is fully controlled — the host application owns the Layer[]
array and re-renders with the next state in response to the onReorder /
onVisibilityToggle / onLockToggle / onSelect / onRename inputs.
Layers are rendered top-down per Photoshop convention: index 0 is the first
row in the UI and represents the front-most layer.
Toggle/rename labels route through t() — add the companion
@molecule/app-locales-layer-panel bond to translate them. Locked layers
cannot be dragged or renamed. The eye / lock toggles render emoji glyphs.
Auto-generated, AI-first package reference for the molecule.dev ecosystem.
It is written to be read by coding agents as much as by people, and is generated from this
package's source — edit src/index.ts JSDoc, not this file.
Quick Start
import { Component, signal } from '@angular/core'
import { LayerPanel, type Layer } from '@molecule/app-layer-panel-angular'
@Component({
selector: 'app-editor',
standalone: true,
imports: [LayerPanel],
template: `
<ul
mol-layer-panel
[layers]="layers()"
[activeId]="activeId()"
[onReorder]="setLayers"
[onVisibilityToggle]="toggleVisibility"
[onLockToggle]="toggleLock"
[onSelect]="select"
[onRename]="rename"
></ul>
`,
})
export class Editor {
readonly layers = signal<Layer[]>([
{ id: 'bg', name: 'Background', visible: true, locked: false },
{ id: 'fg', name: 'Sketch', visible: true, locked: false, opacity: 0.8 },
])
readonly activeId = signal<string | undefined>(undefined)
readonly setLayers = (next: Layer[]): void => this.layers.set(next)
readonly select = (id: string): void => this.activeId.set(id)
readonly rename = (id: string, name: string): void => {
this.layers.update((ls) => ls.map((l) => (l.id === id ? { ...l, name } : l)))
}
private patch(id: string, next: Partial<Layer>): void {
this.layers.update((ls) => ls.map((l) => (l.id === id ? { ...l, ...next } : l)))
}
readonly toggleVisibility = (id: string): void => {
this.patch(id, { visible: !this.layers().find((l) => l.id === id)?.visible })
}
readonly toggleLock = (id: string): void => {
this.patch(id, { locked: !this.layers().find((l) => l.id === id)?.locked })
}
}
Type
feature
Installation
npm install @molecule/app-layer-panel-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-i18n @molecule/app-ui @molecule/app-ui-angular
API
Interfaces
Layer
A single editable layer in the stack. The host application owns the
data — <LayerPanel> is a controlled view that emits intent callbacks
(onReorder, onVisibilityToggle, onLockToggle, onSelect,
onRename) and never mutates anything itself.
interface Layer {
/** Stable id used as the list key and as the value passed to callbacks. */
id: string
/** Human-readable name shown in the row and edited via inline rename. */
name: string
/** When `false` the layer renders dimmed with a slashed-eye icon. */
visible: boolean
/** When `true` interactive controls (rename, drag) are disabled. */
locked: boolean
/** Optional 0–1 alpha shown as a percentage in the row metadata. */
opacity?: number
/** Optional blend mode shown as text in the row's metadata badge. */
blendMode?: LayerBlendMode
/**
* Optional thumbnail data URL or remote URL displayed left of the
* layer name. Apps without thumbnails should omit this.
*/
thumbnail?: string
}
LayerPanelProps
Props accepted by {@link LayerPanel} — the same props React's LayerPanel accepts.
interface LayerPanelProps {
/**
* Ordered layers, **top-down** (index 0 renders as the first row and
* represents the top-most layer in Photoshop terms).
*/
layers: Layer[]
/** Called with the full reordered list after a drag completes. */
onReorder: (next: Layer[]) => void
/** Called when the eye icon is clicked. */
onVisibilityToggle: (id: string) => void
/** Called when the lock icon is clicked. */
onLockToggle: (id: string) => void
/** Called when a row's name button is clicked. */
onSelect: (id: string) => void
/** Called when an inline rename commits with a non-empty trimmed value. */
onRename: (id: string, name: string) => void
/**
* Currently active layer id — drives the row's "selected" highlight and
* `aria-current="true"` on its select (layer-name) button. Optional; when
* omitted no row is highlighted.
*/
activeId?: string
/** Optional extra classes appended to the panel root. */
className?: string
}
Types
LayerBlendMode
Photoshop/Figma-style blend mode. The set mirrors the CSS
mix-blend-mode keywords so apps can pass the value straight through
to a canvas/DOM renderer if they want.
type LayerBlendMode =
| 'normal'
| 'multiply'
| 'screen'
| 'overlay'
| 'darken'
| 'lighten'
| 'color-dodge'
| 'color-burn'
| 'hard-light'
| 'soft-light'
| 'difference'
| 'exclusion'
| 'hue'
| 'saturation'
| 'color'
| 'luminosity'
Classes
LayerPanel
LayerPanel component.
Photoshop / Figma–style layer panel: a vertical, drag-to-reorder list of
layers with eye/lock toggles, inline rename (double-click), and
click-to-select. All interactions emit intent callbacks; the host
application owns the data and re-renders with the next layers array.
It is the Angular counterpart of @molecule/app-layer-panel-react's
LayerPanel: the same props (React names), the same ClassMap tokens and the
same DOM for the same input. The host IS the outer <ul>
(ul[mol-layer-panel]), matching React's root exactly.
Drag-to-reorder uses pointer events (no @dnd-kit or HTML5 DnD
dependency), so it works on touch surfaces and inside transformed canvases
without quirks. The visual convention is top-down — index 0 is the
front-most layer.
@Component({
selector: 'ul[mol-layer-panel]',
standalone: true,
inputs: [
'layers',
'onReorder',
'onVisibilityToggle',
'onLockToggle',
'onSelect',
'onRename',
'activeId',
'className',
],
host: {
'data-mol-id': 'layer-panel',
'[attr.aria-label]': 'label()',
'[class]': 'classes()',
},
template: `@for (layer of layers; track layer.id; let index = $index) {
<li
[attr.data-mol-id]="'layer-panel-row-' + layer.id"
[attr.data-layer-index]="index"
(pointerdown)="onRowPointerDown(index, layer, $event)"
(pointermove)="onRowPointerMove($event)"
(pointerup)="endDrag()"
(pointercancel)="endDrag()"
[class]="rowClasses()"
[style]="rowStyle(layer, index)"
>
<button
type="button"
(click)="toggleVisibility(layer)"
[attr.aria-label]="visibilityLabel(layer)"
[attr.title]="visibilityLabel(layer)"
[attr.aria-pressed]="!layer.visible"
[attr.data-mol-id]="'layer-panel-visibility-' + layer.id"
[class]="toggleClasses()"
[style]="toggleStyle"
>
<span aria-hidden="true">{{ layer.visible ? eyeVisible : eyeHidden }}</span>
</button>
<button
type="button"
(click)="toggleLock(layer)"
[attr.aria-label]="lockLabel(layer)"
[attr.title]="lockLabel(layer)"
[attr.aria-pressed]="layer.locked"
[attr.data-mol-id]="'layer-panel-lock-' + layer.id"
[class]="toggleClasses()"
[style]="toggleStyle"
>
<span aria-hidden="true">{{ layer.locked ? lockLocked : lockUnlocked }}</span>
</button>
@if (layer.thumbnail) {
<img [attr.src]="layer.thumbnail" alt="" aria-hidden="true" [style]="thumbnailStyle" />
}
<div [class]="nameSlotClasses()" (dblclick)="onNameSlotDoubleClick(layer, $event)">
@if (isEditing(layer)) {
<input
type="text"
[attr.value]="layer.name"
(input)="onRenameInput($event)"
(focusout)="commitRename(layer)"
(keydown)="onRenameKeyDown($event, layer)"
(pointerdown)="onRenamePointerDown($event)"
[attr.aria-label]="renameLabel()"
[attr.data-mol-id]="'layer-panel-rename-' + layer.id"
[style]="renameFieldStyle"
/>
} @else {
<button
type="button"
(click)="select(layer)"
[attr.aria-current]="isActive(layer) ? 'true' : null"
[attr.data-mol-id]="'layer-panel-name-' + layer.id"
[class]="nameClasses()"
[style]="nameStyle"
>
{{ layer.name }}
</button>
}
</div>
@if (layer.blendMode || opacityLabel(layer)) {
<span
[attr.aria-label]="metadataLabel()"
[attr.data-mol-id]="'layer-panel-meta-' + layer.id"
[style]="metadataStyle"
>{{ metaText(layer) }}</span
>
}
</li>
}`,
})
export class LayerPanel {
layers: Layer[] = []
onReorder?: LayerPanelProps['onReorder']
onVisibilityToggle?: LayerPanelProps['onVisibilityToggle']
onLockToggle?: LayerPanelProps['onLockToggle']
onSelect?: LayerPanelProps['onSelect']
onRename?: LayerPanelProps['onRename']
activeId?: string
className?: string
protected readonly draggingId = signal<string | null>(null)
protected readonly overIndex = signal<number | null>(null)
protected readonly editingId = signal<string | null>(null)
private editingValue = ''
private dragStartIndex: number | null = null
private readonly host = inject(ElementRef<HTMLElement>)
private readonly injector = inject(Injector)
private readonly i18n = useTranslation()
protected readonly eyeVisible = '\u{1F441}'
protected readonly eyeHidden = '\u{1F441}\u{0338}'
protected readonly lockLocked = '\u{1F512}'
protected readonly lockUnlocked = '\u{1F513}'
protected readonly toggleStyle: Record<string, string> = {
background: 'transparent',
border: 'none',
padding: '0',
}
protected readonly nameStyle: Record<string, string> = {
width: '100%',
background: 'transparent',
border: 'none',
padding: '0',
font: 'inherit',
color: 'inherit',
'text-align': 'left',
}
protected readonly thumbnailStyle: Record<string, string> = {
width: '24px',
height: '24px',
'object-fit': 'cover',
'flex-shrink': '0',
}
protected readonly renameFieldStyle: Record<string, string> = { width: '100%' }
protected readonly metadataStyle: Record<string, string> = {
'font-size': '0.75em',
opacity: '0.7',
}
cm(): UIClassMap {
return getClassMap()
}
classes(): string {
return this.cm().cn(this.cm().stack(0 as const), this.className)
}
rowClasses(): string {
return this.cm().cn(this.cm().flex({ align: 'center', gap: 'sm' }), this.cm().cursorPointer)
}
toggleClasses(): string {
return this.cm().cn(this.cm().cursorPointer, this.cm().touchTarget)
}
nameSlotClasses(): string {
return this.cm().flex1
}
nameClasses(): string {
return this.cm().cn(this.cm().cursorPointer)
}
rowStyle(layer: Layer, index: number): Record<string, string | number> {
const isDragging = layer.id === this.draggingId()
const isOver =
this.overIndex() === index && this.draggingId() !== null && this.draggingId() !== layer.id
const style: Record<string, string | number> = {
opacity: isDragging ? 0.4 : layer.visible ? 1 : 0.55,
padding: '4px 8px',
}
if (isOver) style['border-top'] = '2px solid currentColor'
if (this.isActive(layer)) style.outline = '2px solid currentColor'
return style
}
isActive(layer: Layer): boolean {
return layer.id === this.activeId
}
isEditing(layer: Layer): boolean {
return this.editingId() === layer.id
}
label(): string {
return this.i18n.t('layerPanel.label', {}, { defaultValue: 'Layers' })
}
renameLabel(): string {
return this.i18n.t('layerPanel.renameInput', {}, { defaultValue: 'Rename layer' })
}
metadataLabel(): string {
return this.i18n.t('layerPanel.metadata', {}, { defaultValue: 'Layer metadata' })
}
visibilityLabel(layer: Layer): string {
return layer.visible
? this.i18n.t('layerPanel.hide', {}, { defaultValue: 'Hide layer' })
: this.i18n.t('layerPanel.show', {}, { defaultValue: 'Show layer' })
}
lockLabel(layer: Layer): string {
return layer.locked
? this.i18n.t('layerPanel.unlock', {}, { defaultValue: 'Unlock layer' })
: this.i18n.t('layerPanel.lock', {}, { defaultValue: 'Lock layer' })
}
opacityLabel(layer: Layer): string {
return formatOpacityPercent(layer.opacity)
}
metaText(layer: Layer): string {
const opacityLabel = this.opacityLabel(layer)
return `${layer.blendMode ?? ''}${layer.blendMode && opacityLabel ? ' · ' : ''}${opacityLabel}`
}
onRowPointerDown(index: number, layer: Layer, event: PointerEvent): void {
if (event.button !== 0) return
if (layer.locked) return
this.dragStartIndex = index
this.draggingId.set(layer.id)
this.overIndex.set(index)
;(event.currentTarget as HTMLElement | null)?.setPointerCapture(event.pointerId)
}
onRowPointerMove(event: PointerEvent): void {
if (this.draggingId() === null) return
const target = document.elementFromPoint(event.clientX, event.clientY)
if (!target) return
const row = target.closest('[data-mol-id^="layer-panel-row-"]') as HTMLElement | null
if (!row) return
const idx = Number(row.dataset.layerIndex)
if (Number.isFinite(idx)) this.overIndex.set(idx)
}
// … truncated — 11 more members: endDrag, startRename, onNameSlotDoubleClick, onRenamePointerDown, commitRename, cancelRename, onRenameInput, onRenameKeyDown, toggleVisibility, toggleLock, select; the full declaration is in node_modules/@molecule/app-layer-panel-angular/dist/layer-panel.component.d.ts
_(Member comments are left out to fit; the full declaration is in node_modules/@molecule/app-layer-panel-angular/dist/layer-panel.component.d.ts.)_
Functions
moveLayer(layers, fromIndex, toIndex)
Move a layer from one index to another inside the panel array, returning a
fresh array. The display convention is top-down (index 0 is the
top-most layer in Photoshop terms — the front-most), so callers don't
have to reverse anything.
Out-of-range indices are clamped to [0, layers.length - 1]. If the
source and destination resolve to the same index the original array
is returned unchanged (referential equality preserved).
function moveLayer(layers: readonly Layer[], fromIndex: number, toIndex: number): Layer[]
layers — Current ordered layers (top-down).
fromIndex — Index of the layer being moved.
toIndex — Destination index after the move.
Returns: A new array reflecting the reordered layers, or the original reference if the move is a no-op.
formatOpacityPercent(opacity)
Format an opacity value (0..1) as a Photoshop-style integer
percent string ("100%"). Returns an empty string when opacity is
undefined so callers can render "no metadata" rows naturally.
Values outside [0, 1] are clamped, fractional results are rounded
to the nearest integer.
function formatOpacityPercent(opacity: number | undefined): string
opacity — The 0–1 opacity, or undefined.
Returns: A locale-agnostic "NN%" string, or "" when opacity is undefined.
Injection Notes
Requirements
Peer dependencies: