@intlayer/design-system 4.1.7 → 4.1.8

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 (286) hide show
  1. package/package.json +22 -19
  2. package/dist/CodeBlockShiki-BlmZyrr7.cjs +0 -29
  3. package/dist/CodeBlockShiki-BlmZyrr7.cjs.map +0 -1
  4. package/dist/CodeBlockShiki-CcpV9SVi.js +0 -29
  5. package/dist/CodeBlockShiki-CcpV9SVi.js.map +0 -1
  6. package/dist/CopyButton-Cxu3goRg.cjs +0 -59
  7. package/dist/CopyButton-Cxu3goRg.cjs.map +0 -1
  8. package/dist/CopyButton-DlcDlf6U.js +0 -60
  9. package/dist/CopyButton-DlcDlf6U.js.map +0 -1
  10. package/dist/Form-0D7KBafQ.cjs +0 -311
  11. package/dist/Form-0D7KBafQ.cjs.map +0 -1
  12. package/dist/Form-7BqwvjVI.cjs +0 -320
  13. package/dist/Form-7BqwvjVI.cjs.map +0 -1
  14. package/dist/Form-B2UufQRJ.cjs +0 -319
  15. package/dist/Form-B2UufQRJ.cjs.map +0 -1
  16. package/dist/Form-BB0kpER9.cjs +0 -301
  17. package/dist/Form-BB0kpER9.cjs.map +0 -1
  18. package/dist/Form-BDcoNTLV.cjs +0 -300
  19. package/dist/Form-BDcoNTLV.cjs.map +0 -1
  20. package/dist/Form-BTogr-fp.js +0 -312
  21. package/dist/Form-BTogr-fp.js.map +0 -1
  22. package/dist/Form-BVkkvSKP.js +0 -312
  23. package/dist/Form-BVkkvSKP.js.map +0 -1
  24. package/dist/Form-Be6Uhb5-.js +0 -312
  25. package/dist/Form-Be6Uhb5-.js.map +0 -1
  26. package/dist/Form-BmQQnl-6.js +0 -312
  27. package/dist/Form-BmQQnl-6.js.map +0 -1
  28. package/dist/Form-BoWOdiwq.js +0 -321
  29. package/dist/Form-BoWOdiwq.js.map +0 -1
  30. package/dist/Form-Bp_ubH9I.cjs +0 -311
  31. package/dist/Form-Bp_ubH9I.cjs.map +0 -1
  32. package/dist/Form-BtqRbgLu.cjs +0 -311
  33. package/dist/Form-BtqRbgLu.cjs.map +0 -1
  34. package/dist/Form-COVZyto7.cjs +0 -311
  35. package/dist/Form-COVZyto7.cjs.map +0 -1
  36. package/dist/Form-CVD_3nCD.js +0 -312
  37. package/dist/Form-CVD_3nCD.js.map +0 -1
  38. package/dist/Form-Cfklj1_H.js +0 -320
  39. package/dist/Form-Cfklj1_H.js.map +0 -1
  40. package/dist/Form-ClAAiVNm.cjs +0 -311
  41. package/dist/Form-ClAAiVNm.cjs.map +0 -1
  42. package/dist/Form-DGLgTAdY.js +0 -302
  43. package/dist/Form-DGLgTAdY.js.map +0 -1
  44. package/dist/Form-DhsgC7kB.js +0 -301
  45. package/dist/Form-DhsgC7kB.js.map +0 -1
  46. package/dist/Form-Dv0uHqbL.cjs +0 -320
  47. package/dist/Form-Dv0uHqbL.cjs.map +0 -1
  48. package/dist/Form-OK9zfg6E.js +0 -321
  49. package/dist/Form-OK9zfg6E.js.map +0 -1
  50. package/dist/components/ContentEditor/ContentEditorCode.cjs +0 -78
  51. package/dist/components/ContentEditor/ContentEditorCode.cjs.map +0 -1
  52. package/dist/components/ContentEditor/ContentEditorCode.d.ts +0 -11
  53. package/dist/components/ContentEditor/ContentEditorCode.d.ts.map +0 -1
  54. package/dist/components/ContentEditor/ContentEditorCode.mjs +0 -78
  55. package/dist/components/ContentEditor/ContentEditorCode.mjs.map +0 -1
  56. package/dist/components/DictionaryEditor/useEditedContentStore.cjs +0 -490
  57. package/dist/components/DictionaryEditor/useEditedContentStore.cjs.map +0 -1
  58. package/dist/components/DictionaryEditor/useEditedContentStore.d.ts +0 -28
  59. package/dist/components/DictionaryEditor/useEditedContentStore.d.ts.map +0 -1
  60. package/dist/components/DictionaryEditor/useEditedContentStore.mjs +0 -490
  61. package/dist/components/DictionaryEditor/useEditedContentStore.mjs.map +0 -1
  62. package/dist/components/DictionaryEditor/useEditionPanelStore.cjs +0 -15
  63. package/dist/components/DictionaryEditor/useEditionPanelStore.cjs.map +0 -1
  64. package/dist/components/DictionaryEditor/useEditionPanelStore.d.ts +0 -15
  65. package/dist/components/DictionaryEditor/useEditionPanelStore.d.ts.map +0 -1
  66. package/dist/components/DictionaryEditor/useEditionPanelStore.mjs +0 -15
  67. package/dist/components/DictionaryEditor/useEditionPanelStore.mjs.map +0 -1
  68. package/dist/components/DictionaryFieldEditor/LocaleSelector/LocaleSelector.d.ts +0 -8
  69. package/dist/components/DictionaryFieldEditor/LocaleSelector/LocaleSelector.d.ts.map +0 -1
  70. package/dist/components/DictionaryFieldEditor/LocaleSelector/LocaleSelectorContext.d.ts +0 -13
  71. package/dist/components/DictionaryFieldEditor/LocaleSelector/LocaleSelectorContext.d.ts.map +0 -1
  72. package/dist/components/DictionaryFieldEditor/LocaleSelector/localeSelector.content.d.ts +0 -9
  73. package/dist/components/DictionaryFieldEditor/LocaleSelector/localeSelector.content.d.ts.map +0 -1
  74. package/dist/components/DropDown/types.cjs +0 -2
  75. package/dist/components/DropDown/types.cjs.map +0 -1
  76. package/dist/components/DropDown/types.d.ts +0 -19
  77. package/dist/components/DropDown/types.d.ts.map +0 -1
  78. package/dist/components/DropDown/types.mjs +0 -2
  79. package/dist/components/DropDown/types.mjs.map +0 -1
  80. package/dist/components/IDE/CodeBlock.cjs +0 -54
  81. package/dist/components/IDE/CodeBlock.cjs.map +0 -1
  82. package/dist/components/IDE/CodeBlock.d.ts +0 -12
  83. package/dist/components/IDE/CodeBlock.d.ts.map +0 -1
  84. package/dist/components/IDE/CodeBlock.mjs +0 -54
  85. package/dist/components/IDE/CodeBlock.mjs.map +0 -1
  86. package/dist/components/IDE/CodeBlockLoader.cjs +0 -28
  87. package/dist/components/IDE/CodeBlockLoader.cjs.map +0 -1
  88. package/dist/components/IDE/CodeBlockLoader.d.ts +0 -4
  89. package/dist/components/IDE/CodeBlockLoader.d.ts.map +0 -1
  90. package/dist/components/IDE/CodeBlockLoader.mjs +0 -28
  91. package/dist/components/IDE/CodeBlockLoader.mjs.map +0 -1
  92. package/dist/components/IDE/CodeBlockShiki.d.ts +0 -3
  93. package/dist/components/IDE/CodeBlockShiki.d.ts.map +0 -1
  94. package/dist/components/IDE/CodeRender copy.cjs +0 -141
  95. package/dist/components/IDE/CodeRender copy.cjs.map +0 -1
  96. package/dist/components/IDE/CodeRender copy.d.ts +0 -14
  97. package/dist/components/IDE/CodeRender copy.d.ts.map +0 -1
  98. package/dist/components/IDE/CodeRender copy.mjs +0 -141
  99. package/dist/components/IDE/CodeRender copy.mjs.map +0 -1
  100. package/dist/components/IDE/CodeRender.cjs +0 -49
  101. package/dist/components/IDE/CodeRender.cjs.map +0 -1
  102. package/dist/components/IDE/CodeRender.d.ts +0 -9
  103. package/dist/components/IDE/CodeRender.d.ts.map +0 -1
  104. package/dist/components/IDE/CodeRender.mjs +0 -49
  105. package/dist/components/IDE/CodeRender.mjs.map +0 -1
  106. package/dist/components/IDE/CodeRenderer.cjs +0 -27
  107. package/dist/components/IDE/CodeRenderer.cjs.map +0 -1
  108. package/dist/components/IDE/CodeRenderer.d.ts +0 -5
  109. package/dist/components/IDE/CodeRenderer.d.ts.map +0 -1
  110. package/dist/components/IDE/CodeRenderer.mjs +0 -27
  111. package/dist/components/IDE/CodeRenderer.mjs.map +0 -1
  112. package/dist/components/IDE/EditableCodeBlock.d.ts +0 -9
  113. package/dist/components/IDE/EditableCodeBlock.d.ts.map +0 -1
  114. package/dist/components/LocaleSwitcherContentDropDown/LocaleSelectorContext.d.ts +0 -13
  115. package/dist/components/LocaleSwitcherContentDropDown/LocaleSelectorContext.d.ts.map +0 -1
  116. package/dist/design-system.css +0 -235
  117. package/dist/index-Ai6eeqZH.js +0 -702
  118. package/dist/index-Ai6eeqZH.js.map +0 -1
  119. package/dist/index-B-VAyQ9R.js +0 -673
  120. package/dist/index-B-VAyQ9R.js.map +0 -1
  121. package/dist/index-B1nU1-65.cjs +0 -690
  122. package/dist/index-B1nU1-65.cjs.map +0 -1
  123. package/dist/index-B2UElBcQ.cjs +0 -200
  124. package/dist/index-B2UElBcQ.cjs.map +0 -1
  125. package/dist/index-BIV0x_z2.js +0 -206
  126. package/dist/index-BIV0x_z2.js.map +0 -1
  127. package/dist/index-BIyA5LAs.js +0 -691
  128. package/dist/index-BIyA5LAs.js.map +0 -1
  129. package/dist/index-BMzh1_UJ.js +0 -201
  130. package/dist/index-BMzh1_UJ.js.map +0 -1
  131. package/dist/index-BNH9wXVj.cjs +0 -205
  132. package/dist/index-BNH9wXVj.cjs.map +0 -1
  133. package/dist/index-BbqOa6BU.cjs +0 -701
  134. package/dist/index-BbqOa6BU.cjs.map +0 -1
  135. package/dist/index-BdTa-9zc.js +0 -201
  136. package/dist/index-BdTa-9zc.js.map +0 -1
  137. package/dist/index-BqZwP4Lr.js +0 -691
  138. package/dist/index-BqZwP4Lr.js.map +0 -1
  139. package/dist/index-BtZWYJhL.cjs +0 -200
  140. package/dist/index-BtZWYJhL.cjs.map +0 -1
  141. package/dist/index-Buecpjbh.cjs +0 -690
  142. package/dist/index-Buecpjbh.cjs.map +0 -1
  143. package/dist/index-CDEJjmId.js +0 -694
  144. package/dist/index-CDEJjmId.js.map +0 -1
  145. package/dist/index-CTAyk6RY.cjs +0 -693
  146. package/dist/index-CTAyk6RY.cjs.map +0 -1
  147. package/dist/index-CVC2sfEj.js +0 -693
  148. package/dist/index-CVC2sfEj.js.map +0 -1
  149. package/dist/index-CVz0RdK6.js +0 -691
  150. package/dist/index-CVz0RdK6.js.map +0 -1
  151. package/dist/index-CjF2ksU7.cjs +0 -693
  152. package/dist/index-CjF2ksU7.cjs.map +0 -1
  153. package/dist/index-CuQs5759.cjs +0 -692
  154. package/dist/index-CuQs5759.cjs.map +0 -1
  155. package/dist/index-D69JRZcQ.js +0 -206
  156. package/dist/index-D69JRZcQ.js.map +0 -1
  157. package/dist/index-D9oaKvKC.js +0 -201
  158. package/dist/index-D9oaKvKC.js.map +0 -1
  159. package/dist/index-DFc7og1d.cjs +0 -671
  160. package/dist/index-DFc7og1d.cjs.map +0 -1
  161. package/dist/index-DTCehvKe.cjs +0 -200
  162. package/dist/index-DTCehvKe.cjs.map +0 -1
  163. package/dist/index-D_MDocy7.cjs +0 -690
  164. package/dist/index-D_MDocy7.cjs.map +0 -1
  165. package/dist/index-DcWYZrJW.js +0 -672
  166. package/dist/index-DcWYZrJW.js.map +0 -1
  167. package/dist/index-Djo2Jnua.cjs +0 -693
  168. package/dist/index-Djo2Jnua.cjs.map +0 -1
  169. package/dist/index-LFTthFne.js +0 -694
  170. package/dist/index-LFTthFne.js.map +0 -1
  171. package/dist/index-SOIahRpS.cjs +0 -205
  172. package/dist/index-SOIahRpS.cjs.map +0 -1
  173. package/dist/index-T-TjVQoD.js +0 -671
  174. package/dist/index-T-TjVQoD.js.map +0 -1
  175. package/dist/index-f8_VC6c8.cjs +0 -672
  176. package/dist/index-f8_VC6c8.cjs.map +0 -1
  177. package/dist/index-llGIfxqV.cjs +0 -670
  178. package/dist/index-llGIfxqV.cjs.map +0 -1
  179. package/dist/index-xZoGTokf.js +0 -694
  180. package/dist/index-xZoGTokf.js.map +0 -1
  181. package/dist/jsx-runtime-CL03FswV.cjs +0 -506
  182. package/dist/jsx-runtime-CL03FswV.cjs.map +0 -1
  183. package/dist/jsx-runtime-DaNGiM0W.js +0 -945
  184. package/dist/jsx-runtime-DaNGiM0W.js.map +0 -1
  185. package/dist/jsx-runtime-XHKiWCTo.cjs +0 -944
  186. package/dist/jsx-runtime-XHKiWCTo.cjs.map +0 -1
  187. package/dist/jsx-runtime-kmx34TxC.js +0 -507
  188. package/dist/jsx-runtime-kmx34TxC.js.map +0 -1
  189. package/dist/libs/index.cjs +0 -6
  190. package/dist/libs/index.cjs.map +0 -1
  191. package/dist/libs/index.d.ts +0 -2
  192. package/dist/libs/index.d.ts.map +0 -1
  193. package/dist/libs/index.mjs +0 -6
  194. package/dist/libs/index.mjs.map +0 -1
  195. package/dist/libs/intlayer-api/ai.cjs +0 -64
  196. package/dist/libs/intlayer-api/ai.cjs.map +0 -1
  197. package/dist/libs/intlayer-api/ai.d.ts +0 -18
  198. package/dist/libs/intlayer-api/ai.d.ts.map +0 -1
  199. package/dist/libs/intlayer-api/ai.mjs +0 -64
  200. package/dist/libs/intlayer-api/ai.mjs.map +0 -1
  201. package/dist/libs/intlayer-api/auth.cjs +0 -141
  202. package/dist/libs/intlayer-api/auth.cjs.map +0 -1
  203. package/dist/libs/intlayer-api/auth.d.ts +0 -38
  204. package/dist/libs/intlayer-api/auth.d.ts.map +0 -1
  205. package/dist/libs/intlayer-api/auth.mjs +0 -141
  206. package/dist/libs/intlayer-api/auth.mjs.map +0 -1
  207. package/dist/libs/intlayer-api/dictionary.cjs +0 -78
  208. package/dist/libs/intlayer-api/dictionary.cjs.map +0 -1
  209. package/dist/libs/intlayer-api/dictionary.d.ts +0 -22
  210. package/dist/libs/intlayer-api/dictionary.d.ts.map +0 -1
  211. package/dist/libs/intlayer-api/dictionary.mjs +0 -78
  212. package/dist/libs/intlayer-api/dictionary.mjs.map +0 -1
  213. package/dist/libs/intlayer-api/fetcher.cjs +0 -73
  214. package/dist/libs/intlayer-api/fetcher.cjs.map +0 -1
  215. package/dist/libs/intlayer-api/fetcher.d.ts +0 -70
  216. package/dist/libs/intlayer-api/fetcher.d.ts.map +0 -1
  217. package/dist/libs/intlayer-api/fetcher.mjs +0 -73
  218. package/dist/libs/intlayer-api/fetcher.mjs.map +0 -1
  219. package/dist/libs/intlayer-api/index.cjs +0 -24
  220. package/dist/libs/intlayer-api/index.cjs.map +0 -1
  221. package/dist/libs/intlayer-api/index.d.ts +0 -157
  222. package/dist/libs/intlayer-api/index.d.ts.map +0 -1
  223. package/dist/libs/intlayer-api/index.mjs +0 -24
  224. package/dist/libs/intlayer-api/index.mjs.map +0 -1
  225. package/dist/libs/intlayer-api/organization.cjs +0 -96
  226. package/dist/libs/intlayer-api/organization.cjs.map +0 -1
  227. package/dist/libs/intlayer-api/organization.d.ts +0 -26
  228. package/dist/libs/intlayer-api/organization.d.ts.map +0 -1
  229. package/dist/libs/intlayer-api/organization.mjs +0 -96
  230. package/dist/libs/intlayer-api/organization.mjs.map +0 -1
  231. package/dist/libs/intlayer-api/project.cjs +0 -110
  232. package/dist/libs/intlayer-api/project.cjs.map +0 -1
  233. package/dist/libs/intlayer-api/project.d.ts +0 -28
  234. package/dist/libs/intlayer-api/project.d.ts.map +0 -1
  235. package/dist/libs/intlayer-api/project.mjs +0 -110
  236. package/dist/libs/intlayer-api/project.mjs.map +0 -1
  237. package/dist/libs/intlayer-api/stripe.cjs +0 -31
  238. package/dist/libs/intlayer-api/stripe.cjs.map +0 -1
  239. package/dist/libs/intlayer-api/stripe.d.ts +0 -8
  240. package/dist/libs/intlayer-api/stripe.d.ts.map +0 -1
  241. package/dist/libs/intlayer-api/stripe.mjs +0 -31
  242. package/dist/libs/intlayer-api/stripe.mjs.map +0 -1
  243. package/dist/libs/intlayer-api/tag.cjs +0 -52
  244. package/dist/libs/intlayer-api/tag.cjs.map +0 -1
  245. package/dist/libs/intlayer-api/tag.d.ts +0 -16
  246. package/dist/libs/intlayer-api/tag.d.ts.map +0 -1
  247. package/dist/libs/intlayer-api/tag.mjs +0 -52
  248. package/dist/libs/intlayer-api/tag.mjs.map +0 -1
  249. package/dist/libs/intlayer-api/user.cjs +0 -70
  250. package/dist/libs/intlayer-api/user.cjs.map +0 -1
  251. package/dist/libs/intlayer-api/user.d.ts +0 -22
  252. package/dist/libs/intlayer-api/user.d.ts.map +0 -1
  253. package/dist/libs/intlayer-api/user.mjs +0 -70
  254. package/dist/libs/intlayer-api/user.mjs.map +0 -1
  255. package/dist/navigation-CE0LMHcY.cjs +0 -8538
  256. package/dist/navigation-CE0LMHcY.cjs.map +0 -1
  257. package/dist/navigation-DFabQmdZ.js +0 -914
  258. package/dist/navigation-DFabQmdZ.js.map +0 -1
  259. package/dist/navigation-DRtAVQJF.js +0 -8521
  260. package/dist/navigation-DRtAVQJF.js.map +0 -1
  261. package/dist/navigation-a7EfWhxz.cjs +0 -913
  262. package/dist/navigation-a7EfWhxz.cjs.map +0 -1
  263. package/dist/shallow-lhDIFtEp.cjs +0 -48
  264. package/dist/shallow-lhDIFtEp.cjs.map +0 -1
  265. package/dist/shallow-m9BpCkKh.js +0 -49
  266. package/dist/shallow-m9BpCkKh.js.map +0 -1
  267. package/dist/useGetAllDictionaries-B1sqs2IB.cjs +0 -34
  268. package/dist/useGetAllDictionaries-B1sqs2IB.cjs.map +0 -1
  269. package/dist/useGetAllDictionaries-BbH8vTkY.js +0 -35
  270. package/dist/useGetAllDictionaries-BbH8vTkY.js.map +0 -1
  271. package/dist/useGetAllDictionaries-Bgkytpa2.cjs +0 -34
  272. package/dist/useGetAllDictionaries-Bgkytpa2.cjs.map +0 -1
  273. package/dist/useGetAllDictionaries-D8ma3h41.cjs +0 -33
  274. package/dist/useGetAllDictionaries-D8ma3h41.cjs.map +0 -1
  275. package/dist/useGetAllDictionaries-DHgHEbD5.js +0 -34
  276. package/dist/useGetAllDictionaries-DHgHEbD5.js.map +0 -1
  277. package/dist/useGetAllDictionaries-DUzm0rIa.js +0 -35
  278. package/dist/useGetAllDictionaries-DUzm0rIa.js.map +0 -1
  279. package/dist/utils/dictionary.cjs +0 -158
  280. package/dist/utils/dictionary.cjs.map +0 -1
  281. package/dist/utils/dictionary.d.ts +0 -7
  282. package/dist/utils/dictionary.d.ts.map +0 -1
  283. package/dist/utils/dictionary.mjs +0 -158
  284. package/dist/utils/dictionary.mjs.map +0 -1
  285. /package/dist/components/IDE/{CodeBlockclient.d.ts → CodeBlockClient.d.ts} +0 -0
  286. /package/dist/components/IDE/{CodeBlockclient.d.ts.map → CodeBlockClient.d.ts.map} +0 -0
