@enonic/nextjs-adapter 2.0.0 → 3.0.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 (245) 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} +5 -4
  10. package/{UrlProcessor.js → common/UrlProcessor.js} +40 -17
  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 +28 -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 +1 -41
  40. package/guillotine/fetchContent.js +193 -800
  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 +65 -0
  53. package/guillotine/fetchFromApi.js.map +1 -0
  54. package/guillotine/fetchGuillotine.d.ts +3 -0
  55. package/guillotine/fetchGuillotine.js +55 -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 +7 -0
  106. package/i18n/LocaleContext.jsx +46 -0
  107. package/i18n/LocaleContext.jsx.map +1 -0
  108. package/i18n/i18n.d.ts +11 -0
  109. package/i18n/i18n.js +57 -0
  110. package/i18n/i18n.js.map +1 -0
  111. package/index.d.ts +18 -5
  112. package/index.js +18 -5
  113. package/index.js.map +1 -0
  114. package/package.json +67 -16
  115. package/query/Shortcut.js +1 -0
  116. package/query/Shortcut.js.map +1 -0
  117. package/types/component.d.ts +114 -0
  118. package/types/component.js +2 -0
  119. package/types/component.js.map +1 -0
  120. package/types/componentProps.d.ts +104 -0
  121. package/types/componentProps.js +2 -0
  122. package/types/componentProps.js.map +1 -0
  123. package/types/guillotine.d.ts +342 -0
  124. package/types/guillotine.js +2 -0
  125. package/types/guillotine.js.map +1 -0
  126. package/types/i18n.d.ts +7 -0
  127. package/types/i18n.js +2 -0
  128. package/types/i18n.js.map +1 -0
  129. package/types/index.d.ts +45 -0
  130. package/types/index.js +3 -0
  131. package/types/index.js.map +1 -0
  132. package/types/next.d.ts +6 -0
  133. package/types/next.js +2 -0
  134. package/types/next.js.map +1 -0
  135. package/types/util.d.ts +3 -0
  136. package/types/util.js +3 -0
  137. package/types/util.js.map +1 -0
  138. package/utils/addLineNumbers.d.ts +1 -0
  139. package/utils/addLineNumbers.js +4 -0
  140. package/utils/addLineNumbers.js.map +1 -0
  141. package/utils/buildGuillotineRequestHeaders.d.ts +7 -0
  142. package/utils/buildGuillotineRequestHeaders.js +16 -0
  143. package/utils/buildGuillotineRequestHeaders.js.map +1 -0
  144. package/utils/commonChars.d.ts +1 -0
  145. package/utils/commonChars.js +17 -0
  146. package/utils/commonChars.js.map +1 -0
  147. package/utils/fixDoubleSlashes.d.ts +1 -0
  148. package/utils/fixDoubleSlashes.js +4 -0
  149. package/utils/fixDoubleSlashes.js.map +1 -0
  150. package/utils/getContentApiUrl.d.ts +2 -0
  151. package/utils/getContentApiUrl.js +15 -0
  152. package/utils/getContentApiUrl.js.map +1 -0
  153. package/utils/getProjectLocaleConfig.d.ts +2 -0
  154. package/utils/getProjectLocaleConfig.js +19 -0
  155. package/utils/getProjectLocaleConfig.js.map +1 -0
  156. package/utils/getProjectLocaleConfigById.d.ts +2 -0
  157. package/utils/getProjectLocaleConfigById.js +16 -0
  158. package/utils/getProjectLocaleConfigById.js.map +1 -0
  159. package/utils/getProjectLocaleConfigByLocale.d.ts +2 -0
  160. package/utils/getProjectLocaleConfigByLocale.js +13 -0
  161. package/utils/getProjectLocaleConfigByLocale.js.map +1 -0
  162. package/utils/getProjectLocaleConfigs.d.ts +2 -0
  163. package/utils/getProjectLocaleConfigs.js +30 -0
  164. package/utils/getProjectLocaleConfigs.js.map +1 -0
  165. package/utils/getProjectLocales.d.ts +1 -0
  166. package/utils/getProjectLocales.js +5 -0
  167. package/utils/getProjectLocales.js.map +1 -0
  168. package/utils/getRenderMode.d.ts +3 -0
  169. package/utils/getRenderMode.js +8 -0
  170. package/utils/getRenderMode.js.map +1 -0
  171. package/utils/getRequestLocaleInfo.d.ts +6 -0
  172. package/utils/getRequestLocaleInfo.js +26 -0
  173. package/utils/getRequestLocaleInfo.js.map +1 -0
  174. package/utils/getXpBaseUrl.d.ts +2 -0
  175. package/utils/getXpBaseUrl.js +8 -0
  176. package/utils/getXpBaseUrl.js.map +1 -0
  177. package/utils/indent.d.ts +1 -0
  178. package/utils/indent.js +5 -0
  179. package/utils/indent.js.map +1 -0
  180. package/utils/sanitizeGraphqlName.d.ts +1 -0
  181. package/utils/sanitizeGraphqlName.js +12 -0
  182. package/utils/sanitizeGraphqlName.js.map +1 -0
  183. package/views/BaseComponent.d.ts +5 -10
  184. package/views/BaseComponent.jsx +17 -6
  185. package/views/BaseComponent.jsx.map +1 -0
  186. package/views/BaseContent.d.ts +3 -3
  187. package/views/BaseContent.jsx +2 -5
  188. package/views/BaseContent.jsx.map +1 -0
  189. package/views/BaseLayout.d.ts +3 -16
  190. package/views/BaseLayout.jsx +3 -3
  191. package/views/BaseLayout.jsx.map +1 -0
  192. package/views/BaseMacro.d.ts +3 -13
  193. package/views/BaseMacro.jsx +4 -3
  194. package/views/BaseMacro.jsx.map +1 -0
  195. package/views/BasePage.d.ts +3 -18
  196. package/views/BasePage.jsx +3 -3
  197. package/views/BasePage.jsx.map +1 -0
  198. package/views/BasePart.d.ts +3 -18
  199. package/views/BasePart.jsx +3 -3
  200. package/views/BasePart.jsx.map +1 -0
  201. package/views/Empty.d.ts +2 -2
  202. package/views/Empty.jsx +2 -1
  203. package/views/Empty.jsx.map +1 -0
  204. package/views/Fragment.d.ts +3 -9
  205. package/views/Fragment.jsx +2 -2
  206. package/views/Fragment.jsx.map +1 -0
  207. package/views/MainView.d.ts +3 -3
  208. package/views/MainView.jsx +2 -2
  209. package/views/MainView.jsx.map +1 -0
  210. package/views/PropsView.d.ts +3 -0
  211. package/views/PropsView.jsx +21 -0
  212. package/views/PropsView.jsx.map +1 -0
  213. package/views/Region.d.ts +4 -17
  214. package/views/Region.jsx +2 -2
  215. package/views/Region.jsx.map +1 -0
  216. package/views/RichTextView.d.ts +3 -13
  217. package/views/RichTextView.jsx +6 -3
  218. package/views/RichTextView.jsx.map +1 -0
  219. package/views/SingleComponent.d.ts +3 -3
  220. package/views/SingleComponent.jsx +1 -2
  221. package/views/SingleComponent.jsx.map +1 -0
  222. package/views/StaticContent.d.ts +2 -6
  223. package/views/StaticContent.jsx +1 -0
  224. package/views/StaticContent.jsx.map +1 -0
  225. package/views/Text.d.ts +5 -5
  226. package/views/Text.jsx +1 -1
  227. package/views/Text.jsx.map +1 -0
  228. package/views/getClientHydratedHtml.d.ts +2 -0
  229. package/views/getClientHydratedHtml.jsx +9 -0
  230. package/views/getClientHydratedHtml.jsx.map +1 -0
  231. package/views/macros/DefaultMacro.d.ts +1 -1
  232. package/views/macros/DefaultMacro.jsx +1 -0
  233. package/views/macros/DefaultMacro.jsx.map +1 -0
  234. package/views/macros/DisableMacro.d.ts +1 -1
  235. package/views/macros/DisableMacro.jsx +1 -0
  236. package/views/macros/DisableMacro.jsx.map +1 -0
  237. package/ComponentRegistry.d.ts +0 -64
  238. package/server/ClearableFileCache.d.ts +0 -31
  239. package/server/ClearableFileCache.js +0 -472
  240. package/server/cache.d.ts +0 -2
  241. package/server/cache.js +0 -129
  242. package/server/index.d.ts +0 -5
  243. package/server/index.js +0 -132
  244. package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ACnB,CAAC,CAAC,CAAC;IACP,CAAC,CAAA,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,WAAW,EAAE,CAAC;YACd,KAAK,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,wDAAwD;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 ADDED
