mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 21:38:44 +08:00
refactor(editor): edgeless note toolbar config extension (#10719)
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user