@enonic/nextjs-adapter 3.0.0-B1 → 3.0.0-B3

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 (241) hide show
  1. package/baseMappings.js +3 -2
  2. package/baseMappings.js.map +1 -0
  3. package/client.d.ts +1 -0
  4. package/client.js +3 -0
  5. package/client.js.map +1 -0
  6. package/common/ComponentRegistry.d.ts +34 -0
  7. package/{ComponentRegistry.js → common/ComponentRegistry.js} +26 -26
  8. package/common/ComponentRegistry.js.map +1 -0
  9. package/{UrlProcessor.d.ts → common/UrlProcessor.d.ts} +2 -2
  10. package/{UrlProcessor.js → common/UrlProcessor.js} +16 -8
  11. package/common/UrlProcessor.js.map +1 -0
  12. package/common/constants.d.ts +50 -0
  13. package/common/constants.js +79 -0
  14. package/common/constants.js.map +1 -0
  15. package/common/env.d.ts +11 -0
  16. package/common/env.js +29 -0
  17. package/common/env.js.map +1 -0
  18. package/guillotine/applyProcessors.d.ts +2 -0
  19. package/guillotine/applyProcessors.js +33 -0
  20. package/guillotine/applyProcessors.js.map +1 -0
  21. package/guillotine/buildComponentTree.d.ts +2 -0
  22. package/guillotine/buildComponentTree.js +45 -0
  23. package/guillotine/buildComponentTree.js.map +1 -0
  24. package/guillotine/buildErrorResponse.d.ts +3 -0
  25. package/guillotine/buildErrorResponse.js +26 -0
  26. package/guillotine/buildErrorResponse.js.map +1 -0
  27. package/guillotine/buildPage.d.ts +2 -0
  28. package/guillotine/buildPage.js +10 -0
  29. package/guillotine/buildPage.js.map +1 -0
  30. package/guillotine/collectComponentDescriptors.d.ts +6 -0
  31. package/guillotine/collectComponentDescriptors.js +43 -0
  32. package/guillotine/collectComponentDescriptors.js.map +1 -0
  33. package/guillotine/combineMultipleQueries.d.ts +2 -0
  34. package/guillotine/combineMultipleQueries.js +58 -0
  35. package/guillotine/combineMultipleQueries.js.map +1 -0
  36. package/guillotine/createMetaData.d.ts +17 -0
  37. package/guillotine/createMetaData.js +44 -0
  38. package/guillotine/createMetaData.js.map +1 -0
  39. package/guillotine/fetchContent.d.ts +2 -40
  40. package/guillotine/fetchContent.js +65 -676
  41. package/guillotine/fetchContent.js.map +1 -0
  42. package/guillotine/fetchContentData.d.ts +2 -0
  43. package/guillotine/fetchContentData.js +27 -0
  44. package/guillotine/fetchContentData.js.map +1 -0
  45. package/guillotine/fetchContentPathsForAllLocales.d.ts +2 -0
  46. package/guillotine/fetchContentPathsForAllLocales.js +21 -0
  47. package/guillotine/fetchContentPathsForAllLocales.js.map +1 -0
  48. package/guillotine/fetchContentPathsForLocale.d.ts +2 -0
  49. package/guillotine/fetchContentPathsForLocale.js +40 -0
  50. package/guillotine/fetchContentPathsForLocale.js.map +1 -0
  51. package/guillotine/fetchFromApi.d.ts +3 -0
  52. package/guillotine/fetchFromApi.js +67 -0
  53. package/guillotine/fetchFromApi.js.map +1 -0
  54. package/guillotine/fetchGuillotine.d.ts +3 -0
  55. package/guillotine/fetchGuillotine.js +57 -0
  56. package/guillotine/fetchGuillotine.js.map +1 -0
  57. package/guillotine/fetchMetaData.d.ts +2 -0
  58. package/guillotine/fetchMetaData.js +30 -0
  59. package/guillotine/fetchMetaData.js.map +1 -0
  60. package/guillotine/getCleanContentPathArrayOrThrow400.d.ts +2 -0
  61. package/guillotine/getCleanContentPathArrayOrThrow400.js +20 -0
  62. package/guillotine/getCleanContentPathArrayOrThrow400.js.map +1 -0
  63. package/guillotine/getComponentConfig.d.ts +2 -0
  64. package/guillotine/getComponentConfig.js +5 -0
  65. package/guillotine/getComponentConfig.js.map +1 -0
  66. package/guillotine/getContentAndComponentPaths.d.ts +1 -0
  67. package/guillotine/getContentAndComponentPaths.js +12 -0
  68. package/guillotine/getContentAndComponentPaths.js.map +1 -0
  69. package/guillotine/getMetaData.d.ts +0 -92
  70. package/guillotine/getMetaData.js +47 -109
  71. package/guillotine/getMetaData.js.map +1 -0
  72. package/guillotine/getParentRegion.d.ts +2 -0
  73. package/guillotine/getParentRegion.js +40 -0
  74. package/guillotine/getParentRegion.js.map +1 -0
  75. package/guillotine/getQueryAndVariables.d.ts +2 -0
  76. package/guillotine/getQueryAndVariables.js +32 -0
  77. package/guillotine/getQueryAndVariables.js.map +1 -0
  78. package/guillotine/metadata/configQuery.d.ts +2 -0
  79. package/guillotine/metadata/configQuery.js +36 -0
  80. package/guillotine/metadata/configQuery.js.map +1 -0
  81. package/guillotine/metadata/richTextQuery.d.ts +1 -0
  82. package/guillotine/metadata/richTextQuery.js +32 -0
  83. package/guillotine/metadata/richTextQuery.js.map +1 -0
  84. package/guillotine/parseComponentPath.d.ts +2 -0
  85. package/guillotine/parseComponentPath.js +22 -0
  86. package/guillotine/parseComponentPath.js.map +1 -0
  87. package/guillotine/prefixLayoutPath.d.ts +1 -0
  88. package/guillotine/prefixLayoutPath.js +13 -0
  89. package/guillotine/prefixLayoutPath.js.map +1 -0
  90. package/guillotine/processComponentConfig.d.ts +2 -0
  91. package/guillotine/processComponentConfig.js +30 -0
  92. package/guillotine/processComponentConfig.js.map +1 -0
  93. package/guillotine/restrictComponentsToPath.d.ts +2 -0
  94. package/guillotine/restrictComponentsToPath.js +35 -0
  95. package/guillotine/restrictComponentsToPath.js.map +1 -0
  96. package/guillotine/validateData.d.ts +2 -0
  97. package/guillotine/validateData.js +7 -0
  98. package/guillotine/validateData.js.map +1 -0
  99. package/guillotine/validateNotFound.d.ts +2 -0
  100. package/guillotine/validateNotFound.js +16 -0
  101. package/guillotine/validateNotFound.js.map +1 -0
  102. package/guillotine/validateShortcut.d.ts +2 -0
  103. package/guillotine/validateShortcut.js +29 -0
  104. package/guillotine/validateShortcut.js.map +1 -0
  105. package/i18n/LocaleContext.d.ts +2 -8
  106. package/i18n/LocaleContext.jsx +17 -13
  107. package/i18n/LocaleContext.jsx.map +1 -0
  108. package/i18n/i18n.d.ts +1 -3
  109. package/i18n/i18n.js +2 -1
  110. package/i18n/i18n.js.map +1 -0
  111. package/index.d.ts +14 -7
  112. package/index.js +14 -7
  113. package/index.js.map +1 -0
  114. package/package.json +63 -15
  115. package/query/Shortcut.js +1 -0
  116. package/query/Shortcut.js.map +1 -0
  117. package/server.d.ts +5 -0
  118. package/server.js.map +1 -0
  119. package/types/component.d.ts +114 -0
  120. package/types/component.js +2 -0
  121. package/types/component.js.map +1 -0
  122. package/types/componentProps.d.ts +104 -0
  123. package/types/componentProps.js +2 -0
  124. package/types/componentProps.js.map +1 -0
  125. package/types/guillotine.d.ts +342 -0
  126. package/types/guillotine.js +2 -0
  127. package/types/guillotine.js.map +1 -0
  128. package/types/i18n.d.ts +7 -0
  129. package/types/i18n.js +2 -0
  130. package/types/i18n.js.map +1 -0
  131. package/types/index.d.ts +45 -0
  132. package/types/index.js +3 -0
  133. package/types/index.js.map +1 -0
  134. package/types/next.d.ts +6 -0
  135. package/types/next.js +2 -0
  136. package/types/next.js.map +1 -0
  137. package/types/util.d.ts +3 -0
  138. package/types/util.js +3 -0
  139. package/types/util.js.map +1 -0
  140. package/utils/addLineNumbers.d.ts +1 -0
  141. package/utils/addLineNumbers.js +4 -0
  142. package/utils/addLineNumbers.js.map +1 -0
  143. package/utils/buildGuillotineRequestHeaders.d.ts +7 -0
  144. package/utils/buildGuillotineRequestHeaders.js +16 -0
  145. package/utils/buildGuillotineRequestHeaders.js.map +1 -0
  146. package/utils/commonChars.d.ts +1 -0
  147. package/utils/commonChars.js +17 -0
  148. package/utils/commonChars.js.map +1 -0
  149. package/utils/fixDoubleSlashes.d.ts +1 -0
  150. package/utils/fixDoubleSlashes.js +4 -0
  151. package/utils/fixDoubleSlashes.js.map +1 -0
  152. package/utils/getContentApiUrl.d.ts +2 -0
  153. package/utils/getContentApiUrl.js +15 -0
  154. package/utils/getContentApiUrl.js.map +1 -0
  155. package/utils/getProjectLocaleConfig.d.ts +2 -0
  156. package/utils/getProjectLocaleConfig.js +19 -0
  157. package/utils/getProjectLocaleConfig.js.map +1 -0
  158. package/utils/getProjectLocaleConfigById.d.ts +2 -0
  159. package/utils/getProjectLocaleConfigById.js +16 -0
  160. package/utils/getProjectLocaleConfigById.js.map +1 -0
  161. package/utils/getProjectLocaleConfigByLocale.d.ts +2 -0
  162. package/utils/getProjectLocaleConfigByLocale.js +13 -0
  163. package/utils/getProjectLocaleConfigByLocale.js.map +1 -0
  164. package/utils/getProjectLocaleConfigs.d.ts +2 -0
  165. package/utils/getProjectLocaleConfigs.js +30 -0
  166. package/utils/getProjectLocaleConfigs.js.map +1 -0
  167. package/utils/getProjectLocales.d.ts +1 -0
  168. package/utils/getProjectLocales.js +5 -0
  169. package/utils/getProjectLocales.js.map +1 -0
  170. package/utils/getRenderMode.d.ts +3 -0
  171. package/utils/getRenderMode.js +8 -0
  172. package/utils/getRenderMode.js.map +1 -0
  173. package/utils/getRequestLocaleInfo.d.ts +6 -0
  174. package/utils/getRequestLocaleInfo.js +26 -0
  175. package/utils/getRequestLocaleInfo.js.map +1 -0
  176. package/utils/getXpBaseUrl.d.ts +2 -0
  177. package/utils/getXpBaseUrl.js +8 -0
  178. package/utils/getXpBaseUrl.js.map +1 -0
  179. package/utils/indent.d.ts +1 -0
  180. package/utils/indent.js +5 -0
  181. package/utils/indent.js.map +1 -0
  182. package/utils/sanitizeGraphqlName.d.ts +1 -0
  183. package/utils/sanitizeGraphqlName.js +12 -0
  184. package/utils/sanitizeGraphqlName.js.map +1 -0
  185. package/views/BaseComponent.d.ts +6 -11
  186. package/views/BaseComponent.jsx +18 -21
  187. package/views/BaseComponent.jsx.map +1 -0
  188. package/views/BaseContent.d.ts +3 -3
  189. package/views/BaseContent.jsx +2 -5
  190. package/views/BaseContent.jsx.map +1 -0
  191. package/views/BaseLayout.d.ts +3 -16
  192. package/views/BaseLayout.jsx +3 -3
  193. package/views/BaseLayout.jsx.map +1 -0
  194. package/views/BaseMacro.d.ts +3 -13
  195. package/views/BaseMacro.jsx +4 -3
  196. package/views/BaseMacro.jsx.map +1 -0
  197. package/views/BasePage.d.ts +3 -18
  198. package/views/BasePage.jsx +3 -3
  199. package/views/BasePage.jsx.map +1 -0
  200. package/views/BasePart.d.ts +3 -18
  201. package/views/BasePart.jsx +3 -3
  202. package/views/BasePart.jsx.map +1 -0
  203. package/views/Empty.d.ts +2 -2
  204. package/views/Empty.jsx +2 -1
  205. package/views/Empty.jsx.map +1 -0
  206. package/views/Fragment.d.ts +3 -9
  207. package/views/Fragment.jsx +2 -2
  208. package/views/Fragment.jsx.map +1 -0
  209. package/views/MainView.d.ts +3 -3
  210. package/views/MainView.jsx +2 -2
  211. package/views/MainView.jsx.map +1 -0
  212. package/views/PropsView.d.ts +3 -0
  213. package/views/PropsView.jsx +21 -0
  214. package/views/PropsView.jsx.map +1 -0
  215. package/views/Region.d.ts +4 -17
  216. package/views/Region.jsx +2 -2
  217. package/views/Region.jsx.map +1 -0
  218. package/views/RichTextView.d.ts +3 -13
  219. package/views/RichTextView.jsx +2 -2
  220. package/views/RichTextView.jsx.map +1 -0
  221. package/views/SingleComponent.d.ts +3 -3
  222. package/views/SingleComponent.jsx +1 -2
  223. package/views/SingleComponent.jsx.map +1 -0
  224. package/views/StaticContent.d.ts +2 -6
  225. package/views/StaticContent.jsx +1 -0
  226. package/views/StaticContent.jsx.map +1 -0
  227. package/views/Text.d.ts +5 -5
  228. package/views/Text.jsx +1 -1
  229. package/views/Text.jsx.map +1 -0
  230. package/views/getClientHydratedHtml.d.ts +2 -0
  231. package/views/getClientHydratedHtml.jsx +9 -0
  232. package/views/getClientHydratedHtml.jsx.map +1 -0
  233. package/views/macros/DefaultMacro.d.ts +1 -1
  234. package/views/macros/DefaultMacro.jsx +1 -0
  235. package/views/macros/DefaultMacro.jsx.map +1 -0
  236. package/views/macros/DisableMacro.d.ts +1 -1
  237. package/views/macros/DisableMacro.jsx +1 -0
  238. package/views/macros/DisableMacro.jsx.map +1 -0
  239. package/ComponentRegistry.d.ts +0 -64
  240. package/utils.d.ts +0 -111
  241. package/utils.js +0 -255