@@ -1,158 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const core = require("@intlayer/core");
4
- const require$$0 = require("react");
5
- const getDictionaryValueByKeyPath = (dictionaryContent, keyPath) => {
6
- let currentValue = JSON.parse(JSON.stringify(dictionaryContent ?? {}));
7
- for (const keyObj of keyPath) {
8
- if (keyObj.type === core.NodeType.Object || keyObj.type === core.NodeType.Array) {
9
- currentValue = currentValue?.[keyObj.key];
10
- } else if (keyObj.type === core.NodeType.Translation) {
11
- currentValue = currentValue?.[core.NodeType.Translation][keyObj.key];
12
- } else if (keyObj.type === core.NodeType.Enumeration) {
13
- currentValue = currentValue?.[core.NodeType.Enumeration][keyObj.key];
14
- }
15
- }
16
- return currentValue;
17
- };
18
- const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
19
- let currentValue = dictionaryContent;
20
- let parentValue = null;
21
- let lastKeys = [];
22
- for (const keyObj of keyPath) {
23
- parentValue = currentValue;
24
- if (keyObj.type === core.NodeType.Object) {
25
- lastKeys = [keyObj.key];
26
- if (!currentValue[keyObj.key]) {
27
- currentValue = {
28
- ...currentValue,
29
- [keyObj.key]: {}
30
- };
31
- }
32
- currentValue = currentValue[keyObj.key];
33
- } else if (keyObj.type === core.NodeType.Array) {
34
- lastKeys = [keyObj.key];
35
- if (!currentValue[keyObj.key]) {
36
- currentValue[keyObj.key] = {};
37
- }
38
- currentValue = currentValue[keyObj.key];
39
- } else if (keyObj.type === core.NodeType.Translation) {
40
- lastKeys = [core.NodeType.Translation, keyObj.key];
41
- if (!currentValue[core.NodeType.Translation]) {
42
- currentValue[core.NodeType.Translation] = {
43
- ...currentValue[core.NodeType.Translation],
44
- [keyObj.key]: newValue
45
- };
46
- }
47
- currentValue = currentValue[core.NodeType.Translation][keyObj.key];
48
- } else if (keyObj.type === core.NodeType.Enumeration) {
49
- lastKeys = [core.NodeType.Enumeration, keyObj.key];
50
- if (!currentValue[core.NodeType.Enumeration]) {
51
- currentValue[core.NodeType.Enumeration] = {
52
- ...currentValue[core.NodeType.Enumeration],
53
- [keyObj.key]: newValue
54
- };
55
- }
56
- currentValue = currentValue[core.NodeType.Enumeration][keyObj.key];
57
- }
58
- }
59
- if (parentValue && lastKeys.length > 0) {
60
- for (const key of lastKeys.slice(0, -1)) {
61
- parentValue = parentValue[key];
62
- }
63
- if (
64
- // Remove the field if the new value is undefined
65
- typeof newValue === "undefined"
66
- ) {
67
- delete parentValue[lastKeys[lastKeys.length - 1]];
68
- } else {
69
- parentValue[lastKeys[lastKeys.length - 1]] = newValue;
70
- }
71
- }
72
- return dictionaryContent;
73
- };
74
- const removeDictionaryValueByKeyPath = (dictionaryContent, keyPath) => {
75
- let currentValue = dictionaryContent;
76
- let parentValue = null;
77
- let lastKey = null;
78
- for (const keyObj of keyPath) {
79
- parentValue = currentValue;
80
- if (keyObj.type === core.NodeType.Object || keyObj.type === core.NodeType.Array) {
81
- lastKey = keyObj.key;
82
- currentValue = currentValue[keyObj.key];
83
- } else if (keyObj.type === core.NodeType.Translation) {
84
- lastKey = core.NodeType.Translation;
85
- currentValue = currentValue[core.NodeType.Translation][keyObj.key];
86
- } else if (keyObj.type === core.NodeType.Enumeration) {
87
- lastKey = core.NodeType.Enumeration;
88
- currentValue = currentValue[core.NodeType.Enumeration][keyObj.key];
89
- }
90
- }
91
- if (parentValue && lastKey !== null) {
92
- if (Array.isArray(parentValue)) {
93
- parentValue.splice(lastKey, 1);
94
- } else {
95
- delete parentValue[lastKey];
96
- }
97
- }
98
- return dictionaryContent;
99
- };
100
- const renameDictionaryValueByKeyPath = (dictionaryContent, newKey, keyPath) => {
101
- let currentValue = dictionaryContent;
102
- let parentValue = null;
103
- let lastKey = null;
104
- for (const keyObj of keyPath) {
105
- parentValue = currentValue;
106
- if (keyObj.type === core.NodeType.Object || keyObj.type === core.NodeType.Array) {
107
- lastKey = keyObj.key;
108
- currentValue = currentValue[keyObj.key];
109
- } else if (keyObj.type === core.NodeType.Translation) {
110
- lastKey = core.NodeType.Translation;
111
- currentValue = currentValue[core.NodeType.Translation][keyObj.key];
112
- } else if (keyObj.type === core.NodeType.Enumeration) {
113
- lastKey = core.NodeType.Enumeration;
114
- currentValue = currentValue[core.NodeType.Enumeration][keyObj.key];
115
- }
116
- }
117
- if (parentValue && lastKey !== null) {
118
- if (Array.isArray(parentValue)) {
119
- parentValue[lastKey] = currentValue;
120
- } else {
121
- const newParentValue = {};
122
- for (const key of Object.keys(parentValue)) {
123
- if (key === lastKey) {
124
- newParentValue[newKey] = currentValue;
125
- } else {
126
- newParentValue[key] = parentValue[key];
127
- }
128
- }
129
- Object.keys(parentValue).forEach((key) => delete parentValue[key]);
130
- Object.assign(parentValue, newParentValue);
131
- }
132
- }
133
- return dictionaryContent;
134
- };
135
- const getSectionType = (section) => {
136
- if (typeof section === "string") {
137
- return core.NodeType.Text;
138
- }
139
- if (section?.nodeType === core.NodeType.Translation) {
140
- return core.NodeType.Translation;
141
- }
142
- if (section?.nodeType === core.NodeType.Enumeration) {
143
- return core.NodeType.Enumeration;
144
- }
145
- if (Array.isArray(section)) {
146
- return core.NodeType.Array;
147
- }
148
- if (require$$0.isValidElement(section)) {
149
- return core.NodeType.ReactNode;
150
- }
151
- return core.NodeType.Object;
152
- };
153
- exports.editDictionaryByKeyPath = editDictionaryByKeyPath;
154
- exports.getDictionaryValueByKeyPath = getDictionaryValueByKeyPath;
155
- exports.getSectionType = getSectionType;
156
- exports.removeDictionaryValueByKeyPath = removeDictionaryValueByKeyPath;
157
- exports.renameDictionaryValueByKeyPath = renameDictionaryValueByKeyPath;
158
- //# sourceMappingURL=dictionary.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dictionary.cjs","sources":["../../src/utils/dictionary.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n NodeType,\n type TranslationContent,\n type DictionaryValue,\n type KeyPath,\n type EnumerationContent,\n} from '@intlayer/core';\nimport { isValidElement } from 'react';\n\nexport const getDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = JSON.parse(JSON.stringify(dictionaryContent ?? {}));\n\n for (const keyObj of keyPath) {\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];\n }\n }\n\n return currentValue as DictionaryValue;\n};\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[],\n newValue: DictionaryValue\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object) {\n lastKeys = [keyObj.key];\n\n if (!currentValue[keyObj.key]) {\n currentValue = {\n ...currentValue,\n [keyObj.key]: {},\n };\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n\n if (!currentValue[keyObj.key]) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKeys = [NodeType.Translation, keyObj.key];\n\n if (!currentValue[NodeType.Translation]) {\n currentValue[NodeType.Translation] = {\n ...currentValue[NodeType.Translation],\n [keyObj.key]: newValue,\n };\n }\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKeys = [NodeType.Enumeration, keyObj.key];\n\n if (!currentValue[NodeType.Enumeration]) {\n currentValue[NodeType.Enumeration] = {\n ...currentValue[NodeType.Enumeration],\n [keyObj.key]: newValue,\n };\n }\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n // Assign the new value to the last key of the parent\n if (parentValue && lastKeys.length > 0) {\n for (const key of lastKeys.slice(0, -1)) {\n parentValue = parentValue[key];\n }\n if (\n // Remove the field if the new value is undefined\n typeof newValue === 'undefined'\n ) {\n delete parentValue[lastKeys[lastKeys.length - 1]];\n } else {\n parentValue[lastKeys[lastKeys.length - 1]] = newValue;\n }\n }\n\n return dictionaryContent;\n};\n\nexport const removeDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKey = NodeType.Translation;\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKey = NodeType.Enumeration;\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n\nexport const renameDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n newKey: string | number,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKey = NodeType.Translation;\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKey = NodeType.Enumeration;\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n // Assign the new value to the last key of the parent while preserving the order\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue[lastKey as number] = currentValue;\n } else {\n const newParentValue: any = {};\n for (const key of Object.keys(parentValue)) {\n if (key === lastKey) {\n newParentValue[newKey] = currentValue;\n } else {\n newParentValue[key] = parentValue[key];\n }\n }\n // Replace the contents of parentValue with newParentValue\n Object.keys(parentValue).forEach((key) => delete parentValue[key]);\n Object.assign(parentValue, newParentValue);\n }\n }\n\n return dictionaryContent;\n};\n\nexport const getSectionType = (section: DictionaryValue): NodeType => {\n if (typeof section === 'string') {\n return NodeType.Text;\n }\n\n if (\n (section as TranslationContent<unknown>)?.nodeType === NodeType.Translation\n ) {\n return NodeType.Translation;\n }\n\n if (\n (section as EnumerationContent<unknown>)?.nodeType === NodeType.Enumeration\n ) {\n return NodeType.Enumeration;\n }\n\n if (Array.isArray(section)) {\n return NodeType.Array;\n }\n\n if (isValidElement(section)) {\n return NodeType.ReactNode;\n }\n\n return NodeType.Object;\n};\n"],"names":["NodeType","isValidElement"],"mappings":";;;;AAUa,MAAA,8BAA8B,CACzC,mBACA,YACoB;AAChB,MAAA,eAAoB,KAAK,MAAM,KAAK,UAAU,qBAAqB,CAAA,CAAE,CAAC;AAE1E,aAAW,UAAU,SAAS;AAC5B,QAAI,OAAO,SAASA,cAAS,UAAU,OAAO,SAASA,cAAS,OAAO;AACtD,qBAAA,eAAe,OAAO,GAAG;AAAA,IAC/B,WAAA,OAAO,SAASA,KAAAA,SAAS,aAAa;AAC/C,qBAAe,eAAeA,KAAA,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IACrD,WAAA,OAAO,SAASA,KAAAA,SAAS,aAAa;AAC/C,qBAAe,eAAeA,KAAA,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAAA;AAAA,EAChE;AAGK,SAAA;AACT;AAIO,MAAM,0BAA0B,CACrC,mBACA,SACA,aACoB;AACpB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,WAA0B,CAAC;AAE/B,aAAW,UAAU,SAAS;AACd,kBAAA;AAEV,QAAA,OAAO,SAASA,KAAA,SAAS,QAAQ;AACxB,iBAAA,CAAC,OAAO,GAAG;AAEtB,UAAI,CAAC,aAAa,OAAO,GAAG,GAAG;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,EAAE,OAAO,GAAG;AAAA,IACnD,WAAA,OAAO,SAASA,KAAAA,SAAS,aAAa;AAC/C,gBAAUA,KAAS,SAAA;AACnB,qBAAe,aAAaA,KAAA,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAAA;AAAA,EAC9D;AAIE,MAAA,eAAe,YAAY,MAAM;AAC/B,QAAA,MAAM,QAAQ,WAAW,GAAG;AAC9B,kBAAY,OAAiB,IAAI;AAAA,IAAA,OAC5B;AACL,YAAM,iBAAsB,CAAC;AAC7B,iBAAW,OAAO,OAAO,KAAK,WAAW,GAAG;AAC1C,YAAI,QAAQ,SAAS;AACnB,yBAAe,MAAM,IAAI;AAAA,QAAA,OACpB;AACU,yBAAA,GAAG,IAAI,YAAY,GAAG;AAAA,QAAA;AAAA,MACvC;AAGK,aAAA,KAAK,WAAW,EAAE,QAAQ,CAAC,QAAQ,OAAO,YAAY,GAAG,CAAC;AAC1D,aAAA,OAAO,aAAa,cAAc;AAAA,IAAA;AAAA,EAC3C;AAGK,SAAA;AACT;AAEa,MAAA,iBAAiB,CAAC,YAAuC;AAChE,MAAA,OAAO,YAAY,UAAU;AAC/B,WAAOA,KAAS,SAAA;AAAA,EAAA;AAIf,MAAA,SAAyC,aAAaA,KAAA,SAAS,aAChE;AACA,WAAOA,KAAS,SAAA;AAAA,EAAA;AAIf,MAAA,SAAyC,aAAaA,KAAA,SAAS,aAChE;AACA,WAAOA,KAAS,SAAA;AAAA,EAAA;AAGd,MAAA,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAOA,KAAS,SAAA;AAAA,EAAA;AAGd,MAAAC,WAAAA,eAAe,OAAO,GAAG;AAC3B,WAAOD,KAAS,SAAA;AAAA,EAAA;AAGlB,SAAOA,KAAS,SAAA;AAClB;;;;;;"}
@@ -1,7 +0,0 @@
1
- import { NodeType, DictionaryValue, KeyPath } from '@intlayer/core';
2
- export declare const getDictionaryValueByKeyPath: (dictionaryContent: DictionaryValue, keyPath: KeyPath[]) => DictionaryValue;
3
- export declare const editDictionaryByKeyPath: (dictionaryContent: DictionaryValue, keyPath: KeyPath[], newValue: DictionaryValue) => DictionaryValue;
4
- export declare const removeDictionaryValueByKeyPath: (dictionaryContent: DictionaryValue, keyPath: KeyPath[]) => DictionaryValue;
5
- export declare const renameDictionaryValueByKeyPath: (dictionaryContent: DictionaryValue, newKey: string | number, keyPath: KeyPath[]) => DictionaryValue;
6
- export declare const getSectionType: (section: DictionaryValue) => NodeType;
7
- //# sourceMappingURL=dictionary.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dictionary.d.ts","sourceRoot":"","sources":["../../src/utils/dictionary.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAER,KAAK,eAAe,EACpB,KAAK,OAAO,EAEb,MAAM,gBAAgB,CAAC;AAGxB,eAAO,MAAM,2BAA2B,sBACnB,eAAe,WACzB,OAAO,EAAE,KACjB,eAcF,CAAC;AAIF,eAAO,MAAM,uBAAuB,sBACf,eAAe,WACzB,OAAO,EAAE,YACR,eAAe,KACxB,eAgEF,CAAC;AAEF,eAAO,MAAM,8BAA8B,sBACtB,eAAe,WACzB,OAAO,EAAE,KACjB,eA6BF,CAAC;AAEF,eAAO,MAAM,8BAA8B,sBACtB,eAAe,UAC1B,MAAM,GAAG,MAAM,WACd,OAAO,EAAE,KACjB,eAwCF,CAAC;AAEF,eAAO,MAAM,cAAc,YAAa,eAAe,KAAG,QA0BzD,CAAC"}
@@ -1,158 +0,0 @@
1
- import { NodeType } from "@intlayer/core";
2
- import { isValidElement } from "react";
3
- const getDictionaryValueByKeyPath = (dictionaryContent, keyPath) => {
4
- let currentValue = JSON.parse(JSON.stringify(dictionaryContent ?? {}));
5
- for (const keyObj of keyPath) {
6
- if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
7
- currentValue = currentValue?.[keyObj.key];
8
- } else if (keyObj.type === NodeType.Translation) {
9
- currentValue = currentValue?.[NodeType.Translation][keyObj.key];
10
- } else if (keyObj.type === NodeType.Enumeration) {
11
- currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];
12
- }
13
- }
14
- return currentValue;
15
- };
16
- const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
17
- let currentValue = dictionaryContent;
18
- let parentValue = null;
19
- let lastKeys = [];
20
- for (const keyObj of keyPath) {
21
- parentValue = currentValue;
22
- if (keyObj.type === NodeType.Object) {
23
- lastKeys = [keyObj.key];
24
- if (!currentValue[keyObj.key]) {
25
- currentValue = {
26
- ...currentValue,
27
- [keyObj.key]: {}
28
- };
29
- }
30
- currentValue = currentValue[keyObj.key];
31
- } else if (keyObj.type === NodeType.Array) {
32
- lastKeys = [keyObj.key];
33
- if (!currentValue[keyObj.key]) {
34
- currentValue[keyObj.key] = {};
35
- }
36
- currentValue = currentValue[keyObj.key];
37
- } else if (keyObj.type === NodeType.Translation) {
38
- lastKeys = [NodeType.Translation, keyObj.key];
39
- if (!currentValue[NodeType.Translation]) {
40
- currentValue[NodeType.Translation] = {
41
- ...currentValue[NodeType.Translation],
42
- [keyObj.key]: newValue
43
- };
44
- }
45
- currentValue = currentValue[NodeType.Translation][keyObj.key];
46
- } else if (keyObj.type === NodeType.Enumeration) {
47
- lastKeys = [NodeType.Enumeration, keyObj.key];
48
- if (!currentValue[NodeType.Enumeration]) {
49
- currentValue[NodeType.Enumeration] = {
50
- ...currentValue[NodeType.Enumeration],
51
- [keyObj.key]: newValue
52
- };
53
- }
54
- currentValue = currentValue[NodeType.Enumeration][keyObj.key];
55
- }
56
- }
57
- if (parentValue && lastKeys.length > 0) {
58
- for (const key of lastKeys.slice(0, -1)) {
59
- parentValue = parentValue[key];
60
- }
61
- if (
62
- // Remove the field if the new value is undefined
63
- typeof newValue === "undefined"
64
- ) {
65
- delete parentValue[lastKeys[lastKeys.length - 1]];
66
- } else {
67
- parentValue[lastKeys[lastKeys.length - 1]] = newValue;
68
- }
69
- }
70
- return dictionaryContent;
71
- };
72
- const removeDictionaryValueByKeyPath = (dictionaryContent, keyPath) => {
73
- let currentValue = dictionaryContent;
74
- let parentValue = null;
75
- let lastKey = null;
76
- for (const keyObj of keyPath) {
77
- parentValue = currentValue;
78
- if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
79
- lastKey = keyObj.key;
80
- currentValue = currentValue[keyObj.key];
81
- } else if (keyObj.type === NodeType.Translation) {
82
- lastKey = NodeType.Translation;
83
- currentValue = currentValue[NodeType.Translation][keyObj.key];
84
- } else if (keyObj.type === NodeType.Enumeration) {
85
- lastKey = NodeType.Enumeration;
86
- currentValue = currentValue[NodeType.Enumeration][keyObj.key];
87
- }
88
- }
89
- if (parentValue && lastKey !== null) {
90
- if (Array.isArray(parentValue)) {
91
- parentValue.splice(lastKey, 1);
92
- } else {
93
- delete parentValue[lastKey];
94
- }
95
- }
96
- return dictionaryContent;
97
- };
98
- const renameDictionaryValueByKeyPath = (dictionaryContent, newKey, keyPath) => {
99
- let currentValue = dictionaryContent;
100
- let parentValue = null;
101
- let lastKey = null;
102
- for (const keyObj of keyPath) {
103
- parentValue = currentValue;
104
- if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
105
- lastKey = keyObj.key;
106
- currentValue = currentValue[keyObj.key];
107
- } else if (keyObj.type === NodeType.Translation) {
108
- lastKey = NodeType.Translation;
109
- currentValue = currentValue[NodeType.Translation][keyObj.key];
110
- } else if (keyObj.type === NodeType.Enumeration) {
111
- lastKey = NodeType.Enumeration;
112
- currentValue = currentValue[NodeType.Enumeration][keyObj.key];
113
- }
114
- }
115
- if (parentValue && lastKey !== null) {
116
- if (Array.isArray(parentValue)) {
117
- parentValue[lastKey] = currentValue;
118
- } else {
119
- const newParentValue = {};
120
- for (const key of Object.keys(parentValue)) {
121
- if (key === lastKey) {
122
- newParentValue[newKey] = currentValue;
123
- } else {
124
- newParentValue[key] = parentValue[key];
125
- }
126
- }
127
- Object.keys(parentValue).forEach((key) => delete parentValue[key]);
128
- Object.assign(parentValue, newParentValue);
129
- }
130
- }
131
- return dictionaryContent;
132
- };
133
- const getSectionType = (section) => {
134
- if (typeof section === "string") {
135
- return NodeType.Text;
136
- }
137
- if (section?.nodeType === NodeType.Translation) {
138
- return NodeType.Translation;
139
- }
140
- if (section?.nodeType === NodeType.Enumeration) {
141
- return NodeType.Enumeration;
142
- }
143
- if (Array.isArray(section)) {
144
- return NodeType.Array;
145
- }
146
- if (isValidElement(section)) {
147
- return NodeType.ReactNode;
148
- }
149
- return NodeType.Object;
150
- };
151
- export {
152
- editDictionaryByKeyPath,
153
- getDictionaryValueByKeyPath,
154
- getSectionType,
155
- removeDictionaryValueByKeyPath,
156
- renameDictionaryValueByKeyPath
157
- };
158
- //# sourceMappingURL=dictionary.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dictionary.mjs","sources":["../../src/utils/dictionary.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n NodeType,\n type TranslationContent,\n type DictionaryValue,\n type KeyPath,\n type EnumerationContent,\n} from '@intlayer/core';\nimport { isValidElement } from 'react';\n\nexport const getDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = JSON.parse(JSON.stringify(dictionaryContent ?? {}));\n\n for (const keyObj of keyPath) {\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];\n }\n }\n\n return currentValue as DictionaryValue;\n};\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[],\n newValue: DictionaryValue\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object) {\n lastKeys = [keyObj.key];\n\n if (!currentValue[keyObj.key]) {\n currentValue = {\n ...currentValue,\n [keyObj.key]: {},\n };\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n\n if (!currentValue[keyObj.key]) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKeys = [NodeType.Translation, keyObj.key];\n\n if (!currentValue[NodeType.Translation]) {\n currentValue[NodeType.Translation] = {\n ...currentValue[NodeType.Translation],\n [keyObj.key]: newValue,\n };\n }\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKeys = [NodeType.Enumeration, keyObj.key];\n\n if (!currentValue[NodeType.Enumeration]) {\n currentValue[NodeType.Enumeration] = {\n ...currentValue[NodeType.Enumeration],\n [keyObj.key]: newValue,\n };\n }\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n // Assign the new value to the last key of the parent\n if (parentValue && lastKeys.length > 0) {\n for (const key of lastKeys.slice(0, -1)) {\n parentValue = parentValue[key];\n }\n if (\n // Remove the field if the new value is undefined\n typeof newValue === 'undefined'\n ) {\n delete parentValue[lastKeys[lastKeys.length - 1]];\n } else {\n parentValue[lastKeys[lastKeys.length - 1]] = newValue;\n }\n }\n\n return dictionaryContent;\n};\n\nexport const removeDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKey = NodeType.Translation;\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKey = NodeType.Enumeration;\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n\nexport const renameDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n newKey: string | number,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKey = NodeType.Translation;\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKey = NodeType.Enumeration;\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n // Assign the new value to the last key of the parent while preserving the order\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue[lastKey as number] = currentValue;\n } else {\n const newParentValue: any = {};\n for (const key of Object.keys(parentValue)) {\n if (key === lastKey) {\n newParentValue[newKey] = currentValue;\n } else {\n newParentValue[key] = parentValue[key];\n }\n }\n // Replace the contents of parentValue with newParentValue\n Object.keys(parentValue).forEach((key) => delete parentValue[key]);\n Object.assign(parentValue, newParentValue);\n }\n }\n\n return dictionaryContent;\n};\n\nexport const getSectionType = (section: DictionaryValue): NodeType => {\n if (typeof section === 'string') {\n return NodeType.Text;\n }\n\n if (\n (section as TranslationContent<unknown>)?.nodeType === NodeType.Translation\n ) {\n return NodeType.Translation;\n }\n\n if (\n (section as EnumerationContent<unknown>)?.nodeType === NodeType.Enumeration\n ) {\n return NodeType.Enumeration;\n }\n\n if (Array.isArray(section)) {\n return Node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