This commit is contained in:
Rizky 2024-01-25 10:04:58 +07:00
parent 207281726a
commit 7083db69d7
5 changed files with 73 additions and 23 deletions

View File

@ -8,6 +8,7 @@ import { EdPagePicker } from "./panel/header/mid/page-picker";
import { TopBtn } from "./panel/header/top-btn";
import { useGlobal } from "web-utils";
import { ResponsiveToggle } from "./panel/header/right/responsive-toggle";
import { EdCompEditable } from "./panel/header/mid/comp-editable";
export const EdMid: FC<{}> = () => {
const ed = useGlobal(EDGlobal, "EDITORF");
@ -31,6 +32,7 @@ export const EdMid: FC<{}> = () => {
<EdAddItem />
<EdAddText />
<EdCompPicker />
<EdCompEditable />
</div>
</div>
<div className="flex items-stretch flex-1 justify-end">

View File

@ -197,6 +197,7 @@ export const EDGlobal = {
code: {} as Record<string, { doc: null | DCode }>,
global_prop: [] as string[],
ui: {
comp_editable: localStorage.getItem("prasi-comp-editable") === "yes",
zoom: localStorage.zoom || "100%",
side: { prop: true },
layout: {

View File

@ -0,0 +1,45 @@
import { useGlobal } from "web-utils";
import { EDGlobal } from "../../../logic/ed-global";
import { TopBtn } from "../top-btn";
export const EdCompEditable = () => {
const p = useGlobal(EDGlobal, "EDITOR");
const size = 12;
return (
<TopBtn
onClick={(e) => {
p.ui.comp_editable = !p.ui.comp_editable;
localStorage.setItem(
"prasi-comp-editable",
p.ui.comp_editable ? "yes" : "no"
);
p.render();
}}
style="slim"
>
<div
className={cx(
"flex items-center justify-center pr-1 hover:text-white",
css`
height: 18px;
`,
p.ui.comp_editable ? "text-green-700 " : "text-red-700"
)}
>
<div
className="mr-[2px]"
dangerouslySetInnerHTML={{
__html: p.ui.comp_editable
? `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-file-pen-line"><path d="m18 5-3-3H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2"/><path d="M8 18h1"/><path d="M18.4 9.6a2 2 0 1 1 3 3L17 17l-4 1 1-4Z"/></svg>`
: `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-file-lock-2"><path d="M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v1"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><rect width="8" height="5" x="2" y="13" rx="1"/><path d="M8 13v-2a2 2 0 1 0-4 0v2"/></svg>`,
}}
></div>
<div className="text-[7px] leading-none">
<div>Component</div>
<div>{p.ui.comp_editable ? "Editable" : "Locked"}</div>
</div>
</div>
</TopBtn>
);
};

View File

@ -79,6 +79,7 @@ export const EdSidePropInstance: FC<{ meta: IMeta }> = ({ meta }) => {
<div className="flex-1 overflow-hidden mr-2 text-ellipsis whitespace-nowrap">
{_meta.item.name}
</div>
{p.ui.comp_editable && (
<div
className="border px-1 cursor-pointer bg-white hover:bg-blue-100"
onClick={() => {
@ -106,6 +107,7 @@ export const EdSidePropInstance: FC<{ meta: IMeta }> = ({ meta }) => {
>
Edit Component
</div>
)}
</div>
<div className="flex flex-1 relative overflow-y-auto overflow-x-hidden">

View File

@ -97,7 +97,7 @@ export const EdTreeAction = ({
{comp.enabled && (
<>
{comp.id !== active.comp_id && (
{comp.id !== active.comp_id && p.ui.comp_editable && (
<Tooltip content="Edit Component">
<div
className="flex items-center border border-slate-500 bg-white rounded-sm text-[10px] px-[2px] cursor-pointer hover:bg-purple-100 hover:border-purple-600"