fix(manacore/web): fix cross-module drop — sync entity registration, lazy store imports

Entity registration was async (dynamic imports) so acceptedDropTypes
was always empty when $derived first evaluated. Now entities register
synchronously at import time. Store imports (Dexie, etc.) are deferred
to createItem() call time to avoid circular dependencies.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-04-03 13:42:31 +02:00
parent 66d61962b6
commit df74029423
3 changed files with 13 additions and 10 deletions

View file

@ -11,13 +11,13 @@ export {
getAllEntities,
} from './registry';
// Lazy entity registration — avoids circular imports at module load time.
let registered = false;
// Register module entities eagerly — these are lightweight descriptor files
// with no heavy dependencies (stores are only called at drop time, not import time).
import '$lib/modules/todo/entity';
import '$lib/modules/calendar/entity';
import '$lib/modules/contacts/entity';
// Re-export for consumers that previously used lazy registration
export function ensureEntitiesRegistered(): void {
if (registered) return;
registered = true;
import('$lib/modules/todo/entity');
import('$lib/modules/calendar/entity');
import('$lib/modules/contacts/entity');
// No-op — entities are now registered at import time
}

View file

@ -1,6 +1,4 @@
import { registerEntity } from '$lib/entities/registry';
import { eventsStore } from './stores/events.svelte';
import { db } from '$lib/data/database';
import type { EntityDescriptor } from '$lib/entities/types';
const calendarEntity: EntityDescriptor = {
@ -48,6 +46,10 @@ const calendarEntity: EntityDescriptor = {
},
createItem: async (data) => {
// Lazy imports to avoid circular dependency at registration time
const { db } = await import('$lib/data/database');
const { eventsStore } = await import('./stores/events.svelte');
const calendars = await db.table('calendars').toArray();
const defaultCal = calendars.find((c: Record<string, unknown>) => !c.deletedAt);
const calendarId = (defaultCal?.id as string) ?? 'default';

View file

@ -1,5 +1,4 @@
import { registerEntity } from '$lib/entities/registry';
import { tasksStore } from './stores/tasks.svelte';
import type { EntityDescriptor } from '$lib/entities/types';
const todoEntity: EntityDescriptor = {
@ -27,6 +26,8 @@ const todoEntity: EntityDescriptor = {
},
createItem: async (data) => {
// Lazy import to avoid circular dependency at registration time
const { tasksStore } = await import('./stores/tasks.svelte');
const task = await tasksStore.createTask(
data as { title: string; dueDate?: string; description?: string }
);