@flowgram.ai/form-materials 0.4.5 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/chunk-727SU246.js +13 -0
- package/dist/esm/chunk-727SU246.js.map +1 -0
- package/dist/esm/chunk-DEZUEMUM.js +284 -0
- package/dist/esm/chunk-DEZUEMUM.js.map +1 -0
- package/dist/esm/chunk-MFDEE4HB.js +440 -0
- package/dist/esm/chunk-MFDEE4HB.js.map +1 -0
- package/dist/esm/editor-2YHACGQ2.js +282 -0
- package/dist/esm/editor-2YHACGQ2.js.map +1 -0
- package/dist/esm/editor-6UMULJYB.js +180 -0
- package/dist/esm/editor-6UMULJYB.js.map +1 -0
- package/dist/esm/editor-E2BQTPCD.js +388 -0
- package/dist/esm/editor-E2BQTPCD.js.map +1 -0
- package/dist/esm/editor-G63XGWH2.js +249 -0
- package/dist/esm/editor-G63XGWH2.js.map +1 -0
- package/dist/esm/editor-OXPGKPF5.js +167 -0
- package/dist/esm/editor-OXPGKPF5.js.map +1 -0
- package/dist/esm/index.js +607 -2300
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +141 -51
- package/dist/index.d.ts +141 -51
- package/dist/index.js +3545 -2825
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/components/code-editor/editor.tsx +96 -0
- package/src/components/code-editor/index.tsx +5 -89
- package/src/components/code-editor-mini/index.tsx +2 -2
- package/src/components/condition-row/index.tsx +4 -0
- package/src/components/db-condition-row/hooks/use-left.tsx +66 -0
- package/src/components/db-condition-row/hooks/use-op.tsx +59 -0
- package/src/components/db-condition-row/index.tsx +93 -0
- package/src/components/db-condition-row/styles.tsx +43 -0
- package/src/components/db-condition-row/types.ts +34 -0
- package/src/components/display-inputs-values/index.tsx +1 -1
- package/src/components/dynamic-value-input/hooks.ts +1 -1
- package/src/components/index.ts +1 -0
- package/src/components/inputs-values-tree/hooks/use-child-list.tsx +1 -1
- package/src/components/json-editor-with-variables/editor.tsx +69 -0
- package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +1 -1
- package/src/components/json-editor-with-variables/index.tsx +5 -60
- package/src/components/json-schema-editor/hooks.tsx +1 -1
- package/src/components/prompt-editor/editor.tsx +81 -0
- package/src/components/prompt-editor/index.tsx +5 -69
- package/src/components/prompt-editor-with-inputs/editor.tsx +25 -0
- package/src/components/prompt-editor-with-inputs/index.tsx +5 -15
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +1 -1
- package/src/components/prompt-editor-with-variables/editor.tsx +22 -0
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +1 -1
- package/src/components/prompt-editor-with-variables/index.tsx +5 -13
- package/src/effects/validate-when-variable-sync/index.ts +1 -1
- package/src/form-plugins/infer-assign-plugin/index.ts +1 -1
- package/src/form-plugins/infer-inputs-plugin/index.ts +1 -1
- package/src/hooks/use-object-list/index.tsx +1 -1
- package/src/shared/flow-value/utils.ts +1 -1
- package/src/shared/format-legacy-refs/index.ts +1 -1
- package/src/shared/index.ts +1 -0
- package/src/shared/lazy-suspense/index.tsx +28 -0
- package/src/validate/validate-flow-value/index.tsx +1 -1
|
@@ -3,65 +3,10 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { lazySuspense } from '@/shared';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
import {
|
|
8
|
+
export const JsonEditorWithVariables = lazySuspense(() =>
|
|
9
|
+
import('./editor').then((module) => ({ default: module.JsonEditorWithVariables }))
|
|
10
|
+
);
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { VariableTree } from './extensions/variable-tree';
|
|
14
|
-
import { VariableTagInject } from './extensions/variable-tag';
|
|
15
|
-
import { I18n } from '@flowgram.ai/editor';
|
|
16
|
-
|
|
17
|
-
type Match = { match: string; range: [number, number] };
|
|
18
|
-
function findAllMatches(inputString: string, regex: RegExp): Match[] {
|
|
19
|
-
const globalRegex = new RegExp(
|
|
20
|
-
regex,
|
|
21
|
-
regex.flags.includes('g') ? regex.flags : regex.flags + 'g'
|
|
22
|
-
);
|
|
23
|
-
let match;
|
|
24
|
-
const matches: Match[] = [];
|
|
25
|
-
|
|
26
|
-
while ((match = globalRegex.exec(inputString)) !== null) {
|
|
27
|
-
if (match.index === globalRegex.lastIndex) {
|
|
28
|
-
globalRegex.lastIndex++;
|
|
29
|
-
}
|
|
30
|
-
matches.push({
|
|
31
|
-
match: match[0],
|
|
32
|
-
range: [match.index, match.index + match[0].length],
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return matches;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const transformer = transformerCreator((text: Text) => {
|
|
40
|
-
const originalSource = text.toString();
|
|
41
|
-
const matches = findAllMatches(originalSource, /\{\{([^\}]*)\}\}/g);
|
|
42
|
-
|
|
43
|
-
if (matches.length > 0) {
|
|
44
|
-
matches.forEach(({ range }) => {
|
|
45
|
-
text.replaceRange(range[0], range[1], 'null');
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return text;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
export function JsonEditorWithVariables(props: Omit<CodeEditorPropsType, 'languageId'>) {
|
|
53
|
-
return (
|
|
54
|
-
<CodeEditor
|
|
55
|
-
languageId="json"
|
|
56
|
-
activeLinePlaceholder={I18n.t("Press '@' to Select variable")}
|
|
57
|
-
{...props}
|
|
58
|
-
options={{
|
|
59
|
-
transformer,
|
|
60
|
-
...(props.options || {}),
|
|
61
|
-
}}
|
|
62
|
-
>
|
|
63
|
-
<VariableTree />
|
|
64
|
-
<VariableTagInject />
|
|
65
|
-
</CodeEditor>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
12
|
+
export type { JsonEditorWithVariablesProps } from './editor';
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { useEffect, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import { difference, omit } from 'lodash';
|
|
8
|
+
import { difference, omit } from 'lodash-es';
|
|
9
9
|
import { produce } from 'immer';
|
|
10
10
|
import { IJsonSchema, type JsonSchemaTypeManager, useTypeManager } from '@flowgram.ai/json-schema';
|
|
11
11
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useEffect, useRef } from 'react';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
Renderer,
|
|
10
|
+
EditorProvider,
|
|
11
|
+
ActiveLinePlaceholder,
|
|
12
|
+
InferValues,
|
|
13
|
+
} from '@coze-editor/editor/react';
|
|
14
|
+
import preset, { EditorAPI } from '@coze-editor/editor/preset-prompt';
|
|
15
|
+
|
|
16
|
+
import { PropsType } from './types';
|
|
17
|
+
import { UIContainer } from './styles';
|
|
18
|
+
import MarkdownHighlight from './extensions/markdown';
|
|
19
|
+
import LanguageSupport from './extensions/language-support';
|
|
20
|
+
import JinjaHighlight from './extensions/jinja';
|
|
21
|
+
|
|
22
|
+
type Preset = typeof preset;
|
|
23
|
+
type Options = Partial<InferValues<Preset[number]>>;
|
|
24
|
+
|
|
25
|
+
export interface PromptEditorPropsType extends PropsType {
|
|
26
|
+
options?: Options;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function PromptEditor(props: PromptEditorPropsType) {
|
|
30
|
+
const {
|
|
31
|
+
value,
|
|
32
|
+
onChange,
|
|
33
|
+
readonly,
|
|
34
|
+
placeholder,
|
|
35
|
+
activeLinePlaceholder,
|
|
36
|
+
style,
|
|
37
|
+
hasError,
|
|
38
|
+
children,
|
|
39
|
+
disableMarkdownHighlight,
|
|
40
|
+
options,
|
|
41
|
+
} = props || {};
|
|
42
|
+
|
|
43
|
+
const editorRef = useRef<EditorAPI | null>(null);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
// listen to value change
|
|
47
|
+
if (editorRef.current?.getValue() !== value?.content) {
|
|
48
|
+
editorRef.current?.setValue(String(value?.content || ''));
|
|
49
|
+
}
|
|
50
|
+
}, [value]);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<UIContainer $hasError={hasError} style={style}>
|
|
54
|
+
<EditorProvider>
|
|
55
|
+
<Renderer
|
|
56
|
+
didMount={(editor: EditorAPI) => {
|
|
57
|
+
editorRef.current = editor;
|
|
58
|
+
}}
|
|
59
|
+
plugins={preset}
|
|
60
|
+
defaultValue={String(value?.content)}
|
|
61
|
+
options={{
|
|
62
|
+
readOnly: readonly,
|
|
63
|
+
editable: !readonly,
|
|
64
|
+
placeholder,
|
|
65
|
+
...options,
|
|
66
|
+
}}
|
|
67
|
+
onChange={(e) => {
|
|
68
|
+
onChange({ type: 'template', content: e.value });
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
{activeLinePlaceholder && (
|
|
72
|
+
<ActiveLinePlaceholder>{activeLinePlaceholder}</ActiveLinePlaceholder>
|
|
73
|
+
)}
|
|
74
|
+
{!disableMarkdownHighlight && <MarkdownHighlight />}
|
|
75
|
+
<LanguageSupport />
|
|
76
|
+
<JinjaHighlight />
|
|
77
|
+
{children}
|
|
78
|
+
</EditorProvider>
|
|
79
|
+
</UIContainer>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -3,74 +3,10 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { lazySuspense } from '@/shared';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
import
|
|
8
|
+
export const PromptEditor = lazySuspense(() =>
|
|
9
|
+
import('./editor').then((module) => ({ default: module.PromptEditor }))
|
|
10
|
+
);
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
import { UIContainer } from './styles';
|
|
13
|
-
import MarkdownHighlight from './extensions/markdown';
|
|
14
|
-
import LanguageSupport from './extensions/language-support';
|
|
15
|
-
import JinjaHighlight from './extensions/jinja';
|
|
16
|
-
|
|
17
|
-
type Preset = typeof preset;
|
|
18
|
-
type Options = Partial<InferValues<Preset[number]>>;
|
|
19
|
-
|
|
20
|
-
export interface PromptEditorPropsType extends PropsType {
|
|
21
|
-
options?: Options;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function PromptEditor(props: PromptEditorPropsType) {
|
|
25
|
-
const {
|
|
26
|
-
value,
|
|
27
|
-
onChange,
|
|
28
|
-
readonly,
|
|
29
|
-
placeholder,
|
|
30
|
-
activeLinePlaceholder,
|
|
31
|
-
style,
|
|
32
|
-
hasError,
|
|
33
|
-
children,
|
|
34
|
-
disableMarkdownHighlight,
|
|
35
|
-
options,
|
|
36
|
-
} = props || {};
|
|
37
|
-
|
|
38
|
-
const editorRef = useRef<EditorAPI | null>(null);
|
|
39
|
-
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
// listen to value change
|
|
42
|
-
if (editorRef.current?.getValue() !== value?.content) {
|
|
43
|
-
editorRef.current?.setValue(String(value?.content || ''));
|
|
44
|
-
}
|
|
45
|
-
}, [value]);
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<UIContainer $hasError={hasError} style={style}>
|
|
49
|
-
<EditorProvider>
|
|
50
|
-
<Renderer
|
|
51
|
-
didMount={(editor: EditorAPI) => {
|
|
52
|
-
editorRef.current = editor;
|
|
53
|
-
}}
|
|
54
|
-
plugins={preset}
|
|
55
|
-
defaultValue={String(value?.content)}
|
|
56
|
-
options={{
|
|
57
|
-
readOnly: readonly,
|
|
58
|
-
editable: !readonly,
|
|
59
|
-
placeholder,
|
|
60
|
-
...options
|
|
61
|
-
}}
|
|
62
|
-
onChange={(e) => {
|
|
63
|
-
onChange({ type: 'template', content: e.value });
|
|
64
|
-
}}
|
|
65
|
-
/>
|
|
66
|
-
{activeLinePlaceholder && (
|
|
67
|
-
<ActiveLinePlaceholder>{activeLinePlaceholder}</ActiveLinePlaceholder>
|
|
68
|
-
)}
|
|
69
|
-
{!disableMarkdownHighlight && <MarkdownHighlight />}
|
|
70
|
-
<LanguageSupport />
|
|
71
|
-
<JinjaHighlight />
|
|
72
|
-
{children}
|
|
73
|
-
</EditorProvider>
|
|
74
|
-
</UIContainer>
|
|
75
|
-
);
|
|
76
|
-
}
|
|
12
|
+
export type { PromptEditorPropsType } from './editor';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
|
|
9
|
+
|
|
10
|
+
import { InputsTree } from './extensions/inputs-tree';
|
|
11
|
+
|
|
12
|
+
export interface PromptEditorWithInputsProps extends PromptEditorPropsType {
|
|
13
|
+
inputsValues: any;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function PromptEditorWithInputs({
|
|
17
|
+
inputsValues,
|
|
18
|
+
...restProps
|
|
19
|
+
}: PromptEditorWithInputsProps) {
|
|
20
|
+
return (
|
|
21
|
+
<PromptEditor {...restProps}>
|
|
22
|
+
<InputsTree inputsValues={inputsValues} />
|
|
23
|
+
</PromptEditor>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -3,20 +3,10 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { lazySuspense } from '@/shared';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
export const PromptEditorWithInputs = lazySuspense(() =>
|
|
9
|
+
import('./editor').then((module) => ({ default: module.PromptEditorWithInputs }))
|
|
10
|
+
);
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
interface PropsType extends PromptEditorPropsType {
|
|
13
|
-
inputsValues: any;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function PromptEditorWithInputs({ inputsValues, ...restProps }: PropsType) {
|
|
17
|
-
return (
|
|
18
|
-
<PromptEditor {...restProps}>
|
|
19
|
-
<InputsTree inputsValues={inputsValues} />
|
|
20
|
-
</PromptEditor>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
12
|
+
export type { PromptEditorWithInputsProps } from './editor';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
|
|
9
|
+
|
|
10
|
+
import { VariableTree } from './extensions/variable-tree';
|
|
11
|
+
import { VariableTagInject } from './extensions/variable-tag';
|
|
12
|
+
|
|
13
|
+
export interface PromptEditorWithVariablesProps extends PromptEditorPropsType {}
|
|
14
|
+
|
|
15
|
+
export function PromptEditorWithVariables(props: PromptEditorWithVariablesProps) {
|
|
16
|
+
return (
|
|
17
|
+
<PromptEditor {...props}>
|
|
18
|
+
<VariableTree />
|
|
19
|
+
<VariableTagInject />
|
|
20
|
+
</PromptEditor>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -3,18 +3,10 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { lazySuspense } from '@/shared';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
export const PromptEditorWithVariables = lazySuspense(() =>
|
|
9
|
+
import('./editor').then((module) => ({ default: module.PromptEditorWithVariables }))
|
|
10
|
+
);
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
import { VariableTagInject } from './extensions/variable-tag';
|
|
12
|
-
|
|
13
|
-
export function PromptEditorWithVariables(props: PromptEditorPropsType) {
|
|
14
|
-
return (
|
|
15
|
-
<PromptEditor {...props}>
|
|
16
|
-
<VariableTree />
|
|
17
|
-
<VariableTagInject />
|
|
18
|
-
</PromptEditor>
|
|
19
|
-
);
|
|
20
|
-
}
|
|
12
|
+
export type { PromptEditorWithVariablesProps } from './editor';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { isArray, isObject, isPlainObject, uniq } from 'lodash';
|
|
6
|
+
import { isArray, isObject, isPlainObject, uniq } from 'lodash-es';
|
|
7
7
|
import { IJsonSchema, JsonSchemaUtils } from '@flowgram.ai/json-schema';
|
|
8
8
|
import { Scope } from '@flowgram.ai/editor';
|
|
9
9
|
|
package/src/shared/index.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { ComponentType, lazy, Suspense } from 'react';
|
|
7
|
+
|
|
8
|
+
import { Skeleton } from '@douyinfe/semi-ui';
|
|
9
|
+
|
|
10
|
+
export function withSuspense<T extends ComponentType<any>>(
|
|
11
|
+
Component: T,
|
|
12
|
+
fallback?: React.ReactNode
|
|
13
|
+
): T {
|
|
14
|
+
const WithSuspenseComponent: T = ((props: any) => (
|
|
15
|
+
<Suspense fallback={fallback || <Skeleton.Paragraph style={{ width: '100%' }} rows={1} />}>
|
|
16
|
+
<Component {...props} />
|
|
17
|
+
</Suspense>
|
|
18
|
+
)) as any;
|
|
19
|
+
|
|
20
|
+
return WithSuspenseComponent;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function lazySuspense<T extends ComponentType<any>>(
|
|
24
|
+
params: Parameters<typeof lazy<T>>[0],
|
|
25
|
+
fallback?: React.ReactNode
|
|
26
|
+
) {
|
|
27
|
+
return withSuspense(lazy(params), fallback);
|
|
28
|
+
}
|