UNPKG

@sanity/orderable-document-list

Version:

Drag-and-drop Document Ordering without leaving the Editing surface

16 lines (13 loc) 563 B
import {LexoRank} from 'lexorank' import {NewItemPosition} from '../types' // Use in initial value field by passing in the rank value of the last document // If not value passed, generate a sensibly low rank export default function initialRank( compareRankValue = ``, newItemPosition: NewItemPosition = 'after' ): string { const compareRank = compareRankValue ? LexoRank.parse(compareRankValue) : LexoRank.min() const rank = newItemPosition === 'before' ? compareRank.genPrev().genPrev() : compareRank.genNext().genNext() return rank.toString() }