@ai-stack/payloadcms 3.76.0-beta.1 → 3.76.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/core/generateObject.js +1 -4
- package/dist/ai/core/generateObject.js.map +1 -1
- package/dist/ai/core/generateText.js +1 -5
- package/dist/ai/core/generateText.js.map +1 -1
- package/dist/ai/core/media/generateMedia.js +1 -4
- package/dist/ai/core/media/generateMedia.js.map +1 -1
- package/dist/ai/core/media/image/generateImage.js +4 -14
- package/dist/ai/core/media/image/generateImage.js.map +1 -1
- package/dist/ai/core/media/image/handlers/multimodal.js +7 -24
- package/dist/ai/core/media/image/handlers/multimodal.js.map +1 -1
- package/dist/ai/core/media/image/handlers/standard.js +7 -2
- package/dist/ai/core/media/image/handlers/standard.js.map +1 -1
- package/dist/ai/core/media/speech/generateSpeech.js +2 -3
- package/dist/ai/core/media/speech/generateSpeech.js.map +1 -1
- package/dist/ai/core/media/types.d.ts +2 -3
- package/dist/ai/core/media/types.js.map +1 -1
- package/dist/ai/core/streamObject.js +0 -3
- package/dist/ai/core/streamObject.js.map +1 -1
- package/dist/ai/core/streamText.js +1 -4
- package/dist/ai/core/streamText.js.map +1 -1
- package/dist/ai/core/types.d.ts +2 -2
- package/dist/ai/core/types.js.map +1 -1
- package/dist/ai/providers/blocks/anthropic.js +2 -44
- package/dist/ai/providers/blocks/anthropic.js.map +1 -1
- package/dist/ai/providers/blocks/elevenlabs.js +4 -109
- package/dist/ai/providers/blocks/elevenlabs.js.map +1 -1
- package/dist/ai/providers/blocks/fal.js +2 -120
- package/dist/ai/providers/blocks/fal.js.map +1 -1
- package/dist/ai/providers/blocks/google.js +6 -240
- package/dist/ai/providers/blocks/google.js.map +1 -1
- package/dist/ai/providers/blocks/openai-compatible.js +2 -146
- package/dist/ai/providers/blocks/openai-compatible.js.map +1 -1
- package/dist/ai/providers/blocks/openai.js +2 -202
- package/dist/ai/providers/blocks/openai.js.map +1 -1
- package/dist/ai/providers/blocks/xai.js +2 -55
- package/dist/ai/providers/blocks/xai.js.map +1 -1
- package/dist/ai/providers/index.d.ts +1 -1
- package/dist/ai/providers/index.js +0 -2
- package/dist/ai/providers/index.js.map +1 -1
- package/dist/ai/providers/registry.d.ts +24 -28
- package/dist/ai/providers/registry.js +184 -138
- package/dist/ai/providers/registry.js.map +1 -1
- package/dist/ai/providers/types.d.ts +12 -33
- package/dist/ai/providers/types.js +0 -1
- package/dist/ai/providers/types.js.map +1 -1
- package/dist/ai/schemas/lexicalJsonSchema.js +1 -1
- package/dist/ai/schemas/lexicalJsonSchema.js.map +1 -1
- package/dist/ai/utilities/filterEditorSchemaByNodes.js.map +1 -0
- package/dist/ai/utilities/generateFileNameByPrompt.js.map +1 -0
- package/dist/ai/utilities/isObjectSchema.js.map +1 -0
- package/dist/ai/{utils → utilities}/nodeToSchemaMap.js +6 -6
- package/dist/ai/utilities/nodeToSchemaMap.js.map +1 -0
- package/dist/ai/{prompts.d.ts → utilities/prompts.d.ts} +1 -1
- package/dist/ai/utilities/prompts.js.map +1 -0
- package/dist/ai/utilities/systemGenerate.js.map +1 -0
- package/dist/collections/AIJobs.js +3 -12
- package/dist/collections/AIJobs.js.map +1 -1
- package/dist/collections/AIProviders.js +56 -29
- package/dist/collections/AIProviders.js.map +1 -1
- package/dist/collections/Instructions.js +91 -59
- package/dist/collections/Instructions.js.map +1 -1
- package/dist/collections/shared.d.ts +30 -0
- package/dist/collections/shared.js +15 -0
- package/dist/collections/shared.js.map +1 -0
- package/dist/endpoints/fetchFields.js +14 -6
- package/dist/endpoints/fetchFields.js.map +1 -1
- package/dist/endpoints/fetchVoices.js +1 -1
- package/dist/endpoints/fetchVoices.js.map +1 -1
- package/dist/endpoints/generate.d.ts +7 -0
- package/dist/endpoints/generate.js +268 -0
- package/dist/endpoints/generate.js.map +1 -0
- package/dist/endpoints/index.js +9 -639
- package/dist/endpoints/index.js.map +1 -1
- package/dist/endpoints/promptMentions.d.ts +2 -0
- package/dist/endpoints/promptMentions.js +166 -0
- package/dist/endpoints/promptMentions.js.map +1 -0
- package/dist/endpoints/upload.d.ts +7 -0
- package/dist/endpoints/upload.js +294 -0
- package/dist/endpoints/upload.js.map +1 -0
- package/dist/endpoints/videogenWebhook.d.ts +7 -0
- package/dist/endpoints/videogenWebhook.js +132 -0
- package/dist/endpoints/videogenWebhook.js.map +1 -0
- package/dist/exports/client.d.ts +2 -1
- package/dist/exports/client.js +2 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/fields.d.ts +2 -1
- package/dist/exports/fields.js +2 -1
- package/dist/exports/fields.js.map +1 -1
- package/dist/fields/ArrayComposeField/ArrayComposeField.js +1 -1
- package/dist/fields/ArrayComposeField/ArrayComposeField.js.map +1 -1
- package/dist/fields/ArrayComposeField/ArrayComposeField.jsx +1 -1
- package/dist/fields/ComposeField/ComposeField.d.ts +1 -0
- package/dist/fields/ComposeField/ComposeField.js +18 -8
- package/dist/fields/ComposeField/ComposeField.js.map +1 -1
- package/dist/fields/ComposeField/ComposeField.jsx +12 -7
- package/dist/fields/LexicalEditor/feature.server.js +1 -1
- package/dist/fields/LexicalEditor/feature.server.js.map +1 -1
- package/dist/fields/PromptEditorField/feature.client.d.ts +1 -0
- package/dist/fields/PromptEditorField/feature.client.js +173 -0
- package/dist/fields/PromptEditorField/feature.client.js.map +1 -0
- package/dist/fields/PromptEditorField/feature.client.jsx +148 -0
- package/dist/fields/PromptEditorField/feature.server.d.ts +1 -0
- package/dist/fields/PromptEditorField/feature.server.js +30 -0
- package/dist/fields/PromptEditorField/feature.server.js.map +1 -0
- package/dist/fields/PromptField.d.ts +4 -0
- package/dist/fields/PromptField.js +18 -0
- package/dist/fields/PromptField.js.map +1 -0
- package/dist/fields/SelectField/SelectField.js +0 -1
- package/dist/fields/SelectField/SelectField.js.map +1 -1
- package/dist/fields/SelectField/SelectField.jsx +0 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/libraries/handlebars/helpers.js +2 -2
- package/dist/libraries/handlebars/helpers.js.map +1 -1
- package/dist/libraries/handlebars/replacePlaceholders.js +5 -1
- package/dist/libraries/handlebars/replacePlaceholders.js.map +1 -1
- package/dist/payload-ai.d.ts +5 -19
- package/dist/plugin.js +18 -21
- package/dist/plugin.js.map +1 -1
- package/dist/providers/FieldProvider/FieldProvider.js +11 -20
- package/dist/providers/FieldProvider/FieldProvider.js.map +1 -1
- package/dist/providers/FieldProvider/FieldProvider.jsx +8 -18
- package/dist/providers/InstructionsProvider/InstructionsProvider.js +5 -2
- package/dist/providers/InstructionsProvider/InstructionsProvider.js.map +1 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.jsx +5 -2
- package/dist/translations/de.json +47 -0
- package/dist/translations/en.json +45 -2
- package/dist/translations/es.json +45 -2
- package/dist/translations/fa.json +45 -2
- package/dist/translations/fr.json +46 -3
- package/dist/translations/hi.json +47 -0
- package/dist/translations/index.d.ts +88 -26
- package/dist/translations/index.js +18 -32
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/ja.json +47 -0
- package/dist/translations/nb.json +47 -0
- package/dist/translations/nl.json +47 -0
- package/dist/translations/pl.json +45 -2
- package/dist/translations/pt.json +47 -0
- package/dist/translations/ru.json +45 -2
- package/dist/translations/th.json +47 -0
- package/dist/translations/translation-schema.json +184 -11
- package/dist/translations/uk.json +45 -2
- package/dist/translations/zh.json +47 -0
- package/dist/types.d.ts +64 -28
- package/dist/types.js.map +1 -1
- package/dist/ui/Compose/Compose.js +42 -79
- package/dist/ui/Compose/Compose.js.map +1 -1
- package/dist/ui/Compose/Compose.jsx +32 -86
- package/dist/ui/Compose/ComposePlaceholder.js +1 -1
- package/dist/ui/Compose/ComposePlaceholder.js.map +1 -1
- package/dist/ui/Compose/ComposePlaceholder.jsx +1 -1
- package/dist/ui/Compose/{compose.module.css → compose.module.scss} +3 -5
- package/dist/ui/Compose/hooks/menu/Item.d.ts +1 -1
- package/dist/ui/Compose/hooks/menu/Item.js +7 -3
- package/dist/ui/Compose/hooks/menu/Item.js.map +1 -1
- package/dist/ui/Compose/hooks/menu/Item.jsx +11 -5
- package/dist/ui/Compose/hooks/menu/TranslateMenu.js +15 -5
- package/dist/ui/Compose/hooks/menu/TranslateMenu.js.map +1 -1
- package/dist/ui/Compose/hooks/menu/TranslateMenu.jsx +11 -5
- package/dist/ui/Compose/hooks/menu/items.d.ts +8 -8
- package/dist/ui/Compose/hooks/menu/itemsMap.d.ts +2 -1
- package/dist/ui/Compose/hooks/menu/itemsMap.js.map +1 -1
- package/dist/ui/Compose/hooks/menu/types.d.ts +21 -0
- package/dist/ui/Compose/hooks/menu/types.js +3 -0
- package/dist/ui/Compose/hooks/menu/types.js.map +1 -0
- package/dist/ui/Compose/hooks/menu/useMenu.d.ts +2 -2
- package/dist/ui/Compose/hooks/menu/useMenu.js +45 -23
- package/dist/ui/Compose/hooks/menu/useMenu.js.map +1 -1
- package/dist/ui/Compose/hooks/menu/useMenu.jsx +43 -23
- package/dist/ui/Compose/hooks/mergeGeneratedValue.d.ts +14 -0
- package/dist/ui/Compose/hooks/mergeGeneratedValue.js +38 -0
- package/dist/ui/Compose/hooks/mergeGeneratedValue.js.map +1 -0
- package/dist/ui/Compose/hooks/useGenerate.js +37 -12
- package/dist/ui/Compose/hooks/useGenerate.js.map +1 -1
- package/dist/ui/Compose/hooks/useGenerateUpload.js +66 -24
- package/dist/ui/Compose/hooks/useGenerateUpload.js.map +1 -1
- package/dist/ui/Compose/hooks/useHistory.js +1 -1
- package/dist/ui/Compose/hooks/useHistory.js.map +1 -1
- package/dist/ui/Compose/hooks/useStreamingUpdate.js +4 -4
- package/dist/ui/Compose/hooks/useStreamingUpdate.js.map +1 -1
- package/dist/ui/ConfigDashboard/configDashboard.module.css +94 -0
- package/dist/ui/ConfigDashboard/index.js +27 -92
- package/dist/ui/ConfigDashboard/index.js.map +1 -1
- package/dist/ui/ConfigDashboard/index.jsx +24 -77
- package/dist/ui/DynamicModelSelect/index.js +6 -27
- package/dist/ui/DynamicModelSelect/index.js.map +1 -1
- package/dist/ui/DynamicModelSelect/index.jsx +6 -29
- package/dist/ui/DynamicProviderSelect/index.js +6 -27
- package/dist/ui/DynamicProviderSelect/index.js.map +1 -1
- package/dist/ui/DynamicProviderSelect/index.jsx +6 -29
- package/dist/ui/DynamicVoiceSelect/index.js +34 -83
- package/dist/ui/DynamicVoiceSelect/index.js.map +1 -1
- package/dist/ui/DynamicVoiceSelect/index.jsx +16 -53
- package/dist/ui/GlobalProviderOptions/index.d.ts +2 -0
- package/dist/ui/GlobalProviderOptions/index.js +118 -0
- package/dist/ui/GlobalProviderOptions/index.js.map +1 -0
- package/dist/ui/GlobalProviderOptions/index.jsx +60 -0
- package/dist/ui/Icons/Icons.js +1 -1
- package/dist/ui/Icons/Icons.js.map +1 -1
- package/dist/ui/Icons/Icons.jsx +1 -1
- package/dist/ui/Icons/LottieAnimation.js +1 -1
- package/dist/ui/Icons/LottieAnimation.js.map +1 -1
- package/dist/ui/Icons/LottieAnimation.jsx +1 -1
- package/dist/ui/InstructionProviderOptions/ProviderOptionsTree.d.ts +12 -0
- package/dist/ui/InstructionProviderOptions/ProviderOptionsTree.js +166 -0
- package/dist/ui/InstructionProviderOptions/ProviderOptionsTree.js.map +1 -0
- package/dist/ui/InstructionProviderOptions/ProviderOptionsTree.jsx +83 -0
- package/dist/ui/InstructionProviderOptions/index.d.ts +2 -0
- package/dist/ui/InstructionProviderOptions/index.js +157 -0
- package/dist/ui/InstructionProviderOptions/index.js.map +1 -0
- package/dist/ui/InstructionProviderOptions/index.jsx +92 -0
- package/dist/ui/VoicesFetcher/index.js.map +1 -1
- package/dist/ui/hooks/useAISettings.d.ts +26 -0
- package/dist/ui/hooks/useAISettings.js +73 -0
- package/dist/ui/hooks/useAISettings.js.map +1 -0
- package/dist/ui/providerOptions/updateProviderOptionsValue.d.ts +6 -0
- package/dist/ui/providerOptions/updateProviderOptionsValue.js +50 -0
- package/dist/ui/providerOptions/updateProviderOptionsValue.js.map +1 -0
- package/dist/ui/shared/handleSelectChange.d.ts +5 -0
- package/dist/ui/shared/handleSelectChange.js +12 -0
- package/dist/ui/shared/handleSelectChange.js.map +1 -0
- package/dist/ui/shared/types.d.ts +11 -0
- package/dist/ui/shared/types.js +5 -0
- package/dist/ui/shared/types.js.map +1 -0
- package/dist/utilities/ai/resolveEffectiveInstructionSettings.d.ts +15 -0
- package/dist/utilities/ai/resolveEffectiveInstructionSettings.js +136 -0
- package/dist/utilities/ai/resolveEffectiveInstructionSettings.js.map +1 -0
- package/dist/{endpoints → utilities}/buildPromptUtils.js +14 -5
- package/dist/utilities/buildPromptUtils.js.map +1 -0
- package/dist/utilities/buildSmartPrompt.js +3 -3
- package/dist/utilities/buildSmartPrompt.js.map +1 -1
- package/dist/utilities/fields/fieldToJsonSchema.js.map +1 -0
- package/dist/utilities/fields/getFieldBySchemaPath.js.map +1 -0
- package/dist/utilities/fields/getFieldInfo.js.map +1 -0
- package/dist/utilities/{updateFieldsConfig.js → fields/updateFieldsConfig.js} +8 -3
- package/dist/utilities/fields/updateFieldsConfig.js.map +1 -0
- package/dist/utilities/images/extractImageData.js.map +1 -0
- package/dist/utilities/images/extractPromptAttachments.js.map +1 -0
- package/dist/utilities/{fetchImages.d.ts → images/fetchImages.d.ts} +1 -1
- package/dist/utilities/images/fetchImages.js +49 -0
- package/dist/utilities/images/fetchImages.js.map +1 -0
- package/dist/utilities/images/resolveImageReferences.js +183 -0
- package/dist/utilities/images/resolveImageReferences.js.map +1 -0
- package/dist/utilities/init/autoSetupProviders.d.ts +3 -0
- package/dist/utilities/init/autoSetupProviders.js +216 -0
- package/dist/utilities/init/autoSetupProviders.js.map +1 -0
- package/dist/utilities/lexical/editorSchemaValidator.js.map +1 -0
- package/dist/utilities/lexical/lexicalToHTML.js.map +1 -0
- package/dist/utilities/lexical/lexicalToPromptTemplate.d.ts +2 -0
- package/dist/utilities/lexical/lexicalToPromptTemplate.js +50 -0
- package/dist/utilities/lexical/lexicalToPromptTemplate.js.map +1 -0
- package/dist/utilities/lexical/setSafeLexicalState.js.map +1 -0
- package/dist/utilities/lexical/stringToLexicalJSON.d.ts +2 -0
- package/dist/utilities/lexical/stringToLexicalJSON.js +39 -0
- package/dist/utilities/lexical/stringToLexicalJSON.js.map +1 -0
- package/dist/utilities/sanitizeLog.d.ts +1 -0
- package/dist/utilities/sanitizeLog.js +39 -0
- package/dist/utilities/sanitizeLog.js.map +1 -0
- package/dist/utilities/seedProperties.js +54 -22
- package/dist/utilities/seedProperties.js.map +1 -1
- package/package.json +36 -2
- package/dist/ai/analyse.d.ts +0 -1
- package/dist/ai/analyse.js +0 -3
- package/dist/ai/analyse.js.map +0 -1
- package/dist/ai/index.d.ts +0 -11
- package/dist/ai/index.js +0 -25
- package/dist/ai/index.js.map +0 -1
- package/dist/ai/prompts.js.map +0 -1
- package/dist/ai/utils/filterEditorSchemaByNodes.js.map +0 -1
- package/dist/ai/utils/generateFileNameByPrompt.js.map +0 -1
- package/dist/ai/utils/isObjectSchema.js.map +0 -1
- package/dist/ai/utils/nodeToSchemaMap.js.map +0 -1
- package/dist/ai/utils/systemGenerate.js.map +0 -1
- package/dist/endpoints/buildPromptUtils.js.map +0 -1
- package/dist/endpoints/chat.d.ts +0 -4
- package/dist/fields/PromptEditorField/PromptEditorField.d.ts +0 -3
- package/dist/fields/PromptEditorField/PromptEditorField.js +0 -217
- package/dist/fields/PromptEditorField/PromptEditorField.js.map +0 -1
- package/dist/fields/PromptEditorField/PromptEditorField.jsx +0 -160
- package/dist/ui/AIConfigDashboard/index.d.ts +0 -2
- package/dist/ui/AIConfigDashboard/index.js +0 -224
- package/dist/ui/AIConfigDashboard/index.js.map +0 -1
- package/dist/ui/AIConfigDashboard/index.jsx +0 -175
- package/dist/ui/ProviderOptionsEditor/index.d.ts +0 -7
- package/dist/ui/ProviderOptionsEditor/index.js +0 -291
- package/dist/ui/ProviderOptionsEditor/index.js.map +0 -1
- package/dist/ui/ProviderOptionsEditor/index.jsx +0 -210
- package/dist/utilities/editorSchemaValidator.js.map +0 -1
- package/dist/utilities/extractImageData.js.map +0 -1
- package/dist/utilities/extractPromptAttachments.js.map +0 -1
- package/dist/utilities/fetchImages.js +0 -38
- package/dist/utilities/fetchImages.js.map +0 -1
- package/dist/utilities/fieldToJsonSchema.js.map +0 -1
- package/dist/utilities/getFieldBySchemaPath.js.map +0 -1
- package/dist/utilities/getFieldInfo.js.map +0 -1
- package/dist/utilities/getProviderOptionsFields.d.ts +0 -16
- package/dist/utilities/getProviderOptionsFields.js +0 -80
- package/dist/utilities/getProviderOptionsFields.js.map +0 -1
- package/dist/utilities/isPluginActivated.d.ts +0 -2
- package/dist/utilities/isPluginActivated.js +0 -5
- package/dist/utilities/isPluginActivated.js.map +0 -1
- package/dist/utilities/lexicalToHTML.js.map +0 -1
- package/dist/utilities/resolveImageReferences.js +0 -167
- package/dist/utilities/resolveImageReferences.js.map +0 -1
- package/dist/utilities/schemaConverter.d.ts +0 -3
- package/dist/utilities/schemaConverter.js +0 -93
- package/dist/utilities/schemaConverter.js.map +0 -1
- package/dist/utilities/setSafeLexicalState.js.map +0 -1
- package/dist/utilities/updateFieldsConfig.js.map +0 -1
- /package/dist/ai/{utils → utilities}/filterEditorSchemaByNodes.d.ts +0 -0
- /package/dist/ai/{utils → utilities}/filterEditorSchemaByNodes.js +0 -0
- /package/dist/ai/{utils → utilities}/generateFileNameByPrompt.d.ts +0 -0
- /package/dist/ai/{utils → utilities}/generateFileNameByPrompt.js +0 -0
- /package/dist/ai/{utils → utilities}/isObjectSchema.d.ts +0 -0
- /package/dist/ai/{utils → utilities}/isObjectSchema.js +0 -0
- /package/dist/ai/{utils → utilities}/nodeToSchemaMap.d.ts +0 -0
- /package/dist/ai/{prompts.js → utilities/prompts.js} +0 -0
- /package/dist/ai/{utils → utilities}/systemGenerate.d.ts +0 -0
- /package/dist/ai/{utils → utilities}/systemGenerate.js +0 -0
- /package/dist/ui/Icons/{icons.module.css → icons.module.scss} +0 -0
- /package/dist/{endpoints → utilities}/buildPromptUtils.d.ts +0 -0
- /package/dist/utilities/{fieldToJsonSchema.d.ts → fields/fieldToJsonSchema.d.ts} +0 -0
- /package/dist/utilities/{fieldToJsonSchema.js → fields/fieldToJsonSchema.js} +0 -0
- /package/dist/utilities/{getFieldBySchemaPath.d.ts → fields/getFieldBySchemaPath.d.ts} +0 -0
- /package/dist/utilities/{getFieldBySchemaPath.js → fields/getFieldBySchemaPath.js} +0 -0
- /package/dist/utilities/{getFieldInfo.d.ts → fields/getFieldInfo.d.ts} +0 -0
- /package/dist/utilities/{getFieldInfo.js → fields/getFieldInfo.js} +0 -0
- /package/dist/utilities/{updateFieldsConfig.d.ts → fields/updateFieldsConfig.d.ts} +0 -0
- /package/dist/utilities/{extractImageData.d.ts → images/extractImageData.d.ts} +0 -0
- /package/dist/utilities/{extractImageData.js → images/extractImageData.js} +0 -0
- /package/dist/utilities/{extractPromptAttachments.d.ts → images/extractPromptAttachments.d.ts} +0 -0
- /package/dist/utilities/{extractPromptAttachments.js → images/extractPromptAttachments.js} +0 -0
- /package/dist/utilities/{resolveImageReferences.d.ts → images/resolveImageReferences.d.ts} +0 -0
- /package/dist/utilities/{editorSchemaValidator.d.ts → lexical/editorSchemaValidator.d.ts} +0 -0
- /package/dist/utilities/{editorSchemaValidator.js → lexical/editorSchemaValidator.js} +0 -0
- /package/dist/utilities/{lexicalToHTML.d.ts → lexical/lexicalToHTML.d.ts} +0 -0
- /package/dist/utilities/{lexicalToHTML.js → lexical/lexicalToHTML.js} +0 -0
- /package/dist/utilities/{setSafeLexicalState.d.ts → lexical/setSafeLexicalState.d.ts} +0 -0
- /package/dist/utilities/{setSafeLexicalState.js → lexical/setSafeLexicalState.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ui/Compose/Compose.tsx"],"sourcesContent":["'use client'\n\nimport type { ClientField } from 'payload'\nimport type { FC } from 'react'\n\nimport { useEditorConfigContext } from '@payloadcms/richtext-lexical/client'\nimport { Popup, useField } from '@payloadcms/ui'\nimport React, { useCallback, useMemo, useState } from 'react'\n\nimport { PLUGIN_INSTRUCTIONS_TABLE } from '../../defaults.js'\nimport { useInstructions } from '../../providers/InstructionsProvider/useInstructions.js'\nimport { setSafeLexicalState } from '../../utilities/setSafeLexicalState.js'\nimport { PluginIcon } from '../Icons/Icons.js'\nimport styles from './compose.module.css'\nimport { useMenu } from './hooks/menu/useMenu.js'\nimport { useActiveFieldTracking } from './hooks/useActiveFieldTracking.js'\nimport { useGenerate } from './hooks/useGenerate.js'\nimport { UndoRedoActions } from './UndoRedoActions.js'\n\nexport type ComposeProps = {\n descriptionProps?: {\n field: ClientField\n path: string\n schemaPath: string\n }\n forceVisible?: boolean\n instructionId: string\n isConfigAllowed: boolean\n}\n\nexport const Compose: FC<ComposeProps> = ({ descriptionProps, forceVisible, instructionId, isConfigAllowed }) => {\n const pathFromContext = descriptionProps?.path\n const { editor: lexicalEditor } = useEditorConfigContext()\n \n // Get global openDrawer from context\n const { openDrawer } = useInstructions()\n\n // Initialize global active-field tracking\n useActiveFieldTracking()\n\n const [isProcessing, setIsProcessing] = useState<boolean>(false)\n const { generate, isJobActive, isLoading, jobProgress, jobStatus, stop } = useGenerate({ instructionId })\n\n // Memoize menu event handlers to prevent recreation on every render\n const onCompose = useCallback(() => {\n console.log('Composing...')\n setIsProcessing(true)\n generate({\n action: 'Compose',\n })\n .catch((reason) => {\n console.error('Compose : ', reason)\n })\n .finally(() => {\n setIsProcessing(false)\n })\n }, [generate])\n\n const onExpand = useCallback(() => {\n console.log('Expanding...')\n generate({\n action: 'Expand',\n })\n .catch((reason) => {\n console.error('Compose : ', reason)\n })\n .finally(() => {\n setIsProcessing(false)\n })\n }, [generate])\n\n const onProofread = useCallback(() => {\n console.log('Proofreading...')\n generate({\n action: 'Proofread',\n })\n .catch((reason) => {\n console.error('Compose : ', reason)\n })\n .finally(() => {\n setIsProcessing(false)\n })\n }, [generate])\n\n const onRephrase = useCallback(() => {\n console.log('Rephrasing...')\n generate({\n action: 'Rephrase',\n })\n .catch((reason) => {\n console.error('Compose : ', reason)\n })\n .finally(() => {\n setIsProcessing(false)\n })\n }, [generate])\n\n const onSimplify = useCallback(() => {\n console.log('Simplifying...')\n generate({\n action: 'Simplify',\n })\n .catch((reason) => {\n console.error('Compose : ', reason)\n })\n .finally(() => {\n setIsProcessing(false)\n })\n }, [generate])\n\n const onSummarize = useCallback(() => {\n console.log('Summarizing...')\n generate({\n action: 'Summarize',\n })\n .catch((reason) => {\n console.error('Compose : ', reason)\n })\n .finally(() => {\n setIsProcessing(false)\n })\n }, [generate])\n\n const onTranslate = useCallback((data: unknown) => {\n console.log('Translating...')\n generate({\n action: 'Translate',\n params: data,\n })\n .catch((reason) => {\n console.error('Compose : ', reason)\n })\n .finally(() => {\n setIsProcessing(false)\n })\n }, [generate])\n\n const handleOpenSettings = useCallback(() => {\n if (isConfigAllowed) {\n openDrawer(instructionId)\n }\n }, [isConfigAllowed, openDrawer, instructionId])\n\n const { ActiveComponent, Menu } = useMenu(\n {\n onCompose,\n onExpand,\n onProofread,\n onRephrase,\n onSettings: isConfigAllowed ? handleOpenSettings : undefined,\n onSimplify,\n onSummarize,\n onTranslate,\n },\n {\n isConfigAllowed,\n },\n )\n\n const { setValue } = useField<string>({\n path: pathFromContext,\n })\n\n const setIfValueIsLexicalState = useCallback((val: any) => {\n // Prevent setting incomplete states during streaming\n if (!val || typeof val !== 'object' || !('root' in val) || !lexicalEditor) {\n return\n }\n\n // Validate that the state is complete before setting\n // Check for common incomplete streaming states\n if (!val.root || typeof val.root !== 'object' || Object.keys(val.root).length === 0) {\n return\n }\n\n if (val.root.type !== 'root') {\n return\n }\n\n if (!val.root.children || !Array.isArray(val.root.children) || val.root.children.length === 0) {\n return\n }\n\n // Check for invalid child types (common streaming issue)\n const hasInvalidChildren = val.root.children.some(\n (child: any) => !child || !child.type || child.type === 'undefined' || child.type === '',\n )\n\n if (hasInvalidChildren) {\n return\n }\n\n // State looks valid, proceed\n setSafeLexicalState(JSON.stringify(val), lexicalEditor)\n\n // DO NOT PROVIDE lexicalEditor as a dependency, it freaks out and does not update the editor after first undo/redo - revisit\n }, [])\n\n const popupRender = useCallback(\n ({ close }: { close: () => void }) => {\n return <Menu isLoading={isProcessing || isLoading} onClose={close} />\n },\n [isProcessing, isLoading, Menu],\n )\n\n // Combine loading states to reduce re-renders\n const isAnyLoading = isProcessing || isLoading || isJobActive\n\n const memoizedPopup = useMemo(() => {\n return (\n <Popup\n button={<PluginIcon isLoading={isAnyLoading} />}\n render={popupRender}\n verticalAlign=\"bottom\"\n />\n )\n }, [popupRender, isAnyLoading])\n\n return (\n <label\n className={`payloadai-compose__actions ${styles.actions} ${forceVisible ? styles.actionsVisible : ''}`}\n onClick={(e) => e.preventDefault()}\n role=\"presentation\"\n >\n {memoizedPopup}\n <ActiveComponent\n isLoading={isProcessing || isLoading || isJobActive}\n loadingLabel={isJobActive ? (jobStatus === 'running' ? `Video ${Math.max(0, Math.min(100, Math.round(jobProgress ?? 0)))}%` : (jobStatus || 'Queued')) : undefined}\n stop={stop}\n />\n <UndoRedoActions\n onChange={(val) => {\n setValue(val)\n setIfValueIsLexicalState(val)\n }}\n />\n </label>\n )\n}\n"],"names":["useEditorConfigContext","Popup","useField","React","useCallback","useMemo","useState","useInstructions","setSafeLexicalState","PluginIcon","styles","useMenu","useActiveFieldTracking","useGenerate","UndoRedoActions","Compose","descriptionProps","forceVisible","instructionId","isConfigAllowed","pathFromContext","path","editor","lexicalEditor","openDrawer","isProcessing","setIsProcessing","generate","isJobActive","isLoading","jobProgress","jobStatus","stop","onCompose","console","log","action","catch","reason","error","finally","onExpand","onProofread","onRephrase","onSimplify","onSummarize","onTranslate","data","params","handleOpenSettings","ActiveComponent","Menu","onSettings","undefined","setValue","setIfValueIsLexicalState","val","root","Object","keys","length","type","children","Array","isArray","hasInvalidChildren","some","child","JSON","stringify","popupRender","close","onClose","isAnyLoading","memoizedPopup","button","render","verticalAlign","label","className","actions","actionsVisible","onClick","e","preventDefault","role","loadingLabel","Math","max","min","round","onChange"],"mappings":"AAAA;;AAKA,SAASA,sBAAsB,QAAQ,sCAAqC;AAC5E,SAASC,KAAK,EAAEC,QAAQ,QAAQ,iBAAgB;AAChD,OAAOC,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAG7D,SAASC,eAAe,QAAQ,0DAAyD;AACzF,SAASC,mBAAmB,QAAQ,yCAAwC;AAC5E,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,OAAOC,YAAY,uBAAsB;AACzC,SAASC,OAAO,QAAQ,0BAAyB;AACjD,SAASC,sBAAsB,QAAQ,oCAAmC;AAC1E,SAASC,WAAW,QAAQ,yBAAwB;AACpD,SAASC,eAAe,QAAQ,uBAAsB;AAatD,OAAO,MAAMC,UAA4B,CAAC,EAAEC,gBAAgB,EAAEC,YAAY,EAAEC,aAAa,EAAEC,eAAe,EAAE;IAC1G,MAAMC,kBAAkBJ,kBAAkBK;IAC1C,MAAM,EAAEC,QAAQC,aAAa,EAAE,GAAGvB;IAElC,qCAAqC;IACrC,MAAM,EAAEwB,UAAU,EAAE,GAAGjB;IAEvB,0CAA0C;IAC1CK;IAEA,MAAM,CAACa,cAAcC,gBAAgB,GAAGpB,SAAkB;IAC1D,MAAM,EAAEqB,QAAQ,EAAEC,WAAW,EAAEC,SAAS,EAAEC,WAAW,EAAEC,SAAS,EAAEC,IAAI,EAAE,GAAGnB,YAAY;QAAEK;IAAc;IAEvG,oEAAoE;IACpE,MAAMe,YAAY7B,YAAY;QAC5B8B,QAAQC,GAAG,CAAC;QACZT,gBAAgB;QAChBC,SAAS;YACPS,QAAQ;QACV,GACGC,KAAK,CAAC,CAACC;YACNJ,QAAQK,KAAK,CAAC,cAAcD;QAC9B,GACCE,OAAO,CAAC;YACPd,gBAAgB;QAClB;IACJ,GAAG;QAACC;KAAS;IAEb,MAAMc,WAAWrC,YAAY;QAC3B8B,QAAQC,GAAG,CAA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AE;IAEL,MAAM+C,cAAclE,YAClB,CAAC,EAAEmE,KAAK,EAAyB;QAC/B,qBAAO,KAACpB;YAAKtB,WAAWJ,gBAAgBI;YAAW2C,SAASD;;IAC9D,GACA;QAAC9C;QAAcI;QAAWsB;KAAK;IAGjC,8CAA8C;IAC9C,MAAMsB,eAAehD,gBAAgBI,aAAaD;IAElD,MAAM8C,gBAAgBrE,QAAQ;QAC5B,qBACE,KAACJ;YACC0E,sBAAQ,KAAClE;gBAAWoB,WAAW4C;;YAC/BG,QAAQN;YACRO,eAAc;;IAGpB,GAAG;QAACP;QAAaG;KAAa;IAE9B,qBACE,MAACK;QACCC,WAAW,CAAC,2BAA2B,EAAErE,OAAOsE,OAAO,CAAC,CAAC,EAAE/D,eAAeP,OAAOuE,cAAc,GAAG,GAAG,CAAC;QACtGC,SAAS,CAACC,IAAMA,EAAEC,cAAc;QAChCC,MAAK;;YAEJX;0BACD,KAACxB;gBACCrB,WAAWJ,gBAAgBI,aAAaD;gBACxC0D,cAAc1D,cAAeG,cAAc,YAAY,CAAC,MAAM,EAAEwD,KAAKC,GAAG,CAAC,GAAGD,KAAKE,GAAG,CAAC,KAAKF,KAAKG,KAAK,CAAC5D,eAAe,KAAK,CAAC,CAAC,GAAIC,aAAa,WAAasB;gBACzJrB,MAAMA;;0BAER,KAAClB;gBACC6E,UAAU,CAACnC;oBACTF,SAASE;oBACTD,yBAAyBC;gBAC3B;;;;AAIR,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/Compose/Compose.tsx"],"sourcesContent":["'use client'\n\nimport type { ClientField } from 'payload'\nimport type { FC } from 'react'\n\nimport { useEditorConfigContext } from '@payloadcms/richtext-lexical/client'\nimport { Popup, useField, useTranslation } from '@payloadcms/ui'\nimport React, { useCallback, useMemo, useState } from 'react'\n\nimport type { PluginAITranslationKeys, PluginAITranslations } from '../../translations/index.js'\nimport type { ActionMenuItems } from '../../types.js'\n\nimport { useInstructions } from '../../providers/InstructionsProvider/useInstructions.js'\nimport { setSafeLexicalState } from '../../utilities/lexical/setSafeLexicalState.js'\nimport { PluginIcon } from '../Icons/Icons.js'\nimport styles from './compose.module.scss'\nimport { useMenu } from './hooks/menu/useMenu.js'\nimport { useActiveFieldTracking } from './hooks/useActiveFieldTracking.js'\nimport { useGenerate } from './hooks/useGenerate.js'\nimport { UndoRedoActions } from './UndoRedoActions.js'\n\nexport type ComposeProps = {\n descriptionProps?: {\n field: ClientField\n path: string\n schemaPath: string\n }\n forceVisible?: boolean\n instructionId: string\n isConfigAllowed: boolean\n}\n\nexport const Compose: FC<ComposeProps> = ({\n descriptionProps,\n forceVisible,\n instructionId,\n isConfigAllowed,\n}) => {\n const pathFromContext = descriptionProps?.path\n const { editor: lexicalEditor } = useEditorConfigContext()\n\n // Get global openDrawer from context\n const { openDrawer } = useInstructions()\n\n // Initialize global active-field tracking\n useActiveFieldTracking()\n\n const { t } = useTranslation<PluginAITranslations, PluginAITranslationKeys>()\n\n const [isProcessing, setIsProcessing] = useState<boolean>(false)\n const { generate, isJobActive, isLoading, jobProgress, jobStatus, stop } = useGenerate({\n instructionId,\n })\n\n // Single factory for all action callbacks, eliminating duplication\n const createAction = useCallback(\n (action: ActionMenuItems, params?: unknown) => {\n setIsProcessing(true)\n generate({ action, params })\n .catch((reason) => {\n console.error(`AI Plugin — ${action}:`, reason)\n })\n .finally(() => {\n setIsProcessing(false)\n })\n },\n [generate],\n )\n\n const onCompose = useCallback(() => createAction('Compose'), [createAction])\n const onExpand = useCallback(() => createAction('Expand'), [createAction])\n const onProofread = useCallback(() => createAction('Proofread'), [createAction])\n const onRephrase = useCallback(() => createAction('Rephrase'), [createAction])\n const onSimplify = useCallback(() => createAction('Simplify'), [createAction])\n const onSummarize = useCallback(() => createAction('Summarize'), [createAction])\n const onTranslate = useCallback(\n (data: unknown) => {\n // If the action is triggered directly via the button click,\n // it passes a React SyntheticEvent which cannot (and should not) be stringified.\n // We only want to pass data if it's the actual payload containing { locale }.\n const isEvent = data && typeof data === 'object' && 'nativeEvent' in data\n return createAction('Translate', isEvent ? undefined : data)\n },\n [createAction],\n )\n\n const handleOpenSettings = useCallback(() => {\n if (isConfigAllowed) {\n openDrawer(instructionId)\n }\n }, [isConfigAllowed, openDrawer, instructionId])\n\n const { ActiveComponent, Menu } = useMenu(\n {\n onCompose,\n onExpand,\n onProofread,\n onRephrase,\n onSettings: isConfigAllowed ? handleOpenSettings : undefined,\n onSimplify,\n onSummarize,\n onTranslate,\n },\n {\n isConfigAllowed,\n },\n )\n\n const { setValue } = useField<string>({\n path: pathFromContext,\n })\n\n const setIfValueIsLexicalState = useCallback((val: any) => {\n // Prevent setting incomplete states during streaming\n if (!val || typeof val !== 'object' || !('root' in val) || !lexicalEditor) {\n return\n }\n\n // Validate that the state is complete before setting\n // Check for common incomplete streaming states\n if (!val.root || typeof val.root !== 'object' || Object.keys(val.root).length === 0) {\n return\n }\n\n if (val.root.type !== 'root') {\n return\n }\n\n if (!val.root.children || !Array.isArray(val.root.children) || val.root.children.length === 0) {\n return\n }\n\n // Check for invalid child types (common streaming issue)\n const hasInvalidChildren = val.root.children.some(\n (child: any) => !child || !child.type || child.type === 'undefined' || child.type === '',\n )\n\n if (hasInvalidChildren) {\n return\n }\n\n // State looks valid, proceed\n setSafeLexicalState(JSON.stringify(val), lexicalEditor)\n\n // DO NOT PROVIDE lexicalEditor as a dependency, it freaks out and does not update the editor after first undo/redo - revisit\n }, [])\n\n const popupRender = useCallback(\n ({ close }: { close: () => void }) => {\n return <Menu isLoading={isProcessing || isLoading} onClose={close} />\n },\n [isProcessing, isLoading, Menu],\n )\n\n // Combine loading states to reduce re-renders\n const isAnyLoading = isProcessing || isLoading || isJobActive\n\n const memoizedPopup = useMemo(() => {\n return (\n <Popup\n button={<PluginIcon isLoading={isAnyLoading} />}\n render={popupRender}\n verticalAlign=\"bottom\"\n />\n )\n }, [popupRender, isAnyLoading])\n\n return (\n <label\n className={`payloadai-compose__actions ${styles.actions} ${forceVisible ? styles.actionsVisible : ''}`}\n onClick={(e) => e.preventDefault()}\n role=\"presentation\"\n >\n {memoizedPopup}\n <ActiveComponent\n isLoading={isProcessing || isLoading || isJobActive}\n loadingLabel={\n isJobActive\n ? jobStatus === 'running'\n ? `${t('ai-plugin:general:video' as any)} ${Math.max(0, Math.min(100, Math.round(jobProgress ?? 0)))}%`\n : jobStatus || t('ai-plugin:general:queued' as any)\n : undefined\n }\n stop={stop}\n />\n <div style={{ alignItems: 'center', display: 'flex', gap: '10px', marginLeft: 'auto' }}>\n <UndoRedoActions\n onChange={(val) => {\n setValue(val)\n setIfValueIsLexicalState(val)\n }}\n />\n </div>\n </label>\n )\n}\n"],"names":["useEditorConfigContext","Popup","useField","useTranslation","React","useCallback","useMemo","useState","useInstructions","setSafeLexicalState","PluginIcon","styles","useMenu","useActiveFieldTracking","useGenerate","UndoRedoActions","Compose","descriptionProps","forceVisible","instructionId","isConfigAllowed","pathFromContext","path","editor","lexicalEditor","openDrawer","t","isProcessing","setIsProcessing","generate","isJobActive","isLoading","jobProgress","jobStatus","stop","createAction","action","params","catch","reason","console","error","finally","onCompose","onExpand","onProofread","onRephrase","onSimplify","onSummarize","onTranslate","data","isEvent","undefined","handleOpenSettings","ActiveComponent","Menu","onSettings","setValue","setIfValueIsLexicalState","val","root","Object","keys","length","type","children","Array","isArray","hasInvalidChildren","some","child","JSON","stringify","popupRender","close","onClose","isAnyLoading","memoizedPopup","button","render","verticalAlign","label","className","actions","actionsVisible","onClick","e","preventDefault","role","loadingLabel","Math","max","min","round","div","style","alignItems","display","gap","marginLeft","onChange"],"mappings":"AAAA;;AAKA,SAASA,sBAAsB,QAAQ,sCAAqC;AAC5E,SAASC,KAAK,EAAEC,QAAQ,EAAEC,cAAc,QAAQ,iBAAgB;AAChE,OAAOC,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAK7D,SAASC,eAAe,QAAQ,0DAAyD;AACzF,SAASC,mBAAmB,QAAQ,iDAAgD;AACpF,SAASC,UAAU,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D,yBAAyBC;oBAC3B;;;;;AAKV,EAAC"}
|
|
@@ -1,111 +1,51 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useEditorConfigContext } from '@payloadcms/richtext-lexical/client';
|
|
3
|
-
import { Popup, useField } from '@payloadcms/ui';
|
|
3
|
+
import { Popup, useField, useTranslation } from '@payloadcms/ui';
|
|
4
4
|
import React, { useCallback, useMemo, useState } from 'react';
|
|
5
5
|
import { useInstructions } from '../../providers/InstructionsProvider/useInstructions.js';
|
|
6
|
-
import { setSafeLexicalState } from '../../utilities/setSafeLexicalState.js';
|
|
6
|
+
import { setSafeLexicalState } from '../../utilities/lexical/setSafeLexicalState.js';
|
|
7
7
|
import { PluginIcon } from '../Icons/Icons.js';
|
|
8
|
-
import styles from './compose.module.
|
|
8
|
+
import styles from './compose.module.scss';
|
|
9
9
|
import { useMenu } from './hooks/menu/useMenu.js';
|
|
10
10
|
import { useActiveFieldTracking } from './hooks/useActiveFieldTracking.js';
|
|
11
11
|
import { useGenerate } from './hooks/useGenerate.js';
|
|
12
12
|
import { UndoRedoActions } from './UndoRedoActions.js';
|
|
13
|
-
export const Compose = ({ descriptionProps, forceVisible, instructionId, isConfigAllowed }) => {
|
|
13
|
+
export const Compose = ({ descriptionProps, forceVisible, instructionId, isConfigAllowed, }) => {
|
|
14
14
|
const pathFromContext = descriptionProps?.path;
|
|
15
15
|
const { editor: lexicalEditor } = useEditorConfigContext();
|
|
16
16
|
// Get global openDrawer from context
|
|
17
17
|
const { openDrawer } = useInstructions();
|
|
18
18
|
// Initialize global active-field tracking
|
|
19
19
|
useActiveFieldTracking();
|
|
20
|
+
const { t } = useTranslation();
|
|
20
21
|
const [isProcessing, setIsProcessing] = useState(false);
|
|
21
|
-
const { generate, isJobActive, isLoading, jobProgress, jobStatus, stop } = useGenerate({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const { generate, isJobActive, isLoading, jobProgress, jobStatus, stop } = useGenerate({
|
|
23
|
+
instructionId,
|
|
24
|
+
});
|
|
25
|
+
// Single factory for all action callbacks, eliminating duplication
|
|
26
|
+
const createAction = useCallback((action, params) => {
|
|
25
27
|
setIsProcessing(true);
|
|
26
|
-
generate({
|
|
27
|
-
action: 'Compose',
|
|
28
|
-
})
|
|
29
|
-
.catch((reason) => {
|
|
30
|
-
console.error('Compose : ', reason);
|
|
31
|
-
})
|
|
32
|
-
.finally(() => {
|
|
33
|
-
setIsProcessing(false);
|
|
34
|
-
});
|
|
35
|
-
}, [generate]);
|
|
36
|
-
const onExpand = useCallback(() => {
|
|
37
|
-
console.log('Expanding...');
|
|
38
|
-
generate({
|
|
39
|
-
action: 'Expand',
|
|
40
|
-
})
|
|
41
|
-
.catch((reason) => {
|
|
42
|
-
console.error('Compose : ', reason);
|
|
43
|
-
})
|
|
44
|
-
.finally(() => {
|
|
45
|
-
setIsProcessing(false);
|
|
46
|
-
});
|
|
47
|
-
}, [generate]);
|
|
48
|
-
const onProofread = useCallback(() => {
|
|
49
|
-
console.log('Proofreading...');
|
|
50
|
-
generate({
|
|
51
|
-
action: 'Proofread',
|
|
52
|
-
})
|
|
53
|
-
.catch((reason) => {
|
|
54
|
-
console.error('Compose : ', reason);
|
|
55
|
-
})
|
|
56
|
-
.finally(() => {
|
|
57
|
-
setIsProcessing(false);
|
|
58
|
-
});
|
|
59
|
-
}, [generate]);
|
|
60
|
-
const onRephrase = useCallback(() => {
|
|
61
|
-
console.log('Rephrasing...');
|
|
62
|
-
generate({
|
|
63
|
-
action: 'Rephrase',
|
|
64
|
-
})
|
|
65
|
-
.catch((reason) => {
|
|
66
|
-
console.error('Compose : ', reason);
|
|
67
|
-
})
|
|
68
|
-
.finally(() => {
|
|
69
|
-
setIsProcessing(false);
|
|
70
|
-
});
|
|
71
|
-
}, [generate]);
|
|
72
|
-
const onSimplify = useCallback(() => {
|
|
73
|
-
console.log('Simplifying...');
|
|
74
|
-
generate({
|
|
75
|
-
action: 'Simplify',
|
|
76
|
-
})
|
|
77
|
-
.catch((reason) => {
|
|
78
|
-
console.error('Compose : ', reason);
|
|
79
|
-
})
|
|
80
|
-
.finally(() => {
|
|
81
|
-
setIsProcessing(false);
|
|
82
|
-
});
|
|
83
|
-
}, [generate]);
|
|
84
|
-
const onSummarize = useCallback(() => {
|
|
85
|
-
console.log('Summarizing...');
|
|
86
|
-
generate({
|
|
87
|
-
action: 'Summarize',
|
|
88
|
-
})
|
|
28
|
+
generate({ action, params })
|
|
89
29
|
.catch((reason) => {
|
|
90
|
-
console.error(
|
|
30
|
+
console.error(`AI Plugin — ${action}:`, reason);
|
|
91
31
|
})
|
|
92
32
|
.finally(() => {
|
|
93
33
|
setIsProcessing(false);
|
|
94
34
|
});
|
|
95
35
|
}, [generate]);
|
|
36
|
+
const onCompose = useCallback(() => createAction('Compose'), [createAction]);
|
|
37
|
+
const onExpand = useCallback(() => createAction('Expand'), [createAction]);
|
|
38
|
+
const onProofread = useCallback(() => createAction('Proofread'), [createAction]);
|
|
39
|
+
const onRephrase = useCallback(() => createAction('Rephrase'), [createAction]);
|
|
40
|
+
const onSimplify = useCallback(() => createAction('Simplify'), [createAction]);
|
|
41
|
+
const onSummarize = useCallback(() => createAction('Summarize'), [createAction]);
|
|
96
42
|
const onTranslate = useCallback((data) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
console.error('Compose : ', reason);
|
|
104
|
-
})
|
|
105
|
-
.finally(() => {
|
|
106
|
-
setIsProcessing(false);
|
|
107
|
-
});
|
|
108
|
-
}, [generate]);
|
|
43
|
+
// If the action is triggered directly via the button click,
|
|
44
|
+
// it passes a React SyntheticEvent which cannot (and should not) be stringified.
|
|
45
|
+
// We only want to pass data if it's the actual payload containing { locale }.
|
|
46
|
+
const isEvent = data && typeof data === 'object' && 'nativeEvent' in data;
|
|
47
|
+
return createAction('Translate', isEvent ? undefined : data);
|
|
48
|
+
}, [createAction]);
|
|
109
49
|
const handleOpenSettings = useCallback(() => {
|
|
110
50
|
if (isConfigAllowed) {
|
|
111
51
|
openDrawer(instructionId);
|
|
@@ -161,10 +101,16 @@ export const Compose = ({ descriptionProps, forceVisible, instructionId, isConfi
|
|
|
161
101
|
}, [popupRender, isAnyLoading]);
|
|
162
102
|
return (<label className={`payloadai-compose__actions ${styles.actions} ${forceVisible ? styles.actionsVisible : ''}`} onClick={(e) => e.preventDefault()} role="presentation">
|
|
163
103
|
{memoizedPopup}
|
|
164
|
-
<ActiveComponent isLoading={isProcessing || isLoading || isJobActive} loadingLabel={isJobActive
|
|
165
|
-
|
|
104
|
+
<ActiveComponent isLoading={isProcessing || isLoading || isJobActive} loadingLabel={isJobActive
|
|
105
|
+
? jobStatus === 'running'
|
|
106
|
+
? `${t('ai-plugin:general:video')} ${Math.max(0, Math.min(100, Math.round(jobProgress ?? 0)))}%`
|
|
107
|
+
: jobStatus || t('ai-plugin:general:queued')
|
|
108
|
+
: undefined} stop={stop}/>
|
|
109
|
+
<div style={{ alignItems: 'center', display: 'flex', gap: '10px', marginLeft: 'auto' }}>
|
|
110
|
+
<UndoRedoActions onChange={(val) => {
|
|
166
111
|
setValue(val);
|
|
167
112
|
setIfValueIsLexicalState(val);
|
|
168
113
|
}}/>
|
|
114
|
+
</div>
|
|
169
115
|
</label>);
|
|
170
116
|
};
|
|
@@ -38,7 +38,7 @@ import { Compose } from './Compose.js';
|
|
|
38
38
|
unmountTimerRef.current = setTimeout(()=>{
|
|
39
39
|
setShouldMount(false);
|
|
40
40
|
unmountTimerRef.current = null;
|
|
41
|
-
}, 1200) //
|
|
41
|
+
}, 1200) // 1200ms delay to prevent rapid remounting
|
|
42
42
|
;
|
|
43
43
|
}
|
|
44
44
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ui/Compose/ComposePlaceholder.tsx"],"sourcesContent":["'use client'\n\nimport type { FC } from 'react'\n\nimport React, { useEffect, useRef, useState } from 'react'\n\nimport type { ComposeProps } from './Compose.js'\n\nimport { Compose } from './Compose.js'\n\n/**\n * Lightweight placeholder component that lazy-loads Compose when field becomes active.\n * Uses MutationObserver to watch for .ai-plugin-active class added by useActiveFieldTracking.\n */\nexport const ComposePlaceholder: FC<ComposeProps> = (props) => {\n const [shouldMount, setShouldMount] = useState(false)\n const containerRef = useRef<HTMLDivElement>(null)\n const unmountTimerRef = useRef<null | ReturnType<typeof setTimeout>>(null)\n\n useEffect(() => {\n const container = containerRef.current\n if (!container) {\n return\n }\n\n // Find the parent .field-type container\n const fieldContainer = container.closest('.field-type')\n if (!fieldContainer) {\n return\n }\n\n // Watch for .ai-plugin-active class changes\n const observer = new MutationObserver((mutations) => {\n for (const mutation of mutations) {\n if (mutation.type === 'attributes' && mutation.attributeName === 'class') {\n if (fieldContainer.classList.contains('ai-plugin-active')) {\n // Field is active - mount Compose and cancel any pending unmount\n if (unmountTimerRef.current) {\n clearTimeout(unmountTimerRef.current)\n unmountTimerRef.current = null\n }\n setShouldMount(true)\n } else if (shouldMount) {\n // Field is inactive - schedule unmount after delay\n if (unmountTimerRef.current) {\n clearTimeout(unmountTimerRef.current)\n }\n unmountTimerRef.current = setTimeout(() => {\n setShouldMount(false)\n unmountTimerRef.current = null\n }, 1200) //
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/Compose/ComposePlaceholder.tsx"],"sourcesContent":["'use client'\n\nimport type { FC } from 'react'\n\nimport React, { useEffect, useRef, useState } from 'react'\n\nimport type { ComposeProps } from './Compose.js'\n\nimport { Compose } from './Compose.js'\n\n/**\n * Lightweight placeholder component that lazy-loads Compose when field becomes active.\n * Uses MutationObserver to watch for .ai-plugin-active class added by useActiveFieldTracking.\n */\nexport const ComposePlaceholder: FC<ComposeProps> = (props) => {\n const [shouldMount, setShouldMount] = useState(false)\n const containerRef = useRef<HTMLDivElement>(null)\n const unmountTimerRef = useRef<null | ReturnType<typeof setTimeout>>(null)\n\n useEffect(() => {\n const container = containerRef.current\n if (!container) {\n return\n }\n\n // Find the parent .field-type container\n const fieldContainer = container.closest('.field-type')\n if (!fieldContainer) {\n return\n }\n\n // Watch for .ai-plugin-active class changes\n const observer = new MutationObserver((mutations) => {\n for (const mutation of mutations) {\n if (mutation.type === 'attributes' && mutation.attributeName === 'class') {\n if (fieldContainer.classList.contains('ai-plugin-active')) {\n // Field is active - mount Compose and cancel any pending unmount\n if (unmountTimerRef.current) {\n clearTimeout(unmountTimerRef.current)\n unmountTimerRef.current = null\n }\n setShouldMount(true)\n } else if (shouldMount) {\n // Field is inactive - schedule unmount after delay\n if (unmountTimerRef.current) {\n clearTimeout(unmountTimerRef.current)\n }\n unmountTimerRef.current = setTimeout(() => {\n setShouldMount(false)\n unmountTimerRef.current = null\n }, 1200) // 1200ms delay to prevent rapid remounting\n }\n break\n }\n }\n })\n\n observer.observe(fieldContainer, {\n attributeFilter: ['class'],\n attributes: true,\n })\n\n // Check initial state in case field is already active\n if (fieldContainer.classList.contains('ai-plugin-active')) {\n setShouldMount(true)\n }\n\n return () => {\n observer.disconnect()\n if (unmountTimerRef.current) {\n clearTimeout(unmountTimerRef.current)\n }\n }\n }, [shouldMount])\n\n return (\n <div ref={containerRef} style={{ display: 'contents' }}>\n {shouldMount ? <Compose {...props} /> : null}\n </div>\n )\n}\n"],"names":["React","useEffect","useRef","useState","Compose","ComposePlaceholder","props","shouldMount","setShouldMount","containerRef","unmountTimerRef","container","current","fieldContainer","closest","observer","MutationObserver","mutations","mutation","type","attributeName","classList","contains","clearTimeout","setTimeout","observe","attributeFilter","attributes","disconnect","div","ref","style","display"],"mappings":"AAAA;;AAIA,OAAOA,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAI1D,SAASC,OAAO,QAAQ,eAAc;AAEtC;;;CAGC,GACD,OAAO,MAAMC,qBAAuC,CAACC;IACnD,MAAM,CAACC,aAAaC,eAAe,GAAGL,SAAS;IAC/C,MAAMM,eAAeP,OAAuB;IAC5C,MAAMQ,kBAAkBR,OAA6C;IAErED,UAAU;QACR,M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= (props) => {
|
|
|
39
39
|
unmountTimerRef.current = setTimeout(() => {
|
|
40
40
|
setShouldMount(false);
|
|
41
41
|
unmountTimerRef.current = null;
|
|
42
|
-
}, 1200); //
|
|
42
|
+
}, 1200); // 1200ms delay to prevent rapid remounting
|
|
43
43
|
}
|
|
44
44
|
break;
|
|
45
45
|
}
|
|
@@ -103,11 +103,9 @@
|
|
|
103
103
|
pointer-events: auto;
|
|
104
104
|
max-height: 100px;
|
|
105
105
|
transform: scaleY(1) skewX(0) translateY(0) translateZ(0);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
padding: 0;
|
|
110
|
-
/* flex-direction: row-reverse; - Reverted */
|
|
106
|
+
|
|
107
|
+
margin: 5px 0;
|
|
108
|
+
padding: 5px 0;
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
.actions.actionsVisible > * {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { BaseItemProps } from '
|
|
2
|
+
import type { BaseItemProps } from './types.js';
|
|
3
3
|
export declare const Item: React.FC<BaseItemProps>;
|
|
4
4
|
export declare const createMenuItem: (IconComponent: React.ComponentType<{
|
|
5
5
|
size?: number;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation } from '@payloadcms/ui';
|
|
2
3
|
import React, { memo } from 'react';
|
|
3
4
|
import { ArrowIcon } from '../../../Icons/Icons.js';
|
|
4
5
|
import styles from './menu.module.scss';
|
|
@@ -11,7 +12,9 @@ export const Item = /*#__PURE__*/ memo(({ children, disabled, isActive, onClick,
|
|
|
11
12
|
...rest,
|
|
12
13
|
children: children
|
|
13
14
|
}));
|
|
14
|
-
export const createMenuItem = (IconComponent, initialText)=>/*#__PURE__*/ memo(({ children, disabled, hideIcon, isMenu, onClick, ...rest })
|
|
15
|
+
export const createMenuItem = (IconComponent, initialText)=>/*#__PURE__*/ memo(({ children, disabled, hideIcon, isMenu, onClick, ...rest })=>{
|
|
16
|
+
const { t } = useTranslation();
|
|
17
|
+
return /*#__PURE__*/ _jsxs(Item, {
|
|
15
18
|
disabled: disabled,
|
|
16
19
|
onClick: onClick,
|
|
17
20
|
...rest,
|
|
@@ -21,12 +24,13 @@ export const createMenuItem = (IconComponent, initialText)=>/*#__PURE__*/ memo((
|
|
|
21
24
|
}),
|
|
22
25
|
children || /*#__PURE__*/ _jsx("span", {
|
|
23
26
|
className: styles.text,
|
|
24
|
-
children: initialText
|
|
27
|
+
children: t(`ai-plugin:actions:${initialText.toLowerCase()}`)
|
|
25
28
|
}),
|
|
26
29
|
isMenu && /*#__PURE__*/ _jsx(ArrowIcon, {
|
|
27
30
|
size: 18
|
|
28
31
|
})
|
|
29
32
|
]
|
|
30
|
-
})
|
|
33
|
+
});
|
|
34
|
+
});
|
|
31
35
|
|
|
32
36
|
//# sourceMappingURL=Item.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/ui/Compose/hooks/menu/Item.tsx"],"sourcesContent":["import React, { memo } from 'react'\n\nimport type { BaseItemProps } from '
|
|
1
|
+
{"version":3,"sources":["../../../../../src/ui/Compose/hooks/menu/Item.tsx"],"sourcesContent":["import { useTranslation } from '@payloadcms/ui'\nimport React, { memo } from 'react'\n\nimport type { PluginAITranslationKeys, PluginAITranslations } from '../../../../translations/index.js'\nimport type { BaseItemProps } from './types.js'\n\nimport { ArrowIcon } from '../../../Icons/Icons.js'\nimport styles from './menu.module.scss'\n\nexport const Item: React.FC<BaseItemProps> = memo(\n ({ children, disabled, isActive, onClick, ...rest }) => (\n <span\n className={styles.generate_button + ' ' + (isActive ? styles.active : '')}\n data-disabled={disabled}\n onClick={\n !disabled && typeof onClick === 'function'\n ? (onClick as React.MouseEventHandler<HTMLSpanElement>)\n : undefined\n }\n onKeyDown={\n !disabled && typeof onClick === 'function'\n ? (onClick as React.KeyboardEventHandler<HTMLSpanElement>)\n : undefined\n }\n role=\"presentation\"\n {...rest}\n >\n {children}\n </span>\n ),\n)\n\nexport const createMenuItem = (\n IconComponent: React.ComponentType<{ size?: number }>,\n initialText: string,\n) =>\n memo(({ children, disabled, hideIcon, isMenu, onClick, ...rest }: BaseItemProps) => {\n const { t } = useTranslation<PluginAITranslations, PluginAITranslationKeys>()\n return (\n <Item disabled={disabled} onClick={onClick} {...rest}>\n {hideIcon || <IconComponent size={18} />}\n {children || (\n <span className={styles.text}>\n {t(`ai-plugin:actions:${initialText.toLowerCase()}` as any)}\n </span>\n )}\n {isMenu && <ArrowIcon size={18} />}\n </Item>\n )\n })\n"],"names":["useTranslation","React","memo","ArrowIcon","styles","Item","children","disabled","isActive","onClick","rest","span","className","generate_button","active","data-disabled","undefined","onKeyDown","role","createMenuItem","IconComponent","initialText","hideIcon","isMenu","t","size","text","toLowerCase"],"mappings":";AAAA,SAASA,cAAc,QAAQ,iBAAgB;AAC/C,OAAOC,SAASC,IAAI,QAAQ,QAAO;AAKnC,SAASC,SAAS,QAAQ,0BAAyB;AACnD,OAAOC,YAAY,qBAAoB;AAEvC,OAAO,MAAMC,qBAAgCH,KAC3C,CAAC,EAAEI,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,OAAO,EAAE,GAAGC,MAAM,iBACjD,KAACC;QACCC,WAAWR,OAAOS,eAAe,GAAG,MAAOL,CAAAA,WAAWJ,OAAOU,MAAM,GAAG,EAAC;QACvEC,iBAAeR;QACfE,SACE,CAACF,YAAY,OAAOE,YAAY,aAC3BA,UACDO;QAENC,WACE,CAACV,YAAY,OAAOE,YAAY,aAC3BA,UACDO;QAENE,MAAK;QACJ,GAAGR,IAAI;kBAEPJ;QAGN;AAED,OAAO,MAAMa,iBAAiB,CAC5BC,eACAC,4BAEAnB,KAAK,CAAC,EAAEI,QAAQ,EAAEC,QAAQ,EAAEe,QAAQ,EAAEC,MAAM,EAAEd,OAAO,EAAE,GAAGC,MAAqB;QAC7E,MAAM,EAAEc,CAAC,EAAE,GAAGxB;QACd,qBACE,MAACK;YAAKE,UAAUA;YAAUE,SAASA;YAAU,GAAGC,IAAI;;gBACjDY,0BAAY,KAACF;oBAAcK,MAAM;;gBACjCnB,0BACC,KAACK;oBAAKC,WAAWR,OAAOsB,IAAI;8BACzBF,EAAE,CAAC,kBAAkB,EAAEH,YAAYM,WAAW,GAAG,CAAC;;gBAGtDJ,wBAAU,KAACpB;oBAAUsB,MAAM;;;;IAGlC,GAAE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useTranslation } from '@payloadcms/ui';
|
|
1
2
|
import React, { memo } from 'react';
|
|
2
3
|
import { ArrowIcon } from '../../../Icons/Icons.js';
|
|
3
4
|
import styles from './menu.module.scss';
|
|
@@ -8,8 +9,13 @@ export const Item = memo(({ children, disabled, isActive, onClick, ...rest }) =>
|
|
|
8
9
|
: undefined} role="presentation" {...rest}>
|
|
9
10
|
{children}
|
|
10
11
|
</span>));
|
|
11
|
-
export const createMenuItem = (IconComponent, initialText) => memo(({ children, disabled, hideIcon, isMenu, onClick, ...rest }) =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
export const createMenuItem = (IconComponent, initialText) => memo(({ children, disabled, hideIcon, isMenu, onClick, ...rest }) => {
|
|
13
|
+
const { t } = useTranslation();
|
|
14
|
+
return (<Item disabled={disabled} onClick={onClick} {...rest}>
|
|
15
|
+
{hideIcon || <IconComponent size={18}/>}
|
|
16
|
+
{children || (<span className={styles.text}>
|
|
17
|
+
{t(`ai-plugin:actions:${initialText.toLowerCase()}`)}
|
|
18
|
+
</span>)}
|
|
19
|
+
{isMenu && <ArrowIcon size={18}/>}
|
|
20
|
+
</Item>);
|
|
21
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation } from '@payloadcms/ui';
|
|
2
3
|
import locales from 'locale-codes';
|
|
3
4
|
import React, { memo, useEffect, useRef, useState } from 'react';
|
|
4
5
|
import { useInstructions } from '../../../../providers/InstructionsProvider/useInstructions.js';
|
|
@@ -6,6 +7,7 @@ import { Item } from './Item.js';
|
|
|
6
7
|
import { Translate } from './items.js';
|
|
7
8
|
import styles from './menu.module.scss';
|
|
8
9
|
export const TranslateMenu = ({ onClick })=>{
|
|
10
|
+
const { t } = useTranslation();
|
|
9
11
|
const [show, setShow] = useState(false);
|
|
10
12
|
const closeTimeoutRef = useRef(null);
|
|
11
13
|
const { enabledLanguages = [] } = useInstructions();
|
|
@@ -40,21 +42,29 @@ export const TranslateMenu = ({ onClick })=>{
|
|
|
40
42
|
onBlur: (e)=>{
|
|
41
43
|
// Only clear if focus moves outside the menu container
|
|
42
44
|
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
43
|
-
if (typeof window !== 'undefined')
|
|
45
|
+
if (typeof window !== 'undefined') {
|
|
46
|
+
window.__AI_MENU_INTERACTIVE = false;
|
|
47
|
+
}
|
|
44
48
|
}
|
|
45
49
|
},
|
|
46
50
|
onFocus: ()=>{
|
|
47
|
-
if (typeof window !== 'undefined')
|
|
51
|
+
if (typeof window !== 'undefined') {
|
|
52
|
+
window.__AI_MENU_INTERACTIVE = true;
|
|
53
|
+
}
|
|
48
54
|
},
|
|
49
55
|
onMouseEnter: ()=>{
|
|
50
56
|
if (closeTimeoutRef.current) {
|
|
51
57
|
clearTimeout(closeTimeoutRef.current);
|
|
52
58
|
closeTimeoutRef.current = null;
|
|
53
59
|
}
|
|
54
|
-
if (typeof window !== 'undefined')
|
|
60
|
+
if (typeof window !== 'undefined') {
|
|
61
|
+
window.__AI_MENU_INTERACTIVE = true;
|
|
62
|
+
}
|
|
55
63
|
},
|
|
56
64
|
onMouseLeave: ()=>{
|
|
57
|
-
if (typeof window !== 'undefined')
|
|
65
|
+
if (typeof window !== 'undefined') {
|
|
66
|
+
window.__AI_MENU_INTERACTIVE = false;
|
|
67
|
+
}
|
|
58
68
|
if (!inputFocus) {
|
|
59
69
|
closeTimeoutRef.current = setTimeout(()=>{
|
|
60
70
|
setShow(false);
|
|
@@ -98,7 +108,7 @@ export const TranslateMenu = ({ onClick })=>{
|
|
|
98
108
|
}));
|
|
99
109
|
},
|
|
100
110
|
onFocus: ()=>setInputFocus(true),
|
|
101
|
-
placeholder:
|
|
111
|
+
placeholder: t('ai-plugin:general:search')
|
|
102
112
|
})
|
|
103
113
|
}),
|
|
104
114
|
languages.map((locale)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/ui/Compose/hooks/menu/TranslateMenu.tsx"],"sourcesContent":["import locales from 'locale-codes'\nimport React, { memo, useEffect, useRef, useState } from 'react'\n\nimport { useInstructions } from '../../../../providers/InstructionsProvider/useInstructions.js'\nimport { Item } from './Item.js'\nimport { Translate } from './items.js'\nimport styles from './menu.module.scss'\n\ndeclare global {\n interface Window {\n __AI_MENU_INTERACTIVE?: boolean\n }\n}\n\nexport const TranslateMenu = ({ onClick }: { onClick: (data: { locale: string }) => void }) => {\n const [show, setShow] = useState(false)\n const closeTimeoutRef = useRef<NodeJS.Timeout | null>(null)\n\n const { enabledLanguages = [] } = useInstructions()\n\n let filteredLocales = locales.all.filter((a) => {\n return a.tag && a.location\n })\n\n if (enabledLanguages?.length) {\n filteredLocales = filteredLocales.filter((a) => enabledLanguages?.includes(a.tag))\n }\n\n const [languages, setLanguages] = useState(filteredLocales)\n const [inputFocus, setInputFocus] = useState(false)\n\n useEffect(() => {\n if (!show) {\n if (typeof window !== 'undefined') {\n window.__AI_MENU_INTERACTIVE = false\n }\n }\n return () => {\n if (closeTimeoutRef.current) {\n clearTimeout(closeTimeoutRef.current)\n }\n if (show && typeof window !== 'undefined') {\n window.__AI_MENU_INTERACTIVE = false\n }\n }\n }, [show])\n\n return (\n <div\n className={`${styles.menu} ai-interactive-menu`}\n data-ai-interactive=\"true\"\n onBlur={(e) => {\n // Only clear if focus moves outside the menu container\n if (!e.currentTarget.contains(e.relatedTarget as Node)) {\n if (typeof window !== 'undefined') window.__AI_MENU_INTERACTIVE = false\n }\n }}\n onFocus={() => {\n if (typeof window !== 'undefined') window.__AI_MENU_INTERACTIVE = true\n }}\n onMouseEnter={() => {\n if (closeTimeoutRef.current) {\n clearTimeout(closeTimeoutRef.current)\n closeTimeoutRef.current = null\n }\n if (typeof window !== 'undefined') window.__AI_MENU_INTERACTIVE = true\n }}\n onMouseLeave={() => {\n if (typeof window !== 'undefined') window.__AI_MENU_INTERACTIVE = false\n if (!inputFocus) {\n closeTimeoutRef.current = setTimeout(() => {\n setShow(false)\n }, 400)\n }\n }}\n >\n <Translate\n isActive={show}\n isMenu\n onClick={() => {\n setShow(!show)\n }}\n />\n <div className={styles.hoverMenu} data-show={show}>\n <div\n className={`${styles.menu} ${styles.subMenu}`}\n style={{\n background: 'var(--popup-bg)',\n // minHeight: '300px',\n }}\n >\n <Item\n onClick={() => {}}\n style={{\n background: 'transparent',\n padding: '0 0 5px 0',\n position: 'sticky',\n top: 0,\n }}\n >\n <input\n className={`${styles.menuInput} ai-interactive-menu`}\n data-ai-interactive=\"true\"\n onBlur={() => setInputFocus(false)}\n onChange={(event) => {\n const value = event.target.value\n setLanguages(\n filteredLocales.filter((l) => {\n const lowerCaseValue = value.toLowerCase()\n return (\n l.name.toLowerCase().startsWith(lowerCaseValue) ||\n (l.location && l.location.toLowerCase().startsWith(lowerCaseValue)) ||\n l.tag.toLowerCase().startsWith(lowerCaseValue)\n )\n }),\n )\n }}\n onFocus={() => setInputFocus(true)}\n placeholder
|
|
1
|
+
{"version":3,"sources":["../../../../../src/ui/Compose/hooks/menu/TranslateMenu.tsx"],"sourcesContent":["import { useTranslation } from '@payloadcms/ui'\nimport locales from 'locale-codes'\nimport React, { memo, useEffect, useRef, useState } from 'react'\n\nimport type { PluginAITranslationKeys, PluginAITranslations } from '../../../../translations/index.js'\n\nimport { useInstructions } from '../../../../providers/InstructionsProvider/useInstructions.js'\nimport { Item } from './Item.js'\nimport { Translate } from './items.js'\nimport styles from './menu.module.scss'\n\ndeclare global {\n interface Window {\n __AI_MENU_INTERACTIVE?: boolean\n }\n}\n\nexport const TranslateMenu = ({ onClick }: { onClick: (data: { locale: string }) => void }) => {\n const { t } = useTranslation<PluginAITranslations, PluginAITranslationKeys>()\n const [show, setShow] = useState(false)\n const closeTimeoutRef = useRef<NodeJS.Timeout | null>(null)\n\n const { enabledLanguages = [] } = useInstructions()\n\n let filteredLocales = locales.all.filter((a) => {\n return a.tag && a.location\n })\n\n if (enabledLanguages?.length) {\n filteredLocales = filteredLocales.filter((a) => enabledLanguages?.includes(a.tag))\n }\n\n const [languages, setLanguages] = useState(filteredLocales)\n const [inputFocus, setInputFocus] = useState(false)\n\n useEffect(() => {\n if (!show) {\n if (typeof window !== 'undefined') {\n window.__AI_MENU_INTERACTIVE = false\n }\n }\n return () => {\n if (closeTimeoutRef.current) {\n clearTimeout(closeTimeoutRef.current)\n }\n if (show && typeof window !== 'undefined') {\n window.__AI_MENU_INTERACTIVE = false\n }\n }\n }, [show])\n\n return (\n <div\n className={`${styles.menu} ai-interactive-menu`}\n data-ai-interactive=\"true\"\n onBlur={(e) => {\n // Only clear if focus moves outside the menu container\n if (!e.currentTarget.contains(e.relatedTarget as Node)) {\n if (typeof window !== 'undefined') {window.__AI_MENU_INTERACTIVE = false}\n }\n }}\n onFocus={() => {\n if (typeof window !== 'undefined') {window.__AI_MENU_INTERACTIVE = true}\n }}\n onMouseEnter={() => {\n if (closeTimeoutRef.current) {\n clearTimeout(closeTimeoutRef.current)\n closeTimeoutRef.current = null\n }\n if (typeof window !== 'undefined') {window.__AI_MENU_INTERACTIVE = true}\n }}\n onMouseLeave={() => {\n if (typeof window !== 'undefined') {window.__AI_MENU_INTERACTIVE = false}\n if (!inputFocus) {\n closeTimeoutRef.current = setTimeout(() => {\n setShow(false)\n }, 400)\n }\n }}\n >\n <Translate\n isActive={show}\n isMenu\n onClick={() => {\n setShow(!show)\n }}\n />\n <div className={styles.hoverMenu} data-show={show}>\n <div\n className={`${styles.menu} ${styles.subMenu}`}\n style={{\n background: 'var(--popup-bg)',\n // minHeight: '300px',\n }}\n >\n <Item\n onClick={() => {}}\n style={{\n background: 'transparent',\n padding: '0 0 5px 0',\n position: 'sticky',\n top: 0,\n }}\n >\n <input\n className={`${styles.menuInput} ai-interactive-menu`}\n data-ai-interactive=\"true\"\n onBlur={() => setInputFocus(false)}\n onChange={(event) => {\n const value = event.target.value\n setLanguages(\n filteredLocales.filter((l) => {\n const lowerCaseValue = value.toLowerCase()\n return (\n l.name.toLowerCase().startsWith(lowerCaseValue) ||\n (l.location && l.location.toLowerCase().startsWith(lowerCaseValue)) ||\n l.tag.toLowerCase().startsWith(lowerCaseValue)\n )\n }),\n )\n }}\n onFocus={() => setInputFocus(true)}\n placeholder={t('ai-plugin:general:search')}\n />\n </Item>\n {languages.map((locale) => {\n return (\n <Item\n className=\"ai-interactive-menu\"\n data-ai-interactive=\"true\"\n key={locale.tag}\n onClick={() => {\n onClick({ locale: locale.tag })\n }}\n >\n <span className={styles.ellipsis}>{`${locale.location} (${locale.tag})`}</span>\n </Item>\n )\n })}\n </div>\n </div>\n </div>\n )\n}\n\nexport const MemoizedTranslateMenu = memo(TranslateMenu)\n"],"names":["useTranslation","locales","React","memo","useEffect","useRef","useState","useInstructions","Item","Translate","styles","TranslateMenu","onClick","t","show","setShow","closeTimeoutRef","enabledLanguages","filteredLocales","all","filter","a","tag","location","length","includes","languages","setLanguages","inputFocus","setInputFocus","window","__AI_MENU_INTERACTIVE","current","clearTimeout","div","className","menu","data-ai-interactive","onBlur","e","currentTarget","contains","relatedTarget","onFocus","onMouseEnter","onMouseLeave","setTimeout","isActive","isMenu","hoverMenu","data-show","subMenu","style","background","padding","position","top","input","menuInput","onChange","event","value","target","l","lowerCaseValue","toLowerCase","name","startsWith","placeholder","map","locale","span","ellipsis","MemoizedTranslateMenu"],"mappings":";AAAA,SAASA,cAAc,QAAQ,iBAAgB;AAC/C,OAAOC,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,iBAAiBH,MAAMI,WAAW;wCACxC,OACEF,EAAEG,IAAI,CAACD,WAAW,GAAGE,UAAU,CAACH,mBAC/BD,EAAExC,QAAQ,IAAIwC,EAAExC,QAAQ,CAAC0C,WAAW,GAAGE,UAAU,CAACH,mBACnDD,EAAEzC,GAAG,CAAC2C,WAAW,GAAGE,UAAU,CAACH;oCAEnC;gCAEJ;gCACArB,SAAS,IAAMd,cAAc;gCAC7BuC,aAAavD,EAAE;;;wBAGlBa,UAAU2C,GAAG,CAAC,CAACC;4BACd,qBACE,KAAC9D;gCACC2B,WAAU;gCACVE,uBAAoB;gCAEpBzB,SAAS;oCACPA,QAAQ;wCAAE0D,QAAQA,OAAOhD,GAAG;oCAAC;gCAC/B;0CAEA,cAAA,KAACiD;oCAAKpC,WAAWzB,OAAO8D,QAAQ;8CAAG,CAAC,EAAEF,OAAO/C,QAAQ,CAAC,EAAE,EAAE+C,OAAOhD,GAAG,CAAC,CAAC,CAAC;;+BALlEgD,OAAOhD,GAAG;wBAQrB;;;;;;AAKV,EAAC;AAED,OAAO,MAAMmD,sCAAwBtE,KAAKQ,eAAc"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useTranslation } from '@payloadcms/ui';
|
|
1
2
|
import locales from 'locale-codes';
|
|
2
3
|
import React, { memo, useEffect, useRef, useState } from 'react';
|
|
3
4
|
import { useInstructions } from '../../../../providers/InstructionsProvider/useInstructions.js';
|
|
@@ -5,6 +6,7 @@ import { Item } from './Item.js';
|
|
|
5
6
|
import { Translate } from './items.js';
|
|
6
7
|
import styles from './menu.module.scss';
|
|
7
8
|
export const TranslateMenu = ({ onClick }) => {
|
|
9
|
+
const { t } = useTranslation();
|
|
8
10
|
const [show, setShow] = useState(false);
|
|
9
11
|
const closeTimeoutRef = useRef(null);
|
|
10
12
|
const { enabledLanguages = [] } = useInstructions();
|
|
@@ -34,22 +36,26 @@ export const TranslateMenu = ({ onClick }) => {
|
|
|
34
36
|
return (<div className={`${styles.menu} ai-interactive-menu`} data-ai-interactive="true" onBlur={(e) => {
|
|
35
37
|
// Only clear if focus moves outside the menu container
|
|
36
38
|
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
37
|
-
if (typeof window !== 'undefined')
|
|
39
|
+
if (typeof window !== 'undefined') {
|
|
38
40
|
window.__AI_MENU_INTERACTIVE = false;
|
|
41
|
+
}
|
|
39
42
|
}
|
|
40
43
|
}} onFocus={() => {
|
|
41
|
-
if (typeof window !== 'undefined')
|
|
44
|
+
if (typeof window !== 'undefined') {
|
|
42
45
|
window.__AI_MENU_INTERACTIVE = true;
|
|
46
|
+
}
|
|
43
47
|
}} onMouseEnter={() => {
|
|
44
48
|
if (closeTimeoutRef.current) {
|
|
45
49
|
clearTimeout(closeTimeoutRef.current);
|
|
46
50
|
closeTimeoutRef.current = null;
|
|
47
51
|
}
|
|
48
|
-
if (typeof window !== 'undefined')
|
|
52
|
+
if (typeof window !== 'undefined') {
|
|
49
53
|
window.__AI_MENU_INTERACTIVE = true;
|
|
54
|
+
}
|
|
50
55
|
}} onMouseLeave={() => {
|
|
51
|
-
if (typeof window !== 'undefined')
|
|
56
|
+
if (typeof window !== 'undefined') {
|
|
52
57
|
window.__AI_MENU_INTERACTIVE = false;
|
|
58
|
+
}
|
|
53
59
|
if (!inputFocus) {
|
|
54
60
|
closeTimeoutRef.current = setTimeout(() => {
|
|
55
61
|
setShow(false);
|
|
@@ -78,7 +84,7 @@ export const TranslateMenu = ({ onClick }) => {
|
|
|
78
84
|
(l.location && l.location.toLowerCase().startsWith(lowerCaseValue)) ||
|
|
79
85
|
l.tag.toLowerCase().startsWith(lowerCaseValue));
|
|
80
86
|
}));
|
|
81
|
-
}} onFocus={() => setInputFocus(true)} placeholder=
|
|
87
|
+
}} onFocus={() => setInputFocus(true)} placeholder={t('ai-plugin:general:search')}/>
|
|
82
88
|
</Item>
|
|
83
89
|
{languages.map((locale) => {
|
|
84
90
|
return (<Item className="ai-interactive-menu" data-ai-interactive="true" key={locale.tag} onClick={() => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export declare const Proofread: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("
|
|
2
|
-
export declare const Rephrase: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("
|
|
3
|
-
export declare const Translate: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("
|
|
4
|
-
export declare const Expand: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("
|
|
5
|
-
export declare const Summarize: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("
|
|
6
|
-
export declare const Simplify: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("
|
|
7
|
-
export declare const Compose: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("
|
|
8
|
-
export declare const Settings: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("
|
|
1
|
+
export declare const Proofread: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("./types.js").BaseItemProps) => import("react").JSX.Element>;
|
|
2
|
+
export declare const Rephrase: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("./types.js").BaseItemProps) => import("react").JSX.Element>;
|
|
3
|
+
export declare const Translate: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("./types.js").BaseItemProps) => import("react").JSX.Element>;
|
|
4
|
+
export declare const Expand: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("./types.js").BaseItemProps) => import("react").JSX.Element>;
|
|
5
|
+
export declare const Summarize: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("./types.js").BaseItemProps) => import("react").JSX.Element>;
|
|
6
|
+
export declare const Simplify: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("./types.js").BaseItemProps) => import("react").JSX.Element>;
|
|
7
|
+
export declare const Compose: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("./types.js").BaseItemProps) => import("react").JSX.Element>;
|
|
8
|
+
export declare const Settings: import("react").MemoExoticComponent<({ children, disabled, hideIcon, isMenu, onClick, ...rest }: import("./types.js").BaseItemProps) => import("react").JSX.Element>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
import type { ActionMenuItems
|
|
2
|
+
import type { ActionMenuItems } from '../../../../types.js';
|
|
3
|
+
import type { BaseItemProps } from './types.js';
|
|
3
4
|
type MenuItemsMapType = {
|
|
4
5
|
component: React.FC<BaseItemProps>;
|
|
5
6
|
excludedFor?: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/ui/Compose/hooks/menu/itemsMap.ts"],"sourcesContent":["import type React from 'react'\n\nimport type { ActionMenuItems
|
|
1
|
+
{"version":3,"sources":["../../../../../src/ui/Compose/hooks/menu/itemsMap.ts"],"sourcesContent":["import type React from 'react'\n\nimport type { ActionMenuItems } from '../../../../types.js'\nimport type { BaseItemProps } from './types.js'\n\nimport { Compose, Expand, Proofread, Rephrase, Settings, Simplify, Summarize } from './items.js'\nimport { MemoizedTranslateMenu, TranslateMenu } from './TranslateMenu.js'\n\ntype MenuItemsMapType = {\n component: React.FC<BaseItemProps>\n excludedFor?: string[]\n loadingText?: string\n name: ActionMenuItems\n}\n\nexport const menuItemsMap: MenuItemsMapType[] = [\n { name: 'Proofread', component: Proofread, excludedFor: ['upload', 'array'], loadingText: 'Proofreading' },\n { name: 'Rephrase', component: Rephrase, excludedFor: ['upload', 'array'], loadingText: 'Rephrasing' },\n {\n name: 'Translate',\n component: MemoizedTranslateMenu,\n excludedFor: ['upload', 'array'],\n loadingText: 'Translating',\n },\n { name: 'Expand', component: Expand, excludedFor: ['upload', 'text', 'array'], loadingText: 'Expanding' },\n {\n // Turned off - WIP\n name: 'Summarize',\n component: Summarize,\n excludedFor: ['upload', 'text', 'richText', 'array'],\n loadingText: 'Summarizing',\n },\n { name: 'Simplify', component: Simplify, excludedFor: ['upload', 'array'], loadingText: 'Simplifying' },\n { name: 'Compose', component: Compose, loadingText: 'Composing' },\n { name: 'Settings', component: Settings },\n]\n"],"names":["Compose","Expand","Proofread","Rephrase","Settings","Simplify","Summarize","MemoizedTranslateMenu","menuItemsMap","name","component","excludedFor","loadingText"],"mappings":"AAKA,SAASA,OAAO,EAAEC,MAAM,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,aAAY;AAChG,SAASC,qBAAqB,QAAuB,qBAAoB;AASzE,OAAO,MAAMC,eAAmC;IAC9C;QAAEC,MAAM;QAAaC,WAAWR;QAAWS,aAAa;YAAC;YAAU;SAAQ;QAAEC,aAAa;IAAe;IACzG;QAAEH,MAAM;QAAYC,WAAWP;QAAUQ,aAAa;YAAC;YAAU;SAAQ;QAAEC,aAAa;IAAa;IACrG;QACEH,MAAM;QACNC,WAAWH;QACXI,aAAa;YAAC;YAAU;SAAQ;QAChCC,aAAa;IACf;IACA;QAAEH,MAAM;QAAUC,WAAWT;QAAQU,aAAa;YAAC;YAAU;YAAQ;SAAQ;QAAEC,aAAa;IAAY;IACxG;QACE,mBAAmB;QACnBH,MAAM;QACNC,WAAWJ;QACXK,aAAa;YAAC;YAAU;YAAQ;YAAY;SAAQ;QACpDC,aAAa;IACf;IACA;QAAEH,MAAM;QAAYC,WAAWL;QAAUM,aAAa;YAAC;YAAU;SAAQ;QAAEC,aAAa;IAAc;IACtG;QAAEH,MAAM;QAAWC,WAAWV;QAASY,aAAa;IAAY;IAChE;QAAEH,MAAM;QAAYC,WAAWN;IAAS;CACzC,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CSSProperties, MouseEventHandler } from 'react';
|
|
2
|
+
export type ActionMenuEvents = 'onCompose' | 'onExpand' | 'onProofread' | 'onRephrase' | 'onSettings' | 'onSimplify' | 'onSummarize' | 'onTone' | 'onTranslate';
|
|
3
|
+
export type UseMenuEvents = {
|
|
4
|
+
[key in ActionMenuEvents]?: (data?: unknown) => void;
|
|
5
|
+
};
|
|
6
|
+
export type UseMenuOptions = {
|
|
7
|
+
isConfigAllowed: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type BaseItemProps<T = unknown> = {
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
hideIcon?: boolean;
|
|
14
|
+
isActive?: boolean;
|
|
15
|
+
isMenu?: boolean;
|
|
16
|
+
onClick: (data?: unknown) => void;
|
|
17
|
+
onMouseEnter?: MouseEventHandler<T> | undefined;
|
|
18
|
+
onMouseLeave?: MouseEventHandler<T> | undefined;
|
|
19
|
+
style?: CSSProperties | undefined;
|
|
20
|
+
title?: string;
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/ui/Compose/hooks/menu/types.ts"],"sourcesContent":["import type { CSSProperties, MouseEventHandler } from 'react'\n\n\nexport type ActionMenuEvents =\n | 'onCompose'\n | 'onExpand'\n | 'onProofread'\n | 'onRephrase'\n | 'onSettings'\n | 'onSimplify'\n | 'onSummarize'\n | 'onTone'\n | 'onTranslate'\n\nexport type UseMenuEvents = {\n [key in ActionMenuEvents]?: (data?: unknown) => void\n}\n\nexport type UseMenuOptions = {\n isConfigAllowed: boolean\n}\n\nexport type BaseItemProps<T = unknown> = {\n children?: React.ReactNode\n className?: string\n disabled?: boolean\n hideIcon?: boolean\n isActive?: boolean\n isMenu?: boolean\n onClick: (data?: unknown) => void\n onMouseEnter?: MouseEventHandler<T> | undefined\n onMouseLeave?: MouseEventHandler<T> | undefined\n style?: CSSProperties | undefined\n title?: string\n}\n"],"names":[],"mappings":"AAsBA,WAYC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { UseMenuEvents, UseMenuOptions } from '
|
|
2
|
+
import type { UseMenuEvents, UseMenuOptions } from './types.js';
|
|
3
3
|
export declare const useMenu: (menuEvents: UseMenuEvents, options: UseMenuOptions) => {
|
|
4
|
-
ActiveComponent: ({ isLoading, loadingLabel, stop }: {
|
|
4
|
+
ActiveComponent: ({ isLoading, loadingLabel, stop, }: {
|
|
5
5
|
isLoading: boolean;
|
|
6
6
|
loadingLabel?: string;
|
|
7
7
|
stop: () => void;
|