Fantasia he tree

From vishiri/fantasia-archive · View interactive version

Fantasia he tree is an AI agent skill from the GitHub repository vishiri/fantasia-archive. Hierarchical tree UI with @he-tree/vue only — full project replacement for Quasar QTree (forbidden). Virtualization, drag-and-drop, Quasar slot styling. Use when adding or changing any nested tree in the renderer.

How to use this skill

Skill file

Fantasia Archive — hierarchical trees (`@he-tree/vue`)

Policy

Enforced detail: fa-he-tree.mdc.

Why he-tree (not QTree)

QTree excluded. @he-tree/vue: virtual list for scale, optional DnD, slots for Quasar-styled rows.

Installation (already in repo)

yarn add @he-tree/vue

Basic usage (Vue 3 + script setup)

<template>
  <Draggable
    v-model="treeData"
    virtualization
    class="myFeatureTree hasScrollbar"
    :style="{ height: treeHeightPx + 'px' }"
    data-test-locator="myFeature-tree"
  >
    <template #default="{ node, stat }">
      <!-- Quasar + i18n inside the slot -->
      <span
        class="myFeatureTree__label"
        :data-test-locator="'myFeature-tree-node-' + node.id"
      >
        {{ node.label }}
      </span>
    </template>
  </Draggable>
</template>

<script setup lang="ts">
import { Draggable } from '@he-tree/vue'
import '@he-tree/vue/style/default.css'

const treeData = defineModel<Array<{ id: string, label: string, children?: unknown[] }>>('treeData', {
  required: true
})

const treeHeightPx = 400
</script>

Virtualization checklist

  1. Prop virtualization on BaseTree / Draggable.
  2. Fixed height or max-height on tree or bounded scroll parent.
  3. Lazy-load children from main/SQLite on first expand for huge projects.
  4. Avoid expand-all on huge trees in one tick.

Related props: virtualization, virtualizationPrerenderCount.

Drag-and-drop

DnD + scroll preservation (layout tree playbook)

Full postmortem: this skill section below (DnD + scroll preservation). Reference: DialogProjectSettingsWorldTemplateLayoutTree.vue.

Symptom: drop moves data OK; scrollTop jumps (often top). Or add row does not scroll into view.

| Cause | Fix |

| --- | --- |

| :key on Draggable changes on reorder/remount | No :key for sort; resyncTreeDataFromProps updates treeData |

| Topology key uses draft array order or sort fields | Canonical key: sorted ids + groupId only — mapDialogProjectSettingsWorldTemplateLayoutToTreeStructureKey |

| Resync rebuilds treeData when topology unchanged | Match keys → patchWorldTemplateLayoutDisplayLabelsInHeTreeNodes only |

| overflow: auto on wrapper, not he-tree root | Scroll on .dialogProjectSettingsWorldTemplateLayoutTree; host sizing only — resolveDialogProjectSettingsWorldTemplateLayoutTreeScrollContainer |

| Post-drop scrollTop restore | Do not — fights virtualization; fix remount/rebuild instead |

Workspace hierarchy (ProjectHierarchyTree): expand truth = openNodeIds / he-tree stats — never derive drag expand snapshots from mounted DOM rows (virt omits off-screen). No :key remount; soft resync only. Post-drop expand reapply can zero vtlist scrollTop — preserve/restore around commit finalize (not a substitute for remount). he-tree does not forward @virtual-list/vue buffer; hierarchy manager mutates VirtualList default (~10 row heights) before mount.

Pipeline: @before-drag-start → v-model during drag → @after-drop → deferred emitLayoutFromTreeDataIfChanged → props watch resyncTreeDataFromProps. Append: separate count watch → scheduleScrollContainerToRevealLastItem.

Debug: compare topology keys layout vs mapHeTreeNodesToWorldTemplateLayoutDraft(treeData) after drop; check resync rebuild vs patch; find real scroll element in DevTools.

Data and architecture

| Concern | Location |

| --- | --- |

| Node row UI, locators | Feature .vue (thin script) |

| DB → nodes, filter, selection | Feature scripts/ or src/scripts/<domain>/ |

| Shared walk/flatten/id-index | Colocate with feature until ≥2 consumers need same helpers (no src/scripts/faHeTree/ yet) |

| Shared interfaces | types/I_*.ts (app/types/...) |

Two-level: pure transforms in functions/ (import type only); managers wire stores + IPC.

Styling

Utilities

import { walkTreeData } from '@he-tree/vue'

walkTreeData(nodes, (node, index, parent) => {
  // visit
}, { childrenKey: 'children' })

Use walkTreeData for search, bulk expand, validation — not ad hoc recursion everywhere.

Project Settings — world template layout

DialogProjectSettingsWorldTemplateLayoutTree.vue — Draggable, max depth 2, DnD rules in dialogProjectSettingsWorldTemplateLayoutDnD.ts, commit policy + wiring in feature scripts/. DnD scroll playbook: this skill DnD + scroll preservation. Full map: fa-he-tree.mdc and fa-drag-drop-lists.mdc.

Tests

Related docs

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.