@flowgram.ai/form-materials 0.1.0-alpha.10 → 0.1.0-alpha.11
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 +104 -15
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +116 -31
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
- package/src/components/code-editor/config.json +2 -1
- package/src/components/code-editor/index.tsx +16 -1
- package/src/components/code-editor/language-features.ts +3 -4
- 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/hooks.tsx +3 -1
- package/src/components/prompt-editor/index.tsx +2 -1
- package/src/components/prompt-editor/types.tsx +1 -0
- package/src/effects/auto-rename-ref/index.ts +59 -8
package/dist/esm/index.js
CHANGED
|
@@ -943,6 +943,7 @@ var ConstantInputWrapper = styled2.div`
|
|
|
943
943
|
|
|
944
944
|
// src/components/json-schema-editor/hooks.tsx
|
|
945
945
|
import { useEffect, useMemo as useMemo3, useRef, useState } from "react";
|
|
946
|
+
import { omit } from "lodash";
|
|
946
947
|
var _id = 0;
|
|
947
948
|
function genId() {
|
|
948
949
|
return _id++;
|
|
@@ -1015,7 +1016,7 @@ function usePropertiesEdit(value, onChange) {
|
|
|
1015
1016
|
if (!_property.name) {
|
|
1016
1017
|
continue;
|
|
1017
1018
|
}
|
|
1018
|
-
nextProperties[_property.name] = _property;
|
|
1019
|
+
nextProperties[_property.name] = omit(_property, ["key", "name", "isPropertyRequired"]);
|
|
1019
1020
|
if (_property.isPropertyRequired) {
|
|
1020
1021
|
nextRequired.push(_property.name);
|
|
1021
1022
|
}
|
|
@@ -2092,7 +2093,8 @@ function PromptEditor(props) {
|
|
|
2092
2093
|
activeLinePlaceholder,
|
|
2093
2094
|
style,
|
|
2094
2095
|
hasError,
|
|
2095
|
-
children
|
|
2096
|
+
children,
|
|
2097
|
+
disableMarkdownHighlight
|
|
2096
2098
|
} = props || {};
|
|
2097
2099
|
const editorRef = useRef3(null);
|
|
2098
2100
|
useEffect4(() => {
|
|
@@ -2117,7 +2119,7 @@ function PromptEditor(props) {
|
|
|
2117
2119
|
onChange({ type: "template", content: e.value });
|
|
2118
2120
|
}
|
|
2119
2121
|
}
|
|
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));
|
|
2122
|
+
), activeLinePlaceholder && /* @__PURE__ */ React15.createElement(ActiveLinePlaceholder, null, activeLinePlaceholder), !disableMarkdownHighlight && /* @__PURE__ */ React15.createElement(markdown_default, null), /* @__PURE__ */ React15.createElement(language_support_default, null), /* @__PURE__ */ React15.createElement(jinja_default, null), children));
|
|
2121
2123
|
}
|
|
2122
2124
|
|
|
2123
2125
|
// src/components/prompt-editor-with-variables/index.tsx
|
|
@@ -2489,7 +2491,11 @@ function PromptEditorWithInputs({ inputsValues, ...restProps }) {
|
|
|
2489
2491
|
|
|
2490
2492
|
// src/components/code-editor/index.tsx
|
|
2491
2493
|
import React22, { useEffect as useEffect7, useRef as useRef4 } from "react";
|
|
2492
|
-
import {
|
|
2494
|
+
import {
|
|
2495
|
+
ActiveLinePlaceholder as ActiveLinePlaceholder2,
|
|
2496
|
+
createRenderer,
|
|
2497
|
+
EditorProvider as EditorProvider2
|
|
2498
|
+
} from "@coze-editor/editor/react";
|
|
2493
2499
|
import preset2 from "@coze-editor/editor/preset-code";
|
|
2494
2500
|
import { EditorView as EditorView4 } from "@codemirror/view";
|
|
2495
2501
|
|
|
@@ -2538,7 +2544,7 @@ var lightTheme = createTheme({
|
|
|
2538
2544
|
gutterBorderColor: "transparent",
|
|
2539
2545
|
gutterBorderWidth: 0,
|
|
2540
2546
|
lineHighlight: "#f0f0f0",
|
|
2541
|
-
bracketColors: ["#
|
|
2547
|
+
bracketColors: ["#FFD700", "#DD99FF", "#78B0FF"],
|
|
2542
2548
|
tooltip: {
|
|
2543
2549
|
backgroundColor: "#f0f0f0",
|
|
2544
2550
|
color: "#000",
|
|
@@ -2741,11 +2747,14 @@ themes.register("light", lightTheme);
|
|
|
2741
2747
|
|
|
2742
2748
|
// src/components/code-editor/language-features.ts
|
|
2743
2749
|
import { languages } from "@coze-editor/editor/preset-code";
|
|
2750
|
+
import { typescript } from "@coze-editor/editor/language-typescript";
|
|
2744
2751
|
import { shell } from "@coze-editor/editor/language-shell";
|
|
2745
2752
|
import { python } from "@coze-editor/editor/language-python";
|
|
2746
2753
|
import { json } from "@coze-editor/editor/language-json";
|
|
2747
2754
|
import { mixLanguages } from "@coze-editor/editor";
|
|
2748
2755
|
languages.register("python", python);
|
|
2756
|
+
languages.register("typescript", typescript);
|
|
2757
|
+
languages.register("shell", shell);
|
|
2749
2758
|
languages.register("json", {
|
|
2750
2759
|
// mixLanguages is used to solve the problem that interpolation also uses parentheses, which causes incorrect highlighting
|
|
2751
2760
|
language: mixLanguages({
|
|
@@ -2753,7 +2762,6 @@ languages.register("json", {
|
|
|
2753
2762
|
}),
|
|
2754
2763
|
languageService: json.languageService
|
|
2755
2764
|
});
|
|
2756
|
-
languages.register("shell", shell);
|
|
2757
2765
|
|
|
2758
2766
|
// src/components/code-editor/index.tsx
|
|
2759
2767
|
var OriginCodeEditor = createRenderer(preset2, [
|
|
@@ -2770,7 +2778,9 @@ function CodeEditor({
|
|
|
2770
2778
|
theme = "light",
|
|
2771
2779
|
children,
|
|
2772
2780
|
placeholder,
|
|
2773
|
-
activeLinePlaceholder
|
|
2781
|
+
activeLinePlaceholder,
|
|
2782
|
+
options: options2,
|
|
2783
|
+
readonly
|
|
2774
2784
|
}) {
|
|
2775
2785
|
const editorRef = useRef4(null);
|
|
2776
2786
|
useEffect7(() => {
|
|
@@ -2786,7 +2796,10 @@ function CodeEditor({
|
|
|
2786
2796
|
uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
|
|
2787
2797
|
languageId,
|
|
2788
2798
|
theme,
|
|
2789
|
-
placeholder
|
|
2799
|
+
placeholder,
|
|
2800
|
+
readOnly: readonly,
|
|
2801
|
+
editable: !readonly,
|
|
2802
|
+
...options2 || {}
|
|
2790
2803
|
},
|
|
2791
2804
|
didMount: (editor) => {
|
|
2792
2805
|
editorRef.current = editor;
|
|
@@ -2800,6 +2813,7 @@ function CodeEditor({
|
|
|
2800
2813
|
|
|
2801
2814
|
// src/components/json-editor-with-variables/index.tsx
|
|
2802
2815
|
import React25 from "react";
|
|
2816
|
+
import { transformerCreator } from "@coze-editor/editor/preset-code";
|
|
2803
2817
|
|
|
2804
2818
|
// src/components/json-editor-with-variables/extensions/variable-tree.tsx
|
|
2805
2819
|
import React23, { useEffect as useEffect8, useState as useState8 } from "react";
|
|
@@ -3023,8 +3037,49 @@ function VariableTagInject2() {
|
|
|
3023
3037
|
}
|
|
3024
3038
|
|
|
3025
3039
|
// src/components/json-editor-with-variables/index.tsx
|
|
3040
|
+
function findAllMatches(inputString, regex) {
|
|
3041
|
+
const globalRegex = new RegExp(
|
|
3042
|
+
regex,
|
|
3043
|
+
regex.flags.includes("g") ? regex.flags : regex.flags + "g"
|
|
3044
|
+
);
|
|
3045
|
+
let match;
|
|
3046
|
+
const matches = [];
|
|
3047
|
+
while ((match = globalRegex.exec(inputString)) !== null) {
|
|
3048
|
+
if (match.index === globalRegex.lastIndex) {
|
|
3049
|
+
globalRegex.lastIndex++;
|
|
3050
|
+
}
|
|
3051
|
+
matches.push({
|
|
3052
|
+
match: match[0],
|
|
3053
|
+
range: [match.index, match.index + match[0].length]
|
|
3054
|
+
});
|
|
3055
|
+
}
|
|
3056
|
+
return matches;
|
|
3057
|
+
}
|
|
3058
|
+
var transformer = transformerCreator((text) => {
|
|
3059
|
+
const originalSource = text.toString();
|
|
3060
|
+
const matches = findAllMatches(originalSource, /\{\{([^\}]*)\}\}/g);
|
|
3061
|
+
if (matches.length > 0) {
|
|
3062
|
+
matches.forEach(({ range }) => {
|
|
3063
|
+
text.replaceRange(range[0], range[1], "null");
|
|
3064
|
+
});
|
|
3065
|
+
}
|
|
3066
|
+
return text;
|
|
3067
|
+
});
|
|
3026
3068
|
function JsonEditorWithVariables(props) {
|
|
3027
|
-
return /* @__PURE__ */ React25.createElement(
|
|
3069
|
+
return /* @__PURE__ */ React25.createElement(
|
|
3070
|
+
CodeEditor,
|
|
3071
|
+
{
|
|
3072
|
+
languageId: "json",
|
|
3073
|
+
activeLinePlaceholder: "Press '@' to Select variable",
|
|
3074
|
+
...props,
|
|
3075
|
+
options: {
|
|
3076
|
+
transformer,
|
|
3077
|
+
...props.options || {}
|
|
3078
|
+
}
|
|
3079
|
+
},
|
|
3080
|
+
/* @__PURE__ */ React25.createElement(VariableTree2, null),
|
|
3081
|
+
/* @__PURE__ */ React25.createElement(VariableTagInject2, null)
|
|
3082
|
+
);
|
|
3028
3083
|
}
|
|
3029
3084
|
|
|
3030
3085
|
// src/effects/provide-batch-input/index.ts
|
|
@@ -3093,7 +3148,7 @@ var provideBatchOutputsEffect = createEffectFromVariableProvider2({
|
|
|
3093
3148
|
});
|
|
3094
3149
|
|
|
3095
3150
|
// src/effects/auto-rename-ref/index.ts
|
|
3096
|
-
import { isArray, isObject as isObject2 } from "lodash";
|
|
3151
|
+
import { isArray, isObject as isObject2, uniq } from "lodash";
|
|
3097
3152
|
import {
|
|
3098
3153
|
DataEvent,
|
|
3099
3154
|
VariableFieldKeyRenameService
|
|
@@ -3114,9 +3169,30 @@ var autoRenameRefEffect = [
|
|
|
3114
3169
|
after.key
|
|
3115
3170
|
];
|
|
3116
3171
|
traverseRef(name, form.getValueIn(name), (_drilldownName, _v) => {
|
|
3117
|
-
if (
|
|
3118
|
-
|
|
3119
|
-
|
|
3172
|
+
if (_v.type === "ref") {
|
|
3173
|
+
if (isKeyPathMatch(_v.content, beforeKeyPath)) {
|
|
3174
|
+
_v.content = [...afterKeyPath, ...(_v.content || [])?.slice(beforeKeyPath.length)];
|
|
3175
|
+
form.setValueIn(_drilldownName, _v);
|
|
3176
|
+
}
|
|
3177
|
+
} else if (_v.type === "template") {
|
|
3178
|
+
const templateKeyPaths = getTemplateKeyPaths(_v);
|
|
3179
|
+
let hasMatch = false;
|
|
3180
|
+
templateKeyPaths.forEach((_keyPath) => {
|
|
3181
|
+
if (isKeyPathMatch(_keyPath, beforeKeyPath)) {
|
|
3182
|
+
hasMatch = true;
|
|
3183
|
+
const nextKeyPath = [
|
|
3184
|
+
...afterKeyPath,
|
|
3185
|
+
...(_keyPath || [])?.slice(beforeKeyPath.length)
|
|
3186
|
+
];
|
|
3187
|
+
_v.content = _v.content?.replace(
|
|
3188
|
+
`{{${_keyPath.join(".")}}`,
|
|
3189
|
+
`{{${nextKeyPath.join(".")}}`
|
|
3190
|
+
);
|
|
3191
|
+
}
|
|
3192
|
+
});
|
|
3193
|
+
if (hasMatch) {
|
|
3194
|
+
form.setValueIn(_drilldownName, { ..._v });
|
|
3195
|
+
}
|
|
3120
3196
|
}
|
|
3121
3197
|
});
|
|
3122
3198
|
});
|
|
@@ -3126,18 +3202,31 @@ var autoRenameRefEffect = [
|
|
|
3126
3202
|
}
|
|
3127
3203
|
}
|
|
3128
3204
|
];
|
|
3129
|
-
function
|
|
3130
|
-
return targetKeyPath.every((_key, index) => _key ===
|
|
3205
|
+
function isKeyPathMatch(keyPath = [], targetKeyPath) {
|
|
3206
|
+
return targetKeyPath.every((_key, index) => _key === keyPath[index]);
|
|
3207
|
+
}
|
|
3208
|
+
function getTemplateKeyPaths(value) {
|
|
3209
|
+
const keyPathReg = /{{(.*?)}}/g;
|
|
3210
|
+
return uniq(value.content?.match(keyPathReg) || []).map(
|
|
3211
|
+
(_keyPath) => _keyPath.slice(2, -2).split(".")
|
|
3212
|
+
);
|
|
3131
3213
|
}
|
|
3132
3214
|
function isRef(value) {
|
|
3133
3215
|
return value?.type === "ref" && Array.isArray(value?.content) && typeof value?.content[0] === "string";
|
|
3134
3216
|
}
|
|
3217
|
+
function isTemplate(value) {
|
|
3218
|
+
return value?.type === "template" && typeof value?.content === "string";
|
|
3219
|
+
}
|
|
3135
3220
|
function traverseRef(name, value, cb) {
|
|
3136
3221
|
if (isObject2(value)) {
|
|
3137
3222
|
if (isRef(value)) {
|
|
3138
3223
|
cb(name, value);
|
|
3139
3224
|
return;
|
|
3140
3225
|
}
|
|
3226
|
+
if (isTemplate(value)) {
|
|
3227
|
+
cb(name, value);
|
|
3228
|
+
return;
|
|
3229
|
+
}
|
|
3141
3230
|
Object.entries(value).forEach(([_key, _value]) => {
|
|
3142
3231
|
traverseRef(`${name}.${_key}`, _value, cb);
|
|
3143
3232
|
});
|