mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 11:36:25 +08:00
feat(editor): edgeless clipboard config extension (#11168)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import type { RootContentMap } from 'hast';
|
||||
|
||||
type HastUnionType<
|
||||
K extends keyof RootContentMap,
|
||||
V extends RootContentMap[K],
|
||||
> = V;
|
||||
|
||||
export function onlyContainImgElement(
|
||||
ast: HastUnionType<keyof RootContentMap, RootContentMap[keyof RootContentMap]>
|
||||
): 'yes' | 'no' | 'maybe' {
|
||||
if (ast.type === 'element') {
|
||||
switch (ast.tagName) {
|
||||
case 'html':
|
||||
case 'body':
|
||||
return ast.children.map(onlyContainImgElement).reduce((a, b) => {
|
||||
if (a === 'no' || b === 'no') {
|
||||
return 'no';
|
||||
}
|
||||
if (a === 'maybe' && b === 'maybe') {
|
||||
return 'maybe';
|
||||
}
|
||||
return 'yes';
|
||||
}, 'maybe');
|
||||
case 'img':
|
||||
return 'yes';
|
||||
case 'head':
|
||||
return 'maybe';
|
||||
default:
|
||||
return 'no';
|
||||
}
|
||||
}
|
||||
return 'maybe';
|
||||
}
|
||||
Reference in New Issue
Block a user