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

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 (163) hide show
  1. package/LICENSE +201 -0
  2. package/baseMappings.js.map +1 -1
  3. package/client.js.map +1 -1
  4. package/common/ComponentRegistry.js.map +1 -1
  5. package/common/UrlProcessor.js.map +1 -1
  6. package/common/constants.js.map +1 -1
  7. package/common/env.js.map +1 -1
  8. package/guillotine/applyProcessors.js.map +1 -1
  9. package/guillotine/buildComponentTree.js.map +1 -1
  10. package/guillotine/buildErrorResponse.js.map +1 -1
  11. package/guillotine/buildPage.js.map +1 -1
  12. package/guillotine/collectComponentDescriptors.js.map +1 -1
  13. package/guillotine/combineMultipleQueries.js.map +1 -1
  14. package/guillotine/createMetaData.js.map +1 -1
  15. package/guillotine/fetchContent.js.map +1 -1
  16. package/guillotine/fetchContentData.js.map +1 -1
  17. package/guillotine/fetchContentPathsForAllLocales.js.map +1 -1
  18. package/guillotine/fetchContentPathsForLocale.js.map +1 -1
  19. package/guillotine/fetchFromApi.js.map +1 -1
  20. package/guillotine/fetchGuillotine.js.map +1 -1
  21. package/guillotine/fetchMetaData.js.map +1 -1
  22. package/guillotine/getCleanContentPathArrayOrThrow400.js.map +1 -1
  23. package/guillotine/getComponentConfig.js.map +1 -1
  24. package/guillotine/getContentAndComponentPaths.js.map +1 -1
  25. package/guillotine/getMetaData.js.map +1 -1
  26. package/guillotine/getParentRegion.js.map +1 -1
  27. package/guillotine/getQueryAndVariables.js.map +1 -1
  28. package/guillotine/metadata/configQuery.js.map +1 -1
  29. package/guillotine/metadata/richTextQuery.js.map +1 -1
  30. package/guillotine/parseComponentPath.js.map +1 -1
  31. package/guillotine/prefixLayoutPath.js.map +1 -1
  32. package/guillotine/processComponentConfig.js.map +1 -1
  33. package/guillotine/restrictComponentsToPath.js.map +1 -1
  34. package/guillotine/validateData.js.map +1 -1
  35. package/guillotine/validateNotFound.js.map +1 -1
  36. package/guillotine/validateShortcut.js.map +1 -1
  37. package/i18n/LocaleContext.jsx.map +1 -1
  38. package/i18n/i18n.js.map +1 -1
  39. package/index.js.map +1 -1
  40. package/package.json +3 -4
  41. package/query/Shortcut.js.map +1 -1
  42. package/server.js +6 -0
  43. package/server.js.map +1 -1
  44. package/src/baseMappings.ts +53 -0
  45. package/src/client.ts +2 -0
  46. package/src/common/ComponentRegistry.ts +162 -0
  47. package/src/common/UrlProcessor.ts +142 -0
  48. package/src/common/constants.ts +85 -0
  49. package/src/common/env.ts +39 -0
  50. package/src/guillotine/applyProcessors.ts +38 -0
  51. package/src/guillotine/buildComponentTree.ts +63 -0
  52. package/src/guillotine/buildErrorResponse.ts +39 -0
  53. package/src/guillotine/buildPage.ts +15 -0
  54. package/src/guillotine/collectComponentDescriptors.ts +63 -0
  55. package/src/guillotine/combineMultipleQueries.ts +75 -0
  56. package/src/guillotine/createMetaData.ts +73 -0
  57. package/src/guillotine/fetchContent.ts +250 -0
  58. package/src/guillotine/fetchContentData.ts +33 -0
  59. package/src/guillotine/fetchContentPathsForAllLocales.ts +21 -0
  60. package/src/guillotine/fetchContentPathsForLocale.ts +42 -0
  61. package/src/guillotine/fetchFromApi.ts +69 -0
  62. package/src/guillotine/fetchGuillotine.ts +61 -0
  63. package/src/guillotine/fetchMetaData.ts +32 -0
  64. package/src/guillotine/getCleanContentPathArrayOrThrow400.ts +22 -0
  65. package/src/guillotine/getComponentConfig.ts +7 -0
  66. package/src/guillotine/getContentAndComponentPaths.ts +11 -0
  67. package/src/guillotine/getMetaData.ts +73 -0
  68. package/src/guillotine/getParentRegion.ts +59 -0
  69. package/src/guillotine/getQueryAndVariables.ts +52 -0
  70. package/src/guillotine/metadata/configQuery.ts +46 -0
  71. package/src/guillotine/metadata/richTextQuery.ts +34 -0
  72. package/src/guillotine/parseComponentPath.ts +29 -0
  73. package/src/guillotine/prefixLayoutPath.ts +16 -0
  74. package/src/guillotine/processComponentConfig.ts +38 -0
  75. package/src/guillotine/restrictComponentsToPath.ts +45 -0
  76. package/src/guillotine/validateData.ts +11 -0
  77. package/src/guillotine/validateNotFound.ts +20 -0
  78. package/src/guillotine/validateShortcut.ts +37 -0
  79. package/src/i18n/LocaleContext.tsx +54 -0
  80. package/src/i18n/i18n.ts +54 -0
  81. package/src/index.ts +42 -0
  82. package/src/query/Shortcut.ts +14 -0
  83. package/src/server.ts +5 -0
  84. package/src/types/component.ts +147 -0
  85. package/src/types/componentProps.ts +142 -0
  86. package/src/types/guillotine.ts +426 -0
  87. package/src/types/i18n.ts +8 -0
  88. package/src/types/index.ts +58 -0
  89. package/src/types/next.ts +7 -0
  90. package/src/types/util.ts +5 -0
  91. package/src/utils/addLineNumbers.ts +3 -0
  92. package/src/utils/buildGuillotineRequestHeaders.ts +32 -0
  93. package/src/utils/commonChars.ts +16 -0
  94. package/src/utils/fixDoubleSlashes.ts +3 -0
  95. package/src/utils/getContentApiUrl.ts +20 -0
  96. package/src/utils/getProjectLocaleConfig.ts +24 -0
  97. package/src/utils/getProjectLocaleConfigById.ts +21 -0
  98. package/src/utils/getProjectLocaleConfigByLocale.ts +19 -0
  99. package/src/utils/getProjectLocaleConfigs.ts +36 -0
  100. package/src/utils/getProjectLocales.ts +6 -0
  101. package/src/utils/getRenderMode.ts +14 -0
  102. package/src/utils/getRequestLocaleInfo.ts +29 -0
  103. package/src/utils/getXpBaseUrl.ts +12 -0
  104. package/src/utils/indent.ts +4 -0
  105. package/src/utils/sanitizeGraphqlName.ts +11 -0
  106. package/src/views/BaseComponent.tsx +153 -0
  107. package/src/views/BaseContent.tsx +47 -0
  108. package/src/views/BaseLayout.tsx +33 -0
  109. package/src/views/BaseMacro.tsx +94 -0
  110. package/src/views/BasePage.tsx +42 -0
  111. package/src/views/BasePart.tsx +34 -0
  112. package/src/views/Empty.tsx +5 -0
  113. package/src/views/Fragment.tsx +41 -0
  114. package/src/views/MainView.tsx +22 -0
  115. package/src/views/PropsView.tsx +38 -0
  116. package/src/views/Region.tsx +76 -0
  117. package/src/views/RichTextView.tsx +75 -0
  118. package/src/views/SingleComponent.tsx +19 -0
  119. package/src/views/StaticContent.tsx +39 -0
  120. package/src/views/Text.tsx +19 -0
  121. package/src/views/getClientHydratedHtml.tsx +12 -0
  122. package/src/views/macros/DefaultMacro.tsx +9 -0
  123. package/src/views/macros/DisableMacro.tsx +8 -0
  124. package/types/component.js.map +1 -1
  125. package/types/componentProps.js.map +1 -1
  126. package/types/guillotine.js.map +1 -1
  127. package/types/i18n.js.map +1 -1
  128. package/types/index.js.map +1 -1
  129. package/types/next.js.map +1 -1
  130. package/types/util.js.map +1 -1
  131. package/utils/addLineNumbers.js.map +1 -1
  132. package/utils/buildGuillotineRequestHeaders.js.map +1 -1
  133. package/utils/commonChars.js.map +1 -1
  134. package/utils/fixDoubleSlashes.js.map +1 -1
  135. package/utils/getContentApiUrl.js.map +1 -1
  136. package/utils/getProjectLocaleConfig.js.map +1 -1
  137. package/utils/getProjectLocaleConfigById.js.map +1 -1
  138. package/utils/getProjectLocaleConfigByLocale.js.map +1 -1
  139. package/utils/getProjectLocaleConfigs.js.map +1 -1
  140. package/utils/getProjectLocales.js.map +1 -1
  141. package/utils/getRenderMode.js.map +1 -1
  142. package/utils/getRequestLocaleInfo.js.map +1 -1
  143. package/utils/getXpBaseUrl.js.map +1 -1
  144. package/utils/indent.js.map +1 -1
  145. package/utils/sanitizeGraphqlName.js.map +1 -1
  146. package/views/BaseComponent.jsx.map +1 -1
  147. package/views/BaseContent.jsx.map +1 -1
  148. package/views/BaseLayout.jsx.map +1 -1
  149. package/views/BaseMacro.jsx.map +1 -1
  150. package/views/BasePage.jsx.map +1 -1
  151. package/views/BasePart.jsx.map +1 -1
  152. package/views/Empty.jsx.map +1 -1
  153. package/views/Fragment.jsx.map +1 -1
  154. package/views/MainView.jsx.map +1 -1
  155. package/views/PropsView.jsx.map +1 -1
  156. package/views/Region.jsx.map +1 -1
  157. package/views/RichTextView.jsx.map +1 -1
  158. package/views/SingleComponent.jsx.map +1 -1
  159. package/views/StaticContent.jsx.map +1 -1
  160. package/views/Text.jsx.map +1 -1
  161. package/views/getClientHydratedHtml.jsx.map +1 -1
  162. package/views/macros/DefaultMacro.jsx.map +1 -1
  163. package/views/macros/DisableMacro.jsx.map +1 -1
