Skip to content

Commit

Permalink
chore: small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Nov 19, 2024
1 parent 5d2d855 commit a097355
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 56 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"homepage": "https://github.com/liriliri/luna#readme",
"dependencies": {
"licia": "^1.44.0"
"licia": "^1.45.0"
},
"devDependencies": {
"@babel/core": "^7.10.5",
Expand Down
57 changes: 2 additions & 55 deletions src/data-grid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import isUndef from 'licia/isUndef'
import ResizeSensor from 'licia/ResizeSensor'
import throttle from 'licia/throttle'
import defaults from 'licia/defaults'
import startWith from 'licia/startWith'
import naturalSort from 'licia/naturalSort'
import isNull from 'licia/isNull'
import isFn from 'licia/isFn'
import isRegExp from 'licia/isRegExp'
Expand Down Expand Up @@ -477,7 +477,7 @@ export default class DataGrid extends Component<IOptions> {
private sortNodes(id: string, isAscending: boolean) {
const column = this.colMap[id]

const comparator = column.comparator || naturalOrderComparator
const comparator = column.comparator || naturalSort.comparator
function sortFn(a: DataGridNode, b: DataGridNode) {
let aVal = a.data[id]
let bVal = b.data[id]
Expand Down Expand Up @@ -710,59 +710,6 @@ export class DataGridNode {
}
}

function naturalOrderComparator(a: any, b: any) {
a = toStr(a)
b = toStr(b)
if (startWith(a, '_') && !startWith(b, '_')) {
return 1
}
if (startWith(b, '_') && !startWith(a, '_')) {
return -1
}

const chunk = /^\d+|^\D+/
let chunka, chunkb, anum, bnum
/* eslint-disable no-constant-condition */
while (true) {
if (a) {
if (!b) {
return 1
}
} else {
if (b) {
return -1
}
return 0
}
chunka = a.match(chunk)[0]
chunkb = b.match(chunk)[0]
anum = !isNaN(chunka)
bnum = !isNaN(chunkb)
if (anum && !bnum) {
return -1
}
if (bnum && !anum) {
return 1
}
if (anum && bnum) {
const diff = chunka - chunkb
if (diff) {
return diff
}
if (chunka.length !== chunkb.length) {
if (!+chunka && !+chunkb) {
return chunka.length - chunkb.length
}
return chunkb.length - chunka.length
}
} else if (chunka !== chunkb) {
return chunka < chunkb ? -1 : 1
}
a = a.substring(chunka.length)
b = b.substring(chunkb.length)
}
}

if (typeof module !== 'undefined') {
exportCjs(module, DataGrid)
}

0 comments on commit a097355

Please sign in to comment.