Skip to content

Commit 8a373f7

Browse files
authored
feat(material): inject materials like VariableSelector, TypeSelector (bytedance#665)
* feat(material): inject material * feat: update docs * fix: file path * fix: i18n text * fix: remove useless code
1 parent 4b6e4ef commit 8a373f7

File tree

13 files changed

+473
-26
lines changed

13 files changed

+473
-26
lines changed

apps/demo-free-layout/src/hooks/use-editor-props.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export function useEditorProps(
192192
enableScrollLimit: false,
193193
},
194194
materials: {
195+
components: {},
195196
/**
196197
* Render Node
197198
*/

packages/materials/form-materials/src/components/assign-row/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { IconButton } from '@douyinfe/semi-ui';
99
import { IconMinus } from '@douyinfe/semi-icons';
1010

1111
import { IFlowConstantRefValue } from '@/typings';
12-
import { VariableSelector } from '@/components/variable-selector';
13-
import { DynamicValueInput } from '@/components/dynamic-value-input';
12+
import { InjectVariableSelector } from '@/components/variable-selector';
13+
import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
1414

1515
import { AssignRowProps } from './types';
1616
import { BlurInput } from './components/blur-input';
@@ -29,7 +29,7 @@ export function AssignRow(props: AssignRowProps) {
2929
<div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
3030
<div style={{ width: 150, minWidth: 150, maxWidth: 150 }}>
3131
{value?.operator === 'assign' ? (
32-
<VariableSelector
32+
<InjectVariableSelector
3333
style={{ width: '100%', height: 26 }}
3434
value={value?.left?.content}
3535
config={{ placeholder: 'Select Left' }}
@@ -56,7 +56,7 @@ export function AssignRow(props: AssignRowProps) {
5656
)}
5757
</div>
5858
<div style={{ flexGrow: 1 }}>
59-
<DynamicValueInput
59+
<InjectDynamicValueInput
6060
readonly={readonly}
6161
value={value?.right as IFlowConstantRefValue | undefined}
6262
onChange={(v) =>

packages/materials/form-materials/src/components/batch-outputs/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Button, Input } from '@douyinfe/semi-ui';
99
import { IconDelete, IconPlus } from '@douyinfe/semi-icons';
1010

1111
import { useObjectList } from '@/hooks';
12-
import { VariableSelector } from '@/components/variable-selector';
12+
import { InjectVariableSelector } from '@/components/variable-selector';
1313

1414
import { PropsType } from './types';
1515
import { UIRow, UIRows } from './styles';
@@ -31,7 +31,7 @@ export function BatchOutputs(props: PropsType) {
3131
value={item.key}
3232
onChange={(v) => updateKey(item.id, v)}
3333
/>
34-
<VariableSelector
34+
<InjectVariableSelector
3535
style={{ flexGrow: 1 }}
3636
readonly={readonly}
3737
value={item.value?.content}

packages/materials/form-materials/src/components/condition-row/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import React, { useMemo } from 'react';
88
import { I18n } from '@flowgram.ai/editor';
99
import { Input } from '@douyinfe/semi-ui';
1010

11-
import { VariableSelector } from '@/components/variable-selector';
12-
import { DynamicValueInput } from '@/components/dynamic-value-input';
11+
import { InjectVariableSelector } from '@/components/variable-selector';
12+
import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
1313

1414
import { ConditionRowValueType, IRules, OpConfigs } from './types';
1515
import { UIContainer, UILeft, UIOperator, UIRight, UIValues } from './styles';
@@ -59,7 +59,7 @@ export function ConditionRow({
5959
<UIOperator>{renderOpSelect()}</UIOperator>
6060
<UIValues>
6161
<UILeft>
62-
<VariableSelector
62+
<InjectVariableSelector
6363
readonly={readonly}
6464
style={{ width: '100%' }}
6565
value={left?.content}
@@ -76,7 +76,7 @@ export function ConditionRow({
7676
</UILeft>
7777
<UIRight>
7878
{targetSchema ? (
79-
<DynamicValueInput
79+
<InjectDynamicValueInput
8080
readonly={readonly || !rule}
8181
value={right}
8282
schema={targetSchema}

packages/materials/form-materials/src/components/dynamic-value-input/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { IconButton } from '@douyinfe/semi-ui';
1010
import { IconSetting } from '@douyinfe/semi-icons';
1111

1212
import { IFlowConstantRefValue } from '@/typings/flow-value';
13-
import { VariableSelector } from '@/components/variable-selector';
13+
import { createInjectMaterial } from '@/shared';
14+
import { InjectVariableSelector } from '@/components/variable-selector';
1415
import { TypeSelector } from '@/components/type-selector';
1516
import { ConstantInput, ConstantInputStrategy } from '@/components/constant-input';
1617

@@ -88,7 +89,7 @@ export function DynamicValueInput({
8889
if (value?.type === 'ref') {
8990
// Display Variable Or Delete
9091
return (
91-
<VariableSelector
92+
<InjectVariableSelector
9293
style={{ width: '100%' }}
9394
value={value?.content}
9495
onChange={(_v) => onChange(_v ? { type: 'ref', content: _v } : undefined)}
@@ -108,7 +109,7 @@ export function DynamicValueInput({
108109
readonly={readonly}
109110
strategies={[...(constantProps?.strategies || [])]}
110111
fallbackRenderer={() => (
111-
<VariableSelector
112+
<InjectVariableSelector
112113
style={{ width: '100%' }}
113114
onChange={(_v) => onChange(_v ? { type: 'ref', content: _v } : undefined)}
114115
includeSchema={includeSchema}
@@ -121,7 +122,7 @@ export function DynamicValueInput({
121122
};
122123

123124
const renderTrigger = () => (
124-
<VariableSelector
125+
<InjectVariableSelector
125126
style={{ width: '100%' }}
126127
value={value?.type === 'ref' ? value?.content : undefined}
127128
onChange={(_v) => onChange({ type: 'ref', content: _v })}
@@ -141,3 +142,6 @@ export function DynamicValueInput({
141142
</UIContainer>
142143
);
143144
}
145+
146+
DynamicValueInput.renderKey = 'dynamic-value-input-render-key';
147+
export const InjectDynamicValueInput = createInjectMaterial(DynamicValueInput);

packages/materials/form-materials/src/components/inputs-values/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
import React from 'react';
77

8+
import { I18n } from '@flowgram.ai/editor';
89
import { Button, IconButton } from '@douyinfe/semi-ui';
910
import { IconDelete, IconPlus } from '@douyinfe/semi-icons';
1011

1112
import { IFlowConstantRefValue, IFlowValue } from '@/typings';
1213
import { useObjectList } from '@/hooks';
13-
import { DynamicValueInput } from '@/components/dynamic-value-input';
14+
import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
1415

1516
import { PropsType } from './types';
1617
import { UIRow, UIRows } from './styles';
@@ -42,9 +43,9 @@ export function InputsValues({
4243
size="small"
4344
value={item.key}
4445
onChange={(v) => updateKey(item.id, v)}
45-
placeholder="Input Key"
46+
placeholder={I18n.t('Input Key')}
4647
/>
47-
<DynamicValueInput
48+
<InjectDynamicValueInput
4849
style={{ flexGrow: 1 }}
4950
readonly={readonly}
5051
value={item.value as IFlowConstantRefValue}

packages/materials/form-materials/src/components/json-schema-editor/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
IconMinus,
1818
} from '@douyinfe/semi-icons';
1919

20-
import { TypeSelector } from '@/components/type-selector';
20+
import { InjectTypeSelector } from '@/components/type-selector';
2121

2222
import { ConfigType, PropertyValueType } from './types';
2323
import {
@@ -41,14 +41,16 @@ import { usePropertiesEdit } from './hooks';
4141
import { DefaultValue } from './default-value';
4242
import { BlurInput } from './components/blur-input';
4343

44+
const DEFAULT = { type: 'object' };
45+
4446
export function JsonSchemaEditor(props: {
4547
value?: IJsonSchema;
4648
onChange?: (value: IJsonSchema) => void;
4749
config?: ConfigType;
4850
className?: string;
4951
readonly?: boolean;
5052
}) {
51-
const { value = { type: 'object' }, config = {}, onChange: onChangeProps, readonly } = props;
53+
const { value = DEFAULT, config = {}, onChange: onChangeProps, readonly } = props;
5254
const { propertyList, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(
5355
value,
5456
onChangeProps
@@ -170,7 +172,7 @@ function PropertyEdit(props: {
170172
/>
171173
</UIName>
172174
<UIType>
173-
<TypeSelector
175+
<InjectTypeSelector
174176
value={typeSelectorValue}
175177
readonly={readonly}
176178
onChange={(_value) => {

packages/materials/form-materials/src/components/type-selector/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import React, { useMemo } from 'react';
88
import { IJsonSchema } from '@flowgram.ai/json-schema';
99
import { Cascader, Icon, IconButton } from '@douyinfe/semi-ui';
1010

11+
import { createInjectMaterial } from '@/shared/inject-material';
1112
import { useTypeManager } from '@/plugins';
1213

13-
interface PropTypes {
14+
export interface TypeSelectorProps {
1415
value?: Partial<IJsonSchema>;
1516
onChange?: (value?: Partial<IJsonSchema>) => void;
1617
readonly?: boolean;
@@ -41,7 +42,7 @@ export const parseTypeSelectValue = (value?: string[]): Partial<IJsonSchema> | u
4142
return { type };
4243
};
4344

44-
export function TypeSelector(props: PropTypes) {
45+
export function TypeSelector(props: TypeSelectorProps) {
4546
const { value, onChange, readonly, disabled, style } = props;
4647

4748
const selectValue = useMemo(() => getTypeSelectValue(value), [value]);
@@ -101,3 +102,6 @@ export function TypeSelector(props: PropTypes) {
101102
/>
102103
);
103104
}
105+
106+
TypeSelector.renderKey = 'type-selector-render-key';
107+
export const InjectTypeSelector = createInjectMaterial(TypeSelector);

packages/materials/form-materials/src/components/variable-selector/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
1212
import { Popover } from '@douyinfe/semi-ui';
1313
import { IconChevronDownStroked, IconIssueStroked } from '@douyinfe/semi-icons';
1414

15+
import { createInjectMaterial } from '@/shared';
16+
1517
import { useVariableTree } from './use-variable-tree';
1618
import { UIPopoverContent, UIRootTitle, UITag, UITreeSelect, UIVarName } from './styles';
1719

18-
interface PropTypes {
20+
export interface VariableSelectorProps {
1921
value?: string[];
2022
config?: {
2123
placeholder?: string;
@@ -30,8 +32,6 @@ interface PropTypes {
3032
triggerRender?: (props: TriggerRenderProps) => React.ReactNode;
3133
}
3234

33-
export type VariableSelectorProps = PropTypes;
34-
3535
export { useVariableTree };
3636

3737
export const VariableSelector = ({
@@ -44,7 +44,7 @@ export const VariableSelector = ({
4444
excludeSchema,
4545
hasError,
4646
triggerRender,
47-
}: PropTypes) => {
47+
}: VariableSelectorProps) => {
4848
const treeData = useVariableTree({ includeSchema, excludeSchema });
4949

5050
const treeValue = useMemo(() => {
@@ -136,3 +136,6 @@ export const VariableSelector = ({
136136
</>
137137
);
138138
};
139+
140+
VariableSelector.renderKey = 'variable-selector-render-key';
141+
export const InjectVariableSelector = createInjectMaterial(VariableSelector);

packages/materials/form-materials/src/shared/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*/
55

66
export * from './format-legacy-refs';
7+
export * from './inject-material';

0 commit comments

Comments
 (0)