@jahia/javascript-modules-library 0.5.6 → 0.6.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.
- package/README.md +215 -22
- package/dist/core/server/components/AbsoluteArea.d.ts +43 -18
- package/dist/core/server/components/AddResources.d.ts +1 -1
- package/dist/core/server/components/Area.d.ts +32 -16
- package/dist/core/server/components/render/HydrateInBrowser.d.ts +1 -1
- package/dist/core/server/components/render/Render.d.ts +4 -4
- package/dist/core/server/components/render/RenderChild.d.ts +16 -0
- package/dist/core/server/components/render/RenderChildren.d.ts +33 -0
- package/dist/core/server/framework/jahiaComponent.d.ts +7 -0
- package/dist/core/server/hooks/useServerContext.d.ts +6 -4
- package/dist/core/server/utils/i18n.d.ts +11 -0
- package/dist/core/server/utils/jcr/getChildNodes.d.ts +1 -2
- package/dist/core/server/utils/jcr/getNodesByJCRQuery.d.ts +1 -1
- package/dist/core/server/utils/urlBuilder/urlBuilder.d.ts +52 -15
- package/dist/globals.d.ts +3 -0
- package/dist/index.d.ts +6 -3
- package/dist/java.io.d.ts +164 -0
- package/dist/java.lang.d.ts +16 -0
- package/dist/java.util.d.ts +2 -1
- package/dist/javax.jcr.d.ts +13 -0
- package/dist/javax.servlet.http.d.ts +70 -0
- package/dist/nav/server/navBuilder/navBuilder.d.ts +5 -3
- package/dist/org.jahia.modules.javascript.modules.engine.js.server.d.ts +56 -50
- package/dist/org.jahia.services.content.d.ts +41 -1
- package/dist/org.jahia.services.content.decorator.d.ts +97 -2
- package/dist/org.jahia.services.render.d.ts +8 -0
- package/dist/org.jahia.services.usermanager.d.ts +11 -0
- package/dist/package.tgz +0 -0
- package/package.json +5 -1
- package/dist/core/server/hooks/useUrlBuilder.d.ts +0 -52
- package/dist/core/server/utils/jcr/getNodeFromPathOrId.d.ts +0 -14
package/README.md
CHANGED
|
@@ -1,36 +1,229 @@
|
|
|
1
|
-
# javascript-modules-library
|
|
1
|
+
# @jahia/javascript-modules-library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This library exposes common types and utility functions for JavaScript modules running in a Jahia environment. It exposes the following APIs:
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Rendering components
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
that was forked here : https://github.com/Jahia/java-ts-bind/tree/finer-excludes . You don't need to checkout this
|
|
9
|
-
repository as the scripts will automatically do that for you but we mention it in case you need to make modifications
|
|
10
|
-
to it.
|
|
7
|
+
### `RenderInBrowser`
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
using the following steps:
|
|
9
|
+
This component is used to render a React component in the browser. It is used to render a component in the browser, skipping the server-side rendering step. Provided children, if any, will be rendered on the server and replaced by the component in the browser.
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
```tsx
|
|
12
|
+
<RenderInBrowser child={MyComponent} props={{ foo: "bar" }}>
|
|
13
|
+
<div>Loading...</div>
|
|
14
|
+
</RenderInBrowser>
|
|
15
|
+
```
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
### `HydrateInBrowser`
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
This component is used to hydrate a React component in the browser. It will be rendered on the server then hydrated in the browser. Provided children, if any, will be children of the component.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
```tsx
|
|
22
|
+
<HydrateInBrowser child={MyComponent} props={{ foo: "bar" }}>
|
|
23
|
+
<div>I'm a child of MyComponent</div>
|
|
24
|
+
</HydrateInBrowser>
|
|
25
|
+
```
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
### `Render`
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
also compile the source to generated the required symbols JARs. Then it will generate the types, and finally apply
|
|
27
|
-
some post-processing to the generated types to make usable :
|
|
29
|
+
This component renders a Jahia component out of a node or a JS object.
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
```tsx
|
|
32
|
+
// Render a JCR node
|
|
33
|
+
<Render node={node} />
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
// Render a JS object
|
|
36
|
+
<Render content={{ nodeType: "ns:nodeType" }}>
|
|
37
|
+
```
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
### `RenderChild`
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
This component renders a child node of the current node. It's a thin wrapper around `Render` and `AddContentButtons`.
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
<RenderChild name="child" />
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### `RenderChildren`
|
|
48
|
+
|
|
49
|
+
This component renders all children of the current node. It's a thin wrapper around `Render`, `getChildNodes` and `AddContentButtons`.
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
<RenderChildren />
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Components
|
|
56
|
+
|
|
57
|
+
### `AbsoluteArea`
|
|
58
|
+
|
|
59
|
+
This component creates an absolute area in the page. It's an area of user-contributable content, child of the node of your choice.
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
<AbsoluteArea name="footer" parent={renderContext.getSite().getHome()} />
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### `Area`
|
|
66
|
+
|
|
67
|
+
This component creates an area in the page. It's an area of user-contributable content that is local to the page where it is present.
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
<Area name="main" />
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### `AddContentButtons`
|
|
74
|
+
|
|
75
|
+
This component renders a set of buttons to add content to the current node.
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
<AddContentButtons />
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### `AddResources`
|
|
82
|
+
|
|
83
|
+
This component adds resources to the page, making sure they are loaded only once and insert them at the desired position.
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
<AddResources type="css" resources="styles.css" />
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Declaration and registration
|
|
90
|
+
|
|
91
|
+
### `jahiaComponent`
|
|
92
|
+
|
|
93
|
+
This function is used to declare a Jahia component. It takes a component definition as first argument, and a React component as second argument.
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
jahiaComponent(
|
|
97
|
+
{
|
|
98
|
+
componentType: "view",
|
|
99
|
+
nodeType: "ns:hello",
|
|
100
|
+
},
|
|
101
|
+
({ name }: { name: string }) => {
|
|
102
|
+
return <h1>Hello {name}!</h1>;
|
|
103
|
+
},
|
|
104
|
+
);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The first argument of the component function is an object containing the JCR properties of the node being rendered. The server context is passed as the second argument. See `useServerContext` for more information.
|
|
108
|
+
|
|
109
|
+
## Hooks
|
|
110
|
+
|
|
111
|
+
### `useGQLQuery`
|
|
112
|
+
|
|
113
|
+
This hook is used to execute a GraphQL query on the current Jahia instance.
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
const { data, errors } = useGQLQuery({
|
|
117
|
+
query: /* GraphQL */ `
|
|
118
|
+
query MyQuery($workspace: Workspace!) {
|
|
119
|
+
jcr(workspace: $workspace) {
|
|
120
|
+
workspace
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
`,
|
|
124
|
+
variables: {
|
|
125
|
+
workspace: "LIVE",
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### `useJCRQuery`
|
|
131
|
+
|
|
132
|
+
This hook is used to execute a JCR query on the current Jahia instance.
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
const pages = useJCRQuery({ query: "SELECT * FROM [jnt:page]" });
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### `useServerContext`
|
|
139
|
+
|
|
140
|
+
This hook is used to access the server context, which contains information about the current node, page, and rendering context.
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
const {
|
|
144
|
+
/**
|
|
145
|
+
* Jahia's rendering context, it provides access to all kinds of context information, such as the
|
|
146
|
+
* current request, response, user, mode, mainResource and more
|
|
147
|
+
*/
|
|
148
|
+
renderContext,
|
|
149
|
+
/**
|
|
150
|
+
* The current resource being rendered, which is a combination of the current node and its
|
|
151
|
+
* template/view information
|
|
152
|
+
*/
|
|
153
|
+
currentResource,
|
|
154
|
+
/** The current JCR node being rendered */
|
|
155
|
+
currentNode,
|
|
156
|
+
/** The main JCR node being rendered, which is the root node of the current page */
|
|
157
|
+
mainNode,
|
|
158
|
+
/** The OSGi bundle key of the current module being rendered */
|
|
159
|
+
bundleKey,
|
|
160
|
+
} = useServerContext();
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
You do not need to use this hook when rendering a component with `jahiaComponent`, as the server context is passed as the second argument of the component function.
|
|
164
|
+
|
|
165
|
+
## JCR utils
|
|
166
|
+
|
|
167
|
+
### `getChildNodes`
|
|
168
|
+
|
|
169
|
+
This function is used to get the child nodes of a JCR node.
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
const children = getChildNodes(node, limit, offset, filter);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### `getNodeProps`
|
|
176
|
+
|
|
177
|
+
This function is used to get the properties of a JCR node.
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
const { title, description } = getNodeProps(node, ["title", "description"]);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### `getNodesByJCRQuery`
|
|
184
|
+
|
|
185
|
+
This function is used to get nodes by a JCR query.
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
const pages = getNodesByJCRQuery(session, "SELECT * FROM [jnt:page]", limit, offset);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## URL builder
|
|
192
|
+
|
|
193
|
+
### `buildEndpointUrl`
|
|
194
|
+
|
|
195
|
+
This function transforms a path to an endpoint into a full URL.
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
const dashboard = buildEndpointUrl("/jahia/dashboard");
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### `buildNodeUrl`
|
|
202
|
+
|
|
203
|
+
This function transforms a JCR node into a full URL to the node.
|
|
204
|
+
|
|
205
|
+
```tsx
|
|
206
|
+
const home = buildNodeUrl(renderContext.getSite().getHome().getNode());
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### `buildModuleFileUrl`
|
|
210
|
+
|
|
211
|
+
This function transforms a path to a file in the module into a full URL.
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
const styles = buildModuleFileUrl("dist/styles.css");
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Java server API
|
|
218
|
+
|
|
219
|
+
### `server`
|
|
220
|
+
|
|
221
|
+
This variable provides access to the Java server API.
|
|
222
|
+
|
|
223
|
+
```tsx
|
|
224
|
+
const bundle = server.osgi.getBundle(bundleKey);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Remarks
|
|
228
|
+
|
|
229
|
+
This module does not contain actual implementations of the components and hooks. All accesses to `@jahia/javascript-modules-engine` must be replaced by `javascriptModulesLibraryBuilder.getSharedLibrary('@jahia/javascript-modules-engine')` in the final bundle. This is done automatically during the build process if you use [@jahia/vite-plugin](https://www.npmjs.com/package/@jahia/vite-plugin).
|
|
@@ -1,39 +1,64 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
|
+
import type { JCRNodeWrapper } from "org.jahia.services.content";
|
|
2
3
|
/**
|
|
3
4
|
* Generates an absolute area in which editors may insert content objects.
|
|
4
5
|
*
|
|
5
6
|
* @returns The AbsoluteArea component
|
|
6
7
|
*/
|
|
7
|
-
export declare function AbsoluteArea({ name,
|
|
8
|
+
export declare function AbsoluteArea({ name, parent, areaView, view, allowedTypes, allowedNodeTypes, numberOfItems, readOnly, areaType, nodeType, parameters, }: Readonly<{
|
|
8
9
|
/** The name of the area. */
|
|
9
|
-
name
|
|
10
|
-
/**
|
|
10
|
+
name: string;
|
|
11
|
+
/**
|
|
12
|
+
* Parent node where the area is stored in the JCR. Can be anywhere in the JCR. The parent node
|
|
13
|
+
* must exist.
|
|
14
|
+
*/
|
|
15
|
+
parent: JCRNodeWrapper;
|
|
16
|
+
/**
|
|
17
|
+
* The view to use for the area.
|
|
18
|
+
*
|
|
19
|
+
* @deprecated Use {@link #view} instead
|
|
20
|
+
*/
|
|
11
21
|
areaView?: string;
|
|
12
|
-
/** The
|
|
22
|
+
/** The view to use for the area. */
|
|
23
|
+
view?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The allowed types for the area.
|
|
26
|
+
*
|
|
27
|
+
* @deprecated Use {@link #allowedNodeTypes} instead
|
|
28
|
+
*/
|
|
13
29
|
allowedTypes?: string[];
|
|
30
|
+
/** The allowed types for the area. */
|
|
31
|
+
allowedNodeTypes?: string[];
|
|
14
32
|
/** The number of items to display in the area. */
|
|
15
33
|
numberOfItems?: number;
|
|
16
|
-
/** The view to use for the subnodes. */
|
|
17
|
-
subNodesView?: string;
|
|
18
|
-
/** Relative (to the current node) or absolute path to the node to include. */
|
|
19
|
-
path?: string;
|
|
20
34
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
35
|
+
* Makes the area read-only.
|
|
36
|
+
*
|
|
37
|
+
* - When set to `false` (default), the area is editable on all pages.
|
|
38
|
+
* - When set to `true`, the area is read-only on all pages.
|
|
39
|
+
* - When set to `"children"`, the area is read-only on all pages except the one containing its
|
|
40
|
+
* node.
|
|
23
41
|
*
|
|
24
|
-
* @default
|
|
42
|
+
* @default false
|
|
25
43
|
*/
|
|
26
|
-
|
|
27
|
-
/** Ancestor level for absolute area - 0 is Home page, 1 first sub-pages, ... */
|
|
28
|
-
level?: number;
|
|
44
|
+
readOnly?: boolean | "children";
|
|
29
45
|
/**
|
|
30
|
-
*
|
|
46
|
+
* Node type to be used to create the area (if the node does not exist yet)
|
|
31
47
|
*
|
|
48
|
+
* @deprecated Use {@link #nodeType} instead
|
|
32
49
|
* @default jnt:contentList
|
|
33
50
|
*/
|
|
34
51
|
areaType?: string;
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Node type to be used to create the area (if the node does not exist yet)
|
|
54
|
+
*
|
|
55
|
+
* @default jnt:contentList
|
|
56
|
+
*/
|
|
57
|
+
nodeType?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Map of custom parameters that can be passed to the backend engine for advanced logic.
|
|
60
|
+
*
|
|
61
|
+
* @deprecated Not recommended
|
|
62
|
+
*/
|
|
38
63
|
parameters?: Record<string, unknown>;
|
|
39
64
|
}>): React.JSX.Element;
|
|
@@ -24,7 +24,7 @@ export declare function AddResources(props: Readonly<{
|
|
|
24
24
|
* The type of the resource. This could be 'javascript' for .js files, 'css' for .css files,
|
|
25
25
|
* etc.
|
|
26
26
|
*/
|
|
27
|
-
type?: "javascript" | "css";
|
|
27
|
+
type?: "javascript" | "css" | "inline";
|
|
28
28
|
/** The path to the resource file, relative to the module. */
|
|
29
29
|
resources?: string;
|
|
30
30
|
/** Inline HTML that markup will be considered as resource. */
|
|
@@ -4,34 +4,50 @@ import type { JSX } from "react";
|
|
|
4
4
|
*
|
|
5
5
|
* @returns The Area component
|
|
6
6
|
*/
|
|
7
|
-
export declare function Area({ name, areaView,
|
|
7
|
+
export declare function Area({ name, areaView, view, allowedTypes, allowedNodeTypes, numberOfItems, readOnly, areaType, nodeType, parameters, }: Readonly<{
|
|
8
8
|
/** The name of the area. */
|
|
9
|
-
name
|
|
10
|
-
/**
|
|
9
|
+
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* The view to use for the area.
|
|
12
|
+
*
|
|
13
|
+
* @deprecated Use {@link #view} instead
|
|
14
|
+
*/
|
|
11
15
|
areaView?: string;
|
|
12
|
-
/** The
|
|
16
|
+
/** The view to use for the area. */
|
|
17
|
+
view?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The allowed types for the area.
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Use {@link #allowedNodeTypes} instead
|
|
22
|
+
*/
|
|
13
23
|
allowedTypes?: string[];
|
|
24
|
+
/** The allowed types for the area. */
|
|
25
|
+
allowedNodeTypes?: string[];
|
|
14
26
|
/** The number of items to display in the area. */
|
|
15
27
|
numberOfItems?: number;
|
|
16
|
-
/** The view to use for the subnodes. */
|
|
17
|
-
subNodesView?: string;
|
|
18
|
-
/** Relative (to the current node) or absolute path to the node to include. */
|
|
19
|
-
path?: string;
|
|
20
28
|
/**
|
|
21
|
-
*
|
|
22
|
-
* references.
|
|
29
|
+
* Makes the area read-only.
|
|
23
30
|
*
|
|
24
|
-
* @default
|
|
31
|
+
* @default false
|
|
25
32
|
*/
|
|
26
|
-
|
|
27
|
-
/** Allow area to be stored as a subnode */
|
|
28
|
-
areaAsSubNode?: boolean;
|
|
33
|
+
readOnly?: boolean;
|
|
29
34
|
/**
|
|
30
|
-
*
|
|
35
|
+
* Node type to be used to create the area (if the node does not exist yet)
|
|
31
36
|
*
|
|
37
|
+
* @deprecated Use {@link #nodeType} instead
|
|
32
38
|
* @default jnt:contentList
|
|
33
39
|
*/
|
|
34
40
|
areaType?: string;
|
|
35
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Node type to be used to create the area (if the node does not exist yet)
|
|
43
|
+
*
|
|
44
|
+
* @default jnt:contentList
|
|
45
|
+
*/
|
|
46
|
+
nodeType?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Map of custom parameters that can be passed to the backend engine for advanced logic.
|
|
49
|
+
*
|
|
50
|
+
* @deprecated Not recommended
|
|
51
|
+
*/
|
|
36
52
|
parameters?: Record<string, unknown>;
|
|
37
53
|
}>): JSX.Element;
|
|
@@ -16,7 +16,7 @@ export declare function HydrateInBrowser<T, U>(props: Readonly<{
|
|
|
16
16
|
* [devalue](https://www.npmjs.com/package/devalue) allowing most standard JS types, including
|
|
17
17
|
* `Set` and `Map`.
|
|
18
18
|
*/
|
|
19
|
-
props: Omit<T & React.JSX.IntrinsicAttributes,
|
|
19
|
+
props: Omit<T & React.JSX.IntrinsicAttributes, "children">;
|
|
20
20
|
children: U;
|
|
21
21
|
}>): React.JSX.Element;
|
|
22
22
|
export declare function HydrateInBrowser<U>(props: Readonly<{
|
|
@@ -4,7 +4,7 @@ import type { JCRNodeWrapper } from "org.jahia.services.content";
|
|
|
4
4
|
*
|
|
5
5
|
* @returns The rendered output of the view for the specified content
|
|
6
6
|
*/
|
|
7
|
-
export declare function Render({ content, node, path,
|
|
7
|
+
export declare function Render({ content, node, path, readOnly, advanceRenderingConfig, templateType, view, parameters, }: Readonly<{
|
|
8
8
|
/** The content node to render */
|
|
9
9
|
content?: unknown;
|
|
10
10
|
/** The node to render */
|
|
@@ -12,11 +12,11 @@ export declare function Render({ content, node, path, editable, advanceRendering
|
|
|
12
12
|
/** The path to render */
|
|
13
13
|
path?: string;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Makes the child read-only.
|
|
16
16
|
*
|
|
17
|
-
* @default
|
|
17
|
+
* @default false
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
readOnly?: boolean;
|
|
20
20
|
/**
|
|
21
21
|
* Specifies if we should render a node or simply include a view. Acceptable values are : none,
|
|
22
22
|
* INCLUDE or OPTION
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JSX } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Renders a child of the current node, designated by its name.
|
|
4
|
+
*
|
|
5
|
+
* If the child node does not exist, it will display the "Add content" buttons.
|
|
6
|
+
*/
|
|
7
|
+
export declare function RenderChild({ name, view, }: {
|
|
8
|
+
/**
|
|
9
|
+
* The name of the child node to render.
|
|
10
|
+
*
|
|
11
|
+
* In the CND file, it's what's after the `+` in the child node definition: `+ name (type)`.
|
|
12
|
+
*/
|
|
13
|
+
name: string;
|
|
14
|
+
/** View to use when rendering the child. */
|
|
15
|
+
view?: string | undefined;
|
|
16
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { JSX } from "react";
|
|
2
|
+
import type { JCRNodeWrapper } from "org.jahia.services.content";
|
|
3
|
+
/** Renders the children of the current node, and "Add content" buttons afterwards. */
|
|
4
|
+
export declare function RenderChildren({ view, pagination, filter, }: {
|
|
5
|
+
/** View to use when rendering the children. */
|
|
6
|
+
view?: string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Pagination parameters:
|
|
9
|
+
*
|
|
10
|
+
* - `{ count: number; start?: number }` to specify the number of children to display and the
|
|
11
|
+
* starting index (defaults to 0).
|
|
12
|
+
* - `{ count: number; page: number }` to specify the number of children to display and the page
|
|
13
|
+
* number.
|
|
14
|
+
*
|
|
15
|
+
* If not provided, all children will be displayed.
|
|
16
|
+
*/
|
|
17
|
+
pagination?: {
|
|
18
|
+
count: number;
|
|
19
|
+
start?: number;
|
|
20
|
+
} | {
|
|
21
|
+
count: number;
|
|
22
|
+
page: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Filter to apply to the children:
|
|
26
|
+
*
|
|
27
|
+
* - A string to filter by node type.
|
|
28
|
+
* - A function to filter by custom logic.
|
|
29
|
+
*
|
|
30
|
+
* @default "jnt:content"
|
|
31
|
+
*/
|
|
32
|
+
filter?: string | ((node: JCRNodeWrapper) => boolean);
|
|
33
|
+
}): JSX.Element;
|
|
@@ -15,6 +15,13 @@ export interface JahiaComponent {
|
|
|
15
15
|
componentType: "template" | "view";
|
|
16
16
|
/** The content node type the component applies to. */
|
|
17
17
|
nodeType: string;
|
|
18
|
+
/**
|
|
19
|
+
* The priority of the components in case multiple templates/views are applicable to a given
|
|
20
|
+
* resource. The component with the highest priority has precedence over the other components.
|
|
21
|
+
*
|
|
22
|
+
* @default 0
|
|
23
|
+
*/
|
|
24
|
+
priority?: number;
|
|
18
25
|
/** Properties to add on the component, optional. */
|
|
19
26
|
properties?: Record<string, string>;
|
|
20
27
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type ReactNode } from "react";
|
|
1
|
+
import { type ReactNode, type JSX } from "react";
|
|
2
2
|
import type { RenderContext, Resource } from "org.jahia.services.render";
|
|
3
|
-
import type { JCRNodeWrapper } from "org.jahia.services.content";
|
|
3
|
+
import type { JCRNodeWrapper, JCRSessionWrapper } from "org.jahia.services.content";
|
|
4
4
|
/**
|
|
5
5
|
* A context object that gives access to the underlying Jahia Java objects that are part of the
|
|
6
6
|
* current rendering context
|
|
@@ -20,6 +20,8 @@ export interface ServerContext {
|
|
|
20
20
|
currentNode: JCRNodeWrapper;
|
|
21
21
|
/** The main JCR node being rendered, which is the root node of the current page */
|
|
22
22
|
mainNode: JCRNodeWrapper;
|
|
23
|
+
/** The JCR Session of the current user in its current language * */
|
|
24
|
+
jcrSession: JCRSessionWrapper;
|
|
23
25
|
/** The OSGi bundle key of the current module being rendered */
|
|
24
26
|
bundleKey: string;
|
|
25
27
|
}
|
|
@@ -29,6 +31,6 @@ export interface ServerContext {
|
|
|
29
31
|
* @returns The server context
|
|
30
32
|
*/
|
|
31
33
|
export declare function useServerContext(): ServerContext;
|
|
32
|
-
export declare function ServerContextProvider({ renderContext, currentResource, currentNode, mainNode, bundleKey, children, }: ServerContext & {
|
|
34
|
+
export declare function ServerContextProvider({ renderContext, currentResource, currentNode, mainNode, jcrSession, bundleKey, children, }: ServerContext & {
|
|
33
35
|
readonly children: ReactNode;
|
|
34
|
-
}):
|
|
36
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Locale } from "java.util";
|
|
2
|
+
import type { RenderContext } from "org.jahia.services.render";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the locales available on the site, as a record of language code (e.g. en_US) to locale
|
|
5
|
+
* object.
|
|
6
|
+
*
|
|
7
|
+
* If not provided, the `renderContext` is taken from the current server context.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getSiteLocales({ renderContext }?: {
|
|
10
|
+
renderContext: RenderContext;
|
|
11
|
+
}): Record<string, Locale>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Node } from "javax.jcr";
|
|
2
1
|
import type { JCRNodeWrapper } from "org.jahia.services.content";
|
|
3
2
|
/**
|
|
4
3
|
* Returns an array of child nodes of a given node.
|
|
@@ -11,4 +10,4 @@ import type { JCRNodeWrapper } from "org.jahia.services.content";
|
|
|
11
10
|
* @param filter A function to filter the nodes to be returned.
|
|
12
11
|
* @returns An array of child nodes.
|
|
13
12
|
*/
|
|
14
|
-
export declare function getChildNodes(node: JCRNodeWrapper, limit
|
|
13
|
+
export declare function getChildNodes(node: JCRNodeWrapper, limit?: number | undefined, offset?: number, filter?: ((node: JCRNodeWrapper) => boolean) | undefined): JCRNodeWrapper[];
|
|
@@ -11,4 +11,4 @@ import type { JCRSessionWrapper } from "org.jahia.services.content";
|
|
|
11
11
|
* @param offset The offset to start from
|
|
12
12
|
* @returns An array containing the nodes returned by the query
|
|
13
13
|
*/
|
|
14
|
-
export declare function getNodesByJCRQuery(session: JCRSessionWrapper, query: string, limit
|
|
14
|
+
export declare function getNodesByJCRQuery(session: JCRSessionWrapper, query: string, limit?: number | undefined, offset?: number): Node[];
|
|
@@ -1,25 +1,62 @@
|
|
|
1
|
+
import type { JCRNodeWrapper } from "org.jahia.services.content";
|
|
1
2
|
import type { RenderContext, Resource } from "org.jahia.services.render";
|
|
2
3
|
/** Initialize the registry with default url builders */
|
|
3
4
|
export declare function initUrlBuilder(): void;
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
* found, it will log an warning and return '#'
|
|
6
|
+
* Generate a Jahia url for the provided node.
|
|
7
7
|
*
|
|
8
|
-
* @param renderContext The current renderContext
|
|
9
|
-
* @param currentResource The current resource
|
|
10
8
|
* @returns The final URL
|
|
11
9
|
*/
|
|
12
|
-
export declare function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/** The
|
|
16
|
-
path?: string;
|
|
17
|
-
/** The parameters to append to the URL */
|
|
10
|
+
export declare function buildNodeUrl(
|
|
11
|
+
/** The node to build the URL for */
|
|
12
|
+
node: JCRNodeWrapper, config?: {
|
|
13
|
+
/** The querystring parameters to append to the URL */
|
|
18
14
|
parameters?: Record<string, string>;
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The mode to use to build the URL. Defines the mode or override the one provided by the
|
|
17
|
+
* renderContext.
|
|
18
|
+
*/
|
|
19
|
+
mode?: "edit" | "preview" | "live";
|
|
20
|
+
/**
|
|
21
|
+
* The language to use to build the URL. Defines the languages or overrides the one provided by
|
|
22
|
+
* the current resource
|
|
23
|
+
*/
|
|
22
24
|
language?: string;
|
|
23
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* The extension to use to build the URL. Defines the extension or overrides the one provided by
|
|
27
|
+
* the current resource
|
|
28
|
+
*/
|
|
24
29
|
extension?: string;
|
|
25
|
-
},
|
|
30
|
+
}, context?: {
|
|
31
|
+
/** Provided in react context, but you need to provide one otherwise. * */
|
|
32
|
+
renderContext?: RenderContext;
|
|
33
|
+
/** Provided in react context, you need to provide one otherwise. * */
|
|
34
|
+
currentResource?: Resource;
|
|
35
|
+
}): string;
|
|
36
|
+
/**
|
|
37
|
+
* Build a URL for a file in a module. Note that to be accessible, the folder that contains the file
|
|
38
|
+
* must be part of the jahia.static-resources in package.json.
|
|
39
|
+
*
|
|
40
|
+
* The URL must not be absolute (start with a / or a protocol).
|
|
41
|
+
*/
|
|
42
|
+
export declare function buildModuleFileUrl(
|
|
43
|
+
/** Relative path of the file from the module's root (examples: css/my.css, images/myImage.webp) */
|
|
44
|
+
filePath: string, config?: {
|
|
45
|
+
/** Defines a custom module name to access its files */
|
|
46
|
+
moduleName?: string;
|
|
47
|
+
/** Querystring parameters to append to the URL */
|
|
48
|
+
parameters?: Record<string, string>;
|
|
49
|
+
}, context?: {
|
|
50
|
+
/** Provided in react context, you need to provide one (or the module name) otherwise. */
|
|
51
|
+
renderContext?: RenderContext;
|
|
52
|
+
}): string;
|
|
53
|
+
/** Build an url for any endpoint on the server (/cms/*, /graphql, ect). */
|
|
54
|
+
export declare function buildEndpointUrl(
|
|
55
|
+
/** Endpoint to call */
|
|
56
|
+
endpoint: string, config?: {
|
|
57
|
+
/** Querystring parameters to append to the URL */
|
|
58
|
+
parameters?: Record<string, string>;
|
|
59
|
+
}, context?: {
|
|
60
|
+
/** Provided in react context, you need to provide one otherwise. */
|
|
61
|
+
renderContext?: RenderContext;
|
|
62
|
+
}): string;
|
package/dist/globals.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ declare module "virtual:jahia-server" {
|
|
|
17
17
|
import type {
|
|
18
18
|
ConfigHelper,
|
|
19
19
|
GQLHelper,
|
|
20
|
+
JcrHelper,
|
|
20
21
|
OSGiHelper,
|
|
21
22
|
RegistryHelper,
|
|
22
23
|
RenderHelper,
|
|
@@ -28,6 +29,8 @@ declare module "virtual:jahia-server" {
|
|
|
28
29
|
const server: {
|
|
29
30
|
/** This helper provides access to OSGi configuration */
|
|
30
31
|
config: ConfigHelper;
|
|
32
|
+
/** This helper allows to perform JCR operations */
|
|
33
|
+
jcr: JcrHelper;
|
|
31
34
|
/** This helper provides access Jahia's GraphQL API, to execute queries and mutations */
|
|
32
35
|
gql: GQLHelper;
|
|
33
36
|
/** This helper provides access to OSGi bundle for resource loading and service access */
|