@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.
- package/dist/esm/index.js +683 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +42 -10
- package/dist/index.d.ts +42 -10
- package/dist/index.js +707 -48
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
- package/src/components/code-editor/config.json +9 -0
- package/src/components/code-editor/index.tsx +59 -0
- package/src/components/code-editor/language-features.ts +24 -0
- package/src/components/code-editor/theme/dark.ts +119 -0
- package/src/components/code-editor/theme/index.ts +12 -0
- package/src/components/code-editor/theme/light.ts +119 -0
- package/src/components/code-editor/utils.ts +20 -0
- package/src/components/index.ts +3 -0
- package/src/components/json-editor-with-variables/config.json +13 -0
- package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +173 -0
- package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +83 -0
- package/src/components/json-editor-with-variables/index.tsx +19 -0
- package/src/components/json-editor-with-variables/styles.tsx +44 -0
- package/src/components/prompt-editor/config.json +1 -1
- package/src/components/prompt-editor/index.tsx +15 -2
- package/src/components/prompt-editor/types.tsx +2 -0
- package/src/components/prompt-editor-with-inputs/config.json +13 -0
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +82 -0
- package/src/components/prompt-editor-with-inputs/index.tsx +22 -0
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +100 -0
- package/src/components/prompt-editor-with-variables/config.json +4 -3
package/dist/esm/index.js
CHANGED
|
@@ -1952,7 +1952,7 @@ function BatchOutputs(props) {
|
|
|
1952
1952
|
|
|
1953
1953
|
// src/components/prompt-editor/index.tsx
|
|
1954
1954
|
import React15 from "react";
|
|
1955
|
-
import { Renderer, EditorProvider } from "@coze-editor/editor/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,7 +2084,16 @@ 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 || {};
|
|
2088
2097
|
return /* @__PURE__ */ React15.createElement(UIContainer4, { $hasError: hasError, style }, /* @__PURE__ */ React15.createElement(EditorProvider, null, /* @__PURE__ */ React15.createElement(
|
|
2089
2098
|
Renderer,
|
|
2090
2099
|
{
|
|
@@ -2092,13 +2101,14 @@ function PromptEditor(props) {
|
|
|
2092
2101
|
defaultValue: String(value?.content),
|
|
2093
2102
|
options: {
|
|
2094
2103
|
readOnly: readonly,
|
|
2095
|
-
editable: !readonly
|
|
2104
|
+
editable: !readonly,
|
|
2105
|
+
placeholder
|
|
2096
2106
|
},
|
|
2097
2107
|
onChange: (e) => {
|
|
2098
2108
|
onChange({ type: "template", content: e.value });
|
|
2099
2109
|
}
|
|
2100
2110
|
}
|
|
2101
|
-
), /* @__PURE__ */ React15.createElement(markdown_default, null), /* @__PURE__ */ React15.createElement(language_support_default, null), /* @__PURE__ */ React15.createElement(jinja_default, null), children));
|
|
2111
|
+
), 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
2112
|
}
|
|
2103
2113
|
|
|
2104
2114
|
// src/components/prompt-editor-with-variables/index.tsx
|
|
@@ -2330,6 +2340,672 @@ function PromptEditorWithVariables(props) {
|
|
|
2330
2340
|
return /* @__PURE__ */ React18.createElement(PromptEditor, { ...props }, /* @__PURE__ */ React18.createElement(VariableTree, null), /* @__PURE__ */ React18.createElement(VariableTagInject, null));
|
|
2331
2341
|
}
|
|
2332
2342
|
|
|
2343
|
+
// src/components/prompt-editor-with-inputs/index.tsx
|
|
2344
|
+
import React21 from "react";
|
|
2345
|
+
|
|
2346
|
+
// src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx
|
|
2347
|
+
import React20, { useEffect as useEffect5, useState as useState7 } from "react";
|
|
2348
|
+
import { Popover as Popover3 } from "@douyinfe/semi-ui";
|
|
2349
|
+
import {
|
|
2350
|
+
Mention as Mention2,
|
|
2351
|
+
getCurrentMentionReplaceRange as getCurrentMentionReplaceRange2,
|
|
2352
|
+
useEditor as useEditor2,
|
|
2353
|
+
PositionMirror as PositionMirror2
|
|
2354
|
+
} from "@coze-editor/editor/react";
|
|
2355
|
+
|
|
2356
|
+
// src/components/prompt-editor-with-inputs/inputs-picker.tsx
|
|
2357
|
+
import React19, { useMemo as useMemo10 } from "react";
|
|
2358
|
+
import { last as last2 } from "lodash";
|
|
2359
|
+
import {
|
|
2360
|
+
ASTMatch as ASTMatch3,
|
|
2361
|
+
useScopeAvailable as useScopeAvailable2
|
|
2362
|
+
} from "@flowgram.ai/editor";
|
|
2363
|
+
import { Tree as Tree2 } from "@douyinfe/semi-ui";
|
|
2364
|
+
function InputsPicker({
|
|
2365
|
+
inputsValues,
|
|
2366
|
+
onSelect
|
|
2367
|
+
}) {
|
|
2368
|
+
const available = useScopeAvailable2();
|
|
2369
|
+
const getArrayDrilldown = (type, depth = 1) => {
|
|
2370
|
+
if (ASTMatch3.isArray(type.items)) {
|
|
2371
|
+
return getArrayDrilldown(type.items, depth + 1);
|
|
2372
|
+
}
|
|
2373
|
+
return { type: type.items, depth };
|
|
2374
|
+
};
|
|
2375
|
+
const renderVariable = (variable, keyPath) => {
|
|
2376
|
+
let type = variable?.type;
|
|
2377
|
+
let children;
|
|
2378
|
+
if (ASTMatch3.isObject(type)) {
|
|
2379
|
+
children = (type.properties || []).map((_property) => renderVariable(_property, [...keyPath, _property.key])).filter(Boolean);
|
|
2380
|
+
}
|
|
2381
|
+
if (ASTMatch3.isArray(type)) {
|
|
2382
|
+
const drilldown = getArrayDrilldown(type);
|
|
2383
|
+
if (ASTMatch3.isObject(drilldown.type)) {
|
|
2384
|
+
children = (drilldown.type.properties || []).map(
|
|
2385
|
+
(_property) => renderVariable(_property, [
|
|
2386
|
+
...keyPath,
|
|
2387
|
+
...new Array(drilldown.depth).fill("[0]"),
|
|
2388
|
+
_property.key
|
|
2389
|
+
])
|
|
2390
|
+
).filter(Boolean);
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
const key = keyPath.map((_key, idx) => _key === "[0]" || idx === 0 ? _key : `.${_key}`).join("");
|
|
2394
|
+
return {
|
|
2395
|
+
key,
|
|
2396
|
+
label: last2(keyPath),
|
|
2397
|
+
value: key,
|
|
2398
|
+
children
|
|
2399
|
+
};
|
|
2400
|
+
};
|
|
2401
|
+
const treeData = useMemo10(
|
|
2402
|
+
() => Object.entries(inputsValues).map(([key, value]) => {
|
|
2403
|
+
if (value.type === "ref") {
|
|
2404
|
+
const variable = available.getByKeyPath(value.content || []);
|
|
2405
|
+
if (variable) {
|
|
2406
|
+
return renderVariable(variable, [key]);
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
return {
|
|
2410
|
+
key,
|
|
2411
|
+
value: key,
|
|
2412
|
+
label: key
|
|
2413
|
+
};
|
|
2414
|
+
}),
|
|
2415
|
+
[]
|
|
2416
|
+
);
|
|
2417
|
+
return /* @__PURE__ */ React19.createElement(Tree2, { treeData, onSelect: (v) => onSelect(v) });
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
// src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx
|
|
2421
|
+
function InputsTree({ inputsValues }) {
|
|
2422
|
+
const [posKey, setPosKey] = useState7("");
|
|
2423
|
+
const [visible, setVisible] = useState7(false);
|
|
2424
|
+
const [position, setPosition] = useState7(-1);
|
|
2425
|
+
const editor = useEditor2();
|
|
2426
|
+
function insert(variablePath) {
|
|
2427
|
+
const range = getCurrentMentionReplaceRange2(editor.$view.state);
|
|
2428
|
+
if (!range) {
|
|
2429
|
+
return;
|
|
2430
|
+
}
|
|
2431
|
+
editor.replaceText({
|
|
2432
|
+
...range,
|
|
2433
|
+
text: "{{" + variablePath + "}}"
|
|
2434
|
+
});
|
|
2435
|
+
setVisible(false);
|
|
2436
|
+
}
|
|
2437
|
+
function handleOpenChange(e) {
|
|
2438
|
+
setPosition(e.state.selection.main.head);
|
|
2439
|
+
setVisible(e.value);
|
|
2440
|
+
}
|
|
2441
|
+
useEffect5(() => {
|
|
2442
|
+
if (!editor) {
|
|
2443
|
+
return;
|
|
2444
|
+
}
|
|
2445
|
+
}, [editor, visible]);
|
|
2446
|
+
return /* @__PURE__ */ React20.createElement(React20.Fragment, null, /* @__PURE__ */ React20.createElement(Mention2, { triggerCharacters: ["{", "{}", "@"], onOpenChange: handleOpenChange }), /* @__PURE__ */ React20.createElement(
|
|
2447
|
+
Popover3,
|
|
2448
|
+
{
|
|
2449
|
+
visible,
|
|
2450
|
+
trigger: "custom",
|
|
2451
|
+
position: "topLeft",
|
|
2452
|
+
rePosKey: posKey,
|
|
2453
|
+
content: /* @__PURE__ */ React20.createElement("div", { style: { width: 300 } }, /* @__PURE__ */ React20.createElement(
|
|
2454
|
+
InputsPicker,
|
|
2455
|
+
{
|
|
2456
|
+
inputsValues,
|
|
2457
|
+
onSelect: (v) => {
|
|
2458
|
+
insert(v);
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
))
|
|
2462
|
+
},
|
|
2463
|
+
/* @__PURE__ */ React20.createElement(
|
|
2464
|
+
PositionMirror2,
|
|
2465
|
+
{
|
|
2466
|
+
position,
|
|
2467
|
+
onChange: () => setPosKey(String(Math.random()))
|
|
2468
|
+
}
|
|
2469
|
+
)
|
|
2470
|
+
));
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
// src/components/prompt-editor-with-inputs/index.tsx
|
|
2474
|
+
function PromptEditorWithInputs({ inputsValues, ...restProps }) {
|
|
2475
|
+
return /* @__PURE__ */ React21.createElement(PromptEditor, { ...restProps }, /* @__PURE__ */ React21.createElement(InputsTree, { inputsValues }));
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
// src/components/code-editor/index.tsx
|
|
2479
|
+
import React22, { useRef as useRef3 } from "react";
|
|
2480
|
+
import { createRenderer, EditorProvider as EditorProvider2 } from "@coze-editor/editor/react";
|
|
2481
|
+
import preset2 from "@coze-editor/editor/preset-code";
|
|
2482
|
+
import { EditorView as EditorView4 } from "@codemirror/view";
|
|
2483
|
+
|
|
2484
|
+
// src/components/code-editor/utils.ts
|
|
2485
|
+
function getSuffixByLanguageId(languageId) {
|
|
2486
|
+
if (languageId === "python") {
|
|
2487
|
+
return ".py";
|
|
2488
|
+
}
|
|
2489
|
+
if (languageId === "typescript") {
|
|
2490
|
+
return ".ts";
|
|
2491
|
+
}
|
|
2492
|
+
if (languageId === "shell") {
|
|
2493
|
+
return ".sh";
|
|
2494
|
+
}
|
|
2495
|
+
if (languageId === "json") {
|
|
2496
|
+
return ".json";
|
|
2497
|
+
}
|
|
2498
|
+
return "";
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
// src/components/code-editor/theme/index.ts
|
|
2502
|
+
import { themes } from "@coze-editor/editor/preset-code";
|
|
2503
|
+
|
|
2504
|
+
// src/components/code-editor/theme/light.ts
|
|
2505
|
+
import { createTheme, tags as t } from "@coze-editor/editor/preset-code";
|
|
2506
|
+
var colors = {
|
|
2507
|
+
background: "#F7F7FC",
|
|
2508
|
+
// syntax
|
|
2509
|
+
comment: "#000A298A",
|
|
2510
|
+
key: "#00818C",
|
|
2511
|
+
string: "#D1009D",
|
|
2512
|
+
number: "#C74200",
|
|
2513
|
+
boolean: "#2B57D9",
|
|
2514
|
+
null: "#2B57D9",
|
|
2515
|
+
separator: "#0F1529D1"
|
|
2516
|
+
};
|
|
2517
|
+
var lightTheme = createTheme({
|
|
2518
|
+
variant: "light",
|
|
2519
|
+
settings: {
|
|
2520
|
+
background: "#fff",
|
|
2521
|
+
foreground: "#000",
|
|
2522
|
+
caret: "#000",
|
|
2523
|
+
selection: "#d9d9d9",
|
|
2524
|
+
gutterBackground: "#f0f0f0",
|
|
2525
|
+
gutterForeground: "#666",
|
|
2526
|
+
gutterBorderColor: "transparent",
|
|
2527
|
+
gutterBorderWidth: 0,
|
|
2528
|
+
lineHighlight: "#f0f0f0",
|
|
2529
|
+
bracketColors: ["#FFEF61", "#DD99FF", "#78B0FF"],
|
|
2530
|
+
tooltip: {
|
|
2531
|
+
backgroundColor: "#f0f0f0",
|
|
2532
|
+
color: "#000",
|
|
2533
|
+
border: "1px solid #ccc"
|
|
2534
|
+
},
|
|
2535
|
+
link: {
|
|
2536
|
+
color: "#007bff"
|
|
2537
|
+
},
|
|
2538
|
+
completionItemHover: {
|
|
2539
|
+
backgroundColor: "#f0f0f0"
|
|
2540
|
+
},
|
|
2541
|
+
completionItemSelected: {
|
|
2542
|
+
backgroundColor: "#e0e0e0"
|
|
2543
|
+
},
|
|
2544
|
+
completionItemIcon: {
|
|
2545
|
+
color: "#333"
|
|
2546
|
+
},
|
|
2547
|
+
completionItemLabel: {
|
|
2548
|
+
color: "#333"
|
|
2549
|
+
},
|
|
2550
|
+
completionItemInfo: {
|
|
2551
|
+
color: "#333"
|
|
2552
|
+
},
|
|
2553
|
+
completionItemDetail: {
|
|
2554
|
+
color: "#666"
|
|
2555
|
+
}
|
|
2556
|
+
},
|
|
2557
|
+
styles: [
|
|
2558
|
+
// JSON
|
|
2559
|
+
{
|
|
2560
|
+
tag: t.comment,
|
|
2561
|
+
color: colors.comment
|
|
2562
|
+
},
|
|
2563
|
+
{
|
|
2564
|
+
tag: [t.propertyName],
|
|
2565
|
+
color: colors.key
|
|
2566
|
+
},
|
|
2567
|
+
{
|
|
2568
|
+
tag: [t.string],
|
|
2569
|
+
color: colors.string
|
|
2570
|
+
},
|
|
2571
|
+
{
|
|
2572
|
+
tag: [t.number],
|
|
2573
|
+
color: colors.number
|
|
2574
|
+
},
|
|
2575
|
+
{
|
|
2576
|
+
tag: [t.bool],
|
|
2577
|
+
color: colors.boolean
|
|
2578
|
+
},
|
|
2579
|
+
{
|
|
2580
|
+
tag: [t.null],
|
|
2581
|
+
color: colors.null
|
|
2582
|
+
},
|
|
2583
|
+
{
|
|
2584
|
+
tag: [t.separator],
|
|
2585
|
+
color: colors.separator
|
|
2586
|
+
},
|
|
2587
|
+
// markdown
|
|
2588
|
+
{
|
|
2589
|
+
tag: [t.heading],
|
|
2590
|
+
color: "#3e76ef"
|
|
2591
|
+
},
|
|
2592
|
+
{
|
|
2593
|
+
tag: [t.processingInstruction],
|
|
2594
|
+
color: "#3e76ef"
|
|
2595
|
+
},
|
|
2596
|
+
// shell
|
|
2597
|
+
// curl
|
|
2598
|
+
{
|
|
2599
|
+
tag: [t.standard(t.variableName)],
|
|
2600
|
+
color: "#00804A"
|
|
2601
|
+
},
|
|
2602
|
+
// -X
|
|
2603
|
+
{
|
|
2604
|
+
tag: [t.attributeName],
|
|
2605
|
+
color: "#C74200"
|
|
2606
|
+
},
|
|
2607
|
+
// url in string (includes quotes), e.g. "https://..."
|
|
2608
|
+
{
|
|
2609
|
+
tag: [t.special(t.string)],
|
|
2610
|
+
color: "#2B57D9"
|
|
2611
|
+
}
|
|
2612
|
+
]
|
|
2613
|
+
});
|
|
2614
|
+
|
|
2615
|
+
// src/components/code-editor/theme/dark.ts
|
|
2616
|
+
import { createTheme as createTheme2, tags as t2 } from "@coze-editor/editor/preset-code";
|
|
2617
|
+
var colors2 = {
|
|
2618
|
+
background: "#151B27",
|
|
2619
|
+
// syntax
|
|
2620
|
+
comment: "#FFFFFF63",
|
|
2621
|
+
key: "#39E5D7",
|
|
2622
|
+
string: "#FF94D2",
|
|
2623
|
+
number: "#FF9933",
|
|
2624
|
+
boolean: "#78B0FF",
|
|
2625
|
+
null: "#78B0FF",
|
|
2626
|
+
separator: "#FFFFFFC9"
|
|
2627
|
+
};
|
|
2628
|
+
var darkTheme = createTheme2({
|
|
2629
|
+
variant: "dark",
|
|
2630
|
+
settings: {
|
|
2631
|
+
background: colors2.background,
|
|
2632
|
+
foreground: "#fff",
|
|
2633
|
+
caret: "#AEAFAD",
|
|
2634
|
+
selection: "#d9d9d942",
|
|
2635
|
+
gutterBackground: colors2.background,
|
|
2636
|
+
gutterForeground: "#FFFFFF63",
|
|
2637
|
+
gutterBorderColor: "transparent",
|
|
2638
|
+
gutterBorderWidth: 0,
|
|
2639
|
+
lineHighlight: "#272e3d36",
|
|
2640
|
+
bracketColors: ["#FFEF61", "#DD99FF", "#78B0FF"],
|
|
2641
|
+
tooltip: {
|
|
2642
|
+
backgroundColor: "#363D4D",
|
|
2643
|
+
color: "#fff",
|
|
2644
|
+
border: "none"
|
|
2645
|
+
},
|
|
2646
|
+
link: {
|
|
2647
|
+
color: "#4daafc"
|
|
2648
|
+
},
|
|
2649
|
+
completionItemHover: {
|
|
2650
|
+
backgroundColor: "#FFFFFF0F"
|
|
2651
|
+
},
|
|
2652
|
+
completionItemSelected: {
|
|
2653
|
+
backgroundColor: "#FFFFFF17"
|
|
2654
|
+
},
|
|
2655
|
+
completionItemIcon: {
|
|
2656
|
+
color: "#FFFFFFC9"
|
|
2657
|
+
},
|
|
2658
|
+
completionItemLabel: {
|
|
2659
|
+
color: "#FFFFFFC9"
|
|
2660
|
+
},
|
|
2661
|
+
completionItemInfo: {
|
|
2662
|
+
color: "#FFFFFFC9"
|
|
2663
|
+
},
|
|
2664
|
+
completionItemDetail: {
|
|
2665
|
+
color: "#FFFFFF63"
|
|
2666
|
+
}
|
|
2667
|
+
},
|
|
2668
|
+
styles: [
|
|
2669
|
+
// json
|
|
2670
|
+
{
|
|
2671
|
+
tag: t2.comment,
|
|
2672
|
+
color: colors2.comment
|
|
2673
|
+
},
|
|
2674
|
+
{
|
|
2675
|
+
tag: [t2.propertyName],
|
|
2676
|
+
color: colors2.key
|
|
2677
|
+
},
|
|
2678
|
+
{
|
|
2679
|
+
tag: [t2.string],
|
|
2680
|
+
color: colors2.string
|
|
2681
|
+
},
|
|
2682
|
+
{
|
|
2683
|
+
tag: [t2.number],
|
|
2684
|
+
color: colors2.number
|
|
2685
|
+
},
|
|
2686
|
+
{
|
|
2687
|
+
tag: [t2.bool],
|
|
2688
|
+
color: colors2.boolean
|
|
2689
|
+
},
|
|
2690
|
+
{
|
|
2691
|
+
tag: [t2.null],
|
|
2692
|
+
color: colors2.null
|
|
2693
|
+
},
|
|
2694
|
+
{
|
|
2695
|
+
tag: [t2.separator],
|
|
2696
|
+
color: colors2.separator
|
|
2697
|
+
},
|
|
2698
|
+
// markdown
|
|
2699
|
+
{
|
|
2700
|
+
tag: [t2.heading],
|
|
2701
|
+
color: "#6b6bff"
|
|
2702
|
+
},
|
|
2703
|
+
{
|
|
2704
|
+
tag: [t2.processingInstruction],
|
|
2705
|
+
color: "#6b6bff"
|
|
2706
|
+
},
|
|
2707
|
+
// shell
|
|
2708
|
+
// curl
|
|
2709
|
+
{
|
|
2710
|
+
tag: [t2.standard(t2.variableName)],
|
|
2711
|
+
color: "#3BEB84"
|
|
2712
|
+
},
|
|
2713
|
+
// -X
|
|
2714
|
+
{
|
|
2715
|
+
tag: [t2.attributeName],
|
|
2716
|
+
color: "#FF9933"
|
|
2717
|
+
},
|
|
2718
|
+
// url in string (includes quotes), e.g. "https://..."
|
|
2719
|
+
{
|
|
2720
|
+
tag: [t2.special(t2.string)],
|
|
2721
|
+
color: "#78B0FF"
|
|
2722
|
+
}
|
|
2723
|
+
]
|
|
2724
|
+
});
|
|
2725
|
+
|
|
2726
|
+
// src/components/code-editor/theme/index.ts
|
|
2727
|
+
themes.register("dark", darkTheme);
|
|
2728
|
+
themes.register("light", lightTheme);
|
|
2729
|
+
|
|
2730
|
+
// src/components/code-editor/language-features.ts
|
|
2731
|
+
import { languages } from "@coze-editor/editor/preset-code";
|
|
2732
|
+
import { shell } from "@coze-editor/editor/language-shell";
|
|
2733
|
+
import { python } from "@coze-editor/editor/language-python";
|
|
2734
|
+
import { json } from "@coze-editor/editor/language-json";
|
|
2735
|
+
import { mixLanguages } from "@coze-editor/editor";
|
|
2736
|
+
languages.register("python", python);
|
|
2737
|
+
languages.register("json", {
|
|
2738
|
+
// mixLanguages is used to solve the problem that interpolation also uses parentheses, which causes incorrect highlighting
|
|
2739
|
+
language: mixLanguages({
|
|
2740
|
+
outerLanguage: json.language
|
|
2741
|
+
}),
|
|
2742
|
+
languageService: json.languageService
|
|
2743
|
+
});
|
|
2744
|
+
languages.register("shell", shell);
|
|
2745
|
+
|
|
2746
|
+
// src/components/code-editor/index.tsx
|
|
2747
|
+
var OriginCodeEditor = createRenderer(preset2, [
|
|
2748
|
+
EditorView4.theme({
|
|
2749
|
+
"&.cm-focused": {
|
|
2750
|
+
outline: "none"
|
|
2751
|
+
}
|
|
2752
|
+
})
|
|
2753
|
+
]);
|
|
2754
|
+
function CodeEditor({
|
|
2755
|
+
value,
|
|
2756
|
+
onChange,
|
|
2757
|
+
languageId = "python",
|
|
2758
|
+
theme = "light",
|
|
2759
|
+
children
|
|
2760
|
+
}) {
|
|
2761
|
+
const editorRef = useRef3(null);
|
|
2762
|
+
return /* @__PURE__ */ React22.createElement(EditorProvider2, null, /* @__PURE__ */ React22.createElement(
|
|
2763
|
+
OriginCodeEditor,
|
|
2764
|
+
{
|
|
2765
|
+
defaultValue: value,
|
|
2766
|
+
options: {
|
|
2767
|
+
uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
|
|
2768
|
+
languageId,
|
|
2769
|
+
theme
|
|
2770
|
+
},
|
|
2771
|
+
didMount: (editor) => {
|
|
2772
|
+
editorRef.current = editor;
|
|
2773
|
+
},
|
|
2774
|
+
onChange: (e) => onChange?.(e.value)
|
|
2775
|
+
},
|
|
2776
|
+
children
|
|
2777
|
+
));
|
|
2778
|
+
}
|
|
2779
|
+
|
|
2780
|
+
// src/components/json-editor-with-variables/index.tsx
|
|
2781
|
+
import React25 from "react";
|
|
2782
|
+
|
|
2783
|
+
// src/components/json-editor-with-variables/extensions/variable-tree.tsx
|
|
2784
|
+
import React23, { useEffect as useEffect6, useState as useState8 } from "react";
|
|
2785
|
+
import { Popover as Popover4, Tree as Tree3 } from "@douyinfe/semi-ui";
|
|
2786
|
+
import {
|
|
2787
|
+
Mention as Mention3,
|
|
2788
|
+
getCurrentMentionReplaceRange as getCurrentMentionReplaceRange3,
|
|
2789
|
+
useEditor as useEditor3,
|
|
2790
|
+
PositionMirror as PositionMirror3
|
|
2791
|
+
} from "@coze-editor/editor/react";
|
|
2792
|
+
function VariableTree2() {
|
|
2793
|
+
const [posKey, setPosKey] = useState8("");
|
|
2794
|
+
const [visible, setVisible] = useState8(false);
|
|
2795
|
+
const [position, setPosition] = useState8(-1);
|
|
2796
|
+
const editor = useEditor3();
|
|
2797
|
+
function insert(variablePath) {
|
|
2798
|
+
const range = getCurrentMentionReplaceRange3(editor.$view.state);
|
|
2799
|
+
if (!range) {
|
|
2800
|
+
return;
|
|
2801
|
+
}
|
|
2802
|
+
editor.replaceText({
|
|
2803
|
+
...range,
|
|
2804
|
+
text: "{{" + variablePath + "}}"
|
|
2805
|
+
});
|
|
2806
|
+
setVisible(false);
|
|
2807
|
+
}
|
|
2808
|
+
function handleOpenChange(e) {
|
|
2809
|
+
setPosition(e.state.selection.main.head);
|
|
2810
|
+
setVisible(e.value);
|
|
2811
|
+
}
|
|
2812
|
+
useEffect6(() => {
|
|
2813
|
+
if (!editor) {
|
|
2814
|
+
return;
|
|
2815
|
+
}
|
|
2816
|
+
}, [editor, visible]);
|
|
2817
|
+
const treeData = useVariableTree({});
|
|
2818
|
+
return /* @__PURE__ */ React23.createElement(React23.Fragment, null, /* @__PURE__ */ React23.createElement(Mention3, { triggerCharacters: ["@"], onOpenChange: handleOpenChange }), /* @__PURE__ */ React23.createElement(
|
|
2819
|
+
Popover4,
|
|
2820
|
+
{
|
|
2821
|
+
visible,
|
|
2822
|
+
trigger: "custom",
|
|
2823
|
+
position: "topLeft",
|
|
2824
|
+
rePosKey: posKey,
|
|
2825
|
+
content: /* @__PURE__ */ React23.createElement("div", { style: { width: 300 } }, /* @__PURE__ */ React23.createElement(
|
|
2826
|
+
Tree3,
|
|
2827
|
+
{
|
|
2828
|
+
treeData,
|
|
2829
|
+
onSelect: (v) => {
|
|
2830
|
+
insert(v);
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
))
|
|
2834
|
+
},
|
|
2835
|
+
/* @__PURE__ */ React23.createElement(
|
|
2836
|
+
PositionMirror3,
|
|
2837
|
+
{
|
|
2838
|
+
position,
|
|
2839
|
+
onChange: () => setPosKey(String(Math.random()))
|
|
2840
|
+
}
|
|
2841
|
+
)
|
|
2842
|
+
));
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
// src/components/json-editor-with-variables/extensions/variable-tag.tsx
|
|
2846
|
+
import React24, { useLayoutEffect as useLayoutEffect5 } from "react";
|
|
2847
|
+
import { createRoot as createRoot2 } from "react-dom/client";
|
|
2848
|
+
import { isEqual as isEqual2, last as last3 } from "lodash";
|
|
2849
|
+
import {
|
|
2850
|
+
Disposable as Disposable2,
|
|
2851
|
+
DisposableCollection as DisposableCollection2,
|
|
2852
|
+
useCurrentScope as useCurrentScope2
|
|
2853
|
+
} from "@flowgram.ai/editor";
|
|
2854
|
+
import { Popover as Popover5 } from "@douyinfe/semi-ui";
|
|
2855
|
+
import { IconIssueStroked as IconIssueStroked3 } from "@douyinfe/semi-icons";
|
|
2856
|
+
import { useInjector as useInjector5 } from "@coze-editor/editor/react";
|
|
2857
|
+
import {
|
|
2858
|
+
Decoration as Decoration2,
|
|
2859
|
+
EditorView as EditorView5,
|
|
2860
|
+
MatchDecorator as MatchDecorator2,
|
|
2861
|
+
ViewPlugin as ViewPlugin2,
|
|
2862
|
+
WidgetType as WidgetType2
|
|
2863
|
+
} from "@codemirror/view";
|
|
2864
|
+
|
|
2865
|
+
// src/components/json-editor-with-variables/styles.tsx
|
|
2866
|
+
import styled8 from "styled-components";
|
|
2867
|
+
import { Tag as Tag3 } from "@douyinfe/semi-ui";
|
|
2868
|
+
var UIRootTitle3 = styled8.div`
|
|
2869
|
+
margin-right: 4px;
|
|
2870
|
+
min-width: 20px;
|
|
2871
|
+
overflow: hidden;
|
|
2872
|
+
text-overflow: ellipsis;
|
|
2873
|
+
white-space: nowrap;
|
|
2874
|
+
color: var(--semi-color-text-2);
|
|
2875
|
+
`;
|
|
2876
|
+
var UIVarName3 = styled8.div`
|
|
2877
|
+
overflow: hidden;
|
|
2878
|
+
text-overflow: ellipsis;
|
|
2879
|
+
white-space: nowrap;
|
|
2880
|
+
`;
|
|
2881
|
+
var UITag3 = styled8(Tag3)`
|
|
2882
|
+
display: inline-flex;
|
|
2883
|
+
align-items: center;
|
|
2884
|
+
justify-content: flex-start;
|
|
2885
|
+
max-width: 300px;
|
|
2886
|
+
|
|
2887
|
+
& .semi-tag-content-center {
|
|
2888
|
+
justify-content: flex-start;
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
&.semi-tag {
|
|
2892
|
+
margin: 0 5px;
|
|
2893
|
+
}
|
|
2894
|
+
`;
|
|
2895
|
+
var UIPopoverContent2 = styled8.div`
|
|
2896
|
+
padding: 10px;
|
|
2897
|
+
display: inline-flex;
|
|
2898
|
+
align-items: center;
|
|
2899
|
+
justify-content: flex-start;
|
|
2900
|
+
`;
|
|
2901
|
+
|
|
2902
|
+
// src/components/json-editor-with-variables/extensions/variable-tag.tsx
|
|
2903
|
+
var VariableTagWidget2 = class extends WidgetType2 {
|
|
2904
|
+
constructor({ keyPath, scope }) {
|
|
2905
|
+
super();
|
|
2906
|
+
this.toDispose = new DisposableCollection2();
|
|
2907
|
+
this.renderIcon = (icon) => {
|
|
2908
|
+
if (typeof icon === "string") {
|
|
2909
|
+
return /* @__PURE__ */ React24.createElement("img", { style: { marginRight: 8 }, width: 12, height: 12, src: icon });
|
|
2910
|
+
}
|
|
2911
|
+
return icon;
|
|
2912
|
+
};
|
|
2913
|
+
this.keyPath = keyPath;
|
|
2914
|
+
this.scope = scope;
|
|
2915
|
+
}
|
|
2916
|
+
renderVariable(v) {
|
|
2917
|
+
if (!v) {
|
|
2918
|
+
this.root.render(
|
|
2919
|
+
/* @__PURE__ */ React24.createElement(UITag3, { prefixIcon: /* @__PURE__ */ React24.createElement(IconIssueStroked3, null), color: "amber" }, "Unknown")
|
|
2920
|
+
);
|
|
2921
|
+
return;
|
|
2922
|
+
}
|
|
2923
|
+
const rootField = last3(v.parentFields);
|
|
2924
|
+
const rootTitle = /* @__PURE__ */ React24.createElement(UIRootTitle3, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
|
|
2925
|
+
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
2926
|
+
this.root.render(
|
|
2927
|
+
/* @__PURE__ */ React24.createElement(
|
|
2928
|
+
Popover5,
|
|
2929
|
+
{
|
|
2930
|
+
content: /* @__PURE__ */ React24.createElement(UIPopoverContent2, null, rootIcon, rootTitle, /* @__PURE__ */ React24.createElement(UIVarName3, null, v?.keyPath.slice(1).join(".")))
|
|
2931
|
+
},
|
|
2932
|
+
/* @__PURE__ */ React24.createElement(UITag3, { prefixIcon: rootIcon }, rootTitle, /* @__PURE__ */ React24.createElement(UIVarName3, null, v?.key))
|
|
2933
|
+
)
|
|
2934
|
+
);
|
|
2935
|
+
}
|
|
2936
|
+
toDOM(view) {
|
|
2937
|
+
const dom = document.createElement("span");
|
|
2938
|
+
this.root = createRoot2(dom);
|
|
2939
|
+
this.toDispose.push(
|
|
2940
|
+
Disposable2.create(() => {
|
|
2941
|
+
this.root.unmount();
|
|
2942
|
+
})
|
|
2943
|
+
);
|
|
2944
|
+
this.toDispose.push(
|
|
2945
|
+
this.scope.available.trackByKeyPath(
|
|
2946
|
+
this.keyPath,
|
|
2947
|
+
(v) => {
|
|
2948
|
+
this.renderVariable(v);
|
|
2949
|
+
},
|
|
2950
|
+
{ triggerOnInit: false }
|
|
2951
|
+
)
|
|
2952
|
+
);
|
|
2953
|
+
this.renderVariable(this.scope.available.getByKeyPath(this.keyPath));
|
|
2954
|
+
return dom;
|
|
2955
|
+
}
|
|
2956
|
+
eq(other) {
|
|
2957
|
+
return isEqual2(this.keyPath, other.keyPath);
|
|
2958
|
+
}
|
|
2959
|
+
ignoreEvent() {
|
|
2960
|
+
return false;
|
|
2961
|
+
}
|
|
2962
|
+
destroy(dom) {
|
|
2963
|
+
this.toDispose.dispose();
|
|
2964
|
+
}
|
|
2965
|
+
};
|
|
2966
|
+
function VariableTagInject2() {
|
|
2967
|
+
const injector = useInjector5();
|
|
2968
|
+
const scope = useCurrentScope2();
|
|
2969
|
+
useLayoutEffect5(() => {
|
|
2970
|
+
const atMatcher = new MatchDecorator2({
|
|
2971
|
+
regexp: /\{\{([^\}]+)\}\}/g,
|
|
2972
|
+
decoration: (match) => Decoration2.replace({
|
|
2973
|
+
widget: new VariableTagWidget2({
|
|
2974
|
+
keyPath: match[1]?.split(".") ?? [],
|
|
2975
|
+
scope
|
|
2976
|
+
})
|
|
2977
|
+
})
|
|
2978
|
+
});
|
|
2979
|
+
return injector.inject([
|
|
2980
|
+
ViewPlugin2.fromClass(
|
|
2981
|
+
class {
|
|
2982
|
+
constructor(view) {
|
|
2983
|
+
this.view = view;
|
|
2984
|
+
this.decorations = atMatcher.createDeco(view);
|
|
2985
|
+
}
|
|
2986
|
+
update() {
|
|
2987
|
+
this.decorations = atMatcher.createDeco(this.view);
|
|
2988
|
+
}
|
|
2989
|
+
},
|
|
2990
|
+
{
|
|
2991
|
+
decorations: (p) => p.decorations,
|
|
2992
|
+
provide(p) {
|
|
2993
|
+
return EditorView5.atomicRanges.of(
|
|
2994
|
+
(view) => view.plugin(p)?.decorations ?? Decoration2.none
|
|
2995
|
+
);
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
)
|
|
2999
|
+
]);
|
|
3000
|
+
}, [injector]);
|
|
3001
|
+
return null;
|
|
3002
|
+
}
|
|
3003
|
+
|
|
3004
|
+
// src/components/json-editor-with-variables/index.tsx
|
|
3005
|
+
function JsonEditorWithVariables(props) {
|
|
3006
|
+
return /* @__PURE__ */ React25.createElement(CodeEditor, { languageId: "json", ...props }, /* @__PURE__ */ React25.createElement(VariableTree2, null), /* @__PURE__ */ React25.createElement(VariableTagInject2, null));
|
|
3007
|
+
}
|
|
3008
|
+
|
|
2333
3009
|
// src/effects/provide-batch-input/index.ts
|
|
2334
3010
|
import {
|
|
2335
3011
|
ASTFactory as ASTFactory2,
|
|
@@ -2573,12 +3249,15 @@ export {
|
|
|
2573
3249
|
ArrayIcons,
|
|
2574
3250
|
BatchOutputs,
|
|
2575
3251
|
BatchVariableSelector,
|
|
3252
|
+
CodeEditor,
|
|
2576
3253
|
ConditionRow,
|
|
2577
3254
|
ConstantInput,
|
|
2578
3255
|
DynamicValueInput,
|
|
3256
|
+
JsonEditorWithVariables,
|
|
2579
3257
|
JsonSchemaEditor,
|
|
2580
3258
|
JsonSchemaUtils,
|
|
2581
3259
|
PromptEditor,
|
|
3260
|
+
PromptEditorWithInputs,
|
|
2582
3261
|
PromptEditorWithVariables,
|
|
2583
3262
|
TypeSelector,
|
|
2584
3263
|
VariableSelector,
|