@enonic/nextjs-adapter 3.2.2 → 3.3.0-B2

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 (410) hide show
  1. package/{baseMappings.js → dist/baseMappings.js} +9 -9
  2. package/dist/baseMappings.js.map +1 -0
  3. package/dist/client/getClientHydratedHtml.jsx.map +1 -0
  4. package/dist/client.js.map +1 -0
  5. package/{common → dist/common}/ComponentRegistry.js +1 -1
  6. package/dist/common/ComponentRegistry.js.map +1 -0
  7. package/dist/common/UrlProcessor.js.map +1 -0
  8. package/dist/common/constants.js.map +1 -0
  9. package/{common → dist/common}/env.js +1 -1
  10. package/dist/common/env.js.map +1 -0
  11. package/dist/guillotine/applyProcessors.js.map +1 -0
  12. package/dist/guillotine/buildComponentTree.js.map +1 -0
  13. package/{guillotine → dist/guillotine}/buildErrorResponse.js +3 -3
  14. package/dist/guillotine/buildErrorResponse.js.map +1 -0
  15. package/{guillotine → dist/guillotine}/buildPage.js +1 -1
  16. package/dist/guillotine/buildPage.js.map +1 -0
  17. package/{guillotine → dist/guillotine}/collectComponentDescriptors.d.ts +1 -1
  18. package/{guillotine → dist/guillotine}/collectComponentDescriptors.js +4 -4
  19. package/dist/guillotine/collectComponentDescriptors.js.map +1 -0
  20. package/{guillotine → dist/guillotine}/combineMultipleQueries.js +1 -1
  21. package/dist/guillotine/combineMultipleQueries.js.map +1 -0
  22. package/{guillotine → dist/guillotine}/createMetaData.d.ts +1 -1
  23. package/{guillotine → dist/guillotine}/createMetaData.js +2 -2
  24. package/dist/guillotine/createMetaData.js.map +1 -0
  25. package/{guillotine → dist/guillotine}/fetchContent.js +10 -10
  26. package/dist/guillotine/fetchContent.js.map +1 -0
  27. package/{guillotine → dist/guillotine}/fetchContentData.js +2 -2
  28. package/dist/guillotine/fetchContentData.js.map +1 -0
  29. package/dist/guillotine/fetchContentPathsForAllLocales.js.map +1 -0
  30. package/{guillotine → dist/guillotine}/fetchContentPathsForLocale.js +4 -4
  31. package/dist/guillotine/fetchContentPathsForLocale.js.map +1 -0
  32. package/{guillotine → dist/guillotine}/fetchFromApi.js +7 -7
  33. package/dist/guillotine/fetchFromApi.js.map +1 -0
  34. package/{guillotine → dist/guillotine}/fetchGuillotine.js +6 -6
  35. package/dist/guillotine/fetchGuillotine.js.map +1 -0
  36. package/{guillotine → dist/guillotine}/fetchMetaData.js +4 -4
  37. package/dist/guillotine/fetchMetaData.js.map +1 -0
  38. package/{guillotine → dist/guillotine}/getCleanContentPathArrayOrThrow400.js +1 -1
  39. package/dist/guillotine/getCleanContentPathArrayOrThrow400.js.map +1 -0
  40. package/dist/guillotine/getComponentConfig.js.map +1 -0
  41. package/dist/guillotine/getContentAndComponentPaths.js.map +1 -0
  42. package/dist/guillotine/getMetaData.js.map +1 -0
  43. package/{guillotine → dist/guillotine}/getParentRegion.js +1 -1
  44. package/dist/guillotine/getParentRegion.js.map +1 -0
  45. package/{guillotine → dist/guillotine}/getQueryAndVariables.js +2 -2
  46. package/dist/guillotine/getQueryAndVariables.js.map +1 -0
  47. package/dist/guillotine/metadata/configQuery.js.map +1 -0
  48. package/dist/guillotine/metadata/richTextQuery.js.map +1 -0
  49. package/{guillotine → dist/guillotine}/parseComponentPath.js +3 -3
  50. package/dist/guillotine/parseComponentPath.js.map +1 -0
  51. package/dist/guillotine/prefixFragmentCmpPath.js.map +1 -0
  52. package/dist/guillotine/processComponentConfig.js.map +1 -0
  53. package/dist/guillotine/restrictComponentsToPath.js.map +1 -0
  54. package/dist/guillotine/validateData.js.map +1 -0
  55. package/dist/guillotine/validateNotFound.js.map +1 -0
  56. package/dist/guillotine/validateShortcut.js.map +1 -0
  57. package/{i18n → dist/i18n}/LocaleContext.d.ts +1 -1
  58. package/{i18n → dist/i18n}/LocaleContext.jsx +3 -3
  59. package/dist/i18n/LocaleContext.jsx.map +1 -0
  60. package/dist/i18n/i18n.js.map +1 -0
  61. package/{index.d.ts → dist/index.d.ts} +3 -3
  62. package/{index.js → dist/index.js} +3 -3
  63. package/dist/index.js.map +1 -0
  64. package/dist/query/Shortcut.js.map +1 -0
  65. package/dist/server/getServerRenderedHtml.js.map +1 -0
  66. package/dist/server.js.map +1 -0
  67. package/{types → dist/types}/component.js.map +1 -1
  68. package/{types → dist/types}/componentProps.d.ts +2 -1
  69. package/dist/types/componentProps.js.map +1 -0
  70. package/{types → dist/types}/guillotine.d.ts +1 -1
  71. package/{types → dist/types}/guillotine.js.map +1 -1
  72. package/dist/types/i18n.js.map +1 -0
  73. package/dist/types/index.js.map +1 -0
  74. package/dist/types/next.js.map +1 -0
  75. package/dist/types/util.js.map +1 -0
  76. package/dist/utils/addLineNumbers.js.map +1 -0
  77. package/{utils → dist/utils}/buildGuillotineRequestHeaders.d.ts +1 -1
  78. package/{utils → dist/utils}/buildGuillotineRequestHeaders.js +3 -3
  79. package/dist/utils/buildGuillotineRequestHeaders.js.map +1 -0
  80. package/dist/utils/commonChars.js.map +1 -0
  81. package/dist/utils/enonicLog.js.map +1 -0
  82. package/dist/utils/fixDoubleSlashes.js.map +1 -0
  83. package/dist/utils/getAllLocales.js.map +1 -0
  84. package/dist/utils/getContentApiUrl.js.map +1 -0
  85. package/dist/utils/getLocaleMapping.js.map +1 -0
  86. package/dist/utils/getLocaleMappingByLocale.js.map +1 -0
  87. package/dist/utils/getLocaleMappingByProjectId.js.map +1 -0
  88. package/{utils → dist/utils}/getLocaleMappings.js +1 -1
  89. package/dist/utils/getLocaleMappings.js.map +1 -0
  90. package/{utils → dist/utils}/getRenderMode.js +1 -1
  91. package/dist/utils/getRenderMode.js.map +1 -0
  92. package/dist/utils/getRequestLocaleInfo.js.map +1 -0
  93. package/dist/utils/getXpBaseUrl.js.map +1 -0
  94. package/dist/utils/indent.js.map +1 -0
  95. package/dist/utils/sanitizeGraphqlName.js.map +1 -0
  96. package/{views → dist/views}/BaseComponent.d.ts +1 -1
  97. package/{views → dist/views}/BaseComponent.jsx +5 -5
  98. package/dist/views/BaseComponent.jsx.map +1 -0
  99. package/{views → dist/views}/BaseContent.jsx +1 -1
  100. package/dist/views/BaseContent.jsx.map +1 -0
  101. package/dist/views/BaseLayout.jsx.map +1 -0
  102. package/dist/views/BaseMacro.jsx.map +1 -0
  103. package/dist/views/BasePage.jsx.map +1 -0
  104. package/dist/views/BasePart.jsx.map +1 -0
  105. package/dist/views/Empty.jsx.map +1 -0
  106. package/dist/views/Fragment.jsx.map +1 -0
  107. package/dist/views/MainView.jsx.map +1 -0
  108. package/{views → dist/views}/PropsView.jsx +1 -1
  109. package/dist/views/PropsView.jsx.map +1 -0
  110. package/dist/views/Region.jsx.map +1 -0
  111. package/dist/views/RichTextView.jsx +65 -0
  112. package/dist/views/RichTextView.jsx.map +1 -0
  113. package/dist/views/SingleComponent.jsx.map +1 -0
  114. package/dist/views/StaticContent.jsx.map +1 -0
  115. package/dist/views/Text.jsx.map +1 -0
  116. package/dist/views/macros/DefaultMacro.jsx.map +1 -0
  117. package/dist/views/macros/DisableMacro.jsx.map +1 -0
  118. package/package.json +49 -42
  119. package/baseMappings.js.map +0 -1
  120. package/client/getClientHydratedHtml.jsx.map +0 -1
  121. package/client.js.map +0 -1
  122. package/common/ComponentRegistry.js.map +0 -1
  123. package/common/UrlProcessor.js.map +0 -1
  124. package/common/constants.js.map +0 -1
  125. package/common/env.js.map +0 -1
  126. package/guillotine/applyProcessors.js.map +0 -1
  127. package/guillotine/buildComponentTree.js.map +0 -1
  128. package/guillotine/buildErrorResponse.js.map +0 -1
  129. package/guillotine/buildPage.js.map +0 -1
  130. package/guillotine/collectComponentDescriptors.js.map +0 -1
  131. package/guillotine/combineMultipleQueries.js.map +0 -1
  132. package/guillotine/createMetaData.js.map +0 -1
  133. package/guillotine/fetchContent.js.map +0 -1
  134. package/guillotine/fetchContentData.js.map +0 -1
  135. package/guillotine/fetchContentPathsForAllLocales.js.map +0 -1
  136. package/guillotine/fetchContentPathsForLocale.js.map +0 -1
  137. package/guillotine/fetchFromApi.js.map +0 -1
  138. package/guillotine/fetchGuillotine.js.map +0 -1
  139. package/guillotine/fetchMetaData.js.map +0 -1
  140. package/guillotine/getCleanContentPathArrayOrThrow400.js.map +0 -1
  141. package/guillotine/getComponentConfig.js.map +0 -1
  142. package/guillotine/getContentAndComponentPaths.js.map +0 -1
  143. package/guillotine/getMetaData.js.map +0 -1
  144. package/guillotine/getParentRegion.js.map +0 -1
  145. package/guillotine/getQueryAndVariables.js.map +0 -1
  146. package/guillotine/metadata/configQuery.js.map +0 -1
  147. package/guillotine/metadata/richTextQuery.js.map +0 -1
  148. package/guillotine/parseComponentPath.js.map +0 -1
  149. package/guillotine/prefixFragmentCmpPath.js.map +0 -1
  150. package/guillotine/processComponentConfig.js.map +0 -1
  151. package/guillotine/restrictComponentsToPath.js.map +0 -1
  152. package/guillotine/validateData.js.map +0 -1
  153. package/guillotine/validateNotFound.js.map +0 -1
  154. package/guillotine/validateShortcut.js.map +0 -1
  155. package/i18n/LocaleContext.jsx.map +0 -1
  156. package/i18n/i18n.js.map +0 -1
  157. package/index.js.map +0 -1
  158. package/query/Shortcut.js.map +0 -1
  159. package/server/getServerRenderedHtml.js.map +0 -1
  160. package/server.js.map +0 -1
  161. package/src/baseMappings.ts +0 -53
  162. package/src/client/getClientHydratedHtml.tsx +0 -12
  163. package/src/client.ts +0 -2
  164. package/src/common/ComponentRegistry.ts +0 -162
  165. package/src/common/UrlProcessor.ts +0 -172
  166. package/src/common/constants.ts +0 -92
  167. package/src/common/env.ts +0 -41
  168. package/src/guillotine/applyProcessors.ts +0 -38
  169. package/src/guillotine/buildComponentTree.ts +0 -57
  170. package/src/guillotine/buildErrorResponse.ts +0 -35
  171. package/src/guillotine/buildPage.ts +0 -15
  172. package/src/guillotine/collectComponentDescriptors.ts +0 -63
  173. package/src/guillotine/combineMultipleQueries.ts +0 -75
  174. package/src/guillotine/createMetaData.ts +0 -72
  175. package/src/guillotine/fetchContent.ts +0 -246
  176. package/src/guillotine/fetchContentData.ts +0 -37
  177. package/src/guillotine/fetchContentPathsForAllLocales.ts +0 -21
  178. package/src/guillotine/fetchContentPathsForLocale.ts +0 -43
  179. package/src/guillotine/fetchFromApi.ts +0 -76
  180. package/src/guillotine/fetchGuillotine.ts +0 -76
  181. package/src/guillotine/fetchMetaData.ts +0 -31
  182. package/src/guillotine/getCleanContentPathArrayOrThrow400.ts +0 -22
  183. package/src/guillotine/getComponentConfig.ts +0 -7
  184. package/src/guillotine/getContentAndComponentPaths.ts +0 -11
  185. package/src/guillotine/getMetaData.ts +0 -74
  186. package/src/guillotine/getParentRegion.ts +0 -54
  187. package/src/guillotine/getQueryAndVariables.ts +0 -52
  188. package/src/guillotine/metadata/configQuery.ts +0 -46
  189. package/src/guillotine/metadata/richTextQuery.ts +0 -49
  190. package/src/guillotine/parseComponentPath.ts +0 -29
  191. package/src/guillotine/prefixFragmentCmpPath.ts +0 -13
  192. package/src/guillotine/processComponentConfig.ts +0 -38
  193. package/src/guillotine/restrictComponentsToPath.ts +0 -48
  194. package/src/guillotine/validateData.ts +0 -11
  195. package/src/guillotine/validateNotFound.ts +0 -20
  196. package/src/guillotine/validateShortcut.ts +0 -43
  197. package/src/i18n/LocaleContext.tsx +0 -59
  198. package/src/i18n/i18n.ts +0 -57
  199. package/src/index.ts +0 -42
  200. package/src/query/Shortcut.ts +0 -18
  201. package/src/server/getServerRenderedHtml.ts +0 -3
  202. package/src/server.ts +0 -5
  203. package/src/types/component.ts +0 -131
  204. package/src/types/componentProps.ts +0 -142
  205. package/src/types/guillotine.ts +0 -428
  206. package/src/types/i18n.ts +0 -8
  207. package/src/types/index.ts +0 -62
  208. package/src/types/next.ts +0 -7
  209. package/src/types/util.ts +0 -5
  210. package/src/utils/addLineNumbers.ts +0 -3
  211. package/src/utils/buildGuillotineRequestHeaders.ts +0 -32
  212. package/src/utils/commonChars.ts +0 -16
  213. package/src/utils/enonicLog.ts +0 -28
  214. package/src/utils/fixDoubleSlashes.ts +0 -3
  215. package/src/utils/getAllLocales.ts +0 -6
  216. package/src/utils/getContentApiUrl.ts +0 -20
  217. package/src/utils/getLocaleMapping.ts +0 -24
  218. package/src/utils/getLocaleMappingByLocale.ts +0 -19
  219. package/src/utils/getLocaleMappingByProjectId.ts +0 -21
  220. package/src/utils/getLocaleMappings.ts +0 -36
  221. package/src/utils/getRenderMode.ts +0 -14
  222. package/src/utils/getRequestLocaleInfo.ts +0 -30
  223. package/src/utils/getXpBaseUrl.ts +0 -12
  224. package/src/utils/indent.ts +0 -4
  225. package/src/utils/sanitizeGraphqlName.ts +0 -11
  226. package/src/views/BaseComponent.tsx +0 -156
  227. package/src/views/BaseContent.tsx +0 -47
  228. package/src/views/BaseLayout.tsx +0 -33
  229. package/src/views/BaseMacro.tsx +0 -105
  230. package/src/views/BasePage.tsx +0 -42
  231. package/src/views/BasePart.tsx +0 -34
  232. package/src/views/Empty.tsx +0 -5
  233. package/src/views/Fragment.tsx +0 -41
  234. package/src/views/MainView.tsx +0 -22
  235. package/src/views/PropsView.tsx +0 -38
  236. package/src/views/Region.tsx +0 -76
  237. package/src/views/RichTextView.tsx +0 -63
  238. package/src/views/SingleComponent.tsx +0 -19
  239. package/src/views/StaticContent.tsx +0 -39
  240. package/src/views/Text.tsx +0 -19
  241. package/src/views/macros/DefaultMacro.tsx +0 -9
  242. package/src/views/macros/DisableMacro.tsx +0 -8
  243. package/types/componentProps.js.map +0 -1
  244. package/types/i18n.js.map +0 -1
  245. package/types/index.js.map +0 -1
  246. package/types/next.js.map +0 -1
  247. package/types/util.js.map +0 -1
  248. package/utils/addLineNumbers.js.map +0 -1
  249. package/utils/buildGuillotineRequestHeaders.js.map +0 -1
  250. package/utils/commonChars.js.map +0 -1
  251. package/utils/enonicLog.js.map +0 -1
  252. package/utils/fixDoubleSlashes.js.map +0 -1
  253. package/utils/getAllLocales.js.map +0 -1
  254. package/utils/getContentApiUrl.js.map +0 -1
  255. package/utils/getLocaleMapping.js.map +0 -1
  256. package/utils/getLocaleMappingByLocale.js.map +0 -1
  257. package/utils/getLocaleMappingByProjectId.js.map +0 -1
  258. package/utils/getLocaleMappings.js.map +0 -1
  259. package/utils/getRenderMode.js.map +0 -1
  260. package/utils/getRequestLocaleInfo.js.map +0 -1
  261. package/utils/getXpBaseUrl.js.map +0 -1
  262. package/utils/indent.js.map +0 -1
  263. package/utils/sanitizeGraphqlName.js.map +0 -1
  264. package/views/BaseComponent.jsx.map +0 -1
  265. package/views/BaseContent.jsx.map +0 -1
  266. package/views/BaseLayout.jsx.map +0 -1
  267. package/views/BaseMacro.jsx.map +0 -1
  268. package/views/BasePage.jsx.map +0 -1
  269. package/views/BasePart.jsx.map +0 -1
  270. package/views/Empty.jsx.map +0 -1
  271. package/views/Fragment.jsx.map +0 -1
  272. package/views/MainView.jsx.map +0 -1
  273. package/views/PropsView.jsx.map +0 -1
  274. package/views/Region.jsx.map +0 -1
  275. package/views/RichTextView.jsx +0 -39
  276. package/views/RichTextView.jsx.map +0 -1
  277. package/views/SingleComponent.jsx.map +0 -1
  278. package/views/StaticContent.jsx.map +0 -1
  279. package/views/Text.jsx.map +0 -1
  280. package/views/macros/DefaultMacro.jsx.map +0 -1
  281. package/views/macros/DisableMacro.jsx.map +0 -1
  282. /package/{baseMappings.d.ts → dist/baseMappings.d.ts} +0 -0
  283. /package/{client → dist/client}/getClientHydratedHtml.d.ts +0 -0
  284. /package/{client → dist/client}/getClientHydratedHtml.jsx +0 -0
  285. /package/{client.d.ts → dist/client.d.ts} +0 -0
  286. /package/{client.js → dist/client.js} +0 -0
  287. /package/{common → dist/common}/ComponentRegistry.d.ts +0 -0
  288. /package/{common → dist/common}/UrlProcessor.d.ts +0 -0
  289. /package/{common → dist/common}/UrlProcessor.js +0 -0
  290. /package/{common → dist/common}/constants.d.ts +0 -0
  291. /package/{common → dist/common}/constants.js +0 -0
  292. /package/{common → dist/common}/env.d.ts +0 -0
  293. /package/{guillotine → dist/guillotine}/applyProcessors.d.ts +0 -0
  294. /package/{guillotine → dist/guillotine}/applyProcessors.js +0 -0
  295. /package/{guillotine → dist/guillotine}/buildComponentTree.d.ts +0 -0
  296. /package/{guillotine → dist/guillotine}/buildComponentTree.js +0 -0
  297. /package/{guillotine → dist/guillotine}/buildErrorResponse.d.ts +0 -0
  298. /package/{guillotine → dist/guillotine}/buildPage.d.ts +0 -0
  299. /package/{guillotine → dist/guillotine}/combineMultipleQueries.d.ts +0 -0
  300. /package/{guillotine → dist/guillotine}/fetchContent.d.ts +0 -0
  301. /package/{guillotine → dist/guillotine}/fetchContentData.d.ts +0 -0
  302. /package/{guillotine → dist/guillotine}/fetchContentPathsForAllLocales.d.ts +0 -0
  303. /package/{guillotine → dist/guillotine}/fetchContentPathsForAllLocales.js +0 -0
  304. /package/{guillotine → dist/guillotine}/fetchContentPathsForLocale.d.ts +0 -0
  305. /package/{guillotine → dist/guillotine}/fetchFromApi.d.ts +0 -0
  306. /package/{guillotine → dist/guillotine}/fetchGuillotine.d.ts +0 -0
  307. /package/{guillotine → dist/guillotine}/fetchMetaData.d.ts +0 -0
  308. /package/{guillotine → dist/guillotine}/getCleanContentPathArrayOrThrow400.d.ts +0 -0
  309. /package/{guillotine → dist/guillotine}/getComponentConfig.d.ts +0 -0
  310. /package/{guillotine → dist/guillotine}/getComponentConfig.js +0 -0
  311. /package/{guillotine → dist/guillotine}/getContentAndComponentPaths.d.ts +0 -0
  312. /package/{guillotine → dist/guillotine}/getContentAndComponentPaths.js +0 -0
  313. /package/{guillotine → dist/guillotine}/getMetaData.d.ts +0 -0
  314. /package/{guillotine → dist/guillotine}/getMetaData.js +0 -0
  315. /package/{guillotine → dist/guillotine}/getParentRegion.d.ts +0 -0
  316. /package/{guillotine → dist/guillotine}/getQueryAndVariables.d.ts +0 -0
  317. /package/{guillotine → dist/guillotine}/metadata/configQuery.d.ts +0 -0
  318. /package/{guillotine → dist/guillotine}/metadata/configQuery.js +0 -0
  319. /package/{guillotine → dist/guillotine}/metadata/richTextQuery.d.ts +0 -0
  320. /package/{guillotine → dist/guillotine}/metadata/richTextQuery.js +0 -0
  321. /package/{guillotine → dist/guillotine}/parseComponentPath.d.ts +0 -0
  322. /package/{guillotine → dist/guillotine}/prefixFragmentCmpPath.d.ts +0 -0
  323. /package/{guillotine → dist/guillotine}/prefixFragmentCmpPath.js +0 -0
  324. /package/{guillotine → dist/guillotine}/processComponentConfig.d.ts +0 -0
  325. /package/{guillotine → dist/guillotine}/processComponentConfig.js +0 -0
  326. /package/{guillotine → dist/guillotine}/restrictComponentsToPath.d.ts +0 -0
  327. /package/{guillotine → dist/guillotine}/restrictComponentsToPath.js +0 -0
  328. /package/{guillotine → dist/guillotine}/validateData.d.ts +0 -0
  329. /package/{guillotine → dist/guillotine}/validateData.js +0 -0
  330. /package/{guillotine → dist/guillotine}/validateNotFound.d.ts +0 -0
  331. /package/{guillotine → dist/guillotine}/validateNotFound.js +0 -0
  332. /package/{guillotine → dist/guillotine}/validateShortcut.d.ts +0 -0
  333. /package/{guillotine → dist/guillotine}/validateShortcut.js +0 -0
  334. /package/{i18n → dist/i18n}/i18n.d.ts +0 -0
  335. /package/{i18n → dist/i18n}/i18n.js +0 -0
  336. /package/{query → dist/query}/Shortcut.d.ts +0 -0
  337. /package/{query → dist/query}/Shortcut.js +0 -0
  338. /package/{server → dist/server}/getServerRenderedHtml.d.ts +0 -0
  339. /package/{server → dist/server}/getServerRenderedHtml.js +0 -0
  340. /package/{server.d.ts → dist/server.d.ts} +0 -0
  341. /package/{server.js → dist/server.js} +0 -0
  342. /package/{types → dist/types}/component.d.ts +0 -0
  343. /package/{types → dist/types}/component.js +0 -0
  344. /package/{types → dist/types}/componentProps.js +0 -0
  345. /package/{types → dist/types}/guillotine.js +0 -0
  346. /package/{types → dist/types}/i18n.d.ts +0 -0
  347. /package/{types → dist/types}/i18n.js +0 -0
  348. /package/{types → dist/types}/index.d.ts +0 -0
  349. /package/{types → dist/types}/index.js +0 -0
  350. /package/{types → dist/types}/next.d.ts +0 -0
  351. /package/{types → dist/types}/next.js +0 -0
  352. /package/{types → dist/types}/util.d.ts +0 -0
  353. /package/{types → dist/types}/util.js +0 -0
  354. /package/{utils → dist/utils}/addLineNumbers.d.ts +0 -0
  355. /package/{utils → dist/utils}/addLineNumbers.js +0 -0
  356. /package/{utils → dist/utils}/commonChars.d.ts +0 -0
  357. /package/{utils → dist/utils}/commonChars.js +0 -0
  358. /package/{utils → dist/utils}/enonicLog.d.ts +0 -0
  359. /package/{utils → dist/utils}/enonicLog.js +0 -0
  360. /package/{utils → dist/utils}/fixDoubleSlashes.d.ts +0 -0
  361. /package/{utils → dist/utils}/fixDoubleSlashes.js +0 -0
  362. /package/{utils → dist/utils}/getAllLocales.d.ts +0 -0
  363. /package/{utils → dist/utils}/getAllLocales.js +0 -0
  364. /package/{utils → dist/utils}/getContentApiUrl.d.ts +0 -0
  365. /package/{utils → dist/utils}/getContentApiUrl.js +0 -0
  366. /package/{utils → dist/utils}/getLocaleMapping.d.ts +0 -0
  367. /package/{utils → dist/utils}/getLocaleMapping.js +0 -0
  368. /package/{utils → dist/utils}/getLocaleMappingByLocale.d.ts +0 -0
  369. /package/{utils → dist/utils}/getLocaleMappingByLocale.js +0 -0
  370. /package/{utils → dist/utils}/getLocaleMappingByProjectId.d.ts +0 -0
  371. /package/{utils → dist/utils}/getLocaleMappingByProjectId.js +0 -0
  372. /package/{utils → dist/utils}/getLocaleMappings.d.ts +0 -0
  373. /package/{utils → dist/utils}/getRenderMode.d.ts +0 -0
  374. /package/{utils → dist/utils}/getRequestLocaleInfo.d.ts +0 -0
  375. /package/{utils → dist/utils}/getRequestLocaleInfo.js +0 -0
  376. /package/{utils → dist/utils}/getXpBaseUrl.d.ts +0 -0
  377. /package/{utils → dist/utils}/getXpBaseUrl.js +0 -0
  378. /package/{utils → dist/utils}/indent.d.ts +0 -0
  379. /package/{utils → dist/utils}/indent.js +0 -0
  380. /package/{utils → dist/utils}/sanitizeGraphqlName.d.ts +0 -0
  381. /package/{utils → dist/utils}/sanitizeGraphqlName.js +0 -0
  382. /package/{views → dist/views}/BaseContent.d.ts +0 -0
  383. /package/{views → dist/views}/BaseLayout.d.ts +0 -0
  384. /package/{views → dist/views}/BaseLayout.jsx +0 -0
  385. /package/{views → dist/views}/BaseMacro.d.ts +0 -0
  386. /package/{views → dist/views}/BaseMacro.jsx +0 -0
  387. /package/{views → dist/views}/BasePage.d.ts +0 -0
  388. /package/{views → dist/views}/BasePage.jsx +0 -0
  389. /package/{views → dist/views}/BasePart.d.ts +0 -0
  390. /package/{views → dist/views}/BasePart.jsx +0 -0
  391. /package/{views → dist/views}/Empty.d.ts +0 -0
  392. /package/{views → dist/views}/Empty.jsx +0 -0
  393. /package/{views → dist/views}/Fragment.d.ts +0 -0
  394. /package/{views → dist/views}/Fragment.jsx +0 -0
  395. /package/{views → dist/views}/MainView.d.ts +0 -0
  396. /package/{views → dist/views}/MainView.jsx +0 -0
  397. /package/{views → dist/views}/PropsView.d.ts +0 -0
  398. /package/{views → dist/views}/Region.d.ts +0 -0
  399. /package/{views → dist/views}/Region.jsx +0 -0
  400. /package/{views → dist/views}/RichTextView.d.ts +0 -0
  401. /package/{views → dist/views}/SingleComponent.d.ts +0 -0
  402. /package/{views → dist/views}/SingleComponent.jsx +0 -0
  403. /package/{views → dist/views}/StaticContent.d.ts +0 -0
  404. /package/{views → dist/views}/StaticContent.jsx +0 -0
  405. /package/{views → dist/views}/Text.d.ts +0 -0
  406. /package/{views → dist/views}/Text.jsx +0 -0
  407. /package/{views → dist/views}/macros/DefaultMacro.d.ts +0 -0
  408. /package/{views → dist/views}/macros/DefaultMacro.jsx +0 -0
  409. /package/{views → dist/views}/macros/DisableMacro.d.ts +0 -0
  410. /package/{views → dist/views}/macros/DisableMacro.jsx +0 -0
