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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/package.json +26 -24
  2. package/src/index.js +5 -0
  3. package/src/index.js.map +1 -0
  4. package/src/lib/client/{sdk-js-client.ts → sdk-js-client.d.ts} +13 -121
  5. package/src/lib/client/sdk-js-client.js +148 -0
  6. package/src/lib/client/sdk-js-client.js.map +1 -0
  7. package/src/lib/editor/listeners/listeners.d.ts +46 -0
  8. package/src/lib/editor/listeners/{listeners.ts → listeners.js} +38 -61
  9. package/src/lib/editor/listeners/listeners.js.map +1 -0
  10. package/src/lib/editor/models/{client.model.ts → client.model.d.ts} +13 -13
  11. package/src/lib/editor/models/client.model.js +45 -0
  12. package/src/lib/editor/models/client.model.js.map +1 -0
  13. package/src/lib/editor/models/{editor.model.ts → editor.model.d.ts} +0 -1
  14. package/src/lib/editor/models/editor.model.js +2 -0
  15. package/src/lib/editor/models/editor.model.js.map +1 -0
  16. package/src/lib/editor/models/{listeners.model.ts → listeners.model.d.ts} +5 -8
  17. package/src/lib/editor/models/listeners.model.js +22 -0
  18. package/src/lib/editor/models/listeners.model.js.map +1 -0
  19. package/src/lib/editor/sdk-editor-vtl.d.ts +6 -0
  20. package/src/lib/editor/{sdk-editor-vtl.ts → sdk-editor-vtl.js} +2 -14
  21. package/src/lib/editor/sdk-editor-vtl.js.map +1 -0
  22. package/src/lib/editor/sdk-editor.d.ts +23 -0
  23. package/src/lib/editor/{sdk-editor.ts → sdk-editor.js} +7 -21
  24. package/src/lib/editor/sdk-editor.js.map +1 -0
  25. package/src/lib/editor/utils/editor.utils.d.ts +82 -0
  26. package/src/lib/editor/utils/{editor.utils.ts → editor.utils.js} +25 -75
  27. package/src/lib/editor/utils/editor.utils.js.map +1 -0
  28. package/.eslintrc.json +0 -18
  29. package/jest.config.ts +0 -15
  30. package/project.json +0 -63
  31. package/src/lib/client/sdk-js-client.spec.ts +0 -258
  32. package/src/lib/editor/listeners/listeners.spec.ts +0 -58
  33. package/src/lib/editor/sdk-editor.spec.ts +0 -92
  34. package/src/lib/editor/utils/editor.utils.spec.ts +0 -164
  35. package/tsconfig.json +0 -22
  36. package/tsconfig.lib.json +0 -10
  37. package/tsconfig.spec.json +0 -9
  38. /package/src/{index.ts → index.d.ts} +0 -0
package/package.json CHANGED
@@ -1,26 +1,28 @@
1
1
  {
2
- "name": "@dotcms/client",
3
- "version": "0.0.1-alpha.11",
4
- "type": "module",
5
- "description": "Official JavaScript library for interacting with DotCMS REST APIs.",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/dotCMS/core.git#master"
9
- },
10
- "scripts": {
11
- "build": "nx run sdk-client:build:js; cd ../../../../dotCMS/src/main/webapp/html/js/editor-js; rm -rf src package.json *.esm.d.ts"
12
- },
13
- "keywords": [
14
- "dotCMS",
15
- "CMS",
16
- "Content Management",
17
- "API Client",
18
- "REST API"
19
- ],
20
- "author": "dotcms <dev@dotcms.com>",
21
- "license": "MIT",
22
- "bugs": {
23
- "url": "https://github.com/dotCMS/core/issues"
24
- },
25
- "homepage": "https://github.com/dotCMS/core/tree/master/core-web/libs/sdk/client/README.md"
2
+ "name": "@dotcms/client",
3
+ "version": "0.0.1-alpha.13",
4
+ "type": "module",
5
+ "description": "Official JavaScript library for interacting with DotCMS REST APIs.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/dotCMS/core.git#master"
9
+ },
10
+ "scripts": {
11
+ "build": "nx run sdk-client:build:js; cd ../../../../dotCMS/src/main/webapp/html/js/editor-js; rm -rf src package.json *.esm.d.ts"
12
+ },
13
+ "keywords": [
14
+ "dotCMS",
15
+ "CMS",
16
+ "Content Management",
17
+ "API Client",
18
+ "REST API"
19
+ ],
20
+ "author": "dotcms <dev@dotcms.com>",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/dotCMS/core/issues"
24
+ },
25
+ "homepage": "https://github.com/dotCMS/core/tree/master/core-web/libs/sdk/client/README.md",
26
+ "module": "./src/index.js",
27
+ "main": "./src/index.js"
26
28
  }
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './lib/client/sdk-js-client';
2
+ export * from './lib/editor/sdk-editor';
3
+ export * from './lib/editor/models/editor.model';
4
+ export * from './lib/editor/models/client.model';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/sdk/client/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC"}
@@ -36,7 +36,6 @@ export interface ClientConfig {
36
36
  */
37
37
  requestOptions?: Omit<RequestInit, 'body' | 'method'>;
38
38
  }
