@coveo/quantic 3.30.3-pre.b400a05b95 → 3.30.3-pre.bfb80506e9

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 (27) hide show
  1. package/force-app/main/default/lwc/quanticUtils/markdownUtils.js +16 -3
  2. package/force-app/main/default/lwc/quanticUtils/quanticUtils.js +105 -17
  3. package/force-app/main/default/staticresources/coveoheadless/case-assist/headless.js +8 -8
  4. package/force-app/main/default/staticresources/coveoheadless/definitions/api/knowledge/stream-answer-api.d.ts +9 -7
  5. package/force-app/main/default/staticresources/coveoheadless/definitions/api/search/search-api-params.d.ts +1 -1
  6. package/force-app/main/default/staticresources/coveoheadless/definitions/features/configuration/configuration-selectors.d.ts +51 -0
  7. package/force-app/main/default/staticresources/coveoheadless/definitions/features/dictionary-field-context/dictionary-field-context-selectors.d.ts +4 -0
  8. package/force-app/main/default/staticresources/coveoheadless/definitions/features/excerpt-length/excerpt-length-selectors.d.ts +26 -0
  9. package/force-app/main/default/staticresources/coveoheadless/definitions/features/facet-options/facet-options-selectors.d.ts +7 -0
  10. package/force-app/main/default/staticresources/coveoheadless/definitions/features/folding/folding-selectors.d.ts +9 -0
  11. package/force-app/main/default/staticresources/coveoheadless/definitions/features/generated-answer/generated-answer-actions.d.ts +2 -2
  12. package/force-app/main/default/staticresources/coveoheadless/definitions/features/generated-answer/generated-answer-mocks.d.ts +209 -0
  13. package/force-app/main/default/staticresources/coveoheadless/definitions/features/generated-answer/generated-answer-request.d.ts +46 -57
  14. package/force-app/main/default/staticresources/coveoheadless/definitions/features/generated-answer/generated-answer-state.d.ts +2 -2
  15. package/force-app/main/default/staticresources/coveoheadless/definitions/features/query/query-selectors.d.ts +25 -0
  16. package/force-app/main/default/staticresources/coveoheadless/definitions/features/search/legacy/search-request.d.ts +1 -3
  17. package/force-app/main/default/staticresources/coveoheadless/definitions/features/search/search-request.d.ts +1 -3
  18. package/force-app/main/default/staticresources/coveoheadless/definitions/features/sort-criteria/sort-criteria-selectors.d.ts +26 -0
  19. package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-next/commerce/factories/build-factory.d.ts +2 -2
  20. package/force-app/main/default/staticresources/coveoheadless/definitions/test/mock-search-request.d.ts +1 -3
  21. package/force-app/main/default/staticresources/coveoheadless/definitions/utils/utils.d.ts +3 -0
  22. package/force-app/main/default/staticresources/coveoheadless/headless.js +10 -10
  23. package/force-app/main/default/staticresources/coveoheadless/insight/headless.js +9 -9
  24. package/force-app/main/default/staticresources/coveoheadless/recommendation/headless.js +7 -7
  25. package/package.json +2 -2
  26. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/knowledge/generated-answer/headless-answerapi-generated-answer-mocks.d.ts +0 -9036
  27. package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/knowledge/generated-answer/utils/testingUtils.d.ts +0 -8
@@ -7,6 +7,9 @@ import {loadScript} from 'lightning/platformResourceLoader';
7
7
  * Transforms a single line of text that may contain HTML to plain text.
8
8
  * @param {string} textWithHtml A single line of text that may contain HTML
9
9
  * @returns {string} The value as plain text
10
+ * @example
11
+ * toInlinePlainText('<p>Hello <strong>World</strong></p>');
12
+ * // Returns: 'Hello World'
10
13
  */
