UNPKG

nitropage

Version:

A free and open source, extensible visual page builder based on SolidStart.

33 lines (30 loc) 915 B
import { Accessor, createMemo, useContext } from "solid-js"; import { State } from "../../../../../types"; import { StateContext } from "../../../../lib/context/page"; import type { Layout } from "../../../../lib/server/layout"; export const getElementParents = ( state: State | Layout["revision"], id: string, ) => { const childElement = state.elements[id]; if (!childElement.parentSlotId) return; const slot = childElement.parentSlotId ? state.slots[childElement.parentSlotId] : undefined; const element = slot?.parentElementId ? state.elements[slot.parentElementId] : undefined; return { slot, element, }; }; export const useElementParents = ( id: () => string, customState?: Accessor<State | Layout["revision"]>, ) => { const [state] = useContext(StateContext)!; return createMemo(() => getElementParents(customState ? customState() : state, id()), ); };