@dotcms/client 0.0.1-beta.2 → 0.0.1-beta.21

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 (47) hide show
  1. package/README.md +164 -36
  2. package/index.cjs.js +102 -1238
  3. package/index.esm.js +86 -1221
  4. package/next.cjs.d.ts +1 -0
  5. package/next.cjs.default.js +1 -0
  6. package/next.cjs.js +575 -0
  7. package/next.cjs.mjs +2 -0
  8. package/next.esm.d.ts +1 -0
  9. package/next.esm.js +573 -0
  10. package/package.json +32 -7
  11. package/src/index.d.ts +6 -6
  12. package/src/lib/client/client.d.ts +84 -0
  13. package/src/lib/client/content/builders/collection/collection.d.ts +1 -1
  14. package/src/lib/client/content/content-api.d.ts +1 -1
  15. package/src/lib/client/content/shared/types.d.ts +2 -2
  16. package/src/lib/client/models/types.d.ts +573 -10
  17. package/src/lib/client/navigation/navigation-api.d.ts +31 -0
  18. package/src/lib/client/page/page-api.d.ts +172 -0
  19. package/src/lib/client/page/utils.d.ts +41 -0
  20. package/src/lib/{editor → deprecated/editor}/models/client.model.d.ts +13 -0
  21. package/src/lib/{editor → deprecated/editor}/sdk-editor.d.ts +1 -1
  22. package/src/lib/{client → deprecated}/sdk-js-client.d.ts +1 -1
  23. package/src/lib/utils/page/common-utils.d.ts +1 -1
  24. package/src/next.d.ts +1 -0
  25. package/src/types.d.ts +2 -0
  26. package/transforms.cjs.js +1149 -0
  27. package/transforms.esm.js +1143 -0
  28. package/types.cjs.d.ts +1 -0
  29. package/types.cjs.default.js +1 -0
  30. package/types.cjs.js +2 -0
  31. package/types.cjs.mjs +2 -0
  32. package/types.esm.d.ts +1 -0
  33. package/types.esm.js +1 -0
  34. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Equals.d.ts +0 -0
  35. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Field.d.ts +0 -0
  36. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/NotOperand.d.ts +0 -0
  37. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Operand.d.ts +0 -0
  38. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/index.d.ts +0 -0
  39. /package/src/lib/{query-builder/sdk-query-builder.d.ts → client/content/builders/query/query.d.ts} +0 -0
  40. /package/src/lib/{query-builder → client/content/builders/query}/utils/index.d.ts +0 -0
  41. /package/src/lib/{editor → deprecated/editor}/listeners/listeners.d.ts +0 -0
  42. /package/src/lib/{editor → deprecated/editor}/models/editor.model.d.ts +0 -0
  43. /package/src/lib/{editor → deprecated/editor}/models/inline-event.model.d.ts +0 -0
  44. /package/src/lib/{editor → deprecated/editor}/models/listeners.model.d.ts +0 -0
  45. /package/src/lib/{editor → deprecated/editor}/sdk-editor-vtl.d.ts +0 -0
  46. /package/src/lib/{editor → deprecated/editor}/utils/editor.utils.d.ts +0 -0
  47. /package/src/lib/{editor → deprecated/editor}/utils/traditional-vtl.utils.d.ts +0 -0
