This commit is contained in:
Rizky 2023-10-31 13:50:30 +07:00
parent 568e382fda
commit 3bab393c5d
8 changed files with 44 additions and 121 deletions

View File

@ -36,7 +36,6 @@ model component_group {
id String @id(map: "site_comp_group_id") @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String
shared Boolean @default(false)
code_comp code_comp[]
component component[]
component_site component_site[]
}
@ -224,7 +223,6 @@ model site {
is_deleted Boolean @default(false)
responsive String @default("all")
npm_cache String @default(" ") @db.VarChar
code code[]
component_site component_site[]
npm_site npm_site[]
page page[]
@ -277,43 +275,3 @@ model user {
org_user org_user[]
site site[]
}
model code {
id String @id(map: "code_id") @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String @db.Uuid
id_site String @db.Uuid
use_in_site Boolean
site site @relation(fields: [id_site], references: [id], onDelete: NoAction, onUpdate: NoAction)
code_comp code_comp[]
code_file code_file[]
code_npm code_npm[]
}
model code_comp {
id_code String @db.Uuid
id_comp_group String @db.Uuid
code code @relation(fields: [id_code], references: [id], onDelete: NoAction, onUpdate: NoAction)
component_group component_group @relation(fields: [id_comp_group], references: [id], onDelete: NoAction, onUpdate: NoAction)
@@id([id_code, id_comp_group], map: "code_comp_id_code_id_comp_group")
}
model code_npm {
id String @id(map: "code_npm_id") @default(dbgenerated("gen_random_uuid()")) @db.Uuid
module String
version String
bundled Boolean
import_as Json @default("{\"main\": {\"mode\": \"default\", \"name\": \"\"}, \"names\": []}")
id_code String @db.Uuid
code code @relation(fields: [id_code], references: [id], onDelete: NoAction, onUpdate: NoAction)
}
/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
model code_file {
id String @id(map: "code_src_id") @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String
src String
id_code String @db.Uuid
type String @default("f") @db.Char(1)
code code @relation(fields: [id_code], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "code_src_id_code_fkey")
}

View File

@ -11,6 +11,7 @@ import { EdPopCompGroup } from "./panel/popup/comp/comp-group";
import { EdPopSite } from "./panel/popup/site/site";
import { EdScriptInit } from "./panel/script/monaco/init";
import { EdRight } from "./ed-right";
import { EdPopCode } from "./panel/popup/code/code";
export const EdBase = () => {
const p = useGlobal(EDGlobal, "EDITOR");
@ -45,6 +46,7 @@ export const EdBase = () => {
<EdRight />
</div>
<>
<EdPopCode />
<EdPopSite />
<EdPopCompGroup />
<EdScriptInit />

View File

@ -93,9 +93,6 @@ export const EDGlobal = {
list: {} as Record<string, { comp: EComp; doc: DComp }>,
group: {} as Record<string, Awaited<ReturnType<SAction["comp"]["group"]>>>,
},
code: {
doc: null as null | DCode,
},
ui: {
layout: {
left: parseInt(localStorage.getItem("prasi-layout-left") || "250"),

View File

@ -1,12 +1,42 @@
import { useGlobal } from "web-utils";
import { EDGlobal } from "../../../logic/ed-global";
import { Modal } from "../../../../../utils/ui/modal";
export const EdPopCode = () => {
const p = useGlobal(EDGlobal, "EDITOR");
if (!p.ui.popup.code) {
return null;
}
return <></>;
return (
<Modal
open={p.ui.popup.code.open}
onOpenChange={(open) => {
if (!open) {
p.ui.popup.code.open = false;
p.render();
}
}}
>
<div className={cx("bg-white fixed inset-[50px] bottom-0 flex flex-col inset-0")}>
<div className="border-b flex h-[40px] items-stretch">
<div
className={cx(
"border-r flex items-center px-2 w-[100px] overflow-ellipsis space-x-1",
"cursor-pointer"
)}
>
<div
className="-mt-[2px]"
dangerouslySetInnerHTML={{
__html: `<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M3 2.5C3 2.22386 3.22386 2 3.5 2H11.5C11.7761 2 12 2.22386 12 2.5V13.5C12 13.6818 11.9014 13.8492 11.7424 13.9373C11.5834 14.0254 11.3891 14.0203 11.235 13.924L7.5 11.5896L3.765 13.924C3.61087 14.0203 3.41659 14.0254 3.25762 13.9373C3.09864 13.8492 3 13.6818 3 13.5V2.5ZM4 3V12.5979L6.97 10.7416C7.29427 10.539 7.70573 10.539 8.03 10.7416L11 12.5979V3H4Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg>`,
}}
></div>
<div>Site</div>
</div>
</div>
<iframe
className="flex flex-1"
src="http://localhost:3000/?folder=/site"
></iframe>
</div>
</Modal>
);
};

View File

@ -1,71 +0,0 @@
import { compress } from "wasm-gzip";
import { useGlobal, useLocal } from "web-utils";
import { jscript } from "../../../../utils/script/jscript";
import { EDGlobal } from "../../logic/ed-global";
import { EdUserConn } from "../activity/user-conn";
import { EdMonaco } from "./monaco/monaco";
export const EdScriptSite = () => {
const p = useGlobal(EDGlobal, "EDITOR");
const local = useLocal({ timeout: null as any });
const userOpened = Object.keys(p.activity.page.site?.js || {});
// if (!p.ui.script.site) {
// return null;
// }
return (
<EdMonaco
id="script-site"
type="js"
filename="site.tsx"
header={
userOpened.length > 1 ? (
<div className="border-b px-2 min-h-[35px] flex items-center text-sm bg-orange-600 text-white">
WARNING:
<EdUserConn
client_ids={userOpened.filter((e) => e !== p.user.client_id)}
/>
also open this script. Editing may cause conflicts.
</div>
) : undefined
}
monaco={{
value: p.site.js,
onChange: async (v) => {
if (jscript.build) {
const src = v || "";
const built = await jscript.build("site.tsx", src);
p.site.js = src;
p.site.js_compiled = built;
clearTimeout(local.timeout);
local.timeout = setTimeout(async () => {
await p.sync.site.update(p.site.id, {
js: Buffer.from(compress(src)),
js_compiled: Buffer.from(compress(built)),
});
}, 1000);
}
},
}}
prop={{
types: {
exports: "any",
types: "any",
render: "()=>void",
},
}}
onClose={() => {
// p.ui.script.site = false;
// p.sync.activity(
// { page_id: p.page.cur.id, item_id: "site" },
// "js",
// Activity.Null
// );
// p.render();
}}
/>
);
};

View File

@ -1,8 +1,13 @@
import structuredClone from "@ungap/structured-clone";
import { FC, useState } from "react";
import { createRoot } from "react-dom/client";
import { GlobalContext, defineReact, defineWindow } from "web-utils";
import { siteLoader } from "./site-loader";
if (!("structuredClone" in (window as any))) {
(window as any).structuredClone = structuredClone;
}
const w = window as unknown as {
prasiContext: any;
rootRender: any;

BIN
bun.lockb

Binary file not shown.

View File

@ -24,6 +24,8 @@
"typescript": "^5.0.0"
},
"dependencies": {
"@types/ungap__structured-clone": "^0.3.1",
"@ungap/structured-clone": "^1.2.0",
"brotli-wasm": "^2.0.1",
"fdir": "^6.1.0"
}