@jahia/javascript-modules-library 0.3.0 → 0.5.1

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 (112) hide show
  1. package/README.md +11 -10
  2. package/bin/jahia-deploy.mjs +27 -0
  3. package/dist/core/server/components/AbsoluteArea.d.ts +39 -0
  4. package/dist/core/server/components/AddContentButtons.d.ts +47 -0
  5. package/dist/core/server/components/AddResources.d.ts +63 -0
  6. package/dist/core/server/components/Area.d.ts +37 -0
  7. package/dist/core/server/components/render/HydrateInBrowser.d.ts +22 -0
  8. package/dist/core/server/components/render/Render.d.ts +31 -0
  9. package/dist/core/server/components/render/RenderInBrowser.d.ts +21 -0
  10. package/dist/core/server/components/render/internal/InBrowser.d.ts +6 -0
  11. package/dist/core/server/framework/defineJahiaComponent.d.ts +9 -0
  12. package/dist/core/server/framework/jahiaComponent.d.ts +28 -0
  13. package/dist/core/server/framework/register.d.ts +11 -0
  14. package/dist/core/server/hooks/useGQLQuery.d.ts +17 -0
  15. package/dist/core/server/hooks/useJCRQuery.d.ts +10 -0
  16. package/dist/core/server/hooks/useServerContext.d.ts +34 -0
  17. package/dist/core/server/hooks/useUrlBuilder.d.ts +52 -0
  18. package/dist/core/server/utils/jcr/getChildNodes.d.ts +14 -0
  19. package/dist/core/server/utils/jcr/getNodeFromPathOrId.d.ts +14 -0
  20. package/dist/core/server/utils/jcr/getNodeProps.d.ts +9 -0
  21. package/dist/core/server/utils/jcr/getNodesByJCRQuery.d.ts +14 -0
  22. package/dist/core/server/utils/urlBuilder/urlBuilder.d.ts +25 -0
  23. package/dist/globals.d.ts +47 -0
  24. package/dist/index.d.ts +38 -0
  25. package/dist/index.js +5 -0
  26. package/dist/nav/server/navBuilder/navBuilder.d.ts +29 -0
  27. package/{types → dist}/org.jahia.modules.javascript.modules.engine.js.server.d.ts +1 -2
  28. package/dist/package.tgz +0 -0
  29. package/package.json +36 -57
  30. package/core/index.js +0 -1
  31. package/core/server/components/AbsoluteArea.js +0 -1
  32. package/core/server/components/AddContentButtons.js +0 -1
  33. package/core/server/components/AddResources.js +0 -1
  34. package/core/server/components/Area.js +0 -1
  35. package/core/server/components/index.js +0 -1
  36. package/core/server/components/render/HydrateInBrowser.js +0 -1
  37. package/core/server/components/render/Render.js +0 -1
  38. package/core/server/components/render/RenderInBrowser.js +0 -1
  39. package/core/server/components/render/index.js +0 -1
  40. package/core/server/components/render/internal/InBrowser.js +0 -1
  41. package/core/server/framework/defineJahiaComponent.js +0 -1
  42. package/core/server/framework/index.js +0 -1
  43. package/core/server/framework/register.js +0 -1
  44. package/core/server/hooks/index.js +0 -1
  45. package/core/server/hooks/useGQLQuery.js +0 -1
  46. package/core/server/hooks/useJCRQuery.js +0 -1
  47. package/core/server/hooks/useServerContext.js +0 -1
  48. package/core/server/hooks/useUrlBuilder.js +0 -1
  49. package/core/server/index.js +0 -1
  50. package/core/server/utils/index.js +0 -1
  51. package/core/server/utils/jcr/getChildNodes.js +0 -1
  52. package/core/server/utils/jcr/getNodeFromPathOrId.js +0 -1
  53. package/core/server/utils/jcr/getNodeProps.js +0 -1
  54. package/core/server/utils/jcr/getNodesByJCRQuery.js +0 -1
  55. package/core/server/utils/jcr/index.js +0 -1
  56. package/core/server/utils/urlBuilder/index.js +0 -1
  57. package/core/server/utils/urlBuilder/urlBuilder.js +0 -1
  58. package/index.js +0 -1
  59. package/nav/index.js +0 -1
  60. package/nav/server/index.js +0 -1
  61. package/nav/server/navBuilder/index.js +0 -1
  62. package/nav/server/navBuilder/navBuilder.js +0 -24
  63. package/types/@jahia/javascript-modules-library-private.d.ts +0 -60
  64. package/types/core/index.d.ts +0 -1
  65. package/types/core/server/components/AbsoluteArea.d.ts +0 -29
  66. package/types/core/server/components/AddContentButtons.d.ts +0 -13
  67. package/types/core/server/components/AddResources.d.ts +0 -31
  68. package/types/core/server/components/Area.d.ts +0 -27
  69. package/types/core/server/components/index.d.ts +0 -5
  70. package/types/core/server/components/render/HydrateInBrowser.d.ts +0 -13
  71. package/types/core/server/components/render/Render.d.ts +0 -23
  72. package/types/core/server/components/render/RenderInBrowser.d.ts +0 -13
  73. package/types/core/server/components/render/index.d.ts +0 -3
  74. package/types/core/server/components/render/internal/InBrowser.d.ts +0 -8
  75. package/types/core/server/framework/defineJahiaComponent.d.ts +0 -41
  76. package/types/core/server/framework/index.d.ts +0 -2
  77. package/types/core/server/framework/register.d.ts +0 -7
  78. package/types/core/server/hooks/index.d.ts +0 -4
  79. package/types/core/server/hooks/useGQLQuery.d.ts +0 -5
  80. package/types/core/server/hooks/useJCRQuery.d.ts +0 -3
  81. package/types/core/server/hooks/useServerContext.d.ts +0 -14
  82. package/types/core/server/hooks/useUrlBuilder.d.ts +0 -31
  83. package/types/core/server/index.d.ts +0 -4
  84. package/types/core/server/utils/index.d.ts +0 -2
  85. package/types/core/server/utils/jcr/getChildNodes.d.ts +0 -9
  86. package/types/core/server/utils/jcr/getNodeFromPathOrId.d.ts +0 -12
  87. package/types/core/server/utils/jcr/getNodeProps.d.ts +0 -7
  88. package/types/core/server/utils/jcr/getNodesByJCRQuery.d.ts +0 -9
  89. package/types/core/server/utils/jcr/index.d.ts +0 -4
  90. package/types/core/server/utils/urlBuilder/index.d.ts +0 -1
  91. package/types/core/server/utils/urlBuilder/urlBuilder.d.ts +0 -27
  92. package/types/globals.d.ts +0 -11
  93. package/types/index.d.ts +0 -19
  94. package/types/nav/index.d.ts +0 -1
  95. package/types/nav/server/index.d.ts +0 -1
  96. package/types/nav/server/navBuilder/index.d.ts +0 -1
  97. package/types/nav/server/navBuilder/navBuilder.d.ts +0 -78
  98. package/types/server.d.ts +0 -27
  99. package/types/servercontext.d.ts +0 -29
  100. /package/{types → dist}/java.io.d.ts +0 -0
  101. /package/{types → dist}/java.net.d.ts +0 -0
  102. /package/{types → dist}/java.security.d.ts +0 -0
  103. /package/{types → dist}/java.util.d.ts +0 -0
  104. /package/{types → dist}/javax.jcr.d.ts +0 -0
  105. /package/{types → dist}/javax.servlet.d.ts +0 -0
  106. /package/{types → dist}/javax.servlet.http.d.ts +0 -0
  107. /package/{types → dist}/org.jahia.services.content.d.ts +0 -0
  108. /package/{types → dist}/org.jahia.services.content.decorator.d.ts +0 -0
  109. /package/{types → dist}/org.jahia.services.query.d.ts +0 -0
  110. /package/{types → dist}/org.jahia.services.render.d.ts +0 -0
  111. /package/{types → dist}/org.jahia.services.usermanager.d.ts +0 -0
  112. /package/{types → dist}/org.osgi.framework.d.ts +0 -0