package/index.esm.js CHANGED
@@ -1,1066 +1,5 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
- /* global Reflect, Promise, SuppressedError, Symbol */
16
-
17
-
18
- function __classPrivateFieldGet(receiver, state, kind, f) {
19
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
20
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
21
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
22
- }
23
-
24
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
25
- if (kind === "m") throw new TypeError("Private method is not writable");
26
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
27
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
28
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
29
- }
30
-
31
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
32
- var e = new Error(message);
33
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
34
- };
35
-
36
- var _Field_query;
37
- /**
38
- * The `Field` class is used to build a query with a specific field.
39
- * A Lucene Field is a key used to search for a specific value in a document.
40
- *
41
- * @export
42
- * @class Field
43
- */
44
- class Field {
45
- /**
46
- * Creates an instance of the `Field` class.
47
- *
48
- * @param {string} query - The initial query string.
49
- */
50
- constructor(query) {
51
- this.query = query;
52
- _Field_query.set(this, '');
53
- __classPrivateFieldSet(this, _Field_query, this.query, "f");
54
- }
55
- /**
56
- * Appends a term to the query that should be included in the search.
57
- *
58
- * @example
59
- * ```typescript
60
- * const field = new Field("+myField");
61
- * field.equals("myValue");
62
- * ```
63
- *
64
- * @param {string} term - The term that should be included in the search.
65
- * @return {Equals} - An instance of `Equals`.
66
- * @memberof Field
67
- */
68
- equals(term) {
69
- return buildEquals(__classPrivateFieldGet(this, _Field_query, "f"), term);
70
- }
71
- }
72
- _Field_query = new WeakMap();
73
-
74
- var _NotOperand_query;
75
- /**
76
- * 'NotOperand' Is a Typescript class that provides the ability to use the NOT operand in the lucene query string.
77
- *
78
- * @export
79
- * @class NotOperand
80
- */
81
- class NotOperand {
82
- constructor(query) {
83
- this.query = query;
84
- _NotOperand_query.set(this, '');
85
- __classPrivateFieldSet(this, _NotOperand_query, this.query, "f");
86
- }
87
- /**
88
- * This method appends to the query a term that should be included in the search.
89
- *
90
- * @example
91
- * ```typescript
92
- * const notOperand = new NotOperand("+myField");
93
- * notOperand.equals("myValue");
94
- * ```
95
- *
96
- * @param {string} term - The term that should be included in the search.
97
- * @return {*} {Equals} - An instance of Equals.
98
- * @memberof NotOperand
99
- */
100
- equals(term) {
101
- return buildEquals(__classPrivateFieldGet(this, _NotOperand_query, "f"), term);
102
- }
103
- }
104
- _NotOperand_query = new WeakMap();
105
-
106
- var _Operand_query;
107
- /**
108
- * 'Operand' Is a Typescript class that provides the ability to use operands in the lucene query string.}
109
- * An operand is a logical operator used to join two or more conditions in a query.
110
- *
111
- * @export
112
- * @class Operand
113
- */
114
- class Operand {
115
- constructor(query) {
116
- this.query = query;
117
- _Operand_query.set(this, '');
118
- __classPrivateFieldSet(this, _Operand_query, this.query, "f");
119
- }
120
- /**
121
- * This method appends to the query a term that should be excluded in the search.
122
- *
123
- * Ex: "-myValue"
124
- *
125
- * @param {string} field - The field that should be excluded in the search.
126
- * @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
127
- * @memberof Operand
128
- */
129
- excludeField(field) {
130
- return buildExcludeField(__classPrivateFieldGet(this, _Operand_query, "f"), field);
131
- }
132
- /**
133
- * This method appends to the query a field that should be included in the search.
134
- *
135
- * Ex: "+myField:"
136
- *
137
- * @param {string} field - The field that should be included in the search.
138
- * @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
139
- * @memberof Operand
140
- */
141
- field(field) {
142
- return buildField(__classPrivateFieldGet(this, _Operand_query, "f"), field);
143
- }
144
- /**
145
- * This method appends to the query a term that should be included in the search.
146
- *
147
- * Ex: myValue or "My value"
148
- *
149
- * @param {string} term - The term that should be included in the search.
150
- * @return {*} {Equals} - An instance of Equals.
151
- * @memberof Operand
152
- */
153
- equals(term) {
154
- return buildEquals(__classPrivateFieldGet(this, _Operand_query, "f"), term);
155
- }
156
- }
157
- _Operand_query = new WeakMap();
158
-
159
- /**
160
- * Enum for common Operands
161
- *
162
- * @export
163
- * @enum {number}
164
- */
165
- var OPERAND;
166
- (function (OPERAND) {
167
- OPERAND["OR"] = "OR";
168
- OPERAND["AND"] = "AND";
169
- OPERAND["NOT"] = "NOT";
170
- })(OPERAND || (OPERAND = {}));
171
- /**
172
- * This function removes extra spaces from a string.
173
- *
174
- * @example
175
- * ```ts
176
- * sanitizeQuery(" my query "); // Output: "my query"
177
- * ```
178
- *
179
- * @export
180
- * @param {string} str
181
- * @return {*} {string}
182
- */
183
- function sanitizeQuery(str) {
184
- return str.replace(/\s{2,}/g, ' ').trim();
185
- }
186
- /**
187
- * This function sanitizes a term by adding quotes if it contains spaces.
188
- * In lucene, a term with spaces should be enclosed in quotes.
189
- *
190
- * @example
191
- * ```ts
192
- * sanitizePhrases(`my term`); // Output: `"my term"`
193
- * sanitizePhrases(`myterm`); // Output: `myterm`
194
- * ```
195
- *
196
- * @export
197
- * @param {string} term
198
- * @return {*} {string}
199
- */
200
- function sanitizePhrases(term) {
201
- return term.includes(' ') ? `'${term}'` : term;
202
- }
203
- /**
204
- * This function builds a term to be used in a lucene query.
205
- * We need to sanitize the term before adding it to the query.
206
- *
207
- * @example
208
- * ```ts
209
- * const equals = buildEquals("+myField: ", "myValue"); // Current query: "+myField: myValue"
210
- * ```
211
- *
212
- * @export
213
- * @param {string} query
214
- * @param {string} term
215
- * @return {*} {Equals}
216
- */
217
- function buildEquals(query, term) {
218
- const newQuery = query + sanitizePhrases(term);
219
- return new Equals(newQuery);
220
- }
221
- /**
222
- * This function builds a term to be used in a lucene query.
223
- * We need to sanitize the raw query before adding it to the query.
224
- *
225
- * @example
226
- * ```ts
227
- * const query = "+myField: myValue";
228
- * const field = buildRawEquals(query, "-myField2: myValue2"); // Current query: "+myField: myValue -myField2: myValue"
229
- * ```
230
- *
231
- * @export
232
- * @param {string} query
233
- * @param {string} raw
234
- * @return {*} {Equals}
235
- */
236
- function buildRawEquals(query, raw) {
237
- const newQuery = query + ` ${raw}`;
238
- return new Equals(sanitizeQuery(newQuery));
239
- }
240
- /**
241
- * This function builds a field to be used in a lucene query.
242
- * We need to format the field before adding it to the query.
243
- *
244
- * @example
245
- * ```ts
246
- * const field = buildField("+myField: ", "myValue"); // Current query: "+myField: myValue"
247
- * ```
248
- *
249
- * @export
250
- * @param {string} query
251
- * @param {string} field
252
- * @return {*} {Field}
253
- */
254
- function buildField(query, field) {
255
- const newQuery = query + ` +${field}:`;
256
- return new Field(newQuery);
257
- }
258
- /**
259
- * This function builds an exclude field to be used in a lucene query.
260
- * We need to format the field before adding it to the query.
261
- *
262
- * @example
263
- * ```ts
264
- * const query = "+myField: myValue";
265
- * const field = buildExcludeField(query, "myField2"); // Current query: "+myField: myValue -myField2:"
266
- * ```
267
- *
268
- * @export
269
- * @param {string} query
270
- * @param {string} field
271
- * @return {*} {Field}
272
- */
273
- function buildExcludeField(query, field) {
274
- const newQuery = query + ` -${field}:`;
275
- return new Field(newQuery);
276
- }
277
- /**
278
- * This function builds an operand to be used in a lucene query.
279
- * We need to format the operand before adding it to the query.
280
- *
281
- * @example
282
- * <caption>E.g. Using the AND operand</caption>
283
- * ```ts
284
- * const query = "+myField: myValue";
285
- * const field = buildOperand(query, OPERAND.AND); // Current query: "+myField: myValue AND"
286
- * ```
287
- * @example
288
- * <caption>E.g. Using the OR operand</caption>
289
- * ```ts
290
- * const query = "+myField: myValue";
291
- * const field = buildOperand(query, OPERAND.OR); // Current query: "+myField: myValue OR"
292
- * ```
293
- * @export
294
- * @param {string} query
295
- * @param {OPERAND} operand
296
- * @return {*} {Operand}
297
- */
298
- function buildOperand(query, operand) {
299
- const newQuery = query + ` ${operand} `;
300
- return new Operand(newQuery);
301
- }
302
- /**
303
- * This function builds a NOT operand to be used in a lucene query.
304
- * We need to format the operand before adding it to the query.
305
- *
306
- * @example
307
- * ```ts
308
- * const query = "+myField: myValue";
309
- * const field = buildNotOperand(query); // Current query: "+myField: myValue NOT"
310
- * ```
311
- *
312
- * @export
313
- * @param {string} query
314
- * @return {*} {NotOperand}
315
- */
316
- function buildNotOperand(query) {
317
- const newQuery = query + ` ${OPERAND.NOT} `;
318
- return new NotOperand(newQuery);
319
- }
320
-
321
- var _Equals_query;
322
- /**
323
- * 'Equal' Is a Typescript class that provides the ability to use terms in the lucene query string.
324
- * A term is a value used to search for a specific value in a document. It can be a word or a phrase.
325
- *
326
- * Ex: myValue or "My Value"
327
- *
328
- * @export
329
- * @class Equal
330
- */
331
- class Equals {
332
- constructor(query) {
333
- this.query = query;
334
- _Equals_query.set(this, '');
335
- __classPrivateFieldSet(this, _Equals_query, this.query, "f");
336
- }
337
- /**
338
- * This method appends to the query a term that should be excluded in the search.
339
- *
340
- * @example
341
- * ```ts
342
- * const equals = new Equals("+myField: myValue");
343
- * equals.excludeField("myField2").equals("myValue2"); // Current query: "+myField: myValue -myField2: myValue2"
344
- * ```
345
- *
346
- * @param {string} field - The field that should be excluded in the search.
347
- * @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
348
- * @memberof Equal
349
- */
350
- excludeField(field) {
351
- return buildExcludeField(__classPrivateFieldGet(this, _Equals_query, "f"), field);
352
- }
353
- /**
354
- * This method appends to the query a field that should be included in the search.
355
- *
356
- * @example
357
- * ```ts
358
- * const equals = new Equals("+myField: myValue");
359
- * equals.field("myField2").equals("myValue2"); // Current query: "+myField: myValue +myField2: myValue2"
360
- *```
361
- * @param {string} field - The field that should be included in the search.
362
- * @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
363
- * @memberof Equal
364
- */
365
- field(field) {
366
- return buildField(__classPrivateFieldGet(this, _Equals_query, "f"), field);
367
- }
368
- /**
369
- * This method appends to the query an operand to use logic operators in the query.
370
- *
371
- * @example
372
- * @example
373
- * ```ts
374
- * const equals = new Equals("+myField: myValue");
375
- * equals.or().field("myField2").equals("myValue2"); // Current query: "+myField: myValue OR +myField2: myValue2"
376
- * ```
377
- *
378
- * @return {*} {Operand} - An instance of a Lucene Operand. An operand is a logical operator used to combine terms or phrases in a query.
379
- * @memberof Equal
380
- */
381
- or() {
382
- return buildOperand(__classPrivateFieldGet(this, _Equals_query, "f"), OPERAND.OR);
383
- }
384
- /**
385
- * This method appends to the query an operand to use logic operators in the query.
386
- *
387
- * @example
388
- * ```ts
389
- * const equals = new Equals("+myField: myValue");
390
- * equals.and().field("myField2").equals("myValue2"); // Current query: "+myField: myValue AND +myField2: myValue2"
391
- * ```
392
- *
393
- * @return {*} {Operand} - An instance of a Lucene Operand. An operand is a logical operator used to combine terms or phrases in a query.
394
- * @memberof Equal
395
- */
396
- and() {
397
- return buildOperand(__classPrivateFieldGet(this, _Equals_query, "f"), OPERAND.AND);
398
- }
399
- /**
400
- * This method appends to the query an operand to use logic operators in the query.
401
- *
402
- * @example
403
- * ```ts
404
- * const equals = new Equals("+myField: myValue");
405
- * equals.not().field("myField").equals("myValue2"); // Current query: "+myField: myValue NOT +myField: myValue2"
406
- * ```
407
- *
408
- * @return {*} {NotOperand} - An instance of a Lucene Not Operand. A not operand is a logical operator used to exclude terms or phrases in a query.
409
- * @memberof Equal
410
- */
411
- not() {
412
- return buildNotOperand(__classPrivateFieldGet(this, _Equals_query, "f"));
413
- }
414
- /**
415
- * This method allows to pass a raw query string to the query builder.
416
- * This raw query should end in a Lucene Equal.
417
- * This method is useful when you want to append a complex query or an already written query to the query builder.
418
- *
419
- * @example
420
- * ```ts
421
- * // This builds the follow raw query "+myField: value AND (someOtherValue OR anotherValue)"
422
- * const equals = new Equals("+myField: value");
423
- * equals.raw("+myField2: value2"); // Current query: "+myField: value +myField2: anotherValue"
424
- * ```
425
- *
426
- * @param {string} query - A raw query string.
427
- * @return {*} {Equal} - An instance of a Lucene Equal. A term is a value used to search for a specific value in a document.
428
- * @memberof QueryBuilder
429
- */
430
- raw(query) {
431
- return buildRawEquals(__classPrivateFieldGet(this, _Equals_query, "f"), query);
432
- }
433
- /**
434
- * This method returns the final query string.
435
- *
436
- * @example
437
- * ```ts
438
- * const equals = new Equals("+myField: myValue");
439
- * equals.field("myField2").equals("myValue2").build(); // Returns "+myField: myValue +myField2: myValue2"
440
- * ```
441
- *
442
- * @return {*} {string} - The final query string.
443
- * @memberof Equal
444
- */
445
- build() {
446
- return sanitizeQuery(__classPrivateFieldGet(this, _Equals_query, "f"));
447
- }
448
- }
449
- _Equals_query = new WeakMap();
450
-
451
- var _QueryBuilder_query;
452
- /**
453
- * 'QueryBuilder' Is a Typescript class that provides the ability to build a query string using the Lucene syntax in a more readable way.
454
- * @example
455
- * ```ts
456
- * const qb = new QueryBuilder();
457
- * const query = qb
458
- * .field('contentType')
459
- * .equals('Blog')
460
- * .field('conhost')
461
- * .equals('my-super-cool-site')
462
- * .build(); // Output: `+contentType:Blog +conhost:my-super-cool-site"`
463
- * ```
464
- *
465
- * @example
466
- * ```ts
467
- * const qb = new QueryBuilder();
468
- * const query = qb
469
- * .field('contentType')
470
- * .equals('Blog')
471
- * .field('title')
472
- * .equals('Football')
473
- * .excludeField('summary')
474
- * .equals('Lionel Messi')
475
- * .build(); // Output: `+contentType:Blog +title:Football -summary:"Lionel Messi"`
476
- * ```
477
- * @export
478
- * @class QueryBuilder
479
- */
480
- class QueryBuilder {
481
- constructor() {
482
- _QueryBuilder_query.set(this, '');
483
- }
484
- /**
485
- * This method appends to the query a field that should be included in the search.
486
- *
487
- * @example
488
- * ```ts
489
- * const qb = new QueryBuilder();
490
- * qb.field("+myField: ", "myValue"); // Current query: "+myField: myValue"
491
- * ```
492
- *
493
- * @param {string} field - The field that should be included in the search.
494
- * @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
495
- * @memberof QueryBuilder
496
- */
497
- field(field) {
498
- return buildField(__classPrivateFieldGet(this, _QueryBuilder_query, "f"), field);
499
- }
500
- /**
501
- * This method appends to the query a field that should be excluded from the search.
502
- *
503
- * @example
504
- * ```ts
505
- * const qb = new QueryBuilder();
506
- * qb.excludeField("myField").equals("myValue"); // Current query: "-myField: myValue"
507
- * ```
508
- *
509
- * @param {string} field - The field that should be excluded from the search.
510
- * @return {*} {Field} - An instance of a Lucene Exclude Field. An exclude field is a key used to exclude for a specific value in a document.
511
- * @memberof QueryBuilder
512
- */
513
- excludeField(field) {
514
- return buildExcludeField(__classPrivateFieldGet(this, _QueryBuilder_query, "f"), field);
515
- }
516
- /**
517
- * This method allows to pass a raw query string to the query builder.
518
- * This raw query should end in Equals.
519
- * This method is useful when you want to append a complex query or an already written query to the query builder.
520
- *
521
- * @example
522
- * ```ts
523
- * const qb = new QueryBuilder();
524
- * qb.raw("+myField: value AND (someOtherValue OR anotherValue)"); // Current query: "+myField: value AND (someOtherValue OR anotherValue)"
525
- * ```
526
- *
527
- * @param {string} query - A raw query string.
528
- * @return {*} {Equals} - An instance of Equals. A term is a value used to search for a specific value in a document.
529
- * @memberof QueryBuilder
530
- */
531
- raw(query) {
532
- return buildRawEquals(__classPrivateFieldGet(this, _QueryBuilder_query, "f"), query);
533
- }
534
- }
535
- _QueryBuilder_query = new WeakMap();
536
-
537
- /**
538
- * Default variant identifier used in the application.
539
- */
540
- /**
541
- * Fields that should not be formatted when sanitizing the query.
542
- * These fields are essential for maintaining the integrity of the content type.
543
- */
544
- const CONTENT_TYPE_MAIN_FIELDS = ['live', 'variant', 'contentType', 'languageId'];
545
- /**
546
- * URL endpoint for the content API search functionality.
547
- */
548
- const CONTENT_API_URL = '/api/content/_search';
549
-
550
- /**
551
- * @description
552
- * Sanitizes the query for the given content type.
553
- * It replaces the fields that are not content type fields with the correct format.
554
- * Example: +field: -> +contentTypeVar.field:
555
- *
556
- * @example
557
- *
558
- * ```ts
559
- * const query = '+field: value';
560
- * const contentType = 'contentTypeVar';
561
- * const sanitizedQuery = sanitizeQueryForContentType(query, contentType); // Output: '+contentTypeVar.field: value'
562
- * ```
563
- *
564
- * @export
565
- * @param {string} query - The query string to be sanitized.
566
- * @param {string} contentType - The content type to be used for formatting the fields.
567
- * @returns {string} The sanitized query string.
568
- */
569
- function sanitizeQueryForContentType(query, contentType) {
570
- return query.replace(/\+([^+:]*?):/g, (original, field) => {
571
- return !CONTENT_TYPE_MAIN_FIELDS.includes(field) // Fields that are not content type fields
572
- ? `+${contentType}.${field}:` // Should have this format: +contentTypeVar.field:
573
- : original; // Return the field if it is a content type field
574
- });
575
- }
576
-
577
- var _CollectionBuilder_page, _CollectionBuilder_limit, _CollectionBuilder_depth, _CollectionBuilder_render, _CollectionBuilder_sortBy, _CollectionBuilder_contentType, _CollectionBuilder_defaultQuery, _CollectionBuilder_query, _CollectionBuilder_rawQuery, _CollectionBuilder_languageId, _CollectionBuilder_draft, _CollectionBuilder_serverUrl, _CollectionBuilder_requestOptions;
578
- /**
579
- * Creates a Builder to filter and fetch content from the content API for a specific content type.
580
- *
581
- * @export
582
- * @class CollectionBuilder
583
- * @template T Represents the type of the content type to fetch. Defaults to unknown.
584
- */
585
- class CollectionBuilder {
586
- /**
587
- * Creates an instance of CollectionBuilder.
588
- * @param {ClientOptions} requestOptions Options for the client request.
589
- * @param {string} serverUrl The server URL.
590
- * @param {string} contentType The content type to fetch.
591
- * @memberof CollectionBuilder
592
- */
593
- constructor(requestOptions, serverUrl, contentType) {
594
- _CollectionBuilder_page.set(this, 1);
595
- _CollectionBuilder_limit.set(this, 10);
596
- _CollectionBuilder_depth.set(this, 0);
597
- _CollectionBuilder_render.set(this, false);
598
- _CollectionBuilder_sortBy.set(this, void 0);
599
- _CollectionBuilder_contentType.set(this, void 0);
600
- _CollectionBuilder_defaultQuery.set(this, void 0);
601
- _CollectionBuilder_query.set(this, void 0);
602
- _CollectionBuilder_rawQuery.set(this, void 0);
603
- _CollectionBuilder_languageId.set(this, 1);
604
- _CollectionBuilder_draft.set(this, false);
605
- _CollectionBuilder_serverUrl.set(this, void 0);
606
- _CollectionBuilder_requestOptions.set(this, void 0);
607
- __classPrivateFieldSet(this, _CollectionBuilder_requestOptions, requestOptions, "f");
608
- __classPrivateFieldSet(this, _CollectionBuilder_serverUrl, serverUrl, "f");
609
- __classPrivateFieldSet(this, _CollectionBuilder_contentType, contentType, "f");
610
- // Build the default query with the contentType field
611
- __classPrivateFieldSet(this, _CollectionBuilder_defaultQuery, new QueryBuilder().field('contentType').equals(__classPrivateFieldGet(this, _CollectionBuilder_contentType, "f")), "f");
612
- }
613
- /**
614
- * Returns the sort query in the format: field order, field order, ...
615
- *
616
- * @readonly
617
- * @private
618
- * @memberof CollectionBuilder
619
- */
620
- get sort() {
621
- return __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")?.map((sort) => `${sort.field} ${sort.order}`).join(',');
622
- }
623
- /**
624
- * Returns the offset for pagination.
625
- *
626
- * @readonly
627
- * @private
628
- * @memberof CollectionBuilder
629
- */
630
- get offset() {
631
- return __classPrivateFieldGet(this, _CollectionBuilder_limit, "f") * (__classPrivateFieldGet(this, _CollectionBuilder_page, "f") - 1);
632
- }
633
- /**
634
- * Returns the full URL for the content API.
635
- *
636
- * @readonly
637
- * @private
638
- * @memberof CollectionBuilder
639
- */
640
- get url() {
641
- return `${__classPrivateFieldGet(this, _CollectionBuilder_serverUrl, "f")}${CONTENT_API_URL}`;
642
- }
643
- /**
644
- * Returns the current query built.
645
- *
646
- * @readonly
647
- * @private
648
- * @memberof CollectionBuilder
649
- */
650
- get currentQuery() {
651
- return __classPrivateFieldGet(this, _CollectionBuilder_query, "f") ?? __classPrivateFieldGet(this, _CollectionBuilder_defaultQuery, "f");
652
- }
653
- /**
654
- * Filters the content by the specified language ID.
655
- *
656
- * @example
657
- * ```typescript
658
- * const client = new DotCMSClient(config);
659
- * const collectionBuilder = client.content.getCollection("Blog");
660
- * collectionBuilder.language(1);
661
- * ```
662
- *
663
- * @param {number | string} languageId The language ID to filter the content by.
664
- * @return {CollectionBuilder} A CollectionBuilder instance.
665
- * @memberof CollectionBuilder
666
- */
667
- language(languageId) {
668
- __classPrivateFieldSet(this, _CollectionBuilder_languageId, languageId, "f");
669
- return this;
670
- }
671
- /**
672
- * Setting this to true will server side render (using velocity) any widgets that are returned by the content query.
673
- *
674
- * More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
675
- *
676
- * @return {CollectionBuilder} A CollectionBuilder instance.
677
- * @memberof CollectionBuilder
678
- */
679
- render() {
680
- __classPrivateFieldSet(this, _CollectionBuilder_render, true, "f");
681
- return this;
682
- }
683
- /**
684
- * Sorts the content by the specified fields and orders.
685
- *
686
- * @example
687
- * ```typescript
688
- * const client = new DotCMSClient(config);
689
- * const collectionBuilder = client.content.getCollection("Blog");
690
- * const sortBy = [{ field: 'title', order: 'asc' }, { field: 'modDate', order: 'desc' }];
691
- * collectionBuilder("Blog").sortBy(sortBy);
692
- * ```
693
- *
694
- * @param {SortBy[]} sortBy Array of constraints to sort the content by.
695
- * @return {CollectionBuilder} A CollectionBuilder instance.
696
- * @memberof CollectionBuilder
697
- */
698
- sortBy(sortBy) {
699
- __classPrivateFieldSet(this, _CollectionBuilder_sortBy, sortBy, "f");
700
- return this;
701
- }
702
- /**
703
- * Sets the maximum amount of content to fetch.
704
- *
705
- * @param {number} limit The maximum amount of content to fetch.
706
- * @return {CollectionBuilder} A CollectionBuilder instance.
707
- * @memberof CollectionBuilder
708
- */
709
- limit(limit) {
710
- __classPrivateFieldSet(this, _CollectionBuilder_limit, limit, "f");
711
- return this;
712
- }
713
- /**
714
- * Sets the page number to fetch.
715
- *
716
- * @param {number} page The page number to fetch.
717
- * @return {CollectionBuilder} A CollectionBuilder instance.
718
- * @memberof CollectionBuilder
719
- */
720
- page(page) {
721
- __classPrivateFieldSet(this, _CollectionBuilder_page, page, "f");
722
- return this;
723
- }
724
- query(arg) {
725
- if (typeof arg === 'string') {
726
- __classPrivateFieldSet(this, _CollectionBuilder_rawQuery, arg, "f");
727
- return this;
728
- }
729
- if (typeof arg !== 'function') {
730
- throw new Error(`Parameter for query method should be a buildQuery function or a string.\nExample:\nclient.content.getCollection('Activity').query((queryBuilder) => queryBuilder.field('title').equals('Hello World'))\nor\nclient.content.getCollection('Activity').query('+Activity.title:"Hello World"') \nSee documentation for more information.`);
731
- }
732
- const builtQuery = arg(new QueryBuilder());
733
- // This can be use in Javascript so we cannot rely on the type checking
734
- if (builtQuery instanceof Equals) {
735
- __classPrivateFieldSet(this, _CollectionBuilder_query, builtQuery.raw(this.currentQuery.build()), "f");
736
- }
737
- else {
738
- throw new Error('Provided query is not valid. A query should end in an equals method call.\nExample:\n(queryBuilder) => queryBuilder.field("title").equals("Hello World")\nSee documentation for more information.');
739
- }
740
- return this;
741
- }
742
- /**
743
- * Retrieves draft content.
744
- * @example
745
- * ```ts
746
- * const client = new DotCMSClient(config);
747
- * const collectionBuilder = client.content.getCollection("Blog");
748
- * collectionBuilder
749
- * .draft() // This will retrieve draft/working content
750
- * .then((response) => // Your code here })
751
- * .catch((error) => // Your code here })
752
- * ```
753
- *
754
- * @return {CollectionBuilder} A CollectionBuilder instance.
755
- * @memberof CollectionBuilder
756
- */
757
- draft() {
758
- __classPrivateFieldSet(this, _CollectionBuilder_draft, true, "f");
759
- return this;
760
- }
761
- /**
762
- * Filters the content by a variant ID for [Experiments](https://www.dotcms.com/docs/latest/experiments-and-a-b-testing)
763
- *
764
- * More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
765
- *
766
- * @example
767
- * ```ts
768
- * const client = new DotCMSClient(config);
769
- * const collectionBuilder = client.content.getCollection("Blog");
770
- * collectionBuilder
771
- * .variant("YOUR_VARIANT_ID")
772
- * .then((response) => // Your code here })
773
- * .catch((error) => // Your code here })
774
- * ```
775
- *
776
- * @param {string} variantId A string that represents a variant ID.
777
- * @return {CollectionBuilder} A CollectionBuilder instance.
778
- * @memberof CollectionBuilder
779
- */
780
- variant(variantId) {
781
- __classPrivateFieldSet(this, _CollectionBuilder_query, this.currentQuery.field('variant').equals(variantId), "f");
782
- return this;
783
- }
784
- /**
785
- * Sets the depth of the relationships of the content.
786
- * Specifies the depth of related content to return in the results.
787
- *
788
- * More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
789
- *
790
- * @example
791
- * ```ts
792
- * const client = new DotCMSClient(config);
793
- * const collectionBuilder = client.content.getCollection("Blog");
794
- * collectionBuilder
795
- * .depth(1)
796
- * .then((response) => // Your code here })
797
- * .catch((error) => // Your code here })
798
- * ```
799
- *
800
- * @param {number} depth The depth of the relationships of the content.
801
- * @return {CollectionBuilder} A CollectionBuilder instance.
802
- * @memberof CollectionBuilder
803
- */
804
- depth(depth) {
805
- if (depth < 0 || depth > 3) {
806
- throw new Error('Depth value must be between 0 and 3');
807
- }
808
- __classPrivateFieldSet(this, _CollectionBuilder_depth, depth, "f");
809
- return this;
810
- }
811
- /**
812
- * Executes the fetch and returns a promise that resolves to the content or rejects with an error.
813
- *
814
- * @example
815
- * ```ts
816
- * const client = new DotCMSClient(config);
817
- * const collectionBuilder = client.content.getCollection("Blog");
818
- * collectionBuilder
819
- * .limit(10)
820
- * .then((response) => // Your code here })
821
- * .catch((error) => // Your code here })
822
- * ```
823
- *
824
- * @param {OnFullfilled} [onfulfilled] A callback that is called when the fetch is successful.
825
- * @param {OnRejected} [onrejected] A callback that is called when the fetch fails.
826
- * @return {Promise<GetCollectionResponse<T> | GetCollectionError>} A promise that resolves to the content or rejects with an error.
827
- * @memberof CollectionBuilder
828
- */
829
- then(onfulfilled, onrejected) {
830
- return this.fetch().then(async (response) => {
831
- const data = await response.json();
832
- if (response.ok) {
833
- const formattedResponse = this.formatResponse(data);
834
- const finalResponse = typeof onfulfilled === 'function'
835
- ? onfulfilled(formattedResponse)
836
- : formattedResponse;
837
- return finalResponse;
838
- }
839
- else {
840
- return {
841
- status: response.status,
842
- ...data
843
- };
844
- }
845
- }, onrejected);
846
- }
847
- /**
848
- * Formats the response to the desired format.
849
- *
850
- * @private
851
- * @param {GetCollectionRawResponse<T>} data The raw response data.
852
- * @return {GetCollectionResponse<T>} The formatted response.
853
- * @memberof CollectionBuilder
854
- */
855
- formatResponse(data) {
856
- const contentlets = data.entity.jsonObjectView.contentlets;
857
- const total = data.entity.resultsSize;
858
- const mappedResponse = {
859
- contentlets,
860
- total,
861
- page: __classPrivateFieldGet(this, _CollectionBuilder_page, "f"),
862
- size: contentlets.length
863
- };
864
- return __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")
865
- ? {
866
- ...mappedResponse,
867
- sortedBy: __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")
868
- }
869
- : mappedResponse;
870
- }
871
- /**
872
- * Calls the content API to fetch the content.
873
- *
874
- * @private
875
- * @return {Promise<Response>} The fetch response.
876
- * @memberof CollectionBuilder
877
- */
878
- fetch() {
879
- const finalQuery = this.currentQuery
880
- .field('languageId')
881
- .equals(__classPrivateFieldGet(this, _CollectionBuilder_languageId, "f").toString())
882
- .field('live')
883
- .equals((!__classPrivateFieldGet(this, _CollectionBuilder_draft, "f")).toString())
884
- .build();
885
- const sanitizedQuery = sanitizeQueryForContentType(finalQuery, __classPrivateFieldGet(this, _CollectionBuilder_contentType, "f"));
886
- const query = __classPrivateFieldGet(this, _CollectionBuilder_rawQuery, "f") ? `${sanitizedQuery} ${__classPrivateFieldGet(this, _CollectionBuilder_rawQuery, "f")}` : sanitizedQuery;
887
- return fetch(this.url, {
888
- ...__classPrivateFieldGet(this, _CollectionBuilder_requestOptions, "f"),
889
- method: 'POST',
890
- headers: {
891
- ...__classPrivateFieldGet(this, _CollectionBuilder_requestOptions, "f").headers,
892
- 'Content-Type': 'application/json'
893
- },
894
- body: JSON.stringify({
895
- query,
896
- render: __classPrivateFieldGet(this, _CollectionBuilder_render, "f"),
897
- sort: this.sort,
898
- limit: __classPrivateFieldGet(this, _CollectionBuilder_limit, "f"),
899
- offset: this.offset,
900
- depth: __classPrivateFieldGet(this, _CollectionBuilder_depth, "f")
901
- //userId: This exist but we currently don't use it
902
- //allCategoriesInfo: This exist but we currently don't use it
903
- })
904
- });
905
- }
906
- }
907
- _CollectionBuilder_page = new WeakMap(), _CollectionBuilder_limit = new WeakMap(), _CollectionBuilder_depth = new WeakMap(), _CollectionBuilder_render = new WeakMap(), _CollectionBuilder_sortBy = new WeakMap(), _CollectionBuilder_contentType = new WeakMap(), _CollectionBuilder_defaultQuery = new WeakMap(), _CollectionBuilder_query = new WeakMap(), _CollectionBuilder_rawQuery = new WeakMap(), _CollectionBuilder_languageId = new WeakMap(), _CollectionBuilder_draft = new WeakMap(), _CollectionBuilder_serverUrl = new WeakMap(), _CollectionBuilder_requestOptions = new WeakMap();
908
-
909
- var _Content_requestOptions, _Content_serverUrl;
910
- /**
911
- * Creates a builder to filter and fetch a collection of content items.
912
- * @param contentType - The content type to retrieve.
913
- * @returns A CollectionBuilder instance for chaining filters and executing the query.
914
- * @template T - The type of the content items (defaults to unknown).
915
- *
916
- * @example Fetch blog posts with async/await
917
- * ```typescript
918
- * const response = await client.content
919
- * .getCollection<BlogPost>('Blog')
920
- * .limit(10)
921
- * .page(2)
922
- * .sortBy([{ field: 'title', order: 'asc' }])
923
- * .query(q => q.field('author').equals('John Doe'))
924
- * .depth(1)
925
- * .fetch();
926
- *
927
- * console.log(response.contentlets);
928
- * ```
929
- *
930
- * @example Fetch blog posts with Promise chain
931
- * ```typescript
932
- * client.content
933
- * .getCollection<BlogPost>('Blog')
934
- * .limit(10)
935
- * .page(2)
936
- * .sortBy([{ field: 'title', order: 'asc' }])
937
- * .query(q => q.field('author').equals('John Doe'))
938
- * .depth(1)
939
- * .fetch()
940
- * .then(response => console.log(response.contentlets))
941
- * .catch(error => console.error(error));
942
- * ```
943
- *
944
- * @example Using a custom type
945
- * ```typescript
946
- * interface BlogPost {
947
- * summary: string;
948
- * author: string;
949
- * title: string;
950
- * }
951
- *
952
- * const posts = await client.content
953
- * .getCollection<BlogPost>('Blog')
954
- * .limit(10)
955
- * .fetch();
956
- *
957
- * posts.contentlets.forEach(post => {
958
- * console.log(post.title, post.author, post.summary);
959
- * });
960
- * ```
961
- */
962
- class Content {
963
- /**
964
- * Creates an instance of Content.
965
- * @param {ClientOptions} requestOptions - The options for the client request.
966
- * @param {string} serverUrl - The server URL.
967
- */
968
- constructor(requestOptions, serverUrl) {
969
- _Content_requestOptions.set(this, void 0);
970
- _Content_serverUrl.set(this, void 0);
971
- __classPrivateFieldSet(this, _Content_requestOptions, requestOptions, "f");
972
- __classPrivateFieldSet(this, _Content_serverUrl, serverUrl, "f");
973
- }
974
- /**
975
- * Takes a content type and returns a builder to filter and fetch the collection.
976
- * @param {string} contentType - The content type to get the collection.
977
- * @return {CollectionBuilder<T>} CollectionBuilder to filter and fetch the collection.
978
- * @template T - Represents the type of the content type to fetch. Defaults to unknown.
979
- * @memberof Content
980
- *
981
- * @example
982
- * ```javascript
983
- * // Using await and async
984
- * const collectionResponse = await client.content
985
- * .getCollection('Blog')
986
- * .limit(10)
987
- * .page(2)
988
- * .sortBy([{ field: 'title', order: 'asc' }])
989
- * .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
990
- * .depth(1);
991
- * ```
992
- * @example
993
- * ```javascript
994
- * // Using then and catch
995
- * client.content
996
- * .getCollection('Blog')
997
- * .limit(10)
998
- * .page(2)
999
- * .sortBy([{ field: 'title', order: 'asc' }])
1000
- * .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
1001
- * .depth(1)
1002
- * .then((response) => {
1003
- * console.log(response.contentlets);
1004
- * })
1005
- * .catch((error) => {
1006
- * console.error(error);
1007
- * });
1008
- * ```
1009
- * @example
1010
- * ```typescript
1011
- * // Using a specific type for your content
1012
- *
1013
- * type Blog = {
1014
- * summary: string;
1015
- * author: string;
1016
- * title: string;
1017
- * };
1018
- *
1019
- * client.content
1020
- * .getCollection<Blog>('Blog')
1021
- * .limit(10)
1022
- * .page(2)
1023
- * .sortBy([{ field: 'title', order: 'asc' }])
1024
- * .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
1025
- * .depth(1)
1026
- * .then((response) => {
1027
- * response.contentlets.forEach((blog) => {
1028
- * console.log(blog.title);
1029
- * console.log(blog.author);
1030
- * console.log(blog.summary);
1031
- * });
1032
- * })
1033
- * .catch((error) => {
1034
- * console.error(error);
1035
- * });
1036
- * ```
1037
- *
1038
- */
1039
- getCollection(contentType) {
1040
- return new CollectionBuilder(__classPrivateFieldGet(this, _Content_requestOptions, "f"), __classPrivateFieldGet(this, _Content_serverUrl, "f"), contentType);
1041
- }
1042
- }
1043
- _Content_requestOptions = new WeakMap(), _Content_serverUrl = new WeakMap();
1044
-
1045
- /**
1046
- * A record of HTTP status codes and their corresponding error messages.
1047
- *
1048
- * @type {Record<number, string>}
1049
- * @property {string} 401 - Unauthorized. Check the token and try again.
1050
- * @property {string} 403 - Forbidden. Check the permissions and try again.
1051
- * @property {string} 404 - Not Found. Check the URL and try again.
1052
- * @property {string} 500 - Internal Server Error. Try again later.
1053
- * @property {string} 502 - Bad Gateway. Try again later.
1054
- * @property {string} 503 - Service Unavailable. Try again later.
1055
- */
1056
- const ErrorMessages = {
1057
- 401: 'Unauthorized. Check the token and try again.',
1058
- 403: 'Forbidden. Check the permissions and try again.',
1059
- 404: 'Not Found. Check the URL and try again.',
1060
- 500: 'Internal Server Error. Try again later.',
1061
- 502: 'Bad Gateway. Try again later.',
1062
- 503: 'Service Unavailable. Try again later.'
1063
- };
1
+ import { _ as __classPrivateFieldGet, E as ErrorMessages, a as __classPrivateFieldSet, C as Content } from './transforms.esm.js';
2
+ export { g as graphqlToPageEntity } from './transforms.esm.js';
1064
3
 
