@jhb.software/payload-alt-text-plugin 0.2.2 → 0.3.1

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.
Files changed (56) hide show
  1. package/README.md +93 -22
  2. package/dist/components/AltTextField.js +6 -6
  3. package/dist/components/AltTextField.js.map +1 -1
  4. package/dist/components/BulkGenerateAltTextsButton.js +15 -16
  5. package/dist/components/BulkGenerateAltTextsButton.js.map +1 -1
  6. package/dist/components/GenerateAltTextButton.js +24 -25
  7. package/dist/components/GenerateAltTextButton.js.map +1 -1
  8. package/dist/components/icons/Lightning.js +4 -4
  9. package/dist/components/icons/Lightning.js.map +1 -1
  10. package/dist/components/icons/Spinner.js +11 -11
  11. package/dist/components/icons/Spinner.js.map +1 -1
  12. package/dist/endpoints/bulkGenerateAltTexts.js +30 -77
  13. package/dist/endpoints/bulkGenerateAltTexts.js.map +1 -1
  14. package/dist/endpoints/generateAltText.d.ts +1 -1
  15. package/dist/endpoints/generateAltText.js +19 -74
  16. package/dist/endpoints/generateAltText.js.map +1 -1
  17. package/dist/exports/client.d.ts +1 -1
  18. package/dist/exports/client.js +1 -1
  19. package/dist/exports/client.js.map +1 -1
  20. package/dist/fields/altTextField.js +20 -15
  21. package/dist/fields/altTextField.js.map +1 -1
  22. package/dist/fields/keywordsField.js +7 -7
  23. package/dist/fields/keywordsField.js.map +1 -1
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.js +2 -0
  26. package/dist/index.js.map +1 -1
  27. package/dist/plugin.js +24 -32
  28. package/dist/plugin.js.map +1 -1
  29. package/dist/resolvers/openAI.d.ts +24 -0
  30. package/dist/resolvers/openAI.js +177 -0
  31. package/dist/resolvers/openAI.js.map +1 -0
  32. package/dist/resolvers/types.d.ts +68 -0
  33. package/dist/resolvers/types.js +6 -0
  34. package/dist/resolvers/types.js.map +1 -0
  35. package/dist/translations/de.d.ts +1 -1
  36. package/dist/translations/de.js +3 -3
  37. package/dist/translations/de.js.map +1 -1
  38. package/dist/translations/en.d.ts +1 -1
  39. package/dist/translations/en.js +3 -3
  40. package/dist/translations/en.js.map +1 -1
  41. package/dist/types/AltTextPluginConfig.d.ts +28 -26
  42. package/dist/types/AltTextPluginConfig.js.map +1 -1
  43. package/dist/utilities/localesFromConfig.d.ts +1 -1
  44. package/dist/utilities/localesFromConfig.js.map +1 -1
  45. package/dist/utils/translatedLabel.d.ts +1 -1
  46. package/dist/utils/translatedLabel.js.map +1 -1
  47. package/package.json +20 -18
  48. package/dist/utilities/getGenerationCost.d.ts +0 -12
  49. package/dist/utilities/getGenerationCost.js +0 -30
  50. package/dist/utilities/getGenerationCost.js.map +0 -1
  51. package/dist/utilities/zodResponseFormat.d.ts +0 -11
  52. package/dist/utilities/zodResponseFormat.js +0 -23
  53. package/dist/utilities/zodResponseFormat.js.map +0 -1
  54. package/dist/utils/usePluginTranslation.d.ts +0 -5
  55. package/dist/utils/usePluginTranslation.js +0 -16
  56. package/dist/utils/usePluginTranslation.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/AltTextPluginConfig.ts"],"sourcesContent":["import { CollectionSlug, Field } from 'payload'\n\n/** Configuration options for the alt text plugin. */\nexport type IncomingAltTextPluginConfig = {\n /** Whether the plugin is enabled. */\n enabled?: boolean\n\n /** OpenAI API key for authentication. */\n openAIApiKey: string\n\n /** Collection slugs to enable the plugin for. */\n collections: CollectionSlug[]\n\n /** Maximum number of concurrent API requests for bulk operations. */\n maxBulkGenerateConcurrency?: number\n\n /**\n * Function to get the thumbnail URL of an image document.\n * This URL will be sent to the LLM for analysis.\n *\n * @remarks\n * - The URL must be publicly accessible so the LLM can fetch it\n * - Use a thumbnail/preview version of the image when possible (e.g. from the sizes field)\n */\n getImageThumbnail: (doc: Record<string, unknown>) => string\n\n /** The OpenAI LLM model to use for alt text generation. */\n model?: 'gpt-4.1-nano' | 'gpt-4.1-mini'\n\n /** Override the default fields inserted by the plugin via a function that receives the default fields and returns the new fields */\n fieldsOverride?: (args: { defaultFields: Field[] }) => Field[]\n\n /**\n * The locale to generate alt texts in when localization is disabled.\n * Required when localization is disabled, ignored when localization is enabled.\n * @example 'en', 'de'\n */\n locale?: string\n}\n\n/** Configuration of the alt text plugin after defaults have been applied. */\nexport type AltTextPluginConfig = {\n /** Whether the plugin is enabled. */\n enabled: boolean\n\n /** OpenAI API key for authentication. */\n openAIApiKey: string\n\n /** Collection slugs to enable the plugin for. */\n collections: CollectionSlug[]\n\n /** Maximum number of concurrent API requests for bulk generate operations. */\n maxBulkGenerateConcurrency: number\n\n /** Function to get the thumbnail URL of an image document. */\n getImageThumbnail: (doc: Record<string, unknown>) => string\n\n /** The OpenAI LLM model to use for alt text generation. */\n model: 'gpt-4.1-nano' | 'gpt-4.1-mini'\n\n /** Override the default fields inserted by the plugin via a function that receives the default fields and returns the new fields */\n fieldsOverride?: (args: { defaultFields: Field[] }) => Field[]\n\n /** The locales to generate alt texts for. */\n locales: string[]\n\n /** The locale to generate alt texts in when localization is disabled. */\n locale?: string\n}\n"],"names":[],"mappings":"AAwCA,2EAA2E,GAC3E,WA2BC"}
