@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/index.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React$1 from 'react';
|
|
2
2
|
import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
3
|
+
import { InferValues } from '@coze-editor/editor/react';
|
|
4
|
+
import preset from '@coze-editor/editor/preset-code';
|
|
3
5
|
import { EffectOptions, ASTNodeJSON, ASTNode, BaseType, FormPluginCreator } from '@flowgram.ai/editor';
|
|
4
6
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
5
7
|
|
|
@@ -266,6 +268,7 @@ type PropsType$1 = React$1.PropsWithChildren<{
|
|
|
266
268
|
hasError?: boolean;
|
|
267
269
|
placeholder?: string;
|
|
268
270
|
activeLinePlaceholder?: string;
|
|
271
|
+
disableMarkdownHighlight?: boolean;
|
|
269
272
|
style?: React$1.CSSProperties;
|
|
270
273
|
}>;
|
|
271
274
|
|
|
@@ -299,6 +302,8 @@ declare function PromptEditorWithInputs({ inputsValues, ...restProps }: PropsTyp
|
|
|
299
302
|
* SPDX-License-Identifier: MIT
|
|
300
303
|
*/
|
|
301
304
|
|
|
305
|
+
type Preset = typeof preset;
|
|
306
|
+
type Options = Partial<InferValues<Preset[number]>>;
|
|
302
307
|
interface CodeEditorPropsType extends React$1.PropsWithChildren<{}> {
|
|
303
308
|
value?: string;
|
|
304
309
|
onChange?: (value: string) => void;
|
|
@@ -306,8 +311,10 @@ interface CodeEditorPropsType extends React$1.PropsWithChildren<{}> {
|
|
|
306
311
|
theme?: 'dark' | 'light';
|
|
307
312
|
placeholder?: string;
|
|
308
313
|
activeLinePlaceholder?: string;
|
|
314
|
+
readonly?: boolean;
|
|
315
|
+
options?: Options;
|
|
309
316
|
}
|
|
310
|
-
declare function CodeEditor({ value, onChange, languageId, theme, children, placeholder, activeLinePlaceholder, }: CodeEditorPropsType): React$1.JSX.Element;
|
|
317
|
+
declare function CodeEditor({ value, onChange, languageId, theme, children, placeholder, activeLinePlaceholder, options, readonly, }: CodeEditorPropsType): React$1.JSX.Element;
|
|
311
318
|
|
|
312
319
|
/**
|
|
313
320
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React$1 from 'react';
|
|
2
2
|
import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
3
|
+
import { InferValues } from '@coze-editor/editor/react';
|
|
4
|
+
import preset from '@coze-editor/editor/preset-code';
|
|
3
5
|
import { EffectOptions, ASTNodeJSON, ASTNode, BaseType, FormPluginCreator } from '@flowgram.ai/editor';
|
|
4
6
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
5
7
|
|
|
@@ -266,6 +268,7 @@ type PropsType$1 = React$1.PropsWithChildren<{
|
|
|
266
268
|
hasError?: boolean;
|
|
267
269
|
placeholder?: string;
|
|
268
270
|
activeLinePlaceholder?: string;
|
|
271
|
+
disableMarkdownHighlight?: boolean;
|
|
269
272
|
style?: React$1.CSSProperties;
|
|
270
273
|
}>;
|
|
271
274
|
|
|
@@ -299,6 +302,8 @@ declare function PromptEditorWithInputs({ inputsValues, ...restProps }: PropsTyp
|
|
|
299
302
|
* SPDX-License-Identifier: MIT
|
|
300
303
|
*/
|
|
301
304
|
|
|
305
|
+
type Preset = typeof preset;
|
|
306
|
+
type Options = Partial<InferValues<Preset[number]>>;
|
|
302
307
|
interface CodeEditorPropsType extends React$1.PropsWithChildren<{}> {
|
|
303
308
|
value?: string;
|
|
304
309
|
onChange?: (value: string) => void;
|
|
@@ -306,8 +311,10 @@ interface CodeEditorPropsType extends React$1.PropsWithChildren<{}> {
|
|
|
306
311
|
theme?: 'dark' | 'light';
|
|
307
312
|
placeholder?: string;
|
|
308
313
|
activeLinePlaceholder?: string;
|
|
314
|
+
readonly?: boolean;
|
|
315
|
+
options?: Options;
|
|
309
316
|
}
|
|
310
|
-
declare function CodeEditor({ value, onChange, languageId, theme, children, placeholder, activeLinePlaceholder, }: CodeEditorPropsType): React$1.JSX.Element;
|
|
317
|
+
declare function CodeEditor({ value, onChange, languageId, theme, children, placeholder, activeLinePlaceholder, options, readonly, }: CodeEditorPropsType): React$1.JSX.Element;
|
|
311
318
|
|
|
312
319
|
/**
|
|
313
320
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
package/dist/index.js
CHANGED
|
@@ -1003,6 +1003,7 @@ var ConstantInputWrapper = import_styled_components2.default.div`
|
|
|
1003
1003
|
|
|
1004
1004
|
// src/components/json-schema-editor/hooks.tsx
|
|
1005
1005
|
var import_react6 = require("react");
|
|
1006
|
+
var import_lodash2 = require("lodash");
|
|
1006
1007
|
var _id = 0;
|
|
1007
1008
|
function genId() {
|
|
1008
1009
|
return _id++;
|
|
@@ -1075,7 +1076,7 @@ function usePropertiesEdit(value, onChange) {
|
|
|
1075
1076
|
if (!_property.name) {
|
|
1076
1077
|
continue;
|
|
1077
1078
|
}
|
|
1078
|
-
nextProperties[_property.name] = _property;
|
|
1079
|
+
nextProperties[_property.name] = (0, import_lodash2.omit)(_property, ["key", "name", "isPropertyRequired"]);
|
|
1079
1080
|
if (_property.isPropertyRequired) {
|
|
1080
1081
|
nextRequired.push(_property.name);
|
|
1081
1082
|
}
|
|
@@ -1737,9 +1738,9 @@ var opConfigs = {
|
|
|
1737
1738
|
};
|
|
1738
1739
|
|
|
1739
1740
|
// src/utils/format-legacy-refs/index.ts
|
|
1740
|
-
var
|
|
1741
|
+
var import_lodash3 = require("lodash");
|
|
1741
1742
|
function formatLegacyRefOnSubmit(value) {
|
|
1742
|
-
if ((0,
|
|
1743
|
+
if ((0, import_lodash3.isObject)(value)) {
|
|
1743
1744
|
if (isLegacyFlowRefValueSchema(value)) {
|
|
1744
1745
|
return formatLegacyRefToNewRef(value);
|
|
1745
1746
|
}
|
|
@@ -1756,7 +1757,7 @@ function formatLegacyRefOnSubmit(value) {
|
|
|
1756
1757
|
return value;
|
|
1757
1758
|
}
|
|
1758
1759
|
function formatLegacyRefOnInit(value) {
|
|
1759
|
-
if ((0,
|
|
1760
|
+
if ((0, import_lodash3.isObject)(value)) {
|
|
1760
1761
|
if (isNewFlowRefValueSchema(value)) {
|
|
1761
1762
|
return formatNewRefToLegacyRef(value);
|
|
1762
1763
|
}
|
|
@@ -1773,10 +1774,10 @@ function formatLegacyRefOnInit(value) {
|
|
|
1773
1774
|
return value;
|
|
1774
1775
|
}
|
|
1775
1776
|
function isLegacyFlowRefValueSchema(value) {
|
|
1776
|
-
return (0,
|
|
1777
|
+
return (0, import_lodash3.isObject)(value) && Object.keys(value).length === 2 && value.type === "ref" && typeof value.content === "string";
|
|
1777
1778
|
}
|
|
1778
1779
|
function isNewFlowRefValueSchema(value) {
|
|
1779
|
-
return (0,
|
|
1780
|
+
return (0, import_lodash3.isObject)(value) && Object.keys(value).length === 2 && value.type === "ref" && Array.isArray(value.content);
|
|
1780
1781
|
}
|
|
1781
1782
|
function formatLegacyRefToNewRef(value) {
|
|
1782
1783
|
const keyPath = value.content.split(".");
|
|
@@ -1895,7 +1896,7 @@ var import_semi_icons8 = require("@douyinfe/semi-icons");
|
|
|
1895
1896
|
|
|
1896
1897
|
// src/components/batch-outputs/use-list.ts
|
|
1897
1898
|
var import_react16 = require("react");
|
|
1898
|
-
var
|
|
1899
|
+
var import_lodash4 = require("lodash");
|
|
1899
1900
|
var _id2 = 0;
|
|
1900
1901
|
function genId2() {
|
|
1901
1902
|
return _id2++;
|
|
@@ -1906,7 +1907,7 @@ function useList({ value, onChange }) {
|
|
|
1906
1907
|
setList((_prevList) => {
|
|
1907
1908
|
const newKeys = Object.keys(value || {});
|
|
1908
1909
|
const oldKeys = _prevList.map((item) => item.key).filter(Boolean);
|
|
1909
|
-
const addKeys = (0,
|
|
1910
|
+
const addKeys = (0, import_lodash4.difference)(newKeys, oldKeys);
|
|
1910
1911
|
return _prevList.filter((item) => !item.key || newKeys.includes(item.key)).map((item) => ({
|
|
1911
1912
|
id: item.id,
|
|
1912
1913
|
key: item.key,
|
|
@@ -2152,7 +2153,8 @@ function PromptEditor(props) {
|
|
|
2152
2153
|
activeLinePlaceholder,
|
|
2153
2154
|
style,
|
|
2154
2155
|
hasError,
|
|
2155
|
-
children
|
|
2156
|
+
children,
|
|
2157
|
+
disableMarkdownHighlight
|
|
2156
2158
|
} = props || {};
|
|
2157
2159
|
const editorRef = (0, import_react24.useRef)(null);
|
|
2158
2160
|
(0, import_react24.useEffect)(() => {
|
|
@@ -2177,7 +2179,7 @@ function PromptEditor(props) {
|
|
|
2177
2179
|
onChange({ type: "template", content: e.value });
|
|
2178
2180
|
}
|
|
2179
2181
|
}
|
|
2180
|
-
), activeLinePlaceholder && /* @__PURE__ */ import_react24.default.createElement(import_react25.ActiveLinePlaceholder, null, activeLinePlaceholder), /* @__PURE__ */ import_react24.default.createElement(markdown_default, null), /* @__PURE__ */ import_react24.default.createElement(language_support_default, null), /* @__PURE__ */ import_react24.default.createElement(jinja_default, null), children));
|
|
2182
|
+
), activeLinePlaceholder && /* @__PURE__ */ import_react24.default.createElement(import_react25.ActiveLinePlaceholder, null, activeLinePlaceholder), !disableMarkdownHighlight && /* @__PURE__ */ import_react24.default.createElement(markdown_default, null), /* @__PURE__ */ import_react24.default.createElement(language_support_default, null), /* @__PURE__ */ import_react24.default.createElement(jinja_default, null), children));
|
|
2181
2183
|
}
|
|
2182
2184
|
|
|
2183
2185
|
// src/components/prompt-editor-with-variables/index.tsx
|
|
@@ -2243,7 +2245,7 @@ function VariableTree() {
|
|
|
2243
2245
|
// src/components/prompt-editor-with-variables/extensions/variable-tag.tsx
|
|
2244
2246
|
var import_react_dom = __toESM(require("react-dom"));
|
|
2245
2247
|
var import_react28 = __toESM(require("react"));
|
|
2246
|
-
var
|
|
2248
|
+
var import_lodash5 = require("lodash");
|
|
2247
2249
|
var import_editor7 = require("@flowgram.ai/editor");
|
|
2248
2250
|
var import_semi_ui13 = require("@douyinfe/semi-ui");
|
|
2249
2251
|
var import_semi_icons9 = require("@douyinfe/semi-icons");
|
|
@@ -2311,7 +2313,7 @@ var VariableTagWidget = class extends import_view3.WidgetType {
|
|
|
2311
2313
|
);
|
|
2312
2314
|
return;
|
|
2313
2315
|
}
|
|
2314
|
-
const rootField = (0,
|
|
2316
|
+
const rootField = (0, import_lodash5.last)(v.parentFields);
|
|
2315
2317
|
const rootTitle = /* @__PURE__ */ import_react28.default.createElement(UIRootTitle2, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
|
|
2316
2318
|
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
2317
2319
|
this.renderReact(
|
|
@@ -2345,7 +2347,7 @@ var VariableTagWidget = class extends import_view3.WidgetType {
|
|
|
2345
2347
|
return dom;
|
|
2346
2348
|
}
|
|
2347
2349
|
eq(other) {
|
|
2348
|
-
return (0,
|
|
2350
|
+
return (0, import_lodash5.isEqual)(this.keyPath, other.keyPath);
|
|
2349
2351
|
}
|
|
2350
2352
|
ignoreEvent() {
|
|
2351
2353
|
return false;
|
|
@@ -2407,7 +2409,7 @@ var import_react33 = require("@coze-editor/editor/react");
|
|
|
2407
2409
|
|
|
2408
2410
|
// src/components/prompt-editor-with-inputs/inputs-picker.tsx
|
|
2409
2411
|
var import_react31 = __toESM(require("react"));
|
|
2410
|
-
var
|
|
2412
|
+
var import_lodash6 = require("lodash");
|
|
2411
2413
|
var import_editor8 = require("@flowgram.ai/editor");
|
|
2412
2414
|
var import_semi_ui14 = require("@douyinfe/semi-ui");
|
|
2413
2415
|
function InputsPicker({
|
|
@@ -2442,7 +2444,7 @@ function InputsPicker({
|
|
|
2442
2444
|
const key = keyPath.map((_key, idx) => _key === "[0]" || idx === 0 ? _key : `.${_key}`).join("");
|
|
2443
2445
|
return {
|
|
2444
2446
|
key,
|
|
2445
|
-
label: (0,
|
|
2447
|
+
label: (0, import_lodash6.last)(keyPath),
|
|
2446
2448
|
value: key,
|
|
2447
2449
|
children
|
|
2448
2450
|
};
|
|
@@ -2575,7 +2577,7 @@ var lightTheme = (0, import_preset_code.createTheme)({
|
|
|
2575
2577
|
gutterBorderColor: "transparent",
|
|
2576
2578
|
gutterBorderWidth: 0,
|
|
2577
2579
|
lineHighlight: "#f0f0f0",
|
|
2578
|
-
bracketColors: ["#
|
|
2580
|
+
bracketColors: ["#FFD700", "#DD99FF", "#78B0FF"],
|
|
2579
2581
|
tooltip: {
|
|
2580
2582
|
backgroundColor: "#f0f0f0",
|
|
2581
2583
|
color: "#000",
|
|
@@ -2778,11 +2780,14 @@ import_preset_code3.themes.register("light", lightTheme);
|
|
|
2778
2780
|
|
|
2779
2781
|
// src/components/code-editor/language-features.ts
|
|
2780
2782
|
var import_preset_code4 = require("@coze-editor/editor/preset-code");
|
|
2783
|
+
var import_language_typescript = require("@coze-editor/editor/language-typescript");
|
|
2781
2784
|
var import_language_shell = require("@coze-editor/editor/language-shell");
|
|
2782
2785
|
var import_language_python = require("@coze-editor/editor/language-python");
|
|
2783
2786
|
var import_language_json = require("@coze-editor/editor/language-json");
|
|
2784
2787
|
var import_editor9 = require("@coze-editor/editor");
|
|
2785
2788
|
import_preset_code4.languages.register("python", import_language_python.python);
|
|
2789
|
+
import_preset_code4.languages.register("typescript", import_language_typescript.typescript);
|
|
2790
|
+
import_preset_code4.languages.register("shell", import_language_shell.shell);
|
|
2786
2791
|
import_preset_code4.languages.register("json", {
|
|
2787
2792
|
// mixLanguages is used to solve the problem that interpolation also uses parentheses, which causes incorrect highlighting
|
|
2788
2793
|
language: (0, import_editor9.mixLanguages)({
|
|
@@ -2790,7 +2795,6 @@ import_preset_code4.languages.register("json", {
|
|
|
2790
2795
|
}),
|
|
2791
2796
|
languageService: import_language_json.json.languageService
|
|
2792
2797
|
});
|
|
2793
|
-
import_preset_code4.languages.register("shell", import_language_shell.shell);
|
|
2794
2798
|
|
|
2795
2799
|
// src/components/code-editor/index.tsx
|
|
2796
2800
|
var OriginCodeEditor = (0, import_react36.createRenderer)(import_preset_code5.default, [
|
|
@@ -2807,7 +2811,9 @@ function CodeEditor({
|
|
|
2807
2811
|
theme = "light",
|
|
2808
2812
|
children,
|
|
2809
2813
|
placeholder,
|
|
2810
|
-
activeLinePlaceholder
|
|
2814
|
+
activeLinePlaceholder,
|
|
2815
|
+
options: options2,
|
|
2816
|
+
readonly
|
|
2811
2817
|
}) {
|
|
2812
2818
|
const editorRef = (0, import_react35.useRef)(null);
|
|
2813
2819
|
(0, import_react35.useEffect)(() => {
|
|
@@ -2823,7 +2829,10 @@ function CodeEditor({
|
|
|
2823
2829
|
uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
|
|
2824
2830
|
languageId,
|
|
2825
2831
|
theme,
|
|
2826
|
-
placeholder
|
|
2832
|
+
placeholder,
|
|
2833
|
+
readOnly: readonly,
|
|
2834
|
+
editable: !readonly,
|
|
2835
|
+
...options2 || {}
|
|
2827
2836
|
},
|
|
2828
2837
|
didMount: (editor) => {
|
|
2829
2838
|
editorRef.current = editor;
|
|
@@ -2837,6 +2846,7 @@ function CodeEditor({
|
|
|
2837
2846
|
|
|
2838
2847
|
// src/components/json-editor-with-variables/index.tsx
|
|
2839
2848
|
var import_react41 = __toESM(require("react"));
|
|
2849
|
+
var import_preset_code6 = require("@coze-editor/editor/preset-code");
|
|
2840
2850
|
|
|
2841
2851
|
// src/components/json-editor-with-variables/extensions/variable-tree.tsx
|
|
2842
2852
|
var import_react37 = __toESM(require("react"));
|
|
@@ -2898,7 +2908,7 @@ function VariableTree2() {
|
|
|
2898
2908
|
// src/components/json-editor-with-variables/extensions/variable-tag.tsx
|
|
2899
2909
|
var import_react39 = __toESM(require("react"));
|
|
2900
2910
|
var import_client = require("react-dom/client");
|
|
2901
|
-
var
|
|
2911
|
+
var import_lodash7 = require("lodash");
|
|
2902
2912
|
var import_editor10 = require("@flowgram.ai/editor");
|
|
2903
2913
|
var import_semi_ui18 = require("@douyinfe/semi-ui");
|
|
2904
2914
|
var import_semi_icons10 = require("@douyinfe/semi-icons");
|
|
@@ -2963,7 +2973,7 @@ var VariableTagWidget2 = class extends import_view5.WidgetType {
|
|
|
2963
2973
|
);
|
|
2964
2974
|
return;
|
|
2965
2975
|
}
|
|
2966
|
-
const rootField = (0,
|
|
2976
|
+
const rootField = (0, import_lodash7.last)(v.parentFields);
|
|
2967
2977
|
const rootTitle = /* @__PURE__ */ import_react39.default.createElement(UIRootTitle3, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
|
|
2968
2978
|
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
2969
2979
|
this.root.render(
|
|
@@ -2997,7 +3007,7 @@ var VariableTagWidget2 = class extends import_view5.WidgetType {
|
|
|
2997
3007
|
return dom;
|
|
2998
3008
|
}
|
|
2999
3009
|
eq(other) {
|
|
3000
|
-
return (0,
|
|
3010
|
+
return (0, import_lodash7.isEqual)(this.keyPath, other.keyPath);
|
|
3001
3011
|
}
|
|
3002
3012
|
ignoreEvent() {
|
|
3003
3013
|
return false;
|
|
@@ -3045,8 +3055,49 @@ function VariableTagInject2() {
|
|
|
3045
3055
|
}
|
|
3046
3056
|
|
|
3047
3057
|
// src/components/json-editor-with-variables/index.tsx
|
|
3058
|
+
function findAllMatches(inputString, regex) {
|
|
3059
|
+
const globalRegex = new RegExp(
|
|
3060
|
+
regex,
|
|
3061
|
+
regex.flags.includes("g") ? regex.flags : regex.flags + "g"
|
|
3062
|
+
);
|
|
3063
|
+
let match;
|
|
3064
|
+
const matches = [];
|
|
3065
|
+
while ((match = globalRegex.exec(inputString)) !== null) {
|
|
3066
|
+
if (match.index === globalRegex.lastIndex) {
|
|
3067
|
+
globalRegex.lastIndex++;
|
|
3068
|
+
}
|
|
3069
|
+
matches.push({
|
|
3070
|
+
match: match[0],
|
|
3071
|
+
range: [match.index, match.index + match[0].length]
|
|
3072
|
+
});
|
|
3073
|
+
}
|
|
3074
|
+
return matches;
|
|
3075
|
+
}
|
|
3076
|
+
var transformer = (0, import_preset_code6.transformerCreator)((text) => {
|
|
3077
|
+
const originalSource = text.toString();
|
|
3078
|
+
const matches = findAllMatches(originalSource, /\{\{([^\}]*)\}\}/g);
|
|
3079
|
+
if (matches.length > 0) {
|
|
3080
|
+
matches.forEach(({ range }) => {
|
|
3081
|
+
text.replaceRange(range[0], range[1], "null");
|
|
3082
|
+
});
|
|
3083
|
+
}
|
|
3084
|
+
return text;
|
|
3085
|
+
});
|
|
3048
3086
|
function JsonEditorWithVariables(props) {
|
|
3049
|
-
return /* @__PURE__ */ import_react41.default.createElement(
|
|
3087
|
+
return /* @__PURE__ */ import_react41.default.createElement(
|
|
3088
|
+
CodeEditor,
|
|
3089
|
+
{
|
|
3090
|
+
languageId: "json",
|
|
3091
|
+
activeLinePlaceholder: "Press '@' to Select variable",
|
|
3092
|
+
...props,
|
|
3093
|
+
options: {
|
|
3094
|
+
transformer,
|
|
3095
|
+
...props.options || {}
|
|
3096
|
+
}
|
|
3097
|
+
},
|
|
3098
|
+
/* @__PURE__ */ import_react41.default.createElement(VariableTree2, null),
|
|
3099
|
+
/* @__PURE__ */ import_react41.default.createElement(VariableTagInject2, null)
|
|
3100
|
+
);
|
|
3050
3101
|
}
|
|
3051
3102
|
|
|
3052
3103
|
// src/effects/provide-batch-input/index.ts
|
|
@@ -3107,7 +3158,7 @@ var provideBatchOutputsEffect = (0, import_editor12.createEffectFromVariableProv
|
|
|
3107
3158
|
});
|
|
3108
3159
|
|
|
3109
3160
|
// src/effects/auto-rename-ref/index.ts
|
|
3110
|
-
var
|
|
3161
|
+
var import_lodash8 = require("lodash");
|
|
3111
3162
|
var import_editor13 = require("@flowgram.ai/editor");
|
|
3112
3163
|
var autoRenameRefEffect = [
|
|
3113
3164
|
{
|
|
@@ -3125,9 +3176,30 @@ var autoRenameRefEffect = [
|
|
|
3125
3176
|
after.key
|
|
3126
3177
|
];
|
|
3127
3178
|
traverseRef(name, form.getValueIn(name), (_drilldownName, _v) => {
|
|
3128
|
-
if (
|
|
3129
|
-
|
|
3130
|
-
|
|
3179
|
+
if (_v.type === "ref") {
|
|
3180
|
+
if (isKeyPathMatch(_v.content, beforeKeyPath)) {
|
|
3181
|
+
_v.content = [...afterKeyPath, ...(_v.content || [])?.slice(beforeKeyPath.length)];
|
|
3182
|
+
form.setValueIn(_drilldownName, _v);
|
|
3183
|
+
}
|
|
3184
|
+
} else if (_v.type === "template") {
|
|
3185
|
+
const templateKeyPaths = getTemplateKeyPaths(_v);
|
|
3186
|
+
let hasMatch = false;
|
|
3187
|
+
templateKeyPaths.forEach((_keyPath) => {
|
|
3188
|
+
if (isKeyPathMatch(_keyPath, beforeKeyPath)) {
|
|
3189
|
+
hasMatch = true;
|
|
3190
|
+
const nextKeyPath = [
|
|
3191
|
+
...afterKeyPath,
|
|
3192
|
+
...(_keyPath || [])?.slice(beforeKeyPath.length)
|
|
3193
|
+
];
|
|
3194
|
+
_v.content = _v.content?.replace(
|
|
3195
|
+
`{{${_keyPath.join(".")}}`,
|
|
3196
|
+
`{{${nextKeyPath.join(".")}}`
|
|
3197
|
+
);
|
|
3198
|
+
}
|
|
3199
|
+
});
|
|
3200
|
+
if (hasMatch) {
|
|
3201
|
+
form.setValueIn(_drilldownName, { ..._v });
|
|
3202
|
+
}
|
|
3131
3203
|
}
|
|
3132
3204
|
});
|
|
3133
3205
|
});
|
|
@@ -3137,24 +3209,37 @@ var autoRenameRefEffect = [
|
|
|
3137
3209
|
}
|
|
3138
3210
|
}
|
|
3139
3211
|
];
|
|
3140
|
-
function
|
|
3141
|
-
return targetKeyPath.every((_key, index) => _key ===
|
|
3212
|
+
function isKeyPathMatch(keyPath = [], targetKeyPath) {
|
|
3213
|
+
return targetKeyPath.every((_key, index) => _key === keyPath[index]);
|
|
3214
|
+
}
|
|
3215
|
+
function getTemplateKeyPaths(value) {
|
|
3216
|
+
const keyPathReg = /{{(.*?)}}/g;
|
|
3217
|
+
return (0, import_lodash8.uniq)(value.content?.match(keyPathReg) || []).map(
|
|
3218
|
+
(_keyPath) => _keyPath.slice(2, -2).split(".")
|
|
3219
|
+
);
|
|
3142
3220
|
}
|
|
3143
3221
|
function isRef(value) {
|
|
3144
3222
|
return value?.type === "ref" && Array.isArray(value?.content) && typeof value?.content[0] === "string";
|
|
3145
3223
|
}
|
|
3224
|
+
function isTemplate(value) {
|
|
3225
|
+
return value?.type === "template" && typeof value?.content === "string";
|
|
3226
|
+
}
|
|
3146
3227
|
function traverseRef(name, value, cb) {
|
|
3147
|
-
if ((0,
|
|
3228
|
+
if ((0, import_lodash8.isObject)(value)) {
|
|
3148
3229
|
if (isRef(value)) {
|
|
3149
3230
|
cb(name, value);
|
|
3150
3231
|
return;
|
|
3151
3232
|
}
|
|
3233
|
+
if (isTemplate(value)) {
|
|
3234
|
+
cb(name, value);
|
|
3235
|
+
return;
|
|
3236
|
+
}
|
|
3152
3237
|
Object.entries(value).forEach(([_key, _value]) => {
|
|
3153
3238
|
traverseRef(`${name}.${_key}`, _value, cb);
|
|
3154
3239
|
});
|
|
3155
3240
|
return;
|
|
3156
3241
|
}
|
|
3157
|
-
if ((0,
|
|
3242
|
+
if ((0, import_lodash8.isArray)(value)) {
|
|
3158
3243
|
value.forEach((_value, idx) => {
|
|
3159
3244
|
traverseRef(`${name}[${idx}]`, _value, cb);
|
|
3160
3245
|
});
|