@dotcms/client 0.0.1-alpha.4 → 0.0.1-alpha.41
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 +17 -6
- package/index.cjs.d.ts +1 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +1953 -0
- package/index.cjs.mjs +2 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +1944 -0
- package/package.json +19 -7
- package/src/index.d.ts +6 -2
- package/src/lib/client/content/builders/collection/collection.d.ts +226 -0
- package/src/lib/client/content/content-api.d.ts +129 -0
- package/src/lib/client/content/shared/const.d.ts +13 -0
- package/src/lib/client/content/shared/types.d.ts +138 -0
- package/src/lib/client/content/shared/utils.d.ts +20 -0
- package/src/lib/client/models/index.d.ts +12 -0
- package/src/lib/client/models/types.d.ts +13 -0
- package/src/lib/client/sdk-js-client.d.ts +276 -0
- package/src/lib/editor/listeners/listeners.d.ts +50 -0
- package/src/lib/{postMessageToEditor.d.ts → editor/models/client.model.d.ts} +33 -2
- package/src/lib/editor/models/editor.model.d.ts +49 -0
- package/src/lib/editor/models/listeners.model.d.ts +47 -0
- package/src/lib/editor/sdk-editor-vtl.d.ts +6 -0
- package/src/lib/editor/sdk-editor.d.ts +54 -0
- package/src/lib/editor/utils/editor.utils.d.ts +159 -0
- package/src/lib/query-builder/lucene-syntax/Equals.d.ts +114 -0
- package/src/lib/query-builder/lucene-syntax/Field.d.ts +32 -0
- package/src/lib/query-builder/lucene-syntax/NotOperand.d.ts +26 -0
- package/src/lib/query-builder/lucene-syntax/Operand.d.ts +44 -0
- package/src/lib/query-builder/lucene-syntax/index.d.ts +4 -0
- package/src/lib/query-builder/sdk-query-builder.d.ts +76 -0
- package/src/lib/query-builder/utils/index.d.ts +142 -0
- package/src/lib/utils/graphql/transforms.d.ts +24 -0
- package/src/lib/utils/index.d.ts +2 -0
- package/src/lib/utils/page/common-utils.d.ts +33 -0
- package/src/index.js +0 -3
- package/src/index.js.map +0 -1
- package/src/lib/postMessageToEditor.js +0 -42
- package/src/lib/postMessageToEditor.js.map +0 -1
- package/src/lib/sdk-js-client.d.ts +0 -183
- package/src/lib/sdk-js-client.js +0 -145
- package/src/lib/sdk-js-client.js.map +0 -1
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { Content } from './content/content-api';
|
|
2
|
+
export type ClientOptions = Omit<RequestInit, 'body' | 'method'>;
|
|
3
|
+
export interface ClientConfig {
|
|
4
|
+
/**
|
|
5
|
+
* The URL of the dotCMS instance.
|
|
6
|
+
*
|
|
7
|
+
* @description This is the URL of the dotCMS instance you want to interact with. Ensure to include the protocol (http or https).
|
|
8
|
+
* @example `https://demo.dotcms.com`
|
|
9
|
+
* @type {string}
|
|
10
|
+
* @required
|
|
11
|
+
*/
|
|
12
|
+
dotcmsUrl: string;
|
|
13
|
+
/**
|
|
14
|
+
* The id of the site you want to interact with. If not provided, it will use the default site.
|
|
15
|
+
*
|
|
16
|
+
* More information here: {@link https://www.dotcms.com/docs/latest/multi-site-management}
|
|
17
|
+
*
|
|
18
|
+
* @description To get the site id, go to the site you want to interact with and copy the id from the History tab.
|
|
19
|
+
* @type {string}
|
|
20
|
+
* @optional
|
|
21
|
+
*/
|
|
22
|
+
siteId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The authentication token to use for the requests.
|
|
25
|
+
*
|
|
26
|
+
* @description You can get the auth token from our UI {@link https://www.dotcms.com/docs/latest/rest-api-authentication#creating-an-api-token-in-the-ui}
|
|
27
|
+
* @type {string}
|
|
28
|
+
* @required
|
|
29
|
+
*/
|
|
30
|
+
authToken: string;
|
|
31
|
+
/**
|
|
32
|
+
* Additional options to pass to the fetch request.
|
|
33
|
+
*
|
|
34
|
+
* @description These options will be used in the fetch request. Any option can be specified except for 'body' and 'method' which are omitted.
|
|
35
|
+
* @example `{ headers: { 'Content-Type': 'application/json' } }`
|
|
36
|
+
* @type {ClientOptions}
|
|
37
|
+
* @optional
|
|
38
|
+
*/
|
|
39
|
+
requestOptions?: ClientOptions;
|
|
40
|
+
}
|
|
41
|
+
export type PageApiOptions = {
|
|
42
|
+
/**
|
|
43
|
+
* The path of the page you want to retrieve.
|
|
44
|
+
* @type {string}
|
|
45
|
+
*/
|
|
46
|
+
path: string;
|
|
47
|
+
/**
|
|
48
|
+
* The id of the site you want to interact with. If not provided, the one from the config will be used.
|
|
49
|
+
*
|
|
50
|
+
* More information here: {@link https://www.dotcms.com/docs/latest/multi-site-management}
|
|
51
|
+
* @type {string}
|
|
52
|
+
* @optional
|
|
53
|
+
*/
|
|
54
|
+
siteId?: string;
|
|
55
|
+
/**
|
|
56
|
+
* The mode of the page you want to retrieve. If not provided, will use the default mode of the site.
|
|
57
|
+
*
|
|
58
|
+
* More information here: {@link https://www.dotcms.com/docs/latest/page-viewing-modes}
|
|
59
|
+
* @type {string}
|
|
60
|
+
* @optional
|
|
61
|
+
*/
|
|
62
|
+
mode?: 'EDIT_MODE' | 'PREVIEW_MODE' | 'LIVE_MODE';
|
|
63
|
+
/**
|
|
64
|
+
* The language id of the page you want to retrieve. If not provided, will use the default language of the site.
|
|
65
|
+
* @type {number}
|
|
66
|
+
* @optional
|
|
67
|
+
*/
|
|
68
|
+
language_id?: number;
|
|
69
|
+
/**
|
|
70
|
+
* The id of the persona you want to retrieve the page for.
|
|
71
|
+
*
|
|
72
|
+
* More information here: {@link https://www.dotcms.com/docs/latest/personas}
|
|
73
|
+
* @type {string}
|
|
74
|
+
* @optional
|
|
75
|
+
*/
|
|
76
|
+
personaId?: string;
|
|
77
|
+
/**
|
|
78
|
+
* If you want to fire the rules set on the page.
|
|
79
|
+
*
|
|
80
|
+
* More information here: {@link https://www.dotcms.com/docs/latest/adding-rules-to-pages}
|
|
81
|
+
*
|
|
82
|
+
* @type {boolean}
|
|
83
|
+
* @optional
|
|
84
|
+
*/
|
|
85
|
+
fireRules?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Allows access to related content via the Relationship fields of contentlets on a Page; 0 (default).
|
|
88
|
+
* @type {number}
|
|
89
|
+
* @optional
|
|
90
|
+
*/
|
|
91
|
+
depth?: number;
|
|
92
|
+
};
|
|
93
|
+
type NavApiOptions = {
|
|
94
|
+
/**
|
|
95
|
+
* The root path to begin traversing the folder tree.
|
|
96
|
+
* @example
|
|
97
|
+
* `/api/v1/nav/` starts from the root of the site
|
|
98
|
+
* @example
|
|
99
|
+
* `/about-us` starts from the "About Us" folder
|
|
100
|
+
* @type {string}
|
|
101
|
+
*/
|
|
102
|
+
path: string;
|
|
103
|
+
/**
|
|
104
|
+
* The depth of the folder tree to return.
|
|
105
|
+
* @example
|
|
106
|
+
* `1` returns only the element specified in the path.
|
|
107
|
+
* @example
|
|
108
|
+
* `2` returns the element specified in the path, and if that element is a folder, returns all direct children of that folder.
|
|
109
|
+
* @example
|
|
110
|
+
* `3` returns all children and grandchildren of the element specified in the path.
|
|
111
|
+
* @type {number}
|
|
112
|
+
* @optional
|
|
113
|
+
*/
|
|
114
|
+
depth?: number;
|
|
115
|
+
/**
|
|
116
|
+
* The language ID of content to return.
|
|
117
|
+
* @example
|
|
118
|
+
* `1` (or unspecified) returns content in the default language of the site.
|
|
119
|
+
* @link https://www.dotcms.com/docs/latest/system-language-properties#DefaultLanguage
|
|
120
|
+
* @link https://www.dotcms.com/docs/latest/adding-and-editing-languages#LanguageID
|
|
121
|
+
* @type {number}
|
|
122
|
+
* @optional
|
|
123
|
+
*/
|
|
124
|
+
languageId?: number;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* `DotCmsClient` is a TypeScript class that provides methods to interact with the DotCMS REST API.
|
|
128
|
+
* DotCMS is a hybrid-headless CMS and digital experience platform.
|
|
129
|
+
*
|
|
130
|
+
* @class DotCmsClient
|
|
131
|
+
* @property {ClientConfig} config - The configuration object for the DotCMS client.
|
|
132
|
+
* @property {Content} content - Provides methods to interact with content in DotCMS.
|
|
133
|
+
*
|
|
134
|
+
* @method constructor(config: ClientConfig) - Constructs a new instance of the DotCmsClient class.
|
|
135
|
+
*
|
|
136
|
+
* @method page.get(options: PageApiOptions): Promise<PageApiResponse> - Retrieves all the elements of any Page in your dotCMS system in JSON format.
|
|
137
|
+
* The Page API enables you to retrieve page information, layout, template, content blocks, and more.
|
|
138
|
+
* @see {@link https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas}
|
|
139
|
+
*
|
|
140
|
+
* @method nav.get(options: NavApiOptions = { depth: 0, path: '/', languageId: 1 }): Promise<NavApiResponse> - Retrieves information about the dotCMS file and folder tree.
|
|
141
|
+
* The Navigation API allows you to fetch the site structure and menu items.
|
|
142
|
+
* @see {@link https://www.dotcms.com/docs/latest/navigation-rest-api}
|
|
143
|
+
*
|
|
144
|
+
* @method content.get(options: ContentApiOptions): Promise<ContentApiResponse> - Retrieves content items based on specified criteria.
|
|
145
|
+
* The Content API allows you to query and retrieve content by ID, inode, or using Lucene queries.
|
|
146
|
+
* @see {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying}
|
|
147
|
+
*
|
|
148
|
+
* @method editor.on(action: string, callbackFn: (payload: unknown) => void) - Allows you to react to actions issued by the Universal Visual Editor (UVE).
|
|
149
|
+
* @method editor.off(action: string) - Stops listening to an action issued by UVE.
|
|
150
|
+
*
|
|
151
|
+
* @static
|
|
152
|
+
* @method init(config: ClientConfig): DotCmsClient - Initializes and returns a DotCmsClient instance.
|
|
153
|
+
* @method dotcmsUrl: string - Retrieves the DotCMS URL from the instance configuration.
|
|
154
|
+
*
|
|
155
|
+
* @example <caption>Basic usage</caption>
|
|
156
|
+
* ```javascript
|
|
157
|
+
* const client = DotCmsClient.init({ dotcmsUrl: 'https://demo.dotcms.com', authToken: 'your-auth-token' });
|
|
158
|
+
*
|
|
159
|
+
* // Get a page
|
|
160
|
+
* client.page.get({ path: '/about-us' }).then(response => console.log(response));
|
|
161
|
+
*
|
|
162
|
+
* // Get navigation
|
|
163
|
+
* client.nav.get({ path: '/about-us', depth: 2 }).then(response => console.log(response));
|
|
164
|
+
*
|
|
165
|
+
* // Get content
|
|
166
|
+
* client.content.get({ query: '+contentType:Blog +languageId:1', limit: 10 }).then(response => console.log(response));
|
|
167
|
+
*
|
|
168
|
+
* // Listen to editor changes
|
|
169
|
+
* client.editor.on('changes', (payload) => console.log('Changes detected:', payload));
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare class DotCmsClient {
|
|
173
|
+
#private;
|
|
174
|
+
static instance: DotCmsClient;
|
|
175
|
+
dotcmsUrl?: string;
|
|
176
|
+
content: Content;
|
|
177
|
+
constructor(config?: ClientConfig);
|
|
178
|
+
page: {
|
|
179
|
+
/**
|
|
180
|
+
* `page.get` is an asynchronous method of the `DotCmsClient` class that retrieves all the elements of any Page in your dotCMS system in JSON format.
|
|
181
|
+
* It takes a `PageApiOptions` object as a parameter and returns a Promise that resolves to the response from the DotCMS API.
|
|
182
|
+
*
|
|
183
|
+
* The Page API enables you to retrieve all the elements of any Page in your dotCMS system.
|
|
184
|
+
* The elements may be retrieved in JSON format.
|
|
185
|
+
*
|
|
186
|
+
* @link https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas
|
|
187
|
+
* @async
|
|
188
|
+
* @param {PageApiOptions} options - The options for the Page API call.
|
|
189
|
+
* @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
|
|
190
|
+
* @throws {Error} - Throws an error if the options are not valid.
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* const client = new DotCmsClient({ dotcmsUrl: 'https://your.dotcms.com', authToken: 'your-auth-token', siteId: 'your-site-id' });
|
|
194
|
+
* client.page.get({ path: '/about-us' }).then(response => console.log(response));
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
get: (options: PageApiOptions) => Promise<unknown>;
|
|
198
|
+
};
|
|
199
|
+
editor: {
|
|
200
|
+
/**
|
|
201
|
+
* `editor.on` is an asynchronous method of the `DotCmsClient` class that allows you to react to actions issued by the UVE.
|
|
202
|
+
*
|
|
203
|
+
* NOTE: This is being used by the development team - This logic is probably varied or moved to another function/object.
|
|
204
|
+
* @param {string} action - The name of the action emitted by UVE.
|
|
205
|
+
* @param {function} callbackFn - The function to execute when the UVE emits the action.
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* client.editor.on('changes', (payload) => {
|
|
209
|
+
* console.log('Changes detected:', payload);
|
|
210
|
+
* });
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
on: (action: string, callbackFn: (payload: unknown) => void) => void;
|
|
214
|
+
/**
|
|
215
|
+
* `editor.off` is a synchronous method of the `DotCmsClient` class that allows you to stop listening and reacting to an action issued by UVE.
|
|
216
|
+
*
|
|
217
|
+
* NOTE: This is being used by the development team - This logic is probably varied or moved to another function/object.
|
|
218
|
+
* @param {string} action - The name of the action to stop listening to.
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* client.editor.off('changes');
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
off: (action: string) => void;
|
|
225
|
+
};
|
|
226
|
+
nav: {
|
|
227
|
+
/**
|
|
228
|
+
* `nav.get` is an asynchronous method of the `DotCmsClient` class that retrieves information about the dotCMS file and folder tree.
|
|
229
|
+
* It takes a `NavApiOptions` object as a parameter (with default values) and returns a Promise that resolves to the response from the DotCMS API.
|
|
230
|
+
*
|
|
231
|
+
* The navigation REST API enables you to retrieve information about the dotCMS file and folder tree through REST API calls.
|
|
232
|
+
* @link https://www.dotcms.com/docs/latest/navigation-rest-api
|
|
233
|
+
* @async
|
|
234
|
+
* @param {NavApiOptions} options - The options for the Nav API call. Defaults to `{ depth: 0, path: '/', languageId: 1 }`.
|
|
235
|
+
* @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
|
|
236
|
+
* @throws {Error} - Throws an error if the options are not valid.
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* const client = new DotCmsClient({ dotcmsUrl: 'https://your.dotcms.com', authToken: 'your-auth-token', siteId: 'your-site-id' }});
|
|
240
|
+
* client.nav.get({ path: '/about-us', depth: 2 }).then(response => console.log(response));
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
get: (options?: NavApiOptions) => Promise<unknown>;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Initializes the DotCmsClient instance with the provided configuration.
|
|
247
|
+
* If an instance already exists, it returns the existing instance.
|
|
248
|
+
*
|
|
249
|
+
* @param {ClientConfig} config - The configuration object for the DotCMS client.
|
|
250
|
+
* @returns {DotCmsClient} - The initialized DotCmsClient instance.
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* const client = DotCmsClient.init({ dotcmsUrl: 'https://demo.dotcms.com', authToken: 'your-auth-token' });
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
static init(config: ClientConfig): DotCmsClient;
|
|
257
|
+
/**
|
|
258
|
+
* Retrieves the DotCMS URL from the instance configuration.
|
|
259
|
+
*
|
|
260
|
+
* @returns {string} - The DotCMS URL.
|
|
261
|
+
*/
|
|
262
|
+
static get dotcmsUrl(): string;
|
|
263
|
+
/**
|
|
264
|
+
* Throws an error if the path is not valid.
|
|
265
|
+
*
|
|
266
|
+
* @returns {string} - The authentication token.
|
|
267
|
+
*/
|
|
268
|
+
private validatePageOptions;
|
|
269
|
+
/**
|
|
270
|
+
* Throws an error if the path is not valid.
|
|
271
|
+
*
|
|
272
|
+
* @returns {string} - The authentication token.
|
|
273
|
+
*/
|
|
274
|
+
private validateNavOptions;
|
|
275
|
+
}
|
|
276
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DotCMSPageEditorSubscription } from '../models/listeners.model';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
lastScrollYPosition: number;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Represents an array of DotCMSPageEditorSubscription objects.
|
|
9
|
+
* Used to store the subscriptions for the editor and unsubscribe later.
|
|
10
|
+
*/
|
|
11
|
+
export declare const subscriptions: DotCMSPageEditorSubscription[];
|
|
12
|
+
/**
|
|
13
|
+
* Listens for editor messages and performs corresponding actions based on the received message.
|
|
14
|
+
*
|
|
15
|
+
* @private
|
|
16
|
+
* @memberof DotCMSPageEditor
|
|
17
|
+
*/
|
|
18
|
+
export declare function listenEditorMessages(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Listens for pointer move events and extracts information about the hovered contentlet.
|
|
21
|
+
*
|
|
22
|
+
* @private
|
|
23
|
+
* @memberof DotCMSPageEditor
|
|
24
|
+
*/
|
|
25
|
+
export declare function listenHoveredContentlet(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Attaches a scroll event listener to the window
|
|
28
|
+
* and sends a message to the editor when the window is scrolled.
|
|
29
|
+
*
|
|
30
|
+
* @private
|
|
31
|
+
* @memberof DotCMSPageEditor
|
|
32
|
+
*/
|
|
33
|
+
export declare function scrollHandler(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Restores the scroll position of the window when an iframe is loaded.
|
|
36
|
+
* Only used in VTL Pages.
|
|
37
|
+
* @export
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* preserveScrollOnIframe();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function preserveScrollOnIframe(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Sends a message to the editor to get the page data.
|
|
46
|
+
* @param {string} pathname - The pathname of the page.
|
|
47
|
+
* @private
|
|
48
|
+
* @memberof DotCMSPageEditor
|
|
49
|
+
*/
|
|
50
|
+
export declare function fetchPageDataFromInsideUVE(pathname: string): void;
|
|
@@ -8,7 +8,7 @@ export declare enum CUSTOMER_ACTIONS {
|
|
|
8
8
|
/**
|
|
9
9
|
* Tell the dotcms editor that page change
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
NAVIGATION_UPDATE = "set-url",
|
|
12
12
|
/**
|
|
13
13
|
* Send the element position of the rows, columnsm containers and contentlets
|
|
14
14
|
*/
|
|
@@ -21,11 +21,42 @@ export declare enum CUSTOMER_ACTIONS {
|
|
|
21
21
|
* Tell the editor that the page is being scrolled
|
|
22
22
|
*/
|
|
23
23
|
IFRAME_SCROLL = "scroll",
|
|
24
|
+
/**
|
|
25
|
+
* Tell the editor that the page has stopped scrolling
|
|
26
|
+
*/
|
|
27
|
+
IFRAME_SCROLL_END = "scroll-end",
|
|
24
28
|
/**
|
|
25
29
|
* Ping the editor to see if the page is inside the editor
|
|
26
30
|
*/
|
|
27
31
|
PING_EDITOR = "ping-editor",
|
|
28
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Tell the editor to init the inline editing editor.
|
|
34
|
+
*/
|
|
35
|
+
INIT_INLINE_EDITING = "init-inline-editing",
|
|
36
|
+
/**
|
|
37
|
+
* Tell the editor to open the Copy-contentlet dialog
|
|
38
|
+
* To copy a content and then edit it inline.
|
|
39
|
+
*/
|
|
40
|
+
COPY_CONTENTLET_INLINE_EDITING = "copy-contentlet-inline-editing",
|
|
41
|
+
/**
|
|
42
|
+
* Tell the editor to save inline edited contentlet
|
|
43
|
+
*/
|
|
44
|
+
UPDATE_CONTENTLET_INLINE_EDITING = "update-contentlet-inline-editing",
|
|
45
|
+
/**
|
|
46
|
+
* Tell the editor to trigger a menu reorder
|
|
47
|
+
*/
|
|
48
|
+
REORDER_MENU = "reorder-menu",
|
|
49
|
+
/**
|
|
50
|
+
* Tell the editor to send the page info to iframe
|
|
51
|
+
*/
|
|
52
|
+
GET_PAGE_DATA = "get-page-data",
|
|
53
|
+
/**
|
|
54
|
+
* Tell the editor an user send a graphql query
|
|
55
|
+
*/
|
|
56
|
+
CLIENT_READY = "client-ready",
|
|
57
|
+
/**
|
|
58
|
+
* Tell the editor to do nothing
|
|
59
|
+
*/
|
|
29
60
|
NOOP = "noop"
|
|
30
61
|
}
|
|
31
62
|
/**
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Custom client parameters for fetching data.
|
|
3
|
+
*/
|
|
4
|
+
export type CustomClientParams = {
|
|
5
|
+
depth: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @description Union type for fetch configurations.
|
|
9
|
+
* @typedef {GraphQLFetchConfig | PageAPIFetchConfig} DotCMSFetchConfig
|
|
10
|
+
*/
|
|
11
|
+
export type EditorConfig = {
|
|
12
|
+
params: CustomClientParams;
|
|
13
|
+
} | {
|
|
14
|
+
query: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Represents the configuration options for the DotCMS page editor.
|
|
18
|
+
* @export
|
|
19
|
+
* @interface DotCMSPageEditorConfig
|
|
20
|
+
*/
|
|
21
|
+
export interface DotCMSPageEditorConfig {
|
|
22
|
+
/**
|
|
23
|
+
* The pathname of the page being edited. Optional.
|
|
24
|
+
* @type {string}
|
|
25
|
+
*/
|
|
26
|
+
pathname: string;
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @type {DotCMSFetchConfig}
|
|
30
|
+
* @memberof DotCMSPageEditorConfig
|
|
31
|
+
* @description The configuration custom params for data fetching on Edit Mode.
|
|
32
|
+
* @example <caption>Example with Custom GraphQL query</caption>
|
|
33
|
+
* const config: DotCMSPageEditorConfig = {
|
|
34
|
+
* editor: { query: 'query { ... }' }
|
|
35
|
+
* };
|
|
36
|
+
*
|
|
37
|
+
* @example <caption>Example usage with Custom Page API parameters</caption>
|
|
38
|
+
* const config: DotCMSPageEditorConfig = {
|
|
39
|
+
* editor: { params: { depth: '2' } }
|
|
40
|
+
* };
|
|
41
|
+
*/
|
|
42
|
+
editor?: EditorConfig;
|
|
43
|
+
/**
|
|
44
|
+
* The reload function to call when the page is reloaded.
|
|
45
|
+
* @deprecated In future implementation we will be listening for the changes from the editor to update the page state so reload will not be needed.
|
|
46
|
+
* @type {Function}
|
|
47
|
+
*/
|
|
48
|
+
onReload?: () => void;
|
|
49
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Actions received from the dotcms editor
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @enum {number}
|
|
6
|
+
*/
|
|
7
|
+
export declare enum NOTIFY_CUSTOMER {
|
|
8
|
+
/**
|
|
9
|
+
* Request to page to reload
|
|
10
|
+
*/
|
|
11
|
+
EMA_RELOAD_PAGE = "ema-reload-page",
|
|
12
|
+
/**
|
|
13
|
+
* Request the bounds for the elements
|
|
14
|
+
*/
|
|
15
|
+
EMA_REQUEST_BOUNDS = "ema-request-bounds",
|
|
16
|
+
/**
|
|
17
|
+
* Received pong from the editor
|
|
18
|
+
*/
|
|
19
|
+
EMA_EDITOR_PONG = "ema-editor-pong",
|
|
20
|
+
/**
|
|
21
|
+
* Received scroll event trigger from the editor
|
|
22
|
+
*/
|
|
23
|
+
EMA_SCROLL_INSIDE_IFRAME = "scroll-inside-iframe"
|
|
24
|
+
}
|
|
25
|
+
type ListenerCallbackMessage = (event: MessageEvent) => void;
|
|
26
|
+
type ListenerCallbackPointer = (event: PointerEvent) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Listener for the dotcms editor
|
|
29
|
+
*
|
|
30
|
+
* @interface DotCMSPageEditorListener
|
|
31
|
+
*/
|
|
32
|
+
interface DotCMSPageEditorListener {
|
|
33
|
+
type: 'listener';
|
|
34
|
+
event: string;
|
|
35
|
+
callback: ListenerCallbackMessage | ListenerCallbackPointer;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Observer for the dotcms editor
|
|
39
|
+
*
|
|
40
|
+
* @interface DotCMSPageEditorObserver
|
|
41
|
+
*/
|
|
42
|
+
interface DotCMSPageEditorObserver {
|
|
43
|
+
type: 'observer';
|
|
44
|
+
observer: MutationObserver;
|
|
45
|
+
}
|
|
46
|
+
export type DotCMSPageEditorSubscription = DotCMSPageEditorListener | DotCMSPageEditorObserver;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DotCMSPageEditorConfig } from './models/editor.model';
|
|
2
|
+
/**
|
|
3
|
+
* Updates the navigation in the editor.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} pathname - The pathname to update the navigation with.
|
|
6
|
+
* @memberof DotCMSPageEditor
|
|
7
|
+
* @example
|
|
8
|
+
* updateNavigation('/home'); // Sends a message to the editor to update the navigation to '/home'
|
|
9
|
+
*/
|
|
10
|
+
export declare function updateNavigation(pathname: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Checks if the code is running inside an editor.
|
|
13
|
+
*
|
|
14
|
+
* @returns {boolean} Returns true if the code is running inside an editor, otherwise false.
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* if (isInsideEditor()) {
|
|
18
|
+
* console.log('Running inside the editor');
|
|
19
|
+
* } else {
|
|
20
|
+
* console.log('Running outside the editor');
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function isInsideEditor(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Initializes the DotCMS page editor.
|
|
27
|
+
*
|
|
28
|
+
* @param {DotCMSPageEditorConfig} config - Optional configuration for the editor.
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const config = { pathname: '/home' };
|
|
32
|
+
* initEditor(config); // Initializes the editor with the provided configuration
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function initEditor(config: DotCMSPageEditorConfig): void;
|
|
36
|
+
/**
|
|
37
|
+
* Destroys the editor by removing event listeners and disconnecting observers.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* destroyEditor(); // Cleans up the editor by removing all event listeners and disconnecting observers
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function destroyEditor(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Adds a style class to empty contentlets.
|
|
47
|
+
*
|
|
48
|
+
* @export
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* addClassToEmptyContentlets(); // Adds the 'empty-contentlet' class to all contentlets that have no height
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function addClassToEmptyContentlets(): void;
|