1
+ {"version":3,"sources":["../../src/types/AltTextPluginConfig.ts"],"sourcesContent":["import type { CollectionSlug, Field } from 'payload'\n\nimport type { AltTextResolver } from '../resolvers/types.js'\n\n/** Configuration options for the alt text plugin. */\nexport type IncomingAltTextPluginConfig = {\n /** Collection slugs to enable the plugin for. */\n collections: CollectionSlug[]\n\n /** Whether the plugin is enabled. */\n enabled?: boolean\n\n /** Override the default fields inserted by the plugin via a function that receives the default fields and returns the new fields */\n fieldsOverride?: (args: { defaultFields: Field[] }) => Field[]\n\n /**\n * Function to get the thumbnail URL of an image document.\n * This URL will be sent to the LLM for analysis.\n *\n * @remarks\n * - The URL must be publicly accessible so the LLM can fetch it\n * - Use a thumbnail/preview version of the image when possible (e.g. from the sizes field)\n */\n getImageThumbnail: (doc: Record<string, unknown>) => string\n\n /**\n * The locale to generate alt texts in when localization is disabled.\n *\n * Required when localization is disabled, ignored when localization is enabled.\n * @example 'en'\n */\n locale?: string\n\n /**\n * Maximum number of concurrent API requests for bulk generate operations.\n *\n * @default 16\n */\n maxBulkGenerateConcurrency?: number\n\n /** The resolver to use for generating alt text (e.g., openAIResolver) */\n resolver: AltTextResolver\n}\n\n/** Configuration of the alt text plugin after defaults have been applied. */\nexport type AltTextPluginConfig = {\n /** Collection slugs to enable the plugin for. */\n collections: CollectionSlug[]\n\n /** Whether the plugin is enabled. */\n enabled: boolean\n\n /** Override the default fields inserted by the plugin via a function that receives the default fields and returns the new fields */\n fieldsOverride?: (args: { defaultFields: Field[] }) => Field[]\n\n /** Function to get the thumbnail URL of an image document. */\n getImageThumbnail: (doc: Record<string, unknown>) => string\n\n /** The locale to generate alt texts in when localization is disabled. */\n locale?: string\n\n /** The locales to generate alt texts for. */\n locales: string[]\n\n /** Maximum number of concurrent API requests for bulk generate operations. */\n maxBulkGenerateConcurrency: number\n\n /** The resolver to use for generating alt text */\n resolver: AltTextResolver\n}\n"],"names":[],"mappings":"AA4CA,2EAA2E,GAC3E,WAwBC"}
@@ -1,3 +1,3 @@
1
- import { SanitizedConfig } from 'payload';
1
+ import type { SanitizedConfig } from 'payload';
2
2
  /** Returns the locales from the config. Returns undefined when localization is disabled. */