package/i18n/i18n.js.map CHANGED
@@ -1 +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,OAAO,CAAC,IAAI,CAAC,0CAA0C,MAAM,GAAG,CAAC,CAAC;gBAClE,OAAO,OAAO,CAAC;YACnB,CAAC,CAAC,CAAC;QACP,CAAC;KAAA;IAEM,MAAM,CAAC,QAAQ,CAAC,GAAW,EAAE,GAAG,IAAW;QAC9C,OAAO,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACjE,CAAC;IAEM,MAAM,CAAC,SAAS;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAEM,MAAM,CAAC,aAAa;QACvB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;;AAtBc,WAAM,GAAG,EAAE,CAAC;AACZ,eAAU,GAAS,EAAE,CAAC;AAwBzC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAO,MAAc,EAAiB,EAAE;IAC/D,OAAO,MAAM,CAAC,YAAY,MAAM,OAAO,CAAC;SACnC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC;SAChC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,OAAO,CAAC,KAAK,CAAC,sCAAsC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC;QAClE,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACX,CAAC,CAAA,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAc,EAAE,IAAU,EAAE,GAAW,EAAE,GAAG,IAAW,EAAE,EAAE;IACjF,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,2CAA2C,MAAM,OAAO,GAAG,GAAG,CAAC,CAAC;QAC7E,OAAO,IAAI,GAAG,GAAG,CAAC;IACtB,CAAC;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"}
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,OAAO,CAAC,IAAI,CAAC,0CAA0C,MAAM,GAAG,CAAC,CAAC;gBAClE,OAAO,OAAO,CAAC;YACnB,CAAC,CAAC,CAAC;QACP,CAAC;KAAA;IAEM,MAAM,CAAC,QAAQ,CAAC,GAAW,EAAE,GAAG,IAAW;QAC9C,OAAO,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACjE,CAAC;IAEM,MAAM,CAAC,SAAS;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAEM,MAAM,CAAC,aAAa;QACvB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;;AAtBc,WAAM,GAAG,EAAE,CAAC;AACZ,eAAU,GAAS,EAAE,CAAC;AAwBzC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAO,MAAc,EAAiB,EAAE;IAC/D,OAAO,MAAM,CAAC,YAAY,MAAM,OAAO,CAAC;SACnC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC;SAChC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,OAAO,CAAC,KAAK,CAAC,sCAAsC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC;QAClE,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACX,CAAC,CAAA,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAc,EAAE,IAAU,EAAE,GAAW,EAAE,GAAG,IAAW,EAAE,EAAE;IACjF,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,2CAA2C,MAAM,OAAO,GAAG,GAAG,CAAC,CAAC;QAC7E,OAAO,IAAI,GAAG,GAAG,CAAC;IACtB,CAAC;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.js.map CHANGED
@@ -1 +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"}
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@enonic/nextjs-adapter",
3
- "version": "3.0.0-B3",
3
+ "version": "3.0.0-B4",
4
4
  "license": "Apache-2.0",
