ublo-lib 1.46.16 → 1.47.0

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.
@@ -8,11 +8,11 @@ import * as Messages from "./messages";
8
8
  import * as Utils from "./utils";
9
9
  import css from "./cookie-consent.module.css";
10
10
  const { publicRuntimeConfig } = getConfig();
11
- const { gaAccount, hotjar } = publicRuntimeConfig;
11
+ const { gaAccount, hotjar, enableCookieConsent } = publicRuntimeConfig;
12
12
  const COOKIE_STORAGE = "cookie_allowed";
13
13
  const CookieConsent = ({ lang, consent, updateConsent }) => {
14
14
  const [mounted, setMounted] = React.useState(false);
15
- const isEnabled = Boolean(gaAccount || hotjar);
15
+ const isEnabled = Boolean(enableCookieConsent || gaAccount || hotjar);
16
16
  const cookieAllowed = (value) => () => {
17
17
  updateConsent(value);
18
18
  };
@@ -0,0 +1,8 @@
1
+ type Props = {
2
+ search: string;
3
+ selector: string;
4
+ customHighlightName?: string;
5
+ };
6
+ export default function highlight({ search, selector, customHighlightName, }: Props): void;
7
+ export {};
8
+ //# sourceMappingURL=highlight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"highlight.d.ts","sourceRoot":"","sources":["../../../src/common/utils/highlight.ts"],"names":[],"mappings":"AAAA,KAAK,KAAK,GAAG;IACX,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAChC,MAAM,EACN,QAAQ,EACR,mBAA8B,GAC/B,EAAE,KAAK,QAkCP"}
@@ -0,0 +1,61 @@
1
+ export default function highlight({ search, selector, customHighlightName = "search", }) {
2
+ if (!selector) {
3
+ throw new Error("The selector argument is required");
4
+ }
5
+ if (!CSS.highlights)
6
+ return;
7
+ CSS.highlights.delete(customHighlightName);
8
+ if (!search) {
9
+ return;
10
+ }
11
+ const ranges = [];
12
+ try {
13
+ const elements = Array.from(document.querySelectorAll(selector));
14
+ elements.map((element) => {
15
+ getTextNodesInElementContainingText(element, search).forEach((node) => {
16
+ if (!node?.parentElement)
17
+ return;
18
+ ranges.push(...getRangesForSearchTermInElement(node.parentElement, search));
19
+ });
20
+ });
21
+ }
22
+ catch (error) {
23
+ console.error(error);
24
+ }
25
+ if (ranges.length === 0)
26
+ return;
27
+ const highlight = new Highlight(...ranges);
28
+ CSS.highlights.set(customHighlightName, highlight);
29
+ }
30
+ const getTextNodesInElementContainingText = (element, text) => {
31
+ const lowerCaseText = text.toLowerCase();
32
+ const nodes = [];
33
+ const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);
34
+ let node;
35
+ while ((node = walker.nextNode())) {
36
+ if (node.textContent?.toLowerCase().includes(lowerCaseText)) {
37
+ nodes.push(node);
38
+ }
39
+ }
40
+ return nodes;
41
+ };
42
+ const getRangesForSearchTermInElement = (element, search) => {
43
+ const ranges = [];
44
+ const lowerCaseSearch = search.toLowerCase();
45
+ if (element.childNodes.length === 0)
46
+ return ranges;
47
+ const childWithSearchTerm = Array.from(element.childNodes).find((node) => node.textContent?.toLowerCase().includes(lowerCaseSearch));
48
+ if (!childWithSearchTerm)
49
+ return ranges;
50
+ const text = childWithSearchTerm.textContent?.toLowerCase() || "";
51
+ let start = 0;
52
+ let index;
53
+ while ((index = text.indexOf(lowerCaseSearch, start)) >= 0) {
54
+ const range = new Range();
55
+ range.setStart(childWithSearchTerm, index);
56
+ range.setEnd(childWithSearchTerm, index + search.length);
57
+ ranges.push(range);
58
+ start = index + search.length;
59
+ }
60
+ return ranges;
61
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ublo-lib",
3
- "version": "1.46.16",
3
+ "version": "1.47.0",
4
4
  "peerDependencies": {
5
5
  "classnames": "^2.5.1",
6
6
  "dt-design-system": "^3.12.0",