diff --git a/app/srv/api/code.ts b/app/srv/api/code.ts new file mode 100644 index 00000000..74f74d47 --- /dev/null +++ b/app/srv/api/code.ts @@ -0,0 +1,9 @@ +import { apiContext } from "service-srv"; + +export const _ = { + url: "/code/:site_id/:action", + async api(site_id: string, action: "list") { + const { req, res } = apiContext(this); + return "This is code.ts"; + }, +}; diff --git a/app/srv/api/font.ts b/app/srv/api/font.ts index 3fae4d23..f3958d04 100644 --- a/app/srv/api/font.ts +++ b/app/srv/api/font.ts @@ -8,6 +8,7 @@ export const _ = { const f = await fetch(`https://fonts.googleapis.com${pathname}`); const body = await f.arrayBuffer(); const res = new Response(body); + res.headers.set("content-type", f.headers.get("content-type") || ""); return res; }, diff --git a/app/srv/ws/sync/actions/activity.ts b/app/srv/ws/sync/actions/activity.ts index 97f56c69..2d5af520 100644 --- a/app/srv/ws/sync/actions/activity.ts +++ b/app/srv/ws/sync/actions/activity.ts @@ -1,12 +1,11 @@ import { SAction } from "../actions"; -import { SyncConnection } from "../type"; -import { activity as a } from "../entity/activity"; import { prepCode } from "../editor/code/prep-code"; import { - Code, startCodeWatcher, - stopCodeWatcher, + stopCodeWatcher } from "../editor/code/watcher"; +import { activity as a } from "../entity/activity"; +import { SyncConnection } from "../type"; export const activity: SAction["activity"] = async function ( this: SyncConnection, name, @@ -24,7 +23,6 @@ export const activity: SAction["activity"] = async function ( } return data; }); - if (act.action === "open") { await startCodeWatcher(code); } else { diff --git a/app/web/src/render/ed/logic/ed-global.ts b/app/web/src/render/ed/logic/ed-global.ts index 9f3cd872..904ada03 100644 --- a/app/web/src/render/ed/logic/ed-global.ts +++ b/app/web/src/render/ed/logic/ed-global.ts @@ -118,6 +118,7 @@ export const EDGlobal = { log: "", loading: false, show_log: false, + list: {} as Record, }, site: null as null | ((site_id: string) => void | Promise), site_form: null as null | { diff --git a/app/web/src/render/ed/panel/popup/code/code.tsx b/app/web/src/render/ed/panel/popup/code/code.tsx index 70b3161f..1f6efc2c 100644 --- a/app/web/src/render/ed/panel/popup/code/code.tsx +++ b/app/web/src/render/ed/panel/popup/code/code.tsx @@ -1,14 +1,17 @@ import { useEffect } from "react"; -import { useGlobal } from "web-utils"; +import { useGlobal, useLocal } from "web-utils"; import { isLocalhost } from "../../../../../utils/ui/is-localhost"; import { Loading } from "../../../../../utils/ui/loading"; import { Modal } from "../../../../../utils/ui/modal"; import { Tooltip } from "../../../../../utils/ui/tooltip"; import { EDGlobal } from "../../../logic/ed-global"; import { Popover } from "../../../../../utils/ui/popover"; +import { iconChevronDown, iconGear, iconLoading, iconLog } from "./icons"; +import { CodeNameList } from "./name-list"; export const EdPopCode = () => { const p = useGlobal(EDGlobal, "EDITOR"); + const local = useLocal({ namePicker: false }); useEffect(() => { (async () => { @@ -39,92 +42,102 @@ export const EdPopCode = () => { open={p.ui.popup.code.open} onOpenChange={(open) => { if (!open) { - console.clear(); p.ui.popup.code.open = false; p.render(); } }} > -
-
- Hellow
} - autoFocus={false} - popoverClassName="bg-white shadow-md" - className={cx( - "flex items-center px-2 w-[200px] hover:bg-blue-50 space-x-1", - "cursor-pointer justify-between" - )} - > -
- {p.ui.popup.code.name} -
-
`, +
+
+
+ } + popoverClassName="bg-white shadow-md" + className={cx( + "flex items-center px-2 w-[200px] hover:bg-blue-50 space-x-1", + "cursor-pointer justify-between" + )} + open={local.namePicker} + onOpenChange={(open) => { + local.namePicker = open; + local.render(); }} - >
- - - {p.ui.popup.code.name !== "site" && ( -
+ > +
+ {p.ui.popup.code.name} +
`, + __html: iconChevronDown, }} >
+ + + {p.ui.popup.code.name !== "site" && ( +
+
+
+ )} + { + p.ui.popup.code.show_log = !p.ui.popup.code.show_log; + p.render(); + }} + > + {p.ui.popup.code.show_log && ( +
+ )} +
+
+
+ {p.ui.popup.code.show_log && ( +
+
{p.ui.popup.code.log || "stdout is empty..."}
)} - { - p.ui.popup.code.show_log = !p.ui.popup.code.show_log; - p.render(); - }} - > - {p.ui.popup.code.show_log && ( -
- )} + + {!p.ui.popup.code.open || !p.ui.popup.code.id ? ( +
+ +
+ ) : ( + + )} + {local.namePicker && (
` - : ``, + className="absolute inset-0" + onClick={() => { + local.namePicker = false; + local.render(); }} >
-
+ )}
- {p.ui.popup.code.show_log && ( -
-
{p.ui.popup.code.log || "stdout is empty..."}
-
- )} - {!p.ui.popup.code.open || !p.ui.popup.code.id ? ( -
- -
- ) : ( - - )}
); diff --git a/app/web/src/render/ed/panel/popup/code/icons.tsx b/app/web/src/render/ed/panel/popup/code/icons.tsx new file mode 100644 index 00000000..b4a1d485 --- /dev/null +++ b/app/web/src/render/ed/panel/popup/code/icons.tsx @@ -0,0 +1,5 @@ +export const iconLog = ``; +export const iconChevronDown = ``; +export const iconLoading = ``; + +export const iconGear = ``; diff --git a/app/web/src/render/ed/panel/popup/code/name-list.tsx b/app/web/src/render/ed/panel/popup/code/name-list.tsx new file mode 100644 index 00000000..0f25cc67 --- /dev/null +++ b/app/web/src/render/ed/panel/popup/code/name-list.tsx @@ -0,0 +1,25 @@ +import { FC, useEffect } from "react"; +import { useGlobal, useLocal } from "web-utils"; +import { EDGlobal } from "../../../logic/ed-global"; + +export const CodeNameList: FC<{}> = ({}) => { + const p = useGlobal(EDGlobal, "EDITOR"); + const local = useLocal( + { + list: [], + }, + async () => { + local.list = await api.code(p.site.id, "list"); + local.render(); + } + ); + + return ( + <> +
+
+ {JSON.stringify(local.list)} +
+ + ); +}; diff --git a/app/web/src/utils/ui/modal.tsx b/app/web/src/utils/ui/modal.tsx index 78e8a354..2001d48b 100644 --- a/app/web/src/utils/ui/modal.tsx +++ b/app/web/src/utils/ui/modal.tsx @@ -12,7 +12,6 @@ import { } from "@floating-ui/react"; import * as React from "react"; import { useLocal } from "web-utils"; -import { w } from "../types/general"; interface ModalOptions { initialOpen?: boolean; diff --git a/app/web/src/utils/ui/popover.tsx b/app/web/src/utils/ui/popover.tsx index 81bfff93..308e6bb7 100644 --- a/app/web/src/utils/ui/popover.tsx +++ b/app/web/src/utils/ui/popover.tsx @@ -26,7 +26,8 @@ interface PopoverOptions { offset?: number; onOpenChange?: (open: boolean) => void; autoFocus?: boolean; - backdrop?: boolean; + backdrop?: boolean | "self"; + root?: HTMLElement; } export function usePopover({ @@ -36,8 +37,9 @@ export function usePopover({ open: controlledOpen, offset: popoverOffset, onOpenChange: setControlledOpen, - autoFocus = true, + autoFocus = false, backdrop = true, + root, }: PopoverOptions = {}) { const arrowRef = React.useRef(null); const [uncontrolledOpen, setUncontrolledOpen] = React.useState(initialOpen); @@ -89,6 +91,7 @@ export function usePopover({ setDescriptionId, backdrop, autoFocus, + root, }), [ open, @@ -100,6 +103,7 @@ export function usePopover({ descriptionId, backdrop, autoFocus, + root, ] ); } @@ -178,6 +182,7 @@ export function Popover({ ...restOptions }: { className?: string; + root?: HTMLElement; popoverClassName?: string; children: React.ReactNode; content?: React.ReactNode; @@ -190,7 +195,18 @@ export function Popover({ return ( - {children} + { + popover.setOpen(!popover.open); + } + : undefined + } + > + {children} + + {context.backdrop ? ( {content} ) : ( diff --git a/package.json b/package.json index 8a8cfe8c..e5dcd9a9 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,11 @@ "module": "src/index.ts", "type": "module", "scripts": { - "dev": "bun run --watch ./pkgs/core/index.ts dev", - "clean": "rm -rf data && rm -rf app/static && rm -rf app/web/.parcel-cache", + "dev": "bun run --hot ./pkgs/core/index.ts dev", + "clean": "m -rf app/static && rm -rf app/web/.parcel-cache", "build": "bun run --silent ./pkgs/core/build.ts", "build-site": "bun run --silent ./pkgs/core/build-site.ts", - "db-pull": "bun run ./pkgs/core/db-pull.ts", + "db-pull": "bun run ./pkgs/crm -rf data && rore/db-pull.ts", "parcel": "bun clean && bun run ./pkgs/core/parcel.ts", "prod": "bun run --silent ./pkgs/core/index.ts", "local-prod": "bun run build && bun run db-pull && bun run ./pkgs/core/index.ts", diff --git a/pkgs/core/index.ts b/pkgs/core/index.ts index 82c724ac..01f57aad 100644 --- a/pkgs/core/index.ts +++ b/pkgs/core/index.ts @@ -56,12 +56,13 @@ if (!g.apiPrepared) { g.log.info("WS Action defined"); await generateAPIFrm(); - await prepareApiRoutes(); await prepareAPITypes(); g.log.info("API Prepared"); g.apiPrepared = true; } +await prepareApiRoutes(); + if (!g.parcel) { await parcelBuild(); }