39
-
40
39
  type PageApiOptions = {
41
40
  /**
42
41
  * The path of the page you want to retrieve.
@@ -81,7 +80,6 @@ type PageApiOptions = {
81
80
  */
82
81
  depth?: number;
83
82
  };
84
-
85
83
  type NavApiOptions = {
86
84
  /**
87
85
  * The root path to begin traversing the folder tree.
@@ -117,17 +115,6 @@ type NavApiOptions = {
117
115
  */
118
116
  languageId?: number;
119
117
  };
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
118
  /**
132
119
  * `DotCmsClient` is a TypeScript class that provides methods to interact with the DotCMS REST API.
133
120
  * It requires a configuration object on instantiation, which includes the DotCMS URL, site ID, and authentication token.
@@ -143,37 +130,11 @@ function isValidUrl(url: string): boolean {
143
130
  * @method nav.get(options: NavApiOptions = { depth: 0, path: '/', languageId: 1 }): Promise<unknown> - Retrieves information about the dotCMS file and folder tree.
144
131
  *
145
132
  */
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 = {
133
+ export declare class DotCmsClient {
134
+ private config;
135
+ private requestOptions;
136
+ constructor(config?: ClientConfig);
137
+ page: {
177
138
  /**
178
139
  * `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
140
  * It takes a `PageApiOptions` object as a parameter and returns a Promise that resolves to the response from the DotCMS API.
@@ -187,41 +148,9 @@ export class DotCmsClient {
187
148
  * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
188
149
  * @throws {Error} - Throws an error if the options are not valid.
189
150
  */
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
- }
151
+ get: (options: PageApiOptions) => Promise<unknown>;
222
152
  };
223
-
224
- nav = {
153
+ nav: {
225
154
  /**
226
155
  * `nav.get` is an asynchronous method of the `DotCmsClient` class that retrieves information about the dotCMS file and folder tree.
227
156
  * It takes a `NavApiOptions` object as a parameter (with default values) and returns a Promise that resolves to the response from the DotCMS API.
@@ -233,47 +162,11 @@ export class DotCmsClient {
233
162
  * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
234
163
  * @throws {Error} - Throws an error if the options are not valid.
235
164
  */
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
- }
165
+ get: (options?: NavApiOptions) => Promise<unknown>;
262
166
  };
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
- }
167
+ private validatePageOptions;
168
+ private validateNavOptions;
275
169
  }
276
-
277
170
  /**
278
171
  * `dotcmsClient` is an object that provides a method to initialize the DotCMS SDK client.
279
172
  * It has a single method `init` which takes a configuration object and returns an instance of the `DotCmsClient` class.
@@ -282,7 +175,7 @@ export class DotCmsClient {
282
175
  *
283
176
  * @method init(config: ClientConfig): DotCmsClient - Initializes the SDK client.
284
177
  */
