advanced-filter-system 1.0.3 → 1.0.5

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.
package/README.md CHANGED
@@ -1,17 +1,33 @@
1
-
2
1
  # Advanced Filter System
3
2
 
4
- A flexible and powerful JavaScript library for filtering DOM elements with search and sorting capabilities.
3
+ A powerful and flexible JavaScript library for filtering DOM elements with comprehensive search, sorting, and filtering capabilities.
5
4
 
6
5
  ## Features
7
6
 
8
- - 🔍 Multiple typed filters (category, price, etc.)
9
- - 🔎 Text search with debouncing
7
+ ### Core Filtering
8
+
9
+ - 🔍 Multiple filter types (category, price, status, etc.)
10
+ - 🔀 Flexible filter modes (AND/OR logic)
11
+ - 👥 Filter groups with independent logic
10
12
  - 📊 Multi-criteria sorting
11
- - 🔗 URL state management
12
- - Smooth animations
13
+ - 🔎 Text search with debouncing
14
+ - 📱 Responsive design support
15
+ - ✨ Smooth animations and transitions
13
16
  - 🔢 Results counter
14
- - 📱 Responsive
17
+ - 🔗 URL state management
18
+
19
+ ### Advanced Features
20
+
21
+ - 📑 Pagination support
22
+ - 📊 Range-based filtering
23
+ - 💾 Filter presets (save/load)
24
+ - 📈 Analytics integration
25
+ - ⌨️ Keyboard navigation
26
+ - 🔄 Custom sort comparators
27
+ - 🎯 Event system
28
+ - 📱 Responsive breakpoints
29
+ - 🔍 Multiple search keys
30
+ - 🎨 Customizable animations
15
31
 
16
32
  ## Installation
17
33
 
@@ -21,36 +37,39 @@ A flexible and powerful JavaScript library for filtering DOM elements with searc
21
37
  npm install advanced-filter-system
22
38
  ```
23
39
 
40
+ ### Via yarn
41
+
42
+ ```bash
43
+ yarn add advanced-filter-system
44
+ ```
45
+
24
46
  ### Direct Download
25
47
 
26
48
  Download `src/AFS.js` from this repository and include it in your project.
27
49
 
28
- ## Basic Usage
50
+ ## Usage Guide
29
51
 
30
- ### HTML Structure
52
+ ### Basic Setup
31
53
 
32
54
  ```html
33
55
  <div class="filter-container">
34
- <!-- Filter buttons with types -->
56
+ <!-- Filter buttons -->
35
57
  <div class="filters">
36
58
  <button class="btn-filter" data-filter="*">All</button>
37
59
  <button class="btn-filter" data-filter="category:web">Web</button>
38
60
  <button class="btn-filter" data-filter="category:design">Design</button>
39
- <button class="btn-filter" data-filter="price:low">Low Price</button>
40
61
  </div>
41
62
 
42
- <!-- Search (optional) -->
63
+ <!-- Optional components -->
43
64
  <input type="text" class="filter-search" placeholder="Search...">
44
-
45
- <!-- Counter (optional) -->
46
65
  <div class="filter-counter"></div>
47
66
 
48
67
  <!-- Filterable items -->
49
68
  <div class="items">
50
69
  <div class="filter-item"
51
- data-categories="category:web category:low"
70
+ data-categories="category:web"
52
71
  data-title="Project 1"
53
- data-price="low"
72
+ data-price="599"
54
73
  data-year="2023">
55
74
  <!-- Content -->
56
75
  </div>
@@ -58,7 +77,7 @@ Download `src/AFS.js` from this repository and include it in your project.
58
77
  </div>
59
78
  ```
60
79
 
61
- ### JavaScript Initialization
80
+ ### Basic JavaScript Initialization
62
81
 
63
82
  ```javascript
64
83
  import { AFS } from 'advanced-filter-system';
@@ -70,125 +89,216 @@ const filter = new AFS({
70
89
  });
71
90
  ```
72
91
 
73
- ## Advanced Configuration
92
+ ## Feature Documentation
93
+
94
+ ### 1. Filter Modes
95
+
96
+ ```javascript
97
+ // Set filter logic mode
98
+ filter.setFilterMode('AND'); // Items must match all selected filters
99
+ filter.setFilterMode('OR'); // Items must match any selected filter
100
+
101
+ // Alternative method
102
+ filter.setLogic('AND');
103
+ filter.setLogic(true); // true = AND, false = OR
104
+ ```
105
+
106
+ ### 2. Filter Groups
107
+
108
+ Groups allow complex filtering logic with independent AND/OR operations.
109
+
110
+ ```javascript
111
+ // Add filter groups
112
+ filter.addFilterGroup('categories', ['category:tech', 'category:web'], 'OR');
113
+ filter.addFilterGroup('price', ['price:low', 'price:medium'], 'AND');
114
+
115
+ // Set how groups combine
116
+ filter.setGroupMode('AND'); // Items must match all groups
117
+ filter.setGroupMode('OR'); // Items must match any group
118
+
119
+ // Remove groups
120
+ filter.removeFilterGroup('price');
121
+ ```
74
122
 
75
- ### Full Options
123
+ ### 3. Search Functionality
76
124
 
77
125
  ```javascript
