wip fix
This commit is contained in:
parent
3dd306bc87
commit
220fbc2640
|
|
@ -80,6 +80,12 @@ export const parseJs = (meta: IMeta) => {
|
||||||
value: code.substring(loc.start.index, loc.end.index),
|
value: code.substring(loc.start.index, loc.end.index),
|
||||||
index: loc.start.index,
|
index: loc.start.index,
|
||||||
};
|
};
|
||||||
|
} else if (attr.value.loc) {
|
||||||
|
const loc = attr.value.loc as any;
|
||||||
|
passprop[attr.name.name] = {
|
||||||
|
value: code.substring(loc.start.index, loc.end.index),
|
||||||
|
index: loc.start.index,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,21 @@ import { loadApiProxyDef } from "./api-proxy-def";
|
||||||
|
|
||||||
export type ApiProxy<T extends Record<string, any> = {}> = any;
|
export type ApiProxy<T extends Record<string, any> = {}> = any;
|
||||||
|
|
||||||
|
const apiProxyPending: Record<string, Promise<void>> = {};
|
||||||
|
|
||||||
export const apiProxy = (api_url: string) => {
|
export const apiProxy = (api_url: string) => {
|
||||||
|
if (!w.prasiApi) {
|
||||||
|
w.prasiApi = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const base = new URL(api_url);
|
||||||
|
const base_url = `${base.protocol}//${base.host}`;
|
||||||
|
if (!w.prasiApi[base_url]) {
|
||||||
|
if (!apiProxyPending[base_url]) {
|
||||||
|
apiProxyPending[base_url] = loadApiProxyDef(base_url, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new Proxy(
|
return new Proxy(
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
|
|
@ -16,20 +30,12 @@ export const apiProxy = (api_url: string) => {
|
||||||
) {
|
) {
|
||||||
return new Promise<any>(async (resolve, reject) => {
|
return new Promise<any>(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
let base_url = api_url;
|
let api_def = w.prasiApi[base_url];
|
||||||
if (typeof this?.api_url === "string") {
|
|
||||||
base_url = this.api_url;
|
if (!api_def) {
|
||||||
|
await apiProxyPending[base_url];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!w.prasiApi) {
|
|
||||||
w.prasiApi = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!w.prasiApi[base_url]) {
|
|
||||||
await loadApiProxyDef(base_url, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
const api_def = w.prasiApi[base_url];
|
|
||||||
if (api_def) {
|
if (api_def) {
|
||||||
if (!api_def.apiEntry) api_def.apiEntry = {};
|
if (!api_def.apiEntry) api_def.apiEntry = {};
|
||||||
if (api_def.apiEntry && !api_def.apiEntry[actionName]) {
|
if (api_def.apiEntry && !api_def.apiEntry[actionName]) {
|
||||||
|
|
|
||||||
|
|
@ -42,13 +42,35 @@ export const declareScope = async (
|
||||||
if (def.local) {
|
if (def.local) {
|
||||||
addScope({
|
addScope({
|
||||||
monaco,
|
monaco,
|
||||||
loc: { item_id: m.item.id, type: "item" },
|
loc: {
|
||||||
|
item_id: m.item.id,
|
||||||
|
comp_id: m.parent?.comp_id,
|
||||||
|
type: "item",
|
||||||
|
},
|
||||||
source: `\
|
source: `\
|
||||||
export const {};
|
export const {};
|
||||||
declare global {
|
declare global {
|
||||||
const ${def.local.name} = ${def.local.value};
|
const ${def.local.name} = ${def.local.value};
|
||||||
}`,
|
}`,
|
||||||
});
|
});
|
||||||
|
} else if (def.passprop) {
|
||||||
|
Object.keys(def.passprop).map((e) => {
|
||||||
|
if (e !== "idx" && e !== "key") {
|
||||||
|
addScope({
|
||||||
|
monaco,
|
||||||
|
loc: {
|
||||||
|
item_id: m.item.id,
|
||||||
|
comp_id: m.parent?.comp_id,
|
||||||
|
type: "item",
|
||||||
|
},
|
||||||
|
source: `\
|
||||||
|
export const {};
|
||||||
|
declare global {
|
||||||
|
const ${e} = null as any;
|
||||||
|
}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if (def.props) {
|
} else if (def.props) {
|
||||||
Object.keys(def.props).map((e) => {
|
Object.keys(def.props).map((e) => {
|
||||||
addScope({
|
addScope({
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,26 @@ effect={async (local) => {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Local/>
|
<Local/>
|
||||||
|
</Button>{" "}
|
||||||
|
<Button
|
||||||
|
className={cx(css`
|
||||||
|
width: auto !important;
|
||||||
|
padding-left: 5px;
|
||||||
|
padding-right: 5px;
|
||||||
|
font-size: 12px;
|
||||||
|
`)}
|
||||||
|
onClick={() => {
|
||||||
|
p.script.do_edit(
|
||||||
|
`\
|
||||||
|
<PassProp idx={0}>
|
||||||
|
{children}
|
||||||
|
</PassProp>
|
||||||
|
`,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Passprop/>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,11 @@ export const EdTreeName = ({
|
||||||
}}
|
}}
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
item.name = local.rename;
|
item.name = local.rename;
|
||||||
|
|
||||||
|
const mitem = node.data?.mitem;
|
||||||
|
if (mitem) {
|
||||||
|
mitem.set("name", item.name);
|
||||||
|
}
|
||||||
p.ui.tree.rename_id = "";
|
p.ui.tree.rename_id = "";
|
||||||
p.render();
|
p.render();
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ export const ViScript: FC<{ meta: IMeta; children: ReactNode }> = ({
|
||||||
const scope_meta = getScopeMeta({ meta: vi.meta }, meta);
|
const scope_meta = getScopeMeta({ meta: vi.meta }, meta);
|
||||||
const scope = getScopeValue(scope_meta);
|
const scope = getScopeValue(scope_meta);
|
||||||
|
|
||||||
|
|
||||||
if (meta.item.component?.id) {
|
if (meta.item.component?.id) {
|
||||||
viEvalProps(vi, meta, scope);
|
viEvalProps(vi, meta, scope);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,11 @@ export const createViPassProp = (
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [k, v] of Object.entries(arg)) {
|
for (const [k, v] of Object.entries(arg)) {
|
||||||
|
if (k === "key" || k === "idx") continue;
|
||||||
|
|
||||||
if (k !== "children") {
|
if (k !== "children") {
|
||||||
delete meta.scope.val[k];
|
delete meta.scope.val[k];
|
||||||
meta.scope.val = {
|
meta.scope.val[k] = v;
|
||||||
...meta.scope.val,
|
|
||||||
get [k]() {
|
|
||||||
return v;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,21 +21,22 @@ export const getScopeMeta = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const meta of scopes_meta) {
|
for (const m of scopes_meta) {
|
||||||
const def = meta.scope.def;
|
const def = m.scope.def;
|
||||||
if (def) {
|
if (def) {
|
||||||
if (def.passprop) {
|
if (def.passprop) {
|
||||||
for (const p of Object.keys(def.passprop)) {
|
for (const p of Object.keys(def.passprop)) {
|
||||||
scope_meta[p] = { type: "passprop", meta };
|
console.log(meta.item.name, p, def.passprop)
|
||||||
|
scope_meta[p] = { type: "passprop", meta: m };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (def.props) {
|
if (def.props) {
|
||||||
for (const p of Object.keys(def.props)) {
|
for (const p of Object.keys(def.props)) {
|
||||||
scope_meta[p] = { type: "jsxprop", meta };
|
scope_meta[p] = { type: "jsxprop", meta: m };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (def.local) {
|
if (def.local) {
|
||||||
scope_meta[def.local.name] = { type: "local", meta };
|
scope_meta[def.local.name] = { type: "local", meta: m };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +55,3 @@ export const getScopeValue = (scope_meta: ReturnType<typeof getScopeMeta>) => {
|
||||||
|
|
||||||
return scope;
|
return scope;
|
||||||
};
|
};
|
||||||
|
|
||||||
// export const getScope = (vi: { meta: VG["meta"] }, meta: IMeta) => {
|
|
||||||
|
|
||||||
// };
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ export const SiteManager = () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(orgs);
|
|
||||||
if (orgs) {
|
if (orgs) {
|
||||||
orgs.push({
|
orgs.push({
|
||||||
org: {
|
org: {
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ export const baseTypings = `
|
||||||
name: string;
|
name: string;
|
||||||
idx?: any;
|
idx?: any;
|
||||||
value: T;
|
value: T;
|
||||||
children: (local: T & { render: () => void }) => any;
|
children: ReactNode;
|
||||||
deps?: any[];
|
deps?: any[];
|
||||||
effect?: (
|
effect?: (
|
||||||
local: T & { render: () => void }
|
local: T & { render: () => void }
|
||||||
|
|
|
||||||
|
|
@ -19,43 +19,48 @@ export const monacoTypings = async (
|
||||||
if (!map.has(prop.values)) {
|
if (!map.has(prop.values)) {
|
||||||
map.set(prop.values, true);
|
map.set(prop.values, true);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w.prasiApi[p.site.api_url] && w.prasiApi[p.site.api_url].prismaTypes) {
|
const prasi_api = w.prasiApi[p.site.api_url];
|
||||||
const prisma = w.prasiApi[p.site.api_url].prismaTypes;
|
if (prasi_api) {
|
||||||
|
if (prasi_api && prasi_api.prismaTypes) {
|
||||||
|
const prisma = prasi_api.prismaTypes;
|
||||||
|
|
||||||
register(
|
if (prisma) {
|
||||||
monaco,
|
register(
|
||||||
`\
|
monaco,
|
||||||
|
`\
|
||||||
declare module "ts:runtime/index" {
|
declare module "ts:runtime/index" {
|
||||||
${prisma["runtime/index.d.ts"]}
|
${prisma["runtime/index.d.ts"]}
|
||||||
}`,
|
}`,
|
||||||
`ts:runtime/index.d.ts`
|
`ts:runtime/index.d.ts`
|
||||||
);
|
);
|
||||||
|
|
||||||
register(
|
register(
|
||||||
monaco,
|
monaco,
|
||||||
`\
|
`\
|
||||||
declare module "ts:runtime/library" {
|
declare module "ts:runtime/library" {
|
||||||
${prisma["runtime/library.d.ts"]}
|
${prisma["runtime/library.d.ts"]}
|
||||||
}`,
|
}`,
|
||||||
`ts:runtime/library.d.ts`
|
`ts:runtime/library.d.ts`
|
||||||
);
|
);
|
||||||
|
|
||||||
register(
|
register(
|
||||||
monaco,
|
monaco,
|
||||||
`\
|
`\
|
||||||
declare module "ts:prisma" {
|
declare module "ts:prisma" {
|
||||||
${prisma["prisma.d.ts"].replace(
|
${prisma["prisma.d.ts"].replace(
|
||||||
`import * as runtime from './runtime/library';`,
|
`import * as runtime from './runtime/library';`,
|
||||||
`import * as runtime from 'ts:runtime/library';`
|
`import * as runtime from 'ts:runtime/library';`
|
||||||
)}
|
)}
|
||||||
}`,
|
}`,
|
||||||
`ts:prisma.d.ts`
|
`ts:prisma.d.ts`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
register(monaco, w.prasiApi[p.site.api_url].apiTypes, "ts:api.d.ts");
|
const api_types = prasi_api.apiTypes;
|
||||||
|
if (api_types) register(monaco, api_types, "ts:api.d.ts");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
monaco.languages.typescript.typescriptDefaults.setExtraLibs([
|
monaco.languages.typescript.typescriptDefaults.setExtraLibs([
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue