|
@@ -3,16 +3,19 @@
|
|
|
* SPDX-License-Identifier: MIT
|
|
* SPDX-License-Identifier: MIT
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-import React, { useMemo } from 'react';
|
|
|
|
|
|
|
+import React, { useMemo, useState } from 'react';
|
|
|
|
|
|
|
|
|
|
+import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
|
import { IconButton } from '@douyinfe/semi-ui';
|
|
import { IconButton } from '@douyinfe/semi-ui';
|
|
|
import { IconSetting } from '@douyinfe/semi-icons';
|
|
import { IconSetting } from '@douyinfe/semi-icons';
|
|
|
|
|
|
|
|
import { Strategy } from '../constant-input/types';
|
|
import { Strategy } from '../constant-input/types';
|
|
|
import { ConstantInput } from '../constant-input';
|
|
import { ConstantInput } from '../constant-input';
|
|
|
|
|
+import { JsonSchemaUtils } from '../../utils';
|
|
|
import { IFlowConstantRefValue } from '../../typings/flow-value';
|
|
import { IFlowConstantRefValue } from '../../typings/flow-value';
|
|
|
-import { UIContainer, UIMain, UITrigger } from './styles';
|
|
|
|
|
|
|
+import { UIContainer, UIMain, UITrigger, UIType } from './styles';
|
|
|
import { VariableSelector } from '../variable-selector';
|
|
import { VariableSelector } from '../variable-selector';
|
|
|
|
|
+import { TypeSelector } from '../type-selector';
|
|
|
import { IJsonSchema } from '../../typings';
|
|
import { IJsonSchema } from '../../typings';
|
|
|
|
|
|
|
|
interface PropsType {
|
|
interface PropsType {
|
|
@@ -34,16 +37,50 @@ export function DynamicValueInput({
|
|
|
onChange,
|
|
onChange,
|
|
|
readonly,
|
|
readonly,
|
|
|
style,
|
|
style,
|
|
|
- schema,
|
|
|
|
|
|
|
+ schema: schemaFromProps,
|
|
|
constantProps,
|
|
constantProps,
|
|
|
}: PropsType) {
|
|
}: PropsType) {
|
|
|
|
|
+ const available = useScopeAvailable();
|
|
|
|
|
+ const refVariable = useMemo(() => {
|
|
|
|
|
+ if (value?.type === 'ref') {
|
|
|
|
|
+ return available.getByKeyPath(value.content);
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [value, available]);
|
|
|
|
|
+
|
|
|
|
|
+ const [selectSchema, setSelectSchema] = useState(
|
|
|
|
|
+ schemaFromProps || constantProps?.schema || { type: 'string' }
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ const renderTypeSelector = () => {
|
|
|
|
|
+ if (schemaFromProps) {
|
|
|
|
|
+ return <TypeSelector value={schemaFromProps} readonly={true} />;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (value?.type === 'ref') {
|
|
|
|
|
+ const schema = refVariable?.type ? JsonSchemaUtils.astToSchema(refVariable?.type) : undefined;
|
|
|
|
|
+
|
|
|
|
|
+ return <TypeSelector value={schema} readonly={true} />;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <TypeSelector
|
|
|
|
|
+ value={selectSchema}
|
|
|
|
|
+ onChange={(_v) => setSelectSchema(_v || { type: 'string' })}
|
|
|
|
|
+ readonly={readonly}
|
|
|
|
|
+ />
|
|
|
|
|
+ );
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
// When is number type, include integer as well
|
|
// When is number type, include integer as well
|
|
|
const includeSchema = useMemo(() => {
|
|
const includeSchema = useMemo(() => {
|
|
|
- if (schema?.type === 'number') {
|
|
|
|
|
- return [schema, { type: 'integer' }];
|
|
|
|
|
|
|
+ if (!schemaFromProps) {
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- return schema;
|
|
|
|
|
- }, [schema]);
|
|
|
|
|
|
|
+ if (schemaFromProps?.type === 'number') {
|
|
|
|
|
+ return [schemaFromProps, { type: 'integer' }];
|
|
|
|
|
+ }
|
|
|
|
|
+ return { ...schemaFromProps, extra: { ...schemaFromProps?.extra, weak: true } };
|
|
|
|
|
+ }, [schemaFromProps]);
|
|
|
|
|
|
|
|
const renderMain = () => {
|
|
const renderMain = () => {
|
|
|
if (value?.type === 'ref') {
|
|
if (value?.type === 'ref') {
|
|
@@ -59,12 +96,23 @@ export function DynamicValueInput({
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const constantSchema = schemaFromProps || selectSchema || { type: 'string' };
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<ConstantInput
|
|
<ConstantInput
|
|
|
value={value?.content}
|
|
value={value?.content}
|
|
|
- onChange={(_v) => onChange({ type: 'constant', content: _v })}
|
|
|
|
|
- schema={schema || { type: 'string' }}
|
|
|
|
|
|
|
+ onChange={(_v) => onChange({ type: 'constant', content: _v, schema: constantSchema })}
|
|
|
|
|
+ schema={constantSchema || { type: 'string' }}
|
|
|
readonly={readonly}
|
|
readonly={readonly}
|
|
|
|
|
+ strategies={[...(constantProps?.strategies || [])]}
|
|
|
|
|
+ fallbackRenderer={() => (
|
|
|
|
|
+ <VariableSelector
|
|
|
|
|
+ style={{ width: '100%' }}
|
|
|
|
|
+ onChange={(_v) => onChange(_v ? { type: 'ref', content: _v } : undefined)}
|
|
|
|
|
+ includeSchema={includeSchema}
|
|
|
|
|
+ readonly={readonly}
|
|
|
|
|
+ />
|
|
|
|
|
+ )}
|
|
|
{...constantProps}
|
|
{...constantProps}
|
|
|
/>
|
|
/>
|
|
|
);
|
|
);
|
|
@@ -85,6 +133,7 @@ export function DynamicValueInput({
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<UIContainer style={style}>
|
|
<UIContainer style={style}>
|
|
|
|
|
+ <UIType>{renderTypeSelector()}</UIType>
|
|
|
<UIMain>{renderMain()}</UIMain>
|
|
<UIMain>{renderMain()}</UIMain>
|
|
|
<UITrigger>{renderTrigger()}</UITrigger>
|
|
<UITrigger>{renderTrigger()}</UITrigger>
|
|
|
</UIContainer>
|
|
</UIContainer>
|