@flowgram.ai/form-materials 0.4.4 → 0.4.5
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/index.js +129 -76
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +131 -76
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/code-editor/theme/dark.ts +49 -30
- package/src/components/code-editor/theme/light.ts +56 -32
- package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +4 -3
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +10 -18
- package/src/shared/index.ts +1 -0
- package/src/shared/polyfill-create-root/index.tsx +33 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowgram.ai/form-materials",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"@codemirror/state": "~6.5.2",
|
|
36
36
|
"typescript": "^5.8.3",
|
|
37
37
|
"zod": "^3.24.4",
|
|
38
|
-
"@flowgram.ai/editor": "0.4.
|
|
39
|
-
"@flowgram.ai/json-schema": "0.4.
|
|
38
|
+
"@flowgram.ai/editor": "0.4.5",
|
|
39
|
+
"@flowgram.ai/json-schema": "0.4.5"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/lodash": "^4.14.137",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"tsup": "^8.0.1",
|
|
53
53
|
"typescript": "^5.8.3",
|
|
54
54
|
"vitest": "^0.34.6",
|
|
55
|
-
"@flowgram.ai/ts-config": "0.4.
|
|
56
|
-
"@flowgram.ai/eslint-config": "0.4.
|
|
55
|
+
"@flowgram.ai/ts-config": "0.4.5",
|
|
56
|
+
"@flowgram.ai/eslint-config": "0.4.5"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"react": ">=16.8",
|
|
@@ -7,55 +7,56 @@ import { createTheme, tags as t } from '@coze-editor/editor/preset-code';
|
|
|
7
7
|
import { type Extension } from '@codemirror/state';
|
|
8
8
|
|
|
9
9
|
const colors = {
|
|
10
|
-
background: '#
|
|
11
|
-
// syntax
|
|
12
|
-
comment: '#
|
|
13
|
-
key: '#
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
background: '#0D1117',
|
|
11
|
+
// syntax - 现代化暗色主题配色
|
|
12
|
+
comment: '#8B949E',
|
|
13
|
+
key: '#7DD3FC',
|
|
14
|
+
variable: '#F472B6',
|
|
15
|
+
string: '#34D399',
|
|
16
|
+
number: '#FBBF24',
|
|
17
|
+
boolean: '#A78BFA',
|
|
18
|
+
null: '#A78BFA',
|
|
19
|
+
separator: '#E6EDF3',
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
export const darkTheme: Extension = createTheme({
|
|
22
23
|
variant: 'dark',
|
|
23
24
|
settings: {
|
|
24
25
|
background: colors.background,
|
|
25
|
-
foreground: '#
|
|
26
|
-
caret: '#
|
|
27
|
-
selection: '#
|
|
26
|
+
foreground: '#E6EDF3',
|
|
27
|
+
caret: '#7DD3FC',
|
|
28
|
+
selection: '#264F7833',
|
|
28
29
|
gutterBackground: colors.background,
|
|
29
|
-
gutterForeground: '#
|
|
30
|
+
gutterForeground: '#6E7681',
|
|
30
31
|
gutterBorderColor: 'transparent',
|
|
31
32
|
gutterBorderWidth: 0,
|
|
32
|
-
lineHighlight: '#
|
|
33
|
-
bracketColors: ['#
|
|
33
|
+
lineHighlight: '#21262D',
|
|
34
|
+
bracketColors: ['#FBBF24', '#A78BFA', '#7DD3FC'],
|
|
34
35
|
tooltip: {
|
|
35
|
-
backgroundColor: '#
|
|
36
|
-
color: '#
|
|
37
|
-
border: '
|
|
36
|
+
backgroundColor: '#21262D',
|
|
37
|
+
color: '#E6EDF3',
|
|
38
|
+
border: '1px solid #30363D',
|
|
38
39
|
},
|
|
39
40
|
link: {
|
|
40
|
-
color: '#
|
|
41
|
+
color: '#58A6FF',
|
|
41
42
|
},
|
|
42
43
|
completionItemHover: {
|
|
43
|
-
backgroundColor: '#
|
|
44
|
+
backgroundColor: '#21262D',
|
|
44
45
|
},
|
|
45
46
|
completionItemSelected: {
|
|
46
|
-
backgroundColor: '#
|
|
47
|
+
backgroundColor: '#1F6EEB',
|
|
47
48
|
},
|
|
48
49
|
completionItemIcon: {
|
|
49
|
-
color: '#
|
|
50
|
+
color: '#8B949E',
|
|
50
51
|
},
|
|
51
52
|
completionItemLabel: {
|
|
52
|
-
color: '#
|
|
53
|
+
color: '#E6EDF3',
|
|
53
54
|
},
|
|
54
55
|
completionItemInfo: {
|
|
55
|
-
color: '#
|
|
56
|
+
color: '#8B949E',
|
|
56
57
|
},
|
|
57
58
|
completionItemDetail: {
|
|
58
|
-
color: '#
|
|
59
|
+
color: '#6E7681',
|
|
59
60
|
},
|
|
60
61
|
},
|
|
61
62
|
styles: [
|
|
@@ -89,31 +90,49 @@ export const darkTheme: Extension = createTheme({
|
|
|
89
90
|
color: colors.separator,
|
|
90
91
|
},
|
|
91
92
|
|
|
93
|
+
// js
|
|
94
|
+
{
|
|
95
|
+
tag: [t.definitionKeyword],
|
|
96
|
+
color: '#C084FC',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
tag: [t.modifier],
|
|
100
|
+
color: '#C084FC',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
tag: [t.controlKeyword],
|
|
104
|
+
color: '#C084FC',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
tag: [t.operatorKeyword],
|
|
108
|
+
color: '#C084FC',
|
|
109
|
+
},
|
|
110
|
+
|
|
92
111
|
// markdown
|
|
93
112
|
{
|
|
94
113
|
tag: [t.heading],
|
|
95
|
-
color: '#
|
|
114
|
+
color: '#7DD3FC',
|
|
96
115
|
},
|
|
97
116
|
{
|
|
98
117
|
tag: [t.processingInstruction],
|
|
99
|
-
color: '#
|
|
118
|
+
color: '#7DD3FC',
|
|
100
119
|
},
|
|
101
120
|
|
|
102
121
|
// shell
|
|
103
122
|
// curl
|
|
104
123
|
{
|
|
105
124
|
tag: [t.standard(t.variableName)],
|
|
106
|
-
color: '#
|
|
125
|
+
color: '#34D399',
|
|
107
126
|
},
|
|
108
127
|
// -X
|
|
109
128
|
{
|
|
110
129
|
tag: [t.attributeName],
|
|
111
|
-
color: '#
|
|
130
|
+
color: '#FBBF24',
|
|
112
131
|
},
|
|
113
132
|
// url in string (includes quotes), e.g. "https://..."
|
|
114
133
|
{
|
|
115
134
|
tag: [t.special(t.string)],
|
|
116
|
-
color: '#
|
|
135
|
+
color: '#7DD3FC',
|
|
117
136
|
},
|
|
118
137
|
],
|
|
119
138
|
});
|
|
@@ -7,55 +7,56 @@ import { createTheme, tags as t } from '@coze-editor/editor/preset-code';
|
|
|
7
7
|
import { type Extension } from '@codemirror/state';
|
|
8
8
|
|
|
9
9
|
const colors = {
|
|
10
|
-
background: '#
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
string: '#
|
|
15
|
-
number: '#
|
|
16
|
-
boolean: '#
|
|
17
|
-
null: '#
|
|
18
|
-
separator: '#
|
|
10
|
+
background: '#FFFFFF',
|
|
11
|
+
comment: '#6B7280',
|
|
12
|
+
key: '#2563EB',
|
|
13
|
+
variable: '#DC2626',
|
|
14
|
+
string: '#059669',
|
|
15
|
+
number: '#EA580C',
|
|
16
|
+
boolean: '#7C3AED',
|
|
17
|
+
null: '#7C3AED',
|
|
18
|
+
separator: '#374151',
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export const lightTheme: Extension = createTheme({
|
|
22
22
|
variant: 'light',
|
|
23
23
|
settings: {
|
|
24
|
-
background: '#
|
|
25
|
-
foreground: '#
|
|
26
|
-
caret: '#
|
|
27
|
-
selection: '#
|
|
28
|
-
gutterBackground: '#
|
|
29
|
-
gutterForeground: '#
|
|
24
|
+
background: '#FFFFFF',
|
|
25
|
+
foreground: '#1F2937',
|
|
26
|
+
caret: '#2563EB',
|
|
27
|
+
selection: '#E5E7EB',
|
|
28
|
+
gutterBackground: '#F9FAFB',
|
|
29
|
+
gutterForeground: '#6B7280',
|
|
30
30
|
gutterBorderColor: 'transparent',
|
|
31
31
|
gutterBorderWidth: 0,
|
|
32
|
-
lineHighlight: '#
|
|
33
|
-
bracketColors: ['#
|
|
32
|
+
lineHighlight: '#F3F4F680',
|
|
33
|
+
bracketColors: ['#F59E0B', '#8B5CF6', '#06B6D4'],
|
|
34
34
|
tooltip: {
|
|
35
|
-
backgroundColor: '#
|
|
36
|
-
color: '#
|
|
37
|
-
border: '1px solid #
|
|
35
|
+
backgroundColor: '#FFFFFF',
|
|
36
|
+
color: '#1F2937',
|
|
37
|
+
border: '1px solid #E5E7EB',
|
|
38
|
+
boxShadow: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
|
|
38
39
|
},
|
|
39
40
|
link: {
|
|
40
|
-
color: '#
|
|
41
|
+
color: '#2563EB',
|
|
41
42
|
},
|
|
42
43
|
completionItemHover: {
|
|
43
|
-
backgroundColor: '#
|
|
44
|
+
backgroundColor: '#F3F4F6',
|
|
44
45
|
},
|
|
45
46
|
completionItemSelected: {
|
|
46
|
-
backgroundColor: '#
|
|
47
|
+
backgroundColor: '#E5E7EB',
|
|
47
48
|
},
|
|
48
49
|
completionItemIcon: {
|
|
49
|
-
color: '#
|
|
50
|
+
color: '#4B5563',
|
|
50
51
|
},
|
|
51
52
|
completionItemLabel: {
|
|
52
|
-
color: '#
|
|
53
|
+
color: '#1F2937',
|
|
53
54
|
},
|
|
54
55
|
completionItemInfo: {
|
|
55
|
-
color: '#
|
|
56
|
+
color: '#4B5563',
|
|
56
57
|
},
|
|
57
58
|
completionItemDetail: {
|
|
58
|
-
color: '#
|
|
59
|
+
color: '#6B7280',
|
|
59
60
|
},
|
|
60
61
|
},
|
|
61
62
|
styles: [
|
|
@@ -68,6 +69,11 @@ export const lightTheme: Extension = createTheme({
|
|
|
68
69
|
tag: [t.propertyName],
|
|
69
70
|
color: colors.key,
|
|
70
71
|
},
|
|
72
|
+
{
|
|
73
|
+
tag: [t.variableName],
|
|
74
|
+
color: colors.variable,
|
|
75
|
+
},
|
|
76
|
+
|
|
71
77
|
{
|
|
72
78
|
tag: [t.string],
|
|
73
79
|
color: colors.string,
|
|
@@ -92,28 +98,46 @@ export const lightTheme: Extension = createTheme({
|
|
|
92
98
|
// markdown
|
|
93
99
|
{
|
|
94
100
|
tag: [t.heading],
|
|
95
|
-
color: '#
|
|
101
|
+
color: '#2563EB',
|
|
96
102
|
},
|
|
97
103
|
{
|
|
98
104
|
tag: [t.processingInstruction],
|
|
99
|
-
color: '#
|
|
105
|
+
color: '#2563EB',
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
// js
|
|
109
|
+
{
|
|
110
|
+
tag: [t.definitionKeyword],
|
|
111
|
+
color: '#9333EA',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
tag: [t.modifier],
|
|
115
|
+
color: '#9333EA',
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
tag: [t.controlKeyword],
|
|
119
|
+
color: '#9333EA',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
tag: [t.operatorKeyword],
|
|
123
|
+
color: '#9333EA',
|
|
100
124
|
},
|
|
101
125
|
|
|
102
126
|
// shell
|
|
103
127
|
// curl
|
|
104
128
|
{
|
|
105
129
|
tag: [t.standard(t.variableName)],
|
|
106
|
-
color: '#
|
|
130
|
+
color: '#059669',
|
|
107
131
|
},
|
|
108
132
|
// -X
|
|
109
133
|
{
|
|
110
134
|
tag: [t.attributeName],
|
|
111
|
-
color: '#
|
|
135
|
+
color: '#EA580C',
|
|
112
136
|
},
|
|
113
137
|
// url in string (includes quotes), e.g. "https://..."
|
|
114
138
|
{
|
|
115
139
|
tag: [t.special(t.string)],
|
|
116
|
-
color: '#
|
|
140
|
+
color: '#2563EB',
|
|
117
141
|
},
|
|
118
142
|
],
|
|
119
143
|
});
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useLayoutEffect } from 'react';
|
|
7
7
|
|
|
8
|
-
import { createRoot, Root } from 'react-dom/client';
|
|
9
8
|
import { isEqual, last } from 'lodash';
|
|
10
9
|
import {
|
|
11
10
|
BaseVariableField,
|
|
@@ -26,6 +25,8 @@ import {
|
|
|
26
25
|
WidgetType,
|
|
27
26
|
} from '@codemirror/view';
|
|
28
27
|
|
|
28
|
+
import { IPolyfillRoot, polyfillCreateRoot } from '@/shared';
|
|
29
|
+
|
|
29
30
|
import { UIPopoverContent, UIRootTitle, UITag, UIVarName } from '../styles';
|
|
30
31
|
|
|
31
32
|
class VariableTagWidget extends WidgetType {
|
|
@@ -35,7 +36,7 @@ class VariableTagWidget extends WidgetType {
|
|
|
35
36
|
|
|
36
37
|
scope: Scope;
|
|
37
38
|
|
|
38
|
-
root:
|
|
39
|
+
root: IPolyfillRoot;
|
|
39
40
|
|
|
40
41
|
constructor({ keyPath, scope }: { keyPath?: string[]; scope: Scope }) {
|
|
41
42
|
super();
|
|
@@ -90,7 +91,7 @@ class VariableTagWidget extends WidgetType {
|
|
|
90
91
|
toDOM(view: EditorView): HTMLElement {
|
|
91
92
|
const dom = document.createElement('span');
|
|
92
93
|
|
|
93
|
-
this.root =
|
|
94
|
+
this.root = polyfillCreateRoot(dom);
|
|
94
95
|
|
|
95
96
|
this.toDispose.push(
|
|
96
97
|
Disposable.create(() => {
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import ReactDOM from 'react-dom';
|
|
7
6
|
import React, { useLayoutEffect } from 'react';
|
|
8
7
|
|
|
9
8
|
import { isEqual, last } from 'lodash';
|
|
@@ -26,6 +25,8 @@ import {
|
|
|
26
25
|
WidgetType,
|
|
27
26
|
} from '@codemirror/view';
|
|
28
27
|
|
|
28
|
+
import { IPolyfillRoot, polyfillCreateRoot } from '@/shared';
|
|
29
|
+
|
|
29
30
|
import { UIPopoverContent, UIRootTitle, UITag, UIVarName } from '../styles';
|
|
30
31
|
|
|
31
32
|
class VariableTagWidget extends WidgetType {
|
|
@@ -35,7 +36,7 @@ class VariableTagWidget extends WidgetType {
|
|
|
35
36
|
|
|
36
37
|
scope: Scope;
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
root: IPolyfillRoot;
|
|
39
40
|
|
|
40
41
|
constructor({ keyPath, scope }: { keyPath?: string[]; scope: Scope }) {
|
|
41
42
|
super();
|
|
@@ -52,14 +53,9 @@ class VariableTagWidget extends WidgetType {
|
|
|
52
53
|
return icon;
|
|
53
54
|
};
|
|
54
55
|
|
|
55
|
-
renderReact(jsx: React.ReactElement) {
|
|
56
|
-
// NOTICE: For React 19, upgrade to 'react-dom/client'
|
|
57
|
-
ReactDOM.render(jsx, this.rootDOM!);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
56
|
renderVariable(v?: BaseVariableField) {
|
|
61
57
|
if (!v) {
|
|
62
|
-
this.
|
|
58
|
+
this.root.render(
|
|
63
59
|
<UITag prefixIcon={<IconIssueStroked />} color="amber">
|
|
64
60
|
Unknown
|
|
65
61
|
</UITag>
|
|
@@ -67,17 +63,14 @@ class VariableTagWidget extends WidgetType {
|
|
|
67
63
|
return;
|
|
68
64
|
}
|
|
69
65
|
|
|
70
|
-
const rootField = last(v.parentFields)
|
|
71
|
-
const isRoot = v.parentFields.length === 0;
|
|
66
|
+
const rootField = last(v.parentFields);
|
|
72
67
|
|
|
73
68
|
const rootTitle = (
|
|
74
|
-
<UIRootTitle>
|
|
75
|
-
{rootField?.meta.title ? `${rootField.meta.title} ${isRoot ? '' : '-'} ` : ''}
|
|
76
|
-
</UIRootTitle>
|
|
69
|
+
<UIRootTitle>{rootField?.meta.title ? `${rootField.meta.title} -` : ''}</UIRootTitle>
|
|
77
70
|
);
|
|
78
71
|
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
79
72
|
|
|
80
|
-
this.
|
|
73
|
+
this.root.render(
|
|
81
74
|
<Popover
|
|
82
75
|
content={
|
|
83
76
|
<UIPopoverContent>
|
|
@@ -89,7 +82,7 @@ class VariableTagWidget extends WidgetType {
|
|
|
89
82
|
>
|
|
90
83
|
<UITag prefixIcon={rootIcon}>
|
|
91
84
|
{rootTitle}
|
|
92
|
-
|
|
85
|
+
<UIVarName>{v?.key}</UIVarName>
|
|
93
86
|
</UITag>
|
|
94
87
|
</Popover>
|
|
95
88
|
);
|
|
@@ -98,12 +91,11 @@ class VariableTagWidget extends WidgetType {
|
|
|
98
91
|
toDOM(view: EditorView): HTMLElement {
|
|
99
92
|
const dom = document.createElement('span');
|
|
100
93
|
|
|
101
|
-
this.
|
|
94
|
+
this.root = polyfillCreateRoot(dom);
|
|
102
95
|
|
|
103
96
|
this.toDispose.push(
|
|
104
97
|
Disposable.create(() => {
|
|
105
|
-
|
|
106
|
-
ReactDOM.unmountComponentAtNode(this.rootDOM!);
|
|
98
|
+
this.root.unmount();
|
|
107
99
|
})
|
|
108
100
|
);
|
|
109
101
|
|
package/src/shared/index.ts
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as ReactDOM from 'react-dom';
|
|
7
|
+
|
|
8
|
+
export interface IPolyfillRoot {
|
|
9
|
+
render(children: React.ReactNode): void;
|
|
10
|
+
unmount(): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* React 18 polyfill
|
|
15
|
+
* @param dom
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
let unstableCreateRoot = (dom: HTMLElement): IPolyfillRoot => ({
|
|
19
|
+
render(children: JSX.Element) {
|
|
20
|
+
ReactDOM.render(children, dom);
|
|
21
|
+
},
|
|
22
|
+
unmount() {
|
|
23
|
+
ReactDOM.unmountComponentAtNode(dom);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export function polyfillCreateRoot(dom: HTMLElement): IPolyfillRoot {
|
|
28
|
+
return unstableCreateRoot(dom);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function unstableSetCreateRoot(createRoot: (dom: HTMLElement) => IPolyfillRoot) {
|
|
32
|
+
unstableCreateRoot = createRoot;
|
|
33
|
+
}
|