wip fix
This commit is contained in:
parent
d019c54776
commit
8b7422536c
File diff suppressed because one or more lines are too long
|
|
@ -16,6 +16,7 @@ import { declareScope } from "./scope/scope";
|
|||
|
||||
// @ts-ignore
|
||||
import { FNCompDef } from "../../../../../utils/types/meta-fn";
|
||||
import { editorLocalValue } from "../../../../vi/render/script/local";
|
||||
|
||||
const scriptEdit = {
|
||||
timeout: null as any,
|
||||
|
|
@ -142,7 +143,7 @@ export const EdScriptMonaco: FC<{}> = () => {
|
|||
case "prop-instance":
|
||||
{
|
||||
types._raw = declareScope(p, meta, monaco);
|
||||
|
||||
|
||||
const nmodel = monaco.editor.createModel(
|
||||
trim(val),
|
||||
"typescript",
|
||||
|
|
@ -363,6 +364,8 @@ export const EdScriptMonaco: FC<{}> = () => {
|
|||
scope = code_result;
|
||||
}
|
||||
} else {
|
||||
editorLocalValue[active.item_id] = null;
|
||||
|
||||
const code_result = await p.sync.code.edit({
|
||||
type: "adv",
|
||||
mode: mode,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import { updatePropScope } from "./eval-prop";
|
|||
import { modifyChild } from "./passprop";
|
||||
import { VG } from "../global";
|
||||
|
||||
export const editorLocalValue = {} as Record<string, any>;
|
||||
|
||||
export const createViLocal = (
|
||||
vi: {
|
||||
layout: VG["layout"];
|
||||
|
|
@ -23,10 +25,17 @@ export const createViLocal = (
|
|||
hook?: (local: T) => void;
|
||||
effect?: (local: T) => void | Promise<void>;
|
||||
}) => {
|
||||
const isEditor =
|
||||
["localhost", "prasi.avolut.com"].includes(location.hostname) &&
|
||||
location.pathname.startsWith("/ed/");
|
||||
let id = meta.item.id;
|
||||
|
||||
const { children } = arg;
|
||||
const init_local_effect = vi.script?.init_local_effect;
|
||||
const metas = is_layout ? vi.layout?.meta : vi.meta;
|
||||
const ref = useRef<any>(arg.value);
|
||||
const ref = useRef<any>(
|
||||
editorLocalValue[id] ? editorLocalValue[id] : arg.value
|
||||
);
|
||||
const local = ref.current;
|
||||
local.render = meta.render;
|
||||
|
||||
|
|
@ -37,8 +46,6 @@ export const createViLocal = (
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
let id = meta.item.id;
|
||||
|
||||
if (meta.parent?.instance_id && metas) {
|
||||
const parent_meta = metas[meta.parent?.instance_id];
|
||||
if (parent_meta && parent_meta.instances) {
|
||||
|
|
@ -61,6 +68,9 @@ export const createViLocal = (
|
|||
const fn = async () => {
|
||||
if (arg.effect) {
|
||||
await arg.effect(local);
|
||||
if (isEditor) {
|
||||
editorLocalValue[id] = local;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -70,6 +80,22 @@ export const createViLocal = (
|
|||
return () => {};
|
||||
}, [location.pathname]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isEditor) {
|
||||
if (editorLocalValue[id] === null) {
|
||||
const fn = async () => {
|
||||
if (arg.effect) {
|
||||
await arg.effect(local);
|
||||
if (isEditor) {
|
||||
editorLocalValue[id] = local;
|
||||
}
|
||||
}
|
||||
};
|
||||
fn();
|
||||
}
|
||||
}
|
||||
}, [editorLocalValue[id]]);
|
||||
|
||||
return modifyChild(children, {
|
||||
...meta.script?.scope,
|
||||
[arg.name]: local,
|
||||
|
|
|
|||
Loading…
Reference in New Issue