1065
4
  /**
1066
5
  * Actions received from the dotcms editor
@@ -1096,89 +35,6 @@ var NOTIFY_CLIENT;
1096
35
  NOTIFY_CLIENT["UVE_COPY_CONTENTLET_INLINE_EDITING_SUCCESS"] = "uve-copy-contentlet-inline-editing-success";
1097
36
  })(NOTIFY_CLIENT || (NOTIFY_CLIENT = {}));
1098
37
 
1099
- const INITIAL_DOT_UVE = {
1100
- editContentlet,
1101
- initInlineEditing,
1102
- reorderMenu,
1103
- lastScrollYPosition: 0
1104
- };
1105
- /**
1106
- * Actions send to the dotcms editor
1107
- *
1108
- * @export
1109
- * @enum {number}
1110
- */
1111
- var CLIENT_ACTIONS;
1112
- (function (CLIENT_ACTIONS) {
1113
- /**
1114
- * Tell the dotcms editor that page change
1115
- */
1116
- CLIENT_ACTIONS["NAVIGATION_UPDATE"] = "set-url";
1117
- /**
1118
- * Send the element position of the rows, columnsm containers and contentlets
1119
- */
1120
- CLIENT_ACTIONS["SET_BOUNDS"] = "set-bounds";
1121
- /**
1122
- * Send the information of the hovered contentlet
1123
- */
1124
- CLIENT_ACTIONS["SET_CONTENTLET"] = "set-contentlet";
1125
- /**
1126
- * Tell the editor that the page is being scrolled
1127
- */
1128
- CLIENT_ACTIONS["IFRAME_SCROLL"] = "scroll";
1129
- /**
1130
- * Tell the editor that the page has stopped scrolling
1131
- */
1132
- CLIENT_ACTIONS["IFRAME_SCROLL_END"] = "scroll-end";
1133
- /**
1134
- * Ping the editor to see if the page is inside the editor
1135
- */
1136
- CLIENT_ACTIONS["PING_EDITOR"] = "ping-editor";
1137
- /**
1138
- * Tell the editor to init the inline editing editor.
1139
- */
1140
- CLIENT_ACTIONS["INIT_INLINE_EDITING"] = "init-inline-editing";
1141
- /**
1142
- * Tell the editor to open the Copy-contentlet dialog
1143
- * To copy a content and then edit it inline.
1144
- */
1145
- CLIENT_ACTIONS["COPY_CONTENTLET_INLINE_EDITING"] = "copy-contentlet-inline-editing";
1146
- /**
1147
- * Tell the editor to save inline edited contentlet
1148
- */
1149
- CLIENT_ACTIONS["UPDATE_CONTENTLET_INLINE_EDITING"] = "update-contentlet-inline-editing";
1150
- /**
1151
- * Tell the editor to trigger a menu reorder
1152
- */
1153
- CLIENT_ACTIONS["REORDER_MENU"] = "reorder-menu";
1154
- /**
1155
- * Tell the editor to send the page info to iframe
1156
- */
1157
- CLIENT_ACTIONS["GET_PAGE_DATA"] = "get-page-data";
1158
- /**
1159
- * Tell the editor an user send a graphql query
1160
- */
1161
- CLIENT_ACTIONS["CLIENT_READY"] = "client-ready";
1162
- /**
1163
- * Tell the editor to edit a contentlet
1164
- */
1165
- CLIENT_ACTIONS["EDIT_CONTENTLET"] = "edit-contentlet";
1166
- /**
1167
- * Tell the editor to do nothing
1168
- */
1169
- CLIENT_ACTIONS["NOOP"] = "noop";
1170
- })(CLIENT_ACTIONS || (CLIENT_ACTIONS = {}));
1171
- /**
1172
- * Post message to dotcms page editor
1173
- *
1174
- * @export
1175
- * @template T
1176
- * @param {PostMessageProps<T>} message
1177
- */
1178
- function postMessageToEditor(message) {
1179
- window.parent.postMessage(message, '*');
1180
- }
1181
-
1182
38
  /**
1183
39
  * Calculates the bounding information for each page element within the given containers.
1184
40
  *
@@ -1661,6 +517,89 @@ function destroyEditor() {
1661
517
  });
1662
518
  }
1663
519
 
520
+ const INITIAL_DOT_UVE = {
521
+ editContentlet,
522
+ initInlineEditing,
523
+ reorderMenu,
524
+ lastScrollYPosition: 0
525
+ };
526
+ /**
527
+ * Actions send to the dotcms editor
528
+ *
529
+ * @export
530
+ * @enum {number}
531
+ */
532
+ var CLIENT_ACTIONS;
533
+ (function (CLIENT_ACTIONS) {
534
+ /**
535
+ * Tell the dotcms editor that page change
536
+ */
537
+ CLIENT_ACTIONS["NAVIGATION_UPDATE"] = "set-url";
538
+ /**
539
+ * Send the element position of the rows, columnsm containers and contentlets
540
+ */
541
+ CLIENT_ACTIONS["SET_BOUNDS"] = "set-bounds";
542
+ /**
543
+ * Send the information of the hovered contentlet
544
+ */
545
+ CLIENT_ACTIONS["SET_CONTENTLET"] = "set-contentlet";
546
+ /**
547
+ * Tell the editor that the page is being scrolled
548
+ */
549
+ CLIENT_ACTIONS["IFRAME_SCROLL"] = "scroll";
550
+ /**
551
+ * Tell the editor that the page has stopped scrolling
552
+ */
553
+ CLIENT_ACTIONS["IFRAME_SCROLL_END"] = "scroll-end";
554
+ /**
555
+ * Ping the editor to see if the page is inside the editor
556
+ */
557
+ CLIENT_ACTIONS["PING_EDITOR"] = "ping-editor";
558
+ /**
559
+ * Tell the editor to init the inline editing editor.
560
+ */
561
+ CLIENT_ACTIONS["INIT_INLINE_EDITING"] = "init-inline-editing";
562
+ /**
563
+ * Tell the editor to open the Copy-contentlet dialog
564
+ * To copy a content and then edit it inline.
565
+ */
566
+ CLIENT_ACTIONS["COPY_CONTENTLET_INLINE_EDITING"] = "copy-contentlet-inline-editing";
567
+ /**
568
+ * Tell the editor to save inline edited contentlet
569
+ */
570
+ CLIENT_ACTIONS["UPDATE_CONTENTLET_INLINE_EDITING"] = "update-contentlet-inline-editing";
571
+ /**
572
+ * Tell the editor to trigger a menu reorder
573
+ */
574
+ CLIENT_ACTIONS["REORDER_MENU"] = "reorder-menu";
575
+ /**
576
+ * Tell the editor to send the page info to iframe
577
+ */
578
+ CLIENT_ACTIONS["GET_PAGE_DATA"] = "get-page-data";
579
+ /**
580
+ * Tell the editor an user send a graphql query
581
+ */
582
+ CLIENT_ACTIONS["CLIENT_READY"] = "client-ready";
583
+ /**
584
+ * Tell the editor to edit a contentlet
585
+ */
586
+ CLIENT_ACTIONS["EDIT_CONTENTLET"] = "edit-contentlet";
587
+ /**
588
+ * Tell the editor to do nothing
589
+ */
590
+ CLIENT_ACTIONS["NOOP"] = "noop";
591
+ })(CLIENT_ACTIONS || (CLIENT_ACTIONS = {}));
592
+ /**
593
+ * Post message to dotcms page editor
594
+ *
595
+ * @export
596
+ * @template T
597
+ * @param {PostMessageProps<T>} message
598
+ */
599
+ function postMessageToEditor(message) {
600
+ window.parent.postMessage(message, '*');
601
+ }
602
+
1664
603
  var _DotCmsClient_config, _DotCmsClient_requestOptions, _DotCmsClient_listeners;