@@ -8,18 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- import React, { createContext, useContext, useState } from 'react';
11
+ import React, { createContext, useContext, useEffect, useState } from 'react';
12
12
  import { getPhrase, loadPhrases } from './i18n';
13
13
  const LocaleContext = createContext({
14
- setLocale: (locale) => {
15
- },
16
- locale: '',
17
14
  dictionary: {},
15
+ locale: '',
18
16
  localize: (key, ...args) => key,
17
+ setLocale: (locale) => Promise.resolve({}),
19
18
  });
20
19
  export const useLocaleContext = () => useContext(LocaleContext);
21
- export const LocaleContextProvider = ({ children, locale }) => {
22
- const [currentLocale, setLocaleState] = useState(locale);
20
+ export const LocaleContextProvider = ({ children, locale: localeProps = '', }) => {
21
+ const [currentLocale, setLocaleState] = useState(localeProps);
23
22
  const [dictionary, setPhrasesState] = useState({});
24
23
  const setLocale = (locale) => __awaiter(void 0, void 0, void 0, function* () {
25
24
  setLocaleState(locale);
@@ -29,14 +28,19 @@ export const LocaleContextProvider = ({ children, locale }) => {
29
28
  return phrases;
30
29
  });
31
30
  });
32
- if (locale && currentLocale !== locale) {
33
- // async/await is not supported in client components yet
34
- void setLocale(locale);
35
- }
31
+ useEffect(() => {
32
+ if (localeProps) {
33
+ void setLocale(localeProps); // void to avoid @typescript-eslint/no-floating-promises
34
+ }
35
+ }, []);
36
36
  const localize = (key, ...args) => getPhrase(currentLocale, dictionary, key, ...args);
37
- return (
38
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
39
- <LocaleContext.Provider value={{ setLocale, locale: currentLocale, dictionary, localize }}>
37
+ return (<LocaleContext.Provider value={{
38
+ setLocale,
39
+ locale: currentLocale,
40
+ dictionary,
41
+ localize,
42
+ }}>
40
43
  {children}
41
44
  </LocaleContext.Provider>);
42
45
  };
46
+ //# sourceMappingURL=LocaleContext.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocaleContext.jsx","sourceRoot":"","sources":["../../src/i18n/LocaleContext.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;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DAAwD;QACzF,CAAC;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,GAAG,IAAW,EAAE,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAErG,OAAO,CACH,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC3B,SAAS;YACT,MAAM,EAAE,aAAa;YACrB,UAAU;YACV,QAAQ;SACX,CAAC,CACE;YAAA,CAAC,QAAQ,CACb;QAAA,EAAE,aAAa,CAAC,QAAQ,CAAC,CAC5B,CAAC;AACN,CAAC,CAAC"}
package/i18n/i18n.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- export type Dict = {
2
- [key: string]: string;
3
- };
1
+ import type { Dict } from '../types';
4
2
  export declare class I18n {
5
3
  private static locale;
6
4
  private static dictionary;
package/i18n/i18n.js CHANGED
@@ -44,7 +44,7 @@ export const getPhrase = (locale, dict, key, ...args) => {
44
44
  console.warn(`Missing localization phrase for locale "${locale}": <${key}>`);
45
45
  return `<${key}>`;
46
46
  }
47
- if (args === null || args === void 0 ? void 0 : args.length) {
47
+ if (args.length) {
48
48
  let index = -1;
49
49
  return template.replace(/{(\d+)?}/g, (match, digit) => {
50
50
  var _a;
@@ -54,3 +54,4 @@ export const getPhrase = (locale, dict, key, ...args) => {
54
54
  }
55
55
  return template;
56
56
  };
57
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../../src/i18n/i18n.ts"],"names":[],"mappings":";;;;;;;;;AAGA,MAAM,OAAO,IAAI;IAIN,MAAM,CAAO,SAAS,CAAC,MAAc;;YACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;gBACxC,IAAI,CAAC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IACD,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;QACf,OAAO,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;;YAClD,KAAK,EAAE,CAAC;YACR,OAAO,MAAA,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,mCAAI,KAAK,CAAC;QACzC,CAAC,CAAC,CAAC;IACP,CAAC;IACD,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC"}
package/index.d.ts CHANGED
@@ -1,7 +1,14 @@
1
- export * from './utils';
2
- export * from './guillotine/fetchContent';
3
- export * from './guillotine/getMetaData';
4
- export * from './ComponentRegistry';
5
- export * from './UrlProcessor';
6
- export * from './i18n/i18n';
7
- export * from './i18n/LocaleContext';
1
+ export { APP_NAME, APP_NAME_DASHED, APP_NAME_UNDERSCORED, IS_DEV_MODE, } from './common/env';
2
+ export type * from './types';
3
+ export { ComponentRegistry } from './common/ComponentRegistry';
4
+ export { CATCH_ALL, JSESSIONID_HEADER, PORTAL_COMPONENT_ATTRIBUTE, PORTAL_REGION_ATTRIBUTE, PROJECT_ID_HEADER, RENDER_MODE, RENDER_MODE_HEADER, XP_BASE_URL_HEADER, XP_COMPONENT_TYPE, XP_REQUEST_TYPE, } from './common/constants';
5
+ export { richTextQuery } from './guillotine/metadata/richTextQuery';
6
+ export { validateData } from './guillotine/validateData';
7
+ export { I18n } from './i18n/i18n';
8
+ export { getContentApiUrl } from './utils/getContentApiUrl';
9
+ export { getProjectLocaleConfig } from './utils/getProjectLocaleConfig';
10
+ export { getProjectLocaleConfigById } from './utils/getProjectLocaleConfigById';
11
+ export { getProjectLocaleConfigByLocale } from './utils/getProjectLocaleConfigByLocale';
12
+ export { getRequestLocaleInfo } from './utils/getRequestLocaleInfo';
13
+ export { sanitizeGraphqlName } from './utils/sanitizeGraphqlName';
14
+ export { UrlProcessor, getAsset, getUrl, } from './common/UrlProcessor';
package/index.js CHANGED
@@ -1,7 +1,14 @@
1
- export * from './utils';
2
- export * from './guillotine/fetchContent';
3
- export * from './guillotine/getMetaData';
4
- export * from './ComponentRegistry';
5
- export * from './UrlProcessor';
6
- export * from './i18n/i18n';
7
- export * from './i18n/LocaleContext';
1
+ export { APP_NAME, APP_NAME_DASHED, APP_NAME_UNDERSCORED, IS_DEV_MODE, } from './common/env';
2
+ export { ComponentRegistry } from './common/ComponentRegistry';
3
+ export { CATCH_ALL, JSESSIONID_HEADER, PORTAL_COMPONENT_ATTRIBUTE, PORTAL_REGION_ATTRIBUTE, PROJECT_ID_HEADER, RENDER_MODE, RENDER_MODE_HEADER, XP_BASE_URL_HEADER, XP_COMPONENT_TYPE, XP_REQUEST_TYPE, } from './common/constants';
4
+ export { richTextQuery } from './guillotine/metadata/richTextQuery';
5
+ export { validateData } from './guillotine/validateData';
6
+ export { I18n } from './i18n/i18n';
7
+ export { getContentApiUrl } from './utils/getContentApiUrl';
8
+ export { getProjectLocaleConfig } from './utils/getProjectLocaleConfig';
9
+ export { getProjectLocaleConfigById } from './utils/getProjectLocaleConfigById';
10
+ export { getProjectLocaleConfigByLocale } from './utils/getProjectLocaleConfigByLocale';
11
+ export { getRequestLocaleInfo } from './utils/getRequestLocaleInfo';
12
+ export { sanitizeGraphqlName } from './utils/sanitizeGraphqlName';
13
+ export { UrlProcessor, getAsset, getUrl, } from './common/UrlProcessor';
14
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,eAAe,EACf,oBAAoB,EACpB,WAAW,GACd,MAAM,cAAc,CAAC;AAItB,OAAO,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EACH,SAAS,EACT,iBAAiB,EACjB,0BAA0B,EAC1B,uBAAuB,EACvB,iBAAiB,EACjB,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,GAClB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAC,aAAa,EAAC,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAAC,IAAI,EAAC,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAC,sBAAsB,EAAC,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAC,0BAA0B,EAAC,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAC,8BAA8B,EAAC,MAAM,wCAAwC,CAAC;AACtF,OAAO,EAAC,oBAAoB,EAAC,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAC,mBAAmB,EAAC,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EACH,YAAY,EACZ,QAAQ,EACR,MAAM,GACT,MAAM,uBAAuB,CAAC"}
package/package.json CHANGED
@@ -1,37 +1,85 @@
1
1
  {
2
2
  "name": "@enonic/nextjs-adapter",
3
- "version": "3.0.0-B1",
3
+ "version": "3.0.0-B3",
4
4
  "license": "Apache-2.0",
5
5
  "main": "index.js",
6
+ "author": "Pavel Milkevich <pmi@enonic.com>",
7
+ "contributors": [
8
+ "Christian Westgaard <cwe@enonic.com>"
9
+ ],
10
+ "files": [
11
+ "*.d.ts",
12
+ "*.map",
13
+ "baseMappings*",
14
+ "client.js",
15
+ "common",
16
+ "guillotine",
17
+ "index*",
18
+ "i18n",
19
+ "query",
20
+ "src",
21
+ "types",
22
+ "utils",
23
+ "views"
24
+ ],
25
+ "keywords": [
26
+ "enonic",
27
+ "nextjs",
28
+ "adapter",
29
+ "typescript",
30
+ "ecmascript"
31
+ ],
6
32
  "publishConfig": {
7
33
  "access": "public"
8
34
  },
9
35
  "scripts": {
10
- "copy": "npx --yes cpy-cli package.json README.md dist",
11
- "build": "tsc --build tsconfig.json",
36
+ "clean": "del-cli *.d.ts *.js.map baseMappings.* client.* server.* common coverage index.* enonic-nextjs-adapter-*.tgz guillotine i18n query types utils views dist",
37
+ "build": "tsc",
38
+ "build:prod": "tsc --outDir ./dist && npx --yes cpy-cli package.json README.md ./dist",
39
+ "release": "concurrently -c auto -g --timings npm:test npm:lint npm:build:prod",
40
+ "check:types": "tsc --noEmit",
41
+ "madge": "madge -i docs/madge.png -x '(constants|env)\\.ts' src/index.ts",
12
42
  "lint": "eslint --quiet src",
13
- "lint:fix": "eslint --fix src"
43
+ "lint:fix": "eslint --fix src",
44
+ "prebuild:prod": "npm run clean",
45
+ "prebuild": "npm run clean",
46
+ "premadge": "mkdirp docs",
47
+ "pretest": "del-cli coverage",
48
+ "test": "jest --no-cache --coverage"
14
49
  },
15
50
  "dependencies": {
16
- "@formatjs/intl-localematcher": "^0.5.2",
17
- "html-react-parser": "^5.0.11",
18
- "lru-cache": "^10.0.1",
51
+ "@formatjs/intl-localematcher": "^0.5.4",
52
+ "html-react-parser": "^5.1.2",
19
53
  "negotiator": "^0.6.3",
20
- "next": "^14.0.4",
54
+ "next": "^14.1.0",
21
55
  "react": "18.2.0",
22
56
  "react-dom": "18.2.0",
23
57
  "unescape": "^1.0.1"
24
58
  },
25
59
  "devDependencies": {
60
+ "@edge-runtime/jest-environment": "^2.3.9",
61
+ "@enonic-types/core": "^7.14.0-B2",
26
62
  "@enonic/eslint-config": "^1.1.0",
63
+ "@testing-library/jest-dom": "^6.4.2",
64
+ "@testing-library/react": "^14.2.1",
27
65
  "@types/negotiator": "^0.6.3",
28
- "@types/node": "^20.10.7",
29
- "@types/react": "18.2.47",
30
- "@types/react-dom": "18.2.18",
31
- "@typescript-eslint/eslint-plugin": "^6.18.1",
32
- "@typescript-eslint/parser": "^6.18.1",
66
+ "@types/node": "^20.11.17",
67
+ "@types/react": "^18.2.55",
68
+ "@types/react-dom": "^18.2.19",
69
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
70
+ "@typescript-eslint/parser": "^6.21.0",
71
+ "concurrently": "^8.2.2",
72
+ "cpy-cli": "^5.0.0",
73
+ "del-cli": "^5.1.0",
33
74
  "eslint": "^8.56.0",
34
75
  "eslint-plugin-react": "^7.33.2",
35
- "typescript": "^5.2.2"
36
- }
76
+ "jest": "^29.7.0",
77
+ "jest-environment-jsdom": "^29.7.0",
78
+ "madge": "^6.1.0",
79
+ "mkdirp": "^3.0.1",
80
+ "ts-jest": "^29.1.2",
81
+ "ts-node": "^10.9.2",
82
+ "typescript": "^5.3.3"
83
+ },
84
+ "types": "index.d.ts"
37
85
  }
package/query/Shortcut.js CHANGED
@@ -12,3 +12,4 @@ export const getShortcutQuery = `
12
12
  }
13
13
  }
14
14
  }`;
15
+ //# sourceMappingURL=Shortcut.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Shortcut.js","sourceRoot":"","sources":["../../src/query/Shortcut.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;IAa5B,CAAC"}
package/server.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { fetchContent } from './guillotine/fetchContent';
2
+ export { fetchContentPathsForAllLocales } from './guillotine/fetchContentPathsForAllLocales';
3
+ export { fetchContentPathsForLocale } from './guillotine/fetchContentPathsForLocale';
4
+ export { fetchFromApi } from './guillotine/fetchFromApi';
5
+ export { fetchGuillotine } from './guillotine/fetchGuillotine';
package/server.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAC,8BAA8B,EAAC,MAAM,6CAA6C,CAAC;AAC3F,OAAO,EAAC,0BAA0B,EAAC,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,114 @@
1
+ /// <reference types="react" />
2
+ import type { XP_COMPONENT_TYPE } from '../common/constants';
3
+ import type { Context } from './next';
4
+ export interface ComponentDefinitionParams {
5
+ query?: SelectedQueryMaybeVariablesFunc;
6
+ configQuery?: string;
7
+ processor?: DataProcessor;
8
+ view?: React.FunctionComponent<any>;
9
+ }
10
+ /**
11
+ * Object that configures the handling of a particular content type. All attributes are optional (see examples below), and missing values will fall back to default behavior:
12
+ * - 'query' (used in fetchContent.ts) Guillotine query for fetching content data, may also have a function that supplies guillotine variables. So, 'query' can EITHER be only a query string, OR also add a get-guillotine-variables function. In the latter case, 'query' can be an object with 'query' and 'variables' attributes, or an array where the query string is first and the get-variables function is second. Either way, the get-variables function takes two arguments: path (content path, mandatory) and context (next.js-supplied Context from getServerSideProps etc. Optional, and requires that fetchContent is called with the context, of course).
13
+ * - 'props' (used in fetchContent.ts) is a function for processing props after fetching them
14
+ * - 'view' (used in BasePage.tsx) is a React component: top-level content-type-specific rendering with the props first fetched from guillotine (and then optionally preprocessed with the function in 'props').
15
+ */
16
+ export interface ComponentDefinition {
17
+ catchAll?: boolean;
18
+ query?: SelectedQueryMaybeVariablesFunc;
19
+ configQuery?: string;
20
+ processor?: DataProcessor;
21
+ view?: React.FunctionComponent<any>;
22
+ }
23
+ export interface ComponentDescriptor {
24
+ type?: ComponentDefinition;
25
+ component?: PageComponent;
26
+ queryAndVariables?: QueryAndVariables;
27
+ }
28
+ export type ComponentDictionary = Record<string, ComponentDefinitionParams>;
29
+ export type DataProcessor = (data: any, context?: Context, config?: any) => Promise<Record<string, any>>;
30
+ export interface FragmentData {
31
+ id: string;
32
+ fragment: {
33
+ components: PageComponent[];
34
+ };
35
+ }
36
+ export interface ImageData {
37
+ ref: string;
38
+ image: {
39
+ id: string;
40
+ } | null;
41
+ }
42
+ export interface LayoutData {
43
+ descriptor: string;
44
+ config?: any;
45
+ [customKeysFromQuery: string]: any;
46
+ }
47
+ export interface LinkData {
48
+ ref: string;
49
+ media: {
50
+ content: {
51
+ id: string;
52
+ };
53
+ } | null;
54
+ }
55
+ export type MacroConfig = Record<string, any>;
56
+ export interface MacroData {
57
+ ref: string;
58
+ name: string;
59
+ descriptor: string;
60
+ config: Record<string, MacroConfig>;
61
+ }
62
+ export interface PageComponent {
63
+ [key: string]: any;
64
+ type: XP_COMPONENT_TYPE;
65
+ path: string;
66
+ page?: PageData;
67
+ part?: PartData;
68
+ layout?: LayoutData;
69
+ fragment?: FragmentData;
70
+ text?: TextData;
71
+ image?: any;
72
+ regions?: RegionTree;
73
+ data?: any;
74
+ error?: any;
75
+ }
76
+ export interface PageData {
77
+ descriptor: string;
78
+ config?: any;
79
+ template?: string | null;
80
+ regions?: RegionTree;
81
+ }
82
+ export interface PageRegion {
83
+ name: string;
84
+ components: PageComponent[];
85
+ }
86
+ export interface PartData {
87
+ descriptor: string;
88
+ config: any;
89
+ [customKeysFromQuery: string]: any;
90
+ }
91
+ export interface QueryAndVariables {
92
+ query: string;
93
+ variables?: Record<string, any>;
94
+ }
95
+ export type QueryGetter = (path: string, context?: Context, config?: any) => string;
96
+ export type SelectedQueryMaybeVariablesFunc = string | QueryGetter | {
97
+ query: string | QueryGetter;
98
+ variables: VariablesGetter;
99
+ } | [string | QueryGetter, VariablesGetter];
100
+ export type RegionTree = Record<string, PageRegion>;
101
+ export interface RichTextData {
102
+ processedHtml: string;
103
+ links: LinkData[];
104
+ macros: MacroData[];
105
+ images: ImageData[];
106
+ }
107
+ export interface TextData {
108
+ value: RichTextData;
109
+ }
110
+ export type VariablesGetter = (path: string, context?: Context, config?: any) => VariablesGetterResult;
111
+ export interface VariablesGetterResult {
112
+ [variables: string]: any;
113
+ path: string;
114
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/types/component.ts"],"names":[],"mappings":""}
@@ -0,0 +1,104 @@
1
+ /// <reference types="react" />
2
+ import { DOMNode } from 'html-react-parser';
3
+ import type { RENDER_MODE, XP_REQUEST_TYPE } from '../common/constants';
4
+ import type { FragmentData, LayoutData, MacroConfig, MacroData, PageComponent, PageData, PartData, RichTextData, RegionTree } from './component';
5
+ export interface BaseComponentProps {
6
+ component: PageComponent;
7
+ meta: MetaData;
8
+ common?: any;
9
+ }
10
+ export interface BaseLayoutProps {
11
+ component?: LayoutData;
12
+ path: string;
13
+ regions?: RegionTree;
14
+ common?: any;
15
+ meta: MetaData;
16
+ }
17
+ export interface BaseMacroProps {
18
+ data: MacroData;
19
+ meta: MetaData;
20
+ renderInEditMode?: boolean;
21
+ }
22
+ export interface BasePageProps {
23
+ component?: PageData;
24
+ path?: string;
25
+ common?: any;
26
+ data?: any;
27
+ error?: string;
28
+ meta: MetaData;
29
+ }
30
+ export interface BasePartProps {
31
+ component?: PartData;
32
+ path: string;
33
+ common?: any;
34
+ data?: any;
35
+ error?: string;
36
+ meta: MetaData;
37
+ }
38
+ export interface FragmentProps {
39
+ page?: PageData;
40
+ component?: FragmentData;
41
+ common?: any;
42
+ meta: MetaData;
43
+ }
44
+ export interface LayoutProps {
45
+ layout: LayoutData;
46
+ path: string;
47
+ common: any;
48
+ meta: MetaData;
49
+ }
50
+ export interface MacroProps {
51
+ name: string;
52
+ config: MacroConfig;
53
+ meta: MetaData;
54
+ }
55
+ export interface MetaData {
56
+ type: string;
57
+ path: string;
58
+ requestType: XP_REQUEST_TYPE;
59
+ renderMode: RENDER_MODE;
60
+ requestedComponent?: PageComponent;
61
+ canRender: boolean;
62
+ catchAll: boolean;
63
+ apiUrl: string;
64
+ baseUrl: string;
65
+ locale: string;
66
+ defaultLocale: string;
67
+ }
68
+ export interface PageProps {
69
+ page: PageData;
70
+ path: string;
71
+ data?: any;
72
+ common?: any;
73
+ meta: MetaData;
74
+ }
75
+ export interface PartProps {
76
+ part: PartData;
77
+ path: string;
78
+ data?: any;
79
+ common?: any;
80
+ meta: MetaData;
81
+ }
82
+ export interface RegionProps {
83
+ name: string;
84
+ components?: PageComponent[];
85
+ className?: string;
86
+ common?: any;
87
+ meta: MetaData;
88
+ }
89
+ export interface RegionsProps {
90
+ page: PageData | null;
91
+ name?: string;
92
+ common?: any;
93
+ meta: MetaData;
94
+ }
95
+ export type Replacer = (domNode: DOMNode, data: RichTextData, meta: MetaData, renderMacroInEditMode: boolean) => ReplacerResult;
96
+ export type ReplacerResult = JSX.Element | object | void | undefined | null | false;
97
+ export interface RichTextViewProps {
98
+ data: RichTextData;
99
+ meta: MetaData;
100
+ className?: string;
101
+ tag?: string;
102
+ renderMacroInEditMode?: boolean;
103
+ customReplacer?: Replacer;
104
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=componentProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"componentProps.js","sourceRoot":"","sources":["../../src/types/componentProps.ts"],"names":[],"mappings":""}