mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
* feat: global variable panel * feat(variable): on any change to on list or any var change * feat: fix layout add variable panel
41 lines
895 B
TypeScript
41 lines
895 B
TypeScript
import { useEffect } from 'react';
|
|
|
|
import { JsonSchemaEditor, JsonSchemaUtils } from '@flowgram.ai/form-materials';
|
|
import {
|
|
BaseVariableField,
|
|
GlobalScope,
|
|
useRefresh,
|
|
useService,
|
|
} from '@flowgram.ai/fixed-layout-editor';
|
|
|
|
export function GlobalVariableEditor() {
|
|
const globalScope = useService(GlobalScope);
|
|
|
|
const refresh = useRefresh();
|
|
|
|
const globalVar = globalScope.getVar() as BaseVariableField;
|
|
|
|
useEffect(() => {
|
|
const disposable = globalScope.output.onVariableListChange(() => {
|
|
refresh();
|
|
});
|
|
|
|
return () => {
|
|
disposable.dispose();
|
|
};
|
|
}, []);
|
|
|
|
if (!globalVar) {
|
|
return;
|
|
}
|
|
|
|
const value = globalVar.type ? JsonSchemaUtils.astToSchema(globalVar.type) : { type: 'object' };
|
|
|
|
return (
|
|
<JsonSchemaEditor
|
|
value={value}
|
|
onChange={(_schema) => globalVar.updateType(JsonSchemaUtils.schemaToAST(_schema))}
|
|
/>
|
|
);
|
|
}
|