@flowgram.ai/form-materials 0.4.5 → 0.4.6

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.
Files changed (41) hide show
  1. package/dist/esm/chunk-6OZSB6PD.js +10 -0
  2. package/dist/esm/chunk-6OZSB6PD.js.map +1 -0
  3. package/dist/esm/chunk-G4HQ7OSI.js +440 -0
  4. package/dist/esm/chunk-G4HQ7OSI.js.map +1 -0
  5. package/dist/esm/chunk-QIJ4QVB2.js +271 -0
  6. package/dist/esm/chunk-QIJ4QVB2.js.map +1 -0
  7. package/dist/esm/editor-6UMULJYB.js +180 -0
  8. package/dist/esm/editor-6UMULJYB.js.map +1 -0
  9. package/dist/esm/editor-E2BQTPCD.js +388 -0
  10. package/dist/esm/editor-E2BQTPCD.js.map +1 -0
  11. package/dist/esm/editor-H2R7JJLO.js +282 -0
  12. package/dist/esm/editor-H2R7JJLO.js.map +1 -0
  13. package/dist/esm/editor-JX42GFAZ.js +249 -0
  14. package/dist/esm/editor-JX42GFAZ.js.map +1 -0
  15. package/dist/esm/editor-YMNCDGUR.js +167 -0
  16. package/dist/esm/editor-YMNCDGUR.js.map +1 -0
  17. package/dist/esm/index.js +599 -2293
  18. package/dist/esm/index.js.map +1 -1
  19. package/dist/index.d.mts +133 -51
  20. package/dist/index.d.ts +133 -51
  21. package/dist/index.js +3499 -2802
  22. package/dist/index.js.map +1 -1
  23. package/package.json +6 -6
  24. package/src/components/code-editor/editor.tsx +96 -0
  25. package/src/components/code-editor/index.tsx +5 -89
  26. package/src/components/code-editor-mini/index.tsx +2 -2
  27. package/src/components/condition-row/index.tsx +4 -0
  28. package/src/components/db-condition-row/hooks/use-left.tsx +66 -0
  29. package/src/components/db-condition-row/hooks/use-op.tsx +59 -0
  30. package/src/components/db-condition-row/index.tsx +93 -0
  31. package/src/components/db-condition-row/styles.tsx +43 -0
  32. package/src/components/db-condition-row/types.ts +34 -0
  33. package/src/components/index.ts +1 -0
  34. package/src/components/json-editor-with-variables/editor.tsx +69 -0
  35. package/src/components/json-editor-with-variables/index.tsx +5 -60
  36. package/src/components/prompt-editor/editor.tsx +81 -0
  37. package/src/components/prompt-editor/index.tsx +5 -69
  38. package/src/components/prompt-editor-with-inputs/editor.tsx +25 -0
  39. package/src/components/prompt-editor-with-inputs/index.tsx +5 -15
  40. package/src/components/prompt-editor-with-variables/editor.tsx +22 -0
  41. package/src/components/prompt-editor-with-variables/index.tsx +5 -13
@@ -3,65 +3,10 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import React from 'react';
6
+ import { lazy } from 'react';
7
7
 
8
- import { transformerCreator } from '@coze-editor/editor/preset-code';
9
- import { Text } from '@coze-editor/editor/language-json';
8
+ export const JsonEditorWithVariables = lazy(() =>
9
+ import('./editor').then((module) => ({ default: module.JsonEditorWithVariables }))
10
+ );
10
11
 
11
- import { CodeEditor, type CodeEditorPropsType } from '@/components/code-editor';
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';
@@ -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 React, { useEffect, useRef } from 'react';
6
+ import { lazy } from 'react';
7
7
 
8
- import { Renderer, EditorProvider, ActiveLinePlaceholder, InferValues } from '@coze-editor/editor/react';
9
- import preset, { EditorAPI } from '@coze-editor/editor/preset-prompt';
8
+ export const PromptEditor = lazy(() =>
9
+ import('./editor').then((module) => ({ default: module.PromptEditor }))
10
+ );
10
11
 
11
- import { PropsType } from './types';
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 React from 'react';
6
+ import { lazy } from 'react';
7
7
 
8
- import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
8
+ export const PromptEditorWithInputs = lazy(() =>
9
+ import('./editor').then((module) => ({ default: module.PromptEditorWithInputs }))
10
+ );
9
11
 
10
- import { InputsTree } from './extensions/inputs-tree';
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 React from 'react';
6
+ import { lazy } from 'react';
7
7
 
8
- import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
8
+ export const PromptEditorWithVariables = lazy(() =>
9
+ import('./editor').then((module) => ({ default: module.PromptEditorWithVariables }))
10
+ );
9
11
 
10
- import { VariableTree } from './extensions/variable-tree';
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';