titaned-frontend-library 1.0.16 → 1.0.18

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 (59) hide show
  1. package/CHANGELOG.md +43 -43
  2. package/MEILISEARCH_INTEGRATION.md +261 -261
  3. package/README.md +235 -235
  4. package/SEARCH_INTEGRATION_README.md +208 -208
  5. package/dist/components/AnnouncementBanner.scss +193 -0
  6. package/dist/components/ButtonComponent.scss +3 -3
  7. package/dist/components/Footer.scss +86 -86
  8. package/dist/components/MainHeader.scss +920 -920
  9. package/dist/components/Sidebar.scss +176 -176
  10. package/dist/components/common/AnnouncementBanner/AnnouncementBanner.d.ts +4 -0
  11. package/dist/components/common/menu/MenuComponent.d.ts +0 -4
  12. package/dist/contexts/SidebarContext.d.ts +1 -0
  13. package/dist/index.cjs +9 -9
  14. package/dist/index.css +1 -1
  15. package/dist/index.d.ts +2 -0
  16. package/dist/index.js +553 -499
  17. package/dist/interfaces/components.d.ts +5 -0
  18. package/eslint.config.js +28 -28
  19. package/index.html +13 -13
  20. package/next.config.ts +34 -34
  21. package/package.json +44 -44
  22. package/src/App.css +65 -65
  23. package/src/App.tsx +53 -53
  24. package/src/components/common/AnnouncementBanner/AnnouncementBanner.scss +193 -0
  25. package/src/components/common/AnnouncementBanner/AnnouncementBanner.tsx +75 -0
  26. package/src/components/common/Button/ButtonComponent.scss +3 -3
  27. package/src/components/common/Button/ButtonComponent.tsx +33 -33
  28. package/src/components/common/Footer/Footer.scss +86 -86
  29. package/src/components/common/Footer/Footer.tsx +53 -53
  30. package/src/components/common/Header/MainHeader.scss +920 -920
  31. package/src/components/common/Header/MainHeader.tsx +708 -708
  32. package/src/components/common/Header/SimpleSearchContext.tsx +194 -194
  33. package/src/components/common/NavDropdownMenu/NavDropdownMenu.tsx +57 -57
  34. package/src/components/common/SearchHighlight.tsx +64 -64
  35. package/src/components/common/SearchResultItem.tsx +162 -162
  36. package/src/components/common/Sidebar/Sidebar.scss +176 -176
  37. package/src/components/common/Sidebar/Sidebar.tsx +137 -137
  38. package/src/components/common/UserMenu/UserMenu.tsx +73 -73
  39. package/src/components/common/dynamicTheme/dynamicTheme.ts +46 -46
  40. package/src/components/common/menu/MenuComponent.module.css +11 -11
  41. package/src/components/common/menu/MenuComponent.tsx +37 -37
  42. package/src/contexts/SidebarContext.tsx +8 -8
  43. package/src/declarations.d.ts +9 -9
  44. package/src/examples/MeiliSearchUsageExample.tsx +101 -101
  45. package/src/hooks/useIsMobileSize.ts +19 -19
  46. package/src/hooks/useSidebar.ts +9 -9
  47. package/src/index.css +68 -68
  48. package/src/index.ts +22 -22
  49. package/src/interfaces/components.ts +188 -183
  50. package/src/main.tsx +11 -11
  51. package/src/providers/SidebarProvider.tsx +19 -19
  52. package/src/services/meiliSearchService.ts +233 -233
  53. package/src/styles/global-overrides.scss +1164 -1164
  54. package/src/utils/searchNavigation.ts +140 -140
  55. package/src/vite-env.d.ts +1 -1
  56. package/tsconfig.app.json +26 -26
  57. package/tsconfig.json +17 -17
  58. package/tsconfig.node.json +24 -24
  59. package/vite.config.ts +34 -34
