@flowgram.ai/form-materials 0.2.22 → 0.2.23
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/bin/index.ts +6 -1
- package/bin/materials.ts +15 -1
- package/dist/esm/index.js +93 -21
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +79 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/code-editor/index.tsx +32 -2
- package/src/components/code-editor/theme/light.ts +1 -1
- package/src/components/json-editor-with-variables/index.tsx +47 -1
- package/src/components/json-schema-editor/config.json +10 -2
- package/src/components/prompt-editor/index.tsx +14 -2
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +12 -6
package/bin/index.ts
CHANGED
|
@@ -85,9 +85,14 @@ program
|
|
|
85
85
|
// 5. Copy the materials to the project
|
|
86
86
|
console.log(chalk.bold('These Materials will be added to your project'));
|
|
87
87
|
console.log(allMaterials);
|
|
88
|
+
copyMaterial(material, projectInfo, { overwrite: true });
|
|
89
|
+
|
|
88
90
|
allMaterials.forEach((mat: Material) => {
|
|
91
|
+
if (mat === material) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
89
94
|
// Add type for mat
|
|
90
|
-
copyMaterial(mat, projectInfo);
|
|
95
|
+
copyMaterial(mat, projectInfo, { overwrite: false });
|
|
91
96
|
});
|
|
92
97
|
});
|
|
93
98
|
|
package/bin/materials.ts
CHANGED
|
@@ -115,7 +115,15 @@ export function bfsMaterials(material: Material, _materials: Material[] = []): B
|
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
export const copyMaterial = (
|
|
118
|
+
export const copyMaterial = (
|
|
119
|
+
material: Material,
|
|
120
|
+
projectInfo: ProjectInfo,
|
|
121
|
+
{
|
|
122
|
+
overwrite,
|
|
123
|
+
}: {
|
|
124
|
+
overwrite?: boolean;
|
|
125
|
+
} = {}
|
|
126
|
+
): void => {
|
|
119
127
|
const sourceDir: string = material.path;
|
|
120
128
|
const materialRoot: string = path.join(
|
|
121
129
|
projectInfo.projectPath,
|
|
@@ -124,6 +132,12 @@ export const copyMaterial = (material: Material, projectInfo: ProjectInfo): void
|
|
|
124
132
|
`${material.type}`
|
|
125
133
|
);
|
|
126
134
|
const targetDir = path.join(materialRoot, material.name);
|
|
135
|
+
|
|
136
|
+
if (!overwrite && fs.readdirSync(targetDir)?.length > 0) {
|
|
137
|
+
console.log(`Material ${material.name} already exists in ${materialRoot}, skip copying.`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
127
141
|
fs.cpSync(sourceDir, targetDir, { recursive: true });
|
|
128
142
|
|
|
129
143
|
let materialRootIndexTs: string = '';
|
package/dist/esm/index.js
CHANGED
|
@@ -1951,7 +1951,7 @@ function BatchOutputs(props) {
|
|
|
1951
1951
|
}
|
|
1952
1952
|
|
|
1953
1953
|
// src/components/prompt-editor/index.tsx
|
|
1954
|
-
import React15 from "react";
|
|
1954
|
+
import React15, { useEffect as useEffect4, useRef as useRef3 } from "react";
|
|
1955
1955
|
import { Renderer, EditorProvider, ActiveLinePlaceholder } from "@coze-editor/editor/react";
|
|
1956
1956
|
import preset from "@coze-editor/editor/preset-prompt";
|
|
1957
1957
|
|
|
@@ -2094,9 +2094,18 @@ function PromptEditor(props) {
|
|
|
2094
2094
|
hasError,
|
|
2095
2095
|
children
|
|
2096
2096
|
} = props || {};
|
|
2097
|
+
const editorRef = useRef3(null);
|
|
2098
|
+
useEffect4(() => {
|
|
2099
|
+
if (editorRef.current?.getValue() !== value?.content) {
|
|
2100
|
+
editorRef.current?.setValue(String(value?.content || ""));
|
|
2101
|
+
}
|
|
2102
|
+
}, [value]);
|
|
2097
2103
|
return /* @__PURE__ */ React15.createElement(UIContainer4, { $hasError: hasError, style }, /* @__PURE__ */ React15.createElement(EditorProvider, null, /* @__PURE__ */ React15.createElement(
|
|
2098
2104
|
Renderer,
|
|
2099
2105
|
{
|
|
2106
|
+
didMount: (editor) => {
|
|
2107
|
+
editorRef.current = editor;
|
|
2108
|
+
},
|
|
2100
2109
|
plugins: preset,
|
|
2101
2110
|
defaultValue: String(value?.content),
|
|
2102
2111
|
options: {
|
|
@@ -2115,7 +2124,7 @@ function PromptEditor(props) {
|
|
|
2115
2124
|
import React18 from "react";
|
|
2116
2125
|
|
|
2117
2126
|
// src/components/prompt-editor-with-variables/extensions/variable-tree.tsx
|
|
2118
|
-
import React16, { useEffect as
|
|
2127
|
+
import React16, { useEffect as useEffect5, useState as useState6 } from "react";
|
|
2119
2128
|
import { Popover, Tree } from "@douyinfe/semi-ui";
|
|
2120
2129
|
import {
|
|
2121
2130
|
Mention,
|
|
@@ -2143,7 +2152,7 @@ function VariableTree() {
|
|
|
2143
2152
|
setPosition(e.state.selection.main.head);
|
|
2144
2153
|
setVisible(e.value);
|
|
2145
2154
|
}
|
|
2146
|
-
|
|
2155
|
+
useEffect5(() => {
|
|
2147
2156
|
if (!editor) {
|
|
2148
2157
|
return;
|
|
2149
2158
|
}
|
|
@@ -2177,8 +2186,8 @@ function VariableTree() {
|
|
|
2177
2186
|
}
|
|
2178
2187
|
|
|
2179
2188
|
// src/components/prompt-editor-with-variables/extensions/variable-tag.tsx
|
|
2189
|
+
import ReactDOM from "react-dom";
|
|
2180
2190
|
import React17, { useLayoutEffect as useLayoutEffect4 } from "react";
|
|
2181
|
-
import { createRoot } from "react-dom/client";
|
|
2182
2191
|
import { isEqual, last } from "lodash";
|
|
2183
2192
|
import {
|
|
2184
2193
|
Disposable,
|
|
@@ -2247,9 +2256,12 @@ var VariableTagWidget = class extends WidgetType {
|
|
|
2247
2256
|
this.keyPath = keyPath;
|
|
2248
2257
|
this.scope = scope;
|
|
2249
2258
|
}
|
|
2259
|
+
renderReact(jsx) {
|
|
2260
|
+
ReactDOM.render(jsx, this.rootDOM);
|
|
2261
|
+
}
|
|
2250
2262
|
renderVariable(v) {
|
|
2251
2263
|
if (!v) {
|
|
2252
|
-
this.
|
|
2264
|
+
this.renderReact(
|
|
2253
2265
|
/* @__PURE__ */ React17.createElement(UITag2, { prefixIcon: /* @__PURE__ */ React17.createElement(IconIssueStroked2, null), color: "amber" }, "Unknown")
|
|
2254
2266
|
);
|
|
2255
2267
|
return;
|
|
@@ -2257,7 +2269,7 @@ var VariableTagWidget = class extends WidgetType {
|
|
|
2257
2269
|
const rootField = last(v.parentFields);
|
|
2258
2270
|
const rootTitle = /* @__PURE__ */ React17.createElement(UIRootTitle2, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
|
|
2259
2271
|
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
2260
|
-
this.
|
|
2272
|
+
this.renderReact(
|
|
2261
2273
|
/* @__PURE__ */ React17.createElement(
|
|
2262
2274
|
Popover2,
|
|
2263
2275
|
{
|
|
@@ -2269,10 +2281,10 @@ var VariableTagWidget = class extends WidgetType {
|
|
|
2269
2281
|
}
|
|
2270
2282
|
toDOM(view) {
|
|
2271
2283
|
const dom = document.createElement("span");
|
|
2272
|
-
this.
|
|
2284
|
+
this.rootDOM = dom;
|
|
2273
2285
|
this.toDispose.push(
|
|
2274
2286
|
Disposable.create(() => {
|
|
2275
|
-
this.
|
|
2287
|
+
ReactDOM.unmountComponentAtNode(this.rootDOM);
|
|
2276
2288
|
})
|
|
2277
2289
|
);
|
|
2278
2290
|
this.toDispose.push(
|
|
@@ -2344,7 +2356,7 @@ function PromptEditorWithVariables(props) {
|
|
|
2344
2356
|
import React21 from "react";
|
|
2345
2357
|
|
|
2346
2358
|
// src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx
|
|
2347
|
-
import React20, { useEffect as
|
|
2359
|
+
import React20, { useEffect as useEffect6, useState as useState7 } from "react";
|
|
2348
2360
|
import { Popover as Popover3 } from "@douyinfe/semi-ui";
|
|
2349
2361
|
import {
|
|
2350
2362
|
Mention as Mention2,
|
|
@@ -2438,7 +2450,7 @@ function InputsTree({ inputsValues }) {
|
|
|
2438
2450
|
setPosition(e.state.selection.main.head);
|
|
2439
2451
|
setVisible(e.value);
|
|
2440
2452
|
}
|
|
2441
|
-
|
|
2453
|
+
useEffect6(() => {
|
|
2442
2454
|
if (!editor) {
|
|
2443
2455
|
return;
|
|
2444
2456
|
}
|
|
@@ -2476,8 +2488,12 @@ function PromptEditorWithInputs({ inputsValues, ...restProps }) {
|
|
|
2476
2488
|
}
|
|
2477
2489
|
|
|
2478
2490
|
// src/components/code-editor/index.tsx
|
|
2479
|
-
import React22, { useRef as
|
|
2480
|
-
import {
|
|
2491
|
+
import React22, { useEffect as useEffect7, useRef as useRef4 } from "react";
|
|
2492
|
+
import {
|
|
2493
|
+
ActiveLinePlaceholder as ActiveLinePlaceholder2,
|
|
2494
|
+
createRenderer,
|
|
2495
|
+
EditorProvider as EditorProvider2
|
|
2496
|
+
} from "@coze-editor/editor/react";
|
|
2481
2497
|
import preset2 from "@coze-editor/editor/preset-code";
|
|
2482
2498
|
import { EditorView as EditorView4 } from "@codemirror/view";
|
|
2483
2499
|
|
|
@@ -2526,7 +2542,7 @@ var lightTheme = createTheme({
|
|
|
2526
2542
|
gutterBorderColor: "transparent",
|
|
2527
2543
|
gutterBorderWidth: 0,
|
|
2528
2544
|
lineHighlight: "#f0f0f0",
|
|
2529
|
-
bracketColors: ["#
|
|
2545
|
+
bracketColors: ["#FFD700", "#DD99FF", "#78B0FF"],
|
|
2530
2546
|
tooltip: {
|
|
2531
2547
|
backgroundColor: "#f0f0f0",
|
|
2532
2548
|
color: "#000",
|
|
@@ -2756,9 +2772,18 @@ function CodeEditor({
|
|
|
2756
2772
|
onChange,
|
|
2757
2773
|
languageId = "python",
|
|
2758
2774
|
theme = "light",
|
|
2759
|
-
children
|
|
2775
|
+
children,
|
|
2776
|
+
placeholder,
|
|
2777
|
+
activeLinePlaceholder,
|
|
2778
|
+
options: options2,
|
|
2779
|
+
readonly
|
|
2760
2780
|
}) {
|
|
2761
|
-
const editorRef =
|
|
2781
|
+
const editorRef = useRef4(null);
|
|
2782
|
+
useEffect7(() => {
|
|
2783
|
+
if (editorRef.current?.getValue() !== value) {
|
|
2784
|
+
editorRef.current?.setValue(String(value || ""));
|
|
2785
|
+
}
|
|
2786
|
+
}, [value]);
|
|
2762
2787
|
return /* @__PURE__ */ React22.createElement(EditorProvider2, null, /* @__PURE__ */ React22.createElement(
|
|
2763
2788
|
OriginCodeEditor,
|
|
2764
2789
|
{
|
|
@@ -2766,22 +2791,28 @@ function CodeEditor({
|
|
|
2766
2791
|
options: {
|
|
2767
2792
|
uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
|
|
2768
2793
|
languageId,
|
|
2769
|
-
theme
|
|
2794
|
+
theme,
|
|
2795
|
+
placeholder,
|
|
2796
|
+
readOnly: readonly,
|
|
2797
|
+
editable: !readonly,
|
|
2798
|
+
...options2 || {}
|
|
2770
2799
|
},
|
|
2771
2800
|
didMount: (editor) => {
|
|
2772
2801
|
editorRef.current = editor;
|
|
2773
2802
|
},
|
|
2774
2803
|
onChange: (e) => onChange?.(e.value)
|
|
2775
2804
|
},
|
|
2805
|
+
activeLinePlaceholder && /* @__PURE__ */ React22.createElement(ActiveLinePlaceholder2, null, activeLinePlaceholder),
|
|
2776
2806
|
children
|
|
2777
2807
|
));
|
|
2778
2808
|
}
|
|
2779
2809
|
|
|
2780
2810
|
// src/components/json-editor-with-variables/index.tsx
|
|
2781
2811
|
import React25 from "react";
|
|
2812
|
+
import { transformerCreator } from "@coze-editor/editor/preset-code";
|
|
2782
2813
|
|
|
2783
2814
|
// src/components/json-editor-with-variables/extensions/variable-tree.tsx
|
|
2784
|
-
import React23, { useEffect as
|
|
2815
|
+
import React23, { useEffect as useEffect8, useState as useState8 } from "react";
|
|
2785
2816
|
import { Popover as Popover4, Tree as Tree3 } from "@douyinfe/semi-ui";
|
|
2786
2817
|
import {
|
|
2787
2818
|
Mention as Mention3,
|
|
@@ -2809,7 +2840,7 @@ function VariableTree2() {
|
|
|
2809
2840
|
setPosition(e.state.selection.main.head);
|
|
2810
2841
|
setVisible(e.value);
|
|
2811
2842
|
}
|
|
2812
|
-
|
|
2843
|
+
useEffect8(() => {
|
|
2813
2844
|
if (!editor) {
|
|
2814
2845
|
return;
|
|
2815
2846
|
}
|
|
@@ -2844,7 +2875,7 @@ function VariableTree2() {
|
|
|
2844
2875
|
|
|
2845
2876
|
// src/components/json-editor-with-variables/extensions/variable-tag.tsx
|
|
2846
2877
|
import React24, { useLayoutEffect as useLayoutEffect5 } from "react";
|
|
2847
|
-
import { createRoot
|
|
2878
|
+
import { createRoot } from "react-dom/client";
|
|
2848
2879
|
import { isEqual as isEqual2, last as last3 } from "lodash";
|
|
2849
2880
|
import {
|
|
2850
2881
|
Disposable as Disposable2,
|
|
@@ -2935,7 +2966,7 @@ var VariableTagWidget2 = class extends WidgetType2 {
|
|
|
2935
2966
|
}
|
|
2936
2967
|
toDOM(view) {
|
|
2937
2968
|
const dom = document.createElement("span");
|
|
2938
|
-
this.root =
|
|
2969
|
+
this.root = createRoot(dom);
|
|
2939
2970
|
this.toDispose.push(
|
|
2940
2971
|
Disposable2.create(() => {
|
|
2941
2972
|
this.root.unmount();
|
|
@@ -3002,8 +3033,49 @@ function VariableTagInject2() {
|
|
|
3002
3033
|
}
|
|
3003
3034
|
|
|
3004
3035
|
// src/components/json-editor-with-variables/index.tsx
|
|
3036
|
+
function findAllMatches(inputString, regex) {
|
|
3037
|
+
const globalRegex = new RegExp(
|
|
3038
|
+
regex,
|
|
3039
|
+
regex.flags.includes("g") ? regex.flags : regex.flags + "g"
|
|
3040
|
+
);
|
|
3041
|
+
let match;
|
|
3042
|
+
const matches = [];
|
|
3043
|
+
while ((match = globalRegex.exec(inputString)) !== null) {
|
|
3044
|
+
if (match.index === globalRegex.lastIndex) {
|
|
3045
|
+
globalRegex.lastIndex++;
|
|
3046
|
+
}
|
|
3047
|
+
matches.push({
|
|
3048
|
+
match: match[0],
|
|
3049
|
+
range: [match.index, match.index + match[0].length]
|
|
3050
|
+
});
|
|
3051
|
+
}
|
|
3052
|
+
return matches;
|
|
3053
|
+
}
|
|
3054
|
+
var transformer = transformerCreator((text) => {
|
|
3055
|
+
const originalSource = text.toString();
|
|
3056
|
+
const matches = findAllMatches(originalSource, /\{\{([^\}]*)\}\}/g);
|
|
3057
|
+
if (matches.length > 0) {
|
|
3058
|
+
matches.forEach(({ range }) => {
|
|
3059
|
+
text.replaceRange(range[0], range[1], "null");
|
|
3060
|
+
});
|
|
3061
|
+
}
|
|
3062
|
+
return text;
|
|
3063
|
+
});
|
|
3005
3064
|
function JsonEditorWithVariables(props) {
|
|
3006
|
-
return /* @__PURE__ */ React25.createElement(
|
|
3065
|
+
return /* @__PURE__ */ React25.createElement(
|
|
3066
|
+
CodeEditor,
|
|
3067
|
+
{
|
|
3068
|
+
languageId: "json",
|
|
3069
|
+
activeLinePlaceholder: "Press '@' to Select variable",
|
|
3070
|
+
...props,
|
|
3071
|
+
options: {
|
|
3072
|
+
transformer,
|
|
3073
|
+
...props.options || {}
|
|
3074
|
+
}
|
|
3075
|
+
},
|
|
3076
|
+
/* @__PURE__ */ React25.createElement(VariableTree2, null),
|
|
3077
|
+
/* @__PURE__ */ React25.createElement(VariableTagInject2, null)
|
|
3078
|
+
);
|
|
3007
3079
|
}
|
|
3008
3080
|
|
|
3009
3081
|
// src/effects/provide-batch-input/index.ts
|