advanced-filter-system 1.3.3 → 1.3.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 +81 -117
- package/dist/afs.legacy.js +1 -1
- package/dist/afs.legacy.js.map +1 -1
- package/dist/afs.modern.js +1 -1
- package/dist/afs.modern.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,6 +47,7 @@ A powerful and flexible vanilla JavaScript filtering system that provides advanc
|
|
|
47
47
|
- AND/OR logic
|
|
48
48
|
- Filter groups
|
|
49
49
|
- Dynamic filters
|
|
50
|
+
- Multiple categories per item
|
|
50
51
|
- 🔎 **Smart Search**
|
|
51
52
|
- Real-time search
|
|
52
53
|
- Multiple fields
|
|
@@ -69,8 +70,8 @@ A powerful and flexible vanilla JavaScript filtering system that provides advanc
|
|
|
69
70
|
- Efficient DOM manipulation
|
|
70
71
|
- Minimal reflows
|
|
71
72
|
- 🎨 **Rich Animation**
|
|
72
|
-
-
|
|
73
|
-
- Custom
|
|
73
|
+
- Smooth transitions
|
|
74
|
+
- Custom animations
|
|
74
75
|
- Hardware acceleration
|
|
75
76
|
- 💾 **State Management**
|
|
76
77
|
- Centralized state
|
|
@@ -97,7 +98,7 @@ pnpm add advanced-filter-system
|
|
|
97
98
|
Or include via CDN:
|
|
98
99
|
|
|
99
100
|
```html
|
|
100
|
-
<script src="https://unpkg.com/advanced-filter-system@
|
|
101
|
+
<script src="https://unpkg.com/advanced-filter-system@latest/dist/afs.modern.js"></script>
|
|
101
102
|
```
|
|
102
103
|
|
|
103
104
|
## Quick Start
|
|
@@ -143,7 +144,7 @@ Or include via CDN:
|
|
|
143
144
|
<!-- Items Container -->
|
|
144
145
|
<div id="items-container">
|
|
145
146
|
<div class="afs-filter-item"
|
|
146
|
-
data-categories="category:category1"
|
|
147
|
+
data-categories="category:category1 category:category2"
|
|
147
148
|
data-price="99.99"
|
|
148
149
|
data-date="2024-03-15"
|
|
149
150
|
data-title="Item 1"
|
|
@@ -159,7 +160,7 @@ Or include via CDN:
|
|
|
159
160
|
<div class="pagination-container"></div>
|
|
160
161
|
|
|
161
162
|
<!-- Scripts -->
|
|
162
|
-
<script src="https://unpkg.com/advanced-filter-system@
|
|
163
|
+
<script src="https://unpkg.com/advanced-filter-system@latest/dist/afs.modern.js"></script>
|
|
163
164
|
<script>
|
|
164
165
|
const afs = AFS.createAFS({
|
|
165
166
|
containerSelector: '#items-container',
|
|
@@ -178,6 +179,30 @@ Or include via CDN:
|
|
|
178
179
|
pagination: {
|
|
179
180
|
enabled: true,
|
|
180
181
|
itemsPerPage: 10
|
|
182
|
+
},
|
|
183
|
+
styles: {
|
|
184
|
+
button: {
|
|
185
|
+
padding: "12px 24px",
|
|
186
|
+
border: "2px solid #ccc",
|
|
187
|
+
borderRadius: "8px",
|
|
188
|
+
fontSize: "16px",
|
|
189
|
+
fontFamily: "Arial, sans-serif",
|
|
190
|
+
fontWeight: "bold",
|
|
191
|
+
letterSpacing: "0.5px",
|
|
192
|
+
textTransform: "uppercase",
|
|
193
|
+
minHeight: "48px",
|
|
194
|
+
lineHeight: "1.8",
|
|
195
|
+
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
196
|
+
hover: {
|
|
197
|
+
boxShadow: "0 4px 8px rgba(0,0,0,0.2)"
|
|
198
|
+
},
|
|
199
|
+
active: {
|
|
200
|
+
boxShadow: "0 1px 2px rgba(0,0,0,0.1)"
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
dropdown: {
|
|
204
|
+
// Same properties as button
|
|
205
|
+
}
|
|
181
206
|
}
|
|
182
207
|
});
|
|
183
208
|
|
|
@@ -222,16 +247,28 @@ const afs = createAFS({
|
|
|
222
247
|
|
|
223
248
|
### Filtering
|
|
224
249
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
250
|
+
Multiple categories can be specified using space-separated values in the `data-categories` attribute:
|
|
251
|
+
|
|
252
|
+
```html
|
|
253
|
+
<!-- Single category -->
|
|
254
|
+
<div class="afs-filter-item" data-categories="category:category1">
|
|
255
|
+
Item content
|
|
256
|
+
</div>
|
|
229
257
|
|
|
230
|
-
|
|
258
|
+
<!-- Multiple categories -->
|
|
259
|
+
<div class="afs-filter-item" data-categories="category:category1 category:category2 category:category3">
|
|
231
260
|
Item content
|
|
232
261
|
</div>
|
|
233
262
|
|
|
234
|
-
|
|
263
|
+
<!-- Multiple filter types -->
|
|
264
|
+
<div class="afs-filter-item" data-categories="category:category1 month:january season:2024">
|
|
265
|
+
Item content
|
|
266
|
+
</div>
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
JavaScript API:
|
|
270
|
+
|
|
271
|
+
```javascript
|
|
235
272
|
// Set filter mode
|
|
236
273
|
afs.filter.setFilterMode('AND'); // or 'OR'
|
|
237
274
|
|
|
@@ -248,81 +285,48 @@ afs.filter.clearAllFilters();
|
|
|
248
285
|
### Searching
|
|
249
286
|
|
|
250
287
|
```javascript
|
|
251
|
-
// HTML
|
|
252
|
-
<input type="text" class="filter-search">
|
|
253
|
-
<div class="afs-filter-item"
|
|
254
|
-
data-title="Product Name"
|
|
255
|
-
data-description="Product description">
|
|
256
|
-
Item content
|
|
257
|
-
</div>
|
|
258
|
-
|
|
259
|
-
// JavaScript
|
|
260
288
|
// Configure search
|
|
261
|
-
afs.search.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
debounceTime: 300
|
|
289
|
+
afs.search.configure({
|
|
290
|
+
keys: ['title', 'description'],
|
|
291
|
+
minLength: 2,
|
|
292
|
+
debounce: 300
|
|
266
293
|
});
|
|
267
294
|
|
|
268
|
-
//
|
|
295
|
+
// Search programmatically
|
|
269
296
|
afs.search.search('query');
|
|
270
|
-
|
|
271
|
-
// Clear search
|
|
272
|
-
afs.search.clearSearch();
|
|
273
297
|
```
|
|
274
298
|
|
|
275
299
|
### Sorting
|
|
276
300
|
|
|
277
301
|
```javascript
|
|
278
|
-
//
|
|
279
|
-
<button class="afs-btn-sort" data-filter="price">Sort by Price</button>
|
|
280
|
-
<button class="afs-btn-sort" data-filter="date">Sort by Date</button>
|
|
281
|
-
|
|
282
|
-
<div class="afs-filter-item" data-price="99.99" data-date="2024-03-15">
|
|
283
|
-
Item content
|
|
284
|
-
</div>
|
|
285
|
-
|
|
286
|
-
// JavaScript
|
|
287
|
-
// Basic sort
|
|
302
|
+
// Single column sort
|
|
288
303
|
afs.sort.sort('price', 'asc');
|
|
289
304
|
|
|
290
|
-
// Multiple
|
|
305
|
+
// Multiple column sort
|
|
291
306
|
afs.sort.sortMultiple([
|
|
292
307
|
{ key: 'category', direction: 'asc' },
|
|
293
308
|
{ key: 'price', direction: 'desc' }
|
|
294
309
|
]);
|
|
295
310
|
|
|
296
|
-
//
|
|
297
|
-
afs.sort.
|
|
311
|
+
// Custom sort
|
|
312
|
+
afs.sort.sortWithComparator('title', (a, b) => {
|
|
313
|
+
return a.localeCompare(b);
|
|
314
|
+
});
|
|
298
315
|
```
|
|
299
316
|
|
|
300
317
|
### Pagination
|
|
301
318
|
|
|
302
319
|
```javascript
|
|
303
|
-
// HTML
|
|
304
|
-
<div class="afs-pagination-container"></div>
|
|
305
|
-
|
|
306
|
-
// JavaScript
|
|
307
320
|
// Configure pagination
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
itemsPerPage: 10,
|
|
312
|
-
maxButtons: 7,
|
|
313
|
-
showPrevNext: true,
|
|
314
|
-
scrollToTop: true
|
|
315
|
-
}
|
|
321
|
+
afs.pagination.configure({
|
|
322
|
+
itemsPerPage: 10,
|
|
323
|
+
showControls: true
|
|
316
324
|
});
|
|
317
325
|
|
|
318
326
|
// Navigate pages
|
|
319
327
|
afs.pagination.goToPage(2);
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
afs.pagination.setItemsPerPage(20);
|
|
323
|
-
|
|
324
|
-
// Get pagination info
|
|
325
|
-
const info = afs.pagination.getPageInfo();
|
|
328
|
+
afs.pagination.nextPage();
|
|
329
|
+
afs.pagination.previousPage();
|
|
326
330
|
```
|
|
327
331
|
|
|
328
332
|
## Advanced Usage
|
|
@@ -330,42 +334,22 @@ const info = afs.pagination.getPageInfo();
|
|
|
330
334
|
### Filter Groups
|
|
331
335
|
|
|
332
336
|
```javascript
|
|
333
|
-
// Create filter
|
|
334
|
-
afs.filter.
|
|
335
|
-
|
|
337
|
+
// Create filter group
|
|
338
|
+
afs.filter.createGroup('group1', {
|
|
339
|
+
filters: ['category:category1', 'category:category2'],
|
|
336
340
|
operator: 'OR'
|
|
337
341
|
});
|
|
338
342
|
|
|
339
|
-
afs.filter.addFilterGroup('categories', {
|
|
340
|
-
filters: ['electronics', 'books'],
|
|
341
|
-
operator: 'AND'
|
|
342
|
-
});
|
|
343
|
-
|
|
344
343
|
// Set group mode
|
|
345
|
-
afs.filter.setGroupMode('AND');
|
|
346
|
-
|
|
347
|
-
// Remove group
|
|
348
|
-
afs.filter.removeFilterGroup('price');
|
|
344
|
+
afs.filter.setGroupMode('AND'); // or 'OR'
|
|
349
345
|
```
|
|
350
346
|
|
|
351
347
|
### Custom Sorting
|
|
352
348
|
|
|
353
349
|
```javascript
|
|
354
|
-
// Custom
|
|
355
|
-
afs.sort.sortWithComparator('
|
|
356
|
-
|
|
357
|
-
const getLastWord = str => str.split(' ').pop();
|
|
358
|
-
const lastA = getLastWord(a);
|
|
359
|
-
const lastB = getLastWord(b);
|
|
360
|
-
return lastA.localeCompare(lastB);
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
// Sort with multiple languages
|
|
364
|
-
afs.sort.sortWithComparator('title', (a, b) => {
|
|
365
|
-
return a.localeCompare(b, 'es', {
|
|
366
|
-
sensitivity: 'base',
|
|
367
|
-
numeric: true
|
|
368
|
-
});
|
|
350
|
+
// Custom sort function
|
|
351
|
+
afs.sort.sortWithComparator('price', (a, b) => {
|
|
352
|
+
return parseFloat(a) - parseFloat(b);
|
|
369
353
|
});
|
|
370
354
|
```
|
|
371
355
|
|
|
@@ -373,23 +357,13 @@ afs.sort.sortWithComparator('title', (a, b) => {
|
|
|
373
357
|
|
|
374
358
|
```javascript
|
|
375
359
|
// Enable URL state
|
|
376
|
-
|
|
377
|
-
urlStateEnabled: true,
|
|
378
|
-
urlStateKey: 'filter'
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
// Handle state changes
|
|
382
|
-
afs.on('urlStateLoaded', (state) => {
|
|
383
|
-
console.log('State loaded:', state);
|
|
384
|
-
});
|
|
360
|
+
afs.urlManager.enable();
|
|
385
361
|
|
|
386
|
-
//
|
|
387
|
-
afs.urlManager.
|
|
388
|
-
afs.urlManager.loadFromURL();
|
|
389
|
-
afs.urlManager.clearURL();
|
|
362
|
+
// Get current state
|
|
363
|
+
const state = afs.urlManager.getState();
|
|
390
364
|
|
|
391
|
-
//
|
|
392
|
-
|
|
365
|
+
// Set state
|
|
366
|
+
afs.urlManager.setState(state);
|
|
393
367
|
```
|
|
394
368
|
|
|
395
369
|
## Components
|
|
@@ -472,21 +446,11 @@ const afs = createAFS({
|
|
|
472
446
|
|
|
473
447
|
## Browser Support
|
|
474
448
|
|
|
475
|
-
- Chrome (
|
|
476
|
-
- Firefox (
|
|
477
|
-
- Safari (
|
|
478
|
-
- Edge (
|
|
479
|
-
-
|
|
480
|
-
- Android Chrome (last 2 versions)
|
|
481
|
-
|
|
482
|
-
Required browser features:
|
|
483
|
-
|
|
484
|
-
- CSS Transitions
|
|
485
|
-
- Flexbox
|
|
486
|
-
- CSS Grid (optional)
|
|
487
|
-
- History API
|
|
488
|
-
- localStorage
|
|
489
|
-
- MutationObserver
|
|
449
|
+
- Chrome (latest)
|
|
450
|
+
- Firefox (latest)
|
|
451
|
+
- Safari (latest)
|
|
452
|
+
- Edge (latest)
|
|
453
|
+
- Opera (latest)
|
|
490
454
|
|
|
491
455
|
## TypeScript Support
|
|
492
456
|
|