11
14
  const toInlinePlainText = (textWithHtml) => {
12
15
  const withoutHtmlTags = textWithHtml.replace(/<[^>]*>/g, ' ');
@@ -21,7 +24,7 @@ const unclosedElement = /(\*{1,3}|`)($|\w[\w\s]*$)/;
21
24
  /**
22
25
  * Complete unclosed elements such as bold, italic, and code.
23
26
  * @param {string} text
24
- * @returns {string}
27
+ * @returns {string} The original content with closed tags.
25
28
  */
26
29
  const completeUnclosedElement = (text) => {
27
30
  const match = unclosedElement.exec(text);
@@ -41,6 +44,11 @@ const completeUnclosedElement = (text) => {
41
44
  return text;
42
45
  };
43
46
 
47
+ /**
48
+ * Escape HTML special characters in a string.
49
+ * @param {String} text
50
+ * @returns {string} The escaped HTML string.
51
+ */
44
52
  const escapeHtml = (text) => {
45
53
  return text
46
54
  .replace(/&/g, '&amp;')
@@ -50,6 +58,10 @@ const escapeHtml = (text) => {
50
58
  .replace(/'/g, '&#39;');
51
59
  };
52
60
 
61
+ /**
62
+ * Custom Marked renderer to override the default rendering of certain elements.
63
+ * See: https://marked.js.org/using_pro
64
+ */
53
65
  const customRenderer = {
54
66
  code(code) {
55
67
  return `<pre><code>${escapeHtml(code)}</code></pre>`;
@@ -59,6 +71,7 @@ const customRenderer = {
59
71
  * Custom Marked renderer to replace heading elements with div elements.
60
72
  * @param {string} text
61
73
  * @param {string} level
74
+ * @return {string} The heading element to render.
62
75
  */
63
76
  heading(text, level) {
64
77
  const plainText = toInlinePlainText(text);
@@ -69,7 +82,7 @@ const customRenderer = {
69
82
  /**
70
83
  * Returns escaped HTML.
71
84
  * @param {string} text
72
- * @returns
85
+ * @returns {string} The escaped HTML string.
73
86
  */
74
87
  html(text) {
75
88
  return escapeHtml(text);
@@ -119,7 +132,7 @@ const transformMarkdownToHtml = (text, marked) => {
119
132
 
120
133
  /**
121
134
  * Load the libraries Marked and DOMPurify.
122
- * @param element
135
+ * @param element
123
136
  * @returns {Promise<any>}
124
137
  */
125
138
  const loadMarkdownDependencies = (element) => {
@@ -37,6 +37,9 @@ export * from './markdownUtils';
37
37
  export * from './facetDependenciesUtils';
38
38
  export * from './citationAnchoringUtils';
39
39
 
40
+ /**
41
+ * Utility class for debouncing function calls.
42
+ */
40
43
  export class Debouncer {
41
44
  _timeout;
42
45
 
@@ -90,14 +93,18 @@ export class Deferred {
90
93
  }
91
94
  }
92
95
 
96
+ /**
97
+ * Utility class for working with search results and binding analytics events.
98
+ */
93
99
  export class ResultUtils {
94
100
  /**
95
- * Binds the logging of document
96
- * @returns An unbind function for the events
101
+ * Binds analytics logging events to result elements.
97
102
  * @param {import("coveo").SearchEngine} engine An instance of an Headless Engine
98
103
  * @param {import("coveo").Result} result The result object
99
104
  * @param {import("lwc").ShadowRootTheGoodPart} resultElement Parent result element
105
+ * @param {Function} controllerBuilder Function to build the interactive result controller.
100
106
  * @param {string} selector Optional. Css selector that selects all links to the document. Default: "a" tags with the clickUri as "href" parameter.
107
+ * @returns An unbind function for the events
101
108
  */
102
109
  static bindClickEventsOnResult(
103
110
  engine,
@@ -137,12 +144,15 @@ export class ResultUtils {
137
144
  }
138
145
  }
139
146
 
147
+ /**
148
+ * Utility class for link operations and analytics binding.
149
+ */
140
150
  export class LinkUtils {
141
151
  /**
142
152
  * Binds the logging of a link
143
- * @returns An unbind function for the events
144
153
  * @param {HTMLAnchorElement} link the link element
145
154
  * @param {{select:function, beginDelayedSelect: function, cancelPendingSelect: function }} actions
155
+ * @returns An unbind function for the events
146
156
  */
147
157
  static bindAnalyticsToLink(link, actions) {
148
158
  const eventsMap = {
@@ -165,6 +175,9 @@ export class LinkUtils {
165
175
  }
166
176
  }
167
177
 
178
+ /**
179
+ * Utility class for internationalization and localization.
180
+ */
168
181
  export class I18nUtils {
169
182
  static getTextWithDecorator(text, startTag, endTag) {
170
183
  return `${startTag}${text}${endTag}`;
@@ -178,6 +191,13 @@ export class I18nUtils {
178
191
  return new Intl.PluralRules(LOCALE).select(count) === 'one';
179
192
  }
180
193
 
194
+ /**
195
+ * Gets the label name with count.
196
+ * @param {string} labelName
197
+ * @param {string|number} count
198
+ * @returns {string} The label name with count.
199
+ * @example `labelName_zero`, `labelName_plural` or `labelName`
200
+ */
181
201
  static getLabelNameWithCount(labelName, count) {
182
202
  if (count === 0) {
183
203
  return `${labelName}_zero`;
@@ -187,6 +207,16 @@ export class I18nUtils {
187
207
  return labelName;
188
208
  }
189
209
 
210
+ /**
211
+ * Formats a string with the given arguments.
212
+ * @param {String} stringToFormat
213
+ * @param {...any} formattingArguments
214
+ * @returns {string} The formatted string.
215
+ * @throws {Error} If string format is not a string.
216
+ * @example
217
+ * I18nUtils.format('Hello {{0}}, you have {{1}} new messages', 'John', 5);
218
+ * returns 'Hello John, you have 5 new messages'
219
+ */
190
220
  static format(stringToFormat, ...formattingArguments) {
191
221
  if (typeof stringToFormat !== 'string')
192
222
  throw new Error("'stringToFormat' must be a String");
@@ -197,6 +227,11 @@ export class I18nUtils {
197
227
  );
198
228
  }
199
229
 
230
+ /**
231
+ * Gets the short date pattern for the current locale.
232
+ * @returns {string} The short date pattern.
233
+ * @example `M/d/yyyy` for `en-US`, `d/M/yyyy` for `fr-FR`, etc.
234
+ */
200
235
  static getShortDatePattern() {
201
236
  const date = new Date(2000, 2, 4); // month is zero-based
202
237
  const dateAsString = I18nUtils.formatDate(date);
@@ -215,11 +250,13 @@ export class I18nUtils {
215
250
  }
216
251
 
217
252
  /**
253
+ * Formats the date in the current locale.
218
254
  * @param {Date} date
255
+ * @returns {string} The formatted date.
219
256
  */
220
257
  static formatDate(date) {
221
- const result = new Intl.DateTimeFormat(LOCALE).format(date);
222
- return result;
258
+ const formattedDate = new Intl.DateTimeFormat(LOCALE).format(date);
259
+ return formattedDate;
223
260
  }
224
261
 
225
262
  /**
@@ -227,15 +264,24 @@ export class I18nUtils {
227
264
  * @returns {string}
228
265
  */
229
266
  static escapeHTML(html) {
230
- var escape = document.createElement('textarea');
267
+ const escape = document.createElement('textarea');
231
268
  escape.textContent = html;
232
269
  // eslint-disable-next-line @lwc/lwc/no-inner-html
233
270
  return escape.innerHTML;
234
271
  }
235
272
  }
236
273
 
274
+ /**
275
+ * Storage key for standalone search box configuration.
276
+ * @constant {string}
277
+ */
237
278
  export const STANDALONE_SEARCH_BOX_STORAGE_KEY = 'coveo-standalone-search-box';
238
279
 
280
+ /**
281
+ * Key codes for common keyboard interactions.
282
+ * @readonly
283
+ * @enum {string}
284
+ */
239
285
  export const keys = {
240
286
  ESC: 'Escape',
241
287
  TAB: 'Tab',
@@ -259,15 +305,24 @@ export function setItemInLocalStorage(key, item) {
259
305
  /**
260
306
  * Replace char found in pattern with \\$&
261
307
  * @param {string} value
308
+ * @return {string}
262
309
  */
263
310
  export function regexEncode(value) {
264
311
  return value.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
265
312
  }
266
-
313
+ /**
314
+ * Parses an XML string into a DOM Document.
315
+ * @param {string} string
316
+ * @returns {Document}
317
+ */
267
318
  export function parseXML(string) {
268
319
  return new window.DOMParser().parseFromString(string, 'text/xml');
269
320
  }
270
321
 
322
+ /**
323
+ * Utility class for time-based calculations and formatting.
324
+ * Provides methods to convert between different time units and format durations.
325
+ */
271
326
  export class TimeSpan {
272
327
  constructor(time, isMilliseconds = true) {
273
328
  if (isMilliseconds) {
@@ -344,6 +399,10 @@ export class TimeSpan {
344
399
  }
345
400
  }
346
401
 
402
+ /**
403
+ * Utility class for date operations and formatting.
404
+ * Handles conversion between different date formats and provides parsing utilities.
405
+ */
347
406
  export class DateUtils {
348
407
  /**
349
408
  * Converts a date string from the Coveo Search API format to the ISO-8601 format.
@@ -391,6 +450,7 @@ export class DateUtils {
391
450
  * @param {number} hours The local hours to set on the date.
392
451
  * @param {number} minutes The local minutes to set on the date.
393
452
  * @param {number} seconds The local seconds to set on the date.
453
+ * @throws {Error} If specified time is invalid.
394
454
  * @returns {Date} The parsed date.
395
455
  */
396
456
  static fromLocalIsoDate(dateString, hours, minutes, seconds) {
@@ -418,6 +478,11 @@ export class DateUtils {
418
478
  return new Date(`${withoutTime}T${time}`);
419
479
  }
420
480
 
481
+ /**
482
+ * Trims the time portion from an ISO 8601 date string.
483
+ * @param {string} dateString
484
+ * @returns {string}
485
+ */
421
486
  static trimIsoTime(dateString) {
422
487
  const timeIdx = dateString.indexOf('T');
423
488
  return timeIdx !== -1 ? dateString.substring(0, timeIdx) : dateString;
@@ -425,6 +490,7 @@ export class DateUtils {
425
490
 
426
491
  /**
427
492
  * @param {number} timestamp
493
+ * @returns {boolean}
428
494
  */
429
495
  static isValidTimestamp(timestamp) {
430
496
  let isValid = true;
@@ -439,8 +505,6 @@ export class DateUtils {
439
505
 
440
506
  /**
441
507
  * Parses a given timestamp into detailed date components.
442
- *
443
- * @function
444
508
  * @param {number} timestamp - The timestamp in milliseconds since January 1, 1970 (epoch time).
445
509
  * @returns {Object} An object containing the following date details:
446
510
  * - {number} year - The four-digit year (e.g., 2024).
@@ -497,6 +561,10 @@ export function fromSearchApiDate(dateString) {
497
561
  return DateUtils.fromSearchApiDate(dateString);
498
562
  }
499
563
 
564
+ /**
565
+ * Formats relative date ranges into human-readable strings.
566
+ * Supports past and future date ranges with proper pluralization.
567
+ */
500
568
  export class RelativeDateFormatter {
501
569
  constructor() {
502
570
  this.singularIndex = 0;
@@ -519,10 +587,15 @@ export class RelativeDateFormatter {
519
587
  }
520
588
 
521
589
  /**
522
- *
523
- * @param {RelativeDate} begin
524
- * @param {RelativeDate} end
525
- * @returns {string}
590
+ * Formats a relative date range into a human-readable string.
591
+ * @param {RelativeDate} begin The beginning of the relative date range.
592
+ * @param {RelativeDate} end The end of the relative date range.
593
+ * @returns {string} The formatted human-readable date range.
594
+ * @throws {Error} If the provided relative date range is invalid.
595
+ * @example
596
+ * begin = { period: 'past', unit: 'day', amount: 2 };
597
+ * end = { period: 'now', unit: 'day', amount: 1 };
598
+ * Output: "2 days ago - 1 day ago"
526
599
  */
527
600
  formatRange(begin, end) {
528
601
  const isPastRange = begin.period === 'past' && end.period === 'now';
@@ -546,6 +619,10 @@ export class RelativeDateFormatter {
546
619
  }
547
620
  }
548
621
 
622
+ /**
623
+ * Utility class for managing a simple in-memory store.
624
+ * Supports registering and retrieving facet and sort option data.
625
+ */
549
626
  export class Store {
550
627
  static facetTypes = {
551
628
  FACETS: 'facets',
@@ -565,6 +642,7 @@ export class Store {
565
642
  };
566
643
  }
567
644
  /**
645
+ * Registers a facet to the store if it does not already exist.
568
646
  * @param {Record<String, unknown>} store
569
647
  * @param {string} facetType
570
648
  * @param {{ label?: string; facetId: any; format?: Function;}} data
@@ -577,6 +655,7 @@ export class Store {
577
655
  }
578
656
 
579
657
  /**
658
+ * Registers sort option data to the store.
580
659
  * @param {Record<String, any>} store
581
660
  * @param {Array<{label: string; value: string; criterion: SortCriterion;}>} data
582
661
  */
@@ -585,15 +664,19 @@ export class Store {
585
664
  }
586
665
 
587
666
  /**
667
+ * Gets facet data from the store.
588
668
  * @param {Record<String, unknown>} store
589
669
  * @param {string} facetType
670
+ * @return {Object} The facet data.
590
671
  */
591
672
  static getFromStore(store, facetType) {
592
673
  return store.state[facetType];
593
674
  }
594
675
 
595
676
  /**
677
+ * Gets sort options from the store.
596
678
  * @param {Record<String, Object>} store
679
+ * @return {Array} The sort options.
597
680
  */
598
681
  static getSortOptionsFromStore(store) {
599
682
  return store.state.sort;
@@ -612,7 +695,7 @@ export class Store {
612
695
  * @param {string} regionName
613
696
  * @param {Object} elem
614
697
  * @param {boolean} assertive
615
- * @returns {AriaLiveUtils}
698
+ * @returns {AriaLiveUtils} Object with methods to dispatch messages and register the region.
616
699
  */
617
700
  export function AriaLiveRegion(regionName, elem, assertive = false) {
618
701
  function dispatchMessage(message) {
@@ -763,6 +846,7 @@ export function isCustomElement(element) {
763
846
  /**
764
847
  * Returns the last focusable element in an HTML slot.
765
848
  * @param {HTMLElement & {assignedElements?: () => Array<HTMLElement> | null}} slotElement
849
+ * @returns {HTMLElement | null}
766
850
  */
767
851
  function getLastFocusableElementFromSlot(slotElement) {
768
852
  if (!slotElement && slotElement.assignedElements) {
@@ -782,6 +866,7 @@ function getLastFocusableElementFromSlot(slotElement) {
782
866
  /**
783
867
  * Returns the first focusable element in an HTML slot.
784
868
  * @param {HTMLElement & {assignedElements?: () => Array<HTMLElement> | null}} slotElement
869
+ * @return {HTMLElement | null}
785
870
  */
786
871
  function getFirstFocusableElementFromSlot(slotElement) {
787
872
  if (!slotElement && slotElement.assignedElements) {
@@ -802,6 +887,7 @@ function getFirstFocusableElementFromSlot(slotElement) {
802
887
  * Checks whether an element is indeed the targetElement or one of its parents.
803
888
  * @param {HTMLElement} element
804
889
  * @param {string} targetElement
890
+ * @returns {boolean}
805
891
  */
806
892
  export function isParentOf(element, targetElement) {
807
893
  if (!element || element.nodeType === Node.TEXT_NODE) {
@@ -827,6 +913,7 @@ export function isParentOf(element, targetElement) {
827
913
  * Copies text to clipboard using the Clipboard API.
828
914
  * https://developer.mozilla.org/en-US/docs/Web/API/Clipboard
829
915
  * @param {string} text
916
+ * @return {Promise<void>}
830
917
  */
831
918
  export async function copyToClipboard(text) {
832
919
  try {
@@ -853,6 +940,7 @@ export function copyToClipboardFallback(text) {
853
940
  * Read the value of a given key from an object.
854
941
  * @param {object} object
855
942
  * @param {string} key
943
+ * @return {object | undefined} The value of the key.
856
944
  */
857
945
  export function readFromObject(object, key) {
858
946
  const firstPeriodIndex = key.indexOf('.');
@@ -898,9 +986,9 @@ export function getElementPadding(element) {
898
986
  }
899
987
 
900
988
  /**
901
- * Returns the absolute width of an element.
989
+ * Returns the absolute height of an element.
902
990
  * @param {Element} element
903
- * @returns {number}
991
+ * @returns {number} The absolute height of the element including padding.
904
992
  */
905
993
  export function getAbsoluteHeight(element) {
906
994
  if (!element) {
@@ -916,7 +1004,7 @@ export function getAbsoluteHeight(element) {
916
1004
  /**
917
1005
  * Returns the absolute width of an element.
918
1006
  * @param {Element} element
919
- * @returns {number}
1007
+ * @returns {number} The absolute width of the element including padding.
920
1008
  */
921
1009
  export function getAbsoluteWidth(element) {
922
1010
  if (!element) {