@flowgram.ai/form-materials 0.2.20 → 0.2.22

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.
Files changed (28) hide show
  1. package/dist/esm/index.js +683 -4
  2. package/dist/esm/index.js.map +1 -1
  3. package/dist/index.d.mts +42 -10
  4. package/dist/index.d.ts +42 -10
  5. package/dist/index.js +707 -48
  6. package/dist/index.js.map +1 -1
  7. package/package.json +6 -5
  8. package/src/components/code-editor/config.json +9 -0
  9. package/src/components/code-editor/index.tsx +59 -0
  10. package/src/components/code-editor/language-features.ts +24 -0
  11. package/src/components/code-editor/theme/dark.ts +119 -0
  12. package/src/components/code-editor/theme/index.ts +12 -0
  13. package/src/components/code-editor/theme/light.ts +119 -0
  14. package/src/components/code-editor/utils.ts +20 -0
  15. package/src/components/index.ts +3 -0
  16. package/src/components/json-editor-with-variables/config.json +13 -0
  17. package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +173 -0
  18. package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +83 -0
  19. package/src/components/json-editor-with-variables/index.tsx +19 -0
  20. package/src/components/json-editor-with-variables/styles.tsx +44 -0
  21. package/src/components/prompt-editor/config.json +1 -1
  22. package/src/components/prompt-editor/index.tsx +15 -2
  23. package/src/components/prompt-editor/types.tsx +2 -0
  24. package/src/components/prompt-editor-with-inputs/config.json +13 -0
  25. package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +82 -0
  26. package/src/components/prompt-editor-with-inputs/index.tsx +22 -0
  27. package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +100 -0
  28. package/src/components/prompt-editor-with-variables/config.json +4 -3
