@payload-enchants/translator 1.1.32 → 1.1.34

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/translate/traverseFields.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAc,MAAM,eAAe,CAAC;AAIvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,eAAO,MAAM,cAAc,iIASxB;IACD,QAAQ,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,qBAAqB,CAAC,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IAChD,cAAc,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;CACvC,SAwNA,CAAC"}
1
+ {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/translate/traverseFields.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAc,MAAM,eAAe,CAAC;AAIvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,eAAO,MAAM,cAAc,iIASxB;IACD,QAAQ,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,qBAAqB,CAAC,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IAChD,cAAc,EAAE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;CACvC,SAgNA,CAAC"}
@@ -44,13 +44,11 @@ export const traverseFields = ({ dataFrom, emptyOnly, fields, localizedParent, s
44
44
  const arrayDataFrom = siblingDataFrom[field.name];
45
45
  if (isEmpty(arrayDataFrom)) break;
46
46
  const arrayDataTranslated = [];
47
- const currentArrayDataInTranslated = Array.isArray(siblingDataTranslated[field.name]) ? siblingDataTranslated[field.name] : undefined;
48
47
  arrayDataFrom.forEach((item, index)=>{
49
- const currentArrayItemInTranslated = currentArrayDataInTranslated?.[index];
50
48
  arrayDataTranslated.push({
51
- // ensure ids are different, Postgres doesn't like the same.
52
- ...currentArrayItemInTranslated ?? {},
53
- id: currentArrayItemInTranslated?.id ?? ObjectID().toHexString()
49
+ ...item ?? {},
50
+ // ensure ids are different if localized
51
+ id: field.localized || !item.id ? ObjectID().toHexString() : item.id
54
52
  });
55
53
  traverseFields({
56
54
  dataFrom,
@@ -68,15 +66,12 @@ export const traverseFields = ({ dataFrom, emptyOnly, fields, localizedParent, s
68
66
  case 'blocks':
69
67
  const blockDataFrom = siblingDataFrom[field.name];
70
68
  if (isEmpty(blockDataFrom)) break;
71
- const currentBlockDataInTranslated = Array.isArray(siblingDataTranslated[field.name]) ? siblingDataTranslated[field.name] : undefined;
72
69
  const blockDataTranslated = [];
73
70
  blockDataFrom.forEach((item, index)=>{
74
- const currentBlockItemInTranslated = currentBlockDataInTranslated?.[index];
75
71
  blockDataTranslated.push({
76
- blockType: item.blockType,
77
- // ensure ids are different, needed with Postgres
78
- ...currentBlockItemInTranslated ?? {},
79
- id: currentBlockItemInTranslated?.id ?? ObjectID().toHexString()
72
+ ...item,
73
+ // ensure ids are different if localized
74
+ id: field.localized || !item.id ? ObjectID().toHexString() : item.id
80
75
  });
81
76
  const block = field.blocks.find((each)=>each.slug === item.blockType);
82
77
  if (!block) return;
@@ -124,6 +119,10 @@ export const traverseFields = ({ dataFrom, emptyOnly, fields, localizedParent, s
124
119
  case 'textarea':
125
120
  if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) return;
126
121
  if (emptyOnly && siblingDataTranslated[field.name]) return;
122
+ // do not translate the block ID or admin-facing label
123
+ if (field.name === 'blockName' || field.name === 'id') {
124
+ break;
125
+ }
127
126
  valuesToTranslate.push({
128
127
  onTranslate: (translated)=>{
129
128
  siblingDataTranslated[field.name] = translated;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/translate/traverseFields.ts"],"sourcesContent":["import ObjectID from 'bson-objectid';\nimport { type Field, tabHasName } from 'payload/types';\n\nimport { isEmpty } from '../utils/isEmpty';\nimport { traverseRichText } from './traverseRichText';\nimport type { ValueToTranslate } from './types';\n\nexport const traverseFields = ({\n dataFrom,\n emptyOnly,\n fields,\n localizedParent,\n siblingDataFrom,\n siblingDataTranslated,\n translatedData,\n valuesToTranslate,\n}: {\n dataFrom: Record<string, unknown>;\n emptyOnly?: boolean;\n fields: Field[];\n localizedParent?: boolean;\n siblingDataFrom?: Record<string, unknown>;\n siblingDataTranslated?: Record<string, unknown>;\n translatedData: Record<string, unknown>;\n valuesToTranslate: ValueToTranslate[];\n}) => {\n siblingDataFrom = siblingDataFrom ?? dataFrom;\n siblingDataTranslated = siblingDataTranslated ?? translatedData;\n\n fields.forEach((field) => {\n switch (field.type) {\n case 'tabs':\n field.tabs.forEach((tab) => {\n const hasName = tabHasName(tab);\n\n const tabDataFrom = hasName\n ? (siblingDataFrom[tab.name] as Record<string, unknown>)\n : siblingDataFrom;\n\n if (!tabDataFrom) return;\n\n const tabDataTranslated = hasName\n ? (siblingDataTranslated[tab.name] as Record<string, unknown>) ?? {}\n : siblingDataTranslated;\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: tab.fields,\n localizedParent: tab.localized,\n siblingDataFrom: tabDataFrom,\n siblingDataTranslated: tabDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n });\n\n break;\n\n case 'group':\n const groupDataFrom = siblingDataFrom[field.name] as Record<string, unknown>;\n\n if (!groupDataFrom) break;\n\n const groupDataTranslated =\n (siblingDataTranslated[field.name] as Record<string, unknown>) ?? {};\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent: field.localized,\n siblingDataFrom: groupDataFrom,\n siblingDataTranslated: groupDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n\n break;\n\n case 'array':\n const arrayDataFrom = siblingDataFrom[field.name] as {\n id: string;\n }[];\n\n if (isEmpty(arrayDataFrom)) break;\n\n const arrayDataTranslated = [] as { id: string }[];\n\n const currentArrayDataInTranslated = Array.isArray(siblingDataTranslated[field.name])\n ? (siblingDataTranslated[field.name] as { id: string }[])\n : undefined;\n\n arrayDataFrom.forEach((item, index) => {\n const currentArrayItemInTranslated = currentArrayDataInTranslated?.[index];\n\n arrayDataTranslated.push({\n // ensure ids are different, Postgres doesn't like the same.\n ...(currentArrayItemInTranslated ?? {}),\n id: currentArrayItemInTranslated?.id ?? ObjectID().toHexString(),\n });\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent: localizedParent ?? field.localized,\n siblingDataFrom: item,\n siblingDataTranslated: arrayDataTranslated[index],\n translatedData,\n valuesToTranslate,\n });\n });\n\n siblingDataTranslated[field.name] = arrayDataTranslated;\n\n break;\n\n case 'blocks':\n const blockDataFrom = siblingDataFrom[field.name] as { blockType: string; id: string }[];\n\n if (isEmpty(blockDataFrom)) break;\n\n const currentBlockDataInTranslated = Array.isArray(siblingDataTranslated[field.name])\n ? (siblingDataTranslated[field.name] as { id: string }[])\n : undefined;\n\n const blockDataTranslated = [] as { blockType: string; id: string }[];\n\n blockDataFrom.forEach((item, index) => {\n const currentBlockItemInTranslated = currentBlockDataInTranslated?.[index];\n\n blockDataTranslated.push({\n blockType: item.blockType,\n // ensure ids are different, needed with Postgres\n ...(currentBlockItemInTranslated ?? {}),\n id: currentBlockItemInTranslated?.id ?? ObjectID().toHexString(),\n });\n\n const block = field.blocks.find((each) => each.slug === item.blockType);\n\n if (!block) return;\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: block.fields,\n localizedParent,\n siblingDataFrom: item,\n siblingDataTranslated: blockDataTranslated[index],\n translatedData,\n valuesToTranslate,\n });\n });\n\n siblingDataTranslated[field.name] = blockDataTranslated;\n\n break;\n\n case 'collapsible':\n case 'row':\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent,\n siblingDataFrom,\n siblingDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n break;\n\n // long ass cases here we have\n case 'date':\n case 'checkbox':\n case 'json':\n case 'code':\n case 'email':\n case 'number':\n case 'point':\n case 'radio':\n case 'relationship':\n case 'select':\n case 'upload':\n siblingDataTranslated[field.name] = siblingDataFrom[field.name];\n\n break;\n\n case 'text':\n case 'textarea':\n if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) return;\n if (emptyOnly && siblingDataTranslated[field.name]) return;\n\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingDataTranslated[field.name] = translated;\n },\n value: siblingDataFrom[field.name],\n });\n break;\n\n case 'richText':\n if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) break;\n if (emptyOnly && siblingDataTranslated[field.name]) return;\n const richTextDataFrom = siblingDataFrom[field.name] as object;\n\n siblingDataTranslated[field.name] = richTextDataFrom;\n\n if (!richTextDataFrom) break;\n\n const isSlate = Array.isArray(richTextDataFrom);\n\n const isLexical = 'root' in richTextDataFrom;\n\n if (!isSlate && !isLexical) break;\n\n const root = (\n isLexical\n ? (siblingDataTranslated[field.name] as Record<string, unknown>).root\n : (siblingDataTranslated[field.name] as unknown[])?.[0]\n ) as Record<string, unknown>;\n\n traverseRichText({\n onText: (siblingData) => {\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingData.text = translated;\n },\n value: siblingData.text,\n });\n },\n root,\n });\n\n break;\n\n default:\n break;\n }\n });\n};\n"],"names":["ObjectID","tabHasName","isEmpty","traverseRichText","traverseFields","dataFrom","emptyOnly","fields","localizedParent","siblingDataFrom","siblingDataTranslated","translatedData","valuesToTranslate","forEach","field","type","tabs","tab","hasName","tabDataFrom","name","tabDataTranslated","localized","groupDataFrom","groupDataTranslated","arrayDataFrom","arrayDataTranslated","currentArrayDataInTranslated","Array","isArray","undefined","item","index","currentArrayItemInTranslated","push","id","toHexString","blockDataFrom","currentBlockDataInTranslated","blockDataTranslated","currentBlockItemInTranslated","blockType","block","blocks","find","each","slug","onTranslate","translated","value","richTextDataFrom","isSlate","isLexical","root","onText","siblingData","text"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,cAAc,gBAAgB;AACrC,SAAqBC,UAAU,QAAQ,gBAAgB;AAEvD,SAASC,OAAO,QAAQ,mBAAmB;AAC3C,SAASC,gBAAgB,QAAQ,qBAAqB;AAGtD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,QAAQ,EACRC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,eAAe,EACfC,qBAAqB,EACrBC,cAAc,EACdC,iBAAiB,EAUlB;IACCH,kBAAkBA,mBAAmBJ;IACrCK,wBAAwBA,yBAAyBC;IAEjDJ,OAAOM,OAAO,CAAC,CAACC;QACd,OAAQA,MAAMC,IAAI;YAChB,KAAK;gBACHD,MAAME,IAAI,CAACH,OAAO,CAAC,CAACI;oBAClB,MAAMC,UAAUjB,WAAWgB;oBAE3B,MAAME,cAAcD,UACfT,eAAe,CAACQ,IAAIG,IAAI,CAAC,GAC1BX;oBAEJ,IAAI,CAACU,aAAa;oBAElB,MAAME,oBAAoBH,UACtB,AAACR,qBAAqB,CAACO,IAAIG,IAAI,CAAC,IAAgC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AAK;gBACH,IAAI,CAACN,MAAMQ,SAAS,IAAI,CAACd,mBAAmBN,QAAQO,eAAe,CAACK,MAAMM,IAAI,CAAC,GAAG;gBAClF,IAAId,aAAaI,qBAAqB,CAACI,MAAMM,IAAI,CAAC,EAAE;gBAEpDR,kBAAkBsB,IAAI,CAAC;oBACrBa,aAAa,CAACC;wBACZtC,qBAAqB,CAACI,MAAMM,IAAI,CAAC,GAAG4B;oBACtC;oBACAC,OAAOxC,eAAe,CAACK,MAAMM,IAAI,CAAC;gBACpC;gBACA;YAEF,KAAK;gBACH,IAAI,CAACN,MAAMQ,SAAS,IAAI,CAACd,mBAAmBN,QAAQO,eAAe,CAACK,MAAMM,IAAI,CAAC,GAAG;gBAClF,IAAId,aAAaI,qBAAqB,CAACI,MAAMM,IAAI,CAAC,EAAE;gBACpD,MAAM8B,mBAAmBzC,eAAe,CAACK,MAAMM,IAAI,CAAC;gBAEpDV,qBAAqB,CAACI,MAAMM,IAAI,CAAC,GAAG8B;gBAEpC,IAAI,CAACA,kBAAkB;gBAEvB,MAAMC,UAAUvB,MAAMC,OAAO,CAACqB;gBAE9B,MAAME,YAAY,UAAUF;gBAE5B,IAAI,CAACC,WAAW,CAACC,WAAW;gBAE5B,MAAMC,OACJD,YACI,AAAC1C,qBAAqB,CAACI,MAAMM,IAAI,CAAC,CAA6BiC,IAAI,GAClE3C,qBAAqB,CAACI,MAAMM,IAAI,CAAC,EAAgB,CAAC,EAAE;gBAG3DjB,iBAAiB;oBACfmD,QAAQ,CAACC;wBACP3C,kBAAkBsB,IAAI,CAAC;4BACrBa,aAAa,CAACC;gCACZO,YAAYC,IAAI,GAAGR;4BACrB;4BACAC,OAAOM,YAAYC,IAAI;wBACzB;oBACF;oBACAH;gBACF;gBAEA;YAEF;gBACE;QACJ;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../src/translate/traverseFields.ts"],"sourcesContent":["import ObjectID from 'bson-objectid';\nimport { type Field, tabHasName } from 'payload/types';\n\nimport { isEmpty } from '../utils/isEmpty';\nimport { traverseRichText } from './traverseRichText';\nimport type { ValueToTranslate } from './types';\n\nexport const traverseFields = ({\n dataFrom,\n emptyOnly,\n fields,\n localizedParent,\n siblingDataFrom,\n siblingDataTranslated,\n translatedData,\n valuesToTranslate,\n}: {\n dataFrom: Record<string, unknown>;\n emptyOnly?: boolean;\n fields: Field[];\n localizedParent?: boolean;\n siblingDataFrom?: Record<string, unknown>;\n siblingDataTranslated?: Record<string, unknown>;\n translatedData: Record<string, unknown>;\n valuesToTranslate: ValueToTranslate[];\n}) => {\n siblingDataFrom = siblingDataFrom ?? dataFrom;\n siblingDataTranslated = siblingDataTranslated ?? translatedData;\n\n fields.forEach((field) => {\n switch (field.type) {\n case 'tabs':\n field.tabs.forEach((tab) => {\n const hasName = tabHasName(tab);\n\n const tabDataFrom = hasName\n ? (siblingDataFrom[tab.name] as Record<string, unknown>)\n : siblingDataFrom;\n\n if (!tabDataFrom) return;\n\n const tabDataTranslated = hasName\n ? (siblingDataTranslated[tab.name] as Record<string, unknown>) ?? {}\n : siblingDataTranslated;\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: tab.fields,\n localizedParent: tab.localized,\n siblingDataFrom: tabDataFrom,\n siblingDataTranslated: tabDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n });\n\n break;\n\n case 'group':\n const groupDataFrom = siblingDataFrom[field.name] as Record<string, unknown>;\n\n if (!groupDataFrom) break;\n\n const groupDataTranslated =\n (siblingDataTranslated[field.name] as Record<string, unknown>) ?? {};\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent: field.localized,\n siblingDataFrom: groupDataFrom,\n siblingDataTranslated: groupDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n\n break;\n\n case 'array':\n const arrayDataFrom = siblingDataFrom[field.name] as {\n id: string;\n }[];\n\n if (isEmpty(arrayDataFrom)) break;\n\n const arrayDataTranslated = [] as { id: string }[];\n\n arrayDataFrom.forEach((item, index) => {\n arrayDataTranslated.push({\n ...(item ?? {}),\n // ensure ids are different if localized\n id: field.localized || !item.id ? ObjectID().toHexString() : item.id,\n });\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent: localizedParent ?? field.localized,\n siblingDataFrom: item,\n siblingDataTranslated: arrayDataTranslated[index],\n translatedData,\n valuesToTranslate,\n });\n });\n\n siblingDataTranslated[field.name] = arrayDataTranslated;\n\n break;\n\n case 'blocks':\n const blockDataFrom = siblingDataFrom[field.name] as { blockType: string; id: string }[];\n\n if (isEmpty(blockDataFrom)) break;\n\n const blockDataTranslated = [] as { blockType: string; id: string }[];\n\n blockDataFrom.forEach((item, index) => {\n blockDataTranslated.push({\n ...item,\n // ensure ids are different if localized\n id: field.localized || !item.id ? ObjectID().toHexString() : item.id,\n });\n\n const block = field.blocks.find((each) => each.slug === item.blockType);\n\n if (!block) return;\n\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: block.fields,\n localizedParent,\n siblingDataFrom: item,\n siblingDataTranslated: blockDataTranslated[index],\n translatedData,\n valuesToTranslate,\n });\n });\n\n siblingDataTranslated[field.name] = blockDataTranslated;\n\n break;\n\n case 'collapsible':\n case 'row':\n traverseFields({\n dataFrom,\n emptyOnly,\n fields: field.fields,\n localizedParent,\n siblingDataFrom,\n siblingDataTranslated,\n translatedData,\n valuesToTranslate,\n });\n break;\n\n // long ass cases here we have\n case 'date':\n case 'checkbox':\n case 'json':\n case 'code':\n case 'email':\n case 'number':\n case 'point':\n case 'radio':\n case 'relationship':\n case 'select':\n case 'upload':\n siblingDataTranslated[field.name] = siblingDataFrom[field.name];\n\n break;\n\n case 'text':\n case 'textarea':\n if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) return;\n if (emptyOnly && siblingDataTranslated[field.name]) return;\n\n // do not translate the block ID or admin-facing label\n if (field.name === 'blockName' || field.name === 'id') {\n break;\n }\n\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingDataTranslated[field.name] = translated;\n },\n value: siblingDataFrom[field.name],\n });\n break;\n\n case 'richText':\n if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) break;\n if (emptyOnly && siblingDataTranslated[field.name]) return;\n const richTextDataFrom = siblingDataFrom[field.name] as object;\n\n siblingDataTranslated[field.name] = richTextDataFrom;\n\n if (!richTextDataFrom) break;\n\n const isSlate = Array.isArray(richTextDataFrom);\n\n const isLexical = 'root' in richTextDataFrom;\n\n if (!isSlate && !isLexical) break;\n\n const root = (\n isLexical\n ? (siblingDataTranslated[field.name] as Record<string, unknown>).root\n : (siblingDataTranslated[field.name] as unknown[])?.[0]\n ) as Record<string, unknown>;\n\n traverseRichText({\n onText: (siblingData) => {\n valuesToTranslate.push({\n onTranslate: (translated: string) => {\n siblingData.text = translated;\n },\n value: siblingData.text,\n });\n },\n root,\n });\n\n break;\n\n default:\n break;\n }\n });\n};\n"],"names":["ObjectID","tabHasName","isEmpty","traverseRichText","traverseFields","dataFrom","emptyOnly","fields","localizedParent","siblingDataFrom","siblingDataTranslated","translatedData","valuesToTranslate","forEach","field","type","tabs","tab","hasName","tabDataFrom","name","tabDataTranslated","localized","groupDataFrom","groupDataTranslated","arrayDataFrom","arrayDataTranslated","item","index","push","id","toHexString","blockDataFrom","blockDataTranslated","block","blocks","find","each","slug","blockType","onTranslate","translated","value","richTextDataFrom","isSlate","Array","isArray","isLexical","root","onText","siblingData","text"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,cAAc,gBAAgB;AACrC,SAAqBC,UAAU,QAAQ,gBAAgB;AAEvD,SAASC,OAAO,QAAQ,mBAAmB;AAC3C,SAASC,gBAAgB,QAAQ,qBAAqB;AAGtD,OAAO,MAAMC,i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Q,CAACC;wBACPtC,kBAAkBiB,IAAI,CAAC;4BACrBW,aAAa,CAACC;gCACZS,YAAYC,IAAI,GAAGV;4BACrB;4BACAC,OAAOQ,YAAYC,IAAI;wBACzB;oBACF;oBACAH;gBACF;gBAEA;YAEF;gBACE;QACJ;IACF;AACF,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payload-enchants/translator",
3
- "version": "1.1.32",
3
+ "version": "1.1.34",
4
4
  "private": false,
5
5
  "bugs": "https://github.com/r1tsuu/payload-enchants/issues",
6
6
  "repository": "https://github.com/r1tsuu/payload-enchants",