@dotcms/client 0.0.1-alpha.1 → 0.0.1-alpha.11

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.
@@ -0,0 +1,297 @@
1
+ export interface ClientConfig {
2
+ /**
3
+ * The URL of the dotCMS instance.
4
+ *
5
+ * @description This is the URL of the dotCMS instance you want to interact with. Ensure to include the protocol (http or https).
6
+ * @example `https://demo.dotcms.com`
7
+ * @type {string}
8
+ * @required
9
+ */
10
+ dotcmsUrl: string;
11
+ /**
12
+ * The id of the site you want to interact with.
13
+ *
14
+ * @description to get the site id, go to the site you want to interact with and copy the id from the History tab
15
+ *
16
+ * @type {string}
17
+ * @required
18
+ */
19
+ siteId?: string;
20
+ /**
21
+ * The authentication token to use for the requests. If not provided, it will fallback to default site.
22
+ *
23
+ * @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}
24
+ *
25
+ * @type {string}
26
+ * @required
27
+ */
28
+ authToken: string;
29
+ /**
30
+ * Additional options to pass to the fetch request.
31
+ *
32
+ * @description These options will be used in the fetch request. Any option can be specified except for 'body' and 'method' which are omitted.
33
+ * @example `{ headers: { 'Content-Type': 'application/json' } }`
34
+ * @type {Omit<RequestInit, 'body' | 'method'>}
35
+ * @optional
36
+ */
37
+ requestOptions?: Omit<RequestInit, 'body' | 'method'>;
38
+ }
39
+
40
+ type PageApiOptions = {
41
+ /**
42
+ * The path of the page you want to retrieve.
43
+ *
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
+ * @type {number}
51
+ */
52
+ siteId?: string;
53
+ /**
54
+ * The mode of the page you want to retrieve. If not provided will use the default mode of the site.
55
+ *
56
+ * @type {number}
57
+ */
58
+ mode?: string;
59
+ /**
60
+ * The language id of the page you want to retrieve. If not provided will use the default language of the site.
61
+ *
62
+ * @type {number}
63
+ */
64
+ language_id?: number;
65
+ /**
66
+ * The id of the persona you want to retrieve the page for.
67
+ *
68
+ * @type {string}
69
+ */
70
+ personaId?: string;
71
+ /**
72
+ * If you want to fire the rules set on the page
73
+ *
74
+ * @type {boolean}
75
+ */
76
+ fireRules?: boolean;
77
+ /**
78
+ * Allows access to related content via the Relationship fields of contentlets on a Page; 0 (default)
79
+ *
80
+ * @type {number}
81
+ */
82
+ depth?: number;
83
+ };
84
+
85
+ type NavApiOptions = {
86
+ /**
87
+ * The root path to begin traversing the folder tree.
88
+ *
89
+ * @example
90
+ * `/api/v1/nav/` starts from the root of the site
91
+ * @example
92
+ * `/about-us` starts from the "About Us" folder
93
+ *
94
+ * @type {string}
95
+ */
96
+ path: string;
97
+ /**
98
+ * The depth of the folder tree to return.
99
+ * @example
100
+ * `1` returns only the element specified in the path.
101
+ * @example
102
+ * `2` returns the element specified in the path, and if that element is a folder, returns all direct children of that folder.
103
+ * @example
104
+ * `3` returns all children and grandchildren of the element specified in the path.
105
+ *
106
+ * @type {number}
107
+ */
108
+ depth?: number;
109
+ /**
110
+ * The language ID of content to return.
111
+ * @example
112
+ * `1` (or unspecified) returns content in the default language of the site.
113
+ *
114
+ * @link https://www.dotcms.com/docs/latest/system-language-properties#DefaultLanguage
115
+ * @link https://www.dotcms.com/docs/latest/adding-and-editing-languages#LanguageID
116
+ * @type {number}
117
+ */
118
+ languageId?: number;
119
+ };
120
+
121
+ function isValidUrl(url: string): boolean {
122
+ try {
123
+ new URL(url);
124
+
125
+ return true;
126
+ } catch (error) {
127
+ return false;
128
+ }
129
+ }
130
+
131
+ /**
132
+ * `DotCmsClient` is a TypeScript class that provides methods to interact with the DotCMS REST API.
133
+ * It requires a configuration object on instantiation, which includes the DotCMS URL, site ID, and authentication token.
134
+ *
135
+ * @class DotCmsClient
136
+ *
137
+ * @property {ClientConfig} config - The configuration object for the DotCMS client.
138
+ *
139
+ * @method constructor(config: ClientConfig) - Constructs a new instance of the DotCmsClient class.
140
+ *
141
+ * @method page.get(options: PageApiOptions): Promise<unknown> - Retrieves all the elements of any Page in your dotCMS system in JSON format.
142
+ *
143
+ * @method nav.get(options: NavApiOptions = { depth: 0, path: '/', languageId: 1 }): Promise<unknown> - Retrieves information about the dotCMS file and folder tree.
144
+ *
145
+ */
146
+ export class DotCmsClient {
147
+ private config: ClientConfig;
148
+ private requestOptions!: Omit<RequestInit, 'body' | 'method'>;
149
+
150
+ constructor(
151
+ config: ClientConfig = { dotcmsUrl: '', authToken: '', requestOptions: {}, siteId: '' }
152
+ ) {
153
+ if (!config.dotcmsUrl) {
154
+ throw new Error("Invalid configuration - 'dotcmsUrl' is required");
155
+ }
156
+
157
+ if (!isValidUrl(config.dotcmsUrl)) {
158
+ throw new Error("Invalid configuration - 'dotcmsUrl' must be a valid URL");
159
+ }
160
+
161
+ if (!config.authToken) {
162
+ throw new Error("Invalid configuration - 'authToken' is required");
163
+ }
164
+
165
+ this.config = config;
166
+
167
+ this.requestOptions = {
168
+ ...this.config.requestOptions,
169
+ headers: {
170
+ Authorization: `Bearer ${this.config.authToken}`,
171
+ ...this.config.requestOptions?.headers
172
+ }
173
+ };
174
+ }
175
+
176
+ page = {
177
+ /**
178
+ * `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.
179
+ * It takes a `PageApiOptions` object as a parameter and returns a Promise that resolves to the response from the DotCMS API.
180
+ *
181
+ * The Page API enables you to retrieve all the elements of any Page in your dotCMS system.
182
+ * The elements may be retrieved in JSON format.
183
+ *
184
+ * @link https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas
185
+ * @async
186
+ * @param {PageApiOptions} options - The options for the Page API call.
187
+ * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
188
+ * @throws {Error} - Throws an error if the options are not valid.
189
+ */
190
+ get: async (options: PageApiOptions): Promise<unknown> => {
191
+ this.validatePageOptions(options);
192
+
193
+ const queryParamsObj: Record<string, string> = {};
194
+ for (const [key, value] of Object.entries(options)) {
195
+ if (value === undefined || key === 'path' || key === 'siteId') continue;
196
+
197
+ if (key === 'personaId') {
198
+ queryParamsObj['com.dotmarketing.persona.id'] = String(value);
199
+ } else if (key === 'mode' && value) {
200
+ queryParamsObj['mode'] = String(value);
201
+ } else {
202
+ queryParamsObj[key] = String(value);
203
+ }
204
+ }
205
+
206
+ const queryHostId = options.siteId ?? this.config.siteId ?? '';
207
+
208
+ if (queryHostId) {
209
+ queryParamsObj['host_id'] = queryHostId;
210
+ }
211
+
212
+ const queryParams = new URLSearchParams(queryParamsObj).toString();
213
+
214
+ const formattedPath = options.path.startsWith('/') ? options.path : `/${options.path}`;
215
+ const url = `${this.config.dotcmsUrl}/api/v1/page/json${formattedPath}${
216
+ queryParams ? `?${queryParams}` : ''
217
+ }`;
218
+ const response = await fetch(url, this.requestOptions);
219
+
220
+ return response.json();
221
+ }
222
+ };
223
+
224
+ nav = {
225
+ /**
226
+ * `nav.get` is an asynchronous method of the `DotCmsClient` class that retrieves information about the dotCMS file and folder tree.
227
+ * It takes a `NavApiOptions` object as a parameter (with default values) and returns a Promise that resolves to the response from the DotCMS API.
228
+ *
229
+ * The navigation REST API enables you to retrieve information about the dotCMS file and folder tree through REST API calls.
230
+ * @link https://www.dotcms.com/docs/latest/navigation-rest-api
231
+ * @async
232
+ * @param {NavApiOptions} options - The options for the Nav API call. Defaults to `{ depth: 0, path: '/', languageId: 1 }`.
233
+ * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
234
+ * @throws {Error} - Throws an error if the options are not valid.
235
+ */
236
+ get: async (
237
+ options: NavApiOptions = { depth: 0, path: '/', languageId: 1 }
238
+ ): Promise<unknown> => {
239
+ this.validateNavOptions(options);
240
+
241
+ // Extract the 'path' from the options and prepare the rest as query parameters
242
+ const { path, ...queryParamsOptions } = options;
243
+ const queryParamsObj: Record<string, string> = {};
244
+ Object.entries(queryParamsOptions).forEach(([key, value]) => {
245
+ if (value !== undefined) {
246
+ queryParamsObj[key] = String(value);
247
+ }
248
+ });
249
+
250
+ const queryParams = new URLSearchParams(queryParamsObj).toString();
251
+
252
+ // Format the URL correctly depending on the 'path' value
253
+ const formattedPath = path === '/' ? '/' : `/${path}`;
254
+ const url = `${this.config.dotcmsUrl}/api/v1/nav${formattedPath}${
255
+ queryParams ? `?${queryParams}` : ''
256
+ }`;
257
+
258
+ const response = await fetch(url, this.requestOptions);
259
+
260
+ return response.json();
261
+ }
262
+ };
263
+
264
+ private validatePageOptions(options: PageApiOptions): void {
265
+ if (!options.path) {
266
+ throw new Error("The 'path' parameter is required for the Page API");
267
+ }
268
+ }
269
+
270
+ private validateNavOptions(options: NavApiOptions): void {
271
+ if (!options.path) {
272
+ throw new Error("The 'path' parameter is required for the Nav API");
273
+ }
274
+ }
275
+ }
276
+
277
+ /**
278
+ * `dotcmsClient` is an object that provides a method to initialize the DotCMS SDK client.
279
+ * It has a single method `init` which takes a configuration object and returns an instance of the `DotCmsClient` class.
280
+ *
281
+ * @namespace dotcmsClient
282
+ *
283
+ * @method init(config: ClientConfig): DotCmsClient - Initializes the SDK client.
284
+ */
285
+ export const dotcmsClient = {
286
+ /**
287
+ * `init` is a method of the `dotcmsClient` object that initializes the SDK client.
288
+ * It takes a configuration object as a parameter and returns an instance of the `DotCmsClient` class.
289
+ *
290
+ * @method init
291
+ * @param {ClientConfig} config - The configuration object for the DotCMS client.
292
+ * @returns {DotCmsClient} - An instance of the {@link DotCmsClient} class.
293
+ */
294
+ init: (config: ClientConfig): DotCmsClient => {
295
+ return new DotCmsClient(config);
296
+ }
297
+ };
@@ -0,0 +1,58 @@
1
+ import {
2
+ listenEditorMessages,
3
+ listenHoveredContentlet,
4
+ pingEditor,
5
+ preserveScrollOnIframe,
6
+ scrollHandler
7
+ } from './listeners';
8
+
9
+ import { CUSTOMER_ACTIONS, postMessageToEditor } from '../models/client.model';
10
+
11
+ jest.mock('../models/client.model', () => ({
12
+ postMessageToEditor: jest.fn(),
13
+ CUSTOMER_ACTIONS: {
14
+ NAVIGATION_UPDATE: 'set-url',
15
+ SET_BOUNDS: 'set-bounds',
16
+ SET_CONTENTLET: 'set-contentlet',
17
+ IFRAME_SCROLL: 'scroll',
18
+ PING_EDITOR: 'ping-editor',
19
+ CONTENT_CHANGE: 'content-change',
20
+ NOOP: 'noop'
21
+ }
22
+ }));
23
+
24
+ /**
25
+ * Observation: We must test the execution of methods as well.
26
+ */
27
+ describe('listeners', () => {
28
+ it('should listen editor messages', () => {
29
+ const addEventListenerSpy = jest.spyOn(window, 'addEventListener');
30
+ listenEditorMessages();
31
+ expect(addEventListenerSpy).toHaveBeenCalledWith('message', expect.any(Function));
32
+ });
33
+
34
+ it('should listen to hovered contentlet', () => {
35
+ const addEventListenerSpy = jest.spyOn(document, 'addEventListener');
36
+ listenHoveredContentlet();
37
+ expect(addEventListenerSpy).toHaveBeenCalledWith('pointermove', expect.any(Function));
38
+ });
39
+
40
+ it('should handle scroll', () => {
41
+ const addEventListenerSpy = jest.spyOn(window, 'addEventListener');
42
+ scrollHandler();
43
+ expect(addEventListenerSpy).toHaveBeenCalledWith('scroll', expect.any(Function));
44
+ });
45
+
46
+ it('should preserve scroll on iframe', () => {
47
+ const addEventListenerSpy = jest.spyOn(window, 'addEventListener');
48
+ preserveScrollOnIframe();
49
+ expect(addEventListenerSpy).toHaveBeenCalledWith('load', expect.any(Function));
50
+ });
51
+
52
+ it('should send ping to editor', () => {
53
+ pingEditor();
54
+ expect(postMessageToEditor).toHaveBeenCalledWith({
55
+ action: CUSTOMER_ACTIONS.PING_EDITOR
56
+ });
57
+ });
58
+ });
@@ -0,0 +1,195 @@
1
+ import { CUSTOMER_ACTIONS, postMessageToEditor } from '../models/client.model';
2
+ import { DotCMSPageEditorConfig } from '../models/editor.model';
3
+ import { DotCMSPageEditorSubscription, NOTIFY_CUSTOMER } from '../models/listeners.model';
4
+ import {
5
+ findVTLData,
6
+ findContentletElement,
7
+ getClosestContainerData,
8
+ getPageElementBound
9
+ } from '../utils/editor.utils';
10
+
11
+ declare global {
12
+ interface Window {
13
+ lastScrollYPosition: number;
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Default reload function that reloads the current window.
19
+ */
20
+ const defaultReloadFn = () => window.location.reload();
21
+
22
+ /**
23
+ * Configuration object for the DotCMSPageEditor.
24
+ */
25
+ let pageEditorConfig: DotCMSPageEditorConfig = {
26
+ onReload: defaultReloadFn
27
+ };
28
+
29
+ export function setPageEditorConfig(config: DotCMSPageEditorConfig) {
30
+ pageEditorConfig = config;
31
+ }
32
+
33
+ /**
34
+ * Represents an array of DotCMSPageEditorSubscription objects.
35
+ * Used to store the subscriptions for the editor and unsubscribe later.
36
+ */
37
+ export const subscriptions: DotCMSPageEditorSubscription[] = [];
38
+
39
+ /**
40
+ * Sets the bounds of the containers in the editor.
41
+ * Retrieves the containers from the DOM and sends their position data to the editor.
42
+ * @private
43
+ * @memberof DotCMSPageEditor
44
+ */
45
+ function setBounds() {
46
+ const containers = Array.from(
47
+ document.querySelectorAll('[data-dot-object="container"]')
48
+ ) as HTMLDivElement[];
49
+ const positionData = getPageElementBound(containers);
50
+
51
+ postMessageToEditor({
52
+ action: CUSTOMER_ACTIONS.SET_BOUNDS,
53
+ payload: positionData
54
+ });
55
+ }
56
+
57
+ /**
58
+ * Reloads the page and triggers the onReload callback if it exists in the config object.
59
+ */
60
+ function reloadPage() {
61
+ pageEditorConfig?.onReload();
62
+ }
63
+
64
+ /**
65
+ * Listens for editor messages and performs corresponding actions based on the received message.
66
+ *
67
+ * @private
68
+ * @memberof DotCMSPageEditor
69
+ */
70
+ export function listenEditorMessages() {
71
+ const messageCallback = (event: MessageEvent) => {
72
+ switch (event.data) {
73
+ case NOTIFY_CUSTOMER.EMA_REQUEST_BOUNDS: {
74
+ setBounds();
75
+ break;
76
+ }
77
+
78
+ case NOTIFY_CUSTOMER.EMA_RELOAD_PAGE: {
79
+ reloadPage();
80
+ break;
81
+ }
82
+ }
83
+ };
84
+
85
+ window.addEventListener('message', messageCallback);
86
+
87
+ subscriptions.push({
88
+ type: 'listener',
89
+ event: 'message',
90
+ callback: messageCallback
91
+ });
92
+ }
93
+
94
+ /**
95
+ * Listens for pointer move events and extracts information about the hovered contentlet.
96
+ *
97
+ * @private
98
+ * @memberof DotCMSPageEditor
99
+ */
100
+ export function listenHoveredContentlet() {
101
+ const pointerMoveCallback = (event: PointerEvent) => {
102
+ const target = findContentletElement(event.target as HTMLElement);
103
+ if (!target) return;
104
+ const { x, y, width, height } = target.getBoundingClientRect();
105
+
106
+ const vtlFiles = findVTLData(target);
107
+ const contentletPayload = {
108
+ container:
109
+ // Here extract dot-container from contentlet if is Headless
110
+ // or search in parent container if is VTL
111
+ target.dataset?.['dotContainer']
112
+ ? JSON.parse(target.dataset?.['dotContainer'])
113
+ : getClosestContainerData(target),
114
+ contentlet: {
115
+ identifier: target.dataset?.['dotIdentifier'],
116
+ title: target.dataset?.['dotTitle'],
117
+ inode: target.dataset?.['dotInode'],
118
+ contentType: target.dataset?.['dotType'],
119
+ onNumberOfPages: target.dataset?.['dotOnNumberOfPages']
120
+ },
121
+ vtlFiles
122
+ };
123
+
124
+ postMessageToEditor({
125
+ action: CUSTOMER_ACTIONS.SET_CONTENTLET,
126
+ payload: {
127
+ x,
128
+ y,
129
+ width,
130
+ height,
131
+ payload: contentletPayload
132
+ }
133
+ });
134
+ };
135
+
136
+ document.addEventListener('pointermove', pointerMoveCallback);
137
+
138
+ subscriptions.push({
139
+ type: 'listener',
140
+ event: 'pointermove',
141
+ callback: pointerMoveCallback
142
+ });
143
+ }
144
+
145
+ /**
146
+ * Attaches a scroll event listener to the window
147
+ * and sends a message to the editor when the window is scrolled.
148
+ *
149
+ * @private
150
+ * @memberof DotCMSPageEditor
151
+ */
152
+ export function scrollHandler() {
153
+ const scrollCallback = () => {
154
+ postMessageToEditor({
155
+ action: CUSTOMER_ACTIONS.IFRAME_SCROLL
156
+ });
157
+ window.lastScrollYPosition = window.scrollY;
158
+ };
159
+
160
+ window.addEventListener('scroll', scrollCallback);
161
+
162
+ subscriptions.push({
163
+ type: 'listener',
164
+ event: 'scroll',
165
+ callback: scrollCallback
166
+ });
167
+ }
168
+
169
+ /**
170
+ * Restores the scroll position of the window when an iframe is loaded.
171
+ * Only used in VTL Pages.
172
+ * @export
173
+ */
174
+ export function preserveScrollOnIframe() {
175
+ const preserveScrollCallback = () => {
176
+ window.scrollTo(0, window.lastScrollYPosition);
177
+ };
178
+
179
+ window.addEventListener('load', preserveScrollCallback);
180
+ subscriptions.push({
181
+ type: 'listener',
182
+ event: 'scroll',
183
+ callback: preserveScrollCallback
184
+ });
185
+ }
186
+
187
+ /**
188
+ * Sends a ping message to the editor.
189
+ *
190
+ */
191
+ export function pingEditor() {
192
+ postMessageToEditor({
193
+ action: CUSTOMER_ACTIONS.PING_EDITOR
194
+ });
195
+ }
@@ -4,25 +4,31 @@
4
4
  * @export
5
5
  * @enum {number}
6
6
  */
7
- export declare enum CUSTOMER_ACTIONS {
7
+ export enum CUSTOMER_ACTIONS {
8
8
  /**
9
9
  * Tell the dotcms editor that page change
10
10
  */
11
- SET_URL = "set-url",
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 = "set-bounds",
15
+ SET_BOUNDS = 'set-bounds',
16
16
  /**
17
17
  * Send the information of the hovered contentlet
18
18
  */
19
- SET_CONTENTLET = "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 = "scroll",
24
- NOOP = "noop"
23
+ IFRAME_SCROLL = 'scroll',
24
+ /**
25
+ * Ping the editor to see if the page is inside the editor
26
+ */
27
+ PING_EDITOR = 'ping-editor',
28
+
29
+ NOOP = 'noop'
25
30
  }
31
+
26
32
  /**
27
33
  * Post message props
28
34
  *
@@ -34,6 +40,7 @@ type PostMessageProps<T> = {
34
40
  action: CUSTOMER_ACTIONS;
35
41
  payload?: T;
36
42
  };
43
+
37
44
  /**
38
45
  * Post message to dotcms page editor
39
46
  *
@@ -41,5 +48,6 @@ type PostMessageProps<T> = {
41
48
  * @template T
42
49
  * @param {PostMessageProps<T>} message
43
50
  */
44
- export declare function postMessageToEditor<T = unknown>(message: PostMessageProps<T>): void;
45
- export {};
51
+ export function postMessageToEditor<T = unknown>(message: PostMessageProps<T>) {
52
+ window.parent.postMessage(message, '*');
53
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ *
3
+ * Represents the configuration options for the DotCMS page editor.
4
+ * @export
5
+ * @interface DotCMSPageEditorConfig
6
+ */
7
+ export interface DotCMSPageEditorConfig {
8
+ /**
9
+ * A callback function that will be called when the page editor needs to be reloaded.
10
+ */
11
+ onReload: () => void;
12
+
13
+ /**
14
+ * The pathname of the page being edited. Optional.
15
+ */
16
+ pathname?: string;
17
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Actions received from the dotcms editor
3
+ *
4
+ * @export
5
+ * @enum {number}
6
+ */
7
+ export 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
+
22
+ type ListenerCallbackMessage = (event: MessageEvent) => void;
23
+ type ListenerCallbackPointer = (event: PointerEvent) => void;
24
+
25
+ /**
26
+ * Listener for the dotcms editor
27
+ *
28
+ * @interface DotCMSPageEditorListener
29
+ */
30
+ interface DotCMSPageEditorListener {
31
+ type: 'listener';
32
+ event: string;
33
+ callback: ListenerCallbackMessage | ListenerCallbackPointer;
34
+ }
35
+
36
+ /**
37
+ * Observer for the dotcms editor
38
+ *
39
+ * @interface DotCMSPageEditorObserver
40
+ */
41
+ interface DotCMSPageEditorObserver {
42
+ type: 'observer';
43
+ observer: MutationObserver;
44
+ }
45
+
46
+ export type DotCMSPageEditorSubscription = DotCMSPageEditorListener | DotCMSPageEditorObserver;
@@ -0,0 +1,32 @@
1
+ import {
2
+ listenEditorMessages,
3
+ listenHoveredContentlet,
4
+ pingEditor,
5
+ preserveScrollOnIframe,
6
+ scrollHandler
7
+ } from './listeners/listeners';
8
+ import { isInsideEditor } from './sdk-editor';
9
+
10
+ declare global {
11
+ interface Window {
12
+ lastScrollYPosition: number;
13
+ }
14
+ }
15
+
16
+ /**
17
+ * This is the main entry point for the SDK VTL.
18
+ * This is added to VTL Script in the EditPage
19
+ *
20
+ * @remarks
21
+ * This module sets up the necessary listeners and functionality for the SDK VTL.
22
+ * It checks if the script is running inside the editor and then initializes the client by pinging the editor,
23
+ * listening for editor messages, hovered contentlet changes, and content changes.
24
+ *
25
+ */
26
+ if (isInsideEditor()) {
27
+ pingEditor();
28
+ listenEditorMessages();
29
+ scrollHandler();
30
+ preserveScrollOnIframe();
31
+ listenHoveredContentlet();
32
+ }