@flowuent-org/diagramming-core 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Utility function to highlight search terms in text
5
+ * @param text - The text to highlight
6
+ * @param searchQuery - The search query to highlight
7
+ * @returns React node with highlighted text
8
+ */
9
+ export const highlightText = (text: string, searchQuery: string): React.ReactNode => {
10
+ if (!searchQuery.trim() || !text) {
11
+ return text;
12
+ }
13
+
14
+ const searchLower = searchQuery.toLowerCase();
15
+ const textLower = text.toLowerCase();
16
+ const index = textLower.indexOf(searchLower);
17
+
18
+ if (index === -1) {
19
+ return text;
20
+ }
21
+
22
+ const beforeMatch = text.substring(0, index);
23
+ const match = text.substring(index, index + searchQuery.length);
24
+ const afterMatch = text.substring(index + searchQuery.length);
25
+
26
+ return (
27
+ <>
28
+ {beforeMatch}
29
+ <mark
30
+ style={{
31
+ backgroundColor: '#FFD700',
32
+ color: '#000',
33
+ padding: '2px 4px',
34
+ borderRadius: '3px',
35
+ fontWeight: 'bold',
36
+ }}
37
+ >
38
+ {match}
39
+ </mark>
40
+ {afterMatch}
41
+ </>
42
+ );
43
+ };
44
+
45
+ /**
46
+ * Highlight all occurrences of search query in text
47
+ */
48
+ export const highlightAllOccurrences = (text: string, searchQuery: string): React.ReactNode => {
49
+ if (!searchQuery.trim() || !text) {
50
+ return text;
51
+ }
52
+
53
+ const searchLower = searchQuery.toLowerCase();
54
+ const textLower = text.toLowerCase();
55
+ const parts: React.ReactNode[] = [];
56
+ let lastIndex = 0;
57
+ let index = textLower.indexOf(searchLower, lastIndex);
58
+
59
+ while (index !== -1) {
60
+ // Add text before match
61
+ if (index > lastIndex) {
62
+ parts.push(text.substring(lastIndex, index));
63
+ }
64
+
65
+ // Add highlighted match
66
+ parts.push(
67
+ <mark
68
+ key={index}
69
+ style={{
70
+ backgroundColor: '#FFD700',
71
+ color: '#000',
72
+ padding: '2px 4px',
73
+ borderRadius: '3px',
74
+ fontWeight: 'bold',
75
+ }}
76
+ >
77
+ {text.substring(index, index + searchQuery.length)}
78
+ </mark>
79
+ );
80
+
81
+ lastIndex = index + searchQuery.length;
82
+ index = textLower.indexOf(searchLower, lastIndex);
83
+ }
84
+
85
+ // Add remaining text
86
+ if (lastIndex < text.length) {
87
+ parts.push(text.substring(lastIndex));
88
+ }
89
+
90
+ return <>{parts}</>;
91
+ };
92
+
93
+