feat(material): form materials and add scripts (#196)

This commit is contained in:
Yiwei Mao 2025-05-08 20:06:49 +08:00 committed by GitHub
parent 19ff04abc7
commit 79e4bb0556
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
45 changed files with 1271 additions and 961 deletions

View File

@ -32,6 +32,7 @@
"@douyinfe/semi-ui": "^2.72.3",
"@flowgram.ai/fixed-layout-editor": "workspace:*",
"@flowgram.ai/fixed-semi-materials": "workspace:*",
"@flowgram.ai/form-materials": "workspace:*",
"@flowgram.ai/group-plugin": "workspace:*",
"@flowgram.ai/minimap-plugin": "workspace:*",
"lodash-es": "^4.17.21",

View File

@ -1,10 +1,10 @@
import React, { type SVGProps } from 'react';
import { VariableSelector } from '@flowgram.ai/form-materials';
import { Input, Button } from '@douyinfe/semi-ui';
import { ValueDisplay } from '../value-display';
import { FlowRefValueSchema, FlowLiteralValueSchema } from '../../typings';
import { VariableSelector } from '../../plugins/sync-variable-plugin/variable-selector';
export function FxIcon(props: SVGProps<SVGSVGElement>) {
return (

View File

@ -1,11 +1,11 @@
import React, { useState, useLayoutEffect } from 'react';
import { VariableSelector } from '@flowgram.ai/form-materials';
import { Input, Button } from '@douyinfe/semi-ui';
import { IconCrossCircleStroked } from '@douyinfe/semi-icons';
import { TypeSelector } from '../type-selector';
import { JsonSchema } from '../../typings';
import { VariableSelector } from '../../plugins/sync-variable-plugin/variable-selector';
import { LeftColumn, Row } from './styles';
export interface PropertyEditProps {

View File

@ -1,9 +1,8 @@
import React from 'react';
import { VariableTypeIcons } from '@flowgram.ai/form-materials';
import { Tag, Dropdown } from '@douyinfe/semi-ui';
import { VariableTypeIcons } from '../plugins/sync-variable-plugin/icons';
export interface TypeSelectorProps {
value?: string;
disabled?: boolean;

View File

@ -1,8 +1,7 @@
import styled from 'styled-components';
import { VariableTypeIcons, ArrayIcons } from '@flowgram.ai/form-materials';
import { Tag, Tooltip } from '@douyinfe/semi-ui';
import { VariableTypeIcons, ArrayIcons } from '../plugins/sync-variable-plugin/icons';
interface PropsType {
name?: string | JSX.Element;
type: string;

View File

@ -1,3 +1,4 @@
import { JsonSchemaEditor } from '@flowgram.ai/form-materials';
import {
Field,
FieldRenderProps,
@ -8,7 +9,7 @@ import {
import { FlowNodeJSON, JsonSchema } from '../../typings';
import { useIsSidebar } from '../../hooks';
import { FormHeader, FormContent, FormOutputs, PropertiesEdit } from '../../form-components';
import { FormHeader, FormContent, FormOutputs } from '../../form-components';
export const renderForm = ({ form }: FormRenderProps<FlowNodeJSON['data']>) => {
const isSidebar = useIsSidebar();
@ -18,13 +19,13 @@ export const renderForm = ({ form }: FormRenderProps<FlowNodeJSON['data']>) => {
<FormHeader />
<FormContent>
<Field
name="outputs.properties"
render={({
field: { value, onChange },
fieldState,
}: FieldRenderProps<Record<string, JsonSchema>>) => (
name="outputs"
render={({ field: { value, onChange } }: FieldRenderProps<JsonSchema>) => (
<>
<PropertiesEdit value={value} onChange={onChange} />
<JsonSchemaEditor
value={value}
onChange={(value) => onChange(value as JsonSchema)}
/>
</>
)}
/>

View File

@ -49,7 +49,8 @@ export const createSyncVariablePlugin: PluginCreator<SyncVariablePluginOptions>
variableData.setVar(
ASTFactory.createVariableDeclaration({
meta: {
title: `${title}.outputs`,
title: `${title}`,
icon: node.getNodeRegistry()?.info?.icon,
// NOTICE: You can add more metadata here as needed
},
key: `${node.id}.outputs`,

View File

@ -1,68 +0,0 @@
.option-select-item-container {
display: flex;
align-items: flex-start;
.icon {
flex-shrink: 0;
margin-top: 2px;
margin-right: 5px;
}
.text {
word-break: break-all;
white-space: pre-wrap;
}
.error-text {
word-break: break-all;
color: red;
white-space: pre-wrap;
margin-top: 2px;
}
}
.prefix-icon {
margin-left: 2px;
display: inline-block;
padding: 0 2px;
height: 16px;
svg {
scale: 0.7;
}
}
.option-type-icon {
height: 14px;
margin-right: 6px;
svg {
width: 14px;
height: 14px;
}
}
.tree-select {
:global {
.semi-tree-select-selection {
padding-left: 4px;
}
.semi-tree-select-arrow,
.semi-tree-select-clearbtn {
width: 16px;
svg {
scale: 0.7;
}
}
}
}
.description-icon {
margin-left: 3px;
scale: 0.8;
vertical-align: text-top;
}

View File

@ -1,94 +0,0 @@
import React from 'react';
import { type TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
import { TreeSelect } from '@douyinfe/semi-ui';
import { type JsonSchema } from '../../../typings';
import { ValueDisplay } from '../../../form-components';
import { useVariableTree } from './use-variable-tree';
export interface VariableSelectorProps {
value?: string;
onChange: (value?: string) => void;
options?: {
size?: 'small' | 'large' | 'default';
emptyContent?: JSX.Element;
targetSchemas?: JsonSchema[];
strongEqualToTargetSchema?: boolean;
};
hasError?: boolean;
style?: React.CSSProperties;
readonly?: boolean;
}
export const VariableSelector = ({
value,
onChange,
options,
readonly,
style,
hasError,
}: VariableSelectorProps) => {
const { size = 'small', emptyContent, targetSchemas, strongEqualToTargetSchema } = options || {};
if (readonly) {
return <ValueDisplay value={value as string} hasError={hasError} />;
}
const treeData = useVariableTree<TreeNodeData>({
targetSchemas,
strongEqual: strongEqualToTargetSchema,
ignoreReadonly: true,
getTreeData: ({ variable, key, icon, children, disabled, parentFields }) => ({
key,
value: key,
icon: (
<span
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
marginRight: 4,
}}
>
{icon}
</span>
),
label: variable.meta?.expressionTitle || variable.key || '',
disabled,
labelPath: [...parentFields, variable]
.map((_field) => _field.meta?.expressionTitle || _field.key || '')
.join('.'),
children,
}),
});
const renderEmpty = () => {
if (emptyContent) {
return emptyContent;
}
return 'nodata';
};
return (
<>
<TreeSelect
dropdownMatchSelectWidth={false}
treeData={treeData}
size={size}
value={value}
style={{
...style,
outline: hasError ? '1px solid red' : undefined,
}}
validateStatus={hasError ? 'error' : undefined}
onChange={(option) => {
onChange(option as string);
}}
showClear
placeholder="Select Variable..."
emptyContent={renderEmpty()}
/>
</>
);
};

View File

@ -1,134 +0,0 @@
import { useCallback, useMemo } from 'react';
import {
ASTFactory,
ASTKind,
type BaseType,
type UnionJSON,
useScopeAvailable,
ASTMatch,
} from '@flowgram.ai/fixed-layout-editor';
import { createASTFromJSONSchema } from '../utils';
import { ArrayIcons, VariableTypeIcons } from '../icons';
import { type JsonSchema } from '../../../typings';
type VariableField = any;
interface HooksParams<TreeData> {
// filter target type
targetSchemas?: JsonSchema[];
// Is it strongly type-checked?
strongEqual?: boolean;
// ignore global Config
ignoreReadonly?: boolean;
// render tree node
getTreeData: (props: {
key: string;
icon: JSX.Element | undefined;
variable: VariableField;
parentFields: VariableField[];
disabled?: boolean;
children?: TreeData[];
}) => TreeData;
}
export function useVariableTree<TreeData>({
targetSchemas = [],
strongEqual = false,
ignoreReadonly = false,
getTreeData,
}: HooksParams<TreeData>): TreeData[] {
const available = useScopeAvailable();
const getVariableTypeIcon = useCallback((variable: VariableField) => {
const _type = variable.type;
if (ASTMatch.isArray(_type)) {
return (
(ArrayIcons as any)[_type.items?.kind.toLowerCase()] ||
VariableTypeIcons[ASTKind.Array.toLowerCase()]
);
}
if (ASTMatch.isCustomType(_type)) {
return VariableTypeIcons[_type.typeName.toLowerCase()];
}
return (VariableTypeIcons as any)[variable.type?.kind.toLowerCase()];
}, []);
const targetTypeAST: UnionJSON = useMemo(
() =>
ASTFactory.createUnion({
types: targetSchemas.map((_targetSchema) => {
const typeAst = createASTFromJSONSchema(_targetSchema)!;
return strongEqual ? typeAst : { ...typeAst, weak: true };
}),
}),
[strongEqual, ...targetSchemas]
);
const checkTypeFiltered = useCallback(
(type?: BaseType) => {
if (!type) {
return true;
}
if (targetTypeAST.types?.length) {
return !type.isTypeEqual(targetTypeAST);
}
return false;
},
[strongEqual, targetTypeAST]
);
const renderVariable = (
variable: VariableField,
parentFields: VariableField[] = []
): TreeData | null => {
let type = variable?.type;
const isTypeFiltered = checkTypeFiltered(type);
let children: TreeData[] | undefined;
if (ASTMatch.isObject(type)) {
children = (type.properties || [])
.map((_property) => renderVariable(_property as VariableField, [...parentFields, variable]))
.filter(Boolean) as TreeData[];
}
if (isTypeFiltered && !children?.length) {
return null;
}
const currPath = [
...parentFields.map((_field) => _field.meta?.titleKey || _field.key),
variable.meta?.titleKey || variable.key,
].join('.');
return getTreeData({
key: currPath,
icon: getVariableTypeIcon(variable),
variable,
parentFields,
children,
disabled: isTypeFiltered,
});
};
return [
...available.variables
.filter((_v) => {
if (ignoreReadonly) {
return !_v.meta?.readonly;
}
return true;
})
.slice(0)
.reverse(),
]
.map((_variable) => renderVariable(_variable as VariableField))
.filter(Boolean) as TreeData[];
}

View File

@ -1,64 +1,65 @@
{
"name": "@flowgram.ai/demo-free-layout",
"version": "0.1.0",
"description": "",
"keywords": [],
"license": "MIT",
"main": "./src/index.ts",
"files": [
"src/",
".eslintrc.js",
".gitignore",
"index.html",
"package.json",
"rsbuild.config.ts",
"tsconfig.json"
],
"scripts": {
"build": "exit 0",
"build:fast": "exit 0",
"build:watch": "exit 0",
"clean": "rimraf dist",
"dev": "cross-env MODE=app NODE_ENV=development rsbuild dev --open",
"lint": "eslint ./src --cache",
"lint:fix": "eslint ./src --fix",
"start": "cross-env NODE_ENV=development rsbuild dev --open",
"test": "exit",
"test:cov": "exit",
"watch": "exit 0"
},
"dependencies": {
"@douyinfe/semi-icons": "^2.72.3",
"@douyinfe/semi-ui": "^2.72.3",
"@flowgram.ai/free-layout-editor": "workspace:*",
"@flowgram.ai/free-snap-plugin": "workspace:*",
"@flowgram.ai/free-lines-plugin": "workspace:*",
"@flowgram.ai/free-node-panel-plugin": "workspace:*",
"@flowgram.ai/minimap-plugin": "workspace:*",
"@flowgram.ai/free-container-plugin": "workspace:*",
"@flowgram.ai/free-group-plugin": "workspace:*",
"lodash-es": "^4.17.21",
"nanoid": "^4.0.2",
"react": "^18",
"react-dom": "^18",
"styled-components": "^5"
},
"devDependencies": {
"@flowgram.ai/ts-config": "workspace:*",
"@flowgram.ai/eslint-config": "workspace:*",
"@rsbuild/core": "^1.2.16",
"@rsbuild/plugin-react": "^1.1.1",
"@rsbuild/plugin-less": "^1.1.1",
"@types/lodash-es": "^4.17.12",
"@types/node": "^18",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/styled-components": "^5",
"eslint": "^8.54.0",
"cross-env": "~7.0.3"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
"name": "@flowgram.ai/demo-free-layout",
"version": "0.1.0",
"description": "",
"keywords": [],
"license": "MIT",
"main": "./src/index.ts",
"files": [
"src/",
".eslintrc.js",
".gitignore",
"index.html",
"package.json",
"rsbuild.config.ts",
"tsconfig.json"
],
"scripts": {
"build": "exit 0",
"build:fast": "exit 0",
"build:watch": "exit 0",
"clean": "rimraf dist",
"dev": "cross-env MODE=app NODE_ENV=development rsbuild dev --open",
"lint": "eslint ./src --cache",
"lint:fix": "eslint ./src --fix",
"start": "cross-env NODE_ENV=development rsbuild dev --open",
"test": "exit",
"test:cov": "exit",
"watch": "exit 0"
},
"dependencies": {
"@douyinfe/semi-icons": "^2.72.3",
"@douyinfe/semi-ui": "^2.72.3",
"@flowgram.ai/free-layout-editor": "workspace:*",
"@flowgram.ai/free-snap-plugin": "workspace:*",
"@flowgram.ai/free-lines-plugin": "workspace:*",
"@flowgram.ai/free-node-panel-plugin": "workspace:*",
"@flowgram.ai/minimap-plugin": "workspace:*",
"@flowgram.ai/free-container-plugin": "workspace:*",
"@flowgram.ai/free-group-plugin": "workspace:*",
"@flowgram.ai/form-materials": "workspace:*",
"lodash-es": "^4.17.21",
"nanoid": "^4.0.2",
"react": "^18",
"react-dom": "^18",
"styled-components": "^5"
},
"devDependencies": {
"@flowgram.ai/ts-config": "workspace:*",
"@flowgram.ai/eslint-config": "workspace:*",
"@rsbuild/core": "^1.2.16",
"@rsbuild/plugin-react": "^1.1.1",
"@rsbuild/plugin-less": "^1.1.1",
"@types/lodash-es": "^4.17.12",
"@types/node": "^18",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/styled-components": "^5",
"eslint": "^8.54.0",
"cross-env": "~7.0.3"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}

View File

@ -1,10 +1,10 @@
import React, { type SVGProps } from 'react';
import { VariableSelector } from '@flowgram.ai/form-materials';
import { Input, Button } from '@douyinfe/semi-ui';
import { ValueDisplay } from '../value-display';
import { FlowRefValueSchema, FlowLiteralValueSchema } from '../../typings';
import { VariableSelector } from '../../plugins/sync-variable-plugin/variable-selector';
export function FxIcon(props: SVGProps<SVGSVGElement>) {
return (

View File

@ -1,11 +1,11 @@
import React, { useState, useLayoutEffect } from 'react';
import { VariableSelector } from '@flowgram.ai/form-materials';
import { Input, Button } from '@douyinfe/semi-ui';
import { IconCrossCircleStroked } from '@douyinfe/semi-icons';
import { TypeSelector } from '../type-selector';
import { JsonSchema } from '../../typings';
import { VariableSelector } from '../../plugins/sync-variable-plugin/variable-selector';
import { LeftColumn, Row } from './styles';
export interface PropertyEditProps {

View File

@ -1,9 +1,8 @@
import React from 'react';
import { VariableTypeIcons } from '@flowgram.ai/form-materials';
import { Tag, Dropdown } from '@douyinfe/semi-ui';
import { VariableTypeIcons } from '../plugins/sync-variable-plugin/icons';
export interface TypeSelectorProps {
value?: string;
disabled?: boolean;

View File

@ -1,8 +1,7 @@
import styled from 'styled-components';
import { VariableTypeIcons, ArrayIcons } from '@flowgram.ai/form-materials';
import { Tag, Tooltip } from '@douyinfe/semi-ui';
import { VariableTypeIcons, ArrayIcons } from '../plugins/sync-variable-plugin/icons';
interface PropsType {
name?: string | JSX.Element;
type: string;

View File

@ -5,10 +5,11 @@ import {
FormMeta,
ValidateTrigger,
} from '@flowgram.ai/free-layout-editor';
import { JsonSchemaEditor } from '@flowgram.ai/form-materials';
import { FlowNodeJSON, JsonSchema } from '../../typings';
import { useIsSidebar } from '../../hooks';
import { FormHeader, FormContent, FormOutputs, PropertiesEdit } from '../../form-components';
import { FormHeader, FormContent, FormOutputs } from '../../form-components';
export const renderForm = ({ form }: FormRenderProps<FlowNodeJSON>) => {
const isSidebar = useIsSidebar();
@ -18,13 +19,13 @@ export const renderForm = ({ form }: FormRenderProps<FlowNodeJSON>) => {
<FormHeader />
<FormContent>
<Field
name="outputs.properties"
render={({
field: { value, onChange },
fieldState,
}: FieldRenderProps<Record<string, JsonSchema>>) => (
name="outputs"
render={({ field: { value, onChange } }: FieldRenderProps<JsonSchema>) => (
<>
<PropertiesEdit value={value} onChange={onChange} />
<JsonSchemaEditor
value={value}
onChange={(value) => onChange(value as JsonSchema)}
/>
</>
)}
/>

View File

@ -1,265 +0,0 @@
export const VariableTypeIcons: { [key: string]: React.ReactNode } = {
custom: (
<svg
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
focusable="false"
aria-hidden="true"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M5.1 18L4.5032 20.1702C4.24999 21.0909 4.94281 22 5.89773 22C6.54881 22 7.11964 21.565 7.29227 20.9372L8.1 18H12.1L11.5032 20.1702C11.25 21.0909 11.9428 22 12.8977 22C13.5488 22 14.1196 21.565 14.2923 20.9372L15.1 18H19.5C20.3284 18 21 17.3284 21 16.5C21 15.6716 20.3284 15 19.5 15H15.925L17.575 9H20.5C21.3284 9 22 8.32843 22 7.5C22 6.67157 21.3284 6 20.5 6H18.4L18.9968 3.8298C19.25 2.90906 18.5572 2 17.6023 2C16.9512 2 16.3804 2.43504 16.2077 3.06281L15.4 6H11.4L11.9968 3.8298C12.25 2.90906 11.5572 2 10.6023 2C9.95119 2 9.38036 2.43504 9.20773 3.06281L8.4 6H4.5C3.67157 6 3 6.67157 3 7.5C3 8.32843 3.67157 9 4.5 9H7.575L5.925 15H3.5C2.67157 15 2 15.6716 2 16.5C2 17.3284 2.67157 18 3.5 18H5.1ZM8.925 15L10.575 9H14.575L12.925 15H8.925Z"
fill="currentColor"
></path>
</svg>
),
object: (
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M5.33893 1.5835C5.66613 1.5835 5.93137 1.88142 5.93137 2.20862C5.93137 2.53582 5.66613 2.76838 5.33893 2.76838H4.9099C4.34717 2.76838 4.08062 3.07557 4.08062 3.71921V6.58633C4.08062 7.30996 3.80723 7.84734 3.26798 8.19105C3.11426 8.28902 3.10884 8.55273 3.26068 8.65359C3.80476 9.01503 4.08062 9.53994 4.08062 10.2434V13.1251C4.08062 13.7395 4.34717 14.0613 4.9099 14.0613H5.33893C5.66613 14.0613 5.93137 14.3435 5.93137 14.6707C5.93137 14.9979 5.66613 15.2462 5.33893 15.2462H4.64335C3.99177 15.2462 3.48828 15.0268 3.13287 14.6172C2.80708 14.2369 2.64419 13.7103 2.64419 13.0666V10.3165C2.64419 9.8923 2.55534 9.58511 2.37764 9.39494C2.26816 9.27135 1.80618 9.17938 1.38154 9.11602C1.02726 9.06315 0.759057 8.76744 0.765747 8.4093C0.772379 8.0543 1.03439 7.7566 1.38545 7.70346C1.80778 7.63952 2.26906 7.54968 2.37764 7.43477C2.55534 7.22997 2.64419 6.92278 2.64419 6.51319V3.77772C2.64419 3.11945 2.80708 2.59284 3.13287 2.21251C3.48828 1.78829 3.99177 1.5835 4.64335 1.5835H5.33893Z"
fill="currentColor"
/>
<path
d="M10.962 15.2463C10.6348 15.2463 10.3696 14.9483 10.3696 14.6211C10.3696 14.2939 10.6348 14.0614 10.962 14.0614H11.391C11.9538 14.0614 12.2203 13.7542 12.2203 13.1105V10.2434C12.2203 9.51979 12.4937 8.98241 13.033 8.6387C13.1867 8.54073 13.1921 8.27703 13.0403 8.17616C12.4962 7.81472 12.2203 7.28982 12.2203 6.58638V3.70463C12.2203 3.09024 11.9538 2.76842 11.391 2.76842L10.962 2.76842C10.6348 2.76842 10.3696 2.48627 10.3696 2.15907C10.3696 1.83188 10.6348 1.58354 10.962 1.58354L11.6576 1.58354C12.3092 1.58354 12.8127 1.80296 13.1681 2.21255C13.4939 2.59289 13.6568 3.1195 13.6568 3.76314V6.51324C13.6568 6.93745 13.7456 7.24464 13.9233 7.43481C14.03 7.5553 14.4328 7.64858 14.8186 7.71393C15.1718 7.77376 15.4401 8.06977 15.4334 8.42791C15.4268 8.78291 15.1646 9.08018 14.814 9.13633C14.4306 9.19774 14.0291 9.28303 13.9233 9.39499C13.7456 9.59978 13.6568 9.90697 13.6568 10.3166V13.052C13.6568 13.7103 13.4939 14.2369 13.1681 14.6172C12.8127 15.0415 12.3092 15.2463 11.6576 15.2463H10.962Z"
fill="currentColor"
/>
</svg>
),
boolean: (
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M10.668 4.66683H5.33463C3.49369 4.66683 2.0013 6.15921 2.0013 8.00016C2.0013 9.84111 3.49369 11.3335 5.33463 11.3335H10.668C12.5089 11.3335 14.0013 9.84111 14.0013 8.00016C14.0013 6.15921 12.5089 4.66683 10.668 4.66683ZM5.33463 3.3335C2.75731 3.3335 0.667969 5.42283 0.667969 8.00016C0.667969 10.5775 2.75731 12.6668 5.33463 12.6668H10.668C13.2453 12.6668 15.3346 10.5775 15.3346 8.00016C15.3346 5.42283 13.2453 3.3335 10.668 3.3335H5.33463Z"
fill="currentColor"
/>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M8.66797 8.00016C8.66797 6.89559 9.5634 6.00016 10.668 6.00016C11.7725 6.00016 12.668 6.89559 12.668 8.00016C12.668 9.10473 11.7725 10.0002 10.668 10.0002C9.5634 10.0002 8.66797 9.10473 8.66797 8.00016ZM10.668 7.3335C10.2998 7.3335 10.0013 7.63197 10.0013 8.00016C10.0013 8.36835 10.2998 8.66683 10.668 8.66683C11.0362 8.66683 11.3346 8.36835 11.3346 8.00016C11.3346 7.63197 11.0362 7.3335 10.668 7.3335Z"
fill="currentColor"
/>
</svg>
),
string: (
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M9.3342 3.33321C8.96601 3.33321 8.66753 3.63169 8.66753 3.99988C8.66753 4.36807 8.96601 4.66655 9.3342 4.66655H14.6675C15.0357 4.66655 15.3342 4.36807 15.3342 3.99988C15.3342 3.63169 15.0357 3.33321 14.6675 3.33321H9.3342Z"
fill="currentColor"
/>
<path
d="M10.0009 7.99988C10.0009 7.63169 10.2993 7.33321 10.6675 7.33321H14.6675C15.0357 7.33321 15.3342 7.63169 15.3342 7.99988C15.3342 8.36807 15.0357 8.66655 14.6675 8.66655H10.6675C10.2993 8.66655 10.0009 8.36807 10.0009 7.99988Z"
fill="currentColor"
/>
<path
d="M12.0009 11.3332C11.6327 11.3332 11.3342 11.6317 11.3342 11.9999C11.3342 12.3681 11.6327 12.6665 12.0009 12.6665H14.6675C15.0357 12.6665 15.3342 12.3681 15.3342 11.9999C15.3342 11.6317 15.0357 11.3332 14.6675 11.3332H12.0009Z"
fill="currentColor"
/>
<path
d="M9.86659 14.1482L8.23444 10.1844H3.18136C3.13868 10.1844 3.09685 10.1808 3.05616 10.1738L1.66589 14.1129C1.53049 14.4965 1.10971 14.6978 0.726058 14.5624C0.342408 14.427 0.141166 14.0062 0.276572 13.6225L4.37566 2.00848C4.71323 1.05202 6.05321 1.01763 6.4394 1.95552L11.2289 13.5872C11.3838 13.9634 11.2044 14.394 10.8282 14.5489C10.452 14.7038 10.0215 14.5244 9.86659 14.1482ZM5.44412 3.40791L3.57241 8.71109H7.62778L5.44412 3.40791Z"
fill="currentColor"
/>
</svg>
),
integer: (
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M15.132 11.4601C15.644 11.0121 15.9 10.3921 15.9 9.60007C15.9 8.60807 15.5 7.93607 14.7 7.58407C15.412 7.23207 15.768 6.62407 15.768 5.76007C15.768 5.05607 15.536 4.48007 15.072 4.03207C14.608 3.59207 14.012 3.37207 13.284 3.37207C12.588 3.37207 12.008 3.58007 11.544 3.99607C11.064 4.42007 10.808 4.98807 10.776 5.70007H12C12.064 4.88407 12.492 4.47607 13.284 4.47607C14.124 4.47607 14.544 4.91607 14.544 5.79607C14.544 6.66007 14.112 7.09207 13.248 7.09207H13.044V8.16007H13.248C14.2 8.16007 14.676 8.62807 14.676 9.56407C14.676 10.5081 14.212 10.9801 13.284 10.9801C12.9 10.9801 12.584 10.8761 12.336 10.6681C12.064 10.4441 11.916 10.1161 11.892 9.68407H10.668C10.692 10.4761 10.964 11.0841 11.484 11.5081C11.948 11.8921 12.548 12.0841 13.284 12.0841C14.036 12.0841 14.652 11.8761 15.132 11.4601Z"
fill="currentColor"
/>
<path
d="M4.46875 12.0003V10.9083L7.75675 6.91228C8.06075 6.54428 8.21275 6.16428 8.21275 5.77228C8.21275 4.90828 7.79675 4.47628 6.96475 4.47628C6.60475 4.47628 6.31275 4.57628 6.08875 4.77628C5.83275 5.00828 5.70475 5.34828 5.70475 5.79628H4.48075C4.48075 5.07628 4.71275 4.49228 5.17675 4.04428C5.64075 3.60428 6.23675 3.38428 6.96475 3.38428C7.70075 3.38428 8.29675 3.60028 8.75275 4.03228C9.20875 4.47228 9.43675 5.05628 9.43675 5.78428C9.43675 6.13628 9.36875 6.45628 9.23275 6.74428C9.12075 6.97628 8.92075 7.27228 8.63275 7.63228L5.95675 10.9083H9.43675V12.0003H4.46875Z"
fill="currentColor"
/>
<path
d="M1.668 12.0001V4.78805L0 6.25205V4.89605L1.668 3.45605H2.892V12.0001H1.668Z"
fill="currentColor"
/>
</svg>
),
number: (
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M3.44151 5.3068C3.44151 3.83404 4.71542 2.64014 6.18818 2.64014C7.66094 2.64014 8.93484 3.83404 8.93484 5.3068V10.6135C8.93484 12.0862 7.66094 13.2801 6.18818 13.2801C4.71542 13.2801 3.44151 12.0862 3.44151 10.6135V5.3068ZM7.60151 5.3068C7.60151 4.57042 6.92456 3.97347 6.18818 3.97347C5.4518 3.97347 4.77484 4.57042 4.77484 5.3068V10.6135C4.77484 11.3498 5.4518 11.9468 6.18818 11.9468C6.92456 11.9468 7.60151 11.3498 7.60151 10.6135V5.3068Z"
fill="currentColor"
/>
<path
d="M12.9882 2.64014C11.5154 2.64014 10.2415 3.83404 10.2415 5.3068V10.6135C10.2415 12.0862 11.5154 13.2801 12.9882 13.2801C14.4609 13.2801 15.7348 12.0862 15.7348 10.6135V5.3068C15.7348 3.83404 14.4609 2.64014 12.9882 2.64014ZM14.4015 10.6135C14.4015 11.3498 13.7246 11.9468 12.9882 11.9468C12.2518 11.9468 11.5748 11.3498 11.5748 10.6135V5.3068C11.5748 4.57042 12.2518 3.97347 12.9882 3.97347C13.7246 3.97347 14.4015 4.57042 14.4015 5.3068V10.6135Z"
fill="currentColor"
/>
<path
d="M1.21484 13.2001C1.76713 13.2001 2.21484 12.7524 2.21484 12.2001C2.21484 11.6479 1.76713 11.2001 1.21484 11.2001C0.662559 11.2001 0.214844 11.6479 0.214844 12.2001C0.214844 12.7524 0.662559 13.2001 1.21484 13.2001Z"
fill="currentColor"
/>
</svg>
),
array: (
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M5.23759 1.00342H2.00391V14.997H5.23759V13.6251H3.35127V2.37534H5.23759V1.00342Z"
fill="currentColor"
/>
<path
d="M10.7624 1.00342H13.9961V14.997H10.7624V13.6251H12.6487V2.37534H10.7624V1.00342Z"
fill="currentColor"
/>
</svg>
),
stream: (
<svg
viewBox="0 0 1024 1024"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
>
<path
d="M879.674 544.51l-158.254-0.221c-8.534 2.287-17.305-2.776-19.588-11.307l-23.862-75.877-74.742 350.891c0 0-1.523 18.507-11.518 18.507s-26.9 0.281-26.9 0.281c-8.259 2.213-16.748-2.687-18.961-10.949l-92.741-457.648-70.305 330.634c-2.261 8.291-11.94 15.206-20.385 12.986l-24.876 0.339c-8.723 2.293-17.685-2.789-20.023-11.349L270.629 544.51 143.993 544.51c-8.831 0-15.993-7.159-15.993-15.993l0-31.986c0-8.831 7.162-15.993 15.993-15.993l157.429-0.516c9.565-0.304 17.685 0.788 20.023 9.351l24.386 76.092 68.642-358.907c0 0 3.4-10.894 14.397-10.894 10.994 0 34.107-0.448 34.107-0.448 8.262-2.213 16.751 2.687 18.965 10.949l91.912 454.126 67.948-326.182c2.213-8.262 8.707-15.161 16.965-12.948l27.316-0.333c8.531-2.287 17.301 2.776 19.588 11.31l46.665 148.4 127.337 0c8.835 0 15.993 7.162 15.993 15.993l0 31.986C895.667 537.352 888.508 544.51 879.674 544.51z"
fill="currentColor"
></path>
</svg>
),
map: (
<svg
viewBox="0 0 1024 1024"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
>
<path
d="M877.860571 938.642286h-645.851428c-27.574857 0-54.052571-11.337143-73.508572-31.744a110.957714 110.957714 0 0 1-30.500571-76.8V193.828571c0-28.745143 10.971429-56.32 30.500571-76.726857a101.888 101.888 0 0 1 73.508572-31.817143h574.171428c27.501714 0 53.979429 11.337143 73.508572 31.744 19.529143 20.333714 30.500571 48.054857 30.500571 76.8v522.020572a34.157714 34.157714 0 0 1-6.948571 22.820571c-37.156571 19.382857-57.636571 39.350857-57.636572 72.630857 0 39.716571 19.894857 50.029714 57.636572 72.777143a34.816 34.816 0 0 1-8.045714 49.298286 32.256 32.256 0 0 1-17.334858 5.193143z m-32.256-254.537143V193.828571a40.228571 40.228571 0 0 0-39.497142-41.179428H232.009143a40.301714 40.301714 0 0 0-39.497143 41.252571V699.245714c17.773714-9.874286 37.449143-14.994286 57.417143-14.921143h595.675428v-0.073142z m-595.675428 187.245714h566.198857c-22.893714-11.190857-27.940571-39.497143-28.013714-59.977143 0-20.260571 3.218286-43.885714 28.013714-59.904h-566.125714c-31.670857 0-57.417143 26.843429-57.417143 59.977143 0 33.060571 25.746286 59.904 57.344 59.904z"
fill="currentColor"
></path>
<path
d="M320 128m32.036571 0l-0.073142 0q32.036571 0 32.036571 32.036571l0 511.926858q0 32.036571-32.036571 32.036571l0.073142 0q-32.036571 0-32.036571-32.036571l0-511.926858q0-32.036571 32.036571-32.036571Z"
fill="currentColor"
></path>
</svg>
),
};
export const ArrayIcons: { [key: string]: React.ReactNode } = {
object: (
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M0 1.58105H3.6139V2.87326H1.36702V13.1264H3.6139V14.4186H0V1.58105ZM3.41656 13.3264V13.3266H1.17155V13.3264H3.41656ZM0.197344 14.2186H0.199219V1.78125H3.41656V1.78105H0.197344V14.2186ZM12.3861 1.58105H16V14.4186H12.3861V13.1264H14.633V2.87326H12.3861V1.58105ZM12.5834 2.67326V1.78105H15.8027V1.78125H12.5853V2.67326H12.5834ZM12.5853 13.3266V14.2186H12.5834V13.3264H14.8303V2.67345H14.8322V13.3266H12.5853ZM3.82031 5.9091C3.82031 5.18535 4.40703 4.59863 5.13078 4.59863C5.85453 4.59863 6.44124 5.18535 6.44124 5.9091C6.44124 6.56485 5.9596 7.1081 5.33078 7.2044V8.70018H5.32877C5.32982 8.75093 5.33078 8.80912 5.33078 8.87034V9.72111C5.33078 10.0195 5.57268 10.2614 5.87109 10.2614H6.24124C6.55613 10.2614 6.8114 10.5167 6.8114 10.8316C6.8114 11.1465 6.55613 11.4017 6.24124 11.4017H5.87109C4.94291 11.4017 4.19047 10.6493 4.19047 9.72111V6.82186C3.96158 6.58607 3.82031 6.26397 3.82031 5.9091ZM7.33679 5.9091C7.33679 5.59421 7.59205 5.33894 7.90694 5.33894H11.6085C11.9234 5.33894 12.1786 5.59421 12.1786 5.9091C12.1786 6.22399 11.9234 6.47925 11.6085 6.47925H7.90694C7.59205 6.47925 7.33679 6.22399 7.33679 5.9091ZM7.33679 9.86846C7.33679 9.55357 7.59205 9.2983 7.90694 9.2983H11.6085C11.9234 9.2983 12.1786 9.55357 12.1786 9.86846C12.1786 10.1833 11.9234 10.4386 11.6085 10.4386H7.90694C7.59205 10.4386 7.33679 10.1833 7.33679 9.86846Z"
fill="currentColor"
/>
</svg>
),
boolean: (
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M0 1.58105H3.6139V2.87326H1.36702V13.1264H3.6139V14.4186H0V1.58105ZM3.41656 13.3264V13.3266H1.17155V13.3264H3.41656ZM0.197344 14.2186H0.199219V1.78125H3.41656V1.78105H0.197344V14.2186ZM12.3861 1.58105H16V14.4186H12.3861V13.1264H14.633V2.87326H12.3861V1.58105ZM12.5834 2.67326V1.78105H15.8027V1.78125H12.5853V2.67326H12.5834ZM12.5853 13.3266V14.2186H12.5834V13.3264H14.8303V2.67345H14.8322V13.3266H12.5853ZM2.75 7.99993C2.75 6.14518 4.25358 4.6416 6.10833 4.6416H9.775C11.6298 4.6416 13.1333 6.14518 13.1333 7.99993C13.1333 9.85469 11.6298 11.3583 9.775 11.3583H6.10833C4.25358 11.3583 2.75 9.85469 2.75 7.99993ZM6.10833 5.85827C4.92552 5.85827 3.96667 6.81713 3.96667 7.99993C3.96667 9.18274 4.92552 10.1416 6.10833 10.1416H9.775C10.9578 10.1416 11.9167 9.18274 11.9167 7.99993C11.9167 6.81713 10.9578 5.85827 9.775 5.85827H6.10833ZM8.25 7.99993C8.25 7.1577 8.93277 6.47493 9.775 6.47493C10.6172 6.47493 11.3 7.1577 11.3 7.99993C11.3 8.84217 10.6172 9.52493 9.775 9.52493C8.93277 9.52493 8.25 8.84217 8.25 7.99993ZM9.775 7.6916C9.60471 7.6916 9.46667 7.82965 9.46667 7.99993C9.46667 8.17022 9.60471 8.30827 9.775 8.30827C9.94529 8.30827 10.0833 8.17022 10.0833 7.99993C10.0833 7.82965 9.94529 7.6916 9.775 7.6916Z"
fill="currentColor"
/>
</svg>
),
string: (
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M0 1.58105H3.6139V2.87326H1.36702V13.1264H3.6139V14.4186H0V1.58105ZM3.41656 13.3264V13.3266H1.17155V13.3264H3.41656ZM0.197344 14.2186H0.199219V1.78125H3.41656V1.78105H0.197344V14.2186ZM12.3861 1.58105H16V14.4186H12.3861V13.1264H14.633V2.87326H12.3861V1.58105ZM12.5834 2.67326V1.78105H15.8027V1.78125H12.5853V2.67326H12.5834ZM12.5853 13.3266V14.2186H12.5834V13.3264H14.8303V2.67345H14.8322V13.3266H12.5853ZM5.23701 4.07158C5.50364 3.3161 6.56205 3.28894 6.86709 4.02974L10 11.6383C10.1329 11.9609 9.979 12.3302 9.65631 12.4631C9.33363 12.596 8.96434 12.4421 8.83147 12.1194L7.8021 9.61951H4.61903L3.7474 12.0891C3.63126 12.4182 3.27034 12.5908 2.94127 12.4747C2.6122 12.3585 2.43958 11.9976 2.55573 11.6685L5.23701 4.07158ZM6.08814 5.45704L5.06505 8.35579H7.28174L6.08814 5.45704ZM8.81938 6.07534C8.81938 5.75166 9.08177 5.48926 9.40545 5.48926H12.8941C13.2178 5.48926 13.4802 5.75166 13.4802 6.07534C13.4802 6.39902 13.2178 6.66142 12.8941 6.66142H9.40545C9.08177 6.66142 8.81938 6.39902 8.81938 6.07534ZM10.2668 9.69181C10.2668 9.36812 10.5292 9.10573 10.8529 9.10573H12.8941C13.2178 9.10573 13.4802 9.36812 13.4802 9.69181C13.4802 10.0155 13.2178 10.2779 12.8941 10.2779H10.8529C10.5292 10.2779 10.2668 10.0155 10.2668 9.69181Z"
fill="currentColor"
/>
</svg>
),
integer: (
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M0 1.58105H3.6139V2.87326H1.36702V13.1264H3.6139V14.4186H0V1.58105ZM3.41656 13.3264V13.3266H1.17155V13.3264H3.41656ZM0.197344 14.2186H0.199219V1.78125H3.41656V1.78105H0.197344V14.2186ZM12.3861 1.58105H16V14.4186H12.3861V13.1264H14.633V2.87326H12.3861V1.58105ZM12.5834 2.67326V1.78105H15.8027V1.78125H12.5853V2.67326H12.5834ZM12.5853 13.3266V14.2186H12.5834V13.3264H14.8303V2.67345H14.8322V13.3266H12.5853ZM10.3614 5.22374C10.7161 4.90585 11.1581 4.75 11.6762 4.75C12.2173 4.75 12.6723 4.91467 13.0281 5.25207L13.0291 5.253C13.3852 5.59688 13.561 6.03946 13.561 6.56767C13.561 6.89 13.4945 7.17448 13.3539 7.41445C13.2572 7.57972 13.1279 7.71948 12.9685 7.83428C13.1575 7.95643 13.3099 8.11182 13.4225 8.30109C13.5793 8.5644 13.6531 8.88311 13.6531 9.24936C13.6531 9.83787 13.4612 10.3151 13.0656 10.6612C12.6982 10.9795 12.2305 11.1341 11.6762 11.1341C11.1356 11.1341 10.6805 10.9925 10.324 10.6977C9.92124 10.3691 9.71723 9.90026 9.69942 9.31256L9.69473 9.15802H10.846L10.8539 9.2997C10.8689 9.5698 10.9591 9.75553 11.1096 9.87941L11.1106 9.88027C11.2519 9.99882 11.4365 10.0631 11.6762 10.0631C11.9765 10.0631 12.1743 9.98692 12.2984 9.86071C12.4229 9.73404 12.4984 9.53136 12.4984 9.22422C12.4984 8.92116 12.4215 8.72127 12.2939 8.59581C12.1658 8.46989 11.961 8.39373 11.6511 8.39373H11.3586V7.34788H11.6511C11.9297 7.34788 12.111 7.27834 12.2238 7.16555C12.3366 7.05276 12.4062 6.87138 12.4062 6.59281C12.4062 6.30696 12.3378 6.12041 12.2277 6.00501C12.1188 5.89092 11.9446 5.82098 11.6762 5.82098C11.4248 5.82098 11.2539 5.88537 11.1407 5.99325C11.0268 6.10185 10.9497 6.27522 10.9291 6.5375L10.9183 6.67577H9.76788L9.77492 6.51904C9.79886 5.98644 9.99237 5.54989 10.3614 5.22374ZM5.91032 5.26037C6.26612 4.92297 6.72112 4.7583 7.26219 4.7583C7.80751 4.7583 8.26297 4.91938 8.61401 5.25194L8.61501 5.25289C8.96719 5.59272 9.13852 6.04185 9.13852 6.58435C9.13852 6.84997 9.08709 7.09565 8.9817 7.31883L8.98114 7.31999C8.89563 7.49712 8.74775 7.71415 8.54418 7.96862L8.54322 7.96981L6.87446 10.0127H9.13852V11.0753H5.36909V10.1089L7.69946 7.27679C7.89456 7.04062 7.98374 6.80773 7.98374 6.57597C7.98374 6.29602 7.91626 6.11385 7.8078 6.00122C7.70036 5.88964 7.52811 5.8209 7.26219 5.8209C7.04017 5.8209 6.87439 5.88173 6.75075 5.99193C6.61227 6.11766 6.53226 6.30918 6.53226 6.59273V6.74273H5.37747V6.59273C5.37747 6.05443 5.55248 5.60586 5.90934 5.2613L5.91032 5.26037ZM3.50907 4.80865H4.56964V11.0754H3.41486V6.2201L2.25 7.24249V5.89561L3.50907 4.80865Z"
fill="currentColor"
/>
</svg>
),
number: (
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M3.6139 1.58154H0V14.4191H3.6139V13.1269H1.36702V2.87375H3.6139V1.58154ZM3.41656 13.3271V13.3269H1.17155V13.3271H3.41656ZM0.199219 14.2191H0.197344V1.78154H3.41656V1.78174H0.199219V14.2191ZM16 1.58154H12.3861V2.87375H14.633V13.1269H12.3861V14.4191H16V1.58154ZM12.5834 1.78154V2.67375H12.5853V1.78174H15.8027V1.78154H12.5834ZM12.5853 14.2191V13.3271H14.8322V2.67394H14.8303V13.3269H12.5834V14.2191H12.5853ZM6.86771 4.5C5.87019 4.5 5.00104 5.30767 5.00104 6.31667V9.63333C5.00104 10.6423 5.87019 11.45 6.86771 11.45C7.86523 11.45 8.73438 10.6423 8.73438 9.63333V6.31667C8.73438 5.30767 7.86523 4.5 6.86771 4.5ZM11.1177 4.5C10.1202 4.5 9.25104 5.30767 9.25104 6.31667V9.63333C9.25104 10.6423 10.1202 11.45 11.1177 11.45C12.1152 11.45 12.9844 10.6423 12.9844 9.63333V6.31667C12.9844 5.30767 12.1152 4.5 11.1177 4.5ZM6.13438 6.31667C6.13438 5.9503 6.47884 5.63333 6.86771 5.63333C7.25657 5.63333 7.60104 5.9503 7.60104 6.31667V9.63333C7.60104 9.9997 7.25657 10.3167 6.86771 10.3167C6.47884 10.3167 6.13438 9.9997 6.13438 9.63333V6.31667ZM10.3844 6.31667C10.3844 5.9503 10.7288 5.63333 11.1177 5.63333C11.5066 5.63333 11.851 5.9503 11.851 6.31667V9.63333C11.851 9.9997 11.5066 10.3167 11.1177 10.3167C10.7288 10.3167 10.3844 9.9997 10.3844 9.63333V6.31667ZM3.75938 9.85C3.33135 9.85 2.98438 10.197 2.98438 10.625C2.98438 11.053 3.33135 11.4 3.75938 11.4C4.1874 11.4 4.53438 11.053 4.53438 10.625C4.53438 10.197 4.1874 9.85 3.75938 9.85Z"
fill="currentColor"
/>
</svg>
),
};

View File

@ -49,7 +49,8 @@ export const createSyncVariablePlugin: PluginCreator<SyncVariablePluginOptions>
variableData.setVar(
ASTFactory.createVariableDeclaration({
meta: {
title: `${title}.outputs`,
title: `${title}`,
icon: node.getNodeRegistry()?.info?.icon,
// NOTICE: You can add more metadata here as needed
},
key: `${node.id}.outputs`,

View File

@ -1,68 +0,0 @@
.option-select-item-container {
display: flex;
align-items: flex-start;
.icon {
flex-shrink: 0;
margin-top: 2px;
margin-right: 5px;
}
.text {
word-break: break-all;
white-space: pre-wrap;
}
.error-text {
word-break: break-all;
color: red;
white-space: pre-wrap;
margin-top: 2px;
}
}
.prefix-icon {
margin-left: 2px;
display: inline-block;
padding: 0 2px;
height: 16px;
svg {
scale: 0.7;
}
}
.option-type-icon {
height: 14px;
margin-right: 6px;
svg {
width: 14px;
height: 14px;
}
}
.tree-select {
:global {
.semi-tree-select-selection {
padding-left: 4px;
}
.semi-tree-select-arrow,
.semi-tree-select-clearbtn {
width: 16px;
svg {
scale: 0.7;
}
}
}
}
.description-icon {
margin-left: 3px;
scale: 0.8;
vertical-align: text-top;
}

View File

@ -1,94 +0,0 @@
import React from 'react';
import { type TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
import { TreeSelect } from '@douyinfe/semi-ui';
import { type JsonSchema } from '../../../typings';
import { ValueDisplay } from '../../../form-components';
import { useVariableTree } from './use-variable-tree';
export interface VariableSelectorProps {
value?: string;
onChange: (value?: string) => void;
options?: {
size?: 'small' | 'large' | 'default';
emptyContent?: JSX.Element;
targetSchemas?: JsonSchema[];
strongEqualToTargetSchema?: boolean;
};
hasError?: boolean;
style?: React.CSSProperties;
readonly?: boolean;
}
export const VariableSelector = ({
value,
onChange,
options,
readonly,
style,
hasError,
}: VariableSelectorProps) => {
const { size = 'small', emptyContent, targetSchemas, strongEqualToTargetSchema } = options || {};
if (readonly) {
return <ValueDisplay value={value as string} hasError={hasError} />;
}
const treeData = useVariableTree<TreeNodeData>({
targetSchemas,
strongEqual: strongEqualToTargetSchema,
ignoreReadonly: true,
getTreeData: ({ variable, key, icon, children, disabled, parentFields }) => ({
key,
value: key,
icon: (
<span
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
marginRight: 4,
}}
>
{icon}
</span>
),
label: variable.meta?.expressionTitle || variable.key || '',
disabled,
labelPath: [...parentFields, variable]
.map((_field) => _field.meta?.expressionTitle || _field.key || '')
.join('.'),
children,
}),
});
const renderEmpty = () => {
if (emptyContent) {
return emptyContent;
}
return 'nodata';
};
return (
<>
<TreeSelect
dropdownMatchSelectWidth={false}
treeData={treeData}
size={size}
value={value}
style={{
...style,
outline: hasError ? '1px solid red' : undefined,
}}
validateStatus={hasError ? 'error' : undefined}
onChange={(option) => {
onChange(option as string);
}}
showClear
placeholder="Select Variable..."
emptyContent={renderEmpty()}
/>
</>
);
};

View File

@ -1,134 +0,0 @@
import { useCallback, useMemo } from 'react';
import {
ASTFactory,
ASTKind,
type BaseType,
type UnionJSON,
useScopeAvailable,
ASTMatch,
} from '@flowgram.ai/free-layout-editor';
import { createASTFromJSONSchema } from '../utils';
import { ArrayIcons, VariableTypeIcons } from '../icons';
import { type JsonSchema } from '../../../typings';
type VariableField = any;
interface HooksParams<TreeData> {
// filter target type
targetSchemas?: JsonSchema[];
// Is it strongly type-checked?
strongEqual?: boolean;
// ignore global Config
ignoreReadonly?: boolean;
// render tree node
getTreeData: (props: {
key: string;
icon: JSX.Element | undefined;
variable: VariableField;
parentFields: VariableField[];
disabled?: boolean;
children?: TreeData[];
}) => TreeData;
}
export function useVariableTree<TreeData>({
targetSchemas = [],
strongEqual = false,
ignoreReadonly = false,
getTreeData,
}: HooksParams<TreeData>): TreeData[] {
const available = useScopeAvailable();
const getVariableTypeIcon = useCallback((variable: VariableField) => {
const _type = variable.type;
if (ASTMatch.isArray(_type)) {
return (
(ArrayIcons as any)[_type.items?.kind.toLowerCase()] ||
VariableTypeIcons[ASTKind.Array.toLowerCase()]
);
}
if (ASTMatch.isCustomType(_type)) {
return VariableTypeIcons[_type.typeName.toLowerCase()];
}
return (VariableTypeIcons as any)[variable.type?.kind.toLowerCase()];
}, []);
const targetTypeAST: UnionJSON = useMemo(
() =>
ASTFactory.createUnion({
types: targetSchemas.map((_targetSchema) => {
const typeAst = createASTFromJSONSchema(_targetSchema)!;
return strongEqual ? typeAst : { ...typeAst, weak: true };
}),
}),
[strongEqual, ...targetSchemas]
);
const checkTypeFiltered = useCallback(
(type?: BaseType) => {
if (!type) {
return true;
}
if (targetTypeAST.types?.length) {
return !type.isTypeEqual(targetTypeAST);
}
return false;
},
[strongEqual, targetTypeAST]
);
const renderVariable = (
variable: VariableField,
parentFields: VariableField[] = []
): TreeData | null => {
let type = variable?.type;
const isTypeFiltered = checkTypeFiltered(type);
let children: TreeData[] | undefined;
if (ASTMatch.isObject(type)) {
children = (type.properties || [])
.map((_property) => renderVariable(_property as VariableField, [...parentFields, variable]))
.filter(Boolean) as TreeData[];
}
if (isTypeFiltered && !children?.length) {
return null;
}
const currPath = [
...parentFields.map((_field) => _field.meta?.titleKey || _field.key),
variable.meta?.titleKey || variable.key,
].join('.');
return getTreeData({
key: currPath,
icon: getVariableTypeIcon(variable),
variable,
parentFields,
children,
disabled: isTypeFiltered,
});
};
return [
...available.variables
.filter((_v) => {
if (ignoreReadonly) {
return !_v.meta?.readonly;
}
return true;
})
.slice(0)
.reverse(),
]
.map((_variable) => renderVariable(_variable as VariableField))
.filter(Boolean) as TreeData[];
}

View File

@ -68,6 +68,9 @@ importers:
'@flowgram.ai/fixed-semi-materials':
specifier: workspace:*
version: link:../../packages/materials/fixed-semi-materials
'@flowgram.ai/form-materials':
specifier: workspace:*
version: link:../../packages/materials/form-materials
'@flowgram.ai/group-plugin':
specifier: workspace:*
version: link:../../packages/plugins/group-plugin
@ -196,6 +199,9 @@ importers:
'@douyinfe/semi-ui':
specifier: ^2.72.3
version: 2.72.3(acorn@8.14.0)(react-dom@18.3.1)(react@18.3.1)
'@flowgram.ai/form-materials':
specifier: workspace:*
version: link:../../packages/materials/form-materials
'@flowgram.ai/free-container-plugin':
specifier: workspace:*
version: link:../../packages/plugins/free-container-plugin
@ -1728,6 +1734,76 @@ importers:
specifier: ^0.34.6
version: 0.34.6(jsdom@22.1.0)
../../packages/materials/form-materials:
dependencies:
'@douyinfe/semi-icons':
specifier: ^2.72.3
version: 2.72.3(react@18.3.1)
'@douyinfe/semi-illustrations':
specifier: ^2.36.0
version: 2.72.3(react@18.3.1)
'@douyinfe/semi-ui':
specifier: ^2.72.3
version: 2.72.3(acorn@8.14.0)(react-dom@18.3.1)(react@18.3.1)
'@flowgram.ai/editor':
specifier: workspace:*
version: link:../../client/editor
chalk:
specifier: ^5.3.0
version: 5.4.1
commander:
specifier: ^11.0.0
version: 11.1.0
inquirer:
specifier: ^9.2.7
version: 9.3.7
lodash:
specifier: ^4.17.21
version: 4.17.21
nanoid:
specifier: ^4.0.2
version: 4.0.2
devDependencies:
'@flowgram.ai/eslint-config':
specifier: workspace:*
version: link:../../../config/eslint-config
'@flowgram.ai/ts-config':
specifier: workspace:*
version: link:../../../config/ts-config
'@types/lodash':
specifier: ^4.14.137
version: 4.17.13
'@types/react':
specifier: ^18
version: 18.3.16
'@types/react-dom':
specifier: ^18
version: 18.3.5(@types/react@18.3.16)
'@types/styled-components':
specifier: ^5
version: 5.1.34
eslint:
specifier: ^8.54.0
version: 8.57.1
react:
specifier: ^18
version: 18.3.1
react-dom:
specifier: ^18
version: 18.3.1(react@18.3.1)
styled-components:
specifier: ^5
version: 5.3.11(@babel/core@7.26.10)(react-dom@18.3.1)(react-is@18.3.1)(react@18.3.1)
tsup:
specifier: ^8.0.1
version: 8.3.5(typescript@5.0.4)
typescript:
specifier: ^5.0.4
version: 5.0.4
vitest:
specifier: ^0.34.6
version: 0.34.6(jsdom@22.1.0)
../../packages/node-engine/form:
dependencies:
'@flowgram.ai/reactive':
@ -3795,7 +3871,7 @@ packages:
- supports-color
dev: false
/@babel/helper-module-imports@7.25.9:
/@babel/helper-module-imports@7.25.9(supports-color@5.5.0):
resolution: {integrity: sha512-tnUA4RsrmflIM6W6RFTLFSXITtl0wKjgpnLgXyowocVPrbYrLUXSBXDgTs8BlbmIzIdlBySRQjINYs2BAkiLtw==}
engines: {node: '>=6.9.0'}
dependencies:
@ -3804,15 +3880,6 @@ packages:
transitivePeerDependencies:
- supports-color
/@babel/helper-module-imports@7.25.9(supports-color@5.5.0):
resolution: {integrity: sha512-tnUA4RsrmflIM6W6RFTLFSXITtl0wKjgpnLgXyowocVPrbYrLUXSBXDgTs8BlbmIzIdlBySRQjINYs2BAkiLtw==}
engines: {node: '>=6.9.0'}
dependencies:
'@babel/traverse': 7.26.4(supports-color@5.5.0)
'@babel/types': 7.26.3
transitivePeerDependencies:
- supports-color
/@babel/helper-module-transforms@7.26.0(@babel/core@7.26.0):
resolution: {integrity: sha512-xO+xu6B5K2czEnQye6BHA7DolFFmS3LB7stHZFaOLb1pAwO1HWLS8fXA+eh0A2yIvltPVmx3eNNDBJA2SLHXFw==}
engines: {node: '>=6.9.0'}
@ -3820,7 +3887,7 @@ packages:
'@babel/core': ^7.0.0
dependencies:
'@babel/core': 7.26.0
'@babel/helper-module-imports': 7.25.9
'@babel/helper-module-imports': 7.25.9(supports-color@5.5.0)
'@babel/helper-validator-identifier': 7.25.9
'@babel/traverse': 7.26.4(supports-color@5.5.0)
transitivePeerDependencies:
@ -3834,7 +3901,7 @@ packages:
'@babel/core': ^7.0.0
dependencies:
'@babel/core': 7.26.10
'@babel/helper-module-imports': 7.25.9
'@babel/helper-module-imports': 7.25.9(supports-color@5.5.0)
'@babel/helper-validator-identifier': 7.25.9
'@babel/traverse': 7.26.4(supports-color@5.5.0)
transitivePeerDependencies:
@ -4341,7 +4408,7 @@ packages:
'@babel/core': ^7.0.0-0
dependencies:
'@babel/core': 7.26.0
'@babel/helper-module-imports': 7.25.9
'@babel/helper-module-imports': 7.25.9(supports-color@5.5.0)
'@babel/helper-plugin-utils': 7.25.9
'@babel/helper-remap-async-to-generator': 7.25.9(@babel/core@7.26.0)
transitivePeerDependencies:
@ -4635,7 +4702,7 @@ packages:
dependencies:
'@babel/core': 7.26.0
'@babel/helper-annotate-as-pure': 7.25.9
'@babel/helper-module-imports': 7.25.9
'@babel/helper-module-imports': 7.25.9(supports-color@5.5.0)
'@babel/helper-plugin-utils': 7.25.9
'@babel/plugin-syntax-jsx': 7.25.9(@babel/core@7.26.0)
'@babel/types': 7.26.3

View File

@ -0,0 +1,11 @@
const { defineConfig } = require('@flowgram.ai/eslint-config');
module.exports = defineConfig({
preset: 'web',
packageRoot: __dirname,
rules: {
'no-console': 'off',
'react/no-deprecated': 'off',
'@flowgram.ai/e2e-data-testid': 'off',
},
});

View File

@ -0,0 +1,63 @@
import chalk from 'chalk';
import { Command } from 'commander';
import inquirer from 'inquirer';
import { bfsMaterials, copyMaterial, listAllMaterials } from './materials.js';
import { getProjectInfo, installDependencies } from './project.js';
const program = new Command();
program
.version('1.0.0')
.description('Add official materials to your project')
.action(async () => {
console.log(chalk.bgGreenBright('Welcome to @flowgram.ai/form-materials CLI!'));
const projectInfo = getProjectInfo();
console.log(chalk.bold('Project Info:'));
console.log(chalk.black(` - Flowgram Version: ${projectInfo.flowgramVersion}`));
console.log(chalk.black(` - Project Path: ${projectInfo.projectPath}`));
const materials = listAllMaterials();
// 2. User select one component
const { material } = await inquirer.prompt([
{
type: 'list',
name: 'material',
message: 'Select one material to add:',
choices: [
...materials.map((_material) => ({
name: `${_material.type}/${_material.name}`,
value: _material,
})),
],
},
]);
console.log(material);
// 3. Get the component dependencies by BFS (include depMaterials and depPackages)
const { allMaterials, allPackages } = bfsMaterials(material, materials);
// 4. Install the dependencies
let flowgramPackage = `@flowgram.ai/editor`;
if (projectInfo.flowgramVersion !== 'workspace:*') {
flowgramPackage = `@flowgram.ai/editor@${projectInfo.flowgramVersion}`;
}
const packagesToInstall = [flowgramPackage, ...allPackages];
console.log(chalk.bold('These npm dependencies will be added to your project'));
console.log(packagesToInstall);
installDependencies(packagesToInstall, projectInfo);
// 5. Copy the materials to the project
console.log(chalk.bold('These Materials will be added to your project'));
console.log(allMaterials);
allMaterials.forEach((material) => {
copyMaterial(material, projectInfo);
});
});
program.parse(process.argv);

View File

@ -0,0 +1,72 @@
import fs from 'fs';
import path from 'path';
const _types = ['components'];
export function listAllMaterials() {
const _materials = [];
for (const _type of _types) {
const materialsPath = path.join(import.meta.dirname, '..', 'src', _type);
_materials.push(
...fs
.readdirSync(materialsPath)
.map((_path) => {
if (_path === 'index.ts') {
return null;
}
const config = fs.readFileSync(path.join(materialsPath, _path, 'config.json'), 'utf8');
return {
...JSON.parse(config),
type: _type,
path: path.join(materialsPath, _path),
};
})
.filter(Boolean)
);
}
return _materials;
}
export function bfsMaterials(material, _materials = []) {
function findConfigByName(name) {
return _materials.find((_config) => _config.name === name);
}
const queue = [material];
const allMaterials = new Set();
const allPackages = new Set();
while (queue.length > 0) {
const _material = queue.shift();
if (allMaterials.has(_material)) {
continue;
}
allMaterials.add(_material);
if (_material.depPackages) {
for (const _package of _material.depPackages) {
allPackages.add(_package);
}
}
if (_material.depMaterials) {
for (const _materialName of _material.depMaterials) {
queue.push(findConfigByName(_materialName));
}
}
}
return {
allMaterials: Array.from(allMaterials),
allPackages: Array.from(allPackages),
};
}
export const copyMaterial = (material, projectInfo) => {
const sourceDir = material.path;
const targetDir = path.join(projectInfo.projectPath, `form-${material.type}`, material.name);
fs.cpSync(sourceDir, targetDir, { recursive: true });
};

View File

@ -0,0 +1,72 @@
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
export function getProjectInfo() {
// get nearest package.json
let projectPath = process.cwd();
while (projectPath !== '/' && !fs.existsSync(path.join(projectPath, 'package.json'))) {
projectPath = path.join(projectPath, '..');
}
if (projectPath === '/') {
throw new Error('Please run this command in a valid project');
}
const packageJsonPath = path.join(projectPath, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
// fixed layout or free layout
const flowgramVersion =
packageJson.dependencies['@flowgram.ai/fixed-layout-editor'] ||
packageJson.dependencies['@flowgram.ai/free-layout-editor'] ||
packageJson.dependencies['@flowgram.ai/editor'];
if (!flowgramVersion) {
throw new Error(
'Please install @flowgram.ai/fixed-layout-editor or @flowgram.ai/free-layout-editor'
);
}
return {
projectPath,
packageJsonPath,
packageJson,
flowgramVersion,
};
}
export function findRushJson(startPath) {
let currentPath = startPath;
while (currentPath !== '/' && !fs.existsSync(path.join(currentPath, 'rush.json'))) {
currentPath = path.join(currentPath, '..');
}
if (fs.existsSync(path.join(currentPath, 'rush.json'))) {
return path.join(currentPath, 'rush.json');
}
return null;
}
export function installDependencies(packages, projectInfo) {
if (fs.existsSync(path.join(projectInfo.projectPath, 'yarn.lock'))) {
execSync(`yarn add ${packages.join(' ')}`, { stdio: 'inherit' });
return;
}
if (fs.existsSync(path.join(projectInfo.projectPath, 'pnpm-lock.yaml'))) {
execSync(`pnpm add ${packages.join(' ')}`, { stdio: 'inherit' });
return;
}
// rush monorepo
if (findRushJson(projectInfo.projectPath)) {
execSync(`rush add ${packages.map((pkg) => `--package ${pkg}`).join(' ')}`, {
stdio: 'inherit',
});
return;
}
execSync(`npm install ${packages.join(' ')}`, { stdio: 'inherit' });
}

View File

@ -0,0 +1,69 @@
{
"name": "@flowgram.ai/form-materials",
"version": "0.1.8",
"homepage": "https://flowgram.ai/",
"repository": "https://github.com/bytedance/flowgram.ai",
"license": "MIT",
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/index.js"
},
"main": "./dist/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/index.d.ts",
"bin": {
"flowgram-form-materials": "./bin/index.js"
},
"files": [
"dist",
"bin",
"src"
],
"scripts": {
"build": "npm run build:fast -- --dts-resolve",
"build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
"build:watch": "npm run build:fast -- --dts-resolve",
"clean": "rimraf dist",
"test": "exit 0",
"test:cov": "exit 0",
"ts-check": "tsc --noEmit",
"watch": "npm run build:fast -- --dts-resolve --watch --ignore-watch dist",
"run-bin": "node bin/index.js"
},
"dependencies": {
"@douyinfe/semi-icons": "^2.72.3",
"@douyinfe/semi-illustrations": "^2.36.0",
"@douyinfe/semi-ui": "^2.72.3",
"@flowgram.ai/editor": "workspace:*",
"lodash": "^4.17.21",
"nanoid": "^4.0.2",
"commander": "^11.0.0",
"chalk": "^5.3.0",
"inquirer": "^9.2.7"
},
"devDependencies": {
"@flowgram.ai/eslint-config": "workspace:*",
"@flowgram.ai/ts-config": "workspace:*",
"@types/lodash": "^4.14.137",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/styled-components": "^5",
"eslint": "^8.54.0",
"react": "^18",
"react-dom": "^18",
"styled-components": "^5",
"tsup": "^8.0.1",
"typescript": "^5.0.4",
"vitest": "^0.34.6"
},
"peerDependencies": {
"react": ">=17",
"react-dom": ">=17",
"styled-components": ">=4"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}

View File

@ -0,0 +1,3 @@
export { VariableSelector } from './variable-selector';
export { TypeSelector, JsonSchema, VariableTypeIcons, ArrayIcons } from './type-selector';
export { JsonSchemaEditor } from './json-schema-editor';

View File

@ -0,0 +1,5 @@
{
"name": "json-schema-editor",
"depMaterials": ["type-selector"],
"depPackages": ["@douyinfe/semi-ui", "@douyinfe/semi-icons", "styled-components"]
}

View File

@ -0,0 +1,114 @@
import { useEffect, useMemo, useState } from 'react';
import { PropertyValueType } from './types';
import { JsonSchema } from '../type-selector';
let _id = 0;
function genId() {
return _id++;
}
function getDrilldownSchema(
value?: PropertyValueType,
path?: (keyof PropertyValueType)[]
): { schema?: PropertyValueType | null; path?: (keyof PropertyValueType)[] } {
if (!value) {
return {};
}
if (value.type === 'array' && value.items) {
return getDrilldownSchema(value.items, [...(path || []), 'items']);
}
return { schema: value, path };
}
export function usePropertiesEdit(
value?: PropertyValueType,
onChange?: (value: PropertyValueType) => void
) {
// Get drilldown (array.items.items...)
const drilldown = useMemo(() => getDrilldownSchema(value), [value?.type, value?.items]);
const isDrilldownObject = drilldown.schema?.type === 'object';
// Generate Init Property List
const initPropertyList = useMemo(
() =>
isDrilldownObject
? Object.entries(drilldown.schema?.properties || {}).map(
([key, _value]) =>
({
key: genId(),
name: key,
isPropertyRequired: value?.required?.includes(key) || false,
..._value,
} as PropertyValueType)
)
: [],
[isDrilldownObject]
);
const [propertyList, setPropertyList] = useState<PropertyValueType[]>(initPropertyList);
const updatePropertyList = (updater: (list: PropertyValueType[]) => PropertyValueType[]) => {
setPropertyList((_list) => {
const next = updater(_list);
// onChange to parent
const nextProperties: Record<string, JsonSchema> = {};
const nextRequired: string[] = [];
for (const _property of next) {
if (!_property.name) {
continue;
}
nextProperties[_property.name] = _property;
if (_property.isPropertyRequired) {
nextRequired.push(_property.name);
}
}
let drilldownSchema = value || {};
if (drilldown.path) {
drilldownSchema = drilldown.path.reduce((acc, key) => acc[key], value || {});
}
drilldownSchema.properties = nextProperties;
drilldownSchema.required = nextRequired;
onChange?.(value || {});
return next;
});
};
const onAddProperty = () => {
updatePropertyList((_list) => [..._list, { key: genId(), name: '', type: 'string' }]);
};
const onRemoveProperty = (key: number) => {
updatePropertyList((_list) => _list.filter((_property) => _property.key !== key));
};
const onEditProperty = (key: number, nextValue: PropertyValueType) => {
updatePropertyList((_list) =>
_list.map((_property) => (_property.key === key ? nextValue : _property))
);
};
useEffect(() => {
if (!isDrilldownObject) {
setPropertyList([]);
}
}, [isDrilldownObject]);
return {
propertyList,
isDrilldownObject,
onAddProperty,
onRemoveProperty,
onEditProperty,
};
}

View File

@ -0,0 +1,196 @@
import React, { useMemo, useState } from 'react';
import { Button, Checkbox, IconButton, Input } from '@douyinfe/semi-ui';
import {
IconExpand,
IconShrink,
IconPlus,
IconChevronDown,
IconChevronRight,
IconMinus,
} from '@douyinfe/semi-icons';
import { JsonSchema } from '../type-selector/types';
import { TypeSelector } from '../type-selector';
import { PropertyValueType } from './types';
import {
IconAddChildren,
UIActions,
UICollapseTrigger,
UICollapsible,
UIContainer,
UIExpandDetail,
UILabel,
UIProperties,
UIPropertyLeft,
UIPropertyMain,
UIPropertyRight,
UIRequired,
UIType,
} from './styles';
import { UIName } from './styles';
import { UIRow } from './styles';
import { usePropertiesEdit } from './hooks';
export function JsonSchemaEditor(props: {
value?: JsonSchema;
onChange?: (value: JsonSchema) => void;
}) {
const { value = { type: 'object' }, onChange: onChangeProps } = props;
const { propertyList, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(
value,
onChangeProps
);
return (
<UIContainer>
<UIProperties>
{propertyList.map((_property) => (
<PropertyEdit
key={_property.key}
value={_property}
onChange={(_v) => {
onEditProperty(_property.key!, _v);
}}
onRemove={() => {
onRemoveProperty(_property.key!);
}}
/>
))}
</UIProperties>
<Button size="small" style={{ marginTop: 10 }} icon={<IconPlus />} onClick={onAddProperty}>
Add
</Button>
</UIContainer>
);
}
function PropertyEdit(props: {
value?: PropertyValueType;
onChange?: (value: PropertyValueType) => void;
onRemove?: () => void;
$isLast?: boolean;
$showLine?: boolean;
}) {
const { value, onChange: onChangeProps, onRemove, $isLast, $showLine } = props;
console.log('isLast', $isLast);
const [expand, setExpand] = useState(false);
const [collapse, setCollapse] = useState(false);
const { name, type, items, description, isPropertyRequired } = value || {};
const typeSelectorValue = useMemo(() => ({ type, items }), [type, items]);
const { propertyList, isDrilldownObject, onAddProperty, onRemoveProperty, onEditProperty } =
usePropertiesEdit(value, onChangeProps);
const onChange = (key: string, _value: any) => {
onChangeProps?.({
...(value || {}),
[key]: _value,
});
};
const showCollapse = isDrilldownObject && propertyList.length > 0;
return (
<>
<UIPropertyLeft $isLast={$isLast} $showLine={$showLine}>
{showCollapse && (
<UICollapseTrigger onClick={() => setCollapse((_collapse) => !_collapse)}>
{collapse ? <IconChevronDown size="small" /> : <IconChevronRight size="small" />}
</UICollapseTrigger>
)}
</UIPropertyLeft>
<UIPropertyRight>
<UIPropertyMain $expand={expand}>
<UIRow>
<UIName>
<Input
placeholder="Input Variable Name"
size="small"
value={name}
onChange={(value) => onChange('name', value)}
/>
</UIName>
<UIType>
<TypeSelector
value={typeSelectorValue}
onChange={(_value) => {
onChangeProps?.({
...(value || {}),
..._value,
});
}}
/>
</UIType>
<UIRequired>
<Checkbox
checked={isPropertyRequired}
onChange={(e) => onChange('isPropertyRequired', e.target.checked)}
/>
</UIRequired>
<UIActions>
<IconButton
size="small"
theme="borderless"
icon={expand ? <IconShrink size="small" /> : <IconExpand size="small" />}
onClick={() => setExpand((_expand) => !_expand)}
/>
{isDrilldownObject && (
<IconButton
size="small"
theme="borderless"
icon={<IconAddChildren />}
onClick={() => {
onAddProperty();
setCollapse(true);
}}
/>
)}
<IconButton
size="small"
theme="borderless"
icon={<IconMinus size="small" />}
onClick={onRemove}
/>
</UIActions>
</UIRow>
{expand && (
<UIExpandDetail>
<UILabel>Description</UILabel>
<Input
size="small"
value={description}
onChange={(value) => onChange('description', value)}
placeholder="Help LLM to understand the property"
/>
</UIExpandDetail>
)}
</UIPropertyMain>
{showCollapse && (
<UICollapsible $collapse={collapse}>
<UIProperties $shrink={true}>
{propertyList.map((_property, index) => (
<PropertyEdit
key={_property.key}
value={_property}
onChange={(_v) => {
onEditProperty(_property.key!, _v);
}}
onRemove={() => {
onRemoveProperty(_property.key!);
}}
$isLast={index === propertyList.length - 1}
$showLine={true}
/>
))}
</UIProperties>
</UICollapsible>
)}
</UIPropertyRight>
</>
);
}

View File

@ -0,0 +1,145 @@
import React from 'react';
import styled, { css } from 'styled-components';
import Icon from '@douyinfe/semi-icons';
export const UIContainer = styled.div`
/* & .semi-input {
background-color: #fff;
border-radius: 6px;
height: 24px;
} */
`;
export const UIRow = styled.div`
display: flex;
align-items: center;
gap: 6px;
`;
export const UICollapseTrigger = styled.div`
cursor: pointer;
margin-right: 5px;
`;
export const UIExpandDetail = styled.div`
display: flex;
flex-direction: column;
`;
export const UILabel = styled.div`
font-size: 12px;
color: #999;
font-weight: 400;
margin-bottom: 2px;
`;
export const UIProperties = styled.div<{ $shrink?: boolean }>`
display: grid;
grid-template-columns: auto 1fr;
${({ $shrink }) =>
$shrink &&
css`
padding-left: 10px;
margin-top: 10px;
`}
`;
export const UIPropertyLeft = styled.div<{ $isLast?: boolean; $showLine?: boolean }>`
grid-column: 1;
position: relative;
${({ $showLine, $isLast }) =>
$showLine &&
css`
&::before {
/* 竖线 */
content: '';
position: absolute;
left: -22px;
top: -18px;
bottom: ${$isLast ? '12px' : '0px'};
width: 1px;
background: #d9d9d9;
display: block;
}
&::after {
/* 横线 */
content: '';
position: absolute;
left: -22px; // 横线起点和竖线对齐
top: 12px; // 跟随你的行高调整
width: 22px; // 横线长度
height: 1px;
background: #d9d9d9;
display: block;
}
`}
`;
export const UIPropertyRight = styled.div`
grid-column: 2;
margin-bottom: 10px;
&:last-child {
margin-bottom: 0px;
}
`;
export const UIPropertyMain = styled.div<{ $expand?: boolean }>`
display: flex;
flex-direction: column;
gap: 10px;
${({ $expand }) =>
$expand &&
css`
background-color: #f5f5f5;
padding: 10px;
border-radius: 4px;
`}
`;
export const UICollapsible = styled.div<{ $collapse?: boolean }>`
display: none;
${({ $collapse }) =>
$collapse &&
css`
display: block;
`}
`;
export const UIName = styled.div`
flex-grow: 1;
`;
export const UIType = styled.div``;
export const UIRequired = styled.div``;
export const UIActions = styled.div`
white-space: nowrap;
`;
const iconAddChildrenSvg = (
<svg
className="icon-icon icon-icon-coz_add_node "
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="currentColor"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M11 6.49988C11 8.64148 9.50397 10.4337 7.49995 10.8884V15.4998C7.49995 16.0521 7.94767 16.4998 8.49995 16.4998H11.208C11.0742 16.8061 11 17.1443 11 17.4998C11 17.8554 11.0742 18.1936 11.208 18.4998H8.49995C6.8431 18.4998 5.49995 17.1567 5.49995 15.4998V10.8884C3.49599 10.4336 2 8.64145 2 6.49988C2 4.0146 4.01472 1.99988 6.5 1.99988C8.98528 1.99988 11 4.0146 11 6.49988ZM6.5 8.99988C7.88071 8.99988 9 7.88059 9 6.49988C9 5.11917 7.88071 3.99988 6.5 3.99988C5.11929 3.99988 4 5.11917 4 6.49988C4 7.88059 5.11929 8.99988 6.5 8.99988Z"
></path>
<path d="M17.5 12.4999C18.0523 12.4999 18.5 12.9476 18.5 13.4999V16.4999H21.5C22.0523 16.4999 22.5 16.9476 22.5 17.4999C22.5 18.0522 22.0523 18.4999 21.5 18.4999H18.5V21.4999C18.5 22.0522 18.0523 22.4999 17.5 22.4999C16.9477 22.4999 16.5 22.0522 16.5 21.4999V18.4999H13.5C12.9477 18.4999 12.5 18.0522 12.5 17.4999C12.5 16.9476 12.9477 16.4999 13.5 16.4999H16.5V13.4999C16.5 12.9476 16.9477 12.4999 17.5 12.4999Z"></path>
</svg>
);
export const IconAddChildren = () => <Icon size="small" svg={iconAddChildrenSvg} />;

View File

@ -0,0 +1,11 @@
import { JsonSchema } from '../type-selector/types';
export interface PropertyValueType extends JsonSchema {
name?: string;
key?: number;
isPropertyRequired?: boolean;
}
export type PropertiesValueType = Pick<PropertyValueType, 'properties' | 'required'>;
export type JsonSchemaProperties = JsonSchema['properties'];

View File

@ -0,0 +1,5 @@
{
"name": "type-selector",
"depMaterials": [],
"depPackages": ["@douyinfe/semi-ui", "@douyinfe/semi-icons"]
}

View File

@ -1,3 +1,10 @@
import React from 'react';
import { CascaderData } from '@douyinfe/semi-ui/lib/es/cascader';
import Icon from '@douyinfe/semi-icons';
import { JsonSchema } from './types';
export const VariableTypeIcons: { [key: string]: React.ReactNode } = {
custom: (
<svg
@ -263,3 +270,90 @@ export const ArrayIcons: { [key: string]: React.ReactNode } = {
</svg>
),
};
export const getSchemaIcon = (value?: Partial<JsonSchema>) => {
if (value?.type === 'array') {
return ArrayIcons[value.items?.type || 'object'];
}
return VariableTypeIcons[value?.type || 'object'];
};
const labelStyle: React.CSSProperties = { display: 'flex', alignItems: 'center', gap: 5 };
const firstUppercase = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
const baseOptions: CascaderData[] = [
{
label: (
<div style={labelStyle}>
<Icon size="small" svg={getSchemaIcon({ type: 'string' })} />
{firstUppercase('string')}
</div>
),
value: 'string',
},
{
label: (
<div style={labelStyle}>
<Icon size="small" svg={getSchemaIcon({ type: 'integer' })} />
{firstUppercase('integer')}
</div>
),
value: 'integer',
},
{
label: (
<div style={labelStyle}>
<Icon size="small" svg={getSchemaIcon({ type: 'number' })} />
{firstUppercase('number')}
</div>
),
value: 'number',
},
{
label: (
<div style={labelStyle}>
<Icon size="small" svg={getSchemaIcon({ type: 'boolean' })} />
{firstUppercase('boolean')}
</div>
),
value: 'boolean',
},
{
label: (
<div style={labelStyle}>
<Icon size="small" svg={getSchemaIcon({ type: 'object' })} />
{firstUppercase('object')}
</div>
),
value: 'object',
},
];
export const options: CascaderData[] = [
...baseOptions,
{
label: (
<div style={labelStyle}>
<Icon size="small" svg={getSchemaIcon({ type: 'array' })} />
{firstUppercase('array')}
</div>
),
value: 'array',
children: baseOptions.map((_opt) => ({
..._opt,
value: `${_opt.value}`,
label: (
<div style={labelStyle}>
<Icon
size="small"
svg={getSchemaIcon({ type: 'array', items: { type: _opt.value as string } })}
/>
{firstUppercase(_opt.value as string)}
</div>
),
})),
},
];

View File

@ -0,0 +1,54 @@
import React, { useMemo } from 'react';
import { Button, Cascader } from '@douyinfe/semi-ui';
import { JsonSchema } from './types';
import { ArrayIcons, VariableTypeIcons, getSchemaIcon, options } from './constants';
interface PropTypes {
value?: Partial<JsonSchema>;
onChange: (value?: Partial<JsonSchema>) => void;
}
export const getTypeSelectValue = (value?: Partial<JsonSchema>): string[] | undefined => {
if (value?.type === 'array' && value?.items) {
return [value.type, ...(getTypeSelectValue(value.items) || [])];
}
return value?.type ? [value.type] : undefined;
};
export const parseTypeSelectValue = (value?: string[]): Partial<JsonSchema> | undefined => {
const [type, ...subTypes] = value || [];
if (type === 'array') {
return { type: 'array', items: parseTypeSelectValue(subTypes) };
}
return { type };
};
export function TypeSelector(props: PropTypes) {
const { value, onChange } = props;
const selectValue = useMemo(() => getTypeSelectValue(value), [value]);
return (
<Cascader
size="small"
triggerRender={() => (
<Button size="small" style={{ width: 50 }}>
{getSchemaIcon(value)}
</Button>
)}
treeData={options}
value={selectValue}
leafOnly={true}
onChange={(value) => {
onChange(parseTypeSelectValue(value as string[]));
}}
/>
);
}
export { JsonSchema, VariableTypeIcons, ArrayIcons, getSchemaIcon };

View File

@ -0,0 +1,19 @@
export type BasicType = 'boolean' | 'string' | 'integer' | 'number' | 'object' | 'array';
export interface JsonSchema<T = string> {
type?: T;
default?: any;
title?: string;
description?: string;
enum?: (string | number)[];
properties?: Record<string, JsonSchema>;
additionalProperties?: JsonSchema;
items?: JsonSchema;
required?: string[];
$ref?: string;
extra?: {
order?: number;
literal?: boolean; // is literal type
formComponent?: string; // Set the render component
};
}

View File

@ -0,0 +1,5 @@
{
"name": "variable-selector",
"depMaterials": ["type-selector"],
"depPackages": ["@douyinfe/semi-ui"]
}

View File

@ -0,0 +1,45 @@
import React from 'react';
import { TreeSelect } from '@douyinfe/semi-ui';
import { useVariableTree } from './use-variable-tree';
export interface PropTypes {
value?: string;
onChange: (value?: string) => void;
readonly?: boolean;
hasError?: boolean;
style?: React.CSSProperties;
}
export const VariableSelector = ({
value,
onChange,
style,
readonly = false,
hasError,
}: PropTypes) => {
const treeData = useVariableTree();
return (
<>
<TreeSelect
dropdownMatchSelectWidth={false}
disabled={readonly}
treeData={treeData}
size="small"
value={value}
style={{
...style,
outline: hasError ? '1px solid red' : undefined,
}}
validateStatus={hasError ? 'error' : undefined}
onChange={(option) => {
onChange(option as string);
}}
showClear
placeholder="Select Variable..."
/>
</>
);
};

View File

@ -0,0 +1,73 @@
import React, { useCallback } from 'react';
import { useScopeAvailable, ASTMatch, BaseVariableField } from '@flowgram.ai/editor';
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
import { Icon } from '@douyinfe/semi-ui';
import { ArrayIcons, VariableTypeIcons } from '../type-selector/constants';
type VariableField = BaseVariableField<{ icon?: string | JSX.Element; title?: string }>;
export function useVariableTree(): TreeNodeData[] {
const available = useScopeAvailable();
const getVariableTypeIcon = useCallback((variable: VariableField) => {
if (variable.meta.icon) {
if (typeof variable.meta.icon === 'string') {
return <img style={{ marginRight: 8 }} width={12} height={12} src={variable.meta.icon} />;
}
return variable.meta.icon;
}
const _type = variable.type;
if (ASTMatch.isArray(_type)) {
return (
<Icon
size="small"
svg={ArrayIcons[_type.items?.kind.toLowerCase()] || VariableTypeIcons.array}
/>
);
}
if (ASTMatch.isCustomType(_type)) {
return <Icon size="small" svg={VariableTypeIcons[_type.typeName.toLowerCase()]} />;
}
return <Icon size="small" svg={VariableTypeIcons[variable.type?.kind.toLowerCase()]} />;
}, []);
const renderVariable = (
variable: VariableField,
parentFields: VariableField[] = []
): TreeNodeData | null => {
let type = variable?.type;
let children: TreeNodeData[] | undefined;
if (ASTMatch.isObject(type)) {
children = (type.properties || [])
.map((_property) => renderVariable(_property as VariableField, [...parentFields, variable]))
.filter(Boolean) as TreeNodeData[];
if (!children?.length) {
return null;
}
}
const currPath = [...parentFields.map((_field) => _field.key), variable.key].join('.');
return {
key: currPath,
label: variable.meta.title || variable.key,
value: currPath,
icon: getVariableTypeIcon(variable),
children,
};
};
return [...available.variables.slice(0).reverse()]
.map((_variable) => renderVariable(_variable as VariableField))
.filter(Boolean) as TreeNodeData[];
}

View File

@ -0,0 +1 @@
export * from './components';

View File

@ -0,0 +1,8 @@
{
"extends": "@flowgram.ai/ts-config/tsconfig.flow.path.json",
"compilerOptions": {
"jsx": "react",
},
"include": ["./src"],
"exclude": ["node_modules"]
}

View File

@ -0,0 +1,26 @@
const path = require('path');
import { defineConfig } from 'vitest/config';
export default defineConfig({
build: {
commonjsOptions: {
transformMixedEsModules: true,
},
},
test: {
globals: true,
mockReset: false,
environment: 'jsdom',
setupFiles: [path.resolve(__dirname, './vitest.setup.ts')],
include: ['**/?(*.){test,spec}.?(c|m)[jt]s?(x)'],
exclude: [
'**/__mocks__**',
'**/node_modules/**',
'**/dist/**',
'**/lib/**', // lib 编译结果忽略掉
'**/cypress/**',
'**/.{idea,git,cache,output,temp}/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
],
},
});

View File

@ -0,0 +1 @@
import 'reflect-metadata';

View File

@ -713,6 +713,12 @@
"versionPolicyName": "publishPolicy",
"tags": ["level-1", "team-flow"]
},
{
"packageName": "@flowgram.ai/form-materials",
"projectFolder": "packages/materials/form-materials",
"versionPolicyName": "publishPolicy",
"tags": ["level-1", "team-flow"]
},
{
"packageName": "@flowgram.ai/free-auto-layout-plugin",
"projectFolder": "packages/plugins/free-auto-layout-plugin",