126
+ // Configure search
78
127
  const filter = new AFS({
79
- // Required
80
- containerSelector: '.filter-container',
81
- itemSelector: '.filter-item',
82
- filterButtonSelector: '.btn-filter',
83
-
84
- // Optional (default values)
85
128
  searchInputSelector: '.filter-search',
86
- counterSelector: '.filter-counter',
87
- activeClass: 'active',
88
- hiddenClass: 'hidden',
89
- animationDuration: 300,
90
- filterMode: 'OR',
91
- searchKeys: ['title'],
92
- debounceTime: 300
129
+ searchKeys: ['title', 'description'], // Data attributes to search in
130
+ debounceTime: 300 // Milliseconds
93
131
  });
132
+
133
+ // Programmatic search
134
+ filter.search('query');
94
135
  ```
95
136
 
96
- ### Managing Multiple Filters
137
+ ### 4. Sorting
97
138
 
98
139
  ```javascript
99
- // Add filters
100
- filter.addFilter('category', 'web');
101
- filter.addFilter('price', 'low');
140
+ // Multi-criteria sorting
141
+ filter.sortMultiple([
142
+ { key: 'year', direction: 'desc' },
143
+ { key: 'title', direction: 'asc' }
144
+ ]);
145
+
146
+ // Custom comparator
147
+ filter.sortWithComparator('price', (a, b) => parseFloat(a) - parseFloat(b));
148
+ ```
102
149
 
103
- // Remove filters
104
- filter.removeFilter('category', 'web');
150
+ ### 5. Range Filtering
105
151
 
106
- // Get active filters by type
107
- const activeCategories = filter.getActiveFiltersByType('category');
152
+ ```javascript
153
+ // Filter by numeric range
154
+ filter.addRangeFilter('price', 100, 500);
108
155
  ```
109
156
 
110
- ### URL State Management
157
+ ### 6. Pagination
111
158
 
112
- Filters are automatically managed in the URL:
159
+ ```javascript
160
+ // Enable pagination
161
+ filter.setPagination(12); // 12 items per page
162
+ ```
163
+
164
+ ### 7. State Management
113
165
 
114
166
  ```javascript
115
- // URL format:
167
+ // URL State
168
+ // Automatically managed, creates URLs like:
116
169
  // ?category=web,design&price=low,medium&search=project
170
+
171
+ // Export/Import State
172
+ const state = filter.exportState();
173
+ filter.importState(state);
174
+
175
+ // Presets
176
+ filter.savePreset('myFilters');
177
+ filter.loadPreset('myFilters');
117
178
  ```
118
179
 
119
- ## Examples
180
+ ### 8. Analytics
120
181
 
121
- ### Portfolio Filter with Multiple Categories
182
+ ```javascript
183
+ filter.enableAnalytics((data) => {
184
+ console.log('Filter event:', data);
185
+ // { type: 'filter', filters: [...], visibleItems: 10, timestamp: '...' }
186
+ });
187
+ ```
122
188
 
123
- ```html
124
- <div class="portfolio filter-container">
125
- <div class="filters">
126
- <button class="btn-filter" data-filter="*">All</button>
127
- <button class="btn-filter" data-filter="type:web">Web</button>
128
- <button class="btn-filter" data-filter="type:app">Apps</button>
129
- <button class="btn-filter" data-filter="tech:react">React</button>
130
- <button class="btn-filter" data-filter="tech:vue">Vue</button>
131
- </div>
189
+ ### 9. Responsive Design
132
190
 
133
- <div class="portfolio-items">
134
- <div class="filter-item"
135
- data-categories="type:web tech:react"
136
- data-title="React Project">
137
- <h3>React Web Project</h3>
138
- <p>Description...</p>
139
- </div>
140
- </div>
141
- </div>
191
+ ```javascript
192
+ filter.setResponsiveOptions({
193
+ '768': {
194
+ animationDuration: 200,
195
+ itemsPerPage: 8
196
+ },
197
+ '480': {
198
+ animationDuration: 0,
199
+ itemsPerPage: 4
200
+ }
201
+ });
202
+ ```
142
203
 
143
- <script>
144
- const portfolioFilter = new AFS({
145
- containerSelector: '.portfolio',
146
- itemSelector: '.filter-item',
147
- filterButtonSelector: '.btn-filter',
148
- filterMode: 'AND' // Must match all selected filters
204
+ ### 10. Animation Configuration
205
+
206
+ ```javascript
207
+ filter.setAnimationOptions({
208
+ duration: 300,
209
+ type: 'ease-out'
149
210
  });
150
- </script>
151
211
  ```
152
212
 
153
- ### Advanced Product Filter
213
+ ### 11. Event System
154
214
 
155
- ```html
156
- <div class="products filter-container">
157
- <!-- Filters by type -->
158
- <div class="filters">
159
- <button class="btn-filter" data-filter="*">All</button>
160
- <button class="btn-filter" data-filter="category:electronics">Electronics</button>
161
- <button class="btn-filter" data-filter="price:low">Low Price</button>
162
- <button class="btn-filter" data-filter="price:medium">Medium Price</button>
163
- <button class="btn-filter" data-filter="stock:available">In Stock</button>
164
- </div>
215
+ ```javascript
216
+ filter.on('filter', (data) => {
217
+ console.log('Filter changed:', data);
218
+ });
219
+ ```
165
220
 
166
- <input type="text" class="filter-search" placeholder="Search...">
167
- <div class="filter-counter"></div>
221
+ ### 12. Keyboard Navigation
168
222
 
169
- <div class="product-grid">
170
- <div class="filter-item"
171
- data-categories="category:electronics price:low stock:available"
172
- data-title="Smartphone"
173
- data-price="599">
174
- <!-- Product content -->
175
- </div>
176
- </div>
177
- </div>
223
+ ```javascript
224
+ filter.enableKeyboardNavigation();
178
225
  ```
179
226
 
180
227
  ## Browser Compatibility
181
228
 
182
- - Chrome
183
- - Firefox
184
- - Safari
185
- - Edge
186
- - IE11 (with polyfills)
229
+ - Chrome
230
+ - Firefox
231
+ - Safari
232
+ - Edge
233
+ - IE11 (with polyfills)
234
+
235
+ ## Full Configuration Options
236
+
237
+ ```javascript
238
+ const filter = new AFS({
239
+ // Required
240
+ containerSelector: '.filter-container',
241
+ itemSelector: '.filter-item',
242
+ filterButtonSelector: '.btn-filter',
243
+
244
+ // Optional (with defaults)
245
+ searchInputSelector: '.filter-search',
246
+ counterSelector: '.filter-counter',
247
+ activeClass: 'active',
248
+ hiddenClass: 'hidden',
249
+ animationDuration: 300,
250
+ filterMode: 'OR',
251
+ searchKeys: ['title'],
252
+ debounceTime: 300
253
+ });
254
+ ```
255
+
256
+ ## API Methods Reference
257
+
258
+ ### Filter Management
259
+
260
+ - `addFilter(type, value)`
261
+ - `removeFilter(type, value)`
262
+ - `getActiveFiltersByType(type)`
263
+ - `setFilterMode(mode)`
264
+ - `resetFilters()`
265
+
266
+ ### Filter Groups
267
+
268
+ - `addFilterGroup(groupId, filters, operator)`
269
+ - `removeFilterGroup(groupId)`
270
+ - `setGroupMode(mode)`
271
+
272
+ ### Search and Sort
273
+
274
+ - `search(query)`
275
+ - `sortMultiple(criteria)`
276
+ - `sortWithComparator(key, comparator)`
277
+ - `addRangeFilter(key, min, max)`
278
+
279
+ ### State Management
280
+
281
+ - `exportState()`
282
+ - `importState(state)`
283
+ - `savePreset(presetName)`
284
+ - `loadPreset(presetName)`
285
+
286
+ ### UI and Display
287
+
288
+ - `setPagination(itemsPerPage)`
289
+ - `setAnimationOptions(options)`
290
+ - `setResponsiveOptions(breakpoints)`
291
+ - `enableKeyboardNavigation()`
292
+
293
+ ### Events and Analytics
294
+
295
+ - `on(eventName, callback)`
296
+ - `enableAnalytics(callback)`
187
297
 
188
- ## Contribution
298
+ ## Contributing
189
299
 
190
- Contributions are welcome! Feel free to submit a Pull Request.
300
+ Contributions are welcome! Please feel free to submit issues and pull requests.
191
301
 
192
302
  ## License
193
303
 
194
- MIT License
304
+ MIT License - feel free to use this in your projects!