feat(entity): Chunk #4 data layer + entity UI (characters & world-building)
Data layer: - Fuzzy scorer (packages/core/src/fuzzy.ts) with index recovery + unit tests - Backlink computation (packages/core/src/backlinks.ts) incl. entity-level backlinks - Consistency checker (packages/core/src/consistency.ts) incl. reciprocity/scope + unit tests - StorageAdapter contract extended with listEntities/searchEntities/saveEntity/deleteEntity; implemented in Local (Dexie) and Server adapters; contract tests cover entity CRUD + ?q= search - WorldItem.fields now supports list values (keyPeople, rivals); expanded RelationshipKind - @mention autocomplete extension + picker in the editor package Entity UI (apps/web/src/features/entities/): - Generic field renderer (EntityFields) driven by ENTITY_FIELDS/FieldDef - Tabbed directory with fuzzy search + entity cards (EntitiesView) - Create/edit/delete drawer (EntityEditor) reusing shared fields - Relationship editor + force-directed SVG relationship map - Entity engine stylesheet; wired into nav Store: project-store entity methods (load/create/update/delete) over the StorageAdapter contract. CI-green: typecheck, lint, 65 tests, and web build all pass.
This commit is contained in:
+16
-1
@@ -183,7 +183,7 @@ export function toEntity(r: EntityRow): Entity {
|
||||
bio: f.bio ?? "",
|
||||
appearance: f.appearance ?? "",
|
||||
voice: f.voice ?? "",
|
||||
relationships: f.relationships ?? "",
|
||||
relationships: typeof f.relationships === "string" ? JSON.parse(f.relationships) : (f.relationships ?? []),
|
||||
arc: f.arc ?? "",
|
||||
status: f.status ?? "active",
|
||||
tags: f.tags ?? [],
|
||||
@@ -251,6 +251,21 @@ export function entityToRow(e: Entity): Omit<EntityRow, "created_at" | "updated_
|
||||
}
|
||||
|
||||
// ---- helpers ----
|
||||
/** Concatenate every human-readable field of an entity into one searchable string. */
|
||||
export function entitySearchText(e: Entity): string {
|
||||
if ("fields" in e) {
|
||||
const parts = [e.name, e.kind];
|
||||
for (const v of Object.values(e.fields)) if (typeof v === "string") parts.push(v);
|
||||
return parts.join(" ");
|
||||
}
|
||||
if ("body" in e) {
|
||||
return [e.body, ...e.tags].join(" ");
|
||||
}
|
||||
const c = e as Character;
|
||||
const relText = (c.relationships ?? []).map((r) => `${r.targetId} ${r.kind} ${r.note}`).join(" ");
|
||||
return [c.name, c.role, c.bio, c.appearance, c.voice, relText, c.arc, c.status, ...c.tags].join(" ");
|
||||
}
|
||||
|
||||
/** Count words in a ProseMirror doc (text nodes only). */
|
||||
export function wordCount(doc: unknown): number {
|
||||
let count = 0;
|
||||
|
||||
Reference in New Issue
Block a user