mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-12-15 05:36:31 +00:00
22 lines
644 B
TypeScript
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;
|
|
},
|
|
});
|