3
3
  export declare function localesFromConfig(config: SanitizedConfig): string[] | undefined;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/localesFromConfig.ts"],"sourcesContent":["import { SanitizedConfig } from 'payload'\n\n/** Returns the locales from the config. Returns undefined when localization is disabled. */\nexport function localesFromConfig(config: SanitizedConfig): string[] | undefined {\n if (typeof config.localization === 'object' && config.localization) {\n return config.localization.localeCodes\n } else {\n return undefined\n }\n}\n"],"names":["localesFromConfig","config","localization","localeCodes","undefined"],"mappings":"AAEA,0FAA0F,GAC1F,OAAO,SAASA,kBAAkBC,MAAuB;IACvD,IAAI,OAAOA,OAAOC,YAAY,KAAK,YAAYD,OAAOC,YAAY,EAAE;QAClE,OAAOD,OAAOC,YAAY,CAACC,WAAW;IACxC,OAAO;QACL,OAAOC;IACT;AACF"}
1
+ {"version":3,"sources":["../../src/utilities/localesFromConfig.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\n/** Returns the locales from the config. Returns undefined when localization is disabled. */\nexport function localesFromConfig(config: SanitizedConfig): string[] | undefined {\n if (typeof config.localization === 'object' && config.localization) {\n return config.localization.localeCodes\n } else {\n return undefined\n }\n}\n"],"names":["localesFromConfig","config","localization","localeCodes","undefined"],"mappings":"AAEA,0FAA0F,GAC1F,OAAO,SAASA,kBAAkBC,MAAuB;IACvD,IAAI,OAAOA,OAAOC,YAAY,KAAK,YAAYD,OAAOC,YAAY,EAAE;QAClE,OAAOD,OAAOC,YAAY,CAACC,WAAW;IACxC,OAAO;QACL,OAAOC;IACT;AACF"}
@@ -1,3 +1,3 @@
1
- import { StaticLabel } from 'payload';
1
+ import type { StaticLabel } from 'payload';
2
2
  /** Returns the StaticLabel object for the given translation to to use inside the field label. */
3
3
  export declare function translatedLabel(key: string): StaticLabel;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/translatedLabel.ts"],"sourcesContent":["import { StaticLabel } from 'payload'\nimport { translations } from '../translations/index.js'\n\n/** Returns the StaticLabel object for the given translation to to use inside the field label. */\nexport function translatedLabel(key: string): StaticLabel {\n return Object.fromEntries(\n Object.entries(translations).map(([locale, translation]) => [\n locale,\n (translation['@jhb.software/payload-alt-text-plugin'] as Record<string, string>)[key] || key,\n ]),\n )\n}\n"],"names":["translations","translatedLabel","key","Object","fromEntries","entries","map","locale","translation"],"mappings":"AACA,SAASA,YAAY,QAAQ,2BAA0B;AAEvD,+FAA+F,GAC/F,OAAO,SAASC,gBAAgBC,GAAW;IACzC,OAAOC,OAAOC,WAAW,CACvBD,OAAOE,OAAO,CAACL,cAAcM,GAAG,CAAC,CAAC,CAACC,QAAQC,YAAY,GAAK;YAC1DD;YACCC,WAAW,CAAC,wCAAwC,AAA2B,CAACN,IAAI,IAAIA;SAC1F;AAEL"}
