2023-04-10 15:16:32 +08:00

22 lines
644 B
TypeScript

import { isEmpty } from 'lodash-es';
import { CodeBlockContent, HookType, Id } from '@tmagic/schema';
import { Target } from '@editor/services/dep';
import type { HookData } from '@editor/type';
export const createCodeBlockTarget = (id: Id, codeBlock: CodeBlockContent) =>
new Target({
type: 'code-block',
id,
name: codeBlock.name,
isTarget: (key: string | number, value: any) => {
if (value?.hookType === HookType.CODE && !isEmpty(value.hookData)) {
const index = value.hookData.findIndex((item: HookData) => item.codeId === id);
return Boolean(index > -1);
}
return false;
},
});