Skip to content

Commit d65619c

Browse files
authored
4.0 (#78)
* playwright tests work! * demo-folder * updated readme * better logging in playwright ci
1 parent 39bba0b commit d65619c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4092
-2990
lines changed

.github/workflows/CI.yml

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
name: CI
2-
32
on:
43
push:
5-
branches:
6-
- main
7-
paths:
8-
- 'src/sortable.ts'
9-
- '.github/workflows/CI.yml'
4+
branches: [main]
5+
paths-ignore:
6+
- '**.md'
7+
- 'docs/**'
108
pull_request:
11-
branches:
12-
- main
13-
paths:
14-
- 'src/sortable.ts'
15-
- '.github/workflows/CI.yml'
9+
branches: [main]
10+
paths-ignore:
11+
- '**.md'
12+
- 'docs/**'
1613

1714
jobs:
18-
run-linters-and-tests:
19-
name: Run linters
15+
test:
16+
name: Playwright Tests
17+
timeout-minutes: 30
2018
runs-on: ubuntu-latest
21-
strategy:
22-
matrix:
23-
node-version: [20]
2419

2520
steps:
26-
- uses: actions/checkout@v3
27-
- uses: pnpm/action-setup@v2
28-
with:
29-
version: latest
30-
- name: Use Node.js ${{ matrix.node-version }}
31-
uses: actions/setup-node@v3
21+
- uses: actions/checkout@v4
22+
23+
- uses: pnpm/action-setup@v4
24+
25+
- uses: actions/setup-node@v4
3226
with:
33-
node-version: ${{ matrix.node-version }}
27+
node-version: 22
3428
cache: 'pnpm'
3529

3630
- name: Install dependencies
3731
run: pnpm install
3832

39-
- name: Run linters
40-
run: npm run lint
33+
- name: Install Playwright Browsers
34+
run: pnpm exec playwright install chromium --with-deps
4135

42-
- name: Run tests
43-
run: npm run test
36+
- name: Run Playwright tests
37+
run: pnpm run test
4438

45-
- name: Run tests with minified code
46-
run: npm run test:min
39+
- uses: actions/upload-artifact@v4
40+
if: always()
41+
with:
42+
name: playwright-report
43+
path: |
44+
playwright-report/
45+
test-results/
46+
retention-days: 30

.gitignore

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
110
node_modules
11+
dist-ssr
12+
*.local
13+
14+
# Editor directories and files
15+
.vscode/*
16+
!.vscode/extensions.json
17+
.idea
218
.DS_Store
3-
._*
19+
*.suo
20+
*.ntvs*
21+
*.njsproj
22+
*.sln
23+
*.sw?
24+
25+
test-results
26+
playwright-report
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
singleQuote: true,
33
semi: false,
4-
trailingComma: 'all',
4+
trailingComma: "all",
55
tabWidth: 2,
66
printWidth: 120,
7-
}
7+
};

CHANGELOG.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ All notable changes to this project will be documented in this file.
77
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
99

10+
## [4.0.0] - 2024-11-15
11+
12+
### Breaking Changes
13+
14+
- Built files are now located in the `/dist` directory
15+
- Update your references from:
16+
- `sortable.min.js` to `dist/sortable.min.js`
17+
- `sortable.a11y.min.js` to `dist/sortable.a11y.min.js`
18+
- etc.
19+
20+
### Added
21+
22+
- `setTimeout` lets double-click "re-sort" the table only once
23+
- `sort-start` and `sort-end` events
24+
- `dist/standalone` folder where all files are inlined, in case you want the functions to be available in the global scope
25+
1026
## [3.2.3] - 2024-05-08
1127

1228
### Changed
@@ -138,10 +154,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
138154

139155
- First release
140156

141-
## Acknowledgments
142-
143-
This CHANGELOG.md was generated with the assistance of [ChatGPT by OpenAI](https://www.openai.com/research/chatgpt).
144-
157+
[4.0.0]: https://github.com/tofsjonas/sortable/releases/tag/4.0.0
145158
[3.2.3]: https://github.com/tofsjonas/sortable/releases/tag/3.2.3
146159
[3.2.2]: https://github.com/tofsjonas/sortable/releases/tag/3.2.2
147160
[3.2.1]: https://github.com/tofsjonas/sortable/releases/tag/3.2.1

CODE_OF_CONDUCT.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
12
# Contributing
23

3-
I am grateful for any and all contributions.
4+
I am grateful for any and all contributions. 😀
45

5-
If it's a minor thing I guess it's easier to open an issue, but if you prefer creating a fork, go ahead! :)

README.md

Lines changed: 68 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<h1>sortable</h1>
33
<h5>- a tiny, vanilla/plain JavaScript table sorter</h5>
44

5-
![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/tofsjonas/sortable) ![NPM Version](https://img.shields.io/npm/v/sortable-tablesort) ![NPM Downloads](https://img.shields.io/npm/dw/sortable-tablesort) ![GitHub Repo stars](https://img.shields.io/github/stars/tofsjonas/sortable) [![jsdelivr](https://data.jsdelivr.com/v1/package/gh/tofsjonas/sortable/badge)](https://www.jsdelivr.com/package/gh/tofsjonas/sortable)
5+
[![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/tofsjonas/sortable)](https://github.com/tofsjonas/sortable) [![NPM Version](https://img.shields.io/npm/v/sortable-tablesort)](https://www.npmjs.com/package/sortable-tablesort) [![NPM Downloads](https://img.shields.io/npm/dw/sortable-tablesort)](https://www.npmjs.com/package/sortable-tablesort) [![GitHub Repo stars](https://img.shields.io/github/stars/tofsjonas/sortable)](https://github.com/tofsjonas/sortable) [![jsdelivr](https://data.jsdelivr.com/v1/package/gh/tofsjonas/sortable/badge)](https://www.jsdelivr.com/package/gh/tofsjonas/sortable)
66

77
Makes any table with **class="sortable"**, er, sortable. The user can click on a table header and change the sorting of the table rows.
88

@@ -27,6 +27,7 @@ You can find a simple demo on <https://tofsjonas.github.io/sortable/>
2727
- [...using `td` instead of `th`](#using-td-instead-of-th)
2828
- [Indicators/arrows on the left side](#indicatorsarrows-on-the-left-side)
2929
- [NOTE ABOUT CSS/SCSS](#note-about-cssscss)
30+
- [Sticky headers](#sticky-headers)
3031
- [Sorting sizes, dates and such](#sorting-sizes-dates-and-such)
3132
- [Alternative sorting](#alternative-sorting)
3233
- [Colspans/Sort on specific column](#colspanssort-on-specific-column)
@@ -35,12 +36,13 @@ You can find a simple demo on <https://tofsjonas.github.io/sortable/>
3536
- [Tiebreaker / secondary sort](#tiebreaker--secondary-sort)
3637
- [Empty/null rows always last](#emptynull-rows-always-last)
3738
- [Accessibility](#accessibility)
39+
- [Sort Events](#sort-events)
3840
- [Sort on load](#sort-on-load)
3941
- [Thank you...](#thank-you)
4042

4143
## Factoids
4244

43-
- **1148 bytes** minified. (619 bytes gzipped)
45+
- **1.52KB** minified. (795 bytes gzipped)
4446

4547
- Works with **JavaScript generated tables**. (since we are using an eventListener)
4648

@@ -60,12 +62,6 @@ You can find a simple demo on <https://tofsjonas.github.io/sortable/>
6062

6163
There are three ways to use sortable, all of which have their pros and cons. [S Anand](https://github.com/sanand0) and [dkhgh](https://github.com/dkhgh) had some [interesting thoughts](https://github.com/tofsjonas/sortable/issues/28) about it.
6264

63-
1. Include a link to [jsDelivr](https://www.jsdelivr.com/package/gh/tofsjonas/sortable). (easiest)
64-
65-
2. Copy the file from [jsDelivr](https://www.jsdelivr.com/package/gh/tofsjonas/sortable) or [Github](https://github.com/tofsjonas/sortable) and put it in your assets folder. (in between)
66-
67-
3. Install the [npm package](https://www.npmjs.com/package/sortable-tablesort). (most reliable)
68-
6965
### 1. link to jsDelivr
7066

7167
```html
@@ -82,13 +78,13 @@ There are three ways to use sortable, all of which have their pros and cons. [S
8278
<td>Rick</td>
8379
</tr>
8480
<tr>
85-
<td><a href="javascript:alert('Inline javascript works!');">Sidekick</a></td>
81+
<td><a href="javascript:alert('standalone javascript works!');">Sidekick</a></td>
8682
<td>Morty</td>
8783
</tr>
8884
</tbody>
8985
</table>
90-
<link href="https://cdn.jsdelivr.net/gh/tofsjonas/sortable@latest/sortable.min.css" rel="stylesheet" />
91-
<script src="https://cdn.jsdelivr.net/gh/tofsjonas/sortable@latest/sortable.min.js"></script>
86+
<link href="https://cdn.jsdelivr.net/gh/tofsjonas/sortable@latest/dist/sortable.min.css" rel="stylesheet" />
87+
<script src="https://cdn.jsdelivr.net/gh/tofsjonas/sortable@latest/dist/sortable.min.js"></script>
9288
```
9389

9490
The `span` on line four is just there to prove that you can have elements inside `th`!
@@ -97,7 +93,7 @@ The `span` on line four is just there to prove that you can have elements inside
9793

9894
### 2. copy file to assets folder
9995

100-
Same as above, but link to your own files
96+
Same as above, but link to your own files from the `dist` directory
10197

10298
```html
10399
...
@@ -116,16 +112,16 @@ npm install sortable-tablesort
116112
# pnpm install sortable-tablesort
117113
```
118114

119-
Now you can
115+
Now you can:
120116

121117
#### a) use links in the html
122118

123-
Same as above, with links to files
119+
Same as above, with links to files from the `dist` directory
124120

125121
```html
126122
...
127-
<link href="./node_modules/sortable-tablesort/sortable.min.css" rel="stylesheet" />
128-
<script src="./node_modules/sortable-tablesort/sortable.min.js"></script>
123+
<link href="./node_modules/sortable-tablesort/dist/sortable.min.css" rel="stylesheet" />
124+
<script src="./node_modules/sortable-tablesort/dist/sortable.min.js"></script>
129125
...
130126
```
131127

@@ -135,8 +131,8 @@ or
135131

136132
```javascript
137133
// main.js
138-
import 'sortable-tablesort/sortable.min.css'
139-
import 'sortable-tablesort/sortable.min.js'
134+
import 'sortable-tablesort/dist/sortable.min.css'
135+
import 'sortable-tablesort/dist/sortable.min.js'
140136
```
141137

142138
## Non-sortable field
@@ -222,6 +218,28 @@ That said, if you're feeling lazy, here are two stylesheets you can use:
222218
<link href="https://cdn.jsdelivr.net/gh/tofsjonas/sortable@latest/sortable.min.css" rel="stylesheet" />
223219
```
224220

221+
### Sticky headers
222+
223+
I'm not sure if it's a good idea to have it in the main css, BUT if you are using the above `sortable(.min).css` file (not the -base files) and want sticky headers, you can simply add the class `sticky` to the table.
224+
225+
Blame [razorkyle](https://github.com/razorkyle), it was his idea! 😜
226+
227+
```html
228+
<table class="sortable sticky">
229+
...
230+
</table>
231+
```
232+
233+
If you are not using the css file, you can use the following css:
234+
235+
```css
236+
.sortable thead th {
237+
position: sticky;
238+
top: 0;
239+
z-index: 1;
240+
}
241+
```
242+
225243
## Sorting sizes, dates and such
226244

227245
Using the `data-sort` attribute in `tbody` > `td` you can have one visible value and one sortable value. This is useful in case you have for instance sizes like kb, Mb, GB, or really weird date formats. 😉
@@ -410,9 +428,9 @@ Sortable is not very accessible in its raw form. It does not support screen read
410428
<table class="sortable">
411429
...
412430
</table>
413-
<link href="sortable.min.css" rel="stylesheet" />
414-
<script src="sortable.min.js"></script>
415-
<script src="sortable.a11y.min.js"></script>
431+
<link href="dist/sortable.min.css" rel="stylesheet" />
432+
<script src="dist/sortable.min.js"></script>
433+
<script src="dist/sortable.a11y.min.js"></script>
416434
```
417435

418436
By including the file the global function `enhanceSortableAccessibility` will automatically run through all existing `.sortable` tables, but you can also run it manually, like so:
@@ -423,13 +441,38 @@ enhanceSortableAccessibility([table1, table2,...etc.])
423441

424442
The function adds an `aria-label` to each th, as well as `tabindex="0"` to each th in the thead of each table, making it possible to tab through the headers. It updates the `aria-label` depending on the direction.
425443

426-
if you want to import it instead this _should_ work: (I haven't tested it)
444+
If you want to import it instead:
427445

428446
```ts
429-
import { enhanceSortableAccessibility } from 'sortable-tablesort/enhanceSortableAccessibility'
447+
import { enhanceSortableAccessibility } from 'sortable-tablesort/dist/esm/enhanceSortableAccessibility'
430448
enhanceSortableAccessibility([table1, table2,...etc.])
431449
```
432450

451+
## Sort Events
452+
453+
The table element dispatches two custom events that bubble up the DOM tree:
454+
455+
- `sort-start`: Fired when sorting begins
456+
- `sort-end`: Fired when sorting is complete
457+
458+
You can listen for these events on any parent element, including the document itself:
459+
460+
```js
461+
// Listen for events from any sortable table
462+
document.addEventListener('sort-start', function (e) {
463+
console.log('Sorting started on:', e.target) // logs the table element
464+
})
465+
466+
document.addEventListener('sort-end', function (e) {
467+
console.log('Sorting complete on:', e.target) // logs the table element
468+
})
469+
470+
// Or listen to a specific table
471+
const table = document.querySelector('.sortable')
472+
table.addEventListener('sort-start', () => console.log('Sorting started'))
473+
table.addEventListener('sort-end', () => console.log('Sorting complete'))
474+
```
475+
433476
## Sort on load
434477

435478
If you wish to sort a table on load, I would recommend doing something like this:
@@ -494,3 +537,5 @@ Combine this with `<table class="sortable asc">` to reverse the sort order. Or d
494537
- ...[Jojo-IO](https://github.com/Jojo-IO) for the finding the "`parseFloat` messes up time values" bug!
495538

496539
- ...[Steve Wirt](https://github.com/swirtSJW) for lifting the Accessibility issue! 🦾️
540+
541+
- ...[GazHay](https://github.com/gazhay) for the [sort events](#sort-events) idea!

0 commit comments

Comments
 (0)