wip fix script api url
This commit is contained in:
parent
67b0e50afb
commit
ed714bbc0c
|
|
@ -49,7 +49,6 @@ export const syncHandler: WebSocketHandler<WSData> = {
|
|||
|
||||
conn.user_id = user_id;
|
||||
conn.user = await db.user.findFirst({ where: { id: user_id } });
|
||||
|
||||
let conf = await user.conf.getOrCreate(user_id);
|
||||
if (site_id) {
|
||||
const newconf = await loadSitePage(user_id, site_id, page_id);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import { page, useGlobal } from "web-utils";
|
||||
import { EdBase } from "../../nova/ed/ed-base";
|
||||
import { EDGlobal } from "../../nova/ed/logic/ed-global";
|
||||
import { Loading } from "../../utils/ui/loading";
|
||||
import { initSync } from "wasm-gzip";
|
||||
import { edInitSync } from "../../nova/ed/logic/ed-sync";
|
||||
import { Loading } from "../../utils/ui/loading";
|
||||
|
||||
export default page({
|
||||
url: "/ed/:site_id/:page_id",
|
||||
|
|
@ -11,9 +10,9 @@ export default page({
|
|||
const p = useGlobal(EDGlobal, "EDITOR");
|
||||
|
||||
if (!edInitSync(p)) {
|
||||
return <Loading note="init sync" />;
|
||||
return <Loading note="connecting-ws" />;
|
||||
}
|
||||
|
||||
|
||||
return <EdBase />;
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export const EdBase = () => {
|
|||
edUndoManager(p);
|
||||
|
||||
if (p.status === "init") {
|
||||
edInit(p)
|
||||
edInit(p);
|
||||
}
|
||||
|
||||
edRoute(p);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { NodeModel } from "@minoru/react-dnd-treeview";
|
||||
import { ReactElement } from "react";
|
||||
import { FC, ReactElement } from "react";
|
||||
import { deepClone } from "web-utils";
|
||||
import { SAction } from "../../../../../srv/ws/sync/actions";
|
||||
import { clientStartSync } from "../../../utils/sync/ws-client";
|
||||
|
|
@ -61,6 +61,10 @@ export type EdMeta = {
|
|||
mcomp: MItem;
|
||||
};
|
||||
el?: ReactElement;
|
||||
memoize?: Record<string, {
|
||||
Local: FC<any>;
|
||||
PassProp: FC<any>;
|
||||
}>;
|
||||
};
|
||||
|
||||
export const EDGlobal = {
|
||||
|
|
@ -75,7 +79,10 @@ export const EDGlobal = {
|
|||
| "ready",
|
||||
sync: null as unknown as Awaited<ReturnType<typeof clientStartSync>>,
|
||||
site: deepClone(EmptySite),
|
||||
script: { siteTypes: {} as Record<string, string> },
|
||||
script: {
|
||||
siteTypes: {} as Record<string, string>,
|
||||
loaded: false,
|
||||
},
|
||||
page: {
|
||||
cur: EmptyPage,
|
||||
doc: null as null | DPage,
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ import { PG } from "./ed-global";
|
|||
import { jscript } from "../../../utils/script/jscript";
|
||||
|
||||
export const edInit = async (p: PG) => {
|
||||
p.status = "ready";
|
||||
|
||||
await init();
|
||||
jscript.init(p.render);
|
||||
p.status = "ready";
|
||||
p.script.loaded = true;
|
||||
p.render();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -91,3 +91,4 @@ export const edRoute = async (p: PG) => {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,8 @@ export const EdApi = () => {
|
|||
className="flex-1 min-h-[26px] flex items-center justify-center"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
|
||||
<svg width="20px" height="20px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.94358 2.25H14.0564C15.8942 2.24998 17.3498 2.24997 18.489 2.40314C19.6614 2.56076 20.6104 2.89288 21.3588 3.64124C22.1071 4.38961 22.4392 5.33856 22.5969 6.51098C22.75 7.65019 22.75 9.10583 22.75 10.9436V13.0564C22.75 14.8942 22.75 16.3498 22.5969 17.489C22.4392 18.6614 22.1071 19.6104 21.3588 20.3588C20.6104 21.1071 19.6614 21.4392 18.489 21.5969C17.3498 21.75 15.8942 21.75 14.0564 21.75H9.94359C8.10583 21.75 6.65019 21.75 5.51098 21.5969C4.33856 21.4392 3.38961 21.1071 2.64124 20.3588C1.89288 19.6104 1.56076 18.6614 1.40314 17.489C1.24997 16.3498 1.24998 14.8942 1.25 13.0564V10.9436C1.24998 9.10582 1.24997 7.65019 1.40314 6.51098C1.56076 5.33856 1.89288 4.38961 2.64124 3.64124C3.38961 2.89288 4.33856 2.56076 5.51098 2.40314C6.65019 2.24997 8.10582 2.24998 9.94358 2.25ZM5.71085 3.88976C4.70476 4.02502 4.12511 4.27869 3.7019 4.7019C3.27869 5.12511 3.02502 5.70476 2.88976 6.71085C2.75159 7.73851 2.75 9.09318 2.75 11V11.25H21.25V11C21.25 9.09318 21.2484 7.73851 21.1102 6.71085C20.975 5.70476 20.7213 5.12511 20.2981 4.7019C19.8749 4.27869 19.2952 4.02502 18.2892 3.88976C17.2615 3.75159 15.9068 3.75 14 3.75H10C8.09318 3.75 6.73851 3.75159 5.71085 3.88976ZM21.25 12.75H2.75V13C2.75 14.9068 2.75159 16.2615 2.88976 17.2892C3.02502 18.2952 3.27869 18.8749 3.7019 19.2981C4.12511 19.7213 4.70476 19.975 5.71085 20.1102C6.73851 20.2484 8.09318 20.25 10 20.25H14C15.9068 20.25 17.2615 20.2484 18.2892 20.1102C19.2952 19.975 19.8749 19.7213 20.2981 19.2981C20.7213 18.8749 20.975 18.2952 21.1102 17.2892C21.2484 16.2615 21.25 14.9068 21.25 13V12.75ZM6 5.75C6.41421 5.75 6.75 6.08579 6.75 6.5V8.5C6.75 8.91421 6.41421 9.25 6 9.25C5.58579 9.25 5.25 8.91421 5.25 8.5V6.5C5.25 6.08579 5.58579 5.75 6 5.75ZM9 5.75C9.41421 5.75 9.75 6.08579 9.75 6.5V8.5C9.75 8.91421 9.41421 9.25 9 9.25C8.58579 9.25 8.25 8.91421 8.25 8.5V6.5C8.25 6.08579 8.58579 5.75 9 5.75ZM12.75 7.5C12.75 7.08579 13.0858 6.75 13.5 6.75H18C18.4142 6.75 18.75 7.08579 18.75 7.5C18.75 7.91421 18.4142 8.25 18 8.25H13.5C13.0858 8.25 12.75 7.91421 12.75 7.5ZM6 14.75C6.41421 14.75 6.75 15.0858 6.75 15.5V17.5C6.75 17.9142 6.41421 18.25 6 18.25C5.58579 18.25 5.25 17.9142 5.25 17.5V15.5C5.25 15.0858 5.58579 14.75 6 14.75ZM9 14.75C9.41421 14.75 9.75 15.0858 9.75 15.5V17.5C9.75 17.9142 9.41421 18.25 9 18.25C8.58579 18.25 8.25 17.9142 8.25 17.5V15.5C8.25 15.0858 8.58579 14.75 9 14.75ZM12.75 16.5C12.75 16.0858 13.0858 15.75 13.5 15.75H18C18.4142 15.75 18.75 16.0858 18.75 16.5C18.75 16.9142 18.4142 17.25 18 17.25H13.5C13.0858 17.25 12.75 16.9142 12.75 16.5Z" fill="currentColor"/>
|
||||
<svg fill="currentColor" width="13px" height="13px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M0 0h16v16H0V0zm2 2v2h12V2H2zm0 4v2h12V6H2zm0 4v4h12v-4H2zm1 2c0-.552.444-1 1-1 .552 0 1 .444 1 1 0 .552-.444 1-1 1-.552 0-1-.444-1-1z" fill-rule="evenodd"/>
|
||||
</svg>`,
|
||||
}}
|
||||
></div>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
import { ReactElement } from "react";
|
||||
import { IContent } from "../../../utils/types/general";
|
||||
import { IItem } from "../../../utils/types/item";
|
||||
import { ISection } from "../../../utils/types/section";
|
||||
import { IText } from "../../../utils/types/text";
|
||||
import { EdMeta } from "../../ed/logic/ed-global";
|
||||
import { EdMeta, PG } from "../../ed/logic/ed-global";
|
||||
|
||||
export const ViewGlobal = {
|
||||
mode: "" as "desktop" | "mobile",
|
||||
|
|
@ -12,6 +9,15 @@ export const ViewGlobal = {
|
|||
meta: {} as Record<string, EdMeta>,
|
||||
entry: [] as string[],
|
||||
bodyCache: null as null | ReactElement,
|
||||
component: {
|
||||
map: {} as PG["comp"]["map"],
|
||||
load: async (id_comp: string) => {},
|
||||
},
|
||||
script: {
|
||||
api_url: "",
|
||||
db: null as any,
|
||||
api: null as any,
|
||||
},
|
||||
view: {
|
||||
hidden: undefined as undefined | ((item: IContent) => boolean),
|
||||
active: undefined as
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
import { VG } from "./global";
|
||||
|
||||
export const preload = async (p: VG, pathname: string) => {
|
||||
//TODO
|
||||
};
|
||||
|
||||
export const extractNavigate = (str: string) => {
|
||||
return [
|
||||
...findBetween(str, `navigate(`, `)`),
|
||||
...findBetween(str, `href = `, `;`),
|
||||
];
|
||||
};
|
||||
|
||||
const findBetween = (text: string, opener: string, closer: string) => {
|
||||
let i = 0;
|
||||
let last = 0;
|
||||
const founds: string[] = [];
|
||||
while (true) {
|
||||
const startIndex = text.indexOf(opener, i);
|
||||
last = i;
|
||||
if (startIndex >= 0) {
|
||||
const char = text[startIndex + opener.length];
|
||||
if (char === '"' || char === "'" || char === "`") {
|
||||
const end = text.indexOf(
|
||||
`${char}${closer}`,
|
||||
startIndex + opener.length + 1
|
||||
);
|
||||
const found = text.substring(startIndex + opener.length + 1, end);
|
||||
i = end + 2 + closer.length;
|
||||
founds.push(found);
|
||||
}
|
||||
}
|
||||
|
||||
if (last === i) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return founds;
|
||||
};
|
||||
|
|
@ -14,5 +14,5 @@ export type VLoad =
|
|||
|
||||
export type VLoadComponent = {
|
||||
map: PG["comp"]["map"];
|
||||
load: (id_comp: string) => void;
|
||||
load: (id_comp: string) => Promise<void>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,10 +4,15 @@ import { ViewGlobal } from "../../logic/global";
|
|||
import { ViewMetaRender } from "./render";
|
||||
import { ViewMetaScript } from "./script";
|
||||
|
||||
export const ViewMeta: FC<{ id: string }> = ({ id }) => {
|
||||
export const ViewMeta: FC<{ id: string; scopeIndex?: Record<string, any> }> = ({
|
||||
id,
|
||||
scopeIndex,
|
||||
}) => {
|
||||
const v = useGlobal(ViewGlobal, "VIEW");
|
||||
|
||||
const meta = v.meta[id];
|
||||
if (!meta) return null;
|
||||
|
||||
const item = meta.item;
|
||||
|
||||
if (item.hidden && v.view.hidden) {
|
||||
|
|
@ -17,8 +22,8 @@ export const ViewMeta: FC<{ id: string }> = ({ id }) => {
|
|||
}
|
||||
|
||||
if (item.adv) {
|
||||
if (item.adv.js) {
|
||||
return <ViewMetaScript v={v} item={item} />;
|
||||
if (item.adv.js && item.adv.jsBuilt) {
|
||||
return <ViewMetaScript v={v} item={item} scopeIndex={scopeIndex} />;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,49 @@
|
|||
import hash_sum from "hash-sum";
|
||||
import { FC } from "react";
|
||||
import { createAPI, createDB } from "../../../../utils/script/init-api";
|
||||
import { IItem } from "../../../../utils/types/item";
|
||||
import { ISection } from "../../../../utils/types/section";
|
||||
import { IText } from "../../../../utils/types/text";
|
||||
import { VG } from "../../logic/global";
|
||||
import { extractNavigate, preload } from "../../logic/router";
|
||||
import { ViewMetaRender } from "./render";
|
||||
import { createLocal } from "./script/create-local";
|
||||
import { createPassProp } from "./script/create-pass-prop";
|
||||
|
||||
export const ViewMetaScript: FC<{
|
||||
v: VG;
|
||||
item: IItem | IText | ISection;
|
||||
}> = ({ item, v }) => {
|
||||
scopeIndex?: Record<string, any>;
|
||||
}> = ({ item, v, scopeIndex }) => {
|
||||
const js = item.adv?.jsBuilt;
|
||||
const meta = v.meta[item.id];
|
||||
if (js && meta) {
|
||||
if (!meta.memoize) {
|
||||
meta.memoize = {};
|
||||
}
|
||||
const memoizeKey = hash_sum(scopeIndex) || "default";
|
||||
if (!meta.memoize[memoizeKey]) {
|
||||
meta.memoize[memoizeKey] = {
|
||||
Local: createLocal(v, item.id, scopeIndex),
|
||||
PassProp: createPassProp(v, item.id, scopeIndex),
|
||||
};
|
||||
}
|
||||
|
||||
const _js = item.adv?.js;
|
||||
if (typeof _js === "string") {
|
||||
const navs = extractNavigate(_js || "");
|
||||
if (navs.length > 0) {
|
||||
navs.map((nav) => preload(v, nav));
|
||||
}
|
||||
}
|
||||
|
||||
if (v.script.api_url) {
|
||||
if (!v.script.db) v.script.db = createDB(v.script.api_url);
|
||||
if (!v.script.api) v.script.api = createAPI(v.script.api_url);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return <ViewMetaRender item={item} v={v} />;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
import { VG } from "../../../logic/global";
|
||||
|
||||
export const createLocal = (
|
||||
v: VG,
|
||||
id: string,
|
||||
scopeIndex?: Record<string, any>
|
||||
) => {
|
||||
return () => {
|
||||
return <></>;
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import { VG } from "../../../logic/global";
|
||||
|
||||
export const createPassProp = (
|
||||
v: VG,
|
||||
id: string,
|
||||
scopeIndex?: Record<string, any>
|
||||
) => {
|
||||
return () => {
|
||||
return <></>;
|
||||
};
|
||||
};
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
import { FC } from "react";
|
||||
import { useGlobal } from "web-utils";
|
||||
import { IContent } from "../../utils/types/general";
|
||||
import { Loading } from "../../utils/ui/loading";
|
||||
import { VG, ViewGlobal } from "./logic/global";
|
||||
import { ViewGlobal } from "./logic/global";
|
||||
import { vInit } from "./logic/init";
|
||||
import { vLoadCode } from "./logic/load-code";
|
||||
import { VLoad, VLoadComponent } from "./logic/types";
|
||||
import { VEntry } from "./render/entry";
|
||||
import { IContent } from "../../utils/types/general";
|
||||
|
||||
export const View: FC<{
|
||||
load: VLoad;
|
||||
|
|
@ -18,16 +18,17 @@ export const View: FC<{
|
|||
hidden?: (item: IContent) => boolean;
|
||||
hover?: { get: (item: IContent) => boolean; set: (id: string) => void };
|
||||
active?: { get: (item: IContent) => boolean; set: (id: string) => void };
|
||||
}> = ({ load, site_id, page_id, bind, hover, active, hidden }) => {
|
||||
}> = ({ load, site_id, page_id, bind, hover, active, hidden, component }) => {
|
||||
const v = useGlobal(ViewGlobal, "VIEW");
|
||||
|
||||
if (hidden) v.view.hidden = hidden;
|
||||
if (hover) v.view.hover = hover;
|
||||
if (active) v.view.active = active;
|
||||
|
||||
if (v.current.page_id !== page_id || v.current.site_id !== site_id) {
|
||||
v.status = "init";
|
||||
}
|
||||
v.component.map = component.map;
|
||||
v.component.load = component.load;
|
||||
|
||||
if (bind) {
|
||||
bind({
|
||||
|
|
@ -48,7 +49,7 @@ export const View: FC<{
|
|||
if (v.status === "load-code" || v.status === "loading-code") {
|
||||
vLoadCode(v);
|
||||
if (v.status === "load-code" || v.status === "loading-code") {
|
||||
return <Loading backdrop={false} note="load" />;
|
||||
return <Loading backdrop={false} note="rendering-view" />;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue