This commit is contained in:
Rizky 2023-10-30 22:51:33 +07:00
parent e15106866b
commit 568e382fda
12 changed files with 117 additions and 66 deletions

View File

@ -1,52 +1,54 @@
export const SyncActionDefinition = { export const SyncActionDefinition = {
"code": { "code": {
"create": "0", "create": "0",
"load": "1" "list": "1",
"load": "2"
}, },
"site": { "site": {
"list": "2", "list": "3",
"group": "3", "group": "4",
"load": "4", "load": "5",
"update": "5" "update": "6"
}, },
"comp": { "comp": {
"new": "6", "new": "7",
"list": "7", "list": "8",
"group": "8", "group": "9",
"load": "9" "load": "10"
}, },
"page": { "page": {
"list": "10", "list": "11",
"load": "11" "load": "12"
}, },
"yjs": { "yjs": {
"um": "12", "um": "13",
"sv_local": "13", "sv_local": "14",
"diff_local": "14", "diff_local": "15",
"sv_remote": "15" "sv_remote": "16"
}, },
"activity": "16", "activity": "17",
"client": { "client": {
"info": "17" "info": "18"
} }
}; };
export const SyncActionPaths = { export const SyncActionPaths = {
"0": "code.create", "0": "code.create",
"1": "code.load", "1": "code.list",
"2": "site.list", "2": "code.load",
"3": "site.group", "3": "site.list",
"4": "site.load", "4": "site.group",
"5": "site.update", "5": "site.load",
"6": "comp.new", "6": "site.update",
"7": "comp.list", "7": "comp.new",
"8": "comp.group", "8": "comp.list",
"9": "comp.load", "9": "comp.group",
"10": "page.list", "10": "comp.load",
"11": "page.load", "11": "page.list",
"12": "yjs.um", "12": "page.load",
"13": "yjs.sv_local", "13": "yjs.um",
"14": "yjs.diff_local", "14": "yjs.sv_local",
"15": "yjs.sv_remote", "15": "yjs.diff_local",
"16": "activity", "16": "yjs.sv_remote",
"17": "client.info" "17": "activity",
"18": "client.info"
}; };

View File

@ -20,7 +20,8 @@ export type SAction = typeof SyncActions;
export const SyncActions = { export const SyncActions = {
code: { code: {
create: async (id_site: string, name: string) => ({}) as { id: string }, create: async (id_site: string, name: string) => ({}) as { id: string },
load: async (id: string) => ({}) as {}, list: async (id_site: string) => ({}) as { ids: string[] },
load: async (id: string) => ({}) as { bin: Uint8Array } | void,
}, },
site: { site: {
list: async () => list: async () =>

View File

@ -0,0 +1,11 @@
import { SAction } from "../actions";
import { SyncConnection } from "../type";
export const code_list: SAction["code"]["list"] = async function (
this: SyncConnection,
) {
let result = null as unknown as Awaited<
ReturnType<SAction["code"]["list"]>
>;
return result;
}

View File

@ -1,4 +1,5 @@
export * from "./code_create"; export * from "./code_create";
export * from "./code_list";
export * from "./code_load"; export * from "./code_load";
export * from "./site_list"; export * from "./site_list";
export * from "./site_group"; export * from "./site_group";

View File

@ -17,10 +17,10 @@ const start = async () => {
const sw = await registerServiceWorker(); const sw = await registerServiceWorker();
const cacheCurrentPage = () => { const cacheCurrentPage = () => {
const swc = navigator.serviceWorker.controller; const swController = navigator.serviceWorker.controller;
if (swc) { if (swController) {
[location.href, "", "/", "/ed", "/ed/_/_", "/login"].forEach((url) => { [location.href, "", "/", "/ed", "/ed/_/_", "/login"].forEach((url) => {
swc.postMessage({ swController.postMessage({
type: "add-cache", type: "add-cache",
url: url, url: url,
}); });

View File

@ -2,7 +2,7 @@ import { NodeModel } from "@minoru/react-dnd-treeview";
import { ReactElement } from "react"; import { ReactElement } from "react";
import { clientStartSync } from "../../../utils/sync/ws-client"; import { clientStartSync } from "../../../utils/sync/ws-client";
import { IItem, MItem } from "../../../utils/types/item"; import { IItem, MItem } from "../../../utils/types/item";
import { DComp, DPage, IRoot } from "../../../utils/types/root"; import { DCode, DComp, DPage, IRoot } from "../../../utils/types/root";
import { ISection } from "../../../utils/types/section"; import { ISection } from "../../../utils/types/section";
import { IText, MText } from "../../../utils/types/text"; import { IText, MText } from "../../../utils/types/text";
import { SAction } from "../../../../../srv/ws/sync/actions"; import { SAction } from "../../../../../srv/ws/sync/actions";
@ -17,23 +17,6 @@ export const EmptySite = {
js_compiled: "", js_compiled: "",
}; };
type CODE_MODULE_NAME = string;
type CODE_FILE_PATH = string;
export const EmptyCode = {
id: "",
name: "",
use_as_main: false,
npm: {} as Record<
CODE_MODULE_NAME,
{ id: string; module: string; version: string }
>,
files: {} as Record<
CODE_FILE_PATH,
{ id: string; name: string; type: "f" | "d" }
>,
};
export type ECode = typeof EmptyCode;
export type ESite = typeof EmptySite; export type ESite = typeof EmptySite;
export type EPage = typeof EmptyPage; export type EPage = typeof EmptyPage;
export type EComp = typeof EmptyComp; export type EComp = typeof EmptyComp;
@ -110,10 +93,10 @@ export const EDGlobal = {
list: {} as Record<string, { comp: EComp; doc: DComp }>, list: {} as Record<string, { comp: EComp; doc: DComp }>,
group: {} as Record<string, Awaited<ReturnType<SAction["comp"]["group"]>>>, group: {} as Record<string, Awaited<ReturnType<SAction["comp"]["group"]>>>,
}, },
code: {
doc: null as null | DCode,
},
ui: { ui: {
code: {
loaded: {} as Record<string, ECode>,
},
layout: { layout: {
left: parseInt(localStorage.getItem("prasi-layout-left") || "250"), left: parseInt(localStorage.getItem("prasi-layout-left") || "250"),
right: parseInt(localStorage.getItem("prasi-layout-right") || "250"), right: parseInt(localStorage.getItem("prasi-layout-right") || "250"),
@ -134,6 +117,11 @@ export const EDGlobal = {
open: {} as Record<string, string[]>, open: {} as Record<string, string[]>,
}, },
popup: { popup: {
code: {
open: false,
id: "",
file: "",
},
site: null as null | ((site_id: string) => void | Promise<void>), site: null as null | ((site_id: string) => void | Promise<void>),
site_form: null as null | { site_form: null as null | {
group_id: string; group_id: string;

View File

@ -9,11 +9,8 @@ export const EdSiteJS = () => {
style="slim" style="slim"
className="font-bold font-mono" className="font-bold font-mono"
onClick={() => { onClick={() => {
// p.sync.activity( p.ui.popup.code.open = true;
// { page_id: p.page.cur.id, item_id: "site" }, p.render();
// "js",
// Activity.Open
// );
}} }}
> >
<svg <svg

View File

@ -0,0 +1,12 @@
import { useGlobal } from "web-utils";
import { EDGlobal } from "../../../logic/ed-global";
export const EdPopCode = () => {
const p = useGlobal(EDGlobal, "EDITOR");
if (!p.ui.popup.code) {
return null;
}
return <></>;
};

View File

@ -0,0 +1,23 @@
import { useGlobal } from "web-utils";
import { EDGlobal } from "../../../logic/ed-global";
import { EdMonaco } from "../monaco/monaco";
export const EdCode = () => {
const p = useGlobal(EDGlobal, "EDITOR");
if (!p.ui.popup.code.open) return null;
return (
<EdMonaco
id="code"
type="js"
filename=""
modal={false}
monaco={{
value: p.site.js,
onChange: async (v) => {},
}}
onClose={() => {}}
/>
);
};

View File

@ -18,6 +18,7 @@ export const EdMonaco = (arg: {
val?: Record<string, any>; val?: Record<string, any>;
types?: Record<string, string>; types?: Record<string, string>;
}; };
modal?: boolean;
}) => { }) => {
const filename = arg.filename; const filename = arg.filename;
const m = arg.monaco; const m = arg.monaco;
@ -88,6 +89,14 @@ export const EdMonaco = (arg: {
}; };
} }
if (arg.modal === false) {
return (
<EdMonacoWrap header={arg.header} footer={arg.footer}>
{(Editor) => <Editor {...prop} />}
</EdMonacoWrap>
);
}
return ( return (
<Modal <Modal
open open

View File

@ -1,6 +1,5 @@
import { compress } from "wasm-gzip"; import { compress } from "wasm-gzip";
import { useGlobal, useLocal } from "web-utils"; import { useGlobal, useLocal } from "web-utils";
import { Activity } from "../../../../../../srv/ws/sync/type";
import { jscript } from "../../../../utils/script/jscript"; import { jscript } from "../../../../utils/script/jscript";
import { EDGlobal } from "../../logic/ed-global"; import { EDGlobal } from "../../logic/ed-global";
import { EdUserConn } from "../activity/user-conn"; import { EdUserConn } from "../activity/user-conn";

View File

@ -1,7 +1,7 @@
import { TypedArray, TypedDoc, TypedMap } from "yjs-types"; import { TypedArray, TypedDoc, TypedMap } from "yjs-types";
import { ISection } from "./section"; import { ISection } from "./section";
import { MItem } from "./item"; import { MItem } from "./item";
import * as Y from "yjs";
export type IRoot = { export type IRoot = {
id: "root"; id: "root";
type: "root"; type: "root";
@ -20,3 +20,11 @@ export type DPage = TypedDoc<{
export type DComp = TypedDoc<{ export type DComp = TypedDoc<{
map: TypedMap<{ id: string; root: MItem; ts?: number }>; map: TypedMap<{ id: string; root: MItem; ts?: number }>;
}>; }>;
export type DCode = TypedDoc<{
map: TypedMap<{
id: string;
files: TypedMap<Record<string, Y.Text>>;
npm: TypedMap<Record<string, string>>;
}>;
}>;