@visns-studio/visns-components 5.14.0 → 5.14.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,249 @@
1
+ # Enhanced OCR Template Component
2
+
3
+ ## Overview
4
+
5
+ The `OcrTemplateEnhanced` component provides a modern, user-friendly interface for OCR document processing with intelligent data categorization and template building capabilities.
6
+
7
+ ## Key Improvements Over Original OCR Template
8
+
9
+ ### 🎯 **User Experience Enhancements**
10
+
11
+ 1. **Modern Drag-and-Drop Interface**
12
+ - Visual drop zones with hover effects
13
+ - File validation and size limits (10MB)
14
+ - Support for PDF, JPG, PNG formats
15
+ - File preview with metadata display
16
+
17
+ 2. **Real-Time Processing Feedback**
18
+ - Multi-stage progress indicators
19
+ - Visual status updates (Upload → OCR → Analysis)
20
+ - Progress bars for upload stage
21
+ - Loading animations and status icons
22
+
23
+ 3. **Smart Data Categorization**
24
+ - Automatic categorization into 5 groups:
25
+ - 📞 Contact Information (email, phone, names)
26
+ - 💰 Financial Data (amounts, prices, costs)
27
+ - 📅 Dates & Times (dates, timestamps)
28
+ - 🔢 Identifiers (IDs, numbers, references)
29
+ - 📄 Other Data (miscellaneous key-value pairs)
30
+
31
+ 4. **Card-Based Data Organization**
32
+ - Interactive data cards with confidence scoring
33
+ - Color-coded categories with icons
34
+ - Visual selection states with hover effects
35
+ - Confidence badges (High/Medium/Low)
36
+
37
+ ### 🤖 **Intelligent Features**
38
+
39
+ 1. **Template Suggestions**
40
+ - Auto-generated templates based on detected document type
41
+ - Pre-built templates for invoices, contracts, quotes
42
+ - One-click template application
43
+
44
+ 2. **Smart Variable Management**
45
+ - Clickable variable chips for easy insertion
46
+ - Live filename preview
47
+ - Template validation and formatting
48
+
49
+ 3. **Enhanced Document Analysis**
50
+ - Improved text line organization
51
+ - Better title selection interface
52
+ - Grid-based layout for better readability
53
+
54
+ ## Component Usage
55
+
56
+ ### Basic Implementation
57
+
58
+ ```jsx
59
+ import { OcrTemplateEnhanced } from '@visns-studio/visns-components';
60
+
61
+ <OcrTemplateEnhanced
62
+ id="ocr_template_1"
63
+ data={formData}
64
+ setData={setFormData}
65
+ routeParams={routeParams}
66
+ urlParam="id"
67
+ onSave={handleSave}
68
+ />
69
+ ```
70
+
71
+ ### Integration in GenericDetail
72
+
73
+ The component automatically replaces the original OCR template when `type: 'ocrTemplate'` is used in GenericDetail configuration:
74
+
75
+ ```javascript
76
+ {
77
+ id: 'document_processor',
78
+ type: 'ocrTemplate',
79
+ label: 'Document OCR Processing'
80
+ }
81
+ ```
82
+
83
+ ## Props
84
+
85
+ | Prop | Type | Required | Description |
86
+ |------|------|----------|-------------|
87
+ | `id` | string | ✅ | Unique identifier for the OCR template instance |
88
+ | `data` | object | ✅ | Form data object containing OCR results |
89
+ | `setData` | function | ✅ | State setter function for updating form data |
90
+ | `routeParams` | object | ✅ | Route parameters from React Router |
91
+ | `urlParam` | string | ✅ | URL parameter key for template ID |
92
+ | `onSave` | function | ✅ | Callback function for saving template configuration |
93
+
94
+ ## Data Structure
95
+
96
+ ### Expected Data Format
97
+
98
+ ```javascript
99
+ {
100
+ [id]: {
101
+ keyValuePairs: {
102
+ "invoice_number": "INV-001",
103
+ "amount": "1500.00",
104
+ "date": "2025-01-15",
105
+ "client_name": "ACME Corp"
106
+ },
107
+ allText: [
108
+ "INVOICE INV-001",
109
+ "Date: 2025-01-15",
110
+ "Amount: $1,500.00",
111
+ "Client: ACME Corp"
112
+ ],
113
+ selectedKey: ["invoice_number", "amount"],
114
+ selectedTitle: ["INVOICE INV-001"],
115
+ dynamicFilename: "INV_{{invoice_number}}_{{date}}",
116
+ uploadedFile: {
117
+ name: "invoice.pdf",
118
+ size: 524288,
119
+ type: "application/pdf"
120
+ }
121
+ }
122
+ }
123
+ ```
124
+
125
+ ## API Integration
126
+
127
+ ### OCR Processing Endpoint
128
+
129
+ ```
130
+ POST /ajax/ocr/analyzeFile
131
+ ```
132
+
133
+ **Request:**
134
+ - `file`: Document file (PDF/JPG/PNG)
135
+ - `template_id`: Template identifier
136
+
137
+ **Response:**
138
+ ```javascript
139
+ {
140
+ keyValuePairs: { /* extracted key-value pairs */ },
141
+ allText: [ /* array of text lines */ ]
142
+ }
143
+ ```
144
+
145
+ ## Styling & Customization
146
+
147
+ ### CSS Classes
148
+
149
+ The component uses CSS modules with the following key classes:
150
+
151
+ - `.ocrTemplateContainer` - Main container
152
+ - `.dropZone` - File upload area
153
+ - `.dataCard` - Individual data cards
154
+ - `.processingStep` - Progress indicator steps
155
+ - `.templateBuilder` - Template configuration section
156
+
157
+ ### Category Colors
158
+
159
+ - Contact: `#17a2b8` (Info blue)
160
+ - Financial: `#28a745` (Success green)
161
+ - Dates: `#ffc107` (Warning yellow)
162
+ - Identifiers: `#6f42c1` (Purple)
163
+ - Other: `#6c757d` (Gray)
164
+
165
+ ## Advanced Features
166
+
167
+ ### Template Suggestions
168
+
169
+ The component automatically suggests templates based on detected data patterns:
170
+
171
+ ```javascript
172
+ // Auto-detected invoice pattern
173
+ {
174
+ name: "Invoice Template",
175
+ filename: "INV_{{invoice_number}}_{{date}}",
176
+ description: "Standard invoice naming convention"
177
+ }
178
+ ```
179
+
180
+ ### Confidence Scoring
181
+
182
+ Each extracted key-value pair includes a confidence score:
183
+
184
+ - **High (80%+)**: Green badge, reliable data
185
+ - **Medium (60-79%)**: Yellow badge, moderate confidence
186
+ - **Low (<60%)**: Red badge, requires verification
187
+
188
+ ### Responsive Design
189
+
190
+ - Mobile-optimized with single-column layouts
191
+ - Touch-friendly interface elements
192
+ - Adaptive grid systems for different screen sizes
193
+
194
+ ## Migration Guide
195
+
196
+ ### From Original OCR Template
197
+
198
+ The enhanced component is a drop-in replacement. No configuration changes required:
199
+
200
+ **Before:**
201
+ ```javascript
202
+ // Old table-based interface with basic file input
203
+ case 'ocrTemplate':
204
+ return renderOcrTemplate(id);
205
+ ```
206
+
207
+ **After:**
208
+ ```javascript
209
+ // New enhanced component with modern UI
210
+ case 'ocrTemplate':
211
+ return (
212
+ <OcrTemplateEnhanced
213
+ id={id}
214
+ data={data}
215
+ setData={setData}
216
+ routeParams={routeParams}
217
+ urlParam={urlParam}
218
+ onSave={handleOcrTemplateSave}
219
+ />
220
+ );
221
+ ```
222
+
223
+ ### Backward Compatibility
224
+
225
+ - All existing data structures remain compatible
226
+ - Original API endpoints work unchanged
227
+ - Existing templates continue to function
228
+ - State management patterns preserved
229
+
230
+ ## Performance Considerations
231
+
232
+ - File size validation (10MB limit)
233
+ - Optimized re-rendering with React.memo patterns
234
+ - Debounced template preview updates
235
+ - Efficient categorization algorithms
236
+
237
+ ## Accessibility
238
+
239
+ - ARIA labels for all interactive elements
240
+ - Keyboard navigation support
241
+ - Screen reader compatible
242
+ - High contrast mode support
243
+ - Focus management for modal states
244
+
245
+ ---
246
+
247
+ ## Support
248
+
249
+ For technical support or feature requests, please refer to the main component library documentation or contact the development team.