@@ -0,0 +1,38 @@
1
+ export { RenderInBrowser } from "./core/server/components/render/RenderInBrowser.js";
2
+ export { HydrateInBrowser } from "./core/server/components/render/HydrateInBrowser.js";
3
+ export { Render } from "./core/server/components/render/Render.js";
4
+ export { AbsoluteArea } from "./core/server/components/AbsoluteArea.js";
5
+ export { AddContentButtons } from "./core/server/components/AddContentButtons.js";
6
+ export { AddResources } from "./core/server/components/AddResources.js";
7
+ export { Area } from "./core/server/components/Area.js";
8
+ export { defineJahiaComponent } from "./core/server/framework/defineJahiaComponent.js";
9
+ export { jahiaComponent } from "./core/server/framework/jahiaComponent.js";
10
+ export { registerJahiaComponents } from "./core/server/framework/register.js";
11
+ export { useGQLQuery } from "./core/server/hooks/useGQLQuery.js";
12
+ export { useJCRQuery } from "./core/server/hooks/useJCRQuery.js";
13
+ export { useServerContext, ServerContextProvider } from "./core/server/hooks/useServerContext.js";
14
+ export { useUrlBuilder } from "./core/server/hooks/useUrlBuilder.js";
15
+ export { getChildNodes } from "./core/server/utils/jcr/getChildNodes.js";
16
+ export { getNodeFromPathOrId } from "./core/server/utils/jcr/getNodeFromPathOrId.js";
17
+ export { getNodeProps } from "./core/server/utils/jcr/getNodeProps.js";
18
+ export { getNodesByJCRQuery } from "./core/server/utils/jcr/getNodesByJCRQuery.js";
19
+ export { buildUrl, initUrlBuilder } from "./core/server/utils/urlBuilder/urlBuilder.js";
20
+ export { buildNavMenu } from "./nav/server/navBuilder/navBuilder.js";
21
+ export { default as server } from "virtual:jahia-server";
22
+
23
+ // Include declarations for all Java types
24
+ export * from "./globals";
25
+ export * from "./java.io";
26
+ export * from "./java.net";
27
+ export * from "./java.security";
28
+ export * from "./java.util";
29
+ export * from "./javax.jcr";
30
+ export * from "./javax.servlet";
31
+ export * from "./javax.servlet.http";
32
+ export * from "./org.jahia.modules.javascript.modules.engine.js.server";
33
+ export * from "./org.jahia.services.content";
34
+ export * from "./org.jahia.services.content.decorator";
35
+ export * from "./org.jahia.services.query";
36
+ export * from "./org.jahia.services.render";
37
+ export * from "./org.jahia.services.usermanager";
38
+ export * from "./org.osgi.framework";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ console.error(
2
+ "You cannot import and run '@jahia/javascript-modules-library' because it's a virtual module.\n" +
3
+ "Something is wrong with your build configuration: instead of bundling '@jahia/javascript-modules-library', it should be replaced with 'javascriptModulesLibraryBuilder.getSharedLibrary(\"@jahia/javascript-modules-library\")'."
4
+ );
5
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { JCRNodeWrapper } from "org.jahia.services.content";
2
+ import type { RenderContext, Resource } from "org.jahia.services.render";
3
+ interface MenuEntry {
4
+ /** The HTML rendered HTML menu entry */
5
+ render: string;
6
+ /** The node object for the menu entry */
7
+ node: JCRNodeWrapper;
8
+ /** Whether the node is in the path */
9
+ inPath: boolean;
10
+ /** Whether the node is selected */
11
+ selected: boolean;
12
+ /** The level of the node */
13
+ level: number;
14
+ /** The children of the node */
15
+ children?: MenuEntry[];
16
+ }
17
+ /**
18
+ * Build a navigation menu
19
+ *
20
+ * @param maxDepth The maximum depth of the menu
21
+ * @param base The base path of the menu
22
+ * @param menuEntryView The view to use for each menu entry
23
+ * @param startLevelValue The level at which to start the menu
24
+ * @param renderContext The current render context
25
+ * @param currentResource The current resource
26
+ * @returns An array of menu entries objects
27
+ */
28
+ export declare function buildNavMenu(maxDepth: number, base: string, menuEntryView: string, startLevelValue: number, renderContext: RenderContext, currentResource: Resource): MenuEntry[];
29
+ export {};
@@ -5,8 +5,8 @@ import { Collection, List, Map } from 'java.util';
5
5
  import { JCRNodeWrapper, JCRCallback } from 'org.jahia.services.content';
6
6
 
7
7
  import { JCRSiteNode } from 'org.jahia.services.content.decorator';
8
+ import { Promise } from 'org.jahia.modules.javascript.modules.engine.jsengine';
8
9
  import { RenderContext, Resource } from 'org.jahia.services.render';
9
- import { Promise, Registry, ContextProvider } from 'org.jahia.modules.javascript.modules.engine.jsengine';
10
10
  /**
11
11
  * Java helper to expose OSGi configuration values to Javascript code
12
12
  */
@@ -184,7 +184,6 @@ export class RegistryHelper {
184
184
  * @param key the key of the object to remove within the type
185
185
  */
186
186
  remove(type: string, key: string): void;
187
- getRegistry(): Registry;
188
187
  }
189
188
  /**
190
189
  * Helper class to provide rendering functions to the Javascript engine
Binary file
package/package.json CHANGED
@@ -1,36 +1,47 @@
1
1
  {
2
2
  "name": "@jahia/javascript-modules-library",
3
- "version": "0.3.0",
4
- "main": "index.js",
5
- "types": "types/index.d.ts",
6
- "repository": "git@github.com:Jahia/javascript-modules.git",
3
+ "version": "0.5.1",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com:Jahia/javascript-modules.git",
7
+ "directory": "javascript-modules-library"
8
+ },
7
9
  "license": "MIT",
8
- "scripts": {
9
- "types:copy": "mkdir -p dist/types && ncp target/types dist/types",
10
- "build:development": "run types:copy && tsc && node generate-index",
11
- "build:production": "run build:development && run minify",
12
- "build": "run build:production",
13
- "minify": "node minify",
14
- "doc": "typedoc",
15
- "clean": "rm -rf dist",
16
- "lint": "eslint --ext js,jsx,json,ts src/",
17
- "lint:fix": "eslint --ext js,jsx,json,ts --fix src/",
18
- "prepack": "echo 'Please run 'mvn package' to create the tgz so the Maven version can be injected in the package.json' && exit 1"
10
+ "type": "module",
11
+ "exports": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "bin": {
16
+ "jahia-deploy": "bin/jahia-deploy.mjs"
19
17
  },
20
18
  "files": [
19
+ "bin",
21
20
  "dist"
22
21
  ],
22
+ "scripts": {
23
+ "build": "tsc && node post-build.js && mkdir -p dist && yarn pack --out dist/package.tgz && publint",
24
+ "clean": "rm -rf dist",
25
+ "lint": "yarn run --top-level lint"
26
+ },
23
27
  "dependencies": {
24
- "graphql": "^16.0.1",
25
- "graphql-tag": "^2.12.6",
26
- "prop-types": "^15.8.1"
28
+ "dotenv": "^16.4.7"
29
+ },
30
+ "devDependencies": {
31
+ "@types/react": "^19.0.8",
32
+ "devalue": "^5.1.1",
33
+ "graphql": "^16.10.0",
34
+ "i18next": "^23.10.1",
35
+ "publint": "^0.3.6",
36
+ "react-i18next": "^15.4.0",
37
+ "typescript": "^5.7.3"
27
38
  },
28
39
  "peerDependencies": {
29
- "i18next": ">=23.0.0 <23.11.0",
30
- "react": ">=18.0.0 <18.3.0",
31
- "react-dom": ">=18.0.0 <18.3.0",
32
- "react-i18next": ">=14.0.0 <14.2.0",
33
- "styled-jsx": ">=5.0.0 <5.2.0"
40
+ "i18next": "^23.0.0",
41
+ "react": "^19.0.0",
42
+ "react-dom": "^19.0.0",
43
+ "react-i18next": "^15.4.0",
44
+ "styled-jsx": "^5.0.0"
34
45
  },
35
46
  "peerDependenciesMeta": {
36
47
  "i18next": {
@@ -48,37 +59,5 @@
48
59
  "styled-jsx": {
49
60
  "optional": true
50
61
  }
51
- },
52
- "resolutions": {
53
- "minimist": "^1.2.6",
54
- "set-getter": "^0.1.1"
55
- },
56
- "devDependencies": {
57
- "@babel/cli": "^7.23.4",
58
- "@babel/core": "^7.23.7",
59
- "@babel/preset-env": "^7.23.8",
60
- "@babel/preset-react": "^7.23.3",
61
- "@jahia/eslint-config": "^2.1.2",
62
- "@types/node-fetch": "^2.6.11",
63
- "@types/react": "^18.2.48",
64
- "@typescript-eslint/eslint-plugin": "^4.29.3",
65
- "@typescript-eslint/parser": "^4.29.3",
66
- "babel-loader": "^9.1.3",
67
- "babel-plugin-transform-react-jsx": "^6.24.1",
68
- "eslint": "^7.32.0",
69
- "eslint-plugin-cypress": "^2.11.3",
70
- "eslint-plugin-jest": "^27.2.1",
71
- "eslint-plugin-json": "^3.1.0",
72
- "eslint-plugin-prettier": "^4.0.0",
73
- "eslint-plugin-react": "^7.32.2",
74
- "eslint-plugin-react-hooks": "^4.6.0",
75
- "i18next": "^23.10.1",
76
- "ncp": "^2.0.0",
77
- "react": "^18.2.0",
78
- "react-i18next": "^14.1.0",
79
- "terser": "^5.36.0",
80
- "typedoc": "^0.25.13",
81
- "typescript": "^4.3.5"
82
- },
83
- "packageManager": "yarn@4.5.0"
84
- }
62
+ }
63
+ }
package/core/index.js DELETED
@@ -1 +0,0 @@
1
- export*from"./server";
@@ -1 +0,0 @@
1
- import React from"react";import{useServerContext}from"../hooks/useServerContext";import{server}from"@jahia/javascript-modules-library-private";export function AbsoluteArea({name:e,areaView:r,allowedTypes:t,numberOfItems:a,subNodesView:o,path:s,editable:n=!0,level:i,areaType:l="jnt:contentList",limitedAbsoluteAreaEdit:m,parameters:d}){const{renderContext:u}=useServerContext();return React.createElement("unwanteddiv",{dangerouslySetInnerHTML:{__html:server.render.renderAbsoluteArea({name:e,areaView:r,allowedTypes:t,numberOfItems:a,subNodesView:o,path:s,editable:n,level:i,areaType:l,limitedAbsoluteAreaEdit:m,parameters:d},u)}})}
@@ -1 +0,0 @@
1
- import React from"react";import{server}from"@jahia/javascript-modules-library-private";import{useServerContext}from"../hooks/useServerContext";export function AddContentButtons({nodeTypes:e,childName:t="*",editCheck:r=!1}){const{renderContext:n,currentResource:o}=useServerContext();return React.createElement("unwanteddiv",{dangerouslySetInnerHTML:{__html:server.render.createContentButtons(t,e,r,n,o)}})}
@@ -1 +0,0 @@
1
- import React from"react";import{useServerContext}from"../hooks";import{server}from"@jahia/javascript-modules-library-private";export function AddResources({...e}){const{renderContext:r}=useServerContext();return React.createElement("unwanteddiv",{dangerouslySetInnerHTML:{__html:server.render.addResources(e,r)}})}
@@ -1 +0,0 @@
1
- import React from"react";import{useServerContext}from"../hooks/useServerContext";import{server}from"@jahia/javascript-modules-library-private";export function Area({name:e,areaView:r,allowedTypes:a,numberOfItems:t,subNodesView:n,path:o,editable:s=!0,areaAsSubNode:m,areaType:i="jnt:contentList",parameters:d}){const{renderContext:p}=useServerContext();return React.createElement("unwanteddiv",{dangerouslySetInnerHTML:{__html:server.render.renderArea({name:e,areaView:r,allowedTypes:a,numberOfItems:t,subNodesView:n,path:o,editable:s,areaAsSubNode:m,areaType:i,parameters:d},p)}})}
@@ -1 +0,0 @@
1
- export*from"./AddContentButtons";export*from"./AddResources";export*from"./Area";export*from"./AbsoluteArea";export*from"./render";
@@ -1 +0,0 @@
1
- import React from"react";import InBrowser from"./internal/InBrowser";export function HydrateInBrowser({child:r,props:e}){return React.createElement(InBrowser,{preRender:!0,child:r,props:e,dataKey:"data-reacthydrate"})}
@@ -1 +0,0 @@
1
- import React from"react";import{server}from"@jahia/javascript-modules-library-private";import{useServerContext}from"../../hooks/useServerContext";export function Render({content:e,node:r,path:t,editable:n=!0,advanceRenderingConfig:a,templateType:o,view:i,parameters:d}){const{renderContext:p,currentResource:c}=useServerContext();return React.createElement("unwanteddiv",{dangerouslySetInnerHTML:{__html:server.render.render({content:e,node:r,path:t,editable:n,advanceRenderingConfig:a,templateType:o,view:i,parameters:d},p,c)}})}
@@ -1 +0,0 @@
1
- import React from"react";import InBrowser from"./internal/InBrowser";export function RenderInBrowser({child:r,props:e}){return React.createElement(InBrowser,{preRender:!1,child:r,props:e,dataKey:"data-reactrender"})}
@@ -1 +0,0 @@
1
- export*from"./Render";export*from"./HydrateInBrowser";export*from"./RenderInBrowser";
@@ -1 +0,0 @@
1
- import React from"react";import{useServerContext}from"../../../hooks/useServerContext";import{AddResources}from"../../AddResources";import{buildUrl}from"../../../utils/urlBuilder";import{I18nextProvider}from"react-i18next";import i18n from"i18next";const getClientI18nStoreScript=(e,t)=>{const r=i18n.getResourceBundle(e,t);if(r){const n={};return n[e]={},n[e][t]=r,`<script type="text/javascript">\n if(!window.__APPSHELL_INIT_DATA__) {\n window.__APPSHELL_INIT_DATA__ = {};\n }\n if(!window.__APPSHELL_INIT_DATA__.initialI18nStore) {\n window.__APPSHELL_INIT_DATA__.initialI18nStore = [];\n }\n window.__APPSHELL_INIT_DATA__.initialI18nStore.push(${JSON.stringify(n)});\n <\/script>`}},getAppShellInitData=e=>`<script type="text/javascript">\n if(!window.__APPSHELL_INIT_DATA__) {\n window.__APPSHELL_INIT_DATA__ = {};\n }\n window.__APPSHELL_INIT_DATA__.moduleBaseUrl = '${e}';\n <\/script>`;function InBrowser({child:e,props:t,dataKey:r,preRender:n}){const{bundleKey:i,currentResource:o,renderContext:a}=useServerContext(),s=o.getLocale().getLanguage(),c=getAppShellInitData(buildUrl({value:"/modules"},a,o)),l=getClientI18nStoreScript(s,i),_=buildUrl({value:"/modules/"+i+"/javascript/client/remote.js"},a,o),d=buildUrl({value:"/modules/javascript-modules-engine/javascript/apps/reactAppShell.js"},a,o),p={};return p[r]=encodeURIComponent(JSON.stringify({name:e.name,lang:s,bundle:i,props:t||{}})),React.createElement(React.Fragment,null,React.createElement("div",{...p},n&&React.createElement(I18nextProvider,{i18n:i18n},React.createElement(e,{...t}))),l&&React.createElement(AddResources,{key:`i18n_initialStore_${i}`,insert:!0,inlineResource:l}),React.createElement(AddResources,{key:"npm-engine-appShellInitData",insert:!0,inlineResource:c}),React.createElement(AddResources,{insert:!0,type:"javascript",targetTag:"body",resources:_}),React.createElement(AddResources,{type:"javascript",targetTag:"body",resources:d}))}export default InBrowser;
@@ -1 +0,0 @@
1
- export function defineJahiaComponent(n){return n}
@@ -1 +0,0 @@
1
- export*from"./register";export*from"./defineJahiaComponent";
@@ -1 +0,0 @@
1
- import{server}from"@jahia/javascript-modules-library-private";export function registerJahiaComponents(e){if(!bundle)return void console.error("registerJahiaComponents: bundle is not available, make sure you are using this function inside the initialization of the bundle");const n=bundle.getSymbolicName(),o=server.registry.get("view","react");Object.keys(e).forEach((t=>{let i;const r=e[t].jahiaComponent;if(!r||!r.nodeType||!r.componentType)return void console.warn(`registerJahiaComponents(bundle=${n}: Missing mandatory property nodeType and/or componentType, skipping component name=${r.name} nodeType=${r.nodeType} id=${r.id} registration`);i={name:"default",templateType:"html",component:null};let a=r.id;delete r.id,i.component=e[t];const p={...i,...r};a||(a=`${n}_${p.componentType}_${p.nodeType}_${p.name}`),server.registry.add("view",a,o,p)}))}
@@ -1 +0,0 @@
1
- export*from"./useGQLQuery";export*from"./useJCRQuery";export*from"./useServerContext";export*from"./useUrlBuilder";
@@ -1 +0,0 @@
1
- import{useServerContext}from"./useServerContext";import{server}from"@jahia/javascript-modules-library-private";export const useGQLQuery=({query:e,variables:r,operationName:t})=>{const{renderContext:o}=useServerContext();return server.gql.executeQuerySync({query:e,variables:r,operationName:t,renderContext:o})};
@@ -1 +0,0 @@
1
- import{useServerContext}from"./useServerContext";import{getNodesByJCRQuery}from"../utils/jcr";export const useJCRQuery=({query:e})=>{const{renderContext:r}=useServerContext();return getNodesByJCRQuery(r.getMainResource().getNode().getSession(),e,-1,0)};
@@ -1 +0,0 @@
1
- import React,{useContext}from"react";const ServerContext=React.createContext({});export function useServerContext(){return useContext(ServerContext)}export function ServerContextProvider({renderContext:e,currentResource:r,currentNode:t,mainNode:n,bundleKey:o,children:c}){return React.createElement(ServerContext.Provider,{value:{renderContext:e,currentResource:r,currentNode:t,mainNode:n,bundleKey:o}},c)}
@@ -1 +0,0 @@
1
- import{useServerContext}from"./useServerContext";import{buildUrl as originalBuildUrl}from"../utils/urlBuilder";export function useUrlBuilder(){const{renderContext:e,currentResource:r}=useServerContext(),t=({nodePath:t,extension:a,language:l,mode:n,parameters:o})=>originalBuildUrl({path:t,extension:a,language:l,mode:n,parameters:o},e,r);return{buildStaticUrl:({assetPath:t,moduleName:a=e?.getURLGenerator()?.getCurrentModule(),parameters:l})=>{let n=a+"/static"+(t?.startsWith("/")?"":"/")+t;return originalBuildUrl({value:n,parameters:l},e,r)},buildNodeUrl:t,buildHtmlFragmentUrl:({nodePath:e,language:r,mode:a,parameters:l})=>t({nodePath:e,extension:".html.ajax",language:r,mode:a,parameters:l})}}
@@ -1 +0,0 @@
1
- export*from"./components";export*from"./framework";export*from"./hooks";export*from"./utils";
@@ -1 +0,0 @@
1
- export*from"./jcr";export*from"./urlBuilder";
@@ -1 +0,0 @@
1
- export function getChildNodes(e,o,t=0,n=void 0){let r=[];if(!e||!o)return console.warn("Missing one or more mandatory parameters (node, limit) to getChildNodes"),r;const s=e.getNodes();let i=0;for(;s.hasNext();){const e=s.nextNode();if(i<t)n&&!n(e)||i++;else if((!n||n(e))&&(r.push(e),o>0&&r.length===o))break}return r}
@@ -1 +0,0 @@
1
- export function getNodeFromPathOrId(e,t){return e.identifier?t.getNodeByIdentifier(e.identifier):e.path?t.getNode(e.path):null}
@@ -1 +0,0 @@
1
- const STRING=1,LONG=3,DOUBLE=4,DATE=5,BOOLEAN=6,NAME=7,PATH=8,REFERENCE=9,WEAKREFERENCE=10,URI=11,DECIMAL=12,extractProp=(e,t)=>{if(e.hasProperty(t)){const r=e.getProperty(t);if(r.isMultiple()){const t=r.getValues(),o=[];for(const s of t)o.push(extractPropValue(e.getSession(),s,r.getType()));return o}return extractPropValue(e.getSession(),r.getValue(),r.getType())}},extractPropValue=(e,t,r)=>{switch(r){case 1:case 5:case 7:case 8:case 11:case 12:return t.getString();case 3:return t.getLong();case 4:return t.getDouble();case 6:return t.getBoolean();case 9:case 10:try{return e.getNodeByIdentifier(t.getString())}catch(e){return}default:return}};export function getNodeProps(e,t){let r={};if(e&&t&&t.length>0)for(const o of t)e.hasProperty(o)&&(r[o]=extractProp(e,o));return r}
@@ -1 +0,0 @@
1
- export function getNodesByJCRQuery(e,t,r,o=0){let s=[];if(!e||!t||!r)return console.warn("Missing one or more mandatory parameters (session, query, limit) to getNodesByJCRQuery"),s;const n=e.getWorkspace().getQueryManager().createQuery(t,"JCR-SQL2");r>0&&n.setLimit(r),o&&o>0&&n.setOffset(o);const a=n.execute().getNodes();for(;a.hasNext();)s.push(a.nextNode());return s}
@@ -1 +0,0 @@
1
- export*from"./getChildNodes";export*from"./getNodeFromPathOrId";export*from"./getNodeProps";export*from"./getNodesByJCRQuery";
@@ -1 +0,0 @@
1
- export*from"./urlBuilder";
@@ -1 +0,0 @@
1
- import{getNodeFromPathOrId}from"../jcr/getNodeFromPathOrId";import{server}from"@jahia/javascript-modules-library-private";const absoluteUrlRegExp=/^(?:[a-z+]+:)?\/\//i,finalizeUrl=(e,r)=>absoluteUrlRegExp.test(e)?e:(e=e.startsWith("/")?r.getRequest().getContextPath()+e:e,r.getResponse().encodeURL(e));function appendParameters(e,r){const t=e.includes("?")?"&":"?";return`${e}${t}${Object.keys(r).map((e=>`${encodeURIComponent(e)}=${encodeURIComponent(r[e])}`)).join("&")}`}export function initUrlBuilder(){server.registry.add("urlBuilder","nt:file",{priority:1,buildURL:({jcrNode:e,mode:r,currentResource:t})=>"/files/"+(r?"edit"===r||"preview"===r?"default":"live":t.getWorkspace())+server.render.escapePath(e.getCanonicalPath())}),server.registry.add("urlBuilder","*",{priority:0,buildURL:({jcrNode:e,mode:r,language:t,extension:a,renderContext:n,currentResource:o})=>{let i,l;if(r)switch(r){case"edit":l="/cms/edit",i="default";break;case"preview":l="/cms/render",i="default";break;default:l="/cms/render",i="live"}else l=n.getServletPath(),i=o.getWorkspace();return l+"/"+i+"/"+(t||o.getLocale().toString())+server.render.escapePath(e.getPath())+(a||".html")}})}export function buildUrl(e,r,t){let a;if(e.path){let n;try{n=getNodeFromPathOrId({path:e.path},t.getNode().getSession())}catch(r){return console.warn(`Unable to find node for path: ${e.path}\n Replacing by #`),"#"}if(n){const o=server.registry.find({type:"urlBuilder"},"priority");for(const i of o)if("*"===i.key||n.isNodeType(i.key)){a=i.buildURL({jcrNode:n,mode:e.mode,language:e.language,extension:e.extension,renderContext:r,currentResource:t});break}}}else{if(!e.value)return console.warn("Missing parameter to build url, please provide either a content path using 'path' parameter, or a prebuild valid url using 'value' parameter\n replacing by #"),"#";a=e.value}return a?(e.parameters&&"[object Object]"===Object.prototype.toString.call(e.parameters)&&(a=appendParameters(a,e.parameters)),finalizeUrl(a,r)):(console.warn(`Unable to build url for: ${JSON.stringify(e)}\n Replacing by #`),"#")}
package/index.js DELETED
@@ -1 +0,0 @@
1
- export*from"./core";export*from"./nav";
package/nav/index.js DELETED
@@ -1 +0,0 @@
1
- export*from"./server";
@@ -1 +0,0 @@
1
- export*from"./navBuilder";
@@ -1 +0,0 @@
1
- export*from"./navBuilder";
@@ -1,24 +0,0 @@
1
- import{server}from"@jahia/javascript-modules-library-private";import{print}from"graphql";import gql from"graphql-tag";const getPageAncestors=(e,t,r)=>{const n=server.gql.executeQuerySync({query:print(gql`
2
- query ($workspace: Workspace!, $path: String!, $types: [String]!){
3
- jcr(workspace: $workspace) {
4
- nodeByPath(path: $path) {
5
- ancestors(fieldFilter: {filters:[{fieldName:"isNodeType", value:"true"}]}) {
6
- path
7
- isNodeType(type: {types: $types})
8
- }
9
- }
10
- }
11
- }
12
- `),variables:{workspace:e,path:t,types:r}});return n.data?n.data.jcr.nodeByPath.ancestors:[]},getMenuItemsChildren=(e,t,r)=>{const n=server.gql.executeQuerySync({query:print(gql`
13
- query childrenOfType($workspace: Workspace!, $path: String!, $types: [String]!){
14
- jcr(workspace: $workspace) {
15
- nodeByPath(path: $path) {
16
- children(typesFilter: {types:$types}) {
17
- nodes {
18
- path
19
- }
20
- }
21
- }
22
- }
23
- }
24
- `),variables:{workspace:e,path:t,types:r}});return n.data?n.data.jcr.nodeByPath.children.nodes:[]},getBaseNode=(e,t,r)=>{const n=t.getMainResource().getNode(),a=getPageAncestors(r,n.getPath(),["jnt:page"]);if(!e||"home"===e)return t.getSite().getHome();if("currentPage"===e){if(t.getMainResource().getNode().isNodeType("jnt:page"))return n;if(a.length>0)return n.getSession().getNode(a.slice(-1)[0].path)}return n},buildMenu=(e,t,r,n)=>{let a=[];if(e){const s=e.getSession();n||(n=getMenuItemsChildren(r.workspace,e.getPath(),["jmix:navMenuItem"]));for(let e=0;e<n.length;e++){const o={},i=n[e].path,p=s.getNode(i),c=r.mainResourceNode.getPath()===i||r.mainResourceNode.getPath().startsWith(i+"/");let g=!1,u=!1,d=!0;if(p.isNodeType("jmix:nodeReference")){r.currentResource.getDependencies().add(p.getPropertyAsString("j:node"));const e=p.getProperty("j:node").getNode();e?g=r.mainResourceNode.getPath()===e.getPath():(g=!1,u=!0)}else g=r.mainResourceNode.getPath()===p.getPath();if(p.hasProperty["j:displayInMenuName"]&&(d=!1,p.getProperty("j:displayInMenuName").getValues().forEach((e=>{d=d||e.getString()===r.menuName}))),!u&&d&&(r.startLevelValue<t||c)){if(t<r.maxDepth){const e=getMenuItemsChildren(r.workspace,p.getPath(),["jmix:navMenuItem"]);e.length>0&&(o.children=buildMenu(p,t+1,r,e))}r.startLevelValue<t&&(r.currentResource.getDependencies().add(p.getCanonicalPath()),o.render=server.render.render({path:p.getPath(),view:r.menuEntryView||"menuElement"},r.renderContext,r.currentResource)),o.node=p,o.inPath=c,o.selected=g,o.level=t}a.push(o)}}return a};export function buildNavMenu(e,t,r,n,a,s){const o=a.isLiveMode()?"LIVE":"EDIT";return buildMenu(getBaseNode(t,a,o),1,{renderContext:a,mainResourceNode:a.getMainResource().getNode(),currentResource:s,workspace:o,menuName:s.getNode().getName(),startLevelValue:n,maxDepth:e,menuEntryView:r})}
@@ -1,60 +0,0 @@
1
- import {ConfigHelper, GQLHelper, OSGiHelper, RegistryHelper, RenderHelper} from 'org.jahia.modules.javascript.modules.engine.js.server';
2
- import {JCRNodeWrapper} from 'org.jahia.services.content';
3
- import {Resource, RenderContext} from 'org.jahia.services.render';
4
-
5
- /**
6
- * This module is used for internal compilation of the project. It should not be used directly in your code.
7
- */
8
- declare module '@jahia/javascript-modules-library-private' {
9
- /**
10
- * A set of helpers that provide common functionality provided by Jahia for Javascript server-side rendering
11
- */
12
- export const server: {
13
- /**
14
- * This helper provides access to OSGi configuration
15
- */
16
- config: ConfigHelper,
17
- /**
18
- * This helper provides access Jahia's GraphQL API, to execute queries and mutations
19
- */
20
- gql: GQLHelper,
21
- /**
22
- * This helper provides access to OSGi bundle for resource loading and service access
23
- */
24
- osgi: OSGiHelper,
25
- /**
26
- * This helper provides access to Jahia's registry API, to register new UI objects or retrieving existing ones
27
- */
28
- registry: RegistryHelper,
29
- /**
30
- * This helper provides rendering functions such as registering page resources, adding cache dependencies or rendering components
31
- */
32
- render: RenderHelper
33
- };
34
-
35
- /**
36
- * A context object that gives access to the underlying Jahia Java objects that are part of the current rendering context
37
- */
38
- export interface ServerContext {
39
- /**
40
- * Jahia's rendering context, it provides access to all kinds of context information, such as the current request, response, user, mode, mainResource and more
41
- */
42
- renderContext : RenderContext;
43
- /**
44
- * The current resource being rendered, which is a combination of the current node and its template/view information
45
- */
46
- currentResource : Resource;
47
- /**
48
- * The current JCR node being rendered
49
- */
50
- currentNode : JCRNodeWrapper;
51
- /**
52
- * The main JCR node being rendered, which is the root node of the current page
53
- */
54
- mainNode : JCRNodeWrapper;
55
- /**
56
- * The OSGi bundle key of the current module being rendered
57
- */
58
- bundleKey : string;
59
- }
60
- }
@@ -1 +0,0 @@
1
- export * from "./server";
@@ -1,29 +0,0 @@
1
- /**
2
- * Generates an absolute area in which editors may insert content objects.
3
- * @param {object} props The React properties for the component.
4
- * @param {string} [props.name] The name of the area.
5
- * @param {string} [props.areaView] The view to use for the area.
6
- * @param {string[]} [props.allowedTypes] The allowed types for the area.
7
- * @param {number} [props.numberOfItems] The number of items to display in the area.
8
- * @param {string} [props.subNodesView] The view to use for the subnodes.
9
- * @param {string} [props.path] Relative (to the current node) or absolute path to the node to include
10
- * @param {boolean} [props.editable] Enables or disables edition of this content in edit mode. Mainly used for absolute or references.
11
- * @param {number} [props.level] Ancestor level for absolute area - 0 is Home page, 1 first sub-pages, ...
12
- * @param {string} [props.areaType] Content type to be used to create the area (by default jnt:contentList)
13
- * @param {boolean} [props.limitedAbsoluteAreaEdit] Is the absolute area editable everywhere or only on the page containing its node.
14
- * @param {object} [props.parameters] the parameters to pass to the absolute area
15
- * @returns {JSX.Element} The AbsoluteArea component
16
- */
17
- export function AbsoluteArea({ name, areaView, allowedTypes, numberOfItems, subNodesView, path, editable, level, areaType, limitedAbsoluteAreaEdit, parameters }: {
18
- name?: string;
19
- areaView?: string;
20
- allowedTypes?: string[];
21
- numberOfItems?: number;
22
- subNodesView?: string;
23
- path?: string;
24
- editable?: boolean;
25
- level?: number;
26
- areaType?: string;
27
- limitedAbsoluteAreaEdit?: boolean;
28
- parameters?: object;
29
- }): JSX.Element;
@@ -1,13 +0,0 @@
1
- /**
2
- * Generates add content buttons for a content object
3
- * @param {object} properties The React properties for the component.
4
- * @param {string} [properties.nodeTypes] The node types to add.
5
- * @param {string} [properties.childName='*'] The child name.
6
- * @param {boolean} [properties.editCheck=false] If true, the edit check will be performed.
7
- * @returns {JSX.Element} The add content buttons.
8
- */
9
- export function AddContentButtons({ nodeTypes, childName, editCheck }: {
10
- nodeTypes?: string;
11
- childName?: string;
12
- editCheck?: boolean;
13
- }): JSX.Element;
@@ -1,31 +0,0 @@
1
- /**
2
- * Adds a resources to the head tag of the HTML page.
3
- * @param {object} props - The properties for the component.
4
- * @param {boolean} [props.insert] - If true, the resource will be inserted into the document. Typically used for on-demand loading of resources.
5
- * @param {boolean} [props.async] - If true, the resource will be loaded asynchronously. For scripts, this means the script will be executed as soon as it's available, without blocking the rest of the page.
6
- * @param {boolean} [props.defer] - If true, the resource will be deferred, i.e., loaded after the document has been parsed. For scripts, this means the script will not be executed until after the page has loaded.
7
- * @param {string} [props.type] - The type of the resource. This could be 'javascript' for .js files, 'css' for .css files, etc.
8
- * @param {string} [props.resources] - The path to the resource file, relative to the module.
9
- * @param {string} [props.inlineResource] - Inline HTML that markup will be considered as resource.
10
- * @param {string} [props.title] - The title of the resource. This is typically not used for scripts or stylesheets, but may be used for other types of resources.
11
- * @param {string} [props.key] - A unique key for the resource. This could be used to prevent duplicate resources from being added to the document.
12
- * @param {string} [props.targetTag] - The HTML tag where the resource should be added. This could be 'head' for resources that should be added to the <head> tag, 'body' for resources that should be added to the <body> tag, etc.
13
- * @param {string} [props.rel] - The relationship of the resource to the document. This is typically 'stylesheet' for CSS files.
14
- * @param {string} [props.media] - The media for which the resource is intended. This is typically used for CSS files, with values like 'screen', 'print', etc.
15
- * @param {string} [props.condition] - A condition that must be met for the resource to be loaded. This could be used for conditional comments in IE, for example.
16
- * @returns {JSX.Element} A React element that renders a script or link tag.
17
- */
18
- export function AddResources({ ...props }: {
19
- insert?: boolean;
20
- async?: boolean;
21
- defer?: boolean;
22
- type?: string;
23
- resources?: string;
24
- inlineResource?: string;
25
- title?: string;
26
- key?: string;
27
- targetTag?: string;
28
- rel?: string;
29
- media?: string;
30
- condition?: string;
31
- }): JSX.Element;
@@ -1,27 +0,0 @@
1
- /**
2
- * Generates an area in which editors may insert content objects.
3
- * @param {object} props The React properties for the component.
4
- * @param {string} [props.name] The name of the area.
5
- * @param {string} [props.areaView] The view to use for the area.
6
- * @param {string[]} [props.allowedTypes] The allowed types for the area.
7
- * @param {number} [props.numberOfItems] The number of items to display in the area.
8
- * @param {string} [props.subNodesView] The view to use for the subnodes.
9
- * @param {string} [props.path] Relative (to the current node) or absolute path to the node to include
10
- * @param {boolean} [props.editable] Enables or disables edition of this content in edit mode. Mainly used for absolute or references.
11
- * @param {boolean} [props.areaAsSubNode] Allows area to be stored as a subnode
12
- * @param {string} [props.areaType] Content type to be used to create the area (by default jnt:contentList)
13
- * @param {object} [props.parameters] the parameters to pass to the area
14
- * @returns {JSX.Element} The Area component
15
- */
16
- export function Area({ name, areaView, allowedTypes, numberOfItems, subNodesView, path, editable, areaAsSubNode, areaType, parameters }: {
17
- name?: string;
18
- areaView?: string;
19
- allowedTypes?: string[];
20
- numberOfItems?: number;
21
- subNodesView?: string;
22
- path?: string;
23
- editable?: boolean;
24
- areaAsSubNode?: boolean;
25
- areaType?: string;
26
- parameters?: object;
27
- }): JSX.Element;
@@ -1,5 +0,0 @@
1
- export * from "./AddContentButtons";
2
- export * from "./AddResources";
3
- export * from "./Area";
4
- export * from "./AbsoluteArea";
5
- export * from "./render";
@@ -1,13 +0,0 @@
1
- /**
2
- * Will render the given React component server side and hydrate it in the browser to make it dynamic.
3
- * Be careful, the component will not have access to the '@jahia/javascript-modules-library' library from the browser.
4
- *
5
- * @param {object} params The React component.
6
- * @param {object} params.child The React component.
7
- * @param {object} [params.props] The React component props, this props will be serialized/deserialized to be usable server and client side. The serialization and deserialization is done using JSON.stringify server side and JSON.parse in the browser. Please make sure that the props are serializable.
8
- * @returns {JSX.Element} The component to be hydrated in the browser
9
- */
10
- export function HydrateInBrowser({ child: Child, props }: {
11
- child: object;
12
- props?: object;
13
- }): JSX.Element;
@@ -1,23 +0,0 @@
1
- /**
2
- * Render a content node
3
- * @param {object} props the properties for the render
4
- * @param {object} [props.content] the content node to render
5
- * @param {object} [props.node] the node to render
6
- * @param {string} [props.path] the path to render
7
- * @param {boolean} [props.editable] if the content should be editable
8
- * @param {string} [props.advanceRenderingConfig] specifies if we should render a node or simply include a view. Acceptable values are : none, INCLUDE or OPTION
9
- * @param {string} [props.templateType] the template type to use (html, json, ...)
10
- * @param {string} [props.view] the name of the view variant to use
11
- * @param {object} [props.parameters] the parameters to pass to the view
12
- * @returns {JSX.Element} the rendered output of the view for the specified content
13
- */
14
- export function Render({ content, node, path, editable, advanceRenderingConfig, templateType, view, parameters }: {
15
- content?: object;
16
- node?: object;
17
- path?: string;
18
- editable?: boolean;
19
- advanceRenderingConfig?: string;
20
- templateType?: string;
21
- view?: string;
22
- parameters?: object;
23
- }): JSX.Element;
@@ -1,13 +0,0 @@
1
- /**
2
- * Will render the given React component in the browser.
3
- * Be careful, the component will not have access to the '@jahia/javascript-modules-library' library from the browser.
4
- *
5
- * @param {object} params The React component.
6
- * @param {object} params.child The React component.
7
- * @param {object} [params.props] The React component props, this props will be serialized/deserialized to be usable server and client side. The serialization and deserialization is done using JSON.stringify server side and JSON.parse in the browser. Please make sure that the props are serializable.
8
- * @returns {JSX.Element} The component to be rendered in the browser
9
- * */
10
- export function RenderInBrowser({ child: Child, props }: {
11
- child: object;
12
- props?: object;
13
- }): JSX.Element;
@@ -1,3 +0,0 @@
1
- export * from "./Render";
2
- export * from "./HydrateInBrowser";
3
- export * from "./RenderInBrowser";
@@ -1,8 +0,0 @@
1
- export default InBrowser;
2
- declare function InBrowser({ child: Child, props, dataKey, preRender }: {
3
- child: any;
4
- props: any;
5
- dataKey: any;
6
- preRender: any;
7
- }): React.JSX.Element;
8
- import React from "react";