UNPKG

nitropage

Version:

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

69 lines (56 loc) 1.61 kB
import { Blueprint, Config } from "#../types"; import { NONE_BLUEPRINT_ID, ROOT_ELEMENT_ID } from "#lib/constants"; export const blueprintEntries = function ( blueprints: Record<string, Blueprint>, ) { return Object.entries(blueprints) .filter(function ([k, v]) { return k !== NONE_BLUEPRINT_ID; }) .sort(function (a, b) { return a[1].title().localeCompare(b[1].title()); }); }; export const blueprintAllowed = function ( declaration: Config, fromBlueprintId?: string | null, targetBlueprintId?: string | null, targetSlotKey?: string, ) { if (fromBlueprintId == null) { return true; } const elBlueprint = declaration.blueprints[fromBlueprintId]; const parentIsRoot = targetBlueprintId === ROOT_ELEMENT_ID; if (elBlueprint.acceptParentType === "root" && !parentIsRoot) { return false; } if (elBlueprint.acceptParentType === "element" && parentIsRoot) { return false; } if (elBlueprint.acceptParent) { if (!targetBlueprintId) return false; if (!elBlueprint.acceptParent!(targetBlueprintId)) return false; } if (targetBlueprintId === ROOT_ELEMENT_ID) { return true; } if (targetBlueprintId == null) { return true; } if (targetSlotKey == null) { return true; } const blueprint = declaration.blueprints[targetBlueprintId]; if (!blueprint.slots) { return true; } if (!blueprint.slots[targetSlotKey]) { return true; } const acceptBlueprint = blueprint.slots[targetSlotKey].acceptBlueprint; if (acceptBlueprint) { return acceptBlueprint(fromBlueprintId); } return true; };