UNPKG

@shopnex/ai-plugin

Version:

<p align="center"> <img alt="Payload AI Plugin" src="assets/payload-ai-intro.gif" width="100%" /> </p>

22 lines (21 loc) 1.15 kB
import { getFieldInfo } from '../../utilities/getFieldInfo'; import { lexicalToHTML } from '../../utilities/lexicalToHTML'; import { asyncHandlebars } from './asyncHandlebars'; import { handlebarsHelpersMap } from './helpersMap'; export const registerEditorHelper = (payload, schemaPath)=>{ //TODO: add autocomplete ability using handlebars template on PromptEditorField and include custom helpers in dropdown let fieldInfo = getFieldInfo(payload.collections, schemaPath); const schemaPathChunks = schemaPath.split('.'); asyncHandlebars.registerHelper(handlebarsHelpersMap.toHTML.name, async function(content, options) { const collectionSlug = schemaPathChunks[0]; const { ids } = options; for (const id of ids){ //TODO: Find a better way to get schemaPath of defined field in prompt editor const path = `${collectionSlug}.${id}`; fieldInfo = getFieldInfo(payload.collections, path); } const html = await lexicalToHTML(content, fieldInfo.editor?.editorConfig); return new asyncHandlebars.SafeString(html); }); }; //# sourceMappingURL=helpers.js.map