@@ -1,22 +0,0 @@
1
- /** Checks a site-relative contentPath as a slash-delimited string or a string array, and returns a pure site-relative path string (no double slashes, starts with a slash, does not end with one). */
2
- export const getCleanContentPathArrayOrThrow400 = (contentPath: string | string[] | undefined): string => {
3
- if (contentPath === undefined) {
4
- return '';
5
- }
6
- const isArray = Array.isArray(contentPath);
7
-
8
- if (!isArray) {
9
- if (typeof contentPath !== 'string') {
10
- throw Error(JSON.stringify({
11
- code: 400,
12
- message: `Unexpected target content _path: contentPath must be a string or pure string array (contentPath=${JSON.stringify(
13
- contentPath)})`,
14
- }));
15
- }
16
-
17
- return contentPath;
18
-
19
- } else {
20
- return (contentPath).join('/');
21
- }
22
- };
@@ -1,7 +0,0 @@
1
- import type {PageComponent} from '../types';
2
-
3
-
4
- export function getComponentConfig(cmp?: PageComponent) {
5
- const cmpData = cmp && cmp[cmp.type];
6
- return cmpData && 'config' in cmpData ? cmpData.config : undefined;
7
- }
@@ -1,11 +0,0 @@
1
- const COMPONENT_PATH_KEY = /\/?_\/component/; // first slash is optional for root components
2
-
3
- export const getContentAndComponentPaths = (requestPath: string): string[] => {
4
- let contentPath, componentPath;
5
- if (COMPONENT_PATH_KEY.test(requestPath)) {
6
- [contentPath, componentPath] = requestPath.split(COMPONENT_PATH_KEY);
7
- } else {
8
- contentPath = requestPath;
9
- }
10
- return [contentPath, componentPath];
11
- };
@@ -1,74 +0,0 @@
1
- import {ComponentRegistry} from '../common/ComponentRegistry';
2
- import {configQuery} from './metadata/configQuery';
3
- import {richTextQuery} from './metadata/richTextQuery';
4
- import {indent} from '../utils/indent';
5
-
6
-
7
- const partConfigQuery = (): string => {
8
- return configQuery(ComponentRegistry.getParts());
9
- };
10
-
11
- const layoutConfigQuery = (): string => {
12
- return configQuery(ComponentRegistry.getLayouts());
13
- };
14
-
15
- const pageConfigQuery = (): string => {
16
- return configQuery(ComponentRegistry.getPages());
17
- };
18
-
19
-
20
- /*
21
- IMPORTANT: make sure to transform your queries into functions too when using this function inside them !!!
22
- */
23
- const componentsQuery = () => `type
24
- path
25
- page {
26
- descriptor
27
- ${indent(pageConfigQuery(), 4)}
28
- template {
29
- _path
30
- }
31
- }
32
- layout {
33
- descriptor
34
- ${indent(layoutConfigQuery(), 4)}
35
- }
36
- text {
37
- ${indent(richTextQuery('value'), 4)}
38
- }
39
- part {
40
- descriptor
41
- ${indent(partConfigQuery(), 4)}
42
- }
43
- image {
44
- caption
45
- image {
46
- imageUrl (type:absolute, scale: "width-768")
47
- }
48
- }`;
49
-
50
- // THIS QUERY DOES NOT SUPPORT NESTED FRAGMENTS
51
- export const pageFragmentQuery = () => `components(resolveFragment: false, resolveTemplate: true) {
52
- fragment {
53
- id
54
- fragment {
55
- components {
56
- ${indent(componentsQuery(),16)}
57
- }
58
- }
59
- }
60
- ${indent(componentsQuery(),4)}
61
- }`;
62
-
63
- export function getMetaQuery(pageFragment?: string): string {
64
- return `query($path:ID!) {
65
- guillotine {
66
- get(key:$path) {
67
- _id
68
- _path
69
- type
70
- ${indent(pageFragment || '', 12)}
71
- }
72
- }
73
- }`;
74
- }
@@ -1,54 +0,0 @@
1
- import type {PageComponent, PageRegion, PathFragment, RegionTree} from '../types';
2
-
3
-
4
- import {XP_COMPONENT_TYPE} from '../common/constants';
5
- import {prefixFragmentCmpPath} from './prefixFragmentCmpPath';
6
-
7
-
8
- export function getParentRegion(
9
- source: RegionTree,
10
- contentType: string,
11
- cmpPath: PathFragment[],
12
- components: PageComponent[] = [],
13
- createMissing ? : boolean,
14
- ): PageRegion | undefined {
15
- let currentTree: RegionTree = source;
16
- let currentRegion: PageRegion | undefined;
17
- let parentPath = '';
18
-
19
- for (let i = 0; i < cmpPath.length; i++) {
20
- const pathFragment = cmpPath[i];
21
- const regionName = pathFragment.region;
22
- parentPath += `/${pathFragment.region}/${pathFragment.index}`;
23
- currentRegion = currentTree[regionName];
24
-
25
- if (!currentRegion) {
26
- if (createMissing) {
27
- currentRegion = {
28
- name: regionName,
29
- components: [],
30
- };
31
- currentTree[regionName] = currentRegion;
32
- } else {
33
- throw new Error(`Region [${regionName}] was not found`);
34
- }
35
- }
36
-
37
- if (i < cmpPath.length - 1) {
38
- // look for layouts inside if this is not the last path fragment
39
-
40
- const layout = components.find((cmp: PageComponent) => {
41
- return cmp.type === XP_COMPONENT_TYPE.LAYOUT && prefixFragmentCmpPath(contentType, cmp.path) === parentPath;
42
- });
43
- if (!layout) {
44
- throw new Error(`Layout [${parentPath}] not found among components, but needed for component [${JSON.stringify(cmpPath, null, 2)}]`);
45
- }
46
- if (!layout.regions) {
47
- layout.regions = {};
48
- }
49
- currentTree = layout.regions;
50
- }
51
- } // for
52
-
53
- return currentRegion;
54
- }
@@ -1,52 +0,0 @@
1
- import type {
2
- Context,
3
- QueryAndVariables,
4
- SelectedQueryMaybeVariablesFunc,
5
- } from '../types';
6
-
7
-
8
- export function getQueryAndVariables(
9
- type: string,
10
- path: string,
11
- context: Context,
12
- selectedQuery?: SelectedQueryMaybeVariablesFunc,
13
- config?: any,
14
- ): QueryAndVariables | undefined {
15
-
16
- let query, getVariables;
17
-
18
- if (
19
- typeof selectedQuery === 'string' || typeof selectedQuery === 'function'
20
- ) {
21
- query = selectedQuery;
22
-
23
- } else if (Array.isArray(selectedQuery)) {
24
- query = selectedQuery[0];
25
- getVariables = selectedQuery[1];
26
-
27
- } else if (typeof selectedQuery === 'object') {
28
- query = selectedQuery.query;
29
- getVariables = selectedQuery.variables;
30
- }
31
-
32
- if (getVariables && typeof getVariables !== 'function') {
33
- throw Error(`getVariables for content type ${type} should be a function, not: ${typeof getVariables}`);
34
- }
35
-
36
- if (query && typeof query !== 'string' && typeof query !== 'function') {
37
- throw Error(`Query for content type ${type} should be a string or function, not: ${typeof query}`);
38
- }
39
-
40
- if (typeof query === 'function') {
41
- query = query(path, context, config);
42
- }
43
-
44
- if (query) {
45
- return {
46
- query,
47
- variables: getVariables ? getVariables(path, context, config) : {
48
- path,
49
- },
50
- };
51
- }
52
- }
@@ -1,46 +0,0 @@
1
- import type {ComponentDefinition} from '../../types';
2
-
3
-
4
- import {sanitizeGraphqlName} from '../../utils/sanitizeGraphqlName';
5
-
6
-
7
- export const configQuery = (
8
- list: [string, ComponentDefinition][],
9
- includeAppName = true,
10
- canUseConfigAsJson = true,
11
- ): string => {
12
- const hasQueryList = list?.filter(([key, def]) => def.configQuery) || [];
13
- if (hasQueryList.length === 0) {
14
- return canUseConfigAsJson ? 'configAsJson' : '';
15
- }
16
-
17
- const configsByApp: Record<string,string[]> = {};
18
- hasQueryList
19
- .forEach((entry) => {
20
- const nameParts = entry[0].split(':');
21
- if (nameParts.length === 2) {
22
- const sanitizedAppName = sanitizeGraphqlName(nameParts[0]);
23
- let existingConfigs = configsByApp[sanitizedAppName];
24
- if (!existingConfigs) {
25
- existingConfigs = [];
26
- configsByApp[sanitizedAppName] = existingConfigs;
27
- }
28
- existingConfigs.push(`${sanitizeGraphqlName(nameParts[1])}${entry[1].configQuery}`);
29
- }
30
- });
31
-
32
- // Still query for configAsJson if at least one item has no configQuery defined
33
- const configAsJsonQuery = canUseConfigAsJson && hasQueryList.length < list.length ? 'configAsJson' : '';
34
-
35
- if (!includeAppName) {
36
- return `${configAsJsonQuery}
37
- config {
38
- ${Object.values(configsByApp).reduce((arr, curr) => arr.concat(curr), []).join('\n')}
39
- }`;
40
- } else {
41
- return `${configAsJsonQuery}
42
- config {
43
- ${Object.entries(configsByApp).map(entry => entry[0] + '{\n' + entry[1].join('\n') + '\n}')}
44
- }`;
45
- }
46
- };
@@ -1,49 +0,0 @@
1
- import {ComponentRegistry} from '../../common/ComponentRegistry';
2
- import {configQuery} from './configQuery';
3
- import {indent} from '../../utils/indent';
4
-
5
-
6
- const macroConfigQuery = (): string => {
7
- return configQuery(ComponentRegistry.getMacros(), false, false);
8
- };
9
-
10
- export const richTextQuery = (fieldName: string) => {
11
- return `${fieldName}(processHtml:{type:absolute, imageWidths:[400, 800, 1200], imageSizes:"(max-width: 400px) 400px, (max-width: 800px) 800px, 1200px"}) {
12
- processedHtml
13
- macros {
14
- ref
15
- name
16
- descriptor
17
- ${indent(macroConfigQuery(), 8)}
18
- }
19
- links {
20
- ref
21
- uri
22
- content {
23
- _id
24
- }
25
- media {
26
- content {
27
- _id
28
- ... on media_Image {
29
- mediaUrl(type: absolute)
30
- }
31
- }
32
- intent
33
- }
34
- }
35
- images {
36
- ref
37
- image {
38
- _id
39
- ... on media_Image {
40
- imageUrl(scale: "width(768)", type:absolute)
41
- }
42
- }
43
- style {
44
- name
45
- aspectRatio
46
- filter
47
- }
48
- }}`;
49
- };
@@ -1,29 +0,0 @@
1
- import type {PathFragment} from '../types';
2
-
3
-
4
- import {
5
- FRAGMENT_CONTENTTYPE_NAME,
6
- FRAGMENT_DEFAULT_REGION_NAME,
7
- } from '../common/constants';
8
-
9
-
10
- export function parseComponentPath(contentType: string, path: string): PathFragment[] {
11
- const matches: PathFragment[] = [];
12
- let match;
13
- const myRegexp = /(?:(\w+)\/(\d+))+/g;
14
- while ((match = myRegexp.exec(path)) !== null) {
15
- matches.push({
16
- region: match[1],
17
- index: +match[2],
18
- });
19
- }
20
- if (contentType === FRAGMENT_CONTENTTYPE_NAME) {
21
- // there is no main region in fragment content and the root component has '/' path
22
- // prepend FRAGMENT_DEFAULT_REGION_NAME to path to conform to page structure
23
- matches.unshift({
24
- region: FRAGMENT_DEFAULT_REGION_NAME,
25
- index: 0,
26
- });
27
- }
28
- return matches;
29
- }
@@ -1,13 +0,0 @@
1
- import {FRAGMENT_CONTENTTYPE_NAME, FRAGMENT_DEFAULT_REGION_NAME} from '../common/constants';
2
-
3
-
4
- export function prefixFragmentCmpPath(contentType: string, path: string): string {
5
- if (contentType !== FRAGMENT_CONTENTTYPE_NAME) {
6
- return path;
7
- } else {
8
- // prepend FRAGMENT_DEFAULT_REGION_NAME to path to conform to page structure
9
- // so that component with path '/' becomes /FRAGMENT_DEFAULT_REGION_NAME/0
10
- // path /left/1 becomes /FRAGMENT_DEFAULT_REGION_NAME/0/left/1
11
- return `/${FRAGMENT_DEFAULT_REGION_NAME}/0${path === '/' ? '' : path}`;
12
- }
13
- }
@@ -1,38 +0,0 @@
1
- import type {PageComponent} from '../types';
2
-
3
-
4
- import {sanitizeGraphqlName} from '../utils/sanitizeGraphqlName';
5
-
6
-
7
- export function processComponentConfig(
8
- myAppName: string,
9
- myAppNameDashed: string,
10
- cmp: PageComponent,
11
- ): void {
12
- const cmpData = cmp[cmp.type];
13
- if (cmpData && 'descriptor' in cmpData && cmpData.descriptor) {
14
- const [appName, cmpName] = cmpData.descriptor.split(':');
15
- if (appName !== myAppName) {
16
- return;
17
- }
18
- let config;
19
- const configArray: object[] = [];
20
- if ('configAsJson' in cmpData && cmpData.configAsJson && cmpData.configAsJson[myAppNameDashed]) {
21
- config = cmpData.configAsJson[myAppNameDashed][cmpName];
22
- if (config) {
23
- configArray.push(config);
24
- delete cmpData.configAsJson;
25
- }
26
- }
27
- const sanitizedAppName = sanitizeGraphqlName(appName);
28
- if ('config' in cmpData && cmpData.config && cmpData.config[sanitizedAppName]) {
29
- config = cmpData.config[sanitizedAppName][sanitizeGraphqlName(cmpName)];
30
- if (config) {
31
- configArray.push(config);
32
- }
33
- }
34
- if (configArray.length) {
35
- cmpData.config = Object.assign({}, ...configArray);
36
- }
37
- }
38
- }
@@ -1,48 +0,0 @@
1
- import type {PageComponent} from '../types';
2
-
3
-
4
- import {XP_COMPONENT_TYPE} from '../common/constants';
5
- import {parseComponentPath} from './parseComponentPath';
6
- import {prefixFragmentCmpPath} from './prefixFragmentCmpPath';
7
-
8
-
9
- export function restrictComponentsToPath(
10
- contentType: string,
11
- components?: PageComponent[],
12
- componentPath?: string,
13
- ): PageComponent[] {
14
- if (!componentPath || !components?.length) {
15
- return components || [];
16
- }
17
-
18
- // filter components to the requested one only
19
- const component = components.find(cmp => {
20
- return cmp.path === componentPath;
21
- });
22
-
23
- if (!component) {
24
- return [];
25
- }
26
-
27
- let result: PageComponent[] = [component];
28
- if (component.type !== XP_COMPONENT_TYPE.LAYOUT) {
29
- // remember to include all parent layouts too !
30
- const cmpPath = parseComponentPath(contentType, component.path);
31
- for (let i = cmpPath.length - 2; i >= 0; i--) {
32
- const parentPath = cmpPath[i];
33
- const parentCmp = components.find(cmp => {
34
- return prefixFragmentCmpPath(contentType, cmp.path) === `/${parentPath.region}/${parentPath.index}`;
35
- });
36
- if (parentCmp) {
37
- result.unshift(parentCmp);
38
- }
39
- }
40
- } else {
41
- // It's a layout, include child components
42
- const childCmps = components.filter(cmp => cmp.path !== component.path && cmp.path.startsWith(component.path));
43
- if (childCmps.length) {
44
- result = result.concat(childCmps);
45
- }
46
- }
47
- return result;
48
- }
@@ -1,11 +0,0 @@
1
- import type {FetchContentResult} from '../types';
2
-
3
-
4
- import {validateNotFound} from './validateNotFound';
5
- import {validateShortcut} from './validateShortcut';
6
-
7
-
8
- export function validateData(props: FetchContentResult): void {
9
- validateNotFound(props);
10
- validateShortcut(props);
11
- }
@@ -1,20 +0,0 @@
1
- import type {FetchContentResult} from '../types';
2
-
3
-
4
- import {notFound} from 'next/navigation';
5
-
6
-
7
- export function validateNotFound(props: FetchContentResult): void {
8
- const {error} = props;
9
- if (error) {
10
- switch (error.code) {
11
- case '404':
12
- console.warn(error.code, error.message);
13
- notFound();
14
- break;
15
- default:
16
- console.error(error.code, error.message);
17
- throw new Error(error.message);
18
- }
19
- }
20
- }
@@ -1,43 +0,0 @@
1
- import type {FetchContentResult} from '../types';
2
-
3
-
4
- import {notFound, redirect, RedirectType} from 'next/navigation';
5
- import {RENDER_MODE} from '../common/constants';
6
- import {IS_DEV_MODE} from '../common/env';
7
- import {UrlProcessor} from '../common/UrlProcessor';
8
-
9
-
10
- export function validateShortcut(props: FetchContentResult): void {
11
- const {data, meta, error} = props;
12
- const dataObj = data?.get?.data;
13
- const pageUrl = dataObj?.target?.pageUrl;
14
- const parameters = dataObj?.parameters;
15
- if (meta.type === 'base:shortcut' && pageUrl) {
16
- if (meta.renderMode !== RENDER_MODE.NEXT) {
17
- // do not show shortcut targets in preview/edit mode
18
- console.warn(404, `Shortcuts are not available in ${meta.renderMode} render mode`);
19
- notFound();
20
- }
21
-
22
- let destination = UrlProcessor.process(pageUrl, meta, true);
23
- if (parameters) {
24
- const searchParams = parameters.map(({name, value}) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`).join('&');
25
- destination += '?' + searchParams;
26
- }
27
- console.debug(`Redirecting shortcut content [${meta.path}] to`, destination);
28
- redirect(destination, RedirectType.replace);
29
- }
30
-
31
- // we can not set 418 for static paths,
32
- // but we can show 404 instead to be handled in CS
33
- const canNotRender = meta && !meta.canRender && meta.renderMode !== RENDER_MODE.EDIT;
34
-
35
- const catchAllInNextProdMode = meta.renderMode === RENDER_MODE.NEXT && !IS_DEV_MODE && meta.catchAll;
36
-
37
- const isNotFound = (error && error.code === '404') || canNotRender || catchAllInNextProdMode;
38
-
39
- if (isNotFound) {
40
- console.warn(404, `Can not render content at [${meta.path}]`);
41
- notFound();
42
- }
43
- }
@@ -1,59 +0,0 @@
1
- 'use client';
2
- import type {Dict, LocaleContextType} from '../types';
3
-
4
- import React, {createContext, useContext, useEffect, useState} from 'react';
5
- import {getPhrase, loadPhrases} from './i18n';
6
-
7
-
8
- const LocaleContext = createContext<LocaleContextType>({
9
- dictionary: {},
10
- locale: '',
11
- localize: (key: string, ...args: any[]) => key,
12
- setLocale: (locale: string) => Promise.resolve({}),
13
- });
14
-
15
- export const useLocaleContext = () => useContext(LocaleContext);
16
-
17
- export const LocaleContextProvider = ({
18
- children,
19
- locale: localeProps = '',
20
- }: {
21
- children: any
22
- locale?: string
23
- }) => {
24
- const [currentLocale, setLocaleState] = useState(localeProps);
25
- const [dictionary, setPhrasesState] = useState<Dict>({});
26
- const [isLoaded, setLoadedState] = useState(false);
27
-
28
- const setLocale = async (locale: string): Promise<Dict> => {
29
- setLocaleState(locale);
30
- setLoadedState(false);
31
-
32
- return loadPhrases(locale).then((phrases) => {
33
- setPhrasesState(phrases);
34
- setLoadedState(true);
35
- return phrases;
36
- });
37
- };
38
-
39
- useEffect(() => {
40
- if (localeProps) {
41
- void setLocale(localeProps); // void to avoid @typescript-eslint/no-floating-promises
42
- }
43
- }, []);
44
-
45
- const localize = (key: string, ...args: any[]) => {
46
- return isLoaded ? getPhrase(currentLocale, dictionary, key, ...args) : key;
47
- };
48
-
49
- return (
50
- <LocaleContext.Provider value={{
51
- setLocale,
52
- locale: currentLocale,
53
- dictionary,
54
- localize,
55
- }}>
56
- {children}
57
- </LocaleContext.Provider>
58
- );
59
- };
package/src/i18n/i18n.ts DELETED
@@ -1,57 +0,0 @@
1
- import type {Dict} from '../types';
2
-
3
-
4
- export class I18n {
5
- private static locale = '';
6
- private static dictionary: Dict = {};
7
- private static isLoaded = false;
8
-
9
- public static async setLocale(locale: string): Promise<Dict> {
10
- this.locale = locale;
11
- this.isLoaded = false;
12
-
13
- return loadPhrases(locale).then((phrases) => {
14
- this.dictionary = phrases;
15
- this.isLoaded = true;
16
- return phrases;
17
- });
18
- }
19
-
20
- public static localize(key: string, ...args: any[]): string {
21
- return this.isLoaded ? getPhrase(this.locale, this.dictionary, key, ...args) : key;
22
- }
23
-
24
- public static getLocale() {
25
- return this.locale;
26
- }
27
-
28
- public static getDictionary() {
29
- return this.dictionary;
30
- }
31
- }
32
-
33
- export const loadPhrases = async (locale: string): Promise<Dict> => {
34
- return import(`@phrases/${locale}.json`)
35
- .then((module) => module.default)
36
- .catch((e) => {
37
- console.error(`Failed to load phrases for locale "${locale}"`, e);
38
- return {};
39
- });
40
- };
41
-
42
- export const getPhrase = (locale: string, dict: Dict, key: string, ...args: any[]) => {
43
- const template = dict[key];
44
- if (!template) {
45
- console.warn(`Missing localization phrase for locale "${locale}": <${key}>`);
46
- return `<${key}>`;
47
- }
48
- if (args.length) {
49
- let index = -1;
50
- return template.replace(/{(\d+)?}/g, (match, digit) => {
51
- index++;
52
- return args[digit || index] ?? match;
53
- });
54
- }
55
- return template;
56
- };
57
-