feat(demo-fixed-layout): update initialData (#341)

* feat(demo-fixed-layout): update initialData

* fix(fixed-layout-demo): clipboard plugin
This commit is contained in:
xiamidaxia 2025-06-06 19:45:16 +08:00 committed by GitHub
parent fbfe45c993
commit c320ab61e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 89 additions and 98 deletions

View File

@ -88,113 +88,112 @@ export const initialData: FlowDocumentJSON = {
}, },
}, },
{ {
id: 'if_0', id: 'switch_0',
type: 'if', type: 'switch',
data: { data: {
title: 'If', title: 'Switch',
inputsValues: {
condition: { type: 'constant', content: true },
},
inputs: {
type: 'object',
required: ['condition'],
properties: {
condition: {
type: 'boolean',
},
},
},
}, },
blocks: [ blocks: [
{ {
id: 'if_true', id: 'case_0',
type: 'ifBlock', type: 'case',
data: { data: {
title: 'true', title: 'Case_0',
inputsValues: {
condition: { type: 'constant', content: true },
},
inputs: {
type: 'object',
required: ['condition'],
properties: {
condition: {
type: 'boolean',
},
},
},
}, },
blocks: [], blocks: [],
}, },
{ {
id: 'if_false', id: 'case_1',
type: 'ifBlock', type: 'case',
data: { data: {
title: 'false', title: 'Case_1',
inputsValues: {
condition: { type: 'constant', content: true },
},
inputs: {
type: 'object',
required: ['condition'],
properties: {
condition: {
type: 'boolean',
},
},
},
},
},
{
id: 'case_default_1',
type: 'caseDefault',
data: {
title: 'Default',
},
blocks: [],
},
],
},
{
id: 'loop_0',
type: 'loop',
data: {
title: 'Loop',
batchFor: {
type: 'ref',
content: ['start_0', 'array_obj'],
},
},
blocks: [
{
id: 'if_0',
type: 'if',
data: {
title: 'If',
inputsValues: {
condition: { type: 'constant', content: true },
},
inputs: {
type: 'object',
required: ['condition'],
properties: {
condition: {
type: 'boolean',
},
},
},
}, },
blocks: [ blocks: [
{ {
id: 'loop_0', id: 'if_true',
type: 'loop', type: 'ifBlock',
data: { data: {
title: 'Loop', title: 'true',
batchFor: { },
type: 'ref', blocks: [],
content: ['start_0', 'array_obj'], },
}, {
id: 'if_false',
type: 'ifBlock',
data: {
title: 'false',
}, },
blocks: [ blocks: [
{ {
id: 'switch_0', id: 'break_0',
type: 'switch', type: 'breakLoop',
data: { data: {
title: 'Switch', title: 'BreakLoop',
}, },
blocks: [
{
id: 'case_0',
type: 'case',
data: {
title: 'Case_0',
inputsValues: {
condition: { type: 'constant', content: true },
},
inputs: {
type: 'object',
required: ['condition'],
properties: {
condition: {
type: 'boolean',
},
},
},
},
blocks: [],
},
{
id: 'case_1',
type: 'case',
data: {
title: 'Case_1',
inputsValues: {
condition: { type: 'constant', content: true },
},
inputs: {
type: 'object',
required: ['condition'],
properties: {
condition: {
type: 'boolean',
},
},
},
},
},
{
id: 'case_default_1',
type: 'caseDefault',
data: {
title: 'Default',
},
blocks: [
{
id: 'break_0',
type: 'breakLoop',
data: {
title: 'BreakLoop',
},
},
],
},
],
}, },
], ],
}, },

View File

@ -1,14 +1,11 @@
import { import {
definePluginCreator, definePluginCreator,
Disposable,
FixedLayoutPluginContext, FixedLayoutPluginContext,
PluginCreator, PluginCreator,
} from '@flowgram.ai/fixed-layout-editor'; } from '@flowgram.ai/fixed-layout-editor';
import { readData } from '../../shortcuts/utils'; import { readData } from '../../shortcuts/utils';
let disposable: any;
export const createClipboardPlugin: PluginCreator<void> = definePluginCreator< export const createClipboardPlugin: PluginCreator<void> = definePluginCreator<
void, void,
FixedLayoutPluginContext FixedLayoutPluginContext
@ -20,13 +17,8 @@ export const createClipboardPlugin: PluginCreator<void> = definePluginCreator<
clipboard.writeText(e.value); clipboard.writeText(e.value);
}; };
navigator.clipboard.addEventListener('onchange', clipboardListener); navigator.clipboard.addEventListener('onchange', clipboardListener);
ctx.playground.toDispose.onDispose(() => {
disposable = Disposable.create(() => {
navigator.clipboard.removeEventListener('onchange', clipboardListener); navigator.clipboard.removeEventListener('onchange', clipboardListener);
}); });
}, },
onDispose() {
disposable?.dispose?.();
disposable = undefined;
},
}); });

View File

@ -23,7 +23,7 @@ test.describe('node operations', () => {
const prevCount = await editorPage.getNodeCount(); const prevCount = await editorPage.getNodeCount();
await editorPage.insert('switch', { await editorPage.insert('switch', {
from: 'llm_0', from: 'llm_0',
to: 'if_0', to: 'switch_0',
}); });
const defaultNodeCount = await editorPage.getNodeCount(); const defaultNodeCount = await editorPage.getNodeCount();
expect(defaultNodeCount).toEqual(prevCount + 4); expect(defaultNodeCount).toEqual(prevCount + 4);