@dotcms/client 0.0.1-alpha.40 → 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/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 +16 -4
- package/src/index.d.ts +6 -0
- package/src/lib/client/content/builders/collection/{collection.ts → collection.d.ts} +19 -209
- package/src/lib/client/content/{content-api.ts → content-api.d.ts} +4 -14
- package/src/lib/client/content/shared/{const.ts → const.d.ts} +3 -5
- package/src/lib/client/content/shared/{types.ts → types.d.ts} +2 -19
- package/src/lib/client/content/shared/{utils.ts → utils.d.ts} +1 -9
- package/src/lib/client/models/{index.ts → index.d.ts} +1 -8
- package/src/lib/client/models/{types.ts → types.d.ts} +0 -1
- package/src/lib/client/{sdk-js-client.ts → sdk-js-client.d.ts} +15 -181
- package/src/lib/editor/listeners/listeners.d.ts +50 -0
- package/src/lib/editor/models/{client.model.ts → client.model.d.ts} +16 -19
- package/src/lib/editor/models/{editor.model.ts → editor.model.d.ts} +5 -9
- package/src/lib/editor/models/{listeners.model.ts → listeners.model.d.ts} +6 -9
- 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.ts → editor.utils.d.ts} +22 -121
- package/src/lib/query-builder/lucene-syntax/{Equals.ts → Equals.d.ts} +11 -45
- package/src/lib/query-builder/lucene-syntax/{Field.ts → Field.d.ts} +5 -13
- package/src/lib/query-builder/lucene-syntax/{NotOperand.ts → NotOperand.d.ts} +5 -13
- package/src/lib/query-builder/lucene-syntax/{Operand.ts → Operand.d.ts} +7 -21
- package/src/lib/query-builder/{sdk-query-builder.ts → sdk-query-builder.d.ts} +5 -16
- package/src/lib/query-builder/utils/{index.ts → index.d.ts} +12 -49
- package/src/lib/utils/graphql/transforms.d.ts +24 -0
- package/src/lib/utils/page/common-utils.d.ts +33 -0
- package/.eslintrc.json +0 -18
- package/jest.config.ts +0 -15
- package/project.json +0 -72
- package/src/index.ts +0 -30
- package/src/lib/client/content/builders/collection/collection.spec.ts +0 -515
- package/src/lib/client/sdk-js-client.spec.ts +0 -483
- package/src/lib/editor/listeners/listeners.spec.ts +0 -119
- package/src/lib/editor/listeners/listeners.ts +0 -223
- package/src/lib/editor/sdk-editor-vtl.ts +0 -31
- package/src/lib/editor/sdk-editor.spec.ts +0 -116
- package/src/lib/editor/sdk-editor.ts +0 -105
- package/src/lib/editor/utils/editor.utils.spec.ts +0 -206
- package/src/lib/query-builder/sdk-query-builder.spec.ts +0 -159
- package/src/lib/utils/graphql/transforms.spec.ts +0 -150
- package/src/lib/utils/graphql/transforms.ts +0 -99
- package/src/lib/utils/page/common-utils.spec.ts +0 -37
- package/src/lib/utils/page/common-utils.ts +0 -64
- package/tsconfig.json +0 -22
- package/tsconfig.lib.json +0 -13
- package/tsconfig.spec.json +0 -9
- /package/src/lib/query-builder/lucene-syntax/{index.ts → index.d.ts} +0 -0
- /package/src/lib/utils/{index.ts → index.d.ts} +0 -0
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { Content } from './content/content-api';
|
|
2
|
-
import { ErrorMessages } from './models';
|
|
3
|
-
import { DotcmsClientListener } from './models/types';
|
|
4
|
-
|
|
5
|
-
import { isInsideEditor } from '../editor/sdk-editor';
|
|
6
|
-
|
|
7
2
|
export type ClientOptions = Omit<RequestInit, 'body' | 'method'>;
|
|
8
|
-
|
|
9
3
|
export interface ClientConfig {
|
|
10
4
|
/**
|
|
11
5
|
* The URL of the dotCMS instance.
|
|
@@ -44,7 +38,6 @@ export interface ClientConfig {
|
|
|
44
38
|
*/
|
|
45
39
|
requestOptions?: ClientOptions;
|
|
46
40
|
}
|
|
47
|
-
|
|
48
41
|
export type PageApiOptions = {
|
|
49
42
|
/**
|
|
50
43
|
* The path of the page you want to retrieve.
|
|
@@ -97,7 +90,6 @@ export type PageApiOptions = {
|
|
|
97
90
|
*/
|
|
98
91
|
depth?: number;
|
|
99
92
|
};
|
|
100
|
-
|
|
101
93
|
type NavApiOptions = {
|
|
102
94
|
/**
|
|
103
95
|
* The root path to begin traversing the folder tree.
|
|
@@ -131,15 +123,6 @@ type NavApiOptions = {
|
|
|
131
123
|
*/
|
|
132
124
|
languageId?: number;
|
|
133
125
|
};
|
|
134
|
-
|
|
135
|
-
function getHostURL(url: string): URL | undefined {
|
|
136
|
-
try {
|
|
137
|
-
return new URL(url);
|
|
138
|
-
} catch (error) {
|
|
139
|
-
return undefined;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
126
|
/**
|
|
144
127
|
* `DotCmsClient` is a TypeScript class that provides methods to interact with the DotCMS REST API.
|
|
145
128
|
* DotCMS is a hybrid-headless CMS and digital experience platform.
|
|
@@ -186,49 +169,13 @@ function getHostURL(url: string): URL | undefined {
|
|
|
186
169
|
* client.editor.on('changes', (payload) => console.log('Changes detected:', payload));
|
|
187
170
|
* ```
|
|
188
171
|
*/
|
|
189
|
-
export class DotCmsClient {
|
|
172
|
+
export declare class DotCmsClient {
|
|
173
|
+
#private;
|
|
190
174
|
static instance: DotCmsClient;
|
|
191
|
-
#config: ClientConfig;
|
|
192
|
-
#requestOptions!: ClientOptions;
|
|
193
|
-
#listeners: DotcmsClientListener[] = [];
|
|
194
|
-
|
|
195
175
|
dotcmsUrl?: string;
|
|
196
176
|
content: Content;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
config: ClientConfig = { dotcmsUrl: '', authToken: '', requestOptions: {}, siteId: '' }
|
|
200
|
-
) {
|
|
201
|
-
if (!config.dotcmsUrl) {
|
|
202
|
-
throw new Error("Invalid configuration - 'dotcmsUrl' is required");
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
this.dotcmsUrl = getHostURL(config.dotcmsUrl)?.origin;
|
|
206
|
-
|
|
207
|
-
if (!this.dotcmsUrl) {
|
|
208
|
-
throw new Error("Invalid configuration - 'dotcmsUrl' must be a valid URL");
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (!config.authToken) {
|
|
212
|
-
throw new Error("Invalid configuration - 'authToken' is required");
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
this.#config = {
|
|
216
|
-
...config,
|
|
217
|
-
dotcmsUrl: this.dotcmsUrl
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
this.#requestOptions = {
|
|
221
|
-
...this.#config.requestOptions,
|
|
222
|
-
headers: {
|
|
223
|
-
Authorization: `Bearer ${this.#config.authToken}`,
|
|
224
|
-
...this.#config.requestOptions?.headers
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
this.content = new Content(this.#requestOptions, this.#config.dotcmsUrl);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
page = {
|
|
177
|
+
constructor(config?: ClientConfig);
|
|
178
|
+
page: {
|
|
232
179
|
/**
|
|
233
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.
|
|
234
181
|
* It takes a `PageApiOptions` object as a parameter and returns a Promise that resolves to the response from the DotCMS API.
|
|
@@ -247,51 +194,9 @@ export class DotCmsClient {
|
|
|
247
194
|
* client.page.get({ path: '/about-us' }).then(response => console.log(response));
|
|
248
195
|
* ```
|
|
249
196
|
*/
|
|
250
|
-
get:
|
|
251
|
-
this.validatePageOptions(options);
|
|
252
|
-
|
|
253
|
-
const queryParamsObj: Record<string, string> = {};
|
|
254
|
-
for (const [key, value] of Object.entries(options)) {
|
|
255
|
-
if (value === undefined || key === 'path' || key === 'siteId') continue;
|
|
256
|
-
|
|
257
|
-
if (key === 'personaId') {
|
|
258
|
-
queryParamsObj['com.dotmarketing.persona.id'] = String(value);
|
|
259
|
-
} else if (key === 'mode' && value) {
|
|
260
|
-
queryParamsObj['mode'] = String(value);
|
|
261
|
-
} else {
|
|
262
|
-
queryParamsObj[key] = String(value);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const queryHostId = options.siteId ?? this.#config.siteId ?? '';
|
|
267
|
-
|
|
268
|
-
if (queryHostId) {
|
|
269
|
-
queryParamsObj['host_id'] = queryHostId;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const queryParams = new URLSearchParams(queryParamsObj).toString();
|
|
273
|
-
|
|
274
|
-
const formattedPath = options.path.startsWith('/') ? options.path : `/${options.path}`;
|
|
275
|
-
const url = `${this.#config.dotcmsUrl}/api/v1/page/json${formattedPath}${
|
|
276
|
-
queryParams ? `?${queryParams}` : ''
|
|
277
|
-
}`;
|
|
278
|
-
|
|
279
|
-
const response = await fetch(url, this.#requestOptions);
|
|
280
|
-
if (!response.ok) {
|
|
281
|
-
const error = {
|
|
282
|
-
status: response.status,
|
|
283
|
-
message: ErrorMessages[response.status] || response.statusText
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
console.error(error);
|
|
287
|
-
throw error;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return response.json().then((data) => data.entity);
|
|
291
|
-
}
|
|
197
|
+
get: (options: PageApiOptions) => Promise<unknown>;
|
|
292
198
|
};
|
|
293
|
-
|
|
294
|
-
editor = {
|
|
199
|
+
editor: {
|
|
295
200
|
/**
|
|
296
201
|
* `editor.on` is an asynchronous method of the `DotCmsClient` class that allows you to react to actions issued by the UVE.
|
|
297
202
|
*
|
|
@@ -305,22 +210,7 @@ export class DotCmsClient {
|
|
|
305
210
|
* });
|
|
306
211
|
* ```
|
|
307
212
|
*/
|
|
308
|
-
on: (action: string, callbackFn: (payload: unknown) => void) =>
|
|
309
|
-
if (!isInsideEditor()) {
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (action === 'changes') {
|
|
314
|
-
const messageCallback = (event: MessageEvent) => {
|
|
315
|
-
if (event.data.name === 'SET_PAGE_DATA') {
|
|
316
|
-
callbackFn(event.data.payload);
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
window.addEventListener('message', messageCallback);
|
|
321
|
-
this.#listeners.push({ event: 'message', callback: messageCallback, action });
|
|
322
|
-
}
|
|
323
|
-
},
|
|
213
|
+
on: (action: string, callbackFn: (payload: unknown) => void) => void;
|
|
324
214
|
/**
|
|
325
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.
|
|
326
216
|
*
|
|
@@ -331,19 +221,9 @@ export class DotCmsClient {
|
|
|
331
221
|
* client.editor.off('changes');
|
|
332
222
|
* ```
|
|
333
223
|
*/
|
|
334
|
-
off: (action: string) =>
|
|
335
|
-
const listenerIndex = this.#listeners.findIndex(
|
|
336
|
-
(listener) => listener.action === action
|
|
337
|
-
);
|
|
338
|
-
if (listenerIndex !== -1) {
|
|
339
|
-
const listener = this.#listeners[listenerIndex];
|
|
340
|
-
window.removeEventListener(listener.event, listener.callback);
|
|
341
|
-
this.#listeners.splice(listenerIndex, 1);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
224
|
+
off: (action: string) => void;
|
|
344
225
|
};
|
|
345
|
-
|
|
346
|
-
nav = {
|
|
226
|
+
nav: {
|
|
347
227
|
/**
|
|
348
228
|
* `nav.get` is an asynchronous method of the `DotCmsClient` class that retrieves information about the dotCMS file and folder tree.
|
|
349
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.
|
|
@@ -360,34 +240,8 @@ export class DotCmsClient {
|
|
|
360
240
|
* client.nav.get({ path: '/about-us', depth: 2 }).then(response => console.log(response));
|
|
361
241
|
* ```
|
|
362
242
|
*/
|
|
363
|
-
get:
|
|
364
|
-
options: NavApiOptions = { depth: 0, path: '/', languageId: 1 }
|
|
365
|
-
): Promise<unknown> => {
|
|
366
|
-
this.validateNavOptions(options);
|
|
367
|
-
|
|
368
|
-
// Extract the 'path' from the options and prepare the rest as query parameters
|
|
369
|
-
const { path, ...queryParamsOptions } = options;
|
|
370
|
-
const queryParamsObj: Record<string, string> = {};
|
|
371
|
-
Object.entries(queryParamsOptions).forEach(([key, value]) => {
|
|
372
|
-
if (value !== undefined) {
|
|
373
|
-
queryParamsObj[key] = String(value);
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
const queryParams = new URLSearchParams(queryParamsObj).toString();
|
|
378
|
-
|
|
379
|
-
// Format the URL correctly depending on the 'path' value
|
|
380
|
-
const formattedPath = path === '/' ? '/' : `/${path}`;
|
|
381
|
-
const url = `${this.#config.dotcmsUrl}/api/v1/nav${formattedPath}${
|
|
382
|
-
queryParams ? `?${queryParams}` : ''
|
|
383
|
-
}`;
|
|
384
|
-
|
|
385
|
-
const response = await fetch(url, this.#requestOptions);
|
|
386
|
-
|
|
387
|
-
return response.json();
|
|
388
|
-
}
|
|
243
|
+
get: (options?: NavApiOptions) => Promise<unknown>;
|
|
389
244
|
};
|
|
390
|
-
|
|
391
245
|
/**
|
|
392
246
|
* Initializes the DotCmsClient instance with the provided configuration.
|
|
393
247
|
* If an instance already exists, it returns the existing instance.
|
|
@@ -399,44 +253,24 @@ export class DotCmsClient {
|
|
|
399
253
|
* const client = DotCmsClient.init({ dotcmsUrl: 'https://demo.dotcms.com', authToken: 'your-auth-token' });
|
|
400
254
|
* ```
|
|
401
255
|
*/
|
|
402
|
-
static init(config: ClientConfig): DotCmsClient
|
|
403
|
-
if (this.instance) {
|
|
404
|
-
console.warn(
|
|
405
|
-
'DotCmsClient has already been initialized. Please use the instance to interact with the DotCMS API.'
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return this.instance ?? (this.instance = new DotCmsClient(config));
|
|
410
|
-
}
|
|
411
|
-
|
|
256
|
+
static init(config: ClientConfig): DotCmsClient;
|
|
412
257
|
/**
|
|
413
258
|
* Retrieves the DotCMS URL from the instance configuration.
|
|
414
259
|
*
|
|
415
260
|
* @returns {string} - The DotCMS URL.
|
|
416
261
|
*/
|
|
417
|
-
static get dotcmsUrl(): string
|
|
418
|
-
return (this.instance && this.instance.#config.dotcmsUrl) || '';
|
|
419
|
-
}
|
|
420
|
-
|
|
262
|
+
static get dotcmsUrl(): string;
|
|
421
263
|
/**
|
|
422
264
|
* Throws an error if the path is not valid.
|
|
423
265
|
*
|
|
424
266
|
* @returns {string} - The authentication token.
|
|
425
267
|
*/
|
|
426
|
-
private validatePageOptions
|
|
427
|
-
if (!options.path) {
|
|
428
|
-
throw new Error("The 'path' parameter is required for the Page API");
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
268
|
+
private validatePageOptions;
|
|
432
269
|
/**
|
|
433
270
|
* Throws an error if the path is not valid.
|
|
434
271
|
*
|
|
435
272
|
* @returns {string} - The authentication token.
|
|
436
273
|
*/
|
|
437
|
-
private validateNavOptions
|
|
438
|
-
if (!options.path) {
|
|
439
|
-
throw new Error("The 'path' parameter is required for the Nav API");
|
|
440
|
-
}
|
|
441
|
-
}
|
|
274
|
+
private validateNavOptions;
|
|
442
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;
|
|
@@ -4,62 +4,61 @@
|
|
|
4
4
|
* @export
|
|
5
5
|
* @enum {number}
|
|
6
6
|
*/
|
|
7
|
-
export enum CUSTOMER_ACTIONS {
|
|
7
|
+
export declare enum CUSTOMER_ACTIONS {
|
|
8
8
|
/**
|
|
9
9
|
* Tell the dotcms editor that page change
|
|
10
10
|
*/
|
|
11
|
-
NAVIGATION_UPDATE =
|
|
11
|
+
NAVIGATION_UPDATE = "set-url",
|
|
12
12
|
/**
|
|
13
13
|
* Send the element position of the rows, columnsm containers and contentlets
|
|
14
14
|
*/
|
|
15
|
-
SET_BOUNDS =
|
|
15
|
+
SET_BOUNDS = "set-bounds",
|
|
16
16
|
/**
|
|
17
17
|
* Send the information of the hovered contentlet
|
|
18
18
|
*/
|
|
19
|
-
SET_CONTENTLET =
|
|
19
|
+
SET_CONTENTLET = "set-contentlet",
|
|
20
20
|
/**
|
|
21
21
|
* Tell the editor that the page is being scrolled
|
|
22
22
|
*/
|
|
23
|
-
IFRAME_SCROLL =
|
|
23
|
+
IFRAME_SCROLL = "scroll",
|
|
24
24
|
/**
|
|
25
25
|
* Tell the editor that the page has stopped scrolling
|
|
26
26
|
*/
|
|
27
|
-
IFRAME_SCROLL_END =
|
|
27
|
+
IFRAME_SCROLL_END = "scroll-end",
|
|
28
28
|
/**
|
|
29
29
|
* Ping the editor to see if the page is inside the editor
|
|
30
30
|
*/
|
|
31
|
-
PING_EDITOR =
|
|
31
|
+
PING_EDITOR = "ping-editor",
|
|
32
32
|
/**
|
|
33
33
|
* Tell the editor to init the inline editing editor.
|
|
34
34
|
*/
|
|
35
|
-
INIT_INLINE_EDITING =
|
|
35
|
+
INIT_INLINE_EDITING = "init-inline-editing",
|
|
36
36
|
/**
|
|
37
37
|
* Tell the editor to open the Copy-contentlet dialog
|
|
38
38
|
* To copy a content and then edit it inline.
|
|
39
39
|
*/
|
|
40
|
-
COPY_CONTENTLET_INLINE_EDITING =
|
|
40
|
+
COPY_CONTENTLET_INLINE_EDITING = "copy-contentlet-inline-editing",
|
|
41
41
|
/**
|
|
42
42
|
* Tell the editor to save inline edited contentlet
|
|
43
43
|
*/
|
|
44
|
-
UPDATE_CONTENTLET_INLINE_EDITING =
|
|
44
|
+
UPDATE_CONTENTLET_INLINE_EDITING = "update-contentlet-inline-editing",
|
|
45
45
|
/**
|
|
46
46
|
* Tell the editor to trigger a menu reorder
|
|
47
47
|
*/
|
|
48
|
-
REORDER_MENU =
|
|
48
|
+
REORDER_MENU = "reorder-menu",
|
|
49
49
|
/**
|
|
50
50
|
* Tell the editor to send the page info to iframe
|
|
51
51
|
*/
|
|
52
|
-
GET_PAGE_DATA =
|
|
52
|
+
GET_PAGE_DATA = "get-page-data",
|
|
53
53
|
/**
|
|
54
54
|
* Tell the editor an user send a graphql query
|
|
55
55
|
*/
|
|
56
|
-
CLIENT_READY =
|
|
56
|
+
CLIENT_READY = "client-ready",
|
|
57
57
|
/**
|
|
58
58
|
* Tell the editor to do nothing
|
|
59
59
|
*/
|
|
60
|
-
NOOP =
|
|
60
|
+
NOOP = "noop"
|
|
61
61
|
}
|
|
62
|
-
|
|
63
62
|
/**
|
|
64
63
|
* Post message props
|
|
65
64
|
*
|
|
@@ -71,7 +70,6 @@ type PostMessageProps<T> = {
|
|
|
71
70
|
action: CUSTOMER_ACTIONS;
|
|
72
71
|
payload?: T;
|
|
73
72
|
};
|
|
74
|
-
|
|
75
73
|
/**
|
|
76
74
|
* Post message to dotcms page editor
|
|
77
75
|
*
|
|
@@ -79,6 +77,5 @@ type PostMessageProps<T> = {
|
|
|
79
77
|
* @template T
|
|
80
78
|
* @param {PostMessageProps<T>} message
|
|
81
79
|
*/
|
|
82
|
-
export function postMessageToEditor<T = unknown>(message: PostMessageProps<T>)
|
|
83
|
-
|
|
84
|
-
}
|
|
80
|
+
export declare function postMessageToEditor<T = unknown>(message: PostMessageProps<T>): void;
|
|
81
|
+
export {};
|
|
@@ -4,19 +4,15 @@
|
|
|
4
4
|
export type CustomClientParams = {
|
|
5
5
|
depth: string;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* @description Union type for fetch configurations.
|
|
10
9
|
* @typedef {GraphQLFetchConfig | PageAPIFetchConfig} DotCMSFetchConfig
|
|
11
10
|
*/
|
|
12
|
-
export type EditorConfig =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
query: string;
|
|
18
|
-
};
|
|
19
|
-
|
|
11
|
+
export type EditorConfig = {
|
|
12
|
+
params: CustomClientParams;
|
|
13
|
+
} | {
|
|
14
|
+
query: string;
|
|
15
|
+
};
|
|
20
16
|
/**
|
|
21
17
|
* Represents the configuration options for the DotCMS page editor.
|
|
22
18
|
* @export
|
|
@@ -4,28 +4,26 @@
|
|
|
4
4
|
* @export
|
|
5
5
|
* @enum {number}
|
|
6
6
|
*/
|
|
7
|
-
export enum NOTIFY_CUSTOMER {
|
|
7
|
+
export declare enum NOTIFY_CUSTOMER {
|
|
8
8
|
/**
|
|
9
9
|
* Request to page to reload
|
|
10
10
|
*/
|
|
11
|
-
EMA_RELOAD_PAGE =
|
|
11
|
+
EMA_RELOAD_PAGE = "ema-reload-page",
|
|
12
12
|
/**
|
|
13
13
|
* Request the bounds for the elements
|
|
14
14
|
*/
|
|
15
|
-
EMA_REQUEST_BOUNDS =
|
|
15
|
+
EMA_REQUEST_BOUNDS = "ema-request-bounds",
|
|
16
16
|
/**
|
|
17
17
|
* Received pong from the editor
|
|
18
18
|
*/
|
|
19
|
-
EMA_EDITOR_PONG =
|
|
19
|
+
EMA_EDITOR_PONG = "ema-editor-pong",
|
|
20
20
|
/**
|
|
21
21
|
* Received scroll event trigger from the editor
|
|
22
22
|
*/
|
|
23
|
-
EMA_SCROLL_INSIDE_IFRAME =
|
|
23
|
+
EMA_SCROLL_INSIDE_IFRAME = "scroll-inside-iframe"
|
|
24
24
|
}
|
|
25
|
-
|
|
26
25
|
type ListenerCallbackMessage = (event: MessageEvent) => void;
|
|
27
26
|
type ListenerCallbackPointer = (event: PointerEvent) => void;
|
|
28
|
-
|
|
29
27
|
/**
|
|
30
28
|
* Listener for the dotcms editor
|
|
31
29
|
*
|
|
@@ -36,7 +34,6 @@ interface DotCMSPageEditorListener {
|
|
|
36
34
|
event: string;
|
|
37
35
|
callback: ListenerCallbackMessage | ListenerCallbackPointer;
|
|
38
36
|
}
|
|
39
|
-
|
|
40
37
|
/**
|
|
41
38
|
* Observer for the dotcms editor
|
|
42
39
|
*
|
|
@@ -46,5 +43,5 @@ interface DotCMSPageEditorObserver {
|
|
|
46
43
|
type: 'observer';
|
|
47
44
|
observer: MutationObserver;
|
|
48
45
|
}
|
|
49
|
-
|
|
50
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;
|