diff --git a/apps/demo-fixed-layout-simple/.eslintrc.js b/apps/demo-fixed-layout-simple/.eslintrc.js index 02803479..9f8bd759 100644 --- a/apps/demo-fixed-layout-simple/.eslintrc.js +++ b/apps/demo-fixed-layout-simple/.eslintrc.js @@ -7,4 +7,9 @@ module.exports = defineConfig({ 'no-console': 'off', 'react/prop-types': 'off', }, + settings: { + react: { + version: 'detect', // 自动检测 React 版本 + }, + }, }); diff --git a/apps/demo-fixed-layout-simple/src/components/minimap.tsx b/apps/demo-fixed-layout-simple/src/components/minimap.tsx index 79acc454..14161bf2 100644 --- a/apps/demo-fixed-layout-simple/src/components/minimap.tsx +++ b/apps/demo-fixed-layout-simple/src/components/minimap.tsx @@ -1,7 +1,6 @@ import { FlowMinimapService, MinimapRender } from '@flowgram.ai/minimap-plugin'; import { useService } from '@flowgram.ai/fixed-layout-editor'; - export const Minimap = () => { const minimapService = useService(FlowMinimapService); return ( diff --git a/apps/demo-fixed-layout-simple/src/components/tools.tsx b/apps/demo-fixed-layout-simple/src/components/tools.tsx index dfd6cd76..29e32fe3 100644 --- a/apps/demo-fixed-layout-simple/src/components/tools.tsx +++ b/apps/demo-fixed-layout-simple/src/components/tools.tsx @@ -1,4 +1,5 @@ -import { useEffect, useState } from 'react' +import { useEffect, useState } from 'react'; + import { usePlaygroundTools, useClientContext } from '@flowgram.ai/fixed-layout-editor'; export function Tools() { @@ -15,13 +16,21 @@ export function Tools() { return () => disposable.dispose(); }, [history]); - return
- - - - - - - {Math.floor(tools.zoom * 100)}% -
+ return ( +
+ + + + + + + {Math.floor(tools.zoom * 100)}% +
+ ); } diff --git a/apps/demo-fixed-layout-simple/src/editor.tsx b/apps/demo-fixed-layout-simple/src/editor.tsx index d47999fd..1d17c1dc 100644 --- a/apps/demo-fixed-layout-simple/src/editor.tsx +++ b/apps/demo-fixed-layout-simple/src/editor.tsx @@ -1,13 +1,13 @@ import { FixedLayoutEditorProvider, EditorRenderer } from '@flowgram.ai/fixed-layout-editor'; import '@flowgram.ai/fixed-layout-editor/index.css'; -import './index.css' +import './index.css'; +import { nodeRegistries } from './node-registries'; +import { initialData } from './initial-data'; import { useEditorProps } from './hooks/use-editor-props'; -import { initialData } from './initial-data' -import { nodeRegistries } from './node-registries' -import { Tools } from './components/tools' -import { Minimap } from './components/minimap' +import { Tools } from './components/tools'; +import { Minimap } from './components/minimap'; export const Editor = () => { const editorProps = useEditorProps(initialData, nodeRegistries); diff --git a/apps/demo-fixed-layout-simple/src/initial-data.ts b/apps/demo-fixed-layout-simple/src/initial-data.ts index 85156638..742cd940 100644 --- a/apps/demo-fixed-layout-simple/src/initial-data.ts +++ b/apps/demo-fixed-layout-simple/src/initial-data.ts @@ -11,7 +11,7 @@ export const initialData: FlowDocumentJSON = { type: 'start', data: { title: 'Start', - content: 'start content' + content: 'start content', }, blocks: [], }, @@ -20,7 +20,7 @@ export const initialData: FlowDocumentJSON = { id: 'condition_0', type: 'condition', data: { - title: 'Condition' + title: 'Condition', }, blocks: [ { @@ -28,7 +28,7 @@ export const initialData: FlowDocumentJSON = { type: 'block', data: { title: 'Branch 0', - content: 'branch 1 content' + content: 'branch 1 content', }, blocks: [ { @@ -36,7 +36,7 @@ export const initialData: FlowDocumentJSON = { type: 'custom', data: { title: 'Custom', - content: 'custrom content' + content: 'custrom content', }, }, ], @@ -46,7 +46,7 @@ export const initialData: FlowDocumentJSON = { type: 'block', data: { title: 'Branch 1', - content: 'branch 1 content' + content: 'branch 1 content', }, blocks: [], }, @@ -58,9 +58,8 @@ export const initialData: FlowDocumentJSON = { type: 'end', data: { title: 'End', - content: 'end content' + content: 'end content', }, }, ], }; - diff --git a/apps/demo-fixed-layout-simple/src/node-registries.ts b/apps/demo-fixed-layout-simple/src/node-registries.ts index bf2e6687..eed5fea5 100644 --- a/apps/demo-fixed-layout-simple/src/node-registries.ts +++ b/apps/demo-fixed-layout-simple/src/node-registries.ts @@ -1,5 +1,5 @@ -import { FlowNodeRegistry } from '@flowgram.ai/fixed-layout-editor'; import { nanoid } from 'nanoid'; +import { FlowNodeRegistry } from '@flowgram.ai/fixed-layout-editor'; /** * 自定义节点注册 @@ -67,9 +67,9 @@ export const nodeRegistries: FlowNodeRegistry[] = [ type: 'custom', data: { title: 'Custom', - content: 'this is custom content' - } - } - } - } + content: 'this is custom content', + }, + }; + }, + }, ]; diff --git a/apps/demo-fixed-layout/.eslintrc.js b/apps/demo-fixed-layout/.eslintrc.js index 02803479..9f8bd759 100644 --- a/apps/demo-fixed-layout/.eslintrc.js +++ b/apps/demo-fixed-layout/.eslintrc.js @@ -7,4 +7,9 @@ module.exports = defineConfig({ 'no-console': 'off', 'react/prop-types': 'off', }, + settings: { + react: { + version: 'detect', // 自动检测 React 版本 + }, + }, }); diff --git a/apps/demo-fixed-layout/src/components/branch-adder/styles.tsx b/apps/demo-fixed-layout/src/components/branch-adder/styles.tsx index 91a67013..7d8546ba 100644 --- a/apps/demo-fixed-layout/src/components/branch-adder/styles.tsx +++ b/apps/demo-fixed-layout/src/components/branch-adder/styles.tsx @@ -3,7 +3,7 @@ import styled from 'styled-components'; export const Container = styled.div<{ activated?: boolean; isVertical: boolean }>` width: 28px; height: 18px; - background: ${props => (props.activated ? '#82A7FC' : 'rgb(187, 191, 196)')}; + background: ${(props) => (props.activated ? '#82A7FC' : 'rgb(187, 191, 196)')}; display: flex; border-radius: 9px; justify-content: space-evenly; @@ -11,7 +11,7 @@ export const Container = styled.div<{ activated?: boolean; isVertical: boolean } color: #fff; font-size: 10px; font-weight: bold; - transform: ${props => (props.isVertical ? '' : 'rotate(90deg)')}; + transform: ${(props) => (props.isVertical ? '' : 'rotate(90deg)')}; div { display: flex; justify-content: center; diff --git a/apps/demo-fixed-layout/src/components/drag-node/index.tsx b/apps/demo-fixed-layout/src/components/drag-node/index.tsx index af390263..ab96a8f2 100644 --- a/apps/demo-fixed-layout/src/components/drag-node/index.tsx +++ b/apps/demo-fixed-layout/src/components/drag-node/index.tsx @@ -12,14 +12,14 @@ export interface PropsType { export function DragNode(props: PropsType): JSX.Element { const { dragStart, dragNodes } = props; - const icon = FlowNodeRegistries.find(registry => registry.type === dragStart?.flowNodeType)?.info - ?.icon; + const icon = FlowNodeRegistries.find((registry) => registry.type === dragStart?.flowNodeType) + ?.info?.icon; const dragLength = (dragNodes || []) - .map(_node => + .map((_node) => _node.allCollapsedChildren.length - ? _node.allCollapsedChildren.filter(_n => !_n.hidden).length - : 1, + ? _node.allCollapsedChildren.filter((_n) => !_n.hidden).length + : 1 ) .reduce((acm, curr) => acm + curr, 0); diff --git a/apps/demo-fixed-layout/src/components/node-adder/index.tsx b/apps/demo-fixed-layout/src/components/node-adder/index.tsx index 35745ea3..c8421a61 100644 --- a/apps/demo-fixed-layout/src/components/node-adder/index.tsx +++ b/apps/demo-fixed-layout/src/components/node-adder/index.tsx @@ -15,7 +15,7 @@ const generateNewIdForChildren = (n: FlowNodeEntity): FlowNodeEntity => { return { ...n, id: generateNodeId(n), - blocks: n.blocks.map(b => generateNewIdForChildren(b)), + blocks: n.blocks.map((b) => generateNewIdForChildren(b)), } as FlowNodeEntity; } else { return { @@ -39,7 +39,7 @@ export default function Adder(props: { const activated = useMemo( () => props.hoverActivated && !playground.config.readonly, - [props.hoverActivated, playground.config.readonly], + [props.hoverActivated, playground.config.readonly] ); const add = (addProps: any) => { @@ -111,7 +111,7 @@ export default function Adder(props: { } : {} } - onMouseDown={e => e.stopPropagation()} + onMouseDown={(e) => e.stopPropagation()} > {props.hoverActivated ? ( void; from: FlowNodeE }; return ( - {FlowNodeRegistries.map(registry => ( + {FlowNodeRegistries.map((registry) => ( = ({ return false; } const findGroupInNodes = (nodes: FlowNodeEntity[]): boolean => - nodes.some(node => { + nodes.some((node) => { if (node.flowNodeType === FlowNodeBaseType.GROUP) { return true; } @@ -63,7 +63,7 @@ export const SelectorBoxPopover: FunctionComponent = ({ top: bounds.top, transform: 'translate(-100%, -100%)', }} - onMouseDown={e => { + onMouseDown={(e) => { e.stopPropagation(); }} > @@ -78,7 +78,7 @@ export const SelectorBoxPopover: FunctionComponent = ({ icon={} type="primary" theme="solid" - onMouseDown={e => { + onMouseDown={(e) => { e.stopPropagation(); startDrag(e, { dragStartEntity: selectNodes[0], @@ -95,7 +95,7 @@ export const SelectorBoxPopover: FunctionComponent = ({ style={{ height: BUTTON_HEIGHT }} type="primary" theme="solid" - onMouseDown={e => { + onMouseDown={(e) => { commandRegistry.executeCommand(FlowCommandId.COLLAPSE); }} /> @@ -107,7 +107,7 @@ export const SelectorBoxPopover: FunctionComponent = ({ style={{ height: BUTTON_HEIGHT }} type="primary" theme="solid" - onMouseDown={e => { + onMouseDown={(e) => { commandRegistry.executeCommand(FlowCommandId.EXPAND); }} /> @@ -155,7 +155,7 @@ export const SelectorBoxPopover: FunctionComponent = ({
{ + onMouseDown={(e) => { e.stopPropagation(); startDrag(e, { dragStartEntity: selectNodes[0], diff --git a/apps/demo-fixed-layout/src/components/tools/index.tsx b/apps/demo-fixed-layout/src/components/tools/index.tsx index a72dd45d..7d387055 100644 --- a/apps/demo-fixed-layout/src/components/tools/index.tsx +++ b/apps/demo-fixed-layout/src/components/tools/index.tsx @@ -1,10 +1,6 @@ import { useState, useEffect } from 'react'; -import { - usePlayground, - usePlaygroundTools, - useRefresh, -} from '@flowgram.ai/fixed-layout-editor'; +import { usePlayground, usePlaygroundTools, useRefresh } from '@flowgram.ai/fixed-layout-editor'; import { Tooltip, IconButton } from '@douyinfe/semi-ui'; import { IconUndo, IconRedo } from '@douyinfe/semi-icons'; diff --git a/apps/demo-fixed-layout/src/components/tools/save.tsx b/apps/demo-fixed-layout/src/components/tools/save.tsx index b2505e26..7edf72f0 100644 --- a/apps/demo-fixed-layout/src/components/tools/save.tsx +++ b/apps/demo-fixed-layout/src/components/tools/save.tsx @@ -1,10 +1,6 @@ import { useState, useEffect, useCallback } from 'react'; -import { - useClientContext, - getNodeForm, - FlowNodeEntity, -} from '@flowgram.ai/fixed-layout-editor'; +import { useClientContext, getNodeForm, FlowNodeEntity } from '@flowgram.ai/fixed-layout-editor'; import { Button, Badge } from '@douyinfe/semi-ui'; export function Save(props: { disabled: boolean }) { @@ -12,8 +8,8 @@ export function Save(props: { disabled: boolean }) { const clientContext = useClientContext(); const updateValidateData = useCallback(() => { - const allForms = clientContext.document.getAllNodes().map(node => getNodeForm(node)); - const count = allForms.filter(form => form?.state.invalid).length; + const allForms = clientContext.document.getAllNodes().map((node) => getNodeForm(node)); + const count = allForms.filter((form) => form?.state.invalid).length; setErrorCount(count); }, [clientContext]); @@ -21,8 +17,8 @@ export function Save(props: { disabled: boolean }) { * Validate all node and Save */ const onSave = useCallback(async () => { - const allForms = clientContext.document.getAllNodes().map(node => getNodeForm(node)); - await Promise.all(allForms.map(async form => form?.validate())); + const allForms = clientContext.document.getAllNodes().map((node) => getNodeForm(node)); + await Promise.all(allForms.map(async (form) => form?.validate())); console.log('>>>>> save data: ', clientContext.document.toJSON()); }, [clientContext]); @@ -37,9 +33,9 @@ export function Save(props: { disabled: boolean }) { node.onDispose(() => formValidateDispose.dispose()); } }; - clientContext.document.getAllNodes().map(node => listenSingleNodeValidate(node)); + clientContext.document.getAllNodes().map((node) => listenSingleNodeValidate(node)); const dispose = clientContext.document.onNodeCreate(({ node }) => - listenSingleNodeValidate(node), + listenSingleNodeValidate(node) ); return () => dispose.dispose(); }, [clientContext]); diff --git a/apps/demo-fixed-layout/src/form-components/feedback.tsx b/apps/demo-fixed-layout/src/form-components/feedback.tsx index fd5ab902..2000300e 100644 --- a/apps/demo-fixed-layout/src/form-components/feedback.tsx +++ b/apps/demo-fixed-layout/src/form-components/feedback.tsx @@ -19,7 +19,7 @@ const Warning = styled.span` export const Feedback = ({ errors, warnings }: StatePanelProps) => { const renderFeedbacks = (fs: FieldError[] | FieldWarning[] | undefined) => { if (!fs) return null; - return fs.map(f => {f.message}); + return fs.map((f) => {f.message}); }; return (
diff --git a/apps/demo-fixed-layout/src/form-components/form-header/index.tsx b/apps/demo-fixed-layout/src/form-components/form-header/index.tsx index 7107e4d7..8787f2d7 100644 --- a/apps/demo-fixed-layout/src/form-components/form-header/index.tsx +++ b/apps/demo-fixed-layout/src/form-components/form-header/index.tsx @@ -41,7 +41,7 @@ export function FormHeader() { return (
{ + onMouseDown={(e) => { // trigger drag node startDrag(e); e.stopPropagation(); @@ -73,7 +73,7 @@ export function FormHeader() { size="small" theme="borderless" icon={} - onClick={e => e.stopPropagation()} + onClick={(e) => e.stopPropagation()} /> diff --git a/apps/demo-fixed-layout/src/form-components/form-inputs/index.tsx b/apps/demo-fixed-layout/src/form-components/form-inputs/index.tsx index 562811c8..6d9346b2 100644 --- a/apps/demo-fixed-layout/src/form-components/form-inputs/index.tsx +++ b/apps/demo-fixed-layout/src/form-components/form-inputs/index.tsx @@ -18,7 +18,7 @@ export function FormInputs() { if (!properties) { return <>; } - const content = Object.keys(properties).map(key => { + const content = Object.keys(properties).map((key) => { const property = properties[key]; return ( diff --git a/apps/demo-fixed-layout/src/form-components/form-item/index.tsx b/apps/demo-fixed-layout/src/form-components/form-item/index.tsx index 32f83624..698324e5 100644 --- a/apps/demo-fixed-layout/src/form-components/form-item/index.tsx +++ b/apps/demo-fixed-layout/src/form-components/form-item/index.tsx @@ -32,7 +32,7 @@ export function FormItem({ {required && *}
), - [], + [] ); return (
{ const properties = field.value?.properties; if (properties) { - const content = Object.keys(properties).map(key => { + const content = Object.keys(properties).map((key) => { const property = properties[key]; return ; }); diff --git a/apps/demo-fixed-layout/src/form-components/properties-edit/index.tsx b/apps/demo-fixed-layout/src/form-components/properties-edit/index.tsx index 9d88e0be..18ea4d81 100644 --- a/apps/demo-fixed-layout/src/form-components/properties-edit/index.tsx +++ b/apps/demo-fixed-layout/src/form-components/properties-edit/index.tsx @@ -13,7 +13,7 @@ export interface PropertiesEditProps { useFx?: boolean; } -export const PropertiesEdit: React.FC = props => { +export const PropertiesEdit: React.FC = (props) => { const value = (props.value || {}) as Record; const { readonly } = useContext(NodeRenderContext); const [newProperty, updateNewPropertyFromCache] = useState<{ key: string; value: JsonSchema }>({ @@ -28,7 +28,7 @@ export const PropertiesEdit: React.FC = props => { const updateProperty = ( propertyValue: JsonSchema, propertyKey: string, - newPropertyKey?: string, + newPropertyKey?: string ) => { const newValue = { ...value }; if (newPropertyKey) { @@ -42,7 +42,7 @@ export const PropertiesEdit: React.FC = props => { const updateNewProperty = ( propertyValue: JsonSchema, propertyKey: string, - newPropertyKey?: string, + newPropertyKey?: string ) => { // const newValue = { ...value } if (newPropertyKey) { @@ -59,7 +59,7 @@ export const PropertiesEdit: React.FC = props => { }; return ( <> - {Object.keys(props.value || {}).map(key => { + {Object.keys(props.value || {}).map((key) => { const property = (value[key] || {}) as JsonSchema; return ( = props => { +export const GroupNote: FC = (props) => { const { groupController, containerStyle = {}, @@ -65,14 +65,14 @@ export const GroupNote: FC = props => { > { + onChange={(note) => { setEditingValue(note || ''); }} readonly={playground.config.readonly} placeholder="Please enter note" style={textStyle} autoSize={autoSize} - onEditingChange={editingState => { + onEditingChange={(editingState) => { if (editingState) { setTooltipVisible(false); } diff --git a/apps/demo-fixed-layout/src/plugins/group-plugin/group-tools.tsx b/apps/demo-fixed-layout/src/plugins/group-plugin/group-tools.tsx index 6392cf80..1ac24156 100644 --- a/apps/demo-fixed-layout/src/plugins/group-plugin/group-tools.tsx +++ b/apps/demo-fixed-layout/src/plugins/group-plugin/group-tools.tsx @@ -29,7 +29,7 @@ interface GroupToolsProps { const BUTTON_HEIGHT = 24; -export const GroupTools: FC = props => { +export const GroupTools: FC = (props) => { const { groupNode, groupController, visible, style = {} } = props; const groupService = useService(FlowGroupService); @@ -53,7 +53,7 @@ export const GroupTools: FC = props => { color: 'rgb(97, 69, 211)', ...style, }} - onMouseDown={e => { + onMouseDown={(e) => { e.stopPropagation(); }} > @@ -64,7 +64,7 @@ export const GroupTools: FC = props => { icon={} type="primary" theme="borderless" - onMouseDown={e => { + onMouseDown={(e) => { e.stopPropagation(); startDrag(e, { dragStartEntity: groupNode, @@ -80,7 +80,7 @@ export const GroupTools: FC = props => { icon={groupController?.collapsed ? : } type="primary" theme="borderless" - onClick={e => { + onClick={(e) => { if (!groupController) { return; } diff --git a/apps/demo-fixed-layout/src/plugins/group-plugin/multilang-textarea-editor/base-textarea.tsx b/apps/demo-fixed-layout/src/plugins/group-plugin/multilang-textarea-editor/base-textarea.tsx index 7edefa61..4285cc45 100644 --- a/apps/demo-fixed-layout/src/plugins/group-plugin/multilang-textarea-editor/base-textarea.tsx +++ b/apps/demo-fixed-layout/src/plugins/group-plugin/multilang-textarea-editor/base-textarea.tsx @@ -15,7 +15,7 @@ interface Props { [key: string]: any; } -const BaseTextarea: React.FC = props => { +const BaseTextarea: React.FC = (props) => { const { value, onChange, onBlur, editing, onFocus, autoSize = true, ...rest } = props; const [data, setData] = useState(value); @@ -46,7 +46,7 @@ const BaseTextarea: React.FC = props => { {...rest} ref={textareaRef} value={data} - onChange={v => { + onChange={(v) => { setData(v); }} onEnterPress={onSubmit} diff --git a/apps/demo-fixed-layout/src/plugins/group-plugin/multilang-textarea-editor/index.tsx b/apps/demo-fixed-layout/src/plugins/group-plugin/multilang-textarea-editor/index.tsx index 8f3a133c..69b36615 100644 --- a/apps/demo-fixed-layout/src/plugins/group-plugin/multilang-textarea-editor/index.tsx +++ b/apps/demo-fixed-layout/src/plugins/group-plugin/multilang-textarea-editor/index.tsx @@ -21,7 +21,7 @@ interface Props { onEditingChange?: (editing: boolean) => void; } -const MultiLineEditor: React.FC = props => { +const MultiLineEditor: React.FC = (props) => { const { value, onChange, diff --git a/apps/demo-fixed-layout/src/shortcuts/index.ts b/apps/demo-fixed-layout/src/shortcuts/index.ts index 753f8dcb..d63804ed 100644 --- a/apps/demo-fixed-layout/src/shortcuts/index.ts +++ b/apps/demo-fixed-layout/src/shortcuts/index.ts @@ -14,27 +14,27 @@ import { writeData } from './utils'; import { FlowCommandId } from './constants'; type ShortcutGetter = ( - ctx: FixedLayoutPluginContext, + ctx: FixedLayoutPluginContext ) => Parameters[0]; -const copy: ShortcutGetter = ctx => { +const copy: ShortcutGetter = (ctx) => { const selection = ctx.selection; const clipboard = ctx.clipboard; return { commandId: FlowCommandId.COPY, shortcuts: ['meta c', 'ctrl c'], - isEnabled: node => + isEnabled: (node) => (selection?.selection.length > 0 || node instanceof FlowNodeEntity) && !ctx.playground.config.readonlyOrDisabled, - execute: node => { + execute: (node) => { const nodes = node instanceof FlowNodeEntity ? [node] : (selection.selection.filter( - _entity => _entity instanceof FlowNodeEntity, + (_entity) => _entity instanceof FlowNodeEntity ) as FlowNodeEntity[]); - const originNodes = nodes.map(n => ({ + const originNodes = nodes.map((n) => ({ ...n.toJSON(), id: `${n.flowNodeType}_${nanoid()}`, })); @@ -47,7 +47,7 @@ const copy: ShortcutGetter = ctx => { }; }; -const cut: ShortcutGetter = ctx => { +const cut: ShortcutGetter = (ctx) => { const selection = ctx.selection; const commandRegistry = ctx.get(CommandRegistry); @@ -75,7 +75,7 @@ const cut: ShortcutGetter = ctx => { }; }; -const zoomIn: ShortcutGetter = ctx => { +const zoomIn: ShortcutGetter = (ctx) => { const config = ctx.playground.config; return { @@ -87,7 +87,7 @@ const zoomIn: ShortcutGetter = ctx => { }; }; -const zoomOut: ShortcutGetter = ctx => { +const zoomOut: ShortcutGetter = (ctx) => { const config = ctx.playground.config; return { @@ -99,7 +99,7 @@ const zoomOut: ShortcutGetter = ctx => { }; }; -const resetZoom: ShortcutGetter = ctx => ({ +const resetZoom: ShortcutGetter = (ctx) => ({ commandId: FlowCommandId.RESET_ZOOM, commandDetail: { label: 'Reset Zoom', @@ -110,7 +110,7 @@ const resetZoom: ShortcutGetter = ctx => ({ }, }); -const group: ShortcutGetter = ctx => ({ +const group: ShortcutGetter = (ctx) => ({ commandId: FlowCommandId.GROUP, commandDetail: { label: 'Create Group', @@ -123,14 +123,14 @@ const group: ShortcutGetter = ctx => ({ const selection = ctx.playground.selectionService; groupService.createGroup( - selection.selection.filter(_entity => _entity instanceof FlowNodeEntity) as FlowNodeEntity[], + selection.selection.filter((_entity) => _entity instanceof FlowNodeEntity) as FlowNodeEntity[] ); ctx.playground.selectionService.selection = []; }, }); -const selectAll: ShortcutGetter = ctx => ({ +const selectAll: ShortcutGetter = (ctx) => ({ commandId: FlowCommandId.SELECT_ALL, commandDetail: { label: 'Select All', @@ -139,14 +139,14 @@ const selectAll: ShortcutGetter = ctx => ({ isEnabled: () => !ctx.playground.config.readonlyOrDisabled, execute: () => { const allNodes = (ctx.document.root.children || []).filter( - node => node.flowNodeType !== 'start' && node.flowNodeType !== 'end', + (node) => node.flowNodeType !== 'start' && node.flowNodeType !== 'end' ); ctx.playground.selectionService.selection = allNodes; }, }); -const cancelSelect: ShortcutGetter = ctx => ({ +const cancelSelect: ShortcutGetter = (ctx) => ({ commandId: FlowCommandId.CANCEL_SELECT, commandDetail: { label: 'Cancel Select', @@ -157,7 +157,7 @@ const cancelSelect: ShortcutGetter = ctx => ({ }, }); -const collapse: ShortcutGetter = ctx => ({ +const collapse: ShortcutGetter = (ctx) => ({ commandId: FlowCommandId.COLLAPSE, commandDetail: { label: 'Collapse', @@ -168,19 +168,19 @@ const collapse: ShortcutGetter = ctx => ({ const selection = ctx.selection; const selectNodes = selection.selection.filter( - _entity => _entity instanceof FlowNodeEntity, + (_entity) => _entity instanceof FlowNodeEntity ) as FlowNodeEntity[]; selectNodes - .map(_node => [_node, ..._node.allCollapsedChildren]) + .map((_node) => [_node, ..._node.allCollapsedChildren]) .flat() - .forEach(node => { + .forEach((node) => { const renderData = node.getData(FlowNodeRenderData); if ( node.firstChild && [FlowNodeBaseType.BLOCK_ICON, FlowNodeBaseType.BLOCK_ORDER_ICON].includes( - node.firstChild.flowNodeType as FlowNodeBaseType, + node.firstChild.flowNodeType as FlowNodeBaseType ) ) { node.collapsed = true; @@ -191,7 +191,7 @@ const collapse: ShortcutGetter = ctx => ({ }, }); -const expand: ShortcutGetter = ctx => ({ +const expand: ShortcutGetter = (ctx) => ({ commandId: FlowCommandId.EXPAND, commandDetail: { label: 'Expand', @@ -202,19 +202,19 @@ const expand: ShortcutGetter = ctx => ({ const selection = ctx.selection; const selectNodes = selection.selection.filter( - _entity => _entity instanceof FlowNodeEntity, + (_entity) => _entity instanceof FlowNodeEntity ) as FlowNodeEntity[]; selectNodes - .map(_node => [_node, ..._node.allCollapsedChildren]) + .map((_node) => [_node, ..._node.allCollapsedChildren]) .flat() - .forEach(node => { + .forEach((node) => { const renderData = node.getData(FlowNodeRenderData); if ( node.firstChild && [FlowNodeBaseType.BLOCK_ICON, FlowNodeBaseType.BLOCK_ORDER_ICON].includes( - node.firstChild.flowNodeType as FlowNodeBaseType, + node.firstChild.flowNodeType as FlowNodeBaseType ) ) { node.collapsed = false; diff --git a/apps/demo-free-layout-simple/.eslintrc.js b/apps/demo-free-layout-simple/.eslintrc.js index 02803479..9f8bd759 100644 --- a/apps/demo-free-layout-simple/.eslintrc.js +++ b/apps/demo-free-layout-simple/.eslintrc.js @@ -7,4 +7,9 @@ module.exports = defineConfig({ 'no-console': 'off', 'react/prop-types': 'off', }, + settings: { + react: { + version: 'detect', // 自动检测 React 版本 + }, + }, }); diff --git a/apps/demo-free-layout-simple/src/components/minimap.tsx b/apps/demo-free-layout-simple/src/components/minimap.tsx index 012b8ad3..6e35e0e5 100644 --- a/apps/demo-free-layout-simple/src/components/minimap.tsx +++ b/apps/demo-free-layout-simple/src/components/minimap.tsx @@ -1,7 +1,6 @@ import { FlowMinimapService, MinimapRender } from '@flowgram.ai/minimap-plugin'; import { useService } from '@flowgram.ai/free-layout-editor'; - export const Minimap = () => { const minimapService = useService(FlowMinimapService); return ( diff --git a/apps/demo-free-layout-simple/src/components/node-add-panel.tsx b/apps/demo-free-layout-simple/src/components/node-add-panel.tsx index 4e485ab3..ba7ede20 100644 --- a/apps/demo-free-layout-simple/src/components/node-add-panel.tsx +++ b/apps/demo-free-layout-simple/src/components/node-add-panel.tsx @@ -4,21 +4,23 @@ import { WorkflowDragService, useService } from '@flowgram.ai/free-layout-editor const cardkeys = ['Node1', 'Node2']; -export const NodeAddPanel: React.FC = props => { +export const NodeAddPanel: React.FC = (props) => { const startDragSerivce = useService(WorkflowDragService); return (
- {cardkeys.map(nodeType => ( + {cardkeys.map((nodeType) => (
startDragSerivce.startDragCard(nodeType, e, { - data: { - title: `New ${nodeType}`, - content: 'xxxx' - } - })} + onMouseDown={(e) => + startDragSerivce.startDragCard(nodeType, e, { + data: { + title: `New ${nodeType}`, + content: 'xxxx', + }, + }) + } > {nodeType}
diff --git a/apps/demo-free-layout-simple/src/components/tools.tsx b/apps/demo-free-layout-simple/src/components/tools.tsx index 3cce16a0..6f38bac3 100644 --- a/apps/demo-free-layout-simple/src/components/tools.tsx +++ b/apps/demo-free-layout-simple/src/components/tools.tsx @@ -1,4 +1,5 @@ -import { useEffect, useState } from 'react' +import { useEffect, useState } from 'react'; + import { usePlaygroundTools, useClientContext } from '@flowgram.ai/free-layout-editor'; export function Tools() { @@ -15,13 +16,21 @@ export function Tools() { return () => disposable.dispose(); }, [history]); - return
- - - - - - - {Math.floor(tools.zoom * 100)}% -
+ return ( +
+ + + + + + + {Math.floor(tools.zoom * 100)}% +
+ ); } diff --git a/apps/demo-free-layout-simple/src/editor.tsx b/apps/demo-free-layout-simple/src/editor.tsx index 3bf05b84..267f7012 100644 --- a/apps/demo-free-layout-simple/src/editor.tsx +++ b/apps/demo-free-layout-simple/src/editor.tsx @@ -1,17 +1,14 @@ -import { - EditorRenderer, - FreeLayoutEditorProvider, -} from '@flowgram.ai/free-layout-editor'; +import { EditorRenderer, FreeLayoutEditorProvider } from '@flowgram.ai/free-layout-editor'; +import { useEditorProps } from './hooks/use-editor-props'; +import { Tools } from './components/tools'; import { NodeAddPanel } from './components/node-add-panel'; -import { Tools } from './components/tools' -import { Minimap } from './components/minimap' -import { useEditorProps } from './hooks/use-editor-props' +import { Minimap } from './components/minimap'; import '@flowgram.ai/free-layout-editor/index.css'; import './index.css'; export const Editor = () => { - const editorProps = useEditorProps() + const editorProps = useEditorProps(); return (
@@ -23,5 +20,5 @@ export const Editor = () => {
- ) + ); }; diff --git a/apps/demo-free-layout-simple/src/hooks/use-editor-props.tsx b/apps/demo-free-layout-simple/src/hooks/use-editor-props.tsx index 4d3a8f11..84163317 100644 --- a/apps/demo-free-layout-simple/src/hooks/use-editor-props.tsx +++ b/apps/demo-free-layout-simple/src/hooks/use-editor-props.tsx @@ -1,19 +1,20 @@ import { useMemo } from 'react'; +import { createMinimapPlugin } from '@flowgram.ai/minimap-plugin'; +import { createFreeSnapPlugin } from '@flowgram.ai/free-snap-plugin'; import { FreeLayoutProps, WorkflowNodeProps, WorkflowNodeRenderer, Field, - useNodeRender + useNodeRender, } from '@flowgram.ai/free-layout-editor'; -import { createMinimapPlugin } from '@flowgram.ai/minimap-plugin'; -import { createFreeSnapPlugin } from '@flowgram.ai/free-snap-plugin'; +import { nodeRegistries } from '../node-registries'; import { initialData } from '../initial-data'; -import { nodeRegistries } from '../node-registries' -export const useEditorProps = () => useMemo( +export const useEditorProps = () => + useMemo( () => ({ /** * Whether to enable the background @@ -47,7 +48,8 @@ export const useEditorProps = () => useMemo( /** * Render form */ - render: () => <> + render: () => ( + <> name="title"> {({ field }) =>
{field.value}
} @@ -57,7 +59,8 @@ export const useEditorProps = () => useMemo(
- } + ), + }, }; }, materials: { @@ -65,12 +68,12 @@ export const useEditorProps = () => useMemo( * Render Node */ renderDefaultNode: (props: WorkflowNodeProps) => { - const { form } = useNodeRender() + const { form } = useNodeRender(); return ( {form?.render()} - ) + ); }, }, /** @@ -95,7 +98,7 @@ export const useEditorProps = () => useMemo( /** * Playground init */ - onInit: ctx => {}, + onInit: (ctx) => {}, /** * Playground render */ @@ -146,7 +149,7 @@ export const useEditorProps = () => useMemo( alignLineWidth: 1, alignCrossWidth: 8, }), - ] + ], }), - [], + [] ); diff --git a/apps/demo-free-layout-simple/src/initial-data.ts b/apps/demo-free-layout-simple/src/initial-data.ts index f9648dab..e23756e0 100644 --- a/apps/demo-free-layout-simple/src/initial-data.ts +++ b/apps/demo-free-layout-simple/src/initial-data.ts @@ -10,7 +10,7 @@ export const initialData: WorkflowJSON = { }, data: { title: 'Start', - content: 'Start content' + content: 'Start content', }, }, { @@ -21,7 +21,7 @@ export const initialData: WorkflowJSON = { }, data: { title: 'Custom', - content: 'Custom node content' + content: 'Custom node content', }, }, { @@ -32,7 +32,7 @@ export const initialData: WorkflowJSON = { }, data: { title: 'End', - content: 'End content' + content: 'End content', }, }, ], @@ -47,4 +47,3 @@ export const initialData: WorkflowJSON = { }, ], }; - diff --git a/apps/demo-free-layout-simple/src/node-registries.ts b/apps/demo-free-layout-simple/src/node-registries.ts index 81158f21..703a1f60 100644 --- a/apps/demo-free-layout-simple/src/node-registries.ts +++ b/apps/demo-free-layout-simple/src/node-registries.ts @@ -24,8 +24,7 @@ export const nodeRegistries: WorkflowNodeRegistry[] = [ }, { type: 'custom', - meta: { - }, + meta: {}, defaultPorts: [{ type: 'output' }, { type: 'input' }], // A normal node has two ports }, ]; diff --git a/apps/demo-free-layout/.eslintrc.js b/apps/demo-free-layout/.eslintrc.js index 02803479..9f8bd759 100644 --- a/apps/demo-free-layout/.eslintrc.js +++ b/apps/demo-free-layout/.eslintrc.js @@ -7,4 +7,9 @@ module.exports = defineConfig({ 'no-console': 'off', 'react/prop-types': 'off', }, + settings: { + react: { + version: 'detect', // 自动检测 React 版本 + }, + }, }); diff --git a/apps/demo-free-layout/src/components/selector-box-popover/index.tsx b/apps/demo-free-layout/src/components/selector-box-popover/index.tsx index 2a076209..482b56c2 100644 --- a/apps/demo-free-layout/src/components/selector-box-popover/index.tsx +++ b/apps/demo-free-layout/src/components/selector-box-popover/index.tsx @@ -22,7 +22,7 @@ export const SelectorBoxPopover: FunctionComponent = ({ top: bounds.top, transform: 'translate(-100%, -100%)', }} - onMouseDown={e => { + onMouseDown={(e) => { e.stopPropagation(); }} > @@ -36,7 +36,7 @@ export const SelectorBoxPopover: FunctionComponent = ({ style={{ height: BUTTON_HEIGHT }} type="primary" theme="solid" - onMouseDown={e => { + onMouseDown={(e) => { commandRegistry.executeCommand(FlowCommandId.COLLAPSE); }} /> @@ -48,7 +48,7 @@ export const SelectorBoxPopover: FunctionComponent = ({ style={{ height: BUTTON_HEIGHT }} type="primary" theme="solid" - onMouseDown={e => { + onMouseDown={(e) => { commandRegistry.executeCommand(FlowCommandId.EXPAND); }} /> diff --git a/apps/demo-free-layout/src/components/tools/interactive.tsx b/apps/demo-free-layout/src/components/tools/interactive.tsx index f8d73d4a..188d5b5a 100644 --- a/apps/demo-free-layout/src/components/tools/interactive.tsx +++ b/apps/demo-free-layout/src/components/tools/interactive.tsx @@ -4,6 +4,9 @@ import { usePlaygroundTools, type InteractiveType as IdeInteractiveType, } from '@flowgram.ai/free-layout-editor'; +import { Tooltip, Popover } from '@douyinfe/semi-ui'; + +import { MousePadSelector } from './mouse-pad-selector'; export const CACHE_KEY = 'workflow_prefer_interactive_type'; export const SHOW_KEY = 'show_workflow_interactive_type_guide'; @@ -25,9 +28,6 @@ export enum InteractiveType { Mouse = 'MOUSE', Pad = 'PAD', } -import { Tooltip, Popover } from '@douyinfe/semi-ui'; - -import { MousePadSelector } from './mouse-pad-selector'; export const Interactive = () => { const tools = usePlaygroundTools(); diff --git a/apps/demo-free-layout/src/editor.tsx b/apps/demo-free-layout/src/editor.tsx index 60780d04..54587a3c 100644 --- a/apps/demo-free-layout/src/editor.tsx +++ b/apps/demo-free-layout/src/editor.tsx @@ -1,11 +1,11 @@ import { EditorRenderer, FreeLayoutEditorProvider } from '@flowgram.ai/free-layout-editor'; -import { DemoTools } from './components/tools'; import '@flowgram.ai/free-layout-editor/index.css'; import './styles/index.css'; import { nodeRegistries } from './nodes'; import { initialData } from './initial-data'; import { useEditorProps } from './hooks'; +import { DemoTools } from './components/tools'; export const Editor = () => { const editorProps = useEditorProps(initialData, nodeRegistries); diff --git a/apps/demo-free-layout/src/form-components/feedback.tsx b/apps/demo-free-layout/src/form-components/feedback.tsx index b9b6e343..46802b65 100644 --- a/apps/demo-free-layout/src/form-components/feedback.tsx +++ b/apps/demo-free-layout/src/form-components/feedback.tsx @@ -20,7 +20,7 @@ const Warning = styled.span` export const Feedback = ({ errors, warnings, invalid }: StatePanelProps) => { const renderFeedbacks = (fs: FieldError[] | FieldWarning[] | undefined) => { if (!fs) return null; - return fs.map(f => {f.message}); + return fs.map((f) => {f.message}); }; return (
diff --git a/apps/demo-free-layout/src/form-components/form-header/index.tsx b/apps/demo-free-layout/src/form-components/form-header/index.tsx index d23f44fc..350502ea 100644 --- a/apps/demo-free-layout/src/form-components/form-header/index.tsx +++ b/apps/demo-free-layout/src/form-components/form-header/index.tsx @@ -71,7 +71,7 @@ export function FormHeader() { size="small" theme="borderless" icon={} - onClick={e => e.stopPropagation()} + onClick={(e) => e.stopPropagation()} /> diff --git a/apps/demo-free-layout/src/form-components/form-inputs/index.tsx b/apps/demo-free-layout/src/form-components/form-inputs/index.tsx index cd1cba8d..18dc08cc 100644 --- a/apps/demo-free-layout/src/form-components/form-inputs/index.tsx +++ b/apps/demo-free-layout/src/form-components/form-inputs/index.tsx @@ -18,7 +18,7 @@ export function FormInputs() { if (!properties) { return <>; } - const content = Object.keys(properties).map(key => { + const content = Object.keys(properties).map((key) => { const property = properties[key]; return ( diff --git a/apps/demo-free-layout/src/form-components/form-item/index.tsx b/apps/demo-free-layout/src/form-components/form-item/index.tsx index 32f83624..698324e5 100644 --- a/apps/demo-free-layout/src/form-components/form-item/index.tsx +++ b/apps/demo-free-layout/src/form-components/form-item/index.tsx @@ -32,7 +32,7 @@ export function FormItem({ {required && *}
), - [], + [] ); return (
{ const properties = field.value?.properties; if (properties) { - const content = Object.keys(properties).map(key => { + const content = Object.keys(properties).map((key) => { const property = properties[key]; return ; }); diff --git a/apps/demo-free-layout/src/form-components/properties-edit/index.tsx b/apps/demo-free-layout/src/form-components/properties-edit/index.tsx index 9d88e0be..18ea4d81 100644 --- a/apps/demo-free-layout/src/form-components/properties-edit/index.tsx +++ b/apps/demo-free-layout/src/form-components/properties-edit/index.tsx @@ -13,7 +13,7 @@ export interface PropertiesEditProps { useFx?: boolean; } -export const PropertiesEdit: React.FC = props => { +export const PropertiesEdit: React.FC = (props) => { const value = (props.value || {}) as Record; const { readonly } = useContext(NodeRenderContext); const [newProperty, updateNewPropertyFromCache] = useState<{ key: string; value: JsonSchema }>({ @@ -28,7 +28,7 @@ export const PropertiesEdit: React.FC = props => { const updateProperty = ( propertyValue: JsonSchema, propertyKey: string, - newPropertyKey?: string, + newPropertyKey?: string ) => { const newValue = { ...value }; if (newPropertyKey) { @@ -42,7 +42,7 @@ export const PropertiesEdit: React.FC = props => { const updateNewProperty = ( propertyValue: JsonSchema, propertyKey: string, - newPropertyKey?: string, + newPropertyKey?: string ) => { // const newValue = { ...value } if (newPropertyKey) { @@ -59,7 +59,7 @@ export const PropertiesEdit: React.FC = props => { }; return ( <> - {Object.keys(props.value || {}).map(key => { + {Object.keys(props.value || {}).map((key) => { const property = (value[key] || {}) as JsonSchema; return ( childField.onChange({ key: childField.value.key, value: v })} + onChange={(v) => childField.onChange({ key: childField.value.key, value: v })} icon={