@murumets-ee/menus 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +94 -0
- package/dist/admin.d.mts +293 -0
- package/dist/admin.d.mts.map +1 -0
- package/dist/admin.mjs +2 -0
- package/dist/admin.mjs.map +1 -0
- package/dist/en-Cr9XUf6B.mjs +2 -0
- package/dist/en-Cr9XUf6B.mjs.map +1 -0
- package/dist/entity-BxLeqoBC.mjs +2 -0
- package/dist/entity-BxLeqoBC.mjs.map +1 -0
- package/dist/et-C_k3aK3T.mjs +2 -0
- package/dist/et-C_k3aK3T.mjs.map +1 -0
- package/dist/i18n.d.mts +16 -0
- package/dist/i18n.d.mts.map +1 -0
- package/dist/i18n.mjs +2 -0
- package/dist/i18n.mjs.map +1 -0
- package/dist/index.d.mts +75 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1 -0
- package/dist/menu-entity-types-BnKnKbif.mjs +2 -0
- package/dist/menu-entity-types-BnKnKbif.mjs.map +1 -0
- package/dist/menu-item-schema-xXWZKw7t.d.mts +296 -0
- package/dist/menu-item-schema-xXWZKw7t.d.mts.map +1 -0
- package/dist/messages/en.json +19 -0
- package/dist/messages/et.json +19 -0
- package/dist/messages/ru.json +19 -0
- package/dist/resolve.d.mts +205 -0
- package/dist/resolve.d.mts.map +1 -0
- package/dist/resolve.mjs +2 -0
- package/dist/resolve.mjs.map +1 -0
- package/dist/ru-CIJipJXJ.mjs +2 -0
- package/dist/ru-CIJipJXJ.mjs.map +1 -0
- package/dist/schema.d.mts +280 -0
- package/dist/schema.d.mts.map +1 -0
- package/dist/schema.mjs +2 -0
- package/dist/schema.mjs.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.mjs","names":[],"sources":["../src/get-menu.ts","../src/internal/columns.ts","../src/menu-resolve-context.ts"],"sourcesContent":["/**\n * `getMenu()` — turn a stored menu tree into a render-ready structure for one\n * locale (plan/routing phase 11 §2), plus the pure `markActiveTrail()` helper\n * (phase 11 §3).\n *\n * **Leaf module.** Every cross-package capability (the menu row read, the\n * `toolkit_paths` forward index, the publish gate, live entity titles) arrives\n * through the injected {@link MenuResolveDeps}; nothing here imports\n * `@murumets-ee/core` or `@murumets-ee/content`. Concrete deps are built from a\n * live app in `./menu-resolve-context.ts` — the same leaf/seam split\n * `@murumets-ee/content`'s `paths/enumerate.ts` ↔ `paths/resolve-context.ts`\n * uses, and the reason the deps' function types are declared structurally here\n * rather than imported (assignability is still checked, at the seam).\n *\n * **Security.** The resolved output feeds PUBLIC page navigation, so it must\n * never surface an unpublished or deleted document:\n * - the menu itself is read through a publish-filtered client (an unpublished\n * menu resolves to `null` — nothing renders),\n * - every entity-linked item must have BOTH a canonical path in\n * `toolkit_paths` for the requested locale AND survive the batched publish\n * gate; missing either → the item (and its subtree) is dropped,\n * - `url` / `email` targets are re-gated through the same `sanitizeHref`\n * protocol allowlist the write path uses, so a value that reached the column\n * by some route other than the entity API (a direct DB edit, a restored\n * dump) still cannot become a `javascript:` href,\n * - every filtering decision fails CLOSED — anything unresolvable is dropped,\n * never rendered with a placeholder.\n *\n * **No unbounded fan-out** (CLAUDE.md). Backend work is bounded by the number\n * of distinct ENTITY TYPES in the tree, never by the number of items: the walk\n * collects ids grouped by type, then issues at most THREE batched calls per\n * group (forward index → publish gate → titles). The group count is itself hard-\n * capped ({@link MAX_MENU_ENTITY_TYPES}) and the walk carries a node budget\n * ({@link MAX_MENU_TREE_NODES}), so one render costs a fixed, small number of\n * round-trips no matter what the stored tree looks like.\n *\n * **Read-time validation is per-node, not whole-tree.** The write path already\n * runs `buildMenuTreeSchema()` (`menuTreeValidation()`), and this module\n * deliberately does NOT re-run it: that schema whitelists locale KEYS against\n * the app's configured locales, so re-parsing at read time would fail the WHOLE\n * menu — site navigation gone — the moment an operator removes a locale from\n * config after a menu was saved. The locale whitelist is a write-time authoring\n * check with no read-time security value. What DOES matter at read time (node\n * shape, the `LinkValue` protocol gate) is re-checked per node here, and a\n * malformed node is dropped on its own without taking the menu down with it.\n */\n\nimport { resolveLinkHref } from '@murumets-ee/blocks/links'\nimport {\n DEFAULT_MENU_DEPTH,\n LinkValueSchema,\n MAX_MENU_DEPTH,\n MAX_MENU_TREE_NODES,\n type MenuLinkValue,\n} from './menu-item-schema.js'\n\n// ---------------------------------------------------------------------------\n// Bounds\n// ---------------------------------------------------------------------------\n\n/**\n * Hard cap on the number of DISTINCT entity types one menu may fan out over.\n *\n * The batched pipeline costs three DB round-trips per type group, so this — not\n * the item count — is what bounds a render's backend work. A navigation menu\n * pointing at more than a handful of routable types is malformed by\n * construction; types past the cap are dropped (their items disappear) and\n * logged, never silently truncated.\n */\nexport const MAX_MENU_ENTITY_TYPES = 16\n\n/**\n * Longest `handle` accepted — rejected before any DB work. A defensive cap, not\n * a mirror of the entity's `handle` column (`varchar(255)`): a handle is a\n * hand-authored navigation key, so anything approaching this length is\n * malformed by construction.\n */\nconst MAX_HANDLE_LENGTH = 128\n\n// ---------------------------------------------------------------------------\n// Public shape (phase 11 §2)\n// ---------------------------------------------------------------------------\n\n/** One render-ready menu item (phase 11 §2 — exact shape). */\nexport interface ResolvedMenuItem {\n /** The stored item's stable id (DND identity; also a stable React key). */\n id: string\n kind: 'link' | 'header'\n /** Resolved label: the per-locale override, else the live entity title. */\n label: string\n /**\n * Locale-relative canonical path from `toolkit_paths` (+ `#anchor` when set),\n * external `url` / `email` targets verbatim (protocol-gated), `null` for\n * `header` items.\n */\n href: string | null\n newTab: boolean\n /** Exact `currentPath` match on the path part (any `#anchor` ignored). */\n isActive: boolean\n /** An ancestor BY TREE of the active item — never a path-prefix guess. */\n inActiveTrail: boolean\n children: ResolvedMenuItem[]\n}\n\n/**\n * A resolved menu.\n *\n * Phase 11 §2 names `ResolvedMenuItem` and uses `ResolvedMenu` as `getMenu`'s\n * return type without spelling its fields out; this is the minimal wrapper that\n * satisfies it — the requested `handle` (so a caller holding several resolved\n * menus can tell them apart, and so `markActiveTrail` can round-trip a menu\n * without losing its identity) plus the item forest. Deliberately carries no\n * `maxDepth` / `title`: the depth clamp is already APPLIED in `items`, and a\n * menu's admin-facing title is not a rendering concern.\n */\nexport interface ResolvedMenu {\n handle: string\n items: ResolvedMenuItem[]\n}\n\n/** Options for {@link getMenu} (phase 11 §2). */\nexport interface GetMenuOptions {\n /** The locale to resolve labels, visibility and canonical paths for. */\n locale: string\n /**\n * The page being rendered, for active-trail marking. SSG frontends usually\n * OMIT this (one build-time fetch) and call {@link markActiveTrail} per page.\n */\n currentPath?: string | undefined\n}\n\n// ---------------------------------------------------------------------------\n// Injected dependencies\n// ---------------------------------------------------------------------------\n\n/** The projected `menu` row {@link getMenu} reads. */\nexport interface MenuRow {\n /**\n * The menu's own depth cap. Absent / out of range falls back to the entity\n * default — the clamp is renderer-enforced independently of the editor\n * (phase 07 §2.7), so a bad stored value can never widen it.\n */\n maxDepth?: number | null | undefined\n /** Raw `menu.tree` JSONB. Untrusted shape — validated per node during the walk. */\n tree: unknown\n}\n\n/**\n * Structural minimum of a pino/toolkit logger. Declared here (rather than\n * imported) so this module stays import-free; `app.logger.child(...)` satisfies\n * it structurally.\n */\nexport interface MenuResolveLogger {\n warn(obj: object, msg: string): void\n}\n\n/**\n * Everything {@link getMenu} needs from the outside world.\n *\n * Function-shaped (not reader-shaped) on purpose: the concrete implementations\n * live in `./menu-resolve-context.ts`, where assignability against\n * `@murumets-ee/content`'s real `getCanonicalPaths` / `PublishFilter` is\n * type-checked at the seam — so this module needs no `@murumets-ee/content`\n * import and drift is still a build error.\n */\nexport interface MenuResolveDeps {\n /**\n * Fetch the PUBLISHED menu row by handle, or `null`.\n *\n * The publish filter is the implementation's responsibility (the app-side\n * factory reads through a publish-filtering `QueryClient`) — a draft menu\n * must never resolve, per phase 11 §2.\n */\n getMenuRow: (handle: string) => Promise<MenuRow | null>\n /**\n * Batched forward index read: which of `ids` have a canonical path in\n * `locale`? Does NOT publish-filter — {@link MenuResolveDeps.filterPublished}\n * is the required second step.\n */\n resolveCanonicalPaths: (\n entityType: string,\n ids: readonly string[],\n locale: string,\n ) => Promise<ReadonlyMap<string, string>>\n /** Batched publish gate: which of `ids` are published in `locale`? */\n filterPublished: (\n entityType: string,\n ids: readonly string[],\n locale: string,\n ) => Promise<ReadonlySet<string>>\n /**\n * Batched live-title read: `id → display title` for `locale`. Only called for\n * the ids that actually need one (no per-locale label override), and never\n * for `header` items (they have no linked entity to borrow a title from).\n */\n resolveTitles: (\n entityType: string,\n ids: readonly string[],\n locale: string,\n ) => Promise<ReadonlyMap<string, string>>\n /**\n * Fallback locale for label overrides — the app's configured content\n * `defaultLocale`. A label present only in the default locale still renders\n * (the same locale → default fallback `mergeTranslations` gives entity data),\n * instead of silently dropping a partially-translated item.\n */\n defaultLocale: string\n /** Optional — used to report DROPPED work (never silent truncation). */\n logger?: MenuResolveLogger | undefined\n}\n\n// ---------------------------------------------------------------------------\n// Locale-map reads (defensive: these run against raw JSONB)\n// ---------------------------------------------------------------------------\n\n/**\n * Read one locale's string out of a raw `label` map, falling back to\n * `defaultLocale`. Own-property reads only, so a `__proto__` / `constructor`\n * key in stored JSON can't produce a value. Empty strings count as absent — an\n * item labelled `''` renders as an invisible link.\n */\nfunction readLocaleString(map: unknown, locale: string, defaultLocale: string): string | undefined {\n if (map === null || typeof map !== 'object' || Array.isArray(map)) return undefined\n const record: Record<string, unknown> = map as Record<string, unknown>\n for (const key of locale === defaultLocale ? [locale] : [locale, defaultLocale]) {\n if (!Object.hasOwn(record, key)) continue\n const value = record[key]\n if (typeof value === 'string' && value.length > 0) return value\n }\n return undefined\n}\n\n/**\n * Read one locale's visibility flag. NO default-locale fallback on purpose:\n * `enabled` is per-locale visibility in both directions (phase 08 §3), so\n * hiding an item in `en` must not hide it in `et`.\n */\nfunction readLocaleBoolean(map: unknown, locale: string): boolean | undefined {\n if (map === null || typeof map !== 'object' || Array.isArray(map)) return undefined\n const record: Record<string, unknown> = map as Record<string, unknown>\n if (!Object.hasOwn(record, locale)) return undefined\n const value = record[locale]\n return typeof value === 'boolean' ? value : undefined\n}\n\n// ---------------------------------------------------------------------------\n// Pass 1 — structural narrowing + id collection (one walk)\n// ---------------------------------------------------------------------------\n\n/**\n * A node that survived structural validation. Data-driven filtering (publish\n * state, canonical path, label availability, empty-header pruning) happens in\n * pass 2, once the batched lookups have run.\n */\ninterface PreparedNode {\n id: string\n kind: 'link' | 'header'\n link: MenuLinkValue | undefined\n /** Raw label map — read per locale in pass 2. */\n label: unknown\n newTab: boolean\n children: PreparedNode[]\n}\n\ninterface PreparedTree {\n nodes: PreparedNode[]\n /** entityType → every linked id (needs a path + publish check). */\n idsByType: Map<string, Set<string>>\n /** entityType → the subset with no usable label override (needs a live title). */\n titleIdsByType: Map<string, Set<string>>\n /** Nodes discarded because a hard bound was hit (reported, never silent). */\n droppedForBudget: number\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\n/**\n * Walk the raw tree ONCE: validate each node's shape, apply the two filters\n * that need no I/O (per-locale `enabled`, the `maxDepth` clamp), and collect\n * the entity ids the batched lookups will need — grouped by entity type, so\n * pass 2 issues one call per GROUP rather than one per item.\n *\n * Bounded by {@link MAX_MENU_TREE_NODES} visited nodes and {@link MAX_MENU_DEPTH}\n * levels regardless of what is stored, so a hand-edited row can't turn a page\n * render into unbounded work.\n */\nfunction prepareTree(\n rawTree: unknown,\n locale: string,\n defaultLocale: string,\n maxDepth: number,\n): PreparedTree {\n const idsByType = new Map<string, Set<string>>()\n const titleIdsByType = new Map<string, Set<string>>()\n let budget = MAX_MENU_TREE_NODES\n let droppedForBudget = 0\n\n function collect(target: Map<string, Set<string>>, entityType: string, id: string): void {\n const bucket = target.get(entityType)\n if (bucket) bucket.add(id)\n else target.set(entityType, new Set([id]))\n }\n\n function walk(value: unknown, depth: number): PreparedNode[] {\n if (depth > maxDepth || !Array.isArray(value)) return []\n // `Array.isArray` narrows `unknown` to `any[]`; re-binding keeps elements `unknown`.\n const rawNodes: readonly unknown[] = value\n const out: PreparedNode[] = []\n\n for (const raw of rawNodes) {\n if (budget <= 0) {\n droppedForBudget++\n continue\n }\n if (!isPlainObject(raw)) continue\n\n const id = raw.id\n const kind = raw.kind\n if (typeof id !== 'string' || id.length === 0) continue\n if (kind !== 'link' && kind !== 'header') continue\n // Per-locale visibility drops the node AND its subtree — checked before\n // recursing so a hidden branch costs nothing.\n if (readLocaleBoolean(raw.enabled, locale) === false) continue\n\n budget--\n\n let link: MenuLinkValue | undefined\n if (kind === 'link') {\n // Re-validate the stored LinkValue — this is the `sanitizeHref`\n // protocol gate, the one write-time check that genuinely matters again\n // at read time (see the module header). A malformed link drops just\n // this node.\n const parsed = LinkValueSchema.safeParse(raw.link)\n if (!parsed.success) continue\n link = parsed.data\n } else if (raw.link !== undefined) {\n // A header carrying a link target is a shape violation — drop it\n // rather than render a half-defined node.\n continue\n }\n\n const children = walk(raw.children, depth + 1)\n\n if (link?.kind === 'entity') {\n collect(idsByType, link.entity, link.id)\n // Only items WITHOUT a usable override need a live title, so the title\n // read stays as small as possible — and header items, which have no\n // linked entity, can never reach this branch at all.\n if (readLocaleString(raw.label, locale, defaultLocale) === undefined) {\n collect(titleIdsByType, link.entity, link.id)\n }\n }\n\n out.push({ id, kind, link, label: raw.label, newTab: raw.newTab === true, children })\n }\n\n return out\n }\n\n const nodes = walk(rawTree, 1)\n return { nodes, idsByType, titleIdsByType, droppedForBudget }\n}\n\n// ---------------------------------------------------------------------------\n// Pass 2 — batched lookups\n// ---------------------------------------------------------------------------\n\ninterface ResolvedLookups {\n paths: Map<string, ReadonlyMap<string, string>>\n published: Map<string, ReadonlySet<string>>\n titles: Map<string, ReadonlyMap<string, string>>\n}\n\n/**\n * Run the batched lookups: for each entity-type GROUP, one forward-index read,\n * then one publish gate over the ids that had a path, then (only when some item\n * needs it) one title read. Exactly one call each, never per item, and\n * `MAX_MENU_ENTITY_TYPES` bounds the group count — so the number of round-trips\n * per render is fixed.\n *\n * Groups run CONCURRENTLY (bounded by the already-enforced `MAX_MENU_ENTITY_TYPES`\n * cap, never an unbounded `Promise.all`) — they're independent, and this sits on\n * a public SSR request path where the 3-step-per-group sequencing was otherwise\n * fully serial (up to 48 round-trips back to back for one render). Only the\n * THREE STEPS WITHIN one group stay ordered (path lookup → publish gate → title\n * read), since each depends on the previous step's output.\n *\n * How each dep handles an over-large id list is the DEP's business, and they\n * differ: `getCanonicalPaths` chunks internally, and so does the title reader in\n * `./menu-resolve-context.ts` (`TITLE_BATCH_SIZE`). `filterPublished` (content's\n * `buildEnumerateDeps`) does NOT — it issues a single `inArray` over whatever it\n * is handed. That is safe HERE because the id list is bounded tree-wide by\n * {@link MAX_MENU_TREE_NODES} (500) before it ever reaches this function, not\n * because the dep protects itself. A caller that lifts the node budget must\n * revisit that.\n */\nasync function runLookups(\n prepared: PreparedTree,\n locale: string,\n deps: MenuResolveDeps,\n handle: string,\n): Promise<ResolvedLookups> {\n const paths = new Map<string, ReadonlyMap<string, string>>()\n const published = new Map<string, ReadonlySet<string>>()\n const titles = new Map<string, ReadonlyMap<string, string>>()\n\n const groups = [...prepared.idsByType.entries()]\n if (groups.length > MAX_MENU_ENTITY_TYPES) {\n deps.logger?.warn(\n { handle, locale, entityTypes: groups.length, cap: MAX_MENU_ENTITY_TYPES },\n 'menu resolution dropped entity-type groups over the fan-out cap',\n )\n }\n\n await Promise.all(\n groups.slice(0, MAX_MENU_ENTITY_TYPES).map(async ([entityType, idSet]) => {\n const ids = [...idSet]\n // (1) Forward index — which ids have a canonical path in this locale?\n const pathMap = await deps.resolveCanonicalPaths(entityType, ids, locale)\n paths.set(entityType, pathMap)\n if (pathMap.size === 0) return\n\n // (2) Publish gate — `resolveCanonicalPaths` does NOT filter by publish\n // state (`toolkit_paths` has no status column), so this is the\n // required no-unpublished-leak step. Batched, over only the ids that\n // had a path.\n const candidates = [...pathMap.keys()]\n const publishedIds = await deps.filterPublished(entityType, candidates, locale)\n published.set(entityType, publishedIds)\n\n // (3) Live titles — only for items with no usable override, and only for\n // ids that will actually survive pass 3 (had a path AND published) —\n // fetching a title for an id that's about to be dropped is wasted work.\n const needTitles = prepared.titleIdsByType.get(entityType)\n if (needTitles === undefined) return\n const titleIds = candidates.filter((id) => needTitles.has(id) && publishedIds.has(id))\n if (titleIds.length === 0) return\n titles.set(entityType, await deps.resolveTitles(entityType, titleIds, locale))\n }),\n )\n\n return { paths, published, titles }\n}\n\n// ---------------------------------------------------------------------------\n// Pass 3 — resolve + filter, bottom-up\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve prepared nodes into {@link ResolvedMenuItem}s, dropping everything\n * that can't render. Children resolve BEFORE their parent so empty-header\n * pruning sees the already-filtered child list (phase 11 §2: \"header item whose\n * surviving children are all dropped → dropped\").\n */\nfunction resolveNodes(\n nodes: readonly PreparedNode[],\n locale: string,\n lookups: ResolvedLookups,\n deps: MenuResolveDeps,\n): ResolvedMenuItem[] {\n const out: ResolvedMenuItem[] = []\n\n for (const node of nodes) {\n const children = resolveNodes(node.children, locale, lookups, deps)\n const override = readLocaleString(node.label, locale, deps.defaultLocale)\n\n if (node.kind === 'header') {\n // No empty dropdowns (phase 11 §2), and no label → nothing to click on.\n if (children.length === 0) continue\n if (override === undefined) continue\n out.push({\n id: node.id,\n kind: 'header',\n label: override,\n href: null,\n newTab: false,\n isActive: false,\n inActiveTrail: false,\n children,\n })\n continue\n }\n\n const link = node.link\n if (link === undefined) continue\n\n let href: string | null\n let label = override\n\n if (link.kind === 'entity') {\n const path = lookups.paths.get(link.entity)?.get(link.id)\n // No canonical path at all → the target was deleted, never published in\n // this locale, or its type isn't routable. Unpublished → same outcome.\n if (path === undefined) continue\n if (lookups.published.get(link.entity)?.has(link.id) !== true) continue\n href = link.anchor === undefined ? path : `${path}#${link.anchor}`\n label ??= lookups.titles.get(link.entity)?.get(link.id)\n } else {\n // `url` / `email` — the only remaining kinds, so there is no dead\n // fallback branch to carry: `MenuLinkValue` has exactly three arms. A\n // `media` link is rejected at the WRITE boundary by `LinkValueSchema`,\n // which is also what drops one that reached the column by some other\n // route (a direct edit, a restored dump) — `prepareTree`'s `safeParse`\n // never lets it get this far.\n //\n // Verbatim external targets, protocol-gated once more by blocks'\n // `resolveLinkHref` (`mailto:` composition included) — the single source\n // of truth for what may become an `<a href>`. It returns `null` for\n // anything it cannot turn into an href, and a `null` href is dropped just\n // below — so widening `MenuLinkValue` later fails CLOSED here by default\n // rather than emitting a half-resolved item.\n href = resolveLinkHref(link)\n }\n\n // An item with no href or no resolvable label renders as either a dead\n // anchor or an invisible one — drop it, matching every other filter here.\n if (href === null || href.length === 0) continue\n if (label === undefined || label.length === 0) continue\n\n out.push({\n id: node.id,\n kind: 'link',\n label,\n href,\n newTab: node.newTab,\n isActive: false,\n inActiveTrail: false,\n children,\n })\n }\n\n return out\n}\n\n// ---------------------------------------------------------------------------\n// Active trail (phase 11 §3)\n// ---------------------------------------------------------------------------\n\n/**\n * The comparable path part of an href or a current path: the `#fragment` is\n * dropped (an anchor item on the current page is still \"the current page\", per\n * phase 11 §2) and a trailing slash is normalized away, so `/about` and\n * `/about/` match. The root `/` keeps its slash.\n */\nfunction comparablePath(value: string): string {\n const hash = value.indexOf('#')\n const path = hash === -1 ? value : value.slice(0, hash)\n return path.length > 1 && path.endsWith('/') ? path.slice(0, -1) : path\n}\n\ninterface MarkResult {\n items: ResolvedMenuItem[]\n containsActive: boolean\n}\n\nfunction markNodes(nodes: readonly ResolvedMenuItem[], target: string): MarkResult {\n let containsActive = false\n const items = nodes.map((node): ResolvedMenuItem => {\n const marked = markNodes(node.children, target)\n const isActive = node.href !== null && comparablePath(node.href) === target\n // Ancestry is read off the TREE, never guessed from a path prefix — prefix\n // guessing breaks across translated bases and across sibling paths that\n // merely share a prefix (`/about` vs `/about-us`).\n const inActiveTrail = marked.containsActive\n if (isActive || inActiveTrail) containsActive = true\n return { ...node, isActive, inActiveTrail, children: marked.items }\n })\n return { items, containsActive }\n}\n\n/**\n * Mark `isActive` / `inActiveTrail` on a resolved menu for one page.\n *\n * PURE — no I/O, and the input menu is not mutated (a new tree is returned), so\n * an SSG build can fetch a menu ONCE and mark it per page without the pages\n * contaminating each other. `getMenu` calls this internally when\n * `opts.currentPath` is given, so there is exactly one implementation of the\n * ancestry walk.\n *\n * `isActive` is an EXACT match on the path part; `inActiveTrail` marks strict\n * tree ancestors of an active item (an active item is not its own ancestor).\n */\nexport function markActiveTrail(menu: ResolvedMenu, currentPath: string): ResolvedMenu {\n return { ...menu, items: markNodes(menu.items, comparablePath(currentPath)).items }\n}\n\n// ---------------------------------------------------------------------------\n// Entry point\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve a stored menu into a render-ready tree for one locale (phase 11 §2).\n *\n * Returns `null` when the menu does not exist or is not published — a draft\n * menu renders nowhere public. A published menu whose every item was filtered\n * out returns an EMPTY item list, not `null`: \"the menu exists but has nothing\n * to show here\" is a different fact from \"there is no such menu\".\n *\n * Filtering order (phase 11 §2, not reorderable): menu unpublished → `null`;\n * `enabled[locale] === false` → dropped with its subtree; entity target deleted\n * or unpublished-in-locale → dropped; header with no surviving children →\n * dropped; depth clamped to the menu's own `maxDepth`.\n */\nexport async function getMenu(\n handle: string,\n opts: GetMenuOptions,\n deps: MenuResolveDeps,\n): Promise<ResolvedMenu | null> {\n if (handle.length === 0 || handle.length > MAX_HANDLE_LENGTH) return null\n\n const row = await deps.getMenuRow(handle)\n if (row === null) return null\n\n // Renderer-enforced clamp — independent of the editor's own check (phase 07\n // §2.7), and never wider than the absolute ceiling even if the column is not.\n const stored = row.maxDepth\n const maxDepth =\n typeof stored === 'number' && Number.isInteger(stored) && stored >= 1\n ? Math.min(stored, MAX_MENU_DEPTH)\n : DEFAULT_MENU_DEPTH\n\n const prepared = prepareTree(row.tree, opts.locale, deps.defaultLocale, maxDepth)\n if (prepared.droppedForBudget > 0) {\n deps.logger?.warn(\n {\n handle,\n locale: opts.locale,\n dropped: prepared.droppedForBudget,\n cap: MAX_MENU_TREE_NODES,\n },\n 'menu resolution dropped items over the node budget',\n )\n }\n\n const lookups = await runLookups(prepared, opts.locale, deps, handle)\n const menu: ResolvedMenu = {\n handle,\n items: resolveNodes(prepared.nodes, opts.locale, lookups, deps),\n }\n\n return opts.currentPath === undefined ? menu : markActiveTrail(menu, opts.currentPath)\n}\n","/**\n * Typed column access for a dynamically-generated entity table.\n *\n * `AdminClient.getTable()` / `QueryClient.getTable()` both return\n * `PgTableWithColumns<any>` (Drizzle cannot type columns that are generated\n * from a runtime entity definition), so reading a column off one directly\n * yields `any` and silently erodes this package's type coverage. Narrowing\n * through this helper pins the ONE column being filtered on — the same idiom\n * `@murumets-ee/content`'s `buildEnumerateDeps` uses.\n *\n * Internal to `@murumets-ee/menus`; not part of any public entry.\n */\n\nimport type { PgColumn, PgTableWithColumns } from 'drizzle-orm/pg-core'\n\n/** Read one named column off a runtime-generated entity table, typed. */\nexport function column<K extends string>(\n // biome-ignore lint/suspicious/noExplicitAny: Drizzle cannot type dynamically-generated column schemas — `PgTableWithColumns<any>` is `getTable()`'s own declared return type (CLAUDE.md's sanctioned case).\n table: PgTableWithColumns<any>,\n name: K,\n): PgColumn {\n return (table as unknown as Record<K, PgColumn>)[name]\n}\n","/**\n * App-binding for {@link import('./get-menu.js').getMenu} (plan/routing PR09).\n *\n * `./get-menu.ts` is a LEAF — it takes every dependency as an injected function\n * so it imports no `@murumets-ee/core` graph. THIS module is the outer seam\n * that holds those imports and builds concrete deps from a live `ToolkitApp`,\n * mirroring `@murumets-ee/content`'s `paths/resolve-context.ts` exactly. Because\n * the real `getCanonicalPaths` / `PublishFilter` are ASSIGNED to the leaf's\n * structurally-declared dep slots here, drift between the two packages is a\n * build error at this file rather than a silent divergence.\n *\n * **Reads run under an ELEVATED system context** (same `SYSTEM_CONTEXT` shape\n * and rationale as content's `resolve-context.ts` — read that file's header).\n * Rendering a menu is a SYSTEM derivation: it must work for an anonymous public\n * request, or for a build-time SSG run with no request context at all, and must\n * not fail just because the caller holds no per-entity `view` grant. Elevation\n * bypasses ONLY the permission/scope assertion — `QueryClient`'s PUBLISH filter\n * and trashed-row exclusion still apply unconditionally, so:\n * - an unpublished / trashed MENU still resolves to `null` (nothing renders),\n * - an unpublished / trashed TARGET is still absent from the publish gate and\n * from the title read, so its item is dropped.\n * The only data elevation exposes is a published document's title + canonical\n * path — the same facts the public sitemap already enumerates.\n */\n\nimport { getContentConfig } from '@murumets-ee/content/plugin'\nimport {\n buildCanonicalPathsBatchDeps,\n buildEnumerateDeps,\n getCanonicalPaths,\n} from '@murumets-ee/content/resolve'\nimport type { ToolkitApp } from '@murumets-ee/core'\nimport type { SecurityContext } from '@murumets-ee/entity'\nimport { getEntityTitleField } from '@murumets-ee/entity'\nimport { QueryClient } from '@murumets-ee/entity/query'\nimport { eq, inArray } from 'drizzle-orm'\nimport { Menu } from './entity.js'\nimport type { MenuResolveDeps, MenuRow } from './get-menu.js'\nimport { column } from './internal/columns.js'\n\n/**\n * Elevated resolver — the publish/trash filters apply regardless of the\n * checker, so this grants reach, never visibility of unpublished rows. See the\n * file header.\n */\nconst SYSTEM_CONTEXT = (): SecurityContext => ({\n user: { id: 'system', groups: ['admin'] },\n checker: () => true,\n})\n\n/** Ids per batched title lookup — mirrors content's `CANONICAL_BATCH_SIZE`. */\nconst TITLE_BATCH_SIZE = 500\n\n/**\n * Build the concrete {@link MenuResolveDeps} for an app.\n *\n * Cheap to call per request (it constructs no clients eagerly — each read\n * builds its own `QueryClient`, matching `buildEnumerateDeps`'s per-call shape,\n * so this never depends on plugin boot ORDER).\n */\nexport function buildMenuResolveDeps(app: ToolkitApp): MenuResolveDeps {\n const db = app.db.readOnly\n const canonicalBatch = buildCanonicalPathsBatchDeps(app)\n const { filterPublished } = buildEnumerateDeps(app)\n\n return {\n getMenuRow: async (handle: string): Promise<MenuRow | null> => {\n const client = new QueryClient({\n entity: Menu,\n db,\n logger: app.logger.child({ resolve: 'menu' }),\n contextResolver: SYSTEM_CONTEXT,\n })\n // `publishable()` on `Menu` means this client filters to PUBLISHED rows\n // unconditionally — a draft menu returns nothing, which `getMenu` turns\n // into `null`. No `locale` is passed: the menu entity has no translations\n // and no locale-status table (locale variance lives INSIDE the tree, per\n // D009), so a locale would only cost a pointless translation merge.\n const rows = await client.findMany({\n where: eq(column(client.getTable(), 'handle'), handle),\n limit: 1,\n })\n const row = rows[0]\n if (row === undefined) return null\n return { maxDepth: row.maxDepth, tree: row.tree }\n },\n\n resolveCanonicalPaths: (entityType, ids, locale) =>\n getCanonicalPaths(entityType, ids, locale, canonicalBatch),\n\n filterPublished,\n\n resolveTitles: async (entityType, ids, locale) => {\n const titles = new Map<string, string>()\n if (ids.length === 0) return titles\n // An unregistered entity type yields NO title, so its items are dropped\n // — fail-closed, matching `buildEnumerateDeps`'s own unknown-type branch.\n const entity = app.entities.get(entityType)\n if (entity === undefined) return titles\n\n const titleField = getEntityTitleField(entity)\n // `getEntityTitleField` degrades to the row's own `id` when the entity has\n // no display-able field — a raw UUID is not a menu label. Fail closed and\n // let the item drop, matching this module's own stated posture.\n if (titleField === 'id') return titles\n const client = new QueryClient({\n entity,\n db,\n logger: app.logger.child({ resolve: 'menu-title', entity: entityType }),\n contextResolver: SYSTEM_CONTEXT,\n })\n const idColumn = column(client.getTable(), 'id')\n\n for (let i = 0; i < ids.length; i += TITLE_BATCH_SIZE) {\n const chunk = ids.slice(i, i + TITLE_BATCH_SIZE)\n // `locale` drives `mergeTranslations`, so a translatable title comes\n // back in the requested locale (falling back to the base row's value)\n // — the \"live entity title (locale-merged)\" phase 11 §2 asks for.\n const rows = await client.findMany({\n where: inArray(idColumn, [...chunk]),\n locale,\n limit: chunk.length,\n })\n for (const row of rows) {\n const record: Record<string, unknown> = row\n const id = record.id\n const title = record[titleField]\n if (typeof id === 'string' && typeof title === 'string' && title.length > 0) {\n titles.set(id, title)\n }\n }\n }\n return titles\n },\n\n defaultLocale: getContentConfig().defaultLocale,\n logger: app.logger.child({ resolve: 'menu' }),\n }\n}\n"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EAAI,SAAW,EAAG,OAAO,EAG7B,IAAM,EAAS,EAAI,SAAS,IAAI,CAAU,EAC1C,GAAI,IAAW,IAAA,GAAW,OAAO,EAEjC,IAAM,EAAa,EAAoB,CAAM,EAI7C,GAAI,IAAe,KAAM,OAAO,EAChC,IAAM,EAAS,IAAI,EAAY,CAC7B,SACA,KACA,OAAQ,EAAI,OAAO,MAAM,CAAE,QAAS,aAAc,OAAQ,CAAW,CAAC,EACtE,gBAAiB,CACnB,CAAC,EACK,EAAW,EAAO,EAAO,SAAS,EAAG,IAAI,EAE/C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAI,OAAQ,GAAK,IAAkB,CACrD,IAAM,EAAQ,EAAI,MAAM,EAAG,EAAI,GAAgB,EAIzC,EAAO,MAAM,EAAO,SAAS,CACjC,MAAO,EAAQ,EAAU,CAAC,GAAG,CAAK,CAAC,EACnC,SACA,MAAO,EAAM,MACf,CAAC,EACD,IAAK,IAAM,KAAO,EAAM,CACtB,IAAM,EAAkC,EAClC,EAAK,EAAO,GACZ,EAAQ,EAAO,GACjB,OAAO,GAAO,UAAY,OAAO,GAAU,UAAY,EAAM,OAAS,GACxE,EAAO,IAAI,EAAI,CAAK,CAExB,CACF,CACA,OAAO,CACT,EAEA,cAAe,EAAiB,CAAC,CAAC,cAClC,OAAQ,EAAI,OAAO,MAAM,CAAE,QAAS,MAAO,CAAC,CAC9C,CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ru-CIJipJXJ.mjs","names":[],"sources":["../src/messages/ru.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { _ as validateTreeDepth, a as MAX_ANCHOR_LENGTH, b as menuAcceptsEntityType, c as MAX_MENU_URL_LENGTH, d as MenuLinkValue, f as MenuSchemaOptions, g as measureMenuTree, h as buildMenuTreeSchema, i as LinkValueSchema, l as MenuItem, m as buildMenuItemSchema, n as BlockAnchor, o as MAX_MENU_DEPTH, p as MenuTreeMeasurement, r as DEFAULT_MENU_DEPTH, s as MAX_MENU_TREE_NODES, t as ANCHOR_PATTERN, u as MenuItemSummary, v as MAX_MENU_ENTITY_TYPE_WHITELIST, x as normalizeMenuEntityTypes, y as MenuEntityTypesSchema } from "./menu-item-schema-xXWZKw7t.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/menu-tree-flatten.d.ts
|
|
4
|
+
/** A menu node's payload without its children — structure lives on the flat node. */
|
|
5
|
+
type MenuNodeData = Omit<MenuItem, 'children'>;
|
|
6
|
+
/** One row of the flattened, DND-annotated tree. */
|
|
7
|
+
interface FlatMenuNode {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
/** Owning node's id, or `null` for a root row. */
|
|
10
|
+
readonly parentId: string | null;
|
|
11
|
+
/** 0-based nesting level (see the module header's depth convention). */
|
|
12
|
+
readonly depth: number;
|
|
13
|
+
/** Position among the row's siblings. */
|
|
14
|
+
readonly index: number;
|
|
15
|
+
/**
|
|
16
|
+
* How many direct children the node has. Carried on the row (rather than
|
|
17
|
+
* derived from the list) so it stays correct while a drag has temporarily
|
|
18
|
+
* lifted the node's descendants out of the sortable list.
|
|
19
|
+
*/
|
|
20
|
+
readonly childCount: number;
|
|
21
|
+
/** The item itself, minus `children`. */
|
|
22
|
+
readonly data: MenuNodeData;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Flatten a nested menu tree into document order.
|
|
26
|
+
*
|
|
27
|
+
* Recursive rather than iterative, deliberately: the input is an
|
|
28
|
+
* ALREADY-NORMALISED tree (`normalizeMenuTree` bounds it to
|
|
29
|
+
* {@link MAX_MENU_DEPTH} levels and 500 nodes before it ever reaches the
|
|
30
|
+
* client), so there is no hostile-payload stack-depth exposure here — unlike
|
|
31
|
+
* `measureMenuTree`, which parses raw JSONB and is iterative for exactly that
|
|
32
|
+
* reason.
|
|
33
|
+
*/
|
|
34
|
+
declare function flattenMenuTree(items: readonly MenuItem[]): FlatMenuNode[];
|
|
35
|
+
/**
|
|
36
|
+
* Rebuild a nested tree from a flat list, honouring each row's `parentId`.
|
|
37
|
+
*
|
|
38
|
+
* A row whose `parentId` names no row in the list is promoted to the ROOT
|
|
39
|
+
* rather than dropped — silently losing a node on a whole-tree save is the one
|
|
40
|
+
* failure mode this editor must never have (it is the same reason
|
|
41
|
+
* `normalizeMenuTree` counts what it refuses). Cycles cannot arise from the
|
|
42
|
+
* editor's own operations: {@link projectDrop} only ever assigns a parent that
|
|
43
|
+
* appears EARLIER in the list.
|
|
44
|
+
*/
|
|
45
|
+
declare function buildMenuTree(flat: readonly FlatMenuNode[]): MenuItem[];
|
|
46
|
+
/** How many indentation steps a horizontal drag offset represents. */
|
|
47
|
+
declare function getDragDepth(offsetX: number, indentation: number): number;
|
|
48
|
+
/** Number of levels a subtree occupies, counting the node itself (leaf = 1). */
|
|
49
|
+
declare function subtreeHeight(item: MenuItem): number;
|
|
50
|
+
/**
|
|
51
|
+
* The deepest 0-based depth a dragged subtree may land at.
|
|
52
|
+
*
|
|
53
|
+
* Converts the menu's 1-based `maxDepth` column (also hard-capped at the
|
|
54
|
+
* absolute {@link MAX_MENU_DEPTH} — the column is a plain number and a stale
|
|
55
|
+
* row could hold anything) and then reserves room for the dragged subtree's own
|
|
56
|
+
* height, so dropping a 2-level branch can't push its children past the cap.
|
|
57
|
+
* Never negative: an already-too-deep subtree is pinned to the root rather than
|
|
58
|
+
* made undraggable.
|
|
59
|
+
*/
|
|
60
|
+
declare function depthCapForDrag(menuMaxDepth: number, draggedHeight: number): number;
|
|
61
|
+
/** Every transitive descendant id of `parentId` in a flat list. */
|
|
62
|
+
declare function collectDescendantIds(flat: readonly FlatMenuNode[], parentId: string): Set<string>;
|
|
63
|
+
/**
|
|
64
|
+
* Drop every row that has a COLLAPSED ancestor — the rendered subset of the
|
|
65
|
+
* flat list.
|
|
66
|
+
*
|
|
67
|
+
* Collapse is UI-only state (it never touches the saved tree), but it does
|
|
68
|
+
* change which rows exist as sortables. The editor therefore stashes the hidden
|
|
69
|
+
* rows at drag start and re-appends them when rebuilding the tree, so a
|
|
70
|
+
* collapsed branch can never be lost by a drag. Because collapsing hides ALL of
|
|
71
|
+
* a node's children, the stashed rows keep their relative order within their
|
|
72
|
+
* parent and there are no visible siblings to interleave with.
|
|
73
|
+
*/
|
|
74
|
+
declare function hideCollapsedRows(flat: readonly FlatMenuNode[], collapsed: ReadonlySet<string>): readonly FlatMenuNode[];
|
|
75
|
+
/** Input for {@link projectDrop}. */
|
|
76
|
+
interface ProjectDropInput {
|
|
77
|
+
/** The flat list AS CURRENTLY ORDERED (the dragged row already moved). */
|
|
78
|
+
readonly items: readonly FlatMenuNode[];
|
|
79
|
+
/** Id of the row being projected — normally the drag source. */
|
|
80
|
+
readonly activeId: string;
|
|
81
|
+
/** Depth the pointer is asking for (initial depth + horizontal drag steps). */
|
|
82
|
+
readonly requestedDepth: number;
|
|
83
|
+
/** Deepest legal 0-based depth for this drag — see {@link depthCapForDrag}. */
|
|
84
|
+
readonly depthCap: number;
|
|
85
|
+
}
|
|
86
|
+
/** Result of {@link projectDrop}. */
|
|
87
|
+
interface ProjectedDrop {
|
|
88
|
+
/** The depth the row will actually land at. */
|
|
89
|
+
readonly depth: number;
|
|
90
|
+
/** The parent the row will land under (`null` = root). */
|
|
91
|
+
readonly parentId: string | null;
|
|
92
|
+
/**
|
|
93
|
+
* `true` when the MENU's `maxDepth` was the binding constraint — i.e. the
|
|
94
|
+
* user asked to go deeper and only the menu cap said no. The ordinary
|
|
95
|
+
* structural limit ("you can't be more than one level below the row above")
|
|
96
|
+
* does NOT set this: that is normal drag feedback, and toasting on it would
|
|
97
|
+
* fire on nearly every drag.
|
|
98
|
+
*/
|
|
99
|
+
readonly clampedByMaxDepth: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Project a row's new depth + parent from the depth the pointer is asking for.
|
|
103
|
+
*
|
|
104
|
+
* Adapted from dnd-kit's `getProjection` (see the module header). Rules:
|
|
105
|
+
*
|
|
106
|
+
* - the row above sets the structural ceiling — you may be at most one level
|
|
107
|
+
* deeper than it, and never deeper than your own current depth + 1;
|
|
108
|
+
* - the row below sets the floor — you may not be shallower than it, or it
|
|
109
|
+
* would be orphaned mid-drag;
|
|
110
|
+
* - the first row is always at the root (nothing to nest under);
|
|
111
|
+
* - the menu's own cap is applied on top of all of the above.
|
|
112
|
+
*/
|
|
113
|
+
declare function projectDrop({
|
|
114
|
+
items,
|
|
115
|
+
activeId,
|
|
116
|
+
requestedDepth,
|
|
117
|
+
depthCap
|
|
118
|
+
}: ProjectDropInput): ProjectedDrop;
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/menu-tree-normalize.d.ts
|
|
121
|
+
/** One entity target a menu item points at — the `resolveMenuItemSummaries` input shape. */
|
|
122
|
+
interface MenuEntityRef {
|
|
123
|
+
entity: string;
|
|
124
|
+
id: string;
|
|
125
|
+
}
|
|
126
|
+
/** Result of {@link normalizeMenuTree}. */
|
|
127
|
+
interface NormalizedMenuTree {
|
|
128
|
+
/** The stored tree, narrowed to `MenuItem[]`. */
|
|
129
|
+
items: MenuItem[];
|
|
130
|
+
/**
|
|
131
|
+
* How many stored nodes were REFUSED — malformed shape, or past one of the
|
|
132
|
+
* hard bounds. An entire refused subtree counts as ONE (we stop at the
|
|
133
|
+
* refusal point rather than descending into it to count more).
|
|
134
|
+
*
|
|
135
|
+
* Non-zero means a whole-tree save would persist those removals, so the
|
|
136
|
+
* editor must warn before writing.
|
|
137
|
+
*/
|
|
138
|
+
dropped: number;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Narrow a raw `menu.tree` JSONB value to `MenuItem[]`.
|
|
142
|
+
*
|
|
143
|
+
* @param value the raw column value (untrusted shape).
|
|
144
|
+
*/
|
|
145
|
+
declare function normalizeMenuTree(value: unknown): NormalizedMenuTree;
|
|
146
|
+
/**
|
|
147
|
+
* Every distinct entity target in a (already-normalised, therefore bounded)
|
|
148
|
+
* tree, in document order.
|
|
149
|
+
*
|
|
150
|
+
* Deduplicated: two menu items pointing at the same page produce ONE
|
|
151
|
+
* `resolveMenuItemSummaries` ref, so the batched read never scales with item
|
|
152
|
+
* count. The output feeds `resolveMenuItemSummaries(app, refs)`, whose result
|
|
153
|
+
* map is keyed the same `${entity}:${id}` way.
|
|
154
|
+
*/
|
|
155
|
+
declare function collectMenuEntityRefs(items: readonly MenuItem[]): MenuEntityRef[];
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/menu-tree-ops.d.ts
|
|
158
|
+
/**
|
|
159
|
+
* Outcome of a structural operation.
|
|
160
|
+
*
|
|
161
|
+
* `noop` — nothing to do (already at the edge of its sibling list, at the root,
|
|
162
|
+
* or the id isn't in the tree). `max-depth` — the move is legal structurally but
|
|
163
|
+
* would nest deeper than the menu allows; the caller surfaces a toast, the same
|
|
164
|
+
* way a drag that exceeds `maxDepth` clamps with one (phase 09 §3).
|
|
165
|
+
*/
|
|
166
|
+
type TreeOpResult = {
|
|
167
|
+
readonly ok: true;
|
|
168
|
+
readonly tree: MenuItem[];
|
|
169
|
+
} | {
|
|
170
|
+
readonly ok: false;
|
|
171
|
+
readonly reason: 'noop' | 'max-depth';
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Move an item one slot up (`delta: -1`) or down (`delta: 1`) WITHIN its
|
|
175
|
+
* sibling list, carrying its subtree. Never changes nesting — that is
|
|
176
|
+
* {@link indentMenuItem} / {@link outdentMenuItem}'s job, so ⌥↑/⌥↓ and ⌥←/⌥→
|
|
177
|
+
* stay orthogonal (an item at the top of its list does NOT silently escape to
|
|
178
|
+
* the parent level; the user asks for that explicitly).
|
|
179
|
+
*/
|
|
180
|
+
declare function moveMenuItem(items: readonly MenuItem[], id: string, delta: -1 | 1): TreeOpResult;
|
|
181
|
+
/**
|
|
182
|
+
* Make an item the LAST CHILD of its previous sibling (WordPress / Drupal
|
|
183
|
+
* indent semantics). Refuses when it has no previous sibling, or when the moved
|
|
184
|
+
* subtree's own height would push it past the menu's `maxDepth`.
|
|
185
|
+
*/
|
|
186
|
+
declare function indentMenuItem(items: readonly MenuItem[], id: string, menuMaxDepth: number, currentLevel?: number): TreeOpResult;
|
|
187
|
+
/**
|
|
188
|
+
* Move an item OUT of its parent, landing immediately after that parent in the
|
|
189
|
+
* grandparent's list. A root item has nowhere to go (`noop`).
|
|
190
|
+
*
|
|
191
|
+
* Following siblings stay where they are — they are NOT adopted by the
|
|
192
|
+
* outdented item (WordPress does adopt them; that behaviour surprises more
|
|
193
|
+
* often than it helps, and an explicit indent is one keystroke away).
|
|
194
|
+
*/
|
|
195
|
+
declare function outdentMenuItem(items: readonly MenuItem[], id: string): TreeOpResult;
|
|
196
|
+
/** Depth-first lookup by id, or `null` when the tree holds no such item. */
|
|
197
|
+
declare function findMenuItem(items: readonly MenuItem[], id: string): MenuItem | null;
|
|
198
|
+
/** One entity target — the `{ entity, id }` half of an `entity`-kind link. */
|
|
199
|
+
interface MenuEntityTarget {
|
|
200
|
+
/** Entity NAME (`page`, `article`, …), matched exactly. */
|
|
201
|
+
readonly entity: string;
|
|
202
|
+
/** Row id (a uuid), matched exactly. */
|
|
203
|
+
readonly id: string;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Where one matching item sits in the tree — everything a caller needs to
|
|
207
|
+
* describe (or re-place) it without walking the tree a second time.
|
|
208
|
+
*/
|
|
209
|
+
interface MenuItemMatch {
|
|
210
|
+
/**
|
|
211
|
+
* The LIVE node, subtree included — reference-identical to the one in the
|
|
212
|
+
* input tree, so it can be handed straight to {@link replaceMenuItem} /
|
|
213
|
+
* {@link removeMenuItem}.
|
|
214
|
+
*/
|
|
215
|
+
readonly item: MenuItem;
|
|
216
|
+
/** Owning node's id, or `null` when the match is a root item. */
|
|
217
|
+
readonly parentId: string | null;
|
|
218
|
+
/** 0-based position among its siblings. */
|
|
219
|
+
readonly index: number;
|
|
220
|
+
/** 0-based nesting level, matching `flattenMenuTree`'s convention. */
|
|
221
|
+
readonly depth: number;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Every item in the tree whose link points at `target` — "is entity X in this
|
|
225
|
+
* menu, and if so where" (plan/routing phase 10 §4).
|
|
226
|
+
*
|
|
227
|
+
* Returns ALL matches, in document order: nothing stops an author from linking
|
|
228
|
+
* the same page twice (once under a header, once at the root), and a Meta panel
|
|
229
|
+
* that assumed exactly one would silently edit the wrong item — or claim the
|
|
230
|
+
* entity isn't in the menu after removing only the first copy. A matched item's
|
|
231
|
+
* own subtree is still searched, so a self-referential nest reports both.
|
|
232
|
+
*
|
|
233
|
+
* Only `entity`-kind links can match; `url` / `email` links and `header` items
|
|
234
|
+
* are skipped. An `anchor` on the link does NOT affect matching — `/pricing`
|
|
235
|
+
* and `/pricing#plans` are the same page in the same menu.
|
|
236
|
+
*
|
|
237
|
+
* Whether a match sits under a header is one lookup away:
|
|
238
|
+
* `parentId !== null && findMenuItem(items, parentId)?.kind === 'header'`.
|
|
239
|
+
*
|
|
240
|
+
* Pure in-memory traversal of an ALREADY-LOADED tree — no I/O, so this is not a
|
|
241
|
+
* fan-out surface. Recursive like the rest of this module, which is safe for the
|
|
242
|
+
* same reason: menu trees are bounded to {@link MAX_MENU_TREE_NODES} nodes and
|
|
243
|
+
* {@link MAX_MENU_DEPTH} levels at the write boundary (and re-bounded by
|
|
244
|
+
* `normalizeMenuTree` on the read side), so there is no hostile-payload stack
|
|
245
|
+
* exposure here.
|
|
246
|
+
*/
|
|
247
|
+
declare function findMenuItemsByTarget(items: readonly MenuItem[], target: MenuEntityTarget): MenuItemMatch[];
|
|
248
|
+
/** Remove an item and its entire subtree. Unknown ids return an equal tree. */
|
|
249
|
+
declare function removeMenuItem(items: readonly MenuItem[], id: string): MenuItem[];
|
|
250
|
+
/**
|
|
251
|
+
* Swap the item with `id` for `next`, in place — the inspector's write path
|
|
252
|
+
* (plan/routing phase 09 §4).
|
|
253
|
+
*
|
|
254
|
+
* The REPLACEMENT is stored whole, children included: the inspector always
|
|
255
|
+
* hands back the node it was given plus one changed field, so its `children`
|
|
256
|
+
* are the live ones. Re-grafting the old children on top would silently
|
|
257
|
+
* override any caller that meant to change them.
|
|
258
|
+
*
|
|
259
|
+
* Unknown ids return an equal tree — an edit for an item that has since been
|
|
260
|
+
* removed is a no-op, never a throw.
|
|
261
|
+
*
|
|
262
|
+
* **`next === item` (reference-identical) is ALSO a no-op**, not just an
|
|
263
|
+
* unknown id — `./item-edits.ts`'s setters already return the SAME object
|
|
264
|
+
* when a field edit changes nothing (e.g. re-picking the anchor already
|
|
265
|
+
* stored), specifically so the editor's `tree !== savedTree` dirty check
|
|
266
|
+
* doesn't fire for it. Treating every id MATCH as "changed" regardless of
|
|
267
|
+
* whether the value actually differs would silently defeat that guarantee
|
|
268
|
+
* one layer up — the whole tree gets a fresh array, and the menu is marked
|
|
269
|
+
* dirty, even though nothing was edited.
|
|
270
|
+
*/
|
|
271
|
+
declare function replaceMenuItem(items: readonly MenuItem[], id: string, next: MenuItem): MenuItem[];
|
|
272
|
+
/**
|
|
273
|
+
* Insert `node` as the next SIBLING of `afterId`, at that anchor's level.
|
|
274
|
+
* Appends to the root when `afterId` is `null` or names no item — an add
|
|
275
|
+
* action must always land somewhere visible, never silently do nothing.
|
|
276
|
+
*/
|
|
277
|
+
declare function insertMenuItem(items: readonly MenuItem[], node: MenuItem, afterId: string | null): MenuItem[];
|
|
278
|
+
//#endregion
|
|
279
|
+
export { ANCHOR_PATTERN, type BlockAnchor, DEFAULT_MENU_DEPTH, type FlatMenuNode, LinkValueSchema, MAX_ANCHOR_LENGTH, MAX_MENU_DEPTH, MAX_MENU_ENTITY_TYPE_WHITELIST, MAX_MENU_TREE_NODES, MAX_MENU_URL_LENGTH, type MenuEntityRef, type MenuEntityTarget, MenuEntityTypesSchema, type MenuItem, type MenuItemMatch, type MenuItemSummary, type MenuLinkValue, type MenuNodeData, type MenuSchemaOptions, type MenuTreeMeasurement, type NormalizedMenuTree, type ProjectDropInput, type ProjectedDrop, type TreeOpResult, buildMenuItemSchema, buildMenuTree, buildMenuTreeSchema, collectDescendantIds, collectMenuEntityRefs, depthCapForDrag, findMenuItem, findMenuItemsByTarget, flattenMenuTree, getDragDepth, hideCollapsedRows, indentMenuItem, insertMenuItem, measureMenuTree, menuAcceptsEntityType, moveMenuItem, normalizeMenuEntityTypes, normalizeMenuTree, outdentMenuItem, projectDrop, removeMenuItem, replaceMenuItem, subtreeHeight, validateTreeDepth };
|
|
280
|
+
//# sourceMappingURL=schema.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.mts","names":[],"sources":["../src/menu-tree-flatten.ts","../src/menu-tree-normalize.ts","../src/menu-tree-ops.ts"],"mappings":";;;AAiI4C;AAAA,KA9EhC,YAAA,GAAe,IAAI,CAAC,QAAA;;UAGf,YAAA;EAAA,SACN,EAAA;EA6FgE;EAAA,SA3FhE,QAAA;EAiGyB;EAAA,SA/FzB,KAAA;EA+F+E;EAAA,SA7F/E,KAAA;EA6F0B;;;;AAAqD;EAArD,SAvF1B,UAAA;EA6GsB;EAAA,SA3GtB,IAAA,EAAM,YAAY;AAAA;;;;;;;;;;;iBAab,eAAA,CAAgB,KAAA,WAAgB,QAAA,KAAa,YAAY;AAkHzE;;;;;;;;;;AAAA,iBAzFgB,aAAA,CAAc,IAAA,WAAe,YAAA,KAAiB,QAAQ;AAqGtE;AAAA,iBArFgB,YAAA,CAAa,OAAA,UAAiB,WAAmB;;iBAMjD,aAAA,CAAc,IAAc,EAAR,QAAQ;;;;;AA2FhB;AAe5B;;;;;iBAvFgB,eAAA,CAAgB,YAAA,UAAsB,aAAqB;;iBAM3D,oBAAA,CAAqB,IAAA,WAAe,YAAA,IAAgB,QAAA,WAAmB,GAAG;;;;;;;;;;;;iBAsB1E,iBAAA,CACd,IAAA,WAAe,YAAA,IACf,SAAA,EAAW,WAAA,oBACD,YAAA;;UAiBK,gBAAA;EA4CkB;EAAA,SA1CxB,KAAA,WAAgB,YAAY;;WAE5B,QAAA;ECpJM;E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M,QAAQ;EF2Cd;EAAA,SEzCA,QAAA;EFyCiB;EAAA,SEvCjB,KAAA;EFsDgB;EAAA,SEpDhB,KAAA;AAAA;;;;;;;;;;;;;;;;;;;AFyDwB;;;;AC5LnC;;iBC8JgB,qBAAA,CACd,KAAA,WAAgB,QAAA,IAChB,MAAA,EAAQ,gBAAA,GACP,aAAA;;iBAkBa,cAAA,CAAe,KAAA,WAAgB,QAAA,IAAY,EAAA,WAAa,QAAQ;AD7KhF;;;;;;;;AAWS;AAkCT;;;;AAAqE;AAoGrE;;;;;;;AAjJA,iBCgNgB,eAAA,CACd,KAAA,WAAgB,QAAA,IAChB,EAAA,UACA,IAAA,EAAM,QAAA,GACL,QAAA;ADnE6E;;;;AC1JhF;AD0JgF,iBC0FhE,cAAA,CACd,KAAA,WAAgB,QAAA,IAChB,IAAA,EAAM,QAAA,EACN,OAAA,kBACC,QAAA"}
|
package/dist/schema.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as e,c as t,d as n,f as r,h as i,i as a,l as o,m as s,n as c,o as l,p as u,r as d,s as f,t as p,u as m}from"./menu-entity-types-BnKnKbif.mjs";function h(e){let t=[],n=(e,r,i)=>{e.forEach((e,a)=>{let{children:o,...s}=e;t.push({id:e.id,parentId:r,depth:i,index:a,childCount:o.length,data:s}),n(o,e.id,i+1)})};return n(e,null,0),t}function g(e){let t=new Map;for(let n of e)t.set(n.id,{...n.data,children:[]});let n=[];for(let r of e){let e=t.get(r.id);if(e===void 0)continue;let i=r.parentId===null?void 0:t.get(r.parentId);i===void 0?n.push(e):i.children.push(e)}return n}function _(e,t){return t<=0?0:Math.round(e/t)}function v(e){let t=0;for(let n of e.children){let e=v(n);e>t&&(t=e)}return t+1}function y(e,t){return Math.max(Math.min(Math.max(Math.trunc(e),1),6)-Math.max(t,1),0)}function b(e,t){let n=new Set([t]);for(let t of e)t.parentId!==null&&n.has(t.parentId)&&n.add(t.id);return n.delete(t),n}function x(e,t){if(t.size===0)return e;let n=new Set,r=[];for(let i of e){if(i.parentId!==null&&(n.has(i.parentId)||t.has(i.parentId))){n.add(i.id);continue}r.push(i)}return r}function S({items:e,activeId:t,requestedDepth:n,depthCap:r}){let i=e.findIndex(e=>e.id===t);if(i===-1)return{depth:0,parentId:null,clampedByMaxDepth:!1};let a=e[i];if(a===void 0)return{depth:0,parentId:null,clampedByMaxDepth:!1};let o=e[i-1],s=e[i+1],c=s===void 0?0:s.depth;if(o===void 0)return{depth:0,parentId:null,clampedByMaxDepth:!1};let l=Math.min(a.depth+1,o.depth+1),u=Math.min(Math.max(Math.min(n,l),c),r);u=Math.min(Math.max(u,0),r);let d=n>r&&r<l;return{depth:u,parentId:C(e,i,u),clampedByMaxDepth:d}}function C(e,t,n){let r=e[t-1];if(n===0||r===void 0)return null;if(n===r.depth)return r.parentId;if(n>r.depth)return r.id;for(let r=t-1;r>=0;r--){let t=e[r];if(t!==void 0&&t.depth===n)return t.parentId}return null}function w(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function T(e,t){if(!w(e))return;let n={};for(let[r,i]of Object.entries(e))t(i)&&(n[r]=i);return n}const E=e=>typeof e==`string`,D=e=>typeof e==`boolean`;function O(e){let t=500,n=0;function r(e,i){if(!Array.isArray(e))return[];let a=e;if(i>6)return n+=a.length,[];let o=[];for(let e of a){if(!w(e)){n++;continue}let a=e.id,s=e.kind;if(typeof a!=`string`||a.length===0){n++;continue}if(s!==`link`&&s!==`header`){n++;continue}let c;if(s===`link`){let t=f.safeParse(e.link);if(!t.success){n++;continue}c=t.data}else if(e.link!==void 0){n++;continue}if(t<=0){n++;continue}t--;let l=T(e.label,E),u=l!==void 0&&Object.keys(l).length>0?l:void 0,d=T(e.enabled,D),p=d!==void 0&&Object.keys(d).length>0?d:void 0;o.push({id:a,kind:s,link:c,label:u??null,enabled:p,newTab:typeof e.newTab==`boolean`?e.newTab:void 0,children:r(e.children,i+1)})}return o}return{items:r(e,1),dropped:n}}function k(e){let t=new Set,n=[];function r(e){for(let i of e){let e=i.link;if(e?.kind===`entity`){let r=`${e.entity}:${e.id}`;t.has(r)||(t.add(r),n.push({entity:e.entity,id:e.id}))}r(i.children)}}return r(e),n}const A={ok:!1,reason:`noop`},j={ok:!1,reason:`max-depth`};function M(e){return Math.min(Math.max(Math.trunc(e),1),6)}function N(e,t,n){let r=e.findIndex(e=>e.id===t);if(r!==-1){let t=r+n;if(t<0||t>=e.length)return A;let i=e.slice(),a=i.splice(r,1);return i.splice(t,0,...a),{ok:!0,tree:i}}return H(e,e=>N(e,t,n))}function P(e,t,n,r=1){let i=e.findIndex(e=>e.id===t);if(i!==-1){if(i===0)return A;let t=e[i-1],a=e[i];if(t===void 0||a===void 0)return A;if(r+1+(v(a)-1)>M(n))return j;let o=e.slice();return o.splice(i,1),o[i-1]={...t,children:[...t.children,a]},{ok:!0,tree:o}}return H(e,e=>P(e,t,n,r+1))}function F(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(r===void 0)continue;let i=r.children.findIndex(e=>e.id===t);if(i!==-1){let t=r.children[i];if(t===void 0)continue;let a=r.children.slice();a.splice(i,1);let o=e.slice();return o[n]={...r,children:a},o.splice(n+1,0,t),{ok:!0,tree:o}}let a=F(r.children,t);if(a.ok){let t=e.slice();return t[n]={...r,children:a.tree},{ok:!0,tree:t}}}return A}function I(e,t){for(let n of e){if(n.id===t)return n;let e=I(n.children,t);if(e!==null)return e}return null}function L(e,t){let n=[],r=(e,i,a)=>{e.forEach((e,o)=>{let s=e.link;s?.kind===`entity`&&s.entity===t.entity&&s.id===t.id&&n.push({item:e,parentId:i,index:o,depth:a}),r(e.children,e.id,a+1)})};return r(e,null,0),n}function R(e,t){let n=[];for(let r of e){if(r.id===t)continue;let e=R(r.children,t);n.push(e===r.children?r:{...r,children:e})}return n.length===e.length&&n.every((t,n)=>t===e[n])?e:n}function z(e,t,n){let r=!1,i=e.map(e=>{if(e.id===t)return n===e?e:(r=!0,n);let i=z(e.children,t,n);return i===e.children?e:(r=!0,{...e,children:i})});return r?i:e}function B(e,t,n){return n===null?[...e,t]:V(e,t,n)??[...e,t]}function V(e,t,n){let r=e.findIndex(e=>e.id===n);if(r!==-1){let n=e.slice();return n.splice(r+1,0,t),n}for(let r=0;r<e.length;r++){let i=e[r];if(i===void 0)continue;let a=V(i.children,t,n);if(a!==null){let t=e.slice();return t[r]={...i,children:a},t}}return null}function H(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(r===void 0)continue;let i=t(r.children);if(i.ok){let t=e.slice();return t[n]={...r,children:i.tree},{ok:!0,tree:t}}if(i.reason===`max-depth`)return i}return A}export{e as ANCHOR_PATTERN,l as DEFAULT_MENU_DEPTH,f as LinkValueSchema,t as MAX_ANCHOR_LENGTH,o as MAX_MENU_DEPTH,p as MAX_MENU_ENTITY_TYPE_WHITELIST,m as MAX_MENU_TREE_NODES,n as MAX_MENU_URL_LENGTH,c as MenuEntityTypesSchema,r as buildMenuItemSchema,g as buildMenuTree,u as buildMenuTreeSchema,b as collectDescendantIds,k as collectMenuEntityRefs,y as depthCapForDrag,I as findMenuItem,L as findMenuItemsByTarget,h as flattenMenuTree,_ as getDragDepth,x as hideCollapsedRows,P as indentMenuItem,B as insertMenuItem,s as measureMenuTree,d as menuAcceptsEntityType,N as moveMenuItem,a as normalizeMenuEntityTypes,O as normalizeMenuTree,F as outdentMenuItem,S as projectDrop,R as removeMenuItem,z as replaceMenuItem,v as subtreeHeight,i as validateTreeDepth};
|
|
2
|
+
//# sourceMappingURL=schema.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.mjs","names":[],"sources":["../src/menu-tree-flatten.ts","../src/menu-tree-normalize.ts","../src/menu-tree-ops.ts"],"sourcesContent":["/**\n * Tree ⇄ flat-list conversion + the indent-to-nest depth projection\n * (plan/routing phase 09 §3).\n *\n * **Why flat.** `@dnd-kit`'s sortable primitive reorders a LIST. An\n * indent-to-nest tree editor therefore renders the tree as ONE flat sortable\n * list annotated with `depth` / `parentId` / `index`, indents each row with\n * CSS, and derives a NEW depth from the drag's horizontal offset. That is\n * dnd-kit's own reference architecture for a sortable tree (`apps/stories/\n * stories/react/Sortable/Tree` in `clauderic/dnd-kit`), and the projection\n * maths below is adapted from its `utilities.ts` — the off-by-one rules for\n * \"how far right must I drag to nest one level deeper\" are subtle enough that\n * deriving them from scratch would be a bug farm.\n *\n * **What we changed vs. the reference.**\n *\n * - Nodes carry a real {@link MenuItem} payload (`kind` / `link` / `label` /\n * `enabled` / `newTab`), not just an id, so `data` is the item MINUS its\n * children — structure lives in `parentId`/`depth` only, and there is never a\n * stale `children` array riding along a flat node.\n * - Depth is capped by the MENU (`maxDepth`, 1..{@link MAX_MENU_DEPTH}), not\n * unbounded, and {@link projectDrop} reports whether that cap was the binding\n * constraint so the editor can toast (\"drops exceeding maxDepth clamp with a\n * toast\", phase 09 §3) — as opposed to the ordinary structural limit, which\n * is normal drag feedback and must NOT toast.\n * - The cap also reserves room for the DRAGGED SUBTREE's own height\n * ({@link depthCapForDrag}): dropping a 2-level branch at the deepest legal\n * row would push its children past the cap.\n *\n * Everything here is pure and DOM-free — the highest-value tests in this\n * surface live against these functions, not against mounted drag machinery.\n * That purity is also why they live in `@murumets-ee/menus` rather than in the\n * editor package that drives them: {@link flattenMenuTree} is the \"indent-\n * flattened tree\" the Meta panel's parent/position selects render too (phase 10\n * §4), and `menus-ui` can't export it to `admin-ui` without an import cycle —\n * see `./menu-tree-ops.ts`'s header for the full reasoning.\n *\n * ## Depth convention\n *\n * `depth` is **0-based** here (root rows are `0`), matching dnd-kit's reference\n * and making the CSS indent a plain `depth * indentation`. The menu's own\n * `maxDepth` column, `measureMenuTree()` and `./menu-tree-ops.ts` are\n * **1-based** (a flat tree measures `1`). {@link depthCapForDrag} is the single\n * conversion point.\n *\n * @module\n */\n\nimport { MAX_MENU_DEPTH, type MenuItem } from './menu-item-schema.js'\n\n/** A menu node's payload without its children — structure lives on the flat node. */\nexport type MenuNodeData = Omit<MenuItem, 'children'>\n\n/** One row of the flattened, DND-annotated tree. */\nexport interface FlatMenuNode {\n readonly id: string\n /** Owning node's id, or `null` for a root row. */\n readonly parentId: string | null\n /** 0-based nesting level (see the module header's depth convention). */\n readonly depth: number\n /** Position among the row's siblings. */\n readonly index: number\n /**\n * How many direct children the node has. Carried on the row (rather than\n * derived from the list) so it stays correct while a drag has temporarily\n * lifted the node's descendants out of the sortable list.\n */\n readonly childCount: number\n /** The item itself, minus `children`. */\n readonly data: MenuNodeData\n}\n\n/**\n * Flatten a nested menu tree into document order.\n *\n * Recursive rather than iterative, deliberately: the input is an\n * ALREADY-NORMALISED tree (`normalizeMenuTree` bounds it to\n * {@link MAX_MENU_DEPTH} levels and 500 nodes before it ever reaches the\n * client), so there is no hostile-payload stack-depth exposure here — unlike\n * `measureMenuTree`, which parses raw JSONB and is iterative for exactly that\n * reason.\n */\nexport function flattenMenuTree(items: readonly MenuItem[]): FlatMenuNode[] {\n const out: FlatMenuNode[] = []\n\n const walk = (nodes: readonly MenuItem[], parentId: string | null, depth: number): void => {\n nodes.forEach((node, index) => {\n const { children, ...data } = node\n out.push({ id: node.id, parentId, depth, index, childCount: children.length, data })\n walk(children, node.id, depth + 1)\n })\n }\n\n walk(items, null, 0)\n return out\n}\n\n/**\n * Rebuild a nested tree from a flat list, honouring each row's `parentId`.\n *\n * A row whose `parentId` names no row in the list is promoted to the ROOT\n * rather than dropped — silently losing a node on a whole-tree save is the one\n * failure mode this editor must never have (it is the same reason\n * `normalizeMenuTree` counts what it refuses). Cycles cannot arise from the\n * editor's own operations: {@link projectDrop} only ever assigns a parent that\n * appears EARLIER in the list.\n */\nexport function buildMenuTree(flat: readonly FlatMenuNode[]): MenuItem[] {\n const nodes = new Map<string, MenuItem>()\n for (const row of flat) nodes.set(row.id, { ...row.data, children: [] })\n\n const roots: MenuItem[] = []\n for (const row of flat) {\n const node = nodes.get(row.id)\n if (node === undefined) continue\n const parent = row.parentId === null ? undefined : nodes.get(row.parentId)\n if (parent === undefined) roots.push(node)\n else parent.children.push(node)\n }\n return roots\n}\n\n/** How many indentation steps a horizontal drag offset represents. */\nexport function getDragDepth(offsetX: number, indentation: number): number {\n if (indentation <= 0) return 0\n return Math.round(offsetX / indentation)\n}\n\n/** Number of levels a subtree occupies, counting the node itself (leaf = 1). */\nexport function subtreeHeight(item: MenuItem): number {\n let deepest = 0\n for (const child of item.children) {\n const height = subtreeHeight(child)\n if (height > deepest) deepest = height\n }\n return deepest + 1\n}\n\n/**\n * The deepest 0-based depth a dragged subtree may land at.\n *\n * Converts the menu's 1-based `maxDepth` column (also hard-capped at the\n * absolute {@link MAX_MENU_DEPTH} — the column is a plain number and a stale\n * row could hold anything) and then reserves room for the dragged subtree's own\n * height, so dropping a 2-level branch can't push its children past the cap.\n * Never negative: an already-too-deep subtree is pinned to the root rather than\n * made undraggable.\n */\nexport function depthCapForDrag(menuMaxDepth: number, draggedHeight: number): number {\n const levels = Math.min(Math.max(Math.trunc(menuMaxDepth), 1), MAX_MENU_DEPTH)\n return Math.max(levels - Math.max(draggedHeight, 1), 0)\n}\n\n/** Every transitive descendant id of `parentId` in a flat list. */\nexport function collectDescendantIds(flat: readonly FlatMenuNode[], parentId: string): Set<string> {\n const ids = new Set<string>([parentId])\n // One forward pass: the list is in document order, so a node's parent is\n // always already in `ids` by the time the node is visited.\n for (const row of flat) {\n if (row.parentId !== null && ids.has(row.parentId)) ids.add(row.id)\n }\n ids.delete(parentId)\n return ids\n}\n\n/**\n * Drop every row that has a COLLAPSED ancestor — the rendered subset of the\n * flat list.\n *\n * Collapse is UI-only state (it never touches the saved tree), but it does\n * change which rows exist as sortables. The editor therefore stashes the hidden\n * rows at drag start and re-appends them when rebuilding the tree, so a\n * collapsed branch can never be lost by a drag. Because collapsing hides ALL of\n * a node's children, the stashed rows keep their relative order within their\n * parent and there are no visible siblings to interleave with.\n */\nexport function hideCollapsedRows(\n flat: readonly FlatMenuNode[],\n collapsed: ReadonlySet<string>,\n): readonly FlatMenuNode[] {\n if (collapsed.size === 0) return flat\n const hidden = new Set<string>()\n const out: FlatMenuNode[] = []\n // Forward pass: document order guarantees a parent is classified before its\n // children are visited.\n for (const row of flat) {\n if (row.parentId !== null && (hidden.has(row.parentId) || collapsed.has(row.parentId))) {\n hidden.add(row.id)\n continue\n }\n out.push(row)\n }\n return out\n}\n\n/** Input for {@link projectDrop}. */\nexport interface ProjectDropInput {\n /** The flat list AS CURRENTLY ORDERED (the dragged row already moved). */\n readonly items: readonly FlatMenuNode[]\n /** Id of the row being projected — normally the drag source. */\n readonly activeId: string\n /** Depth the pointer is asking for (initial depth + horizontal drag steps). */\n readonly requestedDepth: number\n /** Deepest legal 0-based depth for this drag — see {@link depthCapForDrag}. */\n readonly depthCap: number\n}\n\n/** Result of {@link projectDrop}. */\nexport interface ProjectedDrop {\n /** The depth the row will actually land at. */\n readonly depth: number\n /** The parent the row will land under (`null` = root). */\n readonly parentId: string | null\n /**\n * `true` when the MENU's `maxDepth` was the binding constraint — i.e. the\n * user asked to go deeper and only the menu cap said no. The ordinary\n * structural limit (\"you can't be more than one level below the row above\")\n * does NOT set this: that is normal drag feedback, and toasting on it would\n * fire on nearly every drag.\n */\n readonly clampedByMaxDepth: boolean\n}\n\n/**\n * Project a row's new depth + parent from the depth the pointer is asking for.\n *\n * Adapted from dnd-kit's `getProjection` (see the module header). Rules:\n *\n * - the row above sets the structural ceiling — you may be at most one level\n * deeper than it, and never deeper than your own current depth + 1;\n * - the row below sets the floor — you may not be shallower than it, or it\n * would be orphaned mid-drag;\n * - the first row is always at the root (nothing to nest under);\n * - the menu's own cap is applied on top of all of the above.\n */\nexport function projectDrop({\n items,\n activeId,\n requestedDepth,\n depthCap,\n}: ProjectDropInput): ProjectedDrop {\n const activeIndex = items.findIndex((row) => row.id === activeId)\n if (activeIndex === -1) return { depth: 0, parentId: null, clampedByMaxDepth: false }\n\n const current = items[activeIndex]\n if (current === undefined) return { depth: 0, parentId: null, clampedByMaxDepth: false }\n const previous = items[activeIndex - 1]\n const next = items[activeIndex + 1]\n const minDepth = next === undefined ? 0 : next.depth\n\n // No previous row → this row IS the root, full stop — there is nothing\n // above to nest under, so depth is 0 regardless of what a deeper following\n // row's floor would otherwise ask for. A HARD override, not something that\n // flows through the general ceiling/floor/cap formula below: that formula\n // lets the floor win over the STRUCTURAL ceiling when they conflict (see\n // its own comment), and \"first row\" is exactly a structural-ceiling-of-zero\n // case — folding it into the same formula would let a deeper following row\n // pull the first item away from the root it must stay pinned to.\n if (previous === undefined) {\n return { depth: 0, parentId: null, clampedByMaxDepth: false }\n }\n\n const structuralMax = Math.min(current.depth + 1, previous.depth + 1)\n\n // Explicit precedence, three bounds applied in order — NOT a single merged\n // \"allowedMax\" clamped against the floor, which silently drops the floor\n // whenever the structural ceiling and the floor conflict (an ORDINARY\n // cross-depth-boundary drag, not just a since-reduced-`maxDepth` edge case:\n // it happens whenever the row above is shallower than the row below, which\n // a drag crosses constantly).\n //\n // 1. The structural ceiling first (never more than one level deeper than\n // your own current depth, or than the row above) — the per-gesture\n // ratchet `structuralMax` encodes.\n // 2. The floor next (never shallower than the row below, or it would be\n // orphaned) — this can push ABOVE the structural ceiling when the two\n // conflict, which is the intended resolution: prefer not orphaning a\n // row over honouring the ratchet for one frame.\n // 3. The menu's own absolute depth cap LAST, unconditionally — the one\n // bound that always wins over both of the above.\n let depth = Math.min(Math.max(Math.min(requestedDepth, structuralMax), minDepth), depthCap)\n // Hard invariant regardless of the above: never produce a depth outside\n // [0, depthCap]. The editor's own save-time `validateTreeDepth` pre-flight\n // should be unreachable, and this is what keeps it that way.\n depth = Math.min(Math.max(depth, 0), depthCap)\n\n const clampedByMaxDepth = requestedDepth > depthCap && depthCap < structuralMax\n\n return { depth, parentId: resolveParentId(items, activeIndex, depth), clampedByMaxDepth }\n}\n\n/**\n * Which node owns a row that lands at `depth`, given the rows before it.\n *\n * Verbatim in spirit from dnd-kit's `getParentId`: same depth as the row above\n * → same parent; one deeper → the row above IS the parent; shallower → walk\n * back to the nearest row at that depth and borrow its parent.\n */\nfunction resolveParentId(\n items: readonly FlatMenuNode[],\n activeIndex: number,\n depth: number,\n): string | null {\n const previous = items[activeIndex - 1]\n if (depth === 0 || previous === undefined) return null\n if (depth === previous.depth) return previous.parentId\n if (depth > previous.depth) return previous.id\n\n for (let i = activeIndex - 1; i >= 0; i--) {\n const row = items[i]\n if (row !== undefined && row.depth === depth) return row.parentId\n }\n return null\n}\n","/**\n * Read-side narrowing for a stored `menu.tree` column, plus the entity-ref\n * collection the editor page needs for `resolveMenuItemSummaries()`.\n *\n * **Why this exists.** `field.json()` types its column as `JsonValue`, so the\n * row `fetchEntityById(Menu, id)` returns hands us an untyped blob. Casting it\n * straight to `MenuItem[]` would need an `as unknown as` (CLAUDE.md: don't) and\n * would also be a lie — the column is only *usually* well-formed. Rows written\n * before `menuTreeValidation()` existed, hand-edited rows, and rows restored\n * from an older dump can all violate the shape, and the editor is exactly the\n * tool you reach for when they do. So this walks the raw value ONCE and returns\n * a properly-typed tree.\n *\n * **Deliberately tolerant, and deliberately NOT `getMenu`.** `getMenu` is the\n * public render path: it also applies the per-locale `enabled` filter, the\n * publish gate and the per-menu `maxDepth` clamp, because a visitor must not\n * see a hidden or unpublished item. The editor is the opposite case — it must\n * show *everything* that is stored, including items hidden in the current\n * locale and items nested deeper than the menu's own `maxDepth` (that is the\n * state you opened the editor to fix). The only things dropped here are nodes\n * whose shape cannot be represented as a `MenuItem` at all.\n *\n * **Bounded** (CLAUDE.md \"no unbounded fan-out\"): at most\n * {@link MAX_MENU_TREE_NODES} nodes are materialised and recursion stops at\n * {@link MAX_MENU_DEPTH}, regardless of what the column contains — so a\n * hand-edited row can't turn a page render into unbounded work or a stack\n * overflow. Whatever is refused is COUNTED and returned, never silently\n * swallowed: the caller logs it, and the editor surfaces it before a save\n * would persist the removal.\n *\n * **Why it lives in `@murumets-ee/menus`.** It was a `@murumets-ee/menus-ui`\n * internal until PR12, when the Meta panel's Menus section (`admin-ui`) needed\n * the same narrowing to turn a `menu` row's `tree` column into a `MenuItem[]`.\n * `menus-ui` depends on `admin-ui`, so exporting it from there would close an\n * `admin-ui → menus-ui → admin-ui` import cycle — same reasoning (and same\n * move) as `./menu-tree-ops.ts`.\n *\n * It pulls `LinkValueSchema` — and therefore zod — and nothing else, so it is\n * client-safe and rides the `./schema` subpath alongside the tree operations.\n *\n * @module\n */\n\nimport {\n LinkValueSchema,\n MAX_MENU_DEPTH,\n MAX_MENU_TREE_NODES,\n type MenuItem,\n type MenuLinkValue,\n} from './menu-item-schema.js'\n\n/** One entity target a menu item points at — the `resolveMenuItemSummaries` input shape. */\nexport interface MenuEntityRef {\n entity: string\n id: string\n}\n\n/** Result of {@link normalizeMenuTree}. */\nexport interface NormalizedMenuTree {\n /** The stored tree, narrowed to `MenuItem[]`. */\n items: MenuItem[]\n /**\n * How many stored nodes were REFUSED — malformed shape, or past one of the\n * hard bounds. An entire refused subtree counts as ONE (we stop at the\n * refusal point rather than descending into it to count more).\n *\n * Non-zero means a whole-tree save would persist those removals, so the\n * editor must warn before writing.\n */\n dropped: number\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\n/**\n * Keep only the entries whose value passes `predicate`. Locale KEYS are not\n * checked against the app's configured locale set on purpose: the set can\n * change after a tree is written, and dropping a label for a locale that was\n * just disabled would destroy authored text on the next save. An out-of-set key\n * is instead rejected loudly by `menuTreeValidation()` when the editor saves.\n */\nfunction filterMap<T>(\n value: unknown,\n predicate: (candidate: unknown) => candidate is T,\n): Record<string, T> | undefined {\n if (!isPlainObject(value)) return undefined\n const out: Record<string, T> = {}\n for (const [key, entry] of Object.entries(value)) {\n if (predicate(entry)) out[key] = entry\n }\n return out\n}\n\nconst isString = (value: unknown): value is string => typeof value === 'string'\nconst isBoolean = (value: unknown): value is boolean => typeof value === 'boolean'\n\n/**\n * Narrow a raw `menu.tree` JSONB value to `MenuItem[]`.\n *\n * @param value the raw column value (untrusted shape).\n */\nexport function normalizeMenuTree(value: unknown): NormalizedMenuTree {\n let budget = MAX_MENU_TREE_NODES\n let dropped = 0\n\n function walk(raw: unknown, depth: number): MenuItem[] {\n if (!Array.isArray(raw)) return []\n // `Array.isArray` narrows `unknown` to `any[]`; re-binding through a\n // `readonly unknown[]` annotation keeps every element typed as `unknown`.\n const rawNodes: readonly unknown[] = raw\n if (depth > MAX_MENU_DEPTH) {\n // Past the absolute cap the whole level goes, counted once per node so\n // the editor's warning is proportional to what it lost.\n dropped += rawNodes.length\n return []\n }\n\n const out: MenuItem[] = []\n for (const node of rawNodes) {\n if (!isPlainObject(node)) {\n dropped++\n continue\n }\n\n const id = node.id\n const kind = node.kind\n if (typeof id !== 'string' || id.length === 0) {\n dropped++\n continue\n }\n if (kind !== 'link' && kind !== 'header') {\n dropped++\n continue\n }\n\n let link: MenuLinkValue | undefined\n if (kind === 'link') {\n // Re-validate the stored target through the SAME schema the write path\n // uses — notably the `sanitizeHref` protocol allowlist, so a row that\n // predates (or bypassed) that gate can't hand the editor a\n // `javascript:` href to render.\n const parsed = LinkValueSchema.safeParse(node.link)\n if (!parsed.success) {\n dropped++\n continue\n }\n link = parsed.data\n } else if (node.link !== undefined) {\n // A header carrying a link target is a shape violation the type can't\n // represent — drop it rather than render a half-defined node.\n dropped++\n continue\n }\n\n if (budget <= 0) {\n dropped++\n continue\n }\n budget--\n\n // `filterMap` returns `{}` (not `undefined`) when the stored map WAS an\n // object but every entry failed the predicate (e.g. `{ en: 42 }`, a\n // non-string junk value) — `?? null`/`undefined` below wouldn't catch\n // that, since `{}` is truthy. An all-junk map must collapse the same\n // way a genuinely absent one does: for `label`, `{}` surviving into a\n // save would fail the write-side schema's \"a header needs at least one\n // locale key\" check with a server error instead of this module's own\n // documented tolerant behaviour; for `enabled`, `{}` is a harmless but\n // needless stored key (absent already means \"visible everywhere\").\n const rawLabel = filterMap(node.label, isString)\n const label =\n rawLabel !== undefined && Object.keys(rawLabel).length > 0 ? rawLabel : undefined\n const rawEnabled = filterMap(node.enabled, isBoolean)\n const enabled =\n rawEnabled !== undefined && Object.keys(rawEnabled).length > 0 ? rawEnabled : undefined\n out.push({\n id,\n kind,\n link,\n // `null` = \"use the live entity title per locale\" (the storage default).\n label: label ?? null,\n enabled,\n newTab: typeof node.newTab === 'boolean' ? node.newTab : undefined,\n children: walk(node.children, depth + 1),\n })\n }\n return out\n }\n\n return { items: walk(value, 1), dropped }\n}\n\n/**\n * Every distinct entity target in a (already-normalised, therefore bounded)\n * tree, in document order.\n *\n * Deduplicated: two menu items pointing at the same page produce ONE\n * `resolveMenuItemSummaries` ref, so the batched read never scales with item\n * count. The output feeds `resolveMenuItemSummaries(app, refs)`, whose result\n * map is keyed the same `${entity}:${id}` way.\n */\nexport function collectMenuEntityRefs(items: readonly MenuItem[]): MenuEntityRef[] {\n const seen = new Set<string>()\n const refs: MenuEntityRef[] = []\n\n function walk(nodes: readonly MenuItem[]): void {\n for (const node of nodes) {\n const link = node.link\n if (link?.kind === 'entity') {\n const key = `${link.entity}:${link.id}`\n if (!seen.has(key)) {\n seen.add(key)\n refs.push({ entity: link.entity, id: link.id })\n }\n }\n walk(node.children)\n }\n }\n\n walk(items)\n return refs\n}\n","/**\n * Pure structural operations on a `MenuItem[]` tree — the keyboard / item-menu\n * half of the editor (plan/routing phase 09 §3).\n *\n * **Why they live HERE, in `@murumets-ee/menus`.** They were written as\n * `@murumets-ee/menus-ui` internals for the tree editor (PR10), but the Meta\n * panel's Menus section (`@murumets-ee/admin-ui`, PR12) needs the same\n * insert/remove/replace primitives to toggle one entity's membership in a menu.\n * `menus-ui` depends on `admin-ui`, so exporting them from there would have made\n * `admin-ui → menus-ui → admin-ui` a real import cycle. `@murumets-ee/menus`\n * depends on neither, so it is the one home both consumers can reach — and these\n * functions are pure TS with no React, no DOM and no `@murumets-ee/core`, so the\n * client-safe `./schema` subpath re-exports them without pulling a server graph\n * along (see that module's header).\n *\n * **Why these exist separately from the drag path.** Phase 09 §3 requires a\n * full keyboard fallback (\"the Drupal show-row-weights lesson: DND-only editors\n * fail accessibility\"), and this repo has already learned that dnd-kit's own\n * `KeyboardSensor` is the wrong tool for it — `packages/blocks/src/editor/\n * interactions/dnd-provider.tsx` deliberately drops it (its Enter/Space\n * activation swallowed the editor's ⌘Enter chord) in favour of real move\n * buttons. So reordering by keyboard is REAL BUTTONS + shortcuts calling these\n * functions, not a drag protocol — which also makes the whole reorder surface\n * unit-testable with no DOM and no drag machinery.\n *\n * Every function is immutable: the input tree is never mutated, and untouched\n * subtrees are shared by reference (so React's identity checks stay cheap).\n *\n * ## Depth convention\n *\n * `maxDepth` here is the menu's own **1-based** column (a flat tree is depth 1),\n * matching `measureMenuTree` / `validateTreeDepth` in `./menu-item-schema.ts`.\n * The flat DND view in `./menu-tree-flatten.ts` uses 0-based depths — see its\n * module header.\n *\n * @module\n */\n\nimport { MAX_MENU_DEPTH, MAX_MENU_TREE_NODES, type MenuItem } from './menu-item-schema.js'\nimport { subtreeHeight } from './menu-tree-flatten.js'\n\n/**\n * Outcome of a structural operation.\n *\n * `noop` — nothing to do (already at the edge of its sibling list, at the root,\n * or the id isn't in the tree). `max-depth` — the move is legal structurally but\n * would nest deeper than the menu allows; the caller surfaces a toast, the same\n * way a drag that exceeds `maxDepth` clamps with one (phase 09 §3).\n */\nexport type TreeOpResult =\n | { readonly ok: true; readonly tree: MenuItem[] }\n | { readonly ok: false; readonly reason: 'noop' | 'max-depth' }\n\nconst NOOP: TreeOpResult = { ok: false, reason: 'noop' }\nconst TOO_DEEP: TreeOpResult = { ok: false, reason: 'max-depth' }\n\n/** The effective 1-based nesting cap: the menu's own column, hard-bounded. */\nfunction effectiveMaxDepth(menuMaxDepth: number): number {\n return Math.min(Math.max(Math.trunc(menuMaxDepth), 1), MAX_MENU_DEPTH)\n}\n\n/**\n * Move an item one slot up (`delta: -1`) or down (`delta: 1`) WITHIN its\n * sibling list, carrying its subtree. Never changes nesting — that is\n * {@link indentMenuItem} / {@link outdentMenuItem}'s job, so ⌥↑/⌥↓ and ⌥←/⌥→\n * stay orthogonal (an item at the top of its list does NOT silently escape to\n * the parent level; the user asks for that explicitly).\n */\nexport function moveMenuItem(items: readonly MenuItem[], id: string, delta: -1 | 1): TreeOpResult {\n const index = items.findIndex((item) => item.id === id)\n if (index !== -1) {\n const target = index + delta\n if (target < 0 || target >= items.length) return NOOP\n const next = items.slice()\n const moved = next.splice(index, 1)\n next.splice(target, 0, ...moved)\n return { ok: true, tree: next }\n }\n\n return recurse(items, (children) => moveMenuItem(children, id, delta))\n}\n\n/**\n * Make an item the LAST CHILD of its previous sibling (WordPress / Drupal\n * indent semantics). Refuses when it has no previous sibling, or when the moved\n * subtree's own height would push it past the menu's `maxDepth`.\n */\nexport function indentMenuItem(\n items: readonly MenuItem[],\n id: string,\n menuMaxDepth: number,\n currentLevel = 1,\n): TreeOpResult {\n const index = items.findIndex((item) => item.id === id)\n if (index !== -1) {\n if (index === 0) return NOOP\n const previous = items[index - 1]\n const moved = items[index]\n if (previous === undefined || moved === undefined) return NOOP\n\n // The moved node lands one level deeper; its own deepest descendant lands\n // `subtreeHeight - 1` below that.\n const deepestLevel = currentLevel + 1 + (subtreeHeight(moved) - 1)\n if (deepestLevel > effectiveMaxDepth(menuMaxDepth)) return TOO_DEEP\n\n const next = items.slice()\n next.splice(index, 1)\n next[index - 1] = { ...previous, children: [...previous.children, moved] }\n return { ok: true, tree: next }\n }\n\n return recurse(items, (children) => indentMenuItem(children, id, menuMaxDepth, currentLevel + 1))\n}\n\n/**\n * Move an item OUT of its parent, landing immediately after that parent in the\n * grandparent's list. A root item has nowhere to go (`noop`).\n *\n * Following siblings stay where they are — they are NOT adopted by the\n * outdented item (WordPress does adopt them; that behaviour surprises more\n * often than it helps, and an explicit indent is one keystroke away).\n */\nexport function outdentMenuItem(items: readonly MenuItem[], id: string): TreeOpResult {\n for (let i = 0; i < items.length; i++) {\n const parent = items[i]\n if (parent === undefined) continue\n\n const childIndex = parent.children.findIndex((child) => child.id === id)\n if (childIndex !== -1) {\n const moved = parent.children[childIndex]\n if (moved === undefined) continue\n const remaining = parent.children.slice()\n remaining.splice(childIndex, 1)\n const next = items.slice()\n next[i] = { ...parent, children: remaining }\n next.splice(i + 1, 0, moved)\n return { ok: true, tree: next }\n }\n\n const deeper = outdentMenuItem(parent.children, id)\n if (deeper.ok) {\n const next = items.slice()\n next[i] = { ...parent, children: deeper.tree }\n return { ok: true, tree: next }\n }\n }\n return NOOP\n}\n\n/** Depth-first lookup by id, or `null` when the tree holds no such item. */\nexport function findMenuItem(items: readonly MenuItem[], id: string): MenuItem | null {\n for (const item of items) {\n if (item.id === id) return item\n const found = findMenuItem(item.children, id)\n if (found !== null) return found\n }\n return null\n}\n\n/** One entity target — the `{ entity, id }` half of an `entity`-kind link. */\nexport interface MenuEntityTarget {\n /** Entity NAME (`page`, `article`, …), matched exactly. */\n readonly entity: string\n /** Row id (a uuid), matched exactly. */\n readonly id: string\n}\n\n/**\n * Where one matching item sits in the tree — everything a caller needs to\n * describe (or re-place) it without walking the tree a second time.\n */\nexport interface MenuItemMatch {\n /**\n * The LIVE node, subtree included — reference-identical to the one in the\n * input tree, so it can be handed straight to {@link replaceMenuItem} /\n * {@link removeMenuItem}.\n */\n readonly item: MenuItem\n /** Owning node's id, or `null` when the match is a root item. */\n readonly parentId: string | null\n /** 0-based position among its siblings. */\n readonly index: number\n /** 0-based nesting level, matching `flattenMenuTree`'s convention. */\n readonly depth: number\n}\n\n/**\n * Every item in the tree whose link points at `target` — \"is entity X in this\n * menu, and if so where\" (plan/routing phase 10 §4).\n *\n * Returns ALL matches, in document order: nothing stops an author from linking\n * the same page twice (once under a header, once at the root), and a Meta panel\n * that assumed exactly one would silently edit the wrong item — or claim the\n * entity isn't in the menu after removing only the first copy. A matched item's\n * own subtree is still searched, so a self-referential nest reports both.\n *\n * Only `entity`-kind links can match; `url` / `email` links and `header` items\n * are skipped. An `anchor` on the link does NOT affect matching — `/pricing`\n * and `/pricing#plans` are the same page in the same menu.\n *\n * Whether a match sits under a header is one lookup away:\n * `parentId !== null && findMenuItem(items, parentId)?.kind === 'header'`.\n *\n * Pure in-memory traversal of an ALREADY-LOADED tree — no I/O, so this is not a\n * fan-out surface. Recursive like the rest of this module, which is safe for the\n * same reason: menu trees are bounded to {@link MAX_MENU_TREE_NODES} nodes and\n * {@link MAX_MENU_DEPTH} levels at the write boundary (and re-bounded by\n * `normalizeMenuTree` on the read side), so there is no hostile-payload stack\n * exposure here.\n */\nexport function findMenuItemsByTarget(\n items: readonly MenuItem[],\n target: MenuEntityTarget,\n): MenuItemMatch[] {\n const out: MenuItemMatch[] = []\n\n const walk = (nodes: readonly MenuItem[], parentId: string | null, depth: number): void => {\n nodes.forEach((node, index) => {\n const link = node.link\n if (link?.kind === 'entity' && link.entity === target.entity && link.id === target.id) {\n out.push({ item: node, parentId, index, depth })\n }\n walk(node.children, node.id, depth + 1)\n })\n }\n\n walk(items, null, 0)\n return out\n}\n\n/** Remove an item and its entire subtree. Unknown ids return an equal tree. */\nexport function removeMenuItem(items: readonly MenuItem[], id: string): MenuItem[] {\n const out: MenuItem[] = []\n for (const item of items) {\n if (item.id === id) continue\n const children = removeMenuItem(item.children, id)\n out.push(children === item.children ? item : { ...item, children })\n }\n // Preserve reference identity when nothing changed anywhere in this branch,\n // so React can skip re-rendering untouched subtrees.\n return out.length === items.length && out.every((item, i) => item === items[i])\n ? (items as MenuItem[])\n : out\n}\n\n/**\n * Swap the item with `id` for `next`, in place — the inspector's write path\n * (plan/routing phase 09 §4).\n *\n * The REPLACEMENT is stored whole, children included: the inspector always\n * hands back the node it was given plus one changed field, so its `children`\n * are the live ones. Re-grafting the old children on top would silently\n * override any caller that meant to change them.\n *\n * Unknown ids return an equal tree — an edit for an item that has since been\n * removed is a no-op, never a throw.\n *\n * **`next === item` (reference-identical) is ALSO a no-op**, not just an\n * unknown id — `./item-edits.ts`'s setters already return the SAME object\n * when a field edit changes nothing (e.g. re-picking the anchor already\n * stored), specifically so the editor's `tree !== savedTree` dirty check\n * doesn't fire for it. Treating every id MATCH as \"changed\" regardless of\n * whether the value actually differs would silently defeat that guarantee\n * one layer up — the whole tree gets a fresh array, and the menu is marked\n * dirty, even though nothing was edited.\n */\nexport function replaceMenuItem(\n items: readonly MenuItem[],\n id: string,\n next: MenuItem,\n): MenuItem[] {\n let changed = false\n const out = items.map((item) => {\n if (item.id === id) {\n if (next === item) return item\n changed = true\n return next\n }\n const children = replaceMenuItem(item.children, id, next)\n if (children === item.children) return item\n changed = true\n return { ...item, children }\n })\n // Preserve reference identity when this branch holds nothing that changed,\n // so React can skip re-rendering untouched subtrees.\n return changed ? out : (items as MenuItem[])\n}\n\n/**\n * Insert `node` as the next SIBLING of `afterId`, at that anchor's level.\n * Appends to the root when `afterId` is `null` or names no item — an add\n * action must always land somewhere visible, never silently do nothing.\n */\nexport function insertMenuItem(\n items: readonly MenuItem[],\n node: MenuItem,\n afterId: string | null,\n): MenuItem[] {\n if (afterId === null) return [...items, node]\n const inserted = insertAfter(items, node, afterId)\n return inserted ?? [...items, node]\n}\n\nfunction insertAfter(\n items: readonly MenuItem[],\n node: MenuItem,\n afterId: string,\n): MenuItem[] | null {\n const index = items.findIndex((item) => item.id === afterId)\n if (index !== -1) {\n const next = items.slice()\n next.splice(index + 1, 0, node)\n return next\n }\n for (let i = 0; i < items.length; i++) {\n const item = items[i]\n if (item === undefined) continue\n const children = insertAfter(item.children, node, afterId)\n if (children !== null) {\n const next = items.slice()\n next[i] = { ...item, children }\n return next\n }\n }\n return null\n}\n\n/**\n * Apply `fn` to each item's children until one reports success, rebuilding only\n * the branch that changed.\n *\n * A `noop`/`max-depth` result keeps the scan going. That is safe because item\n * ids are unique: once the target has been found and refused, no later sibling\n * can match it, so the remaining scan simply returns the same refusal.\n */\nfunction recurse(\n items: readonly MenuItem[],\n fn: (children: readonly MenuItem[]) => TreeOpResult,\n): TreeOpResult {\n for (let i = 0; i < items.length; i++) {\n const item = items[i]\n if (item === undefined) continue\n const result = fn(item.children)\n if (result.ok) {\n const next = items.slice()\n next[i] = { ...item, children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ACT,CACA,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAAK,CACrC,IAAM,EAAO,EAAM,GACnB,GAAI,IAAS,IAAA,GAAW,SACxB,IAAM,EAAW,EAAY,EAAK,SAAU,EAAM,CAAO,EACzD,GAAI,IAAa,KAAM,CACrB,IAAM,EAAO,EAAM,MAAM,EAEzB,MADA,GAAK,GAAK,CAAE,GAAG,EAAM,UAAS,EACvB,CACT,CACF,CACA,OAAO,IACT,CAUA,SAAS,EACP,EACA,EACc,CACd,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAAK,CACrC,IAAM,EAAO,EAAM,GACnB,GAAI,IAAS,IAAA,GAAW,SACxB,IAAM,EAAS,EAAG,EAAK,QAAQ,EAC/B,GAAI,EAAO,GAAI,CACb,IAAM,EAAO,EAAM,MAAM,EAEzB,MADA,GAAK,GAAK,CAAE,GAAG,EAAM,SAAU,EAAO,IAAK,EACpC,CAAE,GAAI,GAAM,KAAM,CAAK,CAChC,CACA,GAAI,EAAO,SAAW,YAAa,OAAO,CAC5C,CACA,OAAO,CACT"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@murumets-ee/menus",
|
|
3
|
+
"version": "0.37.0",
|
|
4
|
+
"license": "Elastic-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.mts",
|
|
9
|
+
"import": "./dist/index.mjs"
|
|
10
|
+
},
|
|
11
|
+
"./schema": {
|
|
12
|
+
"types": "./dist/schema.d.mts",
|
|
13
|
+
"import": "./dist/schema.mjs"
|
|
14
|
+
},
|
|
15
|
+
"./admin": {
|
|
16
|
+
"types": "./dist/admin.d.mts",
|
|
17
|
+
"import": "./dist/admin.mjs"
|
|
18
|
+
},
|
|
19
|
+
"./resolve": {
|
|
20
|
+
"types": "./dist/resolve.d.mts",
|
|
21
|
+
"import": "./dist/resolve.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./i18n": {
|
|
24
|
+
"types": "./dist/i18n.d.mts",
|
|
25
|
+
"import": "./dist/i18n.mjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"drizzle-orm": "^0.45.2",
|
|
33
|
+
"zod": "^3.24.1",
|
|
34
|
+
"@murumets-ee/blocks": "0.37.0",
|
|
35
|
+
"@murumets-ee/content": "0.37.0",
|
|
36
|
+
"@murumets-ee/core": "0.37.0",
|
|
37
|
+
"@murumets-ee/entity": "0.37.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^20.19.42",
|
|
41
|
+
"server-only": "^0.0.1",
|
|
42
|
+
"tsdown": "^0.22.2",
|
|
43
|
+
"typescript": "^5.7.3",
|
|
44
|
+
"vitest": "^2.1.8",
|
|
45
|
+
"@murumets-ee/db": "0.37.0"
|
|
46
|
+
},
|
|
47
|
+
"typeCoverage": {
|
|
48
|
+
"atLeast": 100
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsdown && cp -r src/messages dist/messages",
|
|
52
|
+
"dev": "tsdown --watch",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"test:watch": "vitest",
|
|
55
|
+
"test:integration": "vitest run --config vitest.integration.config.ts"
|
|
56
|
+
}
|
|
57
|
+
}
|