package/dist/index.js CHANGED
@@ -33,12 +33,15 @@ __export(src_exports, {
33
33
  ArrayIcons: () => ArrayIcons,
34
34
  BatchOutputs: () => BatchOutputs,
35
35
  BatchVariableSelector: () => BatchVariableSelector,
36
+ CodeEditor: () => CodeEditor,
36
37
  ConditionRow: () => ConditionRow,
37
38
  ConstantInput: () => ConstantInput,
38
39
  DynamicValueInput: () => DynamicValueInput,
40
+ JsonEditorWithVariables: () => JsonEditorWithVariables,
39
41
  JsonSchemaEditor: () => JsonSchemaEditor,
40
42
  JsonSchemaUtils: () => JsonSchemaUtils,
41
43
  PromptEditor: () => PromptEditor,
44
+ PromptEditorWithInputs: () => PromptEditorWithInputs,
42
45
  PromptEditorWithVariables: () => PromptEditorWithVariables,
43
46
  TypeSelector: () => TypeSelector,
44
47
  VariableSelector: () => VariableSelector,
@@ -2141,7 +2144,16 @@ var jinja_default = JinjaHighlight;
2141
2144
 
2142
2145
  // src/components/prompt-editor/index.tsx
2143
2146
  function PromptEditor(props) {
2144
- const { value, onChange, readonly, style, hasError, children } = props || {};
2147
+ const {
2148
+ value,
2149
+ onChange,
2150
+ readonly,
2151
+ placeholder,
2152
+ activeLinePlaceholder,
2153
+ style,
2154
+ hasError,
2155
+ children
2156
+ } = props || {};
2145
2157
  return /* @__PURE__ */ import_react24.default.createElement(UIContainer4, { $hasError: hasError, style }, /* @__PURE__ */ import_react24.default.createElement(import_react25.EditorProvider, null, /* @__PURE__ */ import_react24.default.createElement(
2146
2158
  import_react25.Renderer,
2147
2159
  {
@@ -2149,13 +2161,14 @@ function PromptEditor(props) {
2149
2161
  defaultValue: String(value?.content),
2150
2162
  options: {
2151
2163
  readOnly: readonly,
2152
- editable: !readonly
2164
+ editable: !readonly,
2165
+ placeholder
2153
2166
  },
2154
2167
  onChange: (e) => {
2155
2168
  onChange({ type: "template", content: e.value });
2156
2169
  }
2157
2170
  }
2158
- ), /* @__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));
2171
+ ), 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));
2159
2172
  }
2160
2173
 
2161
2174
  // src/components/prompt-editor-with-variables/index.tsx
@@ -2372,30 +2385,673 @@ function PromptEditorWithVariables(props) {
2372
2385
  return /* @__PURE__ */ import_react30.default.createElement(PromptEditor, { ...props }, /* @__PURE__ */ import_react30.default.createElement(VariableTree, null), /* @__PURE__ */ import_react30.default.createElement(VariableTagInject, null));
2373
2386
  }
2374
2387
 
2375
- // src/effects/provide-batch-input/index.ts
2388
+ // src/components/prompt-editor-with-inputs/index.tsx
2389
+ var import_react34 = __toESM(require("react"));
2390
+
2391
+ // src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx
2392
+ var import_react32 = __toESM(require("react"));
2393
+ var import_semi_ui15 = require("@douyinfe/semi-ui");
2394
+ var import_react33 = require("@coze-editor/editor/react");
2395
+
2396
+ // src/components/prompt-editor-with-inputs/inputs-picker.tsx
2397
+ var import_react31 = __toESM(require("react"));
2398
+ var import_lodash5 = require("lodash");
2376
2399
  var import_editor8 = require("@flowgram.ai/editor");
2377
- var provideBatchInputEffect = (0, import_editor8.createEffectFromVariableProvider)({
2400
+ var import_semi_ui14 = require("@douyinfe/semi-ui");
2401
+ function InputsPicker({
2402
+ inputsValues,
2403
+ onSelect
2404
+ }) {
2405
+ const available = (0, import_editor8.useScopeAvailable)();
2406
+ const getArrayDrilldown = (type, depth = 1) => {
2407
+ if (import_editor8.ASTMatch.isArray(type.items)) {
2408
+ return getArrayDrilldown(type.items, depth + 1);
2409
+ }
2410
+ return { type: type.items, depth };
2411
+ };
2412
+ const renderVariable = (variable, keyPath) => {
2413
+ let type = variable?.type;
2414
+ let children;
2415
+ if (import_editor8.ASTMatch.isObject(type)) {
2416
+ children = (type.properties || []).map((_property) => renderVariable(_property, [...keyPath, _property.key])).filter(Boolean);
2417
+ }
2418
+ if (import_editor8.ASTMatch.isArray(type)) {
2419
+ const drilldown = getArrayDrilldown(type);
2420
+ if (import_editor8.ASTMatch.isObject(drilldown.type)) {
2421
+ children = (drilldown.type.properties || []).map(
2422
+ (_property) => renderVariable(_property, [
2423
+ ...keyPath,
2424
+ ...new Array(drilldown.depth).fill("[0]"),
2425
+ _property.key
2426
+ ])
2427
+ ).filter(Boolean);
2428
+ }
2429
+ }
2430
+ const key = keyPath.map((_key, idx) => _key === "[0]" || idx === 0 ? _key : `.${_key}`).join("");
2431
+ return {
2432
+ key,
2433
+ label: (0, import_lodash5.last)(keyPath),
2434
+ value: key,
2435
+ children
2436
+ };
2437
+ };
2438
+ const treeData = (0, import_react31.useMemo)(
2439
+ () => Object.entries(inputsValues).map(([key, value]) => {
2440
+ if (value.type === "ref") {
2441
+ const variable = available.getByKeyPath(value.content || []);
2442
+ if (variable) {
2443
+ return renderVariable(variable, [key]);
2444
+ }
2445
+ }
2446
+ return {
2447
+ key,
2448
+ value: key,
2449
+ label: key
2450
+ };
2451
+ }),
2452
+ []
2453
+ );
2454
+ return /* @__PURE__ */ import_react31.default.createElement(import_semi_ui14.Tree, { treeData, onSelect: (v) => onSelect(v) });
2455
+ }
2456
+
2457
+ // src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx
2458
+ function InputsTree({ inputsValues }) {
2459
+ const [posKey, setPosKey] = (0, import_react32.useState)("");
2460
+ const [visible, setVisible] = (0, import_react32.useState)(false);
2461
+ const [position, setPosition] = (0, import_react32.useState)(-1);
2462
+ const editor = (0, import_react33.useEditor)();
2463
+ function insert(variablePath) {
2464
+ const range = (0, import_react33.getCurrentMentionReplaceRange)(editor.$view.state);
2465
+ if (!range) {
2466
+ return;
2467
+ }
2468
+ editor.replaceText({
2469
+ ...range,
2470
+ text: "{{" + variablePath + "}}"
2471
+ });
2472
+ setVisible(false);
2473
+ }
2474
+ function handleOpenChange(e) {
2475
+ setPosition(e.state.selection.main.head);
2476
+ setVisible(e.value);
2477
+ }
2478
+ (0, import_react32.useEffect)(() => {
2479
+ if (!editor) {
2480
+ return;
2481
+ }
2482
+ }, [editor, visible]);
2483
+ return /* @__PURE__ */ import_react32.default.createElement(import_react32.default.Fragment, null, /* @__PURE__ */ import_react32.default.createElement(import_react33.Mention, { triggerCharacters: ["{", "{}", "@"], onOpenChange: handleOpenChange }), /* @__PURE__ */ import_react32.default.createElement(
2484
+ import_semi_ui15.Popover,
2485
+ {
2486
+ visible,
2487
+ trigger: "custom",
2488
+ position: "topLeft",
2489
+ rePosKey: posKey,
2490
+ content: /* @__PURE__ */ import_react32.default.createElement("div", { style: { width: 300 } }, /* @__PURE__ */ import_react32.default.createElement(
2491
+ InputsPicker,
2492
+ {
2493
+ inputsValues,
2494
+ onSelect: (v) => {
2495
+ insert(v);
2496
+ }
2497
+ }
2498
+ ))
2499
+ },
2500
+ /* @__PURE__ */ import_react32.default.createElement(
2501
+ import_react33.PositionMirror,
2502
+ {
2503
+ position,
2504
+ onChange: () => setPosKey(String(Math.random()))
2505
+ }
2506
+ )
2507
+ ));
2508
+ }
2509
+
2510
+ // src/components/prompt-editor-with-inputs/index.tsx
2511
+ function PromptEditorWithInputs({ inputsValues, ...restProps }) {
2512
+ return /* @__PURE__ */ import_react34.default.createElement(PromptEditor, { ...restProps }, /* @__PURE__ */ import_react34.default.createElement(InputsTree, { inputsValues }));
2513
+ }
2514
+
2515
+ // src/components/code-editor/index.tsx
2516
+ var import_react35 = __toESM(require("react"));
2517
+ var import_react36 = require("@coze-editor/editor/react");
2518
+ var import_preset_code5 = __toESM(require("@coze-editor/editor/preset-code"));
2519
+ var import_view4 = require("@codemirror/view");
2520
+
2521
+ // src/components/code-editor/utils.ts
2522
+ function getSuffixByLanguageId(languageId) {
2523
+ if (languageId === "python") {
2524
+ return ".py";
2525
+ }
2526
+ if (languageId === "typescript") {
2527
+ return ".ts";
2528
+ }
2529
+ if (languageId === "shell") {
2530
+ return ".sh";
2531
+ }
2532
+ if (languageId === "json") {
2533
+ return ".json";
2534
+ }
2535
+ return "";
2536
+ }
2537
+
2538
+ // src/components/code-editor/theme/index.ts
2539
+ var import_preset_code3 = require("@coze-editor/editor/preset-code");
2540
+
2541
+ // src/components/code-editor/theme/light.ts
2542
+ var import_preset_code = require("@coze-editor/editor/preset-code");
2543
+ var colors = {
2544
+ background: "#F7F7FC",
2545
+ // syntax
2546
+ comment: "#000A298A",
2547
+ key: "#00818C",
2548
+ string: "#D1009D",
2549
+ number: "#C74200",
2550
+ boolean: "#2B57D9",
2551
+ null: "#2B57D9",
2552
+ separator: "#0F1529D1"
2553
+ };
2554
+ var lightTheme = (0, import_preset_code.createTheme)({
2555
+ variant: "light",
2556
+ settings: {
2557
+ background: "#fff",
2558
+ foreground: "#000",
2559
+ caret: "#000",
2560
+ selection: "#d9d9d9",
2561
+ gutterBackground: "#f0f0f0",
2562
+ gutterForeground: "#666",
2563
+ gutterBorderColor: "transparent",
2564
+ gutterBorderWidth: 0,
2565
+ lineHighlight: "#f0f0f0",
2566
+ bracketColors: ["#FFEF61", "#DD99FF", "#78B0FF"],
2567
+ tooltip: {
2568
+ backgroundColor: "#f0f0f0",
2569
+ color: "#000",
2570
+ border: "1px solid #ccc"
2571
+ },
2572
+ link: {
2573
+ color: "#007bff"
2574
+ },
2575
+ completionItemHover: {
2576
+ backgroundColor: "#f0f0f0"
2577
+ },
2578
+ completionItemSelected: {
2579
+ backgroundColor: "#e0e0e0"
2580
+ },
2581
+ completionItemIcon: {
2582
+ color: "#333"
2583
+ },
2584
+ completionItemLabel: {
2585
+ color: "#333"
2586
+ },
2587
+ completionItemInfo: {
2588
+ color: "#333"
2589
+ },
2590
+ completionItemDetail: {
2591
+ color: "#666"
2592
+ }
2593
+ },
2594
+ styles: [
2595
+ // JSON
2596
+ {
2597
+ tag: import_preset_code.tags.comment,
2598
+ color: colors.comment
2599
+ },
2600
+ {
2601
+ tag: [import_preset_code.tags.propertyName],
2602
+ color: colors.key
2603
+ },
2604
+ {
2605
+ tag: [import_preset_code.tags.string],
2606
+ color: colors.string
2607
+ },
2608
+ {
2609
+ tag: [import_preset_code.tags.number],
2610
+ color: colors.number
2611
+ },
2612
+ {
2613
+ tag: [import_preset_code.tags.bool],
2614
+ color: colors.boolean
2615
+ },
2616
+ {
2617
+ tag: [import_preset_code.tags.null],
2618
+ color: colors.null
2619
+ },
2620
+ {
2621
+ tag: [import_preset_code.tags.separator],
2622
+ color: colors.separator
2623
+ },
2624
+ // markdown
2625
+ {
2626
+ tag: [import_preset_code.tags.heading],
2627
+ color: "#3e76ef"
2628
+ },
2629
+ {
2630
+ tag: [import_preset_code.tags.processingInstruction],
2631
+ color: "#3e76ef"
2632
+ },
2633
+ // shell
2634
+ // curl
2635
+ {
2636
+ tag: [import_preset_code.tags.standard(import_preset_code.tags.variableName)],
2637
+ color: "#00804A"
2638
+ },
2639
+ // -X
2640
+ {
2641
+ tag: [import_preset_code.tags.attributeName],
2642
+ color: "#C74200"
2643
+ },
2644
+ // url in string (includes quotes), e.g. "https://..."
2645
+ {
2646
+ tag: [import_preset_code.tags.special(import_preset_code.tags.string)],
2647
+ color: "#2B57D9"
2648
+ }
2649
+ ]
2650
+ });
2651
+
2652
+ // src/components/code-editor/theme/dark.ts
2653
+ var import_preset_code2 = require("@coze-editor/editor/preset-code");
2654
+ var colors2 = {
2655
+ background: "#151B27",
2656
+ // syntax
2657
+ comment: "#FFFFFF63",
2658
+ key: "#39E5D7",
2659
+ string: "#FF94D2",
2660
+ number: "#FF9933",
2661
+ boolean: "#78B0FF",
2662
+ null: "#78B0FF",
2663
+ separator: "#FFFFFFC9"
2664
+ };
2665
+ var darkTheme = (0, import_preset_code2.createTheme)({
2666
+ variant: "dark",
2667
+ settings: {
2668
+ background: colors2.background,
2669
+ foreground: "#fff",
2670
+ caret: "#AEAFAD",
2671
+ selection: "#d9d9d942",
2672
+ gutterBackground: colors2.background,
2673
+ gutterForeground: "#FFFFFF63",
2674
+ gutterBorderColor: "transparent",
2675
+ gutterBorderWidth: 0,
2676
+ lineHighlight: "#272e3d36",
2677
+ bracketColors: ["#FFEF61", "#DD99FF", "#78B0FF"],
2678
+ tooltip: {
2679
+ backgroundColor: "#363D4D",
2680
+ color: "#fff",
2681
+ border: "none"
2682
+ },
2683
+ link: {
2684
+ color: "#4daafc"
2685
+ },
2686
+ completionItemHover: {
2687
+ backgroundColor: "#FFFFFF0F"
2688
+ },
2689
+ completionItemSelected: {
2690
+ backgroundColor: "#FFFFFF17"
2691
+ },
2692
+ completionItemIcon: {
2693
+ color: "#FFFFFFC9"
2694
+ },
2695
+ completionItemLabel: {
2696
+ color: "#FFFFFFC9"
2697
+ },
2698
+ completionItemInfo: {
2699
+ color: "#FFFFFFC9"
2700
+ },
2701
+ completionItemDetail: {
2702
+ color: "#FFFFFF63"
2703
+ }
2704
+ },
2705
+ styles: [
2706
+ // json
2707
+ {
2708
+ tag: import_preset_code2.tags.comment,
2709
+ color: colors2.comment
2710
+ },
2711
+ {
2712
+ tag: [import_preset_code2.tags.propertyName],
2713
+ color: colors2.key
2714
+ },
2715
+ {
2716
+ tag: [import_preset_code2.tags.string],
2717
+ color: colors2.string
2718
+ },
2719
+ {
2720
+ tag: [import_preset_code2.tags.number],
2721
+ color: colors2.number
2722
+ },
2723
+ {
2724
+ tag: [import_preset_code2.tags.bool],
2725
+ color: colors2.boolean
2726
+ },
2727
+ {
2728
+ tag: [import_preset_code2.tags.null],
2729
+ color: colors2.null
2730
+ },
2731
+ {
2732
+ tag: [import_preset_code2.tags.separator],
2733
+ color: colors2.separator
2734
+ },
2735
+ // markdown
2736
+ {
2737
+ tag: [import_preset_code2.tags.heading],
2738
+ color: "#6b6bff"
2739
+ },
2740
+ {
2741
+ tag: [import_preset_code2.tags.processingInstruction],
2742
+ color: "#6b6bff"
2743
+ },
2744
+ // shell
2745
+ // curl
2746
+ {
2747
+ tag: [import_preset_code2.tags.standard(import_preset_code2.tags.variableName)],
2748
+ color: "#3BEB84"
2749
+ },
2750
+ // -X
2751
+ {
2752
+ tag: [import_preset_code2.tags.attributeName],
2753
+ color: "#FF9933"
2754
+ },
2755
+ // url in string (includes quotes), e.g. "https://..."
2756
+ {
2757
+ tag: [import_preset_code2.tags.special(import_preset_code2.tags.string)],
2758
+ color: "#78B0FF"
2759
+ }
2760
+ ]
2761
+ });
2762
+
2763
+ // src/components/code-editor/theme/index.ts
2764
+ import_preset_code3.themes.register("dark", darkTheme);
2765
+ import_preset_code3.themes.register("light", lightTheme);
2766
+
2767
+ // src/components/code-editor/language-features.ts
2768
+ var import_preset_code4 = require("@coze-editor/editor/preset-code");
2769
+ var import_language_shell = require("@coze-editor/editor/language-shell");
2770
+ var import_language_python = require("@coze-editor/editor/language-python");
2771
+ var import_language_json = require("@coze-editor/editor/language-json");
2772
+ var import_editor9 = require("@coze-editor/editor");
2773
+ import_preset_code4.languages.register("python", import_language_python.python);
2774
+ import_preset_code4.languages.register("json", {
2775
+ // mixLanguages is used to solve the problem that interpolation also uses parentheses, which causes incorrect highlighting
2776
+ language: (0, import_editor9.mixLanguages)({
2777
+ outerLanguage: import_language_json.json.language
2778
+ }),
2779
+ languageService: import_language_json.json.languageService
2780
+ });
2781
+ import_preset_code4.languages.register("shell", import_language_shell.shell);
2782
+
2783
+ // src/components/code-editor/index.tsx
2784
+ var OriginCodeEditor = (0, import_react36.createRenderer)(import_preset_code5.default, [
2785
+ import_view4.EditorView.theme({
2786
+ "&.cm-focused": {
2787
+ outline: "none"
2788
+ }
2789
+ })
2790
+ ]);
2791
+ function CodeEditor({
2792
+ value,
2793
+ onChange,
2794
+ languageId = "python",
2795
+ theme = "light",
2796
+ children
2797
+ }) {
2798
+ const editorRef = (0, import_react35.useRef)(null);
2799
+ return /* @__PURE__ */ import_react35.default.createElement(import_react36.EditorProvider, null, /* @__PURE__ */ import_react35.default.createElement(
2800
+ OriginCodeEditor,
2801
+ {
2802
+ defaultValue: value,
2803
+ options: {
2804
+ uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
2805
+ languageId,
2806
+ theme
2807
+ },
2808
+ didMount: (editor) => {
2809
+ editorRef.current = editor;
2810
+ },
2811
+ onChange: (e) => onChange?.(e.value)
2812
+ },
2813
+ children
2814
+ ));
2815
+ }
2816
+
2817
+ // src/components/json-editor-with-variables/index.tsx
2818
+ var import_react41 = __toESM(require("react"));
2819
+
2820
+ // src/components/json-editor-with-variables/extensions/variable-tree.tsx
2821
+ var import_react37 = __toESM(require("react"));
2822
+ var import_semi_ui16 = require("@douyinfe/semi-ui");
2823
+ var import_react38 = require("@coze-editor/editor/react");
2824
+ function VariableTree2() {
2825
+ const [posKey, setPosKey] = (0, import_react37.useState)("");
2826
+ const [visible, setVisible] = (0, import_react37.useState)(false);
2827
+ const [position, setPosition] = (0, import_react37.useState)(-1);
2828
+ const editor = (0, import_react38.useEditor)();
2829
+ function insert(variablePath) {
2830
+ const range = (0, import_react38.getCurrentMentionReplaceRange)(editor.$view.state);
2831
+ if (!range) {
2832
+ return;
2833
+ }
2834
+ editor.replaceText({
2835
+ ...range,
2836
+ text: "{{" + variablePath + "}}"
2837
+ });
2838
+ setVisible(false);
2839
+ }
2840
+ function handleOpenChange(e) {
2841
+ setPosition(e.state.selection.main.head);
2842
+ setVisible(e.value);
2843
+ }
2844
+ (0, import_react37.useEffect)(() => {
2845
+ if (!editor) {
2846
+ return;
2847
+ }
2848
+ }, [editor, visible]);
2849
+ const treeData = useVariableTree({});
2850
+ return /* @__PURE__ */ import_react37.default.createElement(import_react37.default.Fragment, null, /* @__PURE__ */ import_react37.default.createElement(import_react38.Mention, { triggerCharacters: ["@"], onOpenChange: handleOpenChange }), /* @__PURE__ */ import_react37.default.createElement(
2851
+ import_semi_ui16.Popover,
2852
+ {
2853
+ visible,
2854
+ trigger: "custom",
2855
+ position: "topLeft",
2856
+ rePosKey: posKey,
2857
+ content: /* @__PURE__ */ import_react37.default.createElement("div", { style: { width: 300 } }, /* @__PURE__ */ import_react37.default.createElement(
2858
+ import_semi_ui16.Tree,
2859
+ {
2860
+ treeData,
2861
+ onSelect: (v) => {
2862
+ insert(v);
2863
+ }
2864
+ }
2865
+ ))
2866
+ },
2867
+ /* @__PURE__ */ import_react37.default.createElement(
2868
+ import_react38.PositionMirror,
2869
+ {
2870
+ position,
2871
+ onChange: () => setPosKey(String(Math.random()))
2872
+ }
2873
+ )
2874
+ ));
2875
+ }
2876
+
2877
+ // src/components/json-editor-with-variables/extensions/variable-tag.tsx
2878
+ var import_react39 = __toESM(require("react"));
2879
+ var import_client2 = require("react-dom/client");
2880
+ var import_lodash6 = require("lodash");
2881
+ var import_editor10 = require("@flowgram.ai/editor");
2882
+ var import_semi_ui18 = require("@douyinfe/semi-ui");
2883
+ var import_semi_icons10 = require("@douyinfe/semi-icons");
2884
+ var import_react40 = require("@coze-editor/editor/react");
2885
+ var import_view5 = require("@codemirror/view");
2886
+
2887
+ // src/components/json-editor-with-variables/styles.tsx
2888
+ var import_styled_components8 = __toESM(require("styled-components"));
2889
+ var import_semi_ui17 = require("@douyinfe/semi-ui");
2890
+ var UIRootTitle3 = import_styled_components8.default.div`
2891
+ margin-right: 4px;
2892
+ min-width: 20px;
2893
+ overflow: hidden;
2894
+ text-overflow: ellipsis;
2895
+ white-space: nowrap;
2896
+ color: var(--semi-color-text-2);
2897
+ `;
2898
+ var UIVarName3 = import_styled_components8.default.div`
2899
+ overflow: hidden;
2900
+ text-overflow: ellipsis;
2901
+ white-space: nowrap;
2902
+ `;
2903
+ var UITag3 = (0, import_styled_components8.default)(import_semi_ui17.Tag)`
2904
+ display: inline-flex;
2905
+ align-items: center;
2906
+ justify-content: flex-start;
2907
+ max-width: 300px;
2908
+
2909
+ & .semi-tag-content-center {
2910
+ justify-content: flex-start;
2911
+ }
2912
+
2913
+ &.semi-tag {
2914
+ margin: 0 5px;
2915
+ }
2916
+ `;
2917
+ var UIPopoverContent2 = import_styled_components8.default.div`
2918
+ padding: 10px;
2919
+ display: inline-flex;
2920
+ align-items: center;
2921
+ justify-content: flex-start;
2922
+ `;
2923
+
2924
+ // src/components/json-editor-with-variables/extensions/variable-tag.tsx
2925
+ var VariableTagWidget2 = class extends import_view5.WidgetType {
2926
+ constructor({ keyPath, scope }) {
2927
+ super();
2928
+ this.toDispose = new import_editor10.DisposableCollection();
2929
+ this.renderIcon = (icon) => {
2930
+ if (typeof icon === "string") {
2931
+ return /* @__PURE__ */ import_react39.default.createElement("img", { style: { marginRight: 8 }, width: 12, height: 12, src: icon });
2932
+ }
2933
+ return icon;
2934
+ };
2935
+ this.keyPath = keyPath;
2936
+ this.scope = scope;
2937
+ }
2938
+ renderVariable(v) {
2939
+ if (!v) {
2940
+ this.root.render(
2941
+ /* @__PURE__ */ import_react39.default.createElement(UITag3, { prefixIcon: /* @__PURE__ */ import_react39.default.createElement(import_semi_icons10.IconIssueStroked, null), color: "amber" }, "Unknown")
2942
+ );
2943
+ return;
2944
+ }
2945
+ const rootField = (0, import_lodash6.last)(v.parentFields);
2946
+ const rootTitle = /* @__PURE__ */ import_react39.default.createElement(UIRootTitle3, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
2947
+ const rootIcon = this.renderIcon(rootField?.meta.icon);
2948
+ this.root.render(
2949
+ /* @__PURE__ */ import_react39.default.createElement(
2950
+ import_semi_ui18.Popover,
2951
+ {
2952
+ content: /* @__PURE__ */ import_react39.default.createElement(UIPopoverContent2, null, rootIcon, rootTitle, /* @__PURE__ */ import_react39.default.createElement(UIVarName3, null, v?.keyPath.slice(1).join(".")))
2953
+ },
2954
+ /* @__PURE__ */ import_react39.default.createElement(UITag3, { prefixIcon: rootIcon }, rootTitle, /* @__PURE__ */ import_react39.default.createElement(UIVarName3, null, v?.key))
2955
+ )
2956
+ );
2957
+ }
2958
+ toDOM(view) {
2959
+ const dom = document.createElement("span");
2960
+ this.root = (0, import_client2.createRoot)(dom);
2961
+ this.toDispose.push(
2962
+ import_editor10.Disposable.create(() => {
2963
+ this.root.unmount();
2964
+ })
2965
+ );
2966
+ this.toDispose.push(
2967
+ this.scope.available.trackByKeyPath(
2968
+ this.keyPath,
2969
+ (v) => {
2970
+ this.renderVariable(v);
2971
+ },
2972
+ { triggerOnInit: false }
2973
+ )
2974
+ );
2975
+ this.renderVariable(this.scope.available.getByKeyPath(this.keyPath));
2976
+ return dom;
2977
+ }
2978
+ eq(other) {
2979
+ return (0, import_lodash6.isEqual)(this.keyPath, other.keyPath);
2980
+ }
2981
+ ignoreEvent() {
2982
+ return false;
2983
+ }
2984
+ destroy(dom) {
2985
+ this.toDispose.dispose();
2986
+ }
2987
+ };
2988
+ function VariableTagInject2() {
2989
+ const injector = (0, import_react40.useInjector)();
2990
+ const scope = (0, import_editor10.useCurrentScope)();
2991
+ (0, import_react39.useLayoutEffect)(() => {
2992
+ const atMatcher = new import_view5.MatchDecorator({
2993
+ regexp: /\{\{([^\}]+)\}\}/g,
2994
+ decoration: (match) => import_view5.Decoration.replace({
2995
+ widget: new VariableTagWidget2({
2996
+ keyPath: match[1]?.split(".") ?? [],
2997
+ scope
2998
+ })
2999
+ })
3000
+ });
3001
+ return injector.inject([
3002
+ import_view5.ViewPlugin.fromClass(
3003
+ class {
3004
+ constructor(view) {
3005
+ this.view = view;
3006
+ this.decorations = atMatcher.createDeco(view);
3007
+ }
3008
+ update() {
3009
+ this.decorations = atMatcher.createDeco(this.view);
3010
+ }
3011
+ },
3012
+ {
3013
+ decorations: (p) => p.decorations,
3014
+ provide(p) {
3015
+ return import_view5.EditorView.atomicRanges.of(
3016
+ (view) => view.plugin(p)?.decorations ?? import_view5.Decoration.none
3017
+ );
3018
+ }
3019
+ }
3020
+ )
3021
+ ]);
3022
+ }, [injector]);
3023
+ return null;
3024
+ }
3025
+
3026
+ // src/components/json-editor-with-variables/index.tsx
3027
+ function JsonEditorWithVariables(props) {
3028
+ return /* @__PURE__ */ import_react41.default.createElement(CodeEditor, { languageId: "json", ...props }, /* @__PURE__ */ import_react41.default.createElement(VariableTree2, null), /* @__PURE__ */ import_react41.default.createElement(VariableTagInject2, null));
3029
+ }
3030
+
3031
+ // src/effects/provide-batch-input/index.ts
3032
+ var import_editor11 = require("@flowgram.ai/editor");
3033
+ var provideBatchInputEffect = (0, import_editor11.createEffectFromVariableProvider)({
2378
3034
  private: true,
2379
3035
  parse: (value, ctx) => [
2380
- import_editor8.ASTFactory.createVariableDeclaration({
3036
+ import_editor11.ASTFactory.createVariableDeclaration({
2381
3037
  key: `${ctx.node.id}_locals`,
2382
3038
  meta: {
2383
- title: (0, import_editor8.getNodeForm)(ctx.node)?.getValueIn("title"),
3039
+ title: (0, import_editor11.getNodeForm)(ctx.node)?.getValueIn("title"),
2384
3040
  icon: ctx.node.getNodeRegistry().info?.icon
2385
3041
  },
2386
- type: import_editor8.ASTFactory.createObject({
3042
+ type: import_editor11.ASTFactory.createObject({
2387
3043
  properties: [
2388
- import_editor8.ASTFactory.createProperty({
3044
+ import_editor11.ASTFactory.createProperty({
2389
3045
  key: "item",
2390
- initializer: import_editor8.ASTFactory.createEnumerateExpression({
2391
- enumerateFor: import_editor8.ASTFactory.createKeyPathExpression({
3046
+ initializer: import_editor11.ASTFactory.createEnumerateExpression({
3047
+ enumerateFor: import_editor11.ASTFactory.createKeyPathExpression({
2392
3048
  keyPath: value.content || []
2393
3049
  })
2394
3050
  })
2395
3051
  }),
2396
- import_editor8.ASTFactory.createProperty({
3052
+ import_editor11.ASTFactory.createProperty({
2397
3053
  key: "index",
2398
- type: import_editor8.ASTFactory.createNumber()
3054
+ type: import_editor11.ASTFactory.createNumber()
2399
3055
  })
2400
3056
  ]
2401
3057
  })
@@ -2404,21 +3060,21 @@ var provideBatchInputEffect = (0, import_editor8.createEffectFromVariableProvide
2404
3060
  });
2405
3061
 
2406
3062
  // src/effects/provide-batch-outputs/index.ts
2407
- var import_editor9 = require("@flowgram.ai/editor");
2408
- var provideBatchOutputsEffect = (0, import_editor9.createEffectFromVariableProvider)({
3063
+ var import_editor12 = require("@flowgram.ai/editor");
3064
+ var provideBatchOutputsEffect = (0, import_editor12.createEffectFromVariableProvider)({
2409
3065
  parse: (value, ctx) => [
2410
- import_editor9.ASTFactory.createVariableDeclaration({
3066
+ import_editor12.ASTFactory.createVariableDeclaration({
2411
3067
  key: `${ctx.node.id}`,
2412
3068
  meta: {
2413
- title: (0, import_editor9.getNodeForm)(ctx.node)?.getValueIn("title"),
3069
+ title: (0, import_editor12.getNodeForm)(ctx.node)?.getValueIn("title"),
2414
3070
  icon: ctx.node.getNodeRegistry().info?.icon
2415
3071
  },
2416
- type: import_editor9.ASTFactory.createObject({
3072
+ type: import_editor12.ASTFactory.createObject({
2417
3073
  properties: Object.entries(value).map(
2418
- ([_key, value2]) => import_editor9.ASTFactory.createProperty({
3074
+ ([_key, value2]) => import_editor12.ASTFactory.createProperty({
2419
3075
  key: _key,
2420
- initializer: import_editor9.ASTFactory.createWrapArrayExpression({
2421
- wrapFor: import_editor9.ASTFactory.createKeyPathExpression({
3076
+ initializer: import_editor12.ASTFactory.createWrapArrayExpression({
3077
+ wrapFor: import_editor12.ASTFactory.createKeyPathExpression({
2422
3078
  keyPath: value2.content || []
2423
3079
  })
2424
3080
  })
@@ -2430,14 +3086,14 @@ var provideBatchOutputsEffect = (0, import_editor9.createEffectFromVariableProvi
2430
3086
  });
2431
3087
 
2432
3088
  // src/effects/auto-rename-ref/index.ts
2433
- var import_lodash5 = require("lodash");
2434
- var import_editor10 = require("@flowgram.ai/editor");
3089
+ var import_lodash7 = require("lodash");
3090
+ var import_editor13 = require("@flowgram.ai/editor");
2435
3091
  var autoRenameRefEffect = [
2436
3092
  {
2437
- event: import_editor10.DataEvent.onValueInit,
3093
+ event: import_editor13.DataEvent.onValueInit,
2438
3094
  effect: (params) => {
2439
3095
  const { context, form, name } = params;
2440
- const renameService = context.node.getService(import_editor10.VariableFieldKeyRenameService);
3096
+ const renameService = context.node.getService(import_editor13.VariableFieldKeyRenameService);
2441
3097
  const disposable = renameService.onRename(({ before, after }) => {
2442
3098
  const beforeKeyPath = [
2443
3099
  ...before.parentFields.map((_field) => _field.key).reverse(),
@@ -2467,7 +3123,7 @@ function isRef(value) {
2467
3123
  return value?.type === "ref" && Array.isArray(value?.content) && typeof value?.content[0] === "string";
2468
3124
  }
2469
3125
  function traverseRef(name, value, cb) {
2470
- if ((0, import_lodash5.isObject)(value)) {
3126
+ if ((0, import_lodash7.isObject)(value)) {
2471
3127
  if (isRef(value)) {
2472
3128
  cb(name, value);
2473
3129
  return;
@@ -2477,7 +3133,7 @@ function traverseRef(name, value, cb) {
2477
3133
  });
2478
3134
  return;
2479
3135
  }
2480
- if ((0, import_lodash5.isArray)(value)) {
3136
+ if ((0, import_lodash7.isArray)(value)) {
2481
3137
  value.forEach((_value, idx) => {
2482
3138
  traverseRef(`${name}[${idx}]`, _value, cb);
2483
3139
  });
@@ -2487,13 +3143,13 @@ function traverseRef(name, value, cb) {
2487
3143
  }
2488
3144
 
2489
3145
  // src/effects/provide-json-schema-outputs/index.ts
2490
- var import_editor11 = require("@flowgram.ai/editor");
2491
- var provideJsonSchemaOutputs = (0, import_editor11.createEffectFromVariableProvider)({
3146
+ var import_editor14 = require("@flowgram.ai/editor");
3147
+ var provideJsonSchemaOutputs = (0, import_editor14.createEffectFromVariableProvider)({
2492
3148
  parse: (value, ctx) => [
2493
- import_editor11.ASTFactory.createVariableDeclaration({
3149
+ import_editor14.ASTFactory.createVariableDeclaration({
2494
3150
  key: `${ctx.node.id}`,
2495
3151
  meta: {
2496
- title: (0, import_editor11.getNodeForm)(ctx.node)?.getValueIn("title") || ctx.node.id,
3152
+ title: (0, import_editor14.getNodeForm)(ctx.node)?.getValueIn("title") || ctx.node.id,
2497
3153
  icon: ctx.node.getNodeRegistry().info?.icon
2498
3154
  },
2499
3155
  type: JsonSchemaUtils.schemaToAST(value)
@@ -2502,12 +3158,12 @@ var provideJsonSchemaOutputs = (0, import_editor11.createEffectFromVariableProvi
2502
3158
  });
2503
3159
 
2504
3160
  // src/effects/sync-variable-title/index.ts
2505
- var import_editor12 = require("@flowgram.ai/editor");
3161
+ var import_editor15 = require("@flowgram.ai/editor");
2506
3162
  var syncVariableTitle = [
2507
3163
  {
2508
- event: import_editor12.DataEvent.onValueChange,
3164
+ event: import_editor15.DataEvent.onValueChange,
2509
3165
  effect: ({ value, context }) => {
2510
- context.node.getData(import_editor12.FlowNodeVariableData).allScopes.forEach((_scope) => {
3166
+ context.node.getData(import_editor15.FlowNodeVariableData).allScopes.forEach((_scope) => {
2511
3167
  _scope.output.variables.forEach((_var) => {
2512
3168
  _var.updateMeta({
2513
3169
  title: value || context.node.id,
@@ -2520,21 +3176,21 @@ var syncVariableTitle = [
2520
3176
  ];
2521
3177
 
2522
3178
  // src/form-plugins/batch-outputs-plugin/index.ts
2523
- var import_editor13 = require("@flowgram.ai/editor");
2524
- var provideBatchOutputsEffect2 = (0, import_editor13.createEffectFromVariableProvider)({
3179
+ var import_editor16 = require("@flowgram.ai/editor");
3180
+ var provideBatchOutputsEffect2 = (0, import_editor16.createEffectFromVariableProvider)({
2525
3181
  parse: (value, ctx) => [
2526
- import_editor13.ASTFactory.createVariableDeclaration({
3182
+ import_editor16.ASTFactory.createVariableDeclaration({
2527
3183
  key: `${ctx.node.id}`,
2528
3184
  meta: {
2529
- title: (0, import_editor13.getNodeForm)(ctx.node)?.getValueIn("title"),
3185
+ title: (0, import_editor16.getNodeForm)(ctx.node)?.getValueIn("title"),
2530
3186
  icon: ctx.node.getNodeRegistry().info?.icon
2531
3187
  },
2532
- type: import_editor13.ASTFactory.createObject({
3188
+ type: import_editor16.ASTFactory.createObject({
2533
3189
  properties: Object.entries(value).map(
2534
- ([_key, value2]) => import_editor13.ASTFactory.createProperty({
3190
+ ([_key, value2]) => import_editor16.ASTFactory.createProperty({
2535
3191
  key: _key,
2536
- initializer: import_editor13.ASTFactory.createWrapArrayExpression({
2537
- wrapFor: import_editor13.ASTFactory.createKeyPathExpression({
3192
+ initializer: import_editor16.ASTFactory.createWrapArrayExpression({
3193
+ wrapFor: import_editor16.ASTFactory.createKeyPathExpression({
2538
3194
  keyPath: value2?.content || []
2539
3195
  })
2540
3196
  })
@@ -2544,7 +3200,7 @@ var provideBatchOutputsEffect2 = (0, import_editor13.createEffectFromVariablePro
2544
3200
  })
2545
3201
  ]
2546
3202
  });
2547
- var createBatchOutputsFormPlugin = (0, import_editor13.defineFormPluginCreator)({
3203
+ var createBatchOutputsFormPlugin = (0, import_editor16.defineFormPluginCreator)({
2548
3204
  name: "batch-outputs-plugin",
2549
3205
  onSetupFormMeta({ mergeEffect }, { outputKey }) {
2550
3206
  mergeEffect({
@@ -2552,7 +3208,7 @@ var createBatchOutputsFormPlugin = (0, import_editor13.defineFormPluginCreator)(
2552
3208
  });
2553
3209
  },
2554
3210
  onInit(ctx, { outputKey }) {
2555
- const chainTransformService = ctx.node.getService(import_editor13.ScopeChainTransformService);
3211
+ const chainTransformService = ctx.node.getService(import_editor16.ScopeChainTransformService);
2556
3212
  const batchNodeType = ctx.node.flowNodeType;
2557
3213
  const transformerId = `${batchNodeType}-outputs`;
2558
3214
  if (chainTransformService.hasTransformer(transformerId)) {
@@ -2562,21 +3218,21 @@ var createBatchOutputsFormPlugin = (0, import_editor13.defineFormPluginCreator)(
2562
3218
  transformCovers: (covers, ctx2) => {
2563
3219
  const node = ctx2.scope.meta?.node;
2564
3220
  if (node?.parent?.flowNodeType === batchNodeType) {
2565
- return [...covers, (0, import_editor13.getNodeScope)(node.parent)];
3221
+ return [...covers, (0, import_editor16.getNodeScope)(node.parent)];
2566
3222
  }
2567
3223
  return covers;
2568
3224
  },
2569
3225
  transformDeps(scopes, ctx2) {
2570
3226
  const scopeMeta = ctx2.scope.meta;
2571
- if (scopeMeta?.type === import_editor13.FlowNodeScopeType.private) {
3227
+ if (scopeMeta?.type === import_editor16.FlowNodeScopeType.private) {
2572
3228
  return scopes;
2573
3229
  }
2574
3230
  const node = scopeMeta?.node;
2575
3231
  if (node?.flowNodeType === batchNodeType) {
2576
3232
  const childBlocks = node.blocks;
2577
3233
  return [
2578
- (0, import_editor13.getNodePrivateScope)(node),
2579
- ...childBlocks.map((_childBlock) => (0, import_editor13.getNodeScope)(_childBlock))
3234
+ (0, import_editor16.getNodePrivateScope)(node),
3235
+ ...childBlocks.map((_childBlock) => (0, import_editor16.getNodeScope)(_childBlock))
2580
3236
  ];
2581
3237
  }
2582
3238
  return scopes;
@@ -2589,12 +3245,15 @@ var createBatchOutputsFormPlugin = (0, import_editor13.defineFormPluginCreator)(
2589
3245
  ArrayIcons,
2590
3246
  BatchOutputs,
2591
3247
  BatchVariableSelector,
3248
+ CodeEditor,
2592
3249
  ConditionRow,
2593
3250
  ConstantInput,
2594
3251
  DynamicValueInput,
3252
+ JsonEditorWithVariables,
2595
3253
  JsonSchemaEditor,
2596
3254
  JsonSchemaUtils,
2597
3255
  PromptEditor,
3256
+ PromptEditorWithInputs,
2598
3257
  PromptEditorWithVariables,
2599
3258
  TypeSelector,
2600
3259
  VariableSelector,