5
5
  "main": "index.js",
6
6
  "author": "Pavel Milkevich <pmi@enonic.com>",
@@ -12,6 +12,7 @@
12
12
  "*.map",
13
13
  "baseMappings*",
14
14
  "client.js",
15
+ "server.js",
15
16
  "common",
16
17
  "guillotine",
17
18
  "index*",
@@ -35,14 +36,12 @@
35
36
  "scripts": {
36
37
  "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
38
  "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
39
  "check:types": "tsc --noEmit",
41
40
  "madge": "madge -i docs/madge.png -x '(constants|env)\\.ts' src/index.ts",
42
41
  "lint": "eslint --quiet src",
43
42
  "lint:fix": "eslint --fix src",
44
- "prebuild:prod": "npm run clean",
45
43
  "prebuild": "npm run clean",
44
+ "prepack": "concurrently -c auto -g --timings npm:test npm:lint npm:build",
46
45
  "premadge": "mkdirp docs",
47
46
  "pretest": "del-cli coverage",
48
47
  "test": "jest --no-cache --coverage"
@@ -1 +1 @@
1
- {"version":3,"file":"Shortcut.js","sourceRoot":"","sources":["../../src/query/Shortcut.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;IAa5B,CAAC"}
1
+ {"version":3,"file":"Shortcut.js","sourceRoot":"","sources":["../src/query/Shortcut.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;IAa5B,CAAC"}
package/server.js ADDED
@@ -0,0 +1,6 @@
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';
6
+ //# sourceMappingURL=server.js.map
package/server.js.map CHANGED
@@ -1 +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"}
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,53 @@
1
+ import {ComponentRegistry} from './common/ComponentRegistry';
2
+ import {FRAGMENT_CONTENTTYPE_NAME, XP_COMPONENT_TYPE} from './common/constants';
3
+ import FragmentView from './views/Fragment';
4
+ import BasePage from './views/BasePage';
5
+ import BasePart from './views/BasePart';
6
+ import BaseLayout from './views/BaseLayout';
7
+ import TextView from './views/Text';
8
+ import DefaultMacro from './views/macros/DefaultMacro';
9
+ import DisableMacro from './views/macros/DisableMacro';
10
+ import {getShortcutQuery} from './query/Shortcut';
11
+
12
+
13
+ // Base Content Types
14
+
15
+ ComponentRegistry.addContentType(FRAGMENT_CONTENTTYPE_NAME, {
16
+ view: FragmentView,
17
+ });
18
+
19
+ ComponentRegistry.addContentType('base:shortcut', {
20
+ query: getShortcutQuery,
21
+ });
22
+
23
+ // Base Components
24
+
25
+ ComponentRegistry.addComponent(XP_COMPONENT_TYPE.PAGE, {
26
+ view: BasePage,
27
+ });
28
+
29
+ ComponentRegistry.addComponent(XP_COMPONENT_TYPE.PART, {
30
+ view: BasePart,
31
+ });
32
+
33
+ ComponentRegistry.addComponent(XP_COMPONENT_TYPE.LAYOUT, {
34
+ view: BaseLayout,
35
+ });
36
+
37
+ ComponentRegistry.addComponent(XP_COMPONENT_TYPE.FRAGMENT, {
38
+ view: FragmentView,
39
+ });
40
+
41
+ ComponentRegistry.addComponent(XP_COMPONENT_TYPE.TEXT, {
42
+ view: TextView,
43
+ });
44
+
45
+ // Macro mappings
46
+ ComponentRegistry.addMacro('system:embed', {
47
+ view: DefaultMacro,
48
+ configQuery: '{body}',
49
+ });
50
+ ComponentRegistry.addMacro('system:disable', {
51
+ view: DisableMacro,
52
+ configQuery: '{body}',
53
+ });
package/src/client.ts ADDED
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ export {LocaleContextProvider, useLocaleContext} from './i18n/LocaleContext';
@@ -0,0 +1,162 @@
1
+ import type {
2
+ ComponentDefinition,
3
+ ComponentDefinitionParams,
4
+ ComponentDictionary,
5
+ PageComponent,
6
+ SelectedQueryMaybeVariablesFunc,
7
+ SelectorName,
8
+ } from '../types';
9
+
10
+
11
+ import {
12
+ CATCH_ALL,
13
+ XP_COMPONENT_TYPE,
14
+ } from './constants';
15
+
16
+
17
+ function toSelectorName(type: XP_COMPONENT_TYPE): SelectorName | undefined {
18
+ switch (type) {
19
+ case XP_COMPONENT_TYPE.PAGE:
20
+ return 'page';
21
+ case XP_COMPONENT_TYPE.LAYOUT:
22
+ return 'layout';
23
+ case XP_COMPONENT_TYPE.PART:
24
+ return 'part';
25
+ }
26
+ }
27
+
28
+
29
+ export class ComponentRegistry {
30
+
31
+ private static contentTypes: ComponentDictionary = {};
32
+ private static pages: ComponentDictionary = {};
33
+ private static components: ComponentDictionary = {};
34
+ private static parts: ComponentDictionary = {};
35
+ private static layouts: ComponentDictionary = {};
36
+ private static macros: ComponentDictionary = {};
37
+ private static commonQuery: SelectedQueryMaybeVariablesFunc;
38
+
39
+ public static addComponent(name: string, obj: ComponentDefinitionParams): void {
40
+ return ComponentRegistry.addType('component', name, obj);
41
+ }
42
+
43
+ public static addContentType(name: string, obj: ComponentDefinitionParams): void {
44
+ return ComponentRegistry.addType('contentType', name, obj);
45
+ }
46
+
47
+ public static addMacro(name: string, obj: ComponentDefinitionParams): void {
48
+ return ComponentRegistry.addType('macro', name, obj);
49
+ }
50
+
51
+ public static addLayout(name: string, obj: ComponentDefinitionParams): void {
52
+ return ComponentRegistry.addType('layout', name, obj);
53
+ }
54
+
55
+ public static addPage(name: string, obj: ComponentDefinitionParams): void {
56
+ return ComponentRegistry.addType('page', name, obj);
57
+ }
58
+
59
+ public static addPart(name: string, obj: ComponentDefinitionParams): void {
60
+ return ComponentRegistry.addType('part', name, obj);
61
+ }
62
+
63
+ private static addType(selectorName: SelectorName, name: string, obj: ComponentDefinitionParams): void {
64
+ const selector = ComponentRegistry.getSelector(selectorName);
65
+ const curr = selector[name];
66
+ selector[name] = curr ? Object.assign(curr, obj) : obj;
67
+ }
68
+
69
+ private static getSelector(name: SelectorName): ComponentDictionary {
70
+ switch (name) {
71
+ case 'contentType':
72
+ return this.contentTypes;
73
+ case 'page':
74
+ return this.pages;
75
+ case 'component':
76
+ return this.components;
77
+ case 'layout':
78
+ return this.layouts;
79
+ case 'part':
80
+ return this.parts;
81
+ case 'macro':
82
+ return this.macros;
83
+ }
84
+ }
85
+
86
+ private static getType(selectorName: SelectorName, typeName: string, useCatchAll = true): ComponentDefinition | undefined {
87
+ const selector = ComponentRegistry.getSelector(selectorName);
88
+ let type: ComponentDefinition|undefined = selector[typeName];
89
+ if (type) {
90
+ type.catchAll = typeName === CATCH_ALL;
91
+ } else if (!type && useCatchAll) {
92
+ type = selector[CATCH_ALL];
93
+ if (type) {
94
+ type.catchAll = true;
95
+ }
96
+ }
97
+ return type;
98
+ }
99
+
100
+ public static getByComponent(component: PageComponent): ComponentDefinition | undefined {
101
+ const selName = toSelectorName(component.type);
102
+ const cmpData = component[component.type];
103
+ const desc = cmpData && 'descriptor' in cmpData ? cmpData.descriptor : component.path;
104
+ return selName && desc ? this.getType(selName, desc) : undefined;
105
+ }
106
+
107
+ public static setCommonQuery(query: SelectedQueryMaybeVariablesFunc): void {
108
+ this.commonQuery = query;
109
+ }
110
+
111
+ public static getCommonQuery(): SelectedQueryMaybeVariablesFunc {
112
+ return this.commonQuery;
113
+ }
114
+
115
+ public static getMacro(name: string): ComponentDefinition | undefined {
116
+ return ComponentRegistry.getType('macro', name);
117
+ }
118
+
119
+ public static getMacros(): [string, ComponentDefinition][] {
120
+ return Object.entries(this.macros);
121
+ }
122
+
123
+ public static getParts(): [string, ComponentDefinition][] {
124
+ return Object.entries(this.parts);
125
+ }
126
+
127
+ public static getLayouts(): [string, ComponentDefinition][] {
128
+ return Object.entries(this.layouts);
129
+ }
130
+
131
+ public static getPages(): [string, ComponentDefinition][] {
132
+ return Object.entries(this.pages);
133
+ }
134
+
135
+ public static getContentTypes(): [string, ComponentDefinition][] {
136
+ return Object.entries(this.contentTypes);
137
+ }
138
+
139
+ public static getComponents(): [string, ComponentDefinition][] {
140
+ return Object.entries(this.components);
141
+ }
142
+
143
+ public static getContentType(name: string): ComponentDefinition | undefined {
144
+ return ComponentRegistry.getType('contentType', name);
145
+ }
146
+
147
+ public static getPage(name: string): ComponentDefinition | undefined {
148
+ return ComponentRegistry.getType('page', name);
149
+ }
150
+
151
+ public static getPart(name: string): ComponentDefinition | undefined {
152
+ return ComponentRegistry.getType('part', name);
153
+ }
154
+
155
+ public static getLayout(name: string): ComponentDefinition | undefined {
156
+ return ComponentRegistry.getType('layout', name);
157
+ }
158
+
159
+ public static getComponent(name: string): ComponentDefinition | undefined {
160
+ return ComponentRegistry.getType('component', name);
161
+ }
162
+ }
@@ -0,0 +1,142 @@
1
+ import type {ImageData, LinkData, MetaData} from '../types';
2
+
3
+
4
+ import {RENDER_MODE} from './constants';
5
+ import {fixDoubleSlashes} from '../utils/fixDoubleSlashes';
6
+ import {getProjectLocaleConfigById} from '../utils/getProjectLocaleConfigById';
7
+ import {commonChars} from '../utils/commonChars';
8
+ import {addBasePath} from 'next/dist/client/add-base-path';
9
+
10
+
11
+ export class UrlProcessor {
12
+
13
+ public static IMG_TAG = 'img';
14
+ public static LINK_TAG = 'a';
15
+ public static MACRO_TAG = 'editor-macro';
16
+
17
+ public static IMG_ATTR = 'data-image-ref';
18
+ public static LINK_ATTR = 'data-link-ref';
19
+ public static MACRO_ATTR = 'data-macro-ref';
20
+
21
+ private static IMG_ATMT_REGEXP = /_\/image\/|_\/attachment\//;
22
+ private static endSlashPattern = /\/+$/;
23
+ private static startSlashPattern = /^\/+/;
24
+ private static localhostPattern = /localhost/;
25
+
26
+ private static siteKey: string;
27
+
28
+ public static process(url: string, meta: MetaData, serverSide = false, isResource = false): string {
29
+ if (this.startsWithHash(url) || !meta || (this.isAttachmentUrl(url)) && meta.renderMode === RENDER_MODE.NEXT) {
30
+ // do not process if:
31
+ // - url starts with #
32
+ // - meta is absent
33
+ // - attachment urls in NEXT mode
34
+ return url;
35
+ }
36
+
37
+ let normalUrl: string;
38
+ if (this.isRelative(url)) {
39
+ normalUrl = url;
40
+ } else {
41
+ // url is absolute, try to make it relative by striping apiUrl
42
+ // NB: will fail if content api is not on the same domain as enonic xp
43
+ const apiUrl = this.getApiUrl(meta);
44
+ normalUrl = this.stripApiUrl(url, apiUrl);
45
+ }
46
+
47
+ const baseUrl = meta?.baseUrl && meta?.baseUrl !== '/' ? meta.baseUrl : '';
48
+
49
+ let result: string;
50
+ if (meta.renderMode === RENDER_MODE.NEXT) {
51
+ // only add basePath and locale in next mode
52
+ result = `/${normalUrl}`;
53
+ if (!isResource && meta.locale !== meta.defaultLocale) {
54
+ // append locale if it's not the default one
55
+ // to avoid additional middleware redirection
56
+ // NB: don't add locale to resource urls
57
+ result = `/${meta.locale}${result}`;
58
+ }
59
+ if (!serverSide) {
60
+ // no need for baseurl and basepath on server
61
+ result = addBasePath(`${baseUrl}${result}`);
62
+ }
63
+ } else {
64
+ result = `${baseUrl}/${normalUrl}`;
65
+ }
66
+
67
+ return fixDoubleSlashes(result);
68
+ }
69
+
70
+ public static setSiteKey(key: string): void {
71
+ this.siteKey = key;
72
+ }
73
+
74
+ public static isMediaLink(ref: string, linkData: LinkData[]): boolean {
75
+ // Assuming linkData can't contain more than one entry with the same ref
76
+ return Array.isArray(linkData) && !!linkData.find(data => data?.ref === ref)?.media;
77
+ }
78
+
79
+ public static isContentImage(ref: string, imageData: ImageData[]): boolean {
80
+ // Assuming imageData can't contain more than one entry with the same ref
81
+ return Array.isArray(imageData) && !!imageData.find(data => data.ref === ref)?.image;
82
+ }
83
+
84
+ public static processSrcSet(srcset: string, meta: MetaData): string {
85
+ return srcset.split(/, */g).map(src => {
86
+ const srcParts = src.trim().split(' ');
87
+ switch (srcParts.length) {
88
+ case 1: // src only
89
+ return this.process(src, meta);
90
+ case 2: // width descriptor
91
+ return `${this.process(srcParts[0], meta)} ${srcParts[1]}`;
92
+ case 3: // pixel density descriptor
93
+ return `${this.process(srcParts[0], meta)} ${srcParts[1]} ${srcParts[2]}`;
94
+ default:
95
+ console.warn('Can not process image srcset: ' + src);
96
+ return src;
97
+ }
98
+ }).join(', ');
99
+ }
100
+
101
+ private static stripApiUrl(url: string, apiUrl: string): string {
102
+ // normalise localhost-127.0.0.1 if present in urls
103
+ const normalUrl = url.replace(this.localhostPattern, '127.0.0.1');
104
+ const normalApiUrl = apiUrl.replace(this.localhostPattern, '127.0.0.1');
105
+ const common = commonChars(normalUrl, normalApiUrl);
106
+ const remaining = common.length > 0 ? normalUrl.substring(common.length) : normalUrl;
107
+ return (remaining.length > 0 && remaining.charAt(0) === '/') ? remaining.substring(1) : remaining;
108
+ }
109
+
110
+ private static isAttachmentUrl(url: string): boolean {
111
+ return this.IMG_ATMT_REGEXP.test(url);
112
+ }
113
+
114
+ private static startsWithHash(url: string): boolean {
115
+ return url?.charAt(0) == '#';
116
+ }
117
+
118
+ private static isRelative(url: string): boolean {
119
+ return !/^(?:ht|f)tps?:\/\/[^ :\r\n\t]+/.test(url);
120
+ }
121
+
122
+ private static getApiUrl(meta: MetaData) {
123
+ let combinedUrl = meta.apiUrl?.replace(this.endSlashPattern, '') || '';
124
+ if (this.siteKey?.length) {
125
+ combinedUrl += '/' + this.siteKey.replace(this.startSlashPattern, '');
126
+ }
127
+ return combinedUrl;
128
+ }
129
+ }
130
+
131
+ // Actual site is going to be set in fetchContent method, but set a default fallback here too
132
+ const defaultConfig = getProjectLocaleConfigById();
133
+ UrlProcessor.setSiteKey(defaultConfig.site);
134
+
135
+ export function getUrl(url: string, meta: MetaData): string {
136
+ return UrlProcessor.process(url, meta, false, false);
137
+ }
138
+
139
+ export function getAsset(url: string, meta: MetaData): string {
140
+ return UrlProcessor.process(url, meta, false, true);
141
+ }
142
+
@@ -0,0 +1,85 @@
1
+ export const CATCH_ALL = '*';
2
+
3
+ export enum ENV_VARS {
4
+ PROJECTS = 'ENONIC_PROJECTS',
5
+ API_URL = 'ENONIC_API',
6
+ APP_NAME = 'ENONIC_APP_NAME',
7
+ }
8
+
9
+ export const FRAGMENT_CONTENTTYPE_NAME = 'portal:fragment';
10
+ export const FRAGMENT_DEFAULT_REGION_NAME = 'fragment';
11
+
12
+ /** excluded contents:
13
+ * - folder
14
+ * - shortcuts (redirect can't be used in prerender)
15
+ * - media
16
+ * - paths with '/_' in them
17
+ */
18
+ export const GET_STATIC_PATHS_QUERY = `query ($count: Int) {
19
+ guillotine {
20
+ queryDsl(
21
+ first: $count,
22
+ sort: {
23
+ field: "modifiedTime",
24
+ direction: DESC
25
+ }
26
+ query: {boolean: {mustNot: [
27
+ {in: {field: "type", stringValues: ["base:folder", "base:shortcut"]}}
28
+ {like: {field: "type", value: "media:*"}}
29
+ {like: {field: "_path", value: "*/_*"}}
30
+ ]}}
31
+ ) {
32
+ _name
33
+ _path
34
+ site {_name}
35
+ }
36
+ }
37
+ }`;
38
+
39
+ // Seems like NodeJS.fetch lowercases all headers, so we need to lowercase the
40
+ // header names here.
41
+ export enum GUILLOTINE_REQUEST_HEADERS {
42
+ COOKIE = 'Cookie',
43
+ LOCALE = 'locale',
44
+ LOCALES = 'locales',
45
+ DEFAULT_LOCALE = 'default-locale',
46
+ }
47
+
48
+ export const JSESSIONID_HEADER = 'jsessionid';
49
+
50
+ export const PAGE_TEMPLATE_CONTENTTYPE_NAME = 'portal:page-template';
51
+ export const PAGE_TEMPLATE_FOLDER = 'portal:template-folder';
52
+ export const PORTAL_COMPONENT_ATTRIBUTE = 'data-portal-component-type';
53
+ export const PORTAL_REGION_ATTRIBUTE = 'data-portal-region';
54
+ export const PROJECT_ID_HEADER = 'content-studio-project';
55
+
56
+ export enum RENDER_MODE {
57
+ INLINE = 'inline',
58
+ EDIT = 'edit',
59
+ PREVIEW = 'preview',
60
+ LIVE = 'live',
61
+ ADMIN = 'admin',
62
+ NEXT = 'next' // Fallback: not using XP proxy but rendering directly with next.js
63
+ }
64
+
65
+ export const RENDER_MODE_HEADER = 'content-studio-mode';
66
+
67
+ export const SITE_CONTENTTYPE_NAME = 'portal:site';
68
+
69
+ // URI parameter marking that a request is for a preview for CS. MUST MATCH THE VALUE OF 'FROM_XP_PARAM' on XP side.
70
+ export const XP_BASE_URL_HEADER = 'xpbaseurl';
71
+
72
+ // TODO: Use these instead of hardcoded strings everywhere
73
+ export enum XP_COMPONENT_TYPE {
74
+ PART = 'part',
75
+ LAYOUT = 'layout',
76
+ TEXT = 'text',
77
+ FRAGMENT = 'fragment',
78
+ PAGE = 'page',
79
+ }
80
+
81
+ export enum XP_REQUEST_TYPE {
82
+ COMPONENT = 'component',
83
+ TYPE = 'type',
84
+ PAGE = 'page',
85
+ }
@@ -0,0 +1,39 @@
1
+ import {ENV_VARS} from './constants';
2
+
3
+ const isServer = typeof window === 'undefined';
4
+
5
+ // IMPORTANT:
6
+ // NEXT_PUBLIC_ vars should be explicitly referenced to be made available on the client side (substituted with constants) !!!
7
+ /** URL to the guillotine API */
8
+ export const API_URL = isServer ? process.env[ENV_VARS.API_URL] : process.env['NEXT_PUBLIC_ENONIC_API'];
9
+
10
+ /** Optional utility value - defining in one place the name of the target app (the app that defines the content types, the app name is therefore part of the content type strings used both in typeselector and in query introspections) */
11
+ export const APP_NAME = isServer ? process.env[ENV_VARS.APP_NAME] : process.env['NEXT_PUBLIC_ENONIC_APP_NAME'];
12
+
13
+ /** Optional utility value - derived from APP_NAME, only with underscores instead of dots */
14
+ export const APP_NAME_UNDERSCORED = (APP_NAME || '').replace(/\./g, '_');
15
+
16
+ /** Optional utility value - derived from APP_NAME, only with dashes instead of dots */
17
+ export const APP_NAME_DASHED = (APP_NAME || '').replace(/\./g, '-');
18
+
19
+ const mode = isServer ? process.env.MODE : process.env.NEXT_PUBLIC_MODE;
20
+
21
+ export const IS_DEV_MODE = (mode === 'development');
22
+
23
+ /** Locales and Enonic XP projects correspondence list */
24
+ export const PROJECTS = isServer ? process.env[ENV_VARS.PROJECTS] : process.env['NEXT_PUBLIC_ENONIC_PROJECTS'];
25
+
26
+ const requiredConstants = {
27
+ [ENV_VARS.APP_NAME]: APP_NAME,
28
+ [ENV_VARS.API_URL]: API_URL,
29
+ [ENV_VARS.PROJECTS]: PROJECTS,
30
+ };
31
+
32
+ // Verify required values on server-side only
33
+ Object.keys(requiredConstants).forEach((key: string) => {
34
+ const val = requiredConstants[key];
35
+ if (!val) {
36
+ throw new Error(`Environment variable '${isServer ? '' : 'NEXT_PUBLIC_'}${key}' is missing (from .env?)`);
37
+ }
38
+ });
39
+
@@ -0,0 +1,38 @@
1
+ import type {
2
+ ComponentDescriptor,
3
+ ContentResult,
4
+ Context,
5
+ } from '../types';
6
+
7
+
8
+ import {getComponentConfig} from './getComponentConfig';
9
+
10
+
11
+ const NO_PROPS_PROCESSOR = async (props: any) => await props ?? {};
12
+
13
+
14
+ export async function applyProcessors(
15
+ componentDescriptors: ComponentDescriptor[],
16
+ contentResults: ContentResult,
17
+ context: Context,
18
+ ): Promise < PromiseSettledResult < any > [] > {
19
+
20
+ let dataCounter = 0;
21
+ const processorPromises = componentDescriptors.map(async (desc: ComponentDescriptor) => {
22
+ // we're iterating component descriptors here
23
+ // some of them might not have provided graphql requests
24
+ // but we still need to run props processor for them
25
+ // in case they want to fetch their data from elsewhere
26
+ const propsProcessor = desc.type?.processor || NO_PROPS_PROCESSOR;
27
+ let data;
28
+ if (desc.queryAndVariables) {
29
+ // if there is a query then there must be a result for it
30
+ data = contentResults.contents[dataCounter++];
31
+ }
32
+
33
+ const config = getComponentConfig(desc.component);
34
+ return await propsProcessor(data, context, config);
35
+ });
36
+
37
+ return Promise.allSettled(processorPromises);
38
+ }
@@ -0,0 +1,63 @@
1
+ import type {
2
+ PageComponent,
3
+ RegionTree,
4
+ } from '../types';
5
+
6
+
7
+ import {
8
+ FRAGMENT_CONTENTTYPE_NAME,
9
+ XP_COMPONENT_TYPE,
10
+ } from '../common/constants';
11
+ import {parseComponentPath} from './parseComponentPath';
12
+ import {getParentRegion} from './getParentRegion';
13
+
14
+
15
+ export function buildComponentTree(
16
+ comps: PageComponent[],
17
+ rootComp: PageComponent,
18
+ contentType?: string,
19
+ ): PageComponent {
20
+ const rootTree: RegionTree = {};
21
+ const isFragmentType = contentType === FRAGMENT_CONTENTTYPE_NAME;
22
+
23
+ if (isFragmentType) {
24
+ rootComp.regions = rootTree;
25
+ }
26
+
27
+ (comps || []).forEach(cmp => {
28
+ const cmpPath = parseComponentPath(contentType, cmp.path);
29
+
30
+ if (cmp.path === '/') {
31
+ if (cmp.type === XP_COMPONENT_TYPE.PAGE && rootComp.type === XP_COMPONENT_TYPE.PAGE) {
32
+ // add page values to page object
33
+ rootComp = Object.assign(rootComp, cmp);
34
+ rootComp.page.regions = rootTree;
35
+ return;
36
+ } else if (cmp.type === XP_COMPONENT_TYPE.LAYOUT && rootComp.type === XP_COMPONENT_TYPE.FRAGMENT) {
37
+ // when rendering fragment as part of the page with layout at root path
38
+ // remove other children from list as they will be included in layout
39
+ rootComp.fragment.fragment.components = [cmp];
40
+ cmp.regions = rootTree;
41
+ }
42
+ }
43
+
44
+ if (cmp.type === XP_COMPONENT_TYPE.FRAGMENT) {
45
+ // build component subtree for fragment
46
+ cmp = buildComponentTree(cmp.fragment?.fragment?.components, cmp, contentType);
47
+ }
48
+
49
+ const region = getParentRegion(rootTree, contentType, cmpPath, comps, true);
50
+
51
+ if (region) {
52
+ // getting the index of component from string like '/main/0/left/11'
53
+ const cmpIndex = cmpPath[cmpPath.length - 1]?.index;
54
+ if (cmpIndex >= 0) {
55
+ region.components.splice(cmpIndex, 0, cmp);
56
+ } else {
57
+ throw Error(`Could not find [${cmp.type}] component index at ${JSON.stringify(cmpPath, null, 2)}, rendering not possible.`);
58
+ }
59
+ }
60
+ });
61
+
62
+ return rootComp;
63
+ }