1665
604
  function getHostURL(url) {
1666
605
  try {
@@ -1928,80 +867,6 @@ class DotCmsClient {
1928
867
  }
1929
868
  _DotCmsClient_config = new WeakMap(), _DotCmsClient_requestOptions = new WeakMap(), _DotCmsClient_listeners = new WeakMap();
1930
869
 
1931
- /**
1932
- * Transforms a GraphQL Page response to a Page Entity.
1933
- *
1934
- * @param {GraphQLPageResponse} graphQLPageResponse - The GraphQL Page response object.
1935
- * @returns {object|null} The transformed Page Entity or null if the page is not present.
1936
- *
1937
- * @example
1938
- * ```ts
1939
- * const pageEntity = graphqlToPageEntity(graphQLPageResponse);
1940
- * ```
1941
- */
1942
- const graphqlToPageEntity = (graphQLPageResponse) => {
1943
- const { page } = graphQLPageResponse;
1944
- // If there is no page, return null
1945
- if (!page) {
1946
- return null;
1947
- }
1948
- const { layout, template, containers, urlContentMap, viewAs, site, _map, ...pageAsset } = page;
1949
- const data = (_map || {});
1950
- return {
1951
- layout,
1952
- template,
1953
- viewAs,
1954
- urlContentMap,
1955
- site,
1956
- page: {
1957
- ...data,
1958
- ...pageAsset
1959
- },
1960
- containers: parseContainers(containers)
1961
- };
1962
- };
1963
- /**
1964
- * Parses the containers from the GraphQL response.
1965
- *
1966
- * @param {Array<Record<string, unknown>>} [containers=[]] - The containers array from the GraphQL response.
1967
- * @returns {Record<string, unknown>} The parsed containers.
1968
- */
1969
- const parseContainers = (containers = []) => {
1970
- return containers.reduce((acc, container) => {
1971
- const { path, identifier, containerStructures, containerContentlets, ...rest } = container;
1972
- const key = (path || identifier);
1973
- acc[key] = {
1974
- containerStructures,
1975
- container: {
1976
- path,
1977
- identifier,
1978
- ...rest
1979
- },
1980
- contentlets: parseContentletsToUuidMap(containerContentlets)
1981
- };
1982
- return acc;
1983
- }, {});
1984
- };
1985
- /**
1986
- * Parses the contentlets from the GraphQL response.
1987
- *
1988
- * @param {Array<Record<string, unknown>>} containerContentlets - The contentlets array from the GraphQL response.
1989
- * @returns {Record<string, Array<Record<string, unknown>>>} The parsed contentlets mapped by UUID.
1990
- */
1991
- const parseContentletsToUuidMap = (containerContentlets = []) => {
1992
- return containerContentlets.reduce((acc, containerContentlet) => {
1993
- const { uuid, contentlets } = containerContentlet;
1994
- // TODO: This is a temporary solution, we need to find a better way to handle this.
1995
- acc[uuid] = contentlets.map(({ _map = {}, ...rest }) => {
1996
- return {
1997
- ..._map,
1998
- ...rest
1999
- };
2000
- });
2001
- return acc;
2002
- }, {});
2003
- };
2004
-
2005
870
  /**
2006
871
  * Generates the page request parameters to be used in the API call.
2007
872
  *
@@ -2035,4 +900,4 @@ const getPageRequestParams = ({ path = '', params = {} }) => {
2035
900
  };
2036
901
  };
2037
902
 
2038
- export { CLIENT_ACTIONS, DotCmsClient, NOTIFY_CLIENT, destroyEditor, editContentlet, getPageRequestParams, graphqlToPageEntity, initEditor, initInlineEditing, isInsideEditor, postMessageToEditor, reorderMenu, updateNavigation };
903
+ export { CLIENT_ACTIONS, DotCmsClient, NOTIFY_CLIENT, destroyEditor, editContentlet, getPageRequestParams, initEditor, initInlineEditing, isInsideEditor, postMessageToEditor, reorderMenu, updateNavigation };