import { FC, ReactElement, ReactNode } from "react"; import { createRouter } from "radix3"; import { CompDoc } from "../../../base/global/content-editor"; import { IContent, MContent, MPage } from "../../../utils/types/general"; import { IItem, MItem } from "../../../utils/types/item"; import { FNCompDef } from "../../../utils/types/meta-fn"; import { PRASI_COMPONENT } from "../../../utils/types/render"; import { IRoot } from "../../../utils/types/root"; import { LSite } from "../../live/logic/global"; import { ISection } from "../../../utils/types/section"; import { IText } from "../../../utils/types/text"; import { clientStartSync } from "../../../utils/sync/client"; export type WithRequired = T & { [P in K]-?: T[P] }; export type NodeMeta = { meta: ItemMeta; idx: number }; export type ItemMeta = { mitem?: MContent; item: IContent; parent_id: string; indexedScope: Record; parent_comp?: WithRequired & { item: IItem }; parent_prop?: ItemMeta; scope?: any; className?: string; elprop?: any; depth: number; memoize?: { Local: FC; PassProp: FC; }; render: () => void; comp?: { id: string; mcomp?: MItem; propval?: any; propvis?: Record; child_ids: Record; }; }; export const EditorGlobal = { /** ui */ mode: "" as "desktop" | "mobile", sync: null as unknown as ReturnType, status: "init" as | "init" | "loading" | "reload" | "ready" | "not-found" | "error" | "tree-rebuild", focused: "", pendingRebuild: false, localReloading: {} as Record, manager: { page: false, site: false, comp: false, compActionLabel: "Pick", compCallback: (comp: any) => {}, compPreviewRendered: new Set(), }, script: { siteActive: false, siteTypes: {}, prop: null as null | { name: string; mode: | "instance" | "master-value" | "master-option" | "master-visible" | "master-gen"; }, toolbar: null as ReactNode, active: false, type: "js" as "js" | "css" | "html", db: null as any, api: null as any, onClose: undefined as undefined | (() => void), doEdit: null as null | ((newval: string, all?: boolean) => Promise), }, item: { active: "", activeOriginalId: "", hover: "", sideHover: false, selectMode: "single" as "single" | "multi", selection: [] as string[], copy: { mode: "single" as "single" | "multiple", }, }, preventTreeScroll: false, softRender: { tree: () => {}, page: () => {}, side: () => {}, addEl: () => {}, topR: () => {}, all() { this.tree(); this.page(); this.side(); this.addEl(); this.topR(); }, }, /** read-only */ session: { id: "", data: { user: { id: "", username: "" } } }, lsite: null as any, site: { id: "", api_url: "", api_prasi: { port: "", db: "", }, responsive: "all" as "all" | "mobile-only" | "desktop-only", domain: "", name: "", js: "", js_compiled: "", } as LSite, layout: { section: null as null | ISection, content: null as null | IItem | IText, }, site_dts: "", page: null as null | { id: string; name: string; url: string; content_tree: IRoot; js: string; effects?: Record; }, /** content tree */ treeFlat: [] as { id: string; parent: string; text: string; data: { meta: ItemMeta; idx: number }; }[], treeFlatTemp: [] as { id: string; parent: string; text: string; data: { meta: ItemMeta; idx: number }; }[], treePending: null as null | Promise, treeMeta: {} as Record, cachedParentID: {} as Record, compInstance: {} as Record>, /** components */ comp: null as null | { id: string; instance_id?: string; last: { comp_id?: string; active_id: string; active_oid?: string; instance_id?: string; props?: Record; }[]; props: Record; }, comps: { pending: {} as Record>, resolve: {} as Record void>, doc: {} as Record, }, compProp: { backToInstance: false, edit: false, inherit: true, }, compDirectEdit: false, compLoading: {} as Record, /** routing */ pagePreload: {} as Record, route: createRouter<{ id: string; url: string; }>(), /** write-only */ mpage: null as null | MPage, mpageLoaded: null as null | ((mpage: MPage) => void), /** connection */ ws: null as null | WebSocket, wsPing: -1, wsPingTs: 0, wsPingInterval: null as any, wsRetry: { fast: false, localIP: false, disabled: false, reconnecting: false, }, ui: { loading: null as null | ReactElement, preload: null as null | ReactElement, notfound: null as null | ReactElement, error: null as null | ReactElement, }, }; export type PG = typeof EditorGlobal & { render: () => void };