@payload-enchants/translator 1.1.0 → 1.1.2

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":"AAEA,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,SAmNA,CAAC"}
1
+ {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/translate/traverseFields.ts"],"names":[],"mappings":"AAEA,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,SAqNA,CAAC"}
@@ -50,6 +50,7 @@ export const traverseFields = ({ dataFrom, emptyOnly, fields, localizedParent, s
50
50
  const currentArrayItemInTranslated = currentArrayDataInTranslated?.[index];
51
51
  arrayDataTranslated.push({
52
52
  // ensure ids are different, Postgres doesn't like the same.
53
+ ...currentArrayItemInTranslated ?? {},
53
54
  id: currentArrayItemInTranslated?.id ?? ObjectID().toHexString()
54
55
  });
55
56
  traverseFields({
@@ -75,6 +76,7 @@ export const traverseFields = ({ dataFrom, emptyOnly, fields, localizedParent, s
75
76
  blockDataTranslated.push({
76
77
  blockType: item.blockType,
77
78
  // ensure ids are different, needed with Postgres
79
+ ...currentBlockItemInTranslated ?? {},
78
80
  id: currentBlockItemInTranslated?.id ?? ObjectID().toHexString()
79
81
  });
80
82
  const block = field.blocks.find((each)=>each.slug === item.blockType);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/translate/traverseFields.ts"],"sourcesContent":["import ObjectID from 'bson-objectid';\r\nimport { APIError } from 'payload/errors';\r\nimport { type Field, tabHasName } from 'payload/types';\r\n\r\nimport { isEmpty } from '../utils/isEmpty';\r\nimport { traverseRichText } from './traverseRichText';\r\nimport type { ValueToTranslate } from './types';\r\n\r\nexport const traverseFields = ({\r\n dataFrom,\r\n emptyOnly,\r\n fields,\r\n localizedParent,\r\n siblingDataFrom,\r\n siblingDataTranslated,\r\n translatedData,\r\n valuesToTranslate,\r\n}: {\r\n dataFrom: Record<string, unknown>;\r\n emptyOnly?: boolean;\r\n fields: Field[];\r\n localizedParent?: boolean;\r\n siblingDataFrom?: Record<string, unknown>;\r\n siblingDataTranslated?: Record<string, unknown>;\r\n translatedData: Record<string, unknown>;\r\n valuesToTranslate: ValueToTranslate[];\r\n}) => {\r\n siblingDataFrom = siblingDataFrom ?? dataFrom;\r\n siblingDataTranslated = siblingDataTranslated ?? translatedData;\r\n\r\n fields.forEach((field) => {\r\n switch (field.type) {\r\n case 'tabs':\r\n field.tabs.forEach((tab) => {\r\n const hasName = tabHasName(tab);\r\n\r\n const tabDataFrom = hasName\r\n ? (siblingDataFrom[tab.name] as Record<string, unknown>)\r\n : siblingDataFrom;\r\n\r\n if (!tabDataFrom) return;\r\n\r\n const tabDataTranslated = hasName\r\n ? (siblingDataTranslated[tab.name] as Record<string, unknown>) ?? {}\r\n : siblingDataTranslated;\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: tab.fields,\r\n localizedParent: tab.localized,\r\n siblingDataFrom: tabDataFrom,\r\n siblingDataTranslated: tabDataTranslated,\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n });\r\n\r\n break;\r\n\r\n case 'group':\r\n const groupDataFrom = siblingDataFrom[field.name] as Record<string, unknown>;\r\n\r\n if (!groupDataFrom) break;\r\n\r\n const groupDataTranslated =\r\n (siblingDataTranslated[field.name] as Record<string, unknown>) ?? {};\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: field.fields,\r\n localizedParent: field.localized,\r\n siblingDataFrom: groupDataFrom,\r\n siblingDataTranslated: groupDataTranslated,\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n\r\n break;\r\n\r\n case 'array':\r\n const arrayDataFrom = siblingDataFrom[field.name] as {\r\n id: string;\r\n }[];\r\n\r\n if (isEmpty(arrayDataFrom)) break;\r\n\r\n const arrayDataTranslated = [] as { id: string }[];\r\n\r\n const currentArrayDataInTranslated = Array.isArray(siblingDataTranslated[field.name])\r\n ? (siblingDataTranslated[field.name] as { id: string }[])\r\n : undefined;\r\n\r\n arrayDataFrom.forEach((item, index) => {\r\n const currentArrayItemInTranslated = currentArrayDataInTranslated?.[index];\r\n\r\n arrayDataTranslated.push({\r\n // ensure ids are different, Postgres doesn't like the same.\r\n id: currentArrayItemInTranslated?.id ?? ObjectID().toHexString(),\r\n });\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: field.fields,\r\n localizedParent: localizedParent ?? field.localized,\r\n siblingDataFrom: item,\r\n siblingDataTranslated: arrayDataTranslated[index],\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n });\r\n\r\n siblingDataTranslated[field.name] = arrayDataTranslated;\r\n\r\n break;\r\n\r\n case 'blocks':\r\n const blockDataFrom = siblingDataFrom[field.name] as { blockType: string; id: string }[];\r\n\r\n if (isEmpty(blockDataFrom)) break;\r\n\r\n const currentBlockDataInTranslated = Array.isArray(siblingDataTranslated[field.name])\r\n ? (siblingDataTranslated[field.name] as { id: string }[])\r\n : undefined;\r\n\r\n const blockDataTranslated = [] as { blockType: string; id: string }[];\r\n\r\n blockDataFrom.forEach((item, index) => {\r\n const currentBlockItemInTranslated = currentBlockDataInTranslated?.[index];\r\n\r\n blockDataTranslated.push({\r\n blockType: item.blockType,\r\n // ensure ids are different, needed with Postgres\r\n id: currentBlockItemInTranslated?.id ?? ObjectID().toHexString(),\r\n });\r\n\r\n const block = field.blocks.find((each) => each.slug === item.blockType);\r\n\r\n if (!block) throw new APIError(`Block with slug ${item.blockType} is not found`);\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: block.fields,\r\n localizedParent,\r\n siblingDataFrom: item,\r\n siblingDataTranslated: blockDataTranslated[index],\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n });\r\n\r\n siblingDataTranslated[field.name] = blockDataTranslated;\r\n\r\n break;\r\n\r\n case 'collapsible':\r\n case 'row':\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: field.fields,\r\n localizedParent,\r\n siblingDataFrom,\r\n siblingDataTranslated,\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n break;\r\n\r\n // long ass cases here we have\r\n case 'date':\r\n case 'checkbox':\r\n case 'json':\r\n case 'code':\r\n case 'email':\r\n case 'number':\r\n case 'point':\r\n case 'radio':\r\n case 'relationship':\r\n case 'select':\r\n case 'upload':\r\n siblingDataTranslated[field.name] = siblingDataFrom[field.name];\r\n\r\n break;\r\n\r\n case 'text':\r\n case 'textarea':\r\n if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) return;\r\n if (emptyOnly && siblingDataTranslated[field.name]) return;\r\n\r\n valuesToTranslate.push({\r\n onTranslate: (translated: string) => {\r\n siblingDataTranslated[field.name] = translated;\r\n },\r\n value: siblingDataFrom[field.name],\r\n });\r\n break;\r\n\r\n case 'richText':\r\n if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) break;\r\n if (emptyOnly && siblingDataTranslated[field.name]) return;\r\n const richTextDataFrom = siblingDataFrom[field.name] as object;\r\n\r\n siblingDataTranslated[field.name] = richTextDataFrom;\r\n const isSlate = Array.isArray(richTextDataFrom);\r\n\r\n const isLexical = 'root' in richTextDataFrom;\r\n\r\n if (!isSlate && !isLexical) break;\r\n\r\n const root = (\r\n isLexical\r\n ? (siblingDataTranslated[field.name] as Record<string, unknown>).root\r\n : (siblingDataTranslated[field.name] as unknown[])?.[0]\r\n ) as Record<string, unknown>;\r\n\r\n traverseRichText({\r\n onText: (siblingData) => {\r\n valuesToTranslate.push({\r\n onTranslate: (translated: string) => {\r\n siblingData.text = translated;\r\n },\r\n value: siblingData.text,\r\n });\r\n },\r\n root,\r\n });\r\n\r\n break;\r\n\r\n default:\r\n break;\r\n }\r\n });\r\n};\r\n"],"names":["ObjectID","APIError","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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AC;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;gBACpC,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';\r\nimport { APIError } from 'payload/errors';\r\nimport { type Field, tabHasName } from 'payload/types';\r\n\r\nimport { isEmpty } from '../utils/isEmpty';\r\nimport { traverseRichText } from './traverseRichText';\r\nimport type { ValueToTranslate } from './types';\r\n\r\nexport const traverseFields = ({\r\n dataFrom,\r\n emptyOnly,\r\n fields,\r\n localizedParent,\r\n siblingDataFrom,\r\n siblingDataTranslated,\r\n translatedData,\r\n valuesToTranslate,\r\n}: {\r\n dataFrom: Record<string, unknown>;\r\n emptyOnly?: boolean;\r\n fields: Field[];\r\n localizedParent?: boolean;\r\n siblingDataFrom?: Record<string, unknown>;\r\n siblingDataTranslated?: Record<string, unknown>;\r\n translatedData: Record<string, unknown>;\r\n valuesToTranslate: ValueToTranslate[];\r\n}) => {\r\n siblingDataFrom = siblingDataFrom ?? dataFrom;\r\n siblingDataTranslated = siblingDataTranslated ?? translatedData;\r\n\r\n fields.forEach((field) => {\r\n switch (field.type) {\r\n case 'tabs':\r\n field.tabs.forEach((tab) => {\r\n const hasName = tabHasName(tab);\r\n\r\n const tabDataFrom = hasName\r\n ? (siblingDataFrom[tab.name] as Record<string, unknown>)\r\n : siblingDataFrom;\r\n\r\n if (!tabDataFrom) return;\r\n\r\n const tabDataTranslated = hasName\r\n ? (siblingDataTranslated[tab.name] as Record<string, unknown>) ?? {}\r\n : siblingDataTranslated;\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: tab.fields,\r\n localizedParent: tab.localized,\r\n siblingDataFrom: tabDataFrom,\r\n siblingDataTranslated: tabDataTranslated,\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n });\r\n\r\n break;\r\n\r\n case 'group':\r\n const groupDataFrom = siblingDataFrom[field.name] as Record<string, unknown>;\r\n\r\n if (!groupDataFrom) break;\r\n\r\n const groupDataTranslated =\r\n (siblingDataTranslated[field.name] as Record<string, unknown>) ?? {};\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: field.fields,\r\n localizedParent: field.localized,\r\n siblingDataFrom: groupDataFrom,\r\n siblingDataTranslated: groupDataTranslated,\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n\r\n break;\r\n\r\n case 'array':\r\n const arrayDataFrom = siblingDataFrom[field.name] as {\r\n id: string;\r\n }[];\r\n\r\n if (isEmpty(arrayDataFrom)) break;\r\n\r\n const arrayDataTranslated = [] as { id: string }[];\r\n\r\n const currentArrayDataInTranslated = Array.isArray(siblingDataTranslated[field.name])\r\n ? (siblingDataTranslated[field.name] as { id: string }[])\r\n : undefined;\r\n\r\n arrayDataFrom.forEach((item, index) => {\r\n const currentArrayItemInTranslated = currentArrayDataInTranslated?.[index];\r\n\r\n arrayDataTranslated.push({\r\n // ensure ids are different, Postgres doesn't like the same.\r\n ...(currentArrayItemInTranslated ?? {}),\r\n id: currentArrayItemInTranslated?.id ?? ObjectID().toHexString(),\r\n });\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: field.fields,\r\n localizedParent: localizedParent ?? field.localized,\r\n siblingDataFrom: item,\r\n siblingDataTranslated: arrayDataTranslated[index],\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n });\r\n\r\n siblingDataTranslated[field.name] = arrayDataTranslated;\r\n\r\n break;\r\n\r\n case 'blocks':\r\n const blockDataFrom = siblingDataFrom[field.name] as { blockType: string; id: string }[];\r\n\r\n if (isEmpty(blockDataFrom)) break;\r\n\r\n const currentBlockDataInTranslated = Array.isArray(siblingDataTranslated[field.name])\r\n ? (siblingDataTranslated[field.name] as { id: string }[])\r\n : undefined;\r\n\r\n const blockDataTranslated = [] as { blockType: string; id: string }[];\r\n\r\n blockDataFrom.forEach((item, index) => {\r\n const currentBlockItemInTranslated = currentBlockDataInTranslated?.[index];\r\n\r\n blockDataTranslated.push({\r\n blockType: item.blockType,\r\n // ensure ids are different, needed with Postgres\r\n ...(currentBlockItemInTranslated ?? {}),\r\n id: currentBlockItemInTranslated?.id ?? ObjectID().toHexString(),\r\n });\r\n\r\n const block = field.blocks.find((each) => each.slug === item.blockType);\r\n\r\n if (!block) throw new APIError(`Block with slug ${item.blockType} is not found`);\r\n\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: block.fields,\r\n localizedParent,\r\n siblingDataFrom: item,\r\n siblingDataTranslated: blockDataTranslated[index],\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n });\r\n\r\n siblingDataTranslated[field.name] = blockDataTranslated;\r\n\r\n break;\r\n\r\n case 'collapsible':\r\n case 'row':\r\n traverseFields({\r\n dataFrom,\r\n emptyOnly,\r\n fields: field.fields,\r\n localizedParent,\r\n siblingDataFrom,\r\n siblingDataTranslated,\r\n translatedData,\r\n valuesToTranslate,\r\n });\r\n break;\r\n\r\n // long ass cases here we have\r\n case 'date':\r\n case 'checkbox':\r\n case 'json':\r\n case 'code':\r\n case 'email':\r\n case 'number':\r\n case 'point':\r\n case 'radio':\r\n case 'relationship':\r\n case 'select':\r\n case 'upload':\r\n siblingDataTranslated[field.name] = siblingDataFrom[field.name];\r\n\r\n break;\r\n\r\n case 'text':\r\n case 'textarea':\r\n if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) return;\r\n if (emptyOnly && siblingDataTranslated[field.name]) return;\r\n\r\n valuesToTranslate.push({\r\n onTranslate: (translated: string) => {\r\n siblingDataTranslated[field.name] = translated;\r\n },\r\n value: siblingDataFrom[field.name],\r\n });\r\n break;\r\n\r\n case 'richText':\r\n if (!field.localized && !localizedParent && isEmpty(siblingDataFrom[field.name])) break;\r\n if (emptyOnly && siblingDataTranslated[field.name]) return;\r\n const richTextDataFrom = siblingDataFrom[field.name] as object;\r\n\r\n siblingDataTranslated[field.name] = richTextDataFrom;\r\n const isSlate = Array.isArray(richTextDataFrom);\r\n\r\n const isLexical = 'root' in richTextDataFrom;\r\n\r\n if (!isSlate && !isLexical) break;\r\n\r\n const root = (\r\n isLexical\r\n ? (siblingDataTranslated[field.name] as Record<string, unknown>).root\r\n : (siblingDataTranslated[field.name] as unknown[])?.[0]\r\n ) as Record<string, unknown>;\r\n\r\n traverseRichText({\r\n onText: (siblingData) => {\r\n valuesToTranslate.push({\r\n onTranslate: (translated: string) => {\r\n siblingData.text = translated;\r\n },\r\n value: siblingData.text,\r\n });\r\n },\r\n root,\r\n });\r\n\r\n break;\r\n\r\n default:\r\n break;\r\n }\r\n });\r\n};\r\n"],"names":["ObjectID","APIError","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,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,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,CAAC,IACjEV;oBAEJN,eAAe;wBACbC;wBACAC;wBACAC,QAAQU,IAAIV,MAAM;wBAClBC,iBAAiBS,IAAIK,SA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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;gBACpC,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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@payload-enchants/translator",
3
3
  "private": false,
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "repository": "https://github.com/r1tsuu/payload-enchants",
6
6
  "author": "r1tsuu",
7
7
  "bugs": "https://github.com/r1tsuu/payload-enchants/issues",