alinea
Version:
[](https://npmjs.org/package/alinea) [](https://packagephobia.com/result?p=alinea)
60 lines (58 loc) • 1.79 kB
JavaScript
import {
atomFamily
} from "../../chunks/chunk-ZHH24SIG.js";
import {
atom
} from "../../chunks/chunk-OBOPLPUQ.js";
import {
require_dataloader
} from "../../chunks/chunk-ICLGQ53P.js";
import {
__toESM
} from "../../chunks/chunk-U5RRZUYZ.js";
// src/dashboard/atoms/EntrySummaryAtoms.ts
var import_dataloader = __toESM(require_dataloader(), 1);
import { View } from "alinea/core";
import { Entry } from "alinea/core/Entry";
import { Cursor } from "alinea/core/pages/Cursor";
import { EntrySummaryRow } from "../view/entry/EntrySummary.js";
import { configAtom } from "./DashboardAtoms.js";
import { entryRevisionAtoms, graphAtom } from "./DbAtoms.js";
var entrySummaryLoaderAtom = atom(async (get) => {
const { preferDraft: drafts } = await get(graphAtom);
const { schema } = get(configAtom);
const selection = View.getSelection(
schema,
"summaryRow",
EntrySummaryRow.selection()
);
return new import_dataloader.default(async (ids) => {
const res = /* @__PURE__ */ new Map();
let cursor = Entry().where(Entry.entryId.isIn(ids));
cursor = new Cursor.Find({
...cursor[Cursor.Data],
select: selection
});
const entries = await drafts.find(cursor);
for (const entry of entries)
res.set(entry.entryId, entry);
return ids.map((id) => res.get(id));
});
});
var entrySummaryAtoms = atomFamily((id) => {
return atom(async (get) => {
const loader = await get(entrySummaryLoaderAtom);
const summary = await loader.clear(id).load(id);
if (!summary)
return;
get(entryRevisionAtoms(summary.i18nId));
if (summary?.parents)
for (const parent of summary.parents)
get(entryRevisionAtoms(parent.i18nId));
return summary;
});
});
export {
entrySummaryAtoms,
entrySummaryLoaderAtom
};