@flowgram.ai/form-materials 0.2.21 → 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 +107 -25
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +92 -14
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/code-editor/config.json +1 -1
- 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/config.json +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/config.json +1 -1
- package/src/components/prompt-editor/index.tsx +29 -4
- package/src/components/prompt-editor/types.tsx +2 -0
- package/src/components/prompt-editor-with-inputs/config.json +1 -1
- package/src/components/prompt-editor-with-variables/config.json +1 -1
- 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,8 +1951,8 @@ function BatchOutputs(props) {
|
|
|
1951
1951
|
}
|
|
1952
1952
|
|
|
1953
1953
|
// src/components/prompt-editor/index.tsx
|
|
1954
|
-
import React15 from "react";
|
|
1955
|
-
import { Renderer, EditorProvider } from "@coze-editor/editor/react";
|
|
1954
|
+
import React15, { useEffect as useEffect4, useRef as useRef3 } from "react";
|
|
1955
|
+
import { Renderer, EditorProvider, ActiveLinePlaceholder } from "@coze-editor/editor/react";
|
|
1956
1956
|
import preset from "@coze-editor/editor/preset-prompt";
|
|
1957
1957
|
|
|
1958
1958
|
// src/components/prompt-editor/styles.tsx
|
|
@@ -2084,28 +2084,47 @@ var jinja_default = JinjaHighlight;
|
|
|
2084
2084
|
|
|
2085
2085
|
// src/components/prompt-editor/index.tsx
|
|
2086
2086
|
function PromptEditor(props) {
|
|
2087
|
-
const {
|
|
2087
|
+
const {
|
|
2088
|
+
value,
|
|
2089
|
+
onChange,
|
|
2090
|
+
readonly,
|
|
2091
|
+
placeholder,
|
|
2092
|
+
activeLinePlaceholder,
|
|
2093
|
+
style,
|
|
2094
|
+
hasError,
|
|
2095
|
+
children
|
|
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]);
|
|
2088
2103
|
return /* @__PURE__ */ React15.createElement(UIContainer4, { $hasError: hasError, style }, /* @__PURE__ */ React15.createElement(EditorProvider, null, /* @__PURE__ */ React15.createElement(
|
|
2089
2104
|
Renderer,
|
|
2090
2105
|
{
|
|
2106
|
+
didMount: (editor) => {
|
|
2107
|
+
editorRef.current = editor;
|
|
2108
|
+
},
|
|
2091
2109
|
plugins: preset,
|
|
2092
2110
|
defaultValue: String(value?.content),
|
|
2093
2111
|
options: {
|
|
2094
2112
|
readOnly: readonly,
|
|
2095
|
-
editable: !readonly
|
|
2113
|
+
editable: !readonly,
|
|
2114
|
+
placeholder
|
|
2096
2115
|
},
|
|
2097
2116
|
onChange: (e) => {
|
|
2098
2117
|
onChange({ type: "template", content: e.value });
|
|
2099
2118
|
}
|
|
2100
2119
|
}
|
|
2101
|
-
), /* @__PURE__ */ React15.createElement(markdown_default, null), /* @__PURE__ */ React15.createElement(language_support_default, null), /* @__PURE__ */ React15.createElement(jinja_default, null), children));
|
|
2120
|
+
), activeLinePlaceholder && /* @__PURE__ */ React15.createElement(ActiveLinePlaceholder, null, activeLinePlaceholder), /* @__PURE__ */ React15.createElement(markdown_default, null), /* @__PURE__ */ React15.createElement(language_support_default, null), /* @__PURE__ */ React15.createElement(jinja_default, null), children));
|
|
2102
2121
|
}
|
|
2103
2122
|
|
|
2104
2123
|
// src/components/prompt-editor-with-variables/index.tsx
|
|
2105
2124
|
import React18 from "react";
|
|
2106
2125
|
|
|
2107
2126
|
// src/components/prompt-editor-with-variables/extensions/variable-tree.tsx
|
|
2108
|
-
import React16, { useEffect as
|
|
2127
|
+
import React16, { useEffect as useEffect5, useState as useState6 } from "react";
|
|
2109
2128
|
import { Popover, Tree } from "@douyinfe/semi-ui";
|
|
2110
2129
|
import {
|
|
2111
2130
|
Mention,
|
|
@@ -2133,7 +2152,7 @@ function VariableTree() {
|
|
|
2133
2152
|
setPosition(e.state.selection.main.head);
|
|
2134
2153
|
setVisible(e.value);
|
|
2135
2154
|
}
|
|
2136
|
-
|
|
2155
|
+
useEffect5(() => {
|
|
2137
2156
|
if (!editor) {
|
|
2138
2157
|
return;
|
|
2139
2158
|
}
|
|
@@ -2167,8 +2186,8 @@ function VariableTree() {
|
|
|
2167
2186
|
}
|
|
2168
2187
|
|
|
2169
2188
|
// src/components/prompt-editor-with-variables/extensions/variable-tag.tsx
|
|
2189
|
+
import ReactDOM from "react-dom";
|
|
2170
2190
|
import React17, { useLayoutEffect as useLayoutEffect4 } from "react";
|
|
2171
|
-
import { createRoot } from "react-dom/client";
|
|
2172
2191
|
import { isEqual, last } from "lodash";
|
|
2173
2192
|
import {
|
|
2174
2193
|
Disposable,
|
|
@@ -2237,9 +2256,12 @@ var VariableTagWidget = class extends WidgetType {
|
|
|
2237
2256
|
this.keyPath = keyPath;
|
|
2238
2257
|
this.scope = scope;
|
|
2239
2258
|
}
|
|
2259
|
+
renderReact(jsx) {
|
|
2260
|
+
ReactDOM.render(jsx, this.rootDOM);
|
|
2261
|
+
}
|
|
2240
2262
|
renderVariable(v) {
|
|
2241
2263
|
if (!v) {
|
|
2242
|
-
this.
|
|
2264
|
+
this.renderReact(
|
|
2243
2265
|
/* @__PURE__ */ React17.createElement(UITag2, { prefixIcon: /* @__PURE__ */ React17.createElement(IconIssueStroked2, null), color: "amber" }, "Unknown")
|
|
2244
2266
|
);
|
|
2245
2267
|
return;
|
|
@@ -2247,7 +2269,7 @@ var VariableTagWidget = class extends WidgetType {
|
|
|
2247
2269
|
const rootField = last(v.parentFields);
|
|
2248
2270
|
const rootTitle = /* @__PURE__ */ React17.createElement(UIRootTitle2, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
|
|
2249
2271
|
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
2250
|
-
this.
|
|
2272
|
+
this.renderReact(
|
|
2251
2273
|
/* @__PURE__ */ React17.createElement(
|
|
2252
2274
|
Popover2,
|
|
2253
2275
|
{
|
|
@@ -2259,10 +2281,10 @@ var VariableTagWidget = class extends WidgetType {
|
|
|
2259
2281
|
}
|
|
2260
2282
|
toDOM(view) {
|
|
2261
2283
|
const dom = document.createElement("span");
|
|
2262
|
-
this.
|
|
2284
|
+
this.rootDOM = dom;
|
|
2263
2285
|
this.toDispose.push(
|
|
2264
2286
|
Disposable.create(() => {
|
|
2265
|
-
this.
|
|
2287
|
+
ReactDOM.unmountComponentAtNode(this.rootDOM);
|
|
2266
2288
|
})
|
|
2267
2289
|
);
|
|
2268
2290
|
this.toDispose.push(
|
|
@@ -2334,7 +2356,7 @@ function PromptEditorWithVariables(props) {
|
|
|
2334
2356
|
import React21 from "react";
|
|
2335
2357
|
|
|
2336
2358
|
// src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx
|
|
2337
|
-
import React20, { useEffect as
|
|
2359
|
+
import React20, { useEffect as useEffect6, useState as useState7 } from "react";
|
|
2338
2360
|
import { Popover as Popover3 } from "@douyinfe/semi-ui";
|
|
2339
2361
|
import {
|
|
2340
2362
|
Mention as Mention2,
|
|
@@ -2428,7 +2450,7 @@ function InputsTree({ inputsValues }) {
|
|
|
2428
2450
|
setPosition(e.state.selection.main.head);
|
|
2429
2451
|
setVisible(e.value);
|
|
2430
2452
|
}
|
|
2431
|
-
|
|
2453
|
+
useEffect6(() => {
|
|
2432
2454
|
if (!editor) {
|
|
2433
2455
|
return;
|
|
2434
2456
|
}
|
|
@@ -2466,8 +2488,12 @@ function PromptEditorWithInputs({ inputsValues, ...restProps }) {
|
|
|
2466
2488
|
}
|
|
2467
2489
|
|
|
2468
2490
|
// src/components/code-editor/index.tsx
|
|
2469
|
-
import React22, { useRef as
|
|
2470
|
-
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";
|
|
2471
2497
|
import preset2 from "@coze-editor/editor/preset-code";
|
|
2472
2498
|
import { EditorView as EditorView4 } from "@codemirror/view";
|
|
2473
2499
|
|
|
@@ -2516,7 +2542,7 @@ var lightTheme = createTheme({
|
|
|
2516
2542
|
gutterBorderColor: "transparent",
|
|
2517
2543
|
gutterBorderWidth: 0,
|
|
2518
2544
|
lineHighlight: "#f0f0f0",
|
|
2519
|
-
bracketColors: ["#
|
|
2545
|
+
bracketColors: ["#FFD700", "#DD99FF", "#78B0FF"],
|
|
2520
2546
|
tooltip: {
|
|
2521
2547
|
backgroundColor: "#f0f0f0",
|
|
2522
2548
|
color: "#000",
|
|
@@ -2746,9 +2772,18 @@ function CodeEditor({
|
|
|
2746
2772
|
onChange,
|
|
2747
2773
|
languageId = "python",
|
|
2748
2774
|
theme = "light",
|
|
2749
|
-
children
|
|
2775
|
+
children,
|
|
2776
|
+
placeholder,
|
|
2777
|
+
activeLinePlaceholder,
|
|
2778
|
+
options: options2,
|
|
2779
|
+
readonly
|
|
2750
2780
|
}) {
|
|
2751
|
-
const editorRef =
|
|
2781
|
+
const editorRef = useRef4(null);
|
|
2782
|
+
useEffect7(() => {
|
|
2783
|
+
if (editorRef.current?.getValue() !== value) {
|
|
2784
|
+
editorRef.current?.setValue(String(value || ""));
|
|
2785
|
+
}
|
|
2786
|
+
}, [value]);
|
|
2752
2787
|
return /* @__PURE__ */ React22.createElement(EditorProvider2, null, /* @__PURE__ */ React22.createElement(
|
|
2753
2788
|
OriginCodeEditor,
|
|
2754
2789
|
{
|
|
@@ -2756,22 +2791,28 @@ function CodeEditor({
|
|
|
2756
2791
|
options: {
|
|
2757
2792
|
uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
|
|
2758
2793
|
languageId,
|
|
2759
|
-
theme
|
|
2794
|
+
theme,
|
|
2795
|
+
placeholder,
|
|
2796
|
+
readOnly: readonly,
|
|
2797
|
+
editable: !readonly,
|
|
2798
|
+
...options2 || {}
|
|
2760
2799
|
},
|
|
2761
2800
|
didMount: (editor) => {
|
|
2762
2801
|
editorRef.current = editor;
|
|
2763
2802
|
},
|
|
2764
2803
|
onChange: (e) => onChange?.(e.value)
|
|
2765
2804
|
},
|
|
2805
|
+
activeLinePlaceholder && /* @__PURE__ */ React22.createElement(ActiveLinePlaceholder2, null, activeLinePlaceholder),
|
|
2766
2806
|
children
|
|
2767
2807
|
));
|
|
2768
2808
|
}
|
|
2769
2809
|
|
|
2770
2810
|
// src/components/json-editor-with-variables/index.tsx
|
|
2771
2811
|
import React25 from "react";
|
|
2812
|
+
import { transformerCreator } from "@coze-editor/editor/preset-code";
|
|
2772
2813
|
|
|
2773
2814
|
// src/components/json-editor-with-variables/extensions/variable-tree.tsx
|
|
2774
|
-
import React23, { useEffect as
|
|
2815
|
+
import React23, { useEffect as useEffect8, useState as useState8 } from "react";
|
|
2775
2816
|
import { Popover as Popover4, Tree as Tree3 } from "@douyinfe/semi-ui";
|
|
2776
2817
|
import {
|
|
2777
2818
|
Mention as Mention3,
|
|
@@ -2799,7 +2840,7 @@ function VariableTree2() {
|
|
|
2799
2840
|
setPosition(e.state.selection.main.head);
|
|
2800
2841
|
setVisible(e.value);
|
|
2801
2842
|
}
|
|
2802
|
-
|
|
2843
|
+
useEffect8(() => {
|
|
2803
2844
|
if (!editor) {
|
|
2804
2845
|
return;
|
|
2805
2846
|
}
|
|
@@ -2834,7 +2875,7 @@ function VariableTree2() {
|
|
|
2834
2875
|
|
|
2835
2876
|
// src/components/json-editor-with-variables/extensions/variable-tag.tsx
|
|
2836
2877
|
import React24, { useLayoutEffect as useLayoutEffect5 } from "react";
|
|
2837
|
-
import { createRoot
|
|
2878
|
+
import { createRoot } from "react-dom/client";
|
|
2838
2879
|
import { isEqual as isEqual2, last as last3 } from "lodash";
|
|
2839
2880
|
import {
|
|
2840
2881
|
Disposable as Disposable2,
|
|
@@ -2925,7 +2966,7 @@ var VariableTagWidget2 = class extends WidgetType2 {
|
|
|
2925
2966
|
}
|
|
2926
2967
|
toDOM(view) {
|
|
2927
2968
|
const dom = document.createElement("span");
|
|
2928
|
-
this.root =
|
|
2969
|
+
this.root = createRoot(dom);
|
|
2929
2970
|
this.toDispose.push(
|
|
2930
2971
|
Disposable2.create(() => {
|
|
2931
2972
|
this.root.unmount();
|
|
@@ -2992,8 +3033,49 @@ function VariableTagInject2() {
|
|
|
2992
3033
|
}
|
|
2993
3034
|
|
|
2994
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
|
+
});
|
|
2995
3064
|
function JsonEditorWithVariables(props) {
|
|
2996
|
-
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
|
+
);
|
|
2997
3079
|
}
|
|
2998
3080
|
|
|
2999
3081
|
// src/effects/provide-batch-input/index.ts
|