UNPKG

alinea

Version:
86 lines (82 loc) 3.52 kB
import { dist_default } from "../../chunks/chunk-A5O3N2GS.js"; import "../../chunks/chunk-NZLE2WMY.js"; // src/dashboard/pages/ContentView.tsx import { resolveView } from "alinea/core/View"; import { HStack, Icon, Loader } from "alinea/ui"; import IcRoundAddCircle from "alinea/ui/icons/IcRoundAddCircle"; import { useConfig } from "../hook/UseConfig.js"; import { useDashboard } from "../hook/UseDashboard.js"; import { useLocale } from "../hook/UseLocale.js"; import { useNav } from "../hook/UseNav.js"; import { useRoot } from "../hook/UseRoot.js"; import { useWorkspace } from "../hook/UseWorkspace.js"; import { useLocation, useNavigate } from "../util/HashRouter.js"; import { SuspenseBoundary } from "../util/SuspenseBoundary.js"; import { EntryEdit } from "../view/EntryEdit.js"; import { EntryTree } from "../view/EntryTree.js"; import { RootOverview } from "../view/RootOverview.js"; import { SearchBox } from "../view/SearchBox.js"; import { Sidebar } from "../view/Sidebar.js"; import { NewEntry } from "../view/entry/NewEntry.js"; // src/dashboard/pages/ContentView.module.scss var ContentView_module_default = { "root-sidebar": "alinea-ContentView-sidebar", "rootSidebar": "alinea-ContentView-sidebar", "root-create": "alinea-ContentView-create", "rootCreate": "alinea-ContentView-create", "root-create-button": "alinea-ContentView-create-button", "rootCreateButton": "alinea-ContentView-create-button" }; // src/dashboard/pages/ContentView.tsx import { Fragment, jsx, jsxs } from "react/jsx-runtime"; var styles = dist_default(ContentView_module_default); function ContentView({ editor }) { const { views } = useDashboard(); const workspace = useWorkspace(); const root = useRoot(); const locale = useLocale(); const { search } = useLocation(); const EntryView = (editor?.view ? resolveView(views, editor.view) : EntryEdit) ?? EntryEdit; const RootView = (root?.view ? resolveView(views, root.view) : RootOverview) ?? RootOverview; const nav = useNav(); const navigate = useNavigate(); const { schema } = useConfig(); const type = editor && schema[editor.activeVersion.type]; return /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsxs(Sidebar.Tree, { children: [ /* @__PURE__ */ jsx(SearchBox, {}), /* @__PURE__ */ jsx( EntryTree, { selectedId: editor?.activeVersion.id, expanded: editor?.activeVersion.parents } ), /* @__PURE__ */ jsx("div", { className: styles.root.create(), children: /* @__PURE__ */ jsx( "button", { type: "button", className: styles.root.create.button(), onClick: () => navigate( nav.create({ id: editor?.activeVersion.id, workspace: workspace.name, root: root.name }) ), children: /* @__PURE__ */ jsxs(HStack, { center: true, gap: 8, align: "center", children: [ /* @__PURE__ */ jsx(Icon, { icon: IcRoundAddCircle, size: 17 }), /* @__PURE__ */ jsx("span", { children: "Create new" }) ] }) } ) }) ] }), search === "?new" && /* @__PURE__ */ jsx(NewEntry, { parentId: editor?.entryId }), /* @__PURE__ */ jsx(SuspenseBoundary, { name: "content view", fallback: /* @__PURE__ */ jsx(Loader, { absolute: true }), children: type && editor ? /* @__PURE__ */ jsx(EntryView, { type, editor }) : /* @__PURE__ */ jsx(RootView, { root }) }) ] }); } export { ContentView };