1
+ {"version":3,"sources":["../../src/utils/translatedLabel.ts"],"sourcesContent":["import type { StaticLabel } from 'payload'\n\nimport { translations } from '../translations/index.js'\n\n/** Returns the StaticLabel object for the given translation to to use inside the field label. */\nexport function translatedLabel(key: string): StaticLabel {\n return Object.fromEntries(\n Object.entries(translations).map(([locale, translation]) => [\n locale,\n (translation['@jhb.software/payload-alt-text-plugin'] as Record<string, string>)[key] || key,\n ]),\n )\n}\n"],"names":["translations","translatedLabel","key","Object","fromEntries","entries","map","locale","translation"],"mappings":"AAEA,SAASA,YAAY,QAAQ,2BAA0B;AAEvD,+FAA+F,GAC/F,OAAO,SAASC,gBAAgBC,GAAW;IACzC,OAAOC,OAAOC,WAAW,CACvBD,OAAOE,OAAO,CAACL,cAAcM,GAAG,CAAC,CAAC,CAACC,QAAQC,YAAY,GAAK;YAC1DD;YACCC,WAAW,CAAC,wCAAwC,AAA2B,CAACN,IAAI,IAAIA;SAC1F;AAEL"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jhb.software/payload-alt-text-plugin",
3
- "version": "0.2.2",
4
- "description": "A minimal Payload CMS plugin to generate image alt texts using OpenAI's Vision API.",
3
+ "version": "0.3.1",
4
+ "description": "A Payload CMS plugin that adds AI-powered alt text generation for images.",
5
5
  "bugs": "https://github.com/jhb-software/payload-plugins/issues",
6
6
  "repository": "https://github.com/jhb-software/payload-plugins",
7
7
  "keywords": [
@@ -17,25 +17,27 @@
17
17
  "main": "./dist/index.js",
18
18
  "types": "./dist/index.d.ts",
19
19
  "dependencies": {
20
- "openai": "^6.8.1",
21
- "p-map": "^7.0.3",
22
- "zod": "^4.1.12"
20
+ "openai": "^6.16.0",
21
+ "p-map": "^7.0.4",
22
+ "zod": "^4.3.5"
23
23
  },
24
24
  "peerDependencies": {
25
- "@payloadcms/ui": "^3.62.1",
26
- "next": "15.5.6",
27
- "payload": "^3.62.1",
28
- "react": "19.2.0",
29
- "react-dom": "19.2.0"
25
+ "@payloadcms/ui": "^3.72.0",
26
+ "next": "15.5.9",
27
+ "payload": "^3.72.0",
28
+ "react": "19.2.3",
29
+ "react-dom": "19.2.3"
30
30
  },
31
31
  "devDependencies": {
32
- "@swc/cli": "^0.7.9",
33
- "@swc/core": "^1.15.0",
34
- "@types/react": "19.2.2",
35
- "@types/react-dom": "19.2.2",
32
+ "@payloadcms/eslint-config": "^3.28.0",
33
+ "@swc/cli": "^0.7.10",
34
+ "@swc/core": "^1.15.10",
35
+ "@types/react": "19.2.8",
36
+ "@types/react-dom": "19.2.3",
36
37
  "copyfiles": "2.4.1",
37
- "prettier": "^3.6.2",
38
- "rimraf": "6.1.0",
38
+ "eslint": "^9.39.2",
39
+ "prettier": "^3.8.0",
40
+ "rimraf": "6.1.2",
39
41
  "typescript": "5.9.3"
40
42
  },
41
43
  "files": [
@@ -73,7 +75,7 @@
73
75
  "clean": "rimraf --glob {dist,*.tsbuildinfo}",
74
76
  "dev": "tsc -w",
75
77
  "format": "prettier --write src",
76
- "lint": "eslint ./src",
77
- "lint:fix": "eslint ./src --fix"
78
+ "lint": "eslint src",
79
+ "lint:fix": "eslint src --fix"
78
80
  }
79
81
  }
@@ -1,12 +0,0 @@
1
- import type OpenAI from 'openai';
2
- import type { AltTextPluginConfig } from '../types/AltTextPluginConfig.js';
3
- type GenerationCost = {
4
- model: 'gpt-4.1-nano' | 'gpt-4.1-mini';
5
- inputCost: number;
6
- outputCost: number;
7
- totalCost: number;
8
- totalTokens: number;
9
- };
10
- /** Calculates the cost of a generation. */
11
- export declare function getGenerationCost(response: OpenAI.Chat.Completions.ChatCompletion, model: AltTextPluginConfig['model']): GenerationCost;
12
- export {};
@@ -1,30 +0,0 @@
1
- /** Calculates the cost of a generation. */ export function getGenerationCost(response, model) {
2
- const modelCosts = {
3
- // see https://platform.openai.com/docs/models/gpt-4.1-nano
4
- 'gpt-4.1-nano': {
5
- input: 0.1,
6
- output: 0.4
7
- },
8
- // see https://platform.openai.com/docs/models/gpt-4.1-mini
9
- 'gpt-4.1-mini': {
10
- input: 0.4,
11
- output: 1.6
12
- }
13
- };
14
- // Calculate cost based on token usage
15
- const inputTokens = response.usage?.prompt_tokens || 0;
16
- const outputTokens = response.usage?.completion_tokens || 0;
17
- const totalTokens = response.usage?.total_tokens || 0;
18
- const inputCost = inputTokens / 1_000_000 * modelCosts[model].input;
19
- const outputCost = outputTokens / 1_000_000 * modelCosts[model].output;
20
- const totalCost = inputCost + outputCost;
21
- return {
22
- model,
23
- inputCost,
24
- outputCost,
25
- totalCost,
26
- totalTokens
27
- };
28
- }
29
-
30
- //# sourceMappingURL=getGenerationCost.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utilities/getGenerationCost.ts"],"sourcesContent":["import type OpenAI from 'openai'\nimport type { AltTextPluginConfig } from '../types/AltTextPluginConfig.js'\n\ntype GenerationCost = {\n model: 'gpt-4.1-nano' | 'gpt-4.1-mini'\n inputCost: number\n outputCost: number\n totalCost: number\n totalTokens: number\n}\n\n/** Calculates the cost of a generation. */\nexport function getGenerationCost(\n response: OpenAI.Chat.Completions.ChatCompletion,\n model: AltTextPluginConfig['model'],\n): GenerationCost {\n const modelCosts: Record<AltTextPluginConfig['model'], { input: number; output: number }> = {\n // see https://platform.openai.com/docs/models/gpt-4.1-nano\n 'gpt-4.1-nano': {\n input: 0.1,\n output: 0.4,\n },\n // see https://platform.openai.com/docs/models/gpt-4.1-mini\n 'gpt-4.1-mini': {\n input: 0.4,\n output: 1.6,\n },\n }\n\n // Calculate cost based on token usage\n const inputTokens = response.usage?.prompt_tokens || 0\n const outputTokens = response.usage?.completion_tokens || 0\n const totalTokens = response.usage?.total_tokens || 0\n\n const inputCost = (inputTokens / 1_000_000) * modelCosts[model].input\n const outputCost = (outputTokens / 1_000_000) * modelCosts[model].output\n const totalCost = inputCost + outputCost\n\n return {\n model,\n inputCost,\n outputCost,\n totalCost,\n totalTokens,\n }\n}\n"],"names":["getGenerationCost","response","model","modelCosts","input","output","inputTokens","usage","prompt_tokens","outputTokens","completion_tokens","totalTokens","total_tokens","inputCost","outputCost","totalCost"],"mappings":"AAWA,yCAAyC,GACzC,OAAO,SAASA,kBACdC,QAAgD,EAChDC,KAAmC;IAEnC,MAAMC,aAAsF;QAC1F,2DAA2D;QAC3D,gBAAgB;YACdC,OAAO;YACPC,QAAQ;QACV;QACA,2DAA2D;QAC3D,gBAAgB;YACdD,OAAO;YACPC,QAAQ;QACV;IACF;IAEA,sCAAsC;IACtC,MAAMC,cAAcL,SAASM,KAAK,EAAEC,iBAAiB;IACrD,MAAMC,eAAeR,SAASM,KAAK,EAAEG,qBAAqB;IAC1D,MAAMC,cAAcV,SAASM,KAAK,EAAEK,gBAAgB;IAEpD,MAAMC,YAAY,AAACP,cAAc,YAAaH,UAAU,CAACD,MAAM,CAACE,KAAK;IACrE,MAAMU,aAAa,AAACL,eAAe,YAAaN,UAAU,CAACD,MAAM,CAACG,MAAM;IACxE,MAAMU,YAAYF,YAAYC;IAE9B,OAAO;QACLZ;QACAW;QACAC;QACAC;QACAJ;IACF;AACF"}
@@ -1,11 +0,0 @@
1
- import { AutoParseableResponseFormat } from 'openai/lib/parser.mjs';
2
- import { ResponseFormatJSONSchema } from 'openai/resources/shared.mjs';
3
- import { z } from 'zod';
4
- /**
5
- * Creates a chat completion `JSONSchema` response format object from
6
- * the given Zod schema.
7
- *
8
- * This is a temporary drop in replacement for the zodResponseFormat from openai/helpers/zod.ts
9
- * because of issue https://github.com/openai/openai-node/issues/1576
10
- */
11
- export declare function zodResponseFormat<ZodInput extends z.ZodType>(zodObject: ZodInput, name: string, props?: Omit<ResponseFormatJSONSchema.JSONSchema, 'schema' | 'strict' | 'name'>): AutoParseableResponseFormat<z.infer<ZodInput>>;
@@ -1,23 +0,0 @@
1
- import { makeParseableResponseFormat } from 'openai/lib/parser.mjs';
2
- import { z } from 'zod';
3
- /**
4
- * Creates a chat completion `JSONSchema` response format object from
5
- * the given Zod schema.
6
- *
7
- * This is a temporary drop in replacement for the zodResponseFormat from openai/helpers/zod.ts
8
- * because of issue https://github.com/openai/openai-node/issues/1576
9
- */ export function zodResponseFormat(zodObject, name, props) {
10
- return makeParseableResponseFormat({
11
- type: 'json_schema',
12
- json_schema: {
13
- ...props,
14
- name,
15
- strict: true,
16
- schema: z.toJSONSchema(zodObject, {
17
- target: 'draft-7'
18
- })
19
- }
20
- }, (content)=>zodObject.parse(JSON.parse(content)));
21
- }
22
-
23
- //# sourceMappingURL=zodResponseFormat.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utilities/zodResponseFormat.ts"],"sourcesContent":["import { AutoParseableResponseFormat, makeParseableResponseFormat } from 'openai/lib/parser.mjs'\nimport { ResponseFormatJSONSchema } from 'openai/resources/shared.mjs'\nimport { z } from 'zod'\n\n/**\n * Creates a chat completion `JSONSchema` response format object from\n * the given Zod schema.\n *\n * This is a temporary drop in replacement for the zodResponseFormat from openai/helpers/zod.ts\n * because of issue https://github.com/openai/openai-node/issues/1576\n */\nexport function zodResponseFormat<ZodInput extends z.ZodType>(\n zodObject: ZodInput,\n name: string,\n props?: Omit<ResponseFormatJSONSchema.JSONSchema, 'schema' | 'strict' | 'name'>,\n): AutoParseableResponseFormat<z.infer<ZodInput>> {\n return makeParseableResponseFormat(\n {\n type: 'json_schema',\n json_schema: {\n ...props,\n name,\n strict: true,\n schema: z.toJSONSchema(zodObject, { target: 'draft-7' }),\n },\n },\n (content) => zodObject.parse(JSON.parse(content)),\n )\n}\n"],"names":["makeParseableResponseFormat","z","zodResponseFormat","zodObject","name","props","type","json_schema","strict","schema","toJSONSchema","target","content","parse","JSON"],"mappings":"AAAA,SAAsCA,2BAA2B,QAAQ,wBAAuB;AAEhG,SAASC,CAAC,QAAQ,MAAK;AAEvB;;;;;;CAMC,GACD,OAAO,SAASC,kBACdC,SAAmB,EACnBC,IAAY,EACZC,KAA+E;IAE/E,OAAOL,4BACL;QACEM,MAAM;QACNC,aAAa;YACX,GAAGF,KAAK;YACRD;YACAI,QAAQ;YACRC,QAAQR,EAAES,YAAY,CAACP,WAAW;gBAAEQ,QAAQ;YAAU;QACxD;IACF,GACA,CAACC,UAAYT,UAAUU,KAAK,CAACC,KAAKD,KAAK,CAACD;AAE5C"}
@@ -1,5 +0,0 @@
1
- import { PluginAltTextTranslationKeys } from 'src/translations/index.js';
2
- /** Hook which returns a translation function for the plugin translations. */
3
- export declare const usePluginTranslation: () => {
4
- t: (key: PluginAltTextTranslationKeys) => string;
5
- };
@@ -1,16 +0,0 @@
1
- import { useTranslation } from '@payloadcms/ui';
2
- /** Hook which returns a translation function for the plugin translations. */ export const usePluginTranslation = ()=>{
3
- const { i18n } = useTranslation();
4
- const pluginTranslations = i18n.translations['@jhb.software/payload-alt-text-plugin'];
5
- return {
6
- t: (key)=>{
7
- const translation = pluginTranslations[key];
8
- if (!translation) {
9
- console.log('Plugin translation not found', key);
10
- }
11
- return translation ?? key;
12
- }
13
- };
14
- };
15
-
16
- //# sourceMappingURL=usePluginTranslation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/usePluginTranslation.ts"],"sourcesContent":["import { useTranslation } from '@payloadcms/ui'\nimport { PluginAltTextTranslationKeys } from 'src/translations/index.js'\nimport { PluginAltTextTranslations } from 'src/translations/index.js'\n\n/** Hook which returns a translation function for the plugin translations. */\nexport const usePluginTranslation = () => {\n const { i18n } = useTranslation<PluginAltTextTranslations, PluginAltTextTranslationKeys>()\n const pluginTranslations = i18n.translations[\n '@jhb.software/payload-alt-text-plugin'\n ] as PluginAltTextTranslations\n\n return {\n t: (key: PluginAltTextTranslationKeys) => {\n const translation = pluginTranslations[key] as string\n\n if (!translation) {\n console.log('Plugin translation not found', key)\n }\n return translation ?? key\n },\n }\n}\n"],"names":["useTranslation","usePluginTranslation","i18n","pluginTranslations","translations","t","key","translation","console","log"],"mappings":"AAAA,SAASA,cAAc,QAAQ,iBAAgB;AAI/C,2EAA2E,GAC3E,OAAO,MAAMC,uBAAuB;IAClC,MAAM,EAAEC,IAAI,EAAE,GAAGF;IACjB,MAAMG,qBAAqBD,KAAKE,YAAY,CAC1C,wCACD;IAED,OAAO;QACLC,GAAG,CAACC;YACF,MAAMC,cAAcJ,kBAAkB,CAACG,IAAI;YAE3C,IAAI,CAACC,aAAa;gBAChBC,QAAQC,GAAG,CAAC,gCAAgCH;YAC9C;YACA,OAAOC,eAAeD;QACxB;IACF;AACF,EAAC"}