import { type ToolbarAction, ToolbarContext, } from '@blocksuite/affine-shared/services'; import { PropTypes, requiredProperties } from '@blocksuite/block-std'; import { SignalWatcher } from '@blocksuite/global/lit'; import { ArrowDownSmallIcon } from '@blocksuite/icons/lit'; import type { ReadonlySignal, Signal } from '@preact/signals-core'; import { LitElement } from 'lit'; import { property } from 'lit/decorators.js'; import { html } from 'lit-html'; import { ifDefined } from 'lit-html/directives/if-defined.js'; import { repeat } from 'lit-html/directives/repeat.js'; @requiredProperties({ actions: PropTypes.array, context: PropTypes.instanceOf(ToolbarContext), viewType$: PropTypes.object, }) export class ViewDropdownMenu extends SignalWatcher(LitElement) { @property({ attribute: false }) accessor actions!: ToolbarAction[]; @property({ attribute: false }) accessor context!: ToolbarContext; @property({ attribute: false }) accessor viewType$!: Signal | ReadonlySignal; override render() { const { actions, context, viewType$: { value: viewType }, } = this; return html` ${viewType} ${ArrowDownSmallIcon()} `} >
${repeat( actions.filter(action => { if (typeof action.when === 'function') return action.when(context); return action.when ?? true; }), action => action.id, ({ id, label, disabled, run }) => html` run?.(context)} > ${label} ` )}
`; } } declare global { interface HTMLElementTagNameMap { 'affine-view-dropdown-menu': ViewDropdownMenu; } }