@@ -0,0 +1,11 @@
1
+ import type { Dict } from '../types';
2
+ export declare class I18n {
3
+ private static locale;
4
+ private static dictionary;
5
+ static setLocale(locale: string): Promise<Dict>;
6
+ static localize(key: string, ...args: any[]): string;
7
+ static getLocale(): string;
8
+ static getDictionary(): Dict;
9
+ }
10
+ export declare const loadPhrases: (locale: string) => Promise<Dict>;
11
+ export declare const getPhrase: (locale: string, dict: Dict, key: string, ...args: any[]) => string;
package/i18n/i18n.js ADDED
@@ -0,0 +1,57 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export class I18n {
11
+ static setLocale(locale) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ this.locale = locale;
14
+ return loadPhrases(locale).then((phrases) => {
15
+ this.dictionary = phrases;
16
+ console.info(`Loaded server-side phrases for locale "${locale}"`);
17
+ return phrases;
18
+ });
19
+ });
20
+ }
21
+ static localize(key, ...args) {
22
+ return getPhrase(this.locale, this.dictionary, key, ...args);
23
+ }
24
+ static getLocale() {
25
+ return this.locale;
26
+ }
27
+ static getDictionary() {
28
+ return this.dictionary;
29
+ }
30
+ }
31
+ I18n.locale = '';
32
+ I18n.dictionary = {};
33
+ export const loadPhrases = (locale) => __awaiter(void 0, void 0, void 0, function* () {
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
+ export const getPhrase = (locale, dict, key, ...args) => {
42
+ const template = dict[key];
43
+ if (!template) {
44
+ console.warn(`Missing localization phrase for locale "${locale}": <${key}>`);
45
+ return `<${key}>`;
46
+ }
47
+ if (args.length) {
48
+ let index = -1;
49
+ return template.replace(/{(\d+)?}/g, (match, digit) => {
50
+ var _a;
51
+ index++;
52
+ return (_a = args[digit || index]) !== null && _a !== void 0 ? _a : match;
53
+ });
54
+ }
55
+ return template;
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,UAAU,GAAG,OAAO,CAAC;gBAC1B,O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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,5 +1,18 @@
1
- export * from './utils';
2
- export * from './guillotine/fetchContent';
3
- export * from './guillotine/getMetaData';
4
- export * from './ComponentRegistry';
5
- export * from './UrlProcessor';
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 { fetchContent } from './guillotine/fetchContent';
6
+ export { fetchContentPathsForAllLocales } from './guillotine/fetchContentPathsForAllLocales';
7
+ export { fetchContentPathsForLocale } from './guillotine/fetchContentPathsForLocale';
8
+ export { fetchFromApi } from './guillotine/fetchFromApi';
9
+ export { fetchGuillotine } from './guillotine/fetchGuillotine';
10
+ export { richTextQuery } from './guillotine/metadata/richTextQuery';
11
+ export { validateData } from './guillotine/validateData';
12
+ export { I18n } from './i18n/i18n';
13
+ export { getContentApiUrl } from './utils/getContentApiUrl';
14
+ export { getProjectLocaleConfig } from './utils/getProjectLocaleConfig';
15
+ export { getProjectLocaleConfigById } from './utils/getProjectLocaleConfigById';
16
+ export { getRequestLocaleInfo } from './utils/getRequestLocaleInfo';
17
+ export { sanitizeGraphqlName } from './utils/sanitizeGraphqlName';
18
+ export { UrlProcessor, getAsset, getUrl, } from './common/UrlProcessor';
package/index.js CHANGED
@@ -1,5 +1,18 @@
1
- export * from './utils';
2
- export * from './guillotine/fetchContent';
3
- export * from './guillotine/getMetaData';
4
- export * from './ComponentRegistry';
5
- export * from './UrlProcessor';
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 { fetchContent } from './guillotine/fetchContent';
5
+ export { fetchContentPathsForAllLocales } from './guillotine/fetchContentPathsForAllLocales';
6
+ export { fetchContentPathsForLocale } from './guillotine/fetchContentPathsForLocale';
7
+ export { fetchFromApi } from './guillotine/fetchFromApi';
8
+ export { fetchGuillotine } from './guillotine/fetchGuillotine';
9
+ export { richTextQuery } from './guillotine/metadata/richTextQuery';
10
+ export { validateData } from './guillotine/validateData';
11
+ export { I18n } from './i18n/i18n';
12
+ export { getContentApiUrl } from './utils/getContentApiUrl';
13
+ export { getProjectLocaleConfig } from './utils/getProjectLocaleConfig';
14
+ export { getProjectLocaleConfigById } from './utils/getProjectLocaleConfigById';
15
+ export { getRequestLocaleInfo } from './utils/getRequestLocaleInfo';
16
+ export { sanitizeGraphqlName } from './utils/sanitizeGraphqlName';
17
+ export { UrlProcessor, getAsset, getUrl, } from './common/UrlProcessor';
18
+ //# 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;AAE5B,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;AAC7D,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,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,34 +1,85 @@
1
1
  {
2
2
  "name": "@enonic/nextjs-adapter",
3
- "version": "2.0.0",
3
+ "version": "3.0.0-B2",
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 src/tsconfig.json && tsc --build server/tsconfig.json",
12
- "lint": "eslint --quiet server && eslint --quiet src",
13
- "lint:fix": "eslint --fix server && eslint --fix src"
36
+ "clean": "del-cli *.d.ts *.js.map baseMappings.* client.* 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",
42
+ "lint": "eslint --quiet 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
- "html-react-parser": "^4.2.2",
17
- "lru-cache": "^10.0.1",
18
- "next": "13.4.19",
51
+ "@formatjs/intl-localematcher": "^0.5.4",
52
+ "html-react-parser": "^5.1.1",
53
+ "negotiator": "^0.6.3",
54
+ "next": "^14.0.2",
19
55
  "react": "18.2.0",
20
56
  "react-dom": "18.2.0",
21
57
  "unescape": "^1.0.1"
22
58
  },
23
59
  "devDependencies": {
60
+ "@edge-runtime/jest-environment": "^2.3.7",
61
+ "@enonic-types/core": "^7.14.0-B2",
24
62
  "@enonic/eslint-config": "^1.1.0",
25
- "@types/node": "^20.6.0",
26
- "@types/react": "18.2.21",
27
- "@types/react-dom": "18.2.7",
28
- "@typescript-eslint/eslint-plugin": "^5.61.0",
29
- "@typescript-eslint/parser": "^5.62.0",
30
- "eslint": "^8.49.0",
63
+ "@testing-library/jest-dom": "^6.2.0",
64
+ "@testing-library/react": "^14.1.2",
65
+ "@types/negotiator": "^0.6.3",
66
+ "@types/node": "^20.11.10",
67
+ "@types/react": "^18.2.48",
68
+ "@types/react-dom": "^18.2.18",
69
+ "@typescript-eslint/eslint-plugin": "^6.20.0",
70
+ "@typescript-eslint/parser": "^6.19.1",
71
+ "concurrently": "^8.2.2",
72
+ "cpy-cli": "^5.0.0",
73
+ "del-cli": "^5.1.0",
74
+ "eslint": "^8.56.0",
31
75
  "eslint-plugin-react": "^7.33.2",
32
- "typescript": "^5.2.2"
33
- }
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.1",
81
+ "ts-node": "^10.9.2",
82
+ "typescript": "^5.3.3"
83
+ },
84
+ "types": "index.d.ts"
34
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"}
@@ -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":""}