diff --git a/package.json b/package.json index bc376ef..db41649 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/data-grid/index.ts b/src/data-grid/index.ts index 8ef2ce6..c950910 100644 --- a/src/data-grid/index.ts +++ b/src/data-grid/index.ts @@ -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' @@ -477,7 +477,7 @@ export default class DataGrid extends Component { 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] @@ -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) }