|
@@ -18,6 +18,7 @@ import {
|
|
|
} from '@douyinfe/semi-icons';
|
|
} from '@douyinfe/semi-icons';
|
|
|
|
|
|
|
|
import { InjectTypeSelector } from '@/components/type-selector';
|
|
import { InjectTypeSelector } from '@/components/type-selector';
|
|
|
|
|
+import { BlurInput } from '@/components/blur-input';
|
|
|
|
|
|
|
|
import { ConfigType, PropertyValueType } from './types';
|
|
import { ConfigType, PropertyValueType } from './types';
|
|
|
import {
|
|
import {
|
|
@@ -28,10 +29,10 @@ import {
|
|
|
UIContainer,
|
|
UIContainer,
|
|
|
UIExpandDetail,
|
|
UIExpandDetail,
|
|
|
UILabel,
|
|
UILabel,
|
|
|
- UIProperties,
|
|
|
|
|
- UIPropertyLeft,
|
|
|
|
|
- UIPropertyMain,
|
|
|
|
|
- UIPropertyRight,
|
|
|
|
|
|
|
+ UITreeItems,
|
|
|
|
|
+ UITreeItemLeft,
|
|
|
|
|
+ UITreeItemMain,
|
|
|
|
|
+ UITreeItemRight,
|
|
|
UIRequired,
|
|
UIRequired,
|
|
|
UIType,
|
|
UIType,
|
|
|
} from './styles';
|
|
} from './styles';
|
|
@@ -39,7 +40,6 @@ import { UIName } from './styles';
|
|
|
import { DefaultValueWrapper, UIRow } from './styles';
|
|
import { DefaultValueWrapper, UIRow } from './styles';
|
|
|
import { usePropertiesEdit } from './hooks';
|
|
import { usePropertiesEdit } from './hooks';
|
|
|
import { DefaultValue } from './default-value';
|
|
import { DefaultValue } from './default-value';
|
|
|
-import { BlurInput } from './components/blur-input';
|
|
|
|
|
|
|
|
|
|
const DEFAULT = { type: 'object' };
|
|
const DEFAULT = { type: 'object' };
|
|
|
|
|
|
|
@@ -58,14 +58,13 @@ export function JsonSchemaEditor(props: {
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<UIContainer className={props.className}>
|
|
<UIContainer className={props.className}>
|
|
|
- <UIProperties>
|
|
|
|
|
- {propertyList.map((_property, index) => (
|
|
|
|
|
|
|
+ <UITreeItems>
|
|
|
|
|
+ {propertyList.map((_property) => (
|
|
|
<PropertyEdit
|
|
<PropertyEdit
|
|
|
readonly={readonly}
|
|
readonly={readonly}
|
|
|
key={_property.key}
|
|
key={_property.key}
|
|
|
value={_property}
|
|
value={_property}
|
|
|
config={config}
|
|
config={config}
|
|
|
- $index={index}
|
|
|
|
|
onChange={(_v) => {
|
|
onChange={(_v) => {
|
|
|
onEditProperty(_property.key!, _v);
|
|
onEditProperty(_property.key!, _v);
|
|
|
}}
|
|
}}
|
|
@@ -74,7 +73,7 @@ export function JsonSchemaEditor(props: {
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
))}
|
|
))}
|
|
|
- </UIProperties>
|
|
|
|
|
|
|
+ </UITreeItems>
|
|
|
<Button
|
|
<Button
|
|
|
disabled={readonly}
|
|
disabled={readonly}
|
|
|
size="small"
|
|
size="small"
|
|
@@ -95,27 +94,9 @@ function PropertyEdit(props: {
|
|
|
onRemove?: () => void;
|
|
onRemove?: () => void;
|
|
|
readonly?: boolean;
|
|
readonly?: boolean;
|
|
|
$isLast?: boolean;
|
|
$isLast?: boolean;
|
|
|
- $index?: number;
|
|
|
|
|
- $isFirst?: boolean;
|
|
|
|
|
- $parentExpand?: boolean;
|
|
|
|
|
- $parentType?: string;
|
|
|
|
|
- $showLine?: boolean;
|
|
|
|
|
$level?: number; // 添加层级属性
|
|
$level?: number; // 添加层级属性
|
|
|
}) {
|
|
}) {
|
|
|
- const {
|
|
|
|
|
- value,
|
|
|
|
|
- config,
|
|
|
|
|
- readonly,
|
|
|
|
|
- $level = 0,
|
|
|
|
|
- onChange: onChangeProps,
|
|
|
|
|
- onRemove,
|
|
|
|
|
- $index,
|
|
|
|
|
- $isFirst,
|
|
|
|
|
- $isLast,
|
|
|
|
|
- $parentExpand = false,
|
|
|
|
|
- $parentType = '',
|
|
|
|
|
- $showLine,
|
|
|
|
|
- } = props;
|
|
|
|
|
|
|
+ const { value, config, readonly, $level = 0, onChange: onChangeProps, onRemove, $isLast } = props;
|
|
|
|
|
|
|
|
const [expand, setExpand] = useState(false);
|
|
const [expand, setExpand] = useState(false);
|
|
|
const [collapse, setCollapse] = useState(false);
|
|
const [collapse, setCollapse] = useState(false);
|
|
@@ -138,29 +119,15 @@ function PropertyEdit(props: {
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
|
- <UIPropertyLeft
|
|
|
|
|
- type={type}
|
|
|
|
|
- $index={$index}
|
|
|
|
|
- $isFirst={$isFirst}
|
|
|
|
|
- $isLast={$isLast}
|
|
|
|
|
- $showLine={$showLine}
|
|
|
|
|
- $isExpand={expand}
|
|
|
|
|
- $parentExpand={$parentExpand}
|
|
|
|
|
- $parentType={$parentType}
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ <UITreeItemLeft $isLast={$isLast} $showLine={$level > 0} $showCollapse={showCollapse}>
|
|
|
{showCollapse && (
|
|
{showCollapse && (
|
|
|
<UICollapseTrigger onClick={() => setCollapse((_collapse) => !_collapse)}>
|
|
<UICollapseTrigger onClick={() => setCollapse((_collapse) => !_collapse)}>
|
|
|
{collapse ? <IconChevronDown size="small" /> : <IconChevronRight size="small" />}
|
|
{collapse ? <IconChevronDown size="small" /> : <IconChevronRight size="small" />}
|
|
|
</UICollapseTrigger>
|
|
</UICollapseTrigger>
|
|
|
)}
|
|
)}
|
|
|
- </UIPropertyLeft>
|
|
|
|
|
- <UIPropertyRight>
|
|
|
|
|
- <UIPropertyMain
|
|
|
|
|
- $showCollapse={showCollapse}
|
|
|
|
|
- $collapse={collapse}
|
|
|
|
|
- $expand={expand}
|
|
|
|
|
- type={type}
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ </UITreeItemLeft>
|
|
|
|
|
+ <UITreeItemRight>
|
|
|
|
|
+ <UITreeItemMain>
|
|
|
<UIRow>
|
|
<UIRow>
|
|
|
<UIName>
|
|
<UIName>
|
|
|
<BlurInput
|
|
<BlurInput
|
|
@@ -242,9 +209,7 @@ function PropertyEdit(props: {
|
|
|
<DefaultValue
|
|
<DefaultValue
|
|
|
value={defaultValue}
|
|
value={defaultValue}
|
|
|
schema={value}
|
|
schema={value}
|
|
|
- type={type}
|
|
|
|
|
placeholder={config?.defaultValuePlaceholder ?? I18n.t('Default Value')}
|
|
placeholder={config?.defaultValuePlaceholder ?? I18n.t('Default Value')}
|
|
|
- jsonFormatText={config?.jsonFormatText}
|
|
|
|
|
onChange={(value) => onChange('default', value)}
|
|
onChange={(value) => onChange('default', value)}
|
|
|
/>
|
|
/>
|
|
|
</DefaultValueWrapper>
|
|
</DefaultValueWrapper>
|
|
@@ -252,10 +217,10 @@ function PropertyEdit(props: {
|
|
|
)}
|
|
)}
|
|
|
</UIExpandDetail>
|
|
</UIExpandDetail>
|
|
|
)}
|
|
)}
|
|
|
- </UIPropertyMain>
|
|
|
|
|
|
|
+ </UITreeItemMain>
|
|
|
{showCollapse && (
|
|
{showCollapse && (
|
|
|
<UICollapsible $collapse={collapse}>
|
|
<UICollapsible $collapse={collapse}>
|
|
|
- <UIProperties $shrink={true}>
|
|
|
|
|
|
|
+ <UITreeItems $shrink={true}>
|
|
|
{propertyList.map((_property, index) => (
|
|
{propertyList.map((_property, index) => (
|
|
|
<PropertyEdit
|
|
<PropertyEdit
|
|
|
readonly={readonly}
|
|
readonly={readonly}
|
|
@@ -263,8 +228,6 @@ function PropertyEdit(props: {
|
|
|
value={_property}
|
|
value={_property}
|
|
|
config={config}
|
|
config={config}
|
|
|
$level={$level + 1} // 传递递增的层级
|
|
$level={$level + 1} // 传递递增的层级
|
|
|
- $parentExpand={expand}
|
|
|
|
|
- $parentType={type}
|
|
|
|
|
onChange={(_v) => {
|
|
onChange={(_v) => {
|
|
|
onEditProperty(_property.key!, _v);
|
|
onEditProperty(_property.key!, _v);
|
|
|
}}
|
|
}}
|
|
@@ -272,15 +235,12 @@ function PropertyEdit(props: {
|
|
|
onRemoveProperty(_property.key!);
|
|
onRemoveProperty(_property.key!);
|
|
|
}}
|
|
}}
|
|
|
$isLast={index === propertyList.length - 1}
|
|
$isLast={index === propertyList.length - 1}
|
|
|
- $isFirst={index === 0}
|
|
|
|
|
- $index={index}
|
|
|
|
|
- $showLine={true}
|
|
|
|
|
/>
|
|
/>
|
|
|
))}
|
|
))}
|
|
|
- </UIProperties>
|
|
|
|
|
|
|
+ </UITreeItems>
|
|
|
</UICollapsible>
|
|
</UICollapsible>
|
|
|
)}
|
|
)}
|
|
|
- </UIPropertyRight>
|
|
|
|
|
|
|
+ </UITreeItemRight>
|
|
|
</>
|
|
</>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|