Yiwei Mao 7c6c7ab7a2
feat(variable): global variable + variable panel plugin in demo (#435)
* feat: global variable panel

* feat(variable): on any change to on list or any var change

* feat: fix layout add variable panel
2025-07-01 11:30:22 +00:00

36 lines
986 B
TypeScript

import { ASTFactory, definePluginCreator, GlobalScope } from '@flowgram.ai/free-layout-editor';
import { JsonSchemaUtils } from '@flowgram.ai/form-materials';
import iconVariable from '../../assets/icon-variable.png';
import { VariablePanelLayer } from './variable-panel-layer';
const fetchMockVariableFromRemote = async () => {
await new Promise((resolve) => setTimeout(resolve, 1000));
return {
type: 'object',
properties: {
userId: { type: 'string' },
},
};
};
export const createVariablePanelPlugin = definePluginCreator({
onInit(ctx) {
ctx.playground.registerLayer(VariablePanelLayer);
// Fetch Global Variable
fetchMockVariableFromRemote().then((v) => {
ctx.get(GlobalScope).setVar(
ASTFactory.createVariableDeclaration({
key: 'global',
meta: {
title: 'Global',
icon: iconVariable,
},
type: JsonSchemaUtils.schemaToAST(v),
})
);
});
},
});