{"version":3,"file":"addEntityAtIndex.cjs","sources":["../../../../../packages/react-binding/src/accessorSorting/addEntityAtIndex.ts"],"sourcesContent":["import { repairEntitiesOrder } from './repairEntitiesOrder'\nimport { sortEntities } from './sortEntities'\nimport { EntityAccessor, EntityListAccessor, RelativeSingleField } from '@contember/binding'\n\nexport const addEntityAtIndex = (\n\tentityList: EntityListAccessor,\n\tsortableByField: RelativeSingleField,\n\tindex: number,\n\tpreprocess?: EntityAccessor.BatchUpdatesHandler,\n) => {\n\tconst sortedEntities = sortEntities(Array.from(entityList), sortableByField)\n\n\tentityList.createNewEntity((getNewlyAdded, options) => {\n\t\tlet newlyAdded = getNewlyAdded()\n\n\t\tconst sortableField = newlyAdded.getField<number>(sortableByField)\n\n\t\tsortableField.updateValue(index)\n\t\tnewlyAdded = getNewlyAdded()\n\n\t\tsortedEntities.splice(index, 0, newlyAdded)\n\t\trepairEntitiesOrder(sortableByField, sortedEntities)\n\n\t\tpreprocess?.(getNewlyAdded, options)\n\t})\n}\n"],"names":["sortEntities","repairEntitiesOrder"],"mappings":";;;;AAIO,MAAM,mBAAmB,CAC/B,YACA,iBACA,OACA,eACI;AACJ,QAAM,iBAAiBA,aAAAA,aAAa,MAAM,KAAK,UAAU,GAAG,eAAe;AAEhE,aAAA,gBAAgB,CAAC,eAAe,YAAY;AACtD,QAAI,aAAa,cAAc;AAEzB,UAAA,gBAAgB,WAAW,SAAiB,eAAe;AAEjE,kBAAc,YAAY,KAAK;AAC/B,iBAAa,cAAc;AAEZ,mBAAA,OAAO,OAAO,GAAG,UAAU;AAC1CC,wBAAA,oBAAoB,iBAAiB,cAAc;AAEnD,iBAAa,eAAe,OAAO;AAAA,EAAA,CACnC;AACF;;"}