refactor: moveRegion & add csv loader
This commit is contained in:
parent
d4562b8534
commit
97ef1df4fb
|
|
@ -117,41 +117,20 @@ export function shuffle<TMeta>(region: Region, parts: Record<string, Part<TMeta>
|
||||||
region.partMap = buildPartMap(region, parts);
|
region.partMap = buildPartMap(region, parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveToRegion<TMeta>(part: Part<TMeta>, sourceRegion: Region | null, targetRegion: Region, position?: number[]) {
|
export function moveToRegion<TMeta>(part: Part<TMeta>, sourceRegion: Region | null, targetRegion: Region | null, position?: number[]) {
|
||||||
if (sourceRegion && part.regionId === sourceRegion.id) {
|
if (sourceRegion && part.regionId === sourceRegion.id) {
|
||||||
sourceRegion.childIds = sourceRegion.childIds.filter(id => id !== part.id);
|
sourceRegion.childIds = sourceRegion.childIds.filter(id => id !== part.id);
|
||||||
delete sourceRegion.partMap[part.position.join(',')];
|
delete sourceRegion.partMap[part.position.join(',')];
|
||||||
}
|
}
|
||||||
|
|
||||||
targetRegion.childIds.push(part.id);
|
|
||||||
if (position) {
|
if (position) {
|
||||||
part.position = position;
|
part.position = position;
|
||||||
}
|
}
|
||||||
targetRegion.partMap[part.position.join(',')] = part.id;
|
|
||||||
|
|
||||||
part.regionId = targetRegion.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function moveToRegionAll<TMeta>(parts: Record<string, Part<TMeta>>, sourceRegion: Region | null, targetRegion: Region, positions?: number[][]) {
|
|
||||||
const partIds = Object.keys(parts);
|
|
||||||
for (let i = 0; i < partIds.length; i++) {
|
|
||||||
const part = parts[partIds[i]];
|
|
||||||
if (sourceRegion && part.regionId === sourceRegion.id) {
|
|
||||||
sourceRegion.childIds = sourceRegion.childIds.filter(id => id !== part.id);
|
|
||||||
delete sourceRegion.partMap[part.position.join(',')];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(targetRegion){
|
||||||
targetRegion.childIds.push(part.id);
|
targetRegion.childIds.push(part.id);
|
||||||
if (positions && positions[i]) {
|
|
||||||
part.position = positions[i];
|
|
||||||
}
|
|
||||||
targetRegion.partMap[part.position.join(',')] = part.id;
|
targetRegion.partMap[part.position.join(',')] = part.id;
|
||||||
|
|
||||||
part.regionId = targetRegion.id;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function removeFromRegion<TMeta>(part: Part<TMeta>, region: Region) {
|
part.regionId = targetRegion?.id || '';
|
||||||
region.childIds = region.childIds.filter(id => id !== part.id);
|
|
||||||
delete region.partMap[part.position.join(',')];
|
|
||||||
}
|
}
|
||||||
|
|
@ -17,7 +17,7 @@ export type { PartTemplate, PartPool } from './core/part-factory';
|
||||||
export { createPart, createParts, createPartPool, mergePartPools } from './core/part-factory';
|
export { createPart, createParts, createPartPool, mergePartPools } from './core/part-factory';
|
||||||
|
|
||||||
export type { Region, RegionAxis } from './core/region';
|
export type { Region, RegionAxis } from './core/region';
|
||||||
export { createRegion, applyAlign, shuffle, moveToRegion, moveToRegionAll, removeFromRegion } from './core/region';
|
export { createRegion, applyAlign, shuffle, moveToRegion, moveToRegionAll } from './core/region';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
export type { Command, CommandResult, CommandSchema, CommandParamSchema, CommandOptionSchema, CommandFlagSchema } from './utils/command';
|
export type { Command, CommandResult, CommandSchema, CommandParamSchema, CommandOptionSchema, CommandFlagSchema } from './utils/command';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
|
import {csvLoader} from 'inline-schema/csv-loader/rollup';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
test: {
|
test: {
|
||||||
|
|
@ -6,6 +7,9 @@ export default defineConfig({
|
||||||
environment: 'node',
|
environment: 'node',
|
||||||
include: ['tests/**/*.test.ts'],
|
include: ['tests/**/*.test.ts'],
|
||||||
},
|
},
|
||||||
|
plugins: [csvLoader({
|
||||||
|
writeToDisk: true
|
||||||
|
})],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@/': new URL('./src/', import.meta.url).pathname,
|
'@/': new URL('./src/', import.meta.url).pathname,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue