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
36 lines
986 B
TypeScript
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),
|
|
})
|
|
);
|
|
});
|
|
},
|
|
});
|