285
- export const dotcmsClient = {
178
+ export declare const dotcmsClient: {
286
179
  /**
287
180
  * `init` is a method of the `dotcmsClient` object that initializes the SDK client.
288
181
  * It takes a configuration object as a parameter and returns an instance of the `DotCmsClient` class.
@@ -291,7 +184,6 @@ export const dotcmsClient = {
291
184
  * @param {ClientConfig} config - The configuration object for the DotCMS client.
292
185
  * @returns {DotCmsClient} - An instance of the {@link DotCmsClient} class.
293
186
  */
294
- init: (config: ClientConfig): DotCmsClient => {
295
- return new DotCmsClient(config);
296
- }
187
+ init: (config: ClientConfig) => DotCmsClient;
297
188
  };
189
+ export {};
@@ -0,0 +1,148 @@
1
+ function isValidUrl(url) {
2
+ try {
3
+ new URL(url);
4
+ return true;
5
+ }
6
+ catch (error) {
7
+ return false;
8
+ }
9
+ }
10
+ /**
11
+ * `DotCmsClient` is a TypeScript class that provides methods to interact with the DotCMS REST API.
12
+ * It requires a configuration object on instantiation, which includes the DotCMS URL, site ID, and authentication token.
13
+ *
14
+ * @class DotCmsClient
15
+ *
16
+ * @property {ClientConfig} config - The configuration object for the DotCMS client.
17
+ *
18
+ * @method constructor(config: ClientConfig) - Constructs a new instance of the DotCmsClient class.
19
+ *
20
+ * @method page.get(options: PageApiOptions): Promise<unknown> - Retrieves all the elements of any Page in your dotCMS system in JSON format.
21
+ *
22
+ * @method nav.get(options: NavApiOptions = { depth: 0, path: '/', languageId: 1 }): Promise<unknown> - Retrieves information about the dotCMS file and folder tree.
23
+ *
24
+ */
25
+ export class DotCmsClient {
26
+ constructor(config = { dotcmsUrl: '', authToken: '', requestOptions: {}, siteId: '' }) {
27
+ this.page = {
28
+ /**
29
+ * `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.
30
+ * It takes a `PageApiOptions` object as a parameter and returns a Promise that resolves to the response from the DotCMS API.
31
+ *
32
+ * The Page API enables you to retrieve all the elements of any Page in your dotCMS system.
33
+ * The elements may be retrieved in JSON format.
34
+ *
35
+ * @link https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas
36
+ * @async
37
+ * @param {PageApiOptions} options - The options for the Page API call.
38
+ * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
39
+ * @throws {Error} - Throws an error if the options are not valid.
40
+ */
41
+ get: async (options) => {
42
+ this.validatePageOptions(options);
43
+ const queryParamsObj = {};
44
+ for (const [key, value] of Object.entries(options)) {
45
+ if (value === undefined || key === 'path' || key === 'siteId')
46
+ continue;
47
+ if (key === 'personaId') {
48
+ queryParamsObj['com.dotmarketing.persona.id'] = String(value);
49
+ }
50
+ else if (key === 'mode' && value) {
51
+ queryParamsObj['mode'] = String(value);
52
+ }
53
+ else {
54
+ queryParamsObj[key] = String(value);
55
+ }
56
+ }
57
+ const queryHostId = options.siteId ?? this.config.siteId ?? '';
58
+ if (queryHostId) {
59
+ queryParamsObj['host_id'] = queryHostId;
60
+ }
61
+ const queryParams = new URLSearchParams(queryParamsObj).toString();
62
+ const formattedPath = options.path.startsWith('/') ? options.path : `/${options.path}`;
63
+ const url = `${this.config.dotcmsUrl}/api/v1/page/json${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
64
+ const response = await fetch(url, this.requestOptions);
65
+ return response.json();
66
+ }
67
+ };
68
+ this.nav = {
69
+ /**
70
+ * `nav.get` is an asynchronous method of the `DotCmsClient` class that retrieves information about the dotCMS file and folder tree.
71
+ * It takes a `NavApiOptions` object as a parameter (with default values) and returns a Promise that resolves to the response from the DotCMS API.
72
+ *
73
+ * The navigation REST API enables you to retrieve information about the dotCMS file and folder tree through REST API calls.
74
+ * @link https://www.dotcms.com/docs/latest/navigation-rest-api
75
+ * @async
76
+ * @param {NavApiOptions} options - The options for the Nav API call. Defaults to `{ depth: 0, path: '/', languageId: 1 }`.
77
+ * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
78
+ * @throws {Error} - Throws an error if the options are not valid.
79
+ */
80
+ get: async (options = { depth: 0, path: '/', languageId: 1 }) => {
81
+ this.validateNavOptions(options);
82
+ // Extract the 'path' from the options and prepare the rest as query parameters
83
+ const { path, ...queryParamsOptions } = options;
84
+ const queryParamsObj = {};
85
+ Object.entries(queryParamsOptions).forEach(([key, value]) => {
86
+ if (value !== undefined) {
87
+ queryParamsObj[key] = String(value);
88
+ }
89
+ });
90
+ const queryParams = new URLSearchParams(queryParamsObj).toString();
91
+ // Format the URL correctly depending on the 'path' value
92
+ const formattedPath = path === '/' ? '/' : `/${path}`;
93
+ const url = `${this.config.dotcmsUrl}/api/v1/nav${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
94
+ const response = await fetch(url, this.requestOptions);
95
+ return response.json();
96
+ }
97
+ };
98
+ if (!config.dotcmsUrl) {
99
+ throw new Error("Invalid configuration - 'dotcmsUrl' is required");
100
+ }
101
+ if (!isValidUrl(config.dotcmsUrl)) {
102
+ throw new Error("Invalid configuration - 'dotcmsUrl' must be a valid URL");
103
+ }
104
+ if (!config.authToken) {
105
+ throw new Error("Invalid configuration - 'authToken' is required");
106
+ }
107
+ this.config = config;
108
+ this.requestOptions = {
109
+ ...this.config.requestOptions,
110
+ headers: {
111
+ Authorization: `Bearer ${this.config.authToken}`,
112
+ ...this.config.requestOptions?.headers
113
+ }
114
+ };
115
+ }
116
+ validatePageOptions(options) {
117
+ if (!options.path) {
118
+ throw new Error("The 'path' parameter is required for the Page API");
119
+ }
120
+ }
121
+ validateNavOptions(options) {
122
+ if (!options.path) {
123
+ throw new Error("The 'path' parameter is required for the Nav API");
124
+ }
125
+ }
126
+ }
127
+ /**
128
+ * `dotcmsClient` is an object that provides a method to initialize the DotCMS SDK client.
129
+ * It has a single method `init` which takes a configuration object and returns an instance of the `DotCmsClient` class.
130
+ *
131
+ * @namespace dotcmsClient
132
+ *
133
+ * @method init(config: ClientConfig): DotCmsClient - Initializes the SDK client.
134
+ */
135
+ export const dotcmsClient = {
136
+ /**
137
+ * `init` is a method of the `dotcmsClient` object that initializes the SDK client.
138
+ * It takes a configuration object as a parameter and returns an instance of the `DotCmsClient` class.
139
+ *
140
+ * @method init
141
+ * @param {ClientConfig} config - The configuration object for the DotCMS client.
142
+ * @returns {DotCmsClient} - An instance of the {@link DotCmsClient} class.
143
+ */
144
+ init: (config) => {
145
+ return new DotCmsClient(config);
146
+ }
147
+ };
148
+ //# sourceMappingURL=sdk-js-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-js-client.js","sourceRoot":"","sources":["../../../../../../../libs/sdk/client/src/lib/client/sdk-js-client.ts"],"names":[],"mappings":"AAwHA,SAAS,UAAU,CAAC,GAAW;IAC3B,IAAI,CAAC;QACD,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAEb,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,YAAY;IAIrB,YACI,SAAuB,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QAyB3F,SAAI,GAAG;YACH;;;;;;;;;;;;eAYG;YACH,GAAG,EAAE,KAAK,EAAE,OAAuB,EAAoB,EAAE;gBACrD,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;gBAElC,MAAM,cAAc,GAA2B,EAAE,CAAC;gBAClD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EA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QAED,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC/E,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACvE,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,cAAc,GAAG;YAClB,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc;YAC7B,OAAO,EAAE;gBACL,aAAa,EAAE,UAAU,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;gBAChD,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,OAAO;aACzC;SACJ,CAAC;IACN,CAAC;IA0FO,mBAAmB,CAAC,OAAuB;QAC/C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACzE,CAAC;IACL,CAAC;IAEO,kBAAkB,CAAC,OAAsB;QAC7C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACxE,CAAC;IACL,CAAC;CACJ;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB;;;;;;;OAOG;IACH,IAAI,EAAE,CAAC,MAAoB,EAAgB,EAAE;QACzC,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;CACJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { DotCMSPageEditorConfig } from '../models/editor.model';
2
+ import { DotCMSPageEditorSubscription } from '../models/listeners.model';
3
+ declare global {
4
+ interface Window {
5
+ lastScrollYPosition: number;
6
+ }
7
+ }
8
+ export declare function setPageEditorConfig(config: DotCMSPageEditorConfig): void;
9
+ /**
10
+ * Represents an array of DotCMSPageEditorSubscription objects.
11
+ * Used to store the subscriptions for the editor and unsubscribe later.
12
+ */
13
+ export declare const subscriptions: DotCMSPageEditorSubscription[];
14
+ /**
15
+ * Listens for editor messages and performs corresponding actions based on the received message.
16
+ *
17
+ * @private
18
+ * @memberof DotCMSPageEditor
19
+ */
20
+ export declare function listenEditorMessages(): void;
21
+ /**
22
+ * Listens for pointer move events and extracts information about the hovered contentlet.
23
+ *
24
+ * @private
25
+ * @memberof DotCMSPageEditor
26
+ */
27
+ export declare function listenHoveredContentlet(): void;
28
+ /**
29
+ * Attaches a scroll event listener to the window
30
+ * and sends a message to the editor when the window is scrolled.
31
+ *
32
+ * @private
33
+ * @memberof DotCMSPageEditor
34
+ */
35
+ export declare function scrollHandler(): void;
36
+ /**
37
+ * Restores the scroll position of the window when an iframe is loaded.
38
+ * Only used in VTL Pages.
39
+ * @export
40
+ */
41
+ export declare function preserveScrollOnIframe(): void;
42
+ /**
43
+ * Sends a ping message to the editor.
44
+ *
45
+ */
46
+ export declare function pingEditor(): void;
@@ -1,41 +1,24 @@
1
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
-
2
+ import { NOTIFY_CUSTOMER } from '../models/listeners.model';
3
+ import { findVTLData, findDotElement, getClosestContainerData, getPageElementBound } from '../utils/editor.utils';
17
4
  /**
18
5
  * Default reload function that reloads the current window.
19
6
  */
20
7
  const defaultReloadFn = () => window.location.reload();
21
-
22
8
  /**
23
9
  * Configuration object for the DotCMSPageEditor.
24
10
  */
25
- let pageEditorConfig: DotCMSPageEditorConfig = {
11
+ let pageEditorConfig = {
26
12
  onReload: defaultReloadFn
27
13
  };
28
-
29
- export function setPageEditorConfig(config: DotCMSPageEditorConfig) {
14
+ export function setPageEditorConfig(config) {
30
15
  pageEditorConfig = config;
31
16
  }
32
-
33
17
  /**
34
18
  * Represents an array of DotCMSPageEditorSubscription objects.
35
19
  * Used to store the subscriptions for the editor and unsubscribe later.
36
20
  */
37
- export const subscriptions: DotCMSPageEditorSubscription[] = [];
38
-
21
+ export const subscriptions = [];
39
22
  /**
40
23
  * Sets the bounds of the containers in the editor.
41
24
  * Retrieves the containers from the DOM and sends their position data to the editor.
@@ -43,24 +26,19 @@ export const subscriptions: DotCMSPageEditorSubscription[] = [];
43
26
  * @memberof DotCMSPageEditor
44
27
  */
45
28
  function setBounds() {
46
- const containers = Array.from(
47
- document.querySelectorAll('[data-dot-object="container"]')
48
- ) as HTMLDivElement[];
29
+ const containers = Array.from(document.querySelectorAll('[data-dot-object="container"]'));
49
30
  const positionData = getPageElementBound(containers);
50
-
51
31
  postMessageToEditor({
52
32
  action: CUSTOMER_ACTIONS.SET_BOUNDS,
53
33
  payload: positionData
54
34
  });
55
35
  }
56
-
57
36
  /**
58
37
  * Reloads the page and triggers the onReload callback if it exists in the config object.
59
38
  */
60
39
  function reloadPage() {
61
40
  pageEditorConfig?.onReload();
62
41
  }
63
-
64
42
  /**
65
43
  * Listens for editor messages and performs corresponding actions based on the received message.
66
44
  *
@@ -68,29 +46,25 @@ function reloadPage() {
68
46
  * @memberof DotCMSPageEditor
69
47
  */
70
48
  export function listenEditorMessages() {
71
- const messageCallback = (event: MessageEvent) => {
49
+ const messageCallback = (event) => {
72
50
  switch (event.data) {
73
51
  case NOTIFY_CUSTOMER.EMA_REQUEST_BOUNDS: {
74
52
  setBounds();
75
53
  break;
76
54
  }
77
-
78
55
  case NOTIFY_CUSTOMER.EMA_RELOAD_PAGE: {
79
56
  reloadPage();
80
57
  break;
81
58
  }
82
59
  }
83
60
  };
84
-
85
61
  window.addEventListener('message', messageCallback);
86
-
87
62
  subscriptions.push({
88
63
  type: 'listener',
89
64
  event: 'message',
90
65
  callback: messageCallback
91
66
  });
92
67
  }
93
-
94
68
  /**
95
69
  * Listens for pointer move events and extracts information about the hovered contentlet.
96
70
  *
@@ -98,29 +72,39 @@ export function listenEditorMessages() {
98
72
  * @memberof DotCMSPageEditor
99
73
  */
100
74
  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);
75
+ const pointerMoveCallback = (event) => {
76
+ const foundElement = findDotElement(event.target);
77
+ if (!foundElement)
78
+ return;
79
+ const { x, y, width, height } = foundElement.getBoundingClientRect();
80
+ const isContainer = foundElement.dataset?.['dotObject'] === 'container';
81
+ const contentletForEmptyContainer = {
82
+ identifier: 'TEMP_EMPTY_CONTENTLET',
83
+ title: 'TEMP_EMPTY_CONTENTLET',
84
+ contentType: 'TEMP_EMPTY_CONTENTLET_TYPE',
85
+ inode: 'TEMPY_EMPTY_CONTENTLET_INODE',
86
+ widgetTitle: 'TEMP_EMPTY_CONTENTLET',
87
+ onNumberOfPages: 1
88
+ };
89
+ const contentlet = {
90
+ identifier: foundElement.dataset?.['dotIdentifier'],
91
+ title: foundElement.dataset?.['dotTitle'],
92
+ inode: foundElement.dataset?.['dotInode'],
93
+ contentType: foundElement.dataset?.['dotType'],
94
+ widgetTitle: foundElement.dataset?.['dotWidgetTitle'],
95
+ onNumberOfPages: foundElement.dataset?.['dotOnNumberOfPages']
96
+ };
97
+ const vtlFiles = findVTLData(foundElement);
107
98
  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
- },
99
+ container:
100
+ // Here extract dot-container from contentlet if is Headless
101
+ // or search in parent container if is VTL
102
+ foundElement.dataset?.['dotContainer']
103
+ ? JSON.parse(foundElement.dataset?.['dotContainer'])
104
+ : getClosestContainerData(foundElement),
105
+ contentlet: isContainer ? contentletForEmptyContainer : contentlet,
121
106
  vtlFiles
122
107
  };
123
-
124
108
  postMessageToEditor({
125
109
  action: CUSTOMER_ACTIONS.SET_CONTENTLET,
126
110
  payload: {
@@ -132,16 +116,13 @@ export function listenHoveredContentlet() {
132
116
  }
133
117
  });
134
118
  };
135
-
136
119
  document.addEventListener('pointermove', pointerMoveCallback);
137
-
138
120
  subscriptions.push({
139
121
  type: 'listener',
140
122
  event: 'pointermove',
141
123
  callback: pointerMoveCallback
142
124
  });
143
125
  }
144
-
145
126
  /**
146
127
  * Attaches a scroll event listener to the window
147
128
  * and sends a message to the editor when the window is scrolled.
@@ -156,16 +137,13 @@ export function scrollHandler() {
156
137
  });
157
138
  window.lastScrollYPosition = window.scrollY;
158
139
  };
159
-
160
140
  window.addEventListener('scroll', scrollCallback);
161
-
162
141
  subscriptions.push({
163
142
  type: 'listener',
164
143
  event: 'scroll',
165
144
  callback: scrollCallback
166
145
  });
167
146
  }
168
-
169
147
  /**
170
148
  * Restores the scroll position of the window when an iframe is loaded.
171
149
  * Only used in VTL Pages.
@@ -175,7 +153,6 @@ export function preserveScrollOnIframe() {
175
153
  const preserveScrollCallback = () => {
176
154
  window.scrollTo(0, window.lastScrollYPosition);
177
155
  };
178
-
179
156
  window.addEventListener('load', preserveScrollCallback);
180
157
  subscriptions.push({
181
158
  type: 'listener',
@@ -183,7 +160,6 @@ export function preserveScrollOnIframe() {
183
160
  callback: preserveScrollCallback
184
161
  });
185
162
  }
186
-
187
163
  /**
188
164
  * Sends a ping message to the editor.
189
165
  *
@@ -193,3 +169,4 @@ export function pingEditor() {
193
169
  action: CUSTOMER_ACTIONS.PING_EDITOR
194
170
  });
195
171
  }
172
+ //# sourceMappingURL=listeners.js.map