refactor(editor): edgeless note toolbar config extension (#10719)

This commit is contained in:
fundon
2025-03-19 12:34:18 +00:00
parent b5406fa57a
commit e320552594
30 changed files with 1486 additions and 59 deletions
@@ -20,7 +20,7 @@ type ActionBase = {
export type ToolbarAction = ActionBase & {
label?: string;
icon?: TemplateResult;
tooltip?: string;
tooltip?: string | TemplateResult;
variant?: 'destructive';
disabled?: ((cx: ToolbarContext) => boolean) | boolean;
content?:
@@ -56,6 +56,10 @@ abstract class ToolbarContextBase {
return this.std.store;
}
get history() {
return this.store.history;
}
get view() {
return this.std.view;
}
@@ -25,14 +25,14 @@ export function ToolbarModuleExtension(module: ToolbarModule): ExtensionType {
export class ToolbarRegistryExtension extends Extension {
flavour$ = signal<string>('affine:note');
elementsMap$ = signal<Map<string, GfxModel[]>>(new Map());
message$ = signal<{
flavour: string;
element: Element;
setFloating: (element?: Element) => void;
} | null>(null);
elementsMap$ = signal<Map<string, GfxModel[]>>(new Map());
flags = new Flags();
constructor(readonly std: BlockStdScope) {
@@ -0,0 +1,23 @@
import groupBy from 'lodash-es/groupBy';
import maxBy from 'lodash-es/maxBy';
export function getMostCommonValue<T, F extends keyof T>(
records: T[],
field: F
) {
const grouped = groupBy(records, record => record[field]);
const values = Object.values(grouped);
const record = maxBy(values, records => records.length)?.[0];
return record?.[field];
}
export function getMostCommonResolvedValue<
T,
F extends Exclude<keyof T, symbol>,
U,
>(records: T[], field: F, resolve: (value: T[F]) => U) {
return getMostCommonValue(
records.map(record => ({ [field]: resolve(record[field]) })),
field
);
}
+1 -15
View File
@@ -359,18 +359,4 @@ export const createKeydownObserver = ({
target.addEventListener('compositionend', () => onInput?.(true), { signal });
};
export class ColorEvent extends Event {
detail: Palette;
constructor(
type: string,
{
detail,
composed,
bubbles,
}: { detail: Palette; composed: boolean; bubbles: boolean }
) {
super(type, { bubbles, composed });
this.detail = detail;
}
}
export class ColorEvent extends CustomEvent<Palette> {}
@@ -1,6 +1,7 @@
export * from './auto-scroll';
export * from './button-popper';
export * from './collapsed';
export * from './computing';
export * from './dnd';
export * from './dom';
export * from './drag-helper';