package/CHANGELOG.md CHANGED
@@ -1,43 +1,43 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [Unreleased]
9
-
10
- ### Added
11
- - Initial release of TitanEd Library
12
- - MainHeader component with search functionality
13
- - Sidebar component with responsive design
14
- - Footer component
15
- - SidebarProvider and useSidebar hook
16
- - SimpleSearchProvider and useSimpleSearch hook
17
- - MeiliSearch integration
18
- - TypeScript support with full type definitions
19
- - SCSS styling support
20
- - Global style overrides
21
-
22
- ### Changed
23
- - Nothing yet
24
-
25
- ### Deprecated
26
- - Nothing yet
27
-
28
- ### Removed
29
- - Nothing yet
30
-
31
- ### Fixed
32
- - Nothing yet
33
-
34
- ### Security
35
- - Nothing yet
36
-
37
- ## [0.0.134] - 2024-01-XX
38
-
39
- ### Added
40
- - Initial version with core components
41
- - Basic TypeScript setup
42
- - Vite build configuration
43
- - SCSS support with static copying
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+ - Initial release of TitanEd Library
12
+ - MainHeader component with search functionality
13
+ - Sidebar component with responsive design
14
+ - Footer component
15
+ - SidebarProvider and useSidebar hook
16
+ - SimpleSearchProvider and useSimpleSearch hook
17
+ - MeiliSearch integration
18
+ - TypeScript support with full type definitions
19
+ - SCSS styling support
20
+ - Global style overrides
21
+
22
+ ### Changed
23
+ - Nothing yet
24
+
25
+ ### Deprecated
26
+ - Nothing yet
27
+
28
+ ### Removed
29
+ - Nothing yet
30
+
31
+ ### Fixed
32
+ - Nothing yet
33
+
34
+ ### Security
35
+ - Nothing yet
36
+
37
+ ## [0.0.134] - 2024-01-XX
38
+
39
+ ### Added
40
+ - Initial version with core components
41
+ - Basic TypeScript setup
42
+ - Vite build configuration
43
+ - SCSS support with static copying
@@ -1,261 +1,261 @@
1
- # MeiliSearch Integration for TitanEd Library
2
-
3
- This document explains how to use the MeiliSearch integration in the TitanEd library's MainHeader component.
4
-
5
- ## Overview
6
-
7
- The MainHeader component now supports MeiliSearch integration for content searching. It uses the exact API payload structure from your Open edX authoring console logs, making it compatible with your existing MeiliSearch setup.
8
-
9
- ## Features
10
-
11
- - **Real-time Search**: Search as you type with MeiliSearch API
12
- - **Search Results Display**: Shows search results in a dropdown with highlighting
13
- - **Mobile Support**: Full mobile search modal with results
14
- - **Error Handling**: Proper error states and loading indicators
15
- - **Faceted Search**: Supports MeiliSearch facets for advanced filtering
16
- - **Highlighting**: Search term highlighting in results
17
-
18
- ## Configuration
19
-
20
- ### Required Props
21
-
22
- The MainHeader component now requires a `meiliSearchConfig` prop:
23
-
24
- ```typescript
25
- interface MeiliSearchConfig {
26
- host: string; // MeiliSearch server URL
27
- apiKey: string; // MeiliSearch API key
28
- indexName: string; // Index name (e.g., 'tutor_studio_content')
29
- }
30
- ```
31
-
32
- ### Example Usage
33
-
34
- ```tsx
35
- import MainHeader from 'titaned-lib';
36
- import { MeiliSearchConfig } from 'titaned-lib';
37
-
38
- const meiliSearchConfig: MeiliSearchConfig = {
39
- host: 'http://meilisearch.local.openedx.io:7700',
40
- apiKey: 'your-api-key-here',
41
- indexName: 'tutor_studio_content'
42
- };
43
-
44
- <MainHeader
45
- logoUrl="/path/to/logo.png"
46
- menuAlignment="left"
47
- menuList={menuList}
48
- loginSignupButtons={false}
49
- authenticatedUser={user}
50
- userMenuItems={userMenuItems}
51
- onLanguageChange={handleLanguageChange}
52
- getBaseUrl={() => '/'}
53
- onSearchResults={handleSearchResults}
54
- meiliSearchConfig={meiliSearchConfig}
55
- headerButtons={headerButtons}
56
- />
57
- ```
58
-
59
- ## API Integration
60
-
61
- The integration uses the exact payload structure from your console logs:
62
-
63
- ### Search Payload
64
- ```json
65
- {
66
- "queries": [
67
- {
68
- "indexUid": "tutor_studio_content",
69
- "q": "search query",
70
- "filter": [[], "type = \"course_block\""],
71
- "attributesToHighlight": ["display_name", "description", "published"],
72
- "highlightPreTag": "__meili-highlight__",
73
- "highlightPostTag": "__/meili-highlight__",
74
- "attributesToCrop": ["description", "published"],
75
- "sort": [],
76
- "offset": 0,
77
- "limit": 20
78
- },
79
- {
80
- "indexUid": "tutor_studio_content",
81
- "facets": ["block_type", "content.problem_types"],
82
- "filter": ["type = \"course_block\""],
83
- "limit": 0
84
- }
85
- ]
86
- }
87
- ```
88
-
89
- ### Headers and Authentication
90
-
91
- The service automatically includes all necessary headers for MeiliSearch API calls:
92
-
93
- ```typescript
94
- {
95
- 'Content-Type': 'application/json',
96
- 'Authorization': 'Bearer your-api-key-here',
97
- 'X-Meilisearch-Client': 'Meilisearch JavaScript (v0.41.0)'
98
- }
99
- ```
100
-
101
- **Important**: When you pass the complete MeiliSearch client object (recommended), the service will automatically extract and use the exact headers from your client, ensuring compatibility with your existing setup.
102
-
103
- ### Response Handling
104
-
105
- The component handles MeiliSearch responses and converts them to a consistent format:
106
-
107
- ```typescript
108
- interface MeiliSearchResult {
109
- id: string;
110
- display_name: string;
111
- type: string;
112
- description?: string;
113
- published?: string;
114
- url?: string;
115
- block_type?: string;
116
- content?: {
117
- problem_types?: string[];
118
- };
119
- _formatted?: {
120
- display_name?: string;
121
- description?: string;
122
- published?: string;
123
- };
124
- }
125
- ```
126
-
127
- ## Search Results Display
128
-
129
- ### Desktop
130
- - Results appear in a dropdown below the search field
131
- - Shows up to 5 results with "show more" indicator
132
- - Includes highlighting for search terms
133
- - Displays result type and metadata
134
-
135
- ### Mobile
136
- - Full-screen search modal
137
- - Scrollable results list
138
- - Same highlighting and metadata as desktop
139
-
140
- ## Styling
141
-
142
- The component includes comprehensive CSS for:
143
- - Search result dropdowns
144
- - Loading states
145
- - Error messages
146
- - Mobile search modal
147
- - Result highlighting
148
-
149
- All styles are included in `MainHeader.scss` and follow the existing design system.
150
-
151
- ## Error Handling
152
-
153
- The component handles various error states:
154
- - Network errors
155
- - API errors
156
- - Empty results
157
- - Loading states
158
-
159
- Error messages are displayed to users with appropriate styling.
160
-
161
- ## Integration with Open edX Authoring
162
-
163
- To use this in your Open edX authoring repository:
164
-
165
- 1. **Install the library**:
166
- ```bash
167
- npm install titaned-lib
168
- ```
169
-
170
- 2. **Import and configure** (Recommended approach - pass the complete client):
171
- ```tsx
172
- import { MainHeader } from 'titaned-lib';
173
- import { useContentSearchConnection } from './your-search-hook';
174
-
175
- const MyComponent = () => {
176
- const { client, indexName, hasConnectionError } = useContentSearchConnection();
177
-
178
- const meiliSearchConfig = {
179
- host: client.config.host,
180
- apiKey: client.config.apiKey,
181
- indexName: indexName,
182
- client: client // Pass the complete client for automatic header extraction
183
- };
184
-
185
- return (
186
- <MainHeader
187
- // ... other props
188
- meiliSearchConfig={meiliSearchConfig}
189
- onSearchResults={(results, totalHits, facets) => {
190
- // Handle search results
191
- console.log('Search results:', results);
192
- }}
193
- />
194
- );
195
- };
196
- ```
197
-
198
- 3. **Alternative approach - Manual header configuration**:
199
- ```tsx
200
- const meiliSearchConfig = {
201
- host: 'http://meilisearch.local.openedx.io:7700',
202
- apiKey: 'your-api-key-here',
203
- indexName: 'tutor_studio_content'
204
- // Headers will be automatically set based on the API key
205
- };
206
- ```
207
-
208
- ## Advanced Features
209
-
210
- ### Faceted Search
211
- The component supports MeiliSearch facets for advanced filtering. Facets are available in the `onSearchResults` callback:
212
-
213
- ```tsx
214
- onSearchResults={(results, totalHits, facets) => {
215
- console.log('Facets:', facets);
216
- // facets.block_type: { "chapter": 4, "problem": 6, ... }
217
- // facets['content.problem_types']: { "multiplechoiceresponse": 1, ... }
218
- }}
219
- ```
220
-
221
- ### Custom Search Options
222
- You can customize search behavior by modifying the `MeiliSearchService`:
223
-
224
- ```typescript
225
- // In meiliSearchService.ts
226
- const result = await searchService.search(query, {
227
- limit: 20,
228
- offset: 0,
229
- filter: ['type = "course_block"', 'published = true'],
230
- attributesToHighlight: ['display_name', 'description'],
231
- sort: ['published:desc']
232
- });
233
- ```
234
-
235
- ## Troubleshooting
236
-
237
- ### Common Issues
238
-
239
- 1. **CORS Errors**: Ensure your MeiliSearch server allows CORS from your domain
240
- 2. **API Key Issues**: Verify the API key has proper permissions
241
- 3. **Index Not Found**: Check that the index name matches your MeiliSearch setup
242
- 4. **Network Errors**: Verify the host URL is accessible
243
-
244
- ### Debug Mode
245
-
246
- Enable debug logging by checking the browser console. The component logs:
247
- - Search queries
248
- - API responses
249
- - Error messages
250
- - Performance metrics
251
-
252
- ## Migration from Simple Search
253
-
254
- If you're migrating from the simple search implementation:
255
-
256
- 1. Update your MainHeader props to include `meiliSearchConfig`
257
- 2. Remove any custom search logic
258
- 3. Update your `onSearchResults` callback to handle the new result format
259
- 4. Test with your MeiliSearch setup
260
-
261
- The component maintains backward compatibility for other props and functionality.
1
+ # MeiliSearch Integration for TitanEd Library
2
+
3
+ This document explains how to use the MeiliSearch integration in the TitanEd library's MainHeader component.
4
+
5
+ ## Overview
6
+
7
+ The MainHeader component now supports MeiliSearch integration for content searching. It uses the exact API payload structure from your Open edX authoring console logs, making it compatible with your existing MeiliSearch setup.
8
+
9
+ ## Features
10
+
11
+ - **Real-time Search**: Search as you type with MeiliSearch API
12
+ - **Search Results Display**: Shows search results in a dropdown with highlighting
13
+ - **Mobile Support**: Full mobile search modal with results
14
+ - **Error Handling**: Proper error states and loading indicators
15
+ - **Faceted Search**: Supports MeiliSearch facets for advanced filtering
16
+ - **Highlighting**: Search term highlighting in results
17
+
18
+ ## Configuration
19
+
20
+ ### Required Props
21
+
22
+ The MainHeader component now requires a `meiliSearchConfig` prop:
23
+
24
+ ```typescript
25
+ interface MeiliSearchConfig {
26
+ host: string; // MeiliSearch server URL
27
+ apiKey: string; // MeiliSearch API key
28
+ indexName: string; // Index name (e.g., 'tutor_studio_content')
29
+ }
30
+ ```
31
+
32
+ ### Example Usage
33
+
34
+ ```tsx
35
+ import MainHeader from 'titaned-lib';
36
+ import { MeiliSearchConfig } from 'titaned-lib';
37
+
38
+ const meiliSearchConfig: MeiliSearchConfig = {
39
+ host: 'http://meilisearch.local.openedx.io:7700',
40
+ apiKey: 'your-api-key-here',
41
+ indexName: 'tutor_studio_content'
42
+ };
43
+
44
+ <MainHeader
45
+ logoUrl="/path/to/logo.png"
46
+ menuAlignment="left"
47
+ menuList={menuList}
48
+ loginSignupButtons={false}
49
+ authenticatedUser={user}
50
+ userMenuItems={userMenuItems}
51
+ onLanguageChange={handleLanguageChange}
52
+ getBaseUrl={() => '/'}
53
+ onSearchResults={handleSearchResults}
54
+ meiliSearchConfig={meiliSearchConfig}
55
+ headerButtons={headerButtons}
56
+ />
57
+ ```
58
+
59
+ ## API Integration
60
+
61
+ The integration uses the exact payload structure from your console logs:
62
+
63
+ ### Search Payload
64
+ ```json
65
+ {
66
+ "queries": [
67
+ {
68
+ "indexUid": "tutor_studio_content",
69
+ "q": "search query",
70
+ "filter": [[], "type = \"course_block\""],
71
+ "attributesToHighlight": ["display_name", "description", "published"],
72
+ "highlightPreTag": "__meili-highlight__",
73
+ "highlightPostTag": "__/meili-highlight__",
74
+ "attributesToCrop": ["description", "published"],
75
+ "sort": [],
76
+ "offset": 0,
77
+ "limit": 20
78
+ },
79
+ {
80
+ "indexUid": "tutor_studio_content",
81
+ "facets": ["block_type", "content.problem_types"],
82
+ "filter": ["type = \"course_block\""],
83
+ "limit": 0
84
+ }
85
+ ]
86
+ }
87
+ ```
88
+
89
+ ### Headers and Authentication
90
+
91
+ The service automatically includes all necessary headers for MeiliSearch API calls:
92
+
93
+ ```typescript
94
+ {
95
+ 'Content-Type': 'application/json',
96
+ 'Authorization': 'Bearer your-api-key-here',
97
+ 'X-Meilisearch-Client': 'Meilisearch JavaScript (v0.41.0)'
98
+ }
99
+ ```
100
+
101
+ **Important**: When you pass the complete MeiliSearch client object (recommended), the service will automatically extract and use the exact headers from your client, ensuring compatibility with your existing setup.
102
+
103
+ ### Response Handling
104
+
105
+ The component handles MeiliSearch responses and converts them to a consistent format:
106
+
107
+ ```typescript
108
+ interface MeiliSearchResult {
109
+ id: string;
110
+ display_name: string;
111
+ type: string;
112
+ description?: string;
113
+ published?: string;
114
+ url?: string;
115
+ block_type?: string;
116
+ content?: {
117
+ problem_types?: string[];
118
+ };
119
+ _formatted?: {
120
+ display_name?: string;
121
+ description?: string;
122
+ published?: string;
123
+ };
124
+ }
125
+ ```
126
+
127
+ ## Search Results Display
128
+
129
+ ### Desktop
130
+ - Results appear in a dropdown below the search field
131
+ - Shows up to 5 results with "show more" indicator
132
+ - Includes highlighting for search terms
133
+ - Displays result type and metadata
134
+
135
+ ### Mobile
136
+ - Full-screen search modal
137
+ - Scrollable results list
138
+ - Same highlighting and metadata as desktop
139
+
140
+ ## Styling
141
+
142
+ The component includes comprehensive CSS for:
143
+ - Search result dropdowns
144
+ - Loading states
145
+ - Error messages
146
+ - Mobile search modal
147
+ - Result highlighting
148
+
149
+ All styles are included in `MainHeader.scss` and follow the existing design system.
150
+
151
+ ## Error Handling
152
+
153
+ The component handles various error states:
154
+ - Network errors
155
+ - API errors
156
+ - Empty results
157
+ - Loading states
158
+
159
+ Error messages are displayed to users with appropriate styling.
160
+
161
+ ## Integration with Open edX Authoring
162
+
163
+ To use this in your Open edX authoring repository:
164
+
165
+ 1. **Install the library**:
166
+ ```bash
167
+ npm install titaned-lib
168
+ ```
169
+
170
+ 2. **Import and configure** (Recommended approach - pass the complete client):
171
+ ```tsx
172
+ import { MainHeader } from 'titaned-lib';
173
+ import { useContentSearchConnection } from './your-search-hook';
174
+
175
+ const MyComponent = () => {
176
+ const { client, indexName, hasConnectionError } = useContentSearchConnection();
177
+
178
+ const meiliSearchConfig = {
179
+ host: client.config.host,
180
+ apiKey: client.config.apiKey,
181
+ indexName: indexName,
182
+ client: client // Pass the complete client for automatic header extraction
183
+ };
184
+
185
+ return (
186
+ <MainHeader
187
+ // ... other props
188
+ meiliSearchConfig={meiliSearchConfig}
189
+ onSearchResults={(results, totalHits, facets) => {
190
+ // Handle search results
191
+ console.log('Search results:', results);
192
+ }}
193
+ />
194
+ );
195
+ };
196
+ ```
197
+
198
+ 3. **Alternative approach - Manual header configuration**:
199
+ ```tsx
200
+ const meiliSearchConfig = {
201
+ host: 'http://meilisearch.local.openedx.io:7700',
202
+ apiKey: 'your-api-key-here',
203
+ indexName: 'tutor_studio_content'
204
+ // Headers will be automatically set based on the API key
205
+ };
206
+ ```
207
+
208
+ ## Advanced Features
209
+
210
+ ### Faceted Search
211
+ The component supports MeiliSearch facets for advanced filtering. Facets are available in the `onSearchResults` callback:
212
+
213
+ ```tsx
214
+ onSearchResults={(results, totalHits, facets) => {
215
+ console.log('Facets:', facets);
216
+ // facets.block_type: { "chapter": 4, "problem": 6, ... }
217
+ // facets['content.problem_types']: { "multiplechoiceresponse": 1, ... }
218
+ }}
219
+ ```
220
+
221
+ ### Custom Search Options
222
+ You can customize search behavior by modifying the `MeiliSearchService`:
223
+
224
+ ```typescript
225
+ // In meiliSearchService.ts
226
+ const result = await searchService.search(query, {
227
+ limit: 20,
228
+ offset: 0,
229
+ filter: ['type = "course_block"', 'published = true'],
230
+ attributesToHighlight: ['display_name', 'description'],
231
+ sort: ['published:desc']
232
+ });
233
+ ```
234
+
235
+ ## Troubleshooting
236
+
237
+ ### Common Issues
238
+
239
+ 1. **CORS Errors**: Ensure your MeiliSearch server allows CORS from your domain
240
+ 2. **API Key Issues**: Verify the API key has proper permissions
241
+ 3. **Index Not Found**: Check that the index name matches your MeiliSearch setup
242
+ 4. **Network Errors**: Verify the host URL is accessible
243
+
244
+ ### Debug Mode
245
+
246
+ Enable debug logging by checking the browser console. The component logs:
247
+ - Search queries
248
+ - API responses
249
+ - Error messages
250
+ - Performance metrics
251
+
252
+ ## Migration from Simple Search
253
+
254
+ If you're migrating from the simple search implementation:
255
+
256
+ 1. Update your MainHeader props to include `meiliSearchConfig`
257
+ 2. Remove any custom search logic
258
+ 3. Update your `onSearchResults` callback to handle the new result format
259
+ 4. Test with your MeiliSearch setup
260
+
261
+ The component maintains backward compatibility for other props and functionality.