@flowgram.ai/form-materials 0.2.16 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/materials.ts +6 -1
- package/bin/project.ts +5 -0
- package/dist/esm/index.js +462 -14
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +177 -6
- package/dist/index.d.ts +177 -6
- package/dist/index.js +482 -43
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/components/batch-outputs/config.json +12 -0
- package/src/components/batch-outputs/index.tsx +61 -0
- package/src/components/batch-outputs/styles.tsx +19 -0
- package/src/components/batch-outputs/types.ts +22 -0
- package/src/components/batch-outputs/use-list.ts +86 -0
- package/src/components/batch-variable-selector/index.tsx +5 -0
- package/src/components/condition-row/constants.ts +5 -0
- package/src/components/condition-row/hooks/useOp.tsx +5 -0
- package/src/components/condition-row/hooks/useRule.ts +5 -0
- package/src/components/condition-row/index.tsx +5 -0
- package/src/components/condition-row/styles.tsx +5 -0
- package/src/components/condition-row/types.ts +5 -0
- package/src/components/constant-input/index.tsx +5 -0
- package/src/components/constant-input/types.ts +5 -0
- package/src/components/dynamic-value-input/index.tsx +7 -0
- package/src/components/dynamic-value-input/styles.tsx +7 -0
- package/src/components/index.ts +8 -0
- package/src/components/json-schema-editor/components/blur-input.tsx +5 -0
- package/src/components/json-schema-editor/default-value.tsx +5 -0
- package/src/components/json-schema-editor/hooks.tsx +5 -0
- package/src/components/json-schema-editor/index.tsx +5 -0
- package/src/components/json-schema-editor/styles.tsx +5 -0
- package/src/components/json-schema-editor/types.ts +5 -0
- package/src/components/json-schema-editor/utils.ts +5 -0
- package/src/components/prompt-editor/config.json +9 -0
- package/src/components/prompt-editor/extensions/jinja.tsx +58 -0
- package/src/components/prompt-editor/extensions/language-support.tsx +19 -0
- package/src/components/prompt-editor/extensions/markdown.tsx +75 -0
- package/src/components/prompt-editor/index.tsx +43 -0
- package/src/components/prompt-editor/styles.tsx +18 -0
- package/src/components/prompt-editor/types.tsx +16 -0
- package/src/components/prompt-editor-with-variables/config.json +10 -0
- package/src/components/prompt-editor-with-variables/extensions/variable.tsx +85 -0
- package/src/components/prompt-editor-with-variables/index.tsx +17 -0
- package/src/components/type-selector/constants.tsx +5 -0
- package/src/components/type-selector/index.tsx +5 -0
- package/src/components/variable-selector/index.tsx +9 -2
- package/src/components/variable-selector/styles.tsx +17 -1
- package/src/components/variable-selector/use-variable-tree.tsx +8 -3
- package/src/effects/auto-rename-ref/index.ts +5 -0
- package/src/effects/index.ts +5 -0
- package/src/effects/provide-batch-input/index.ts +5 -0
- package/src/effects/provide-batch-outputs/index.ts +5 -1
- package/src/effects/provide-json-schema-outputs/index.ts +5 -0
- package/src/effects/sync-variable-title/index.ts +5 -0
- package/src/form-plugins/batch-outputs-plugin/config.json +7 -0
- package/src/form-plugins/batch-outputs-plugin/index.ts +104 -0
- package/src/form-plugins/index.ts +6 -0
- package/src/index.ts +6 -0
- package/src/typings/flow-value/index.ts +5 -0
- package/src/typings/index.ts +5 -0
- package/src/typings/json-schema/index.ts +5 -0
- package/src/utils/format-legacy-refs/index.ts +5 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/json-schema/index.ts +21 -2
package/bin/materials.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import { fileURLToPath } from 'url';
|
|
2
7
|
import path from 'path';
|
|
3
8
|
import fs from 'fs';
|
|
@@ -17,7 +22,7 @@ export interface Material {
|
|
|
17
22
|
[key: string]: any; // For other properties from config.json
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
const _types: string[] = ['components', 'effects', 'utils', 'typings'];
|
|
25
|
+
const _types: string[] = ['components', 'effects', 'utils', 'typings', 'form-plugins'];
|
|
21
26
|
|
|
22
27
|
export function listAllMaterials(): Material[] {
|
|
23
28
|
const _materials: Material[] = [];
|
package/bin/project.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { IconChevronDownStroked, IconIssueStroked } from "@douyinfe/semi-icons";
|
|
|
4
4
|
|
|
5
5
|
// src/components/variable-selector/use-variable-tree.tsx
|
|
6
6
|
import React2, { useCallback } from "react";
|
|
7
|
-
import {
|
|
7
|
+
import { ASTMatch as ASTMatch2, useAvailableVariables } from "@flowgram.ai/editor";
|
|
8
8
|
import { Icon as Icon2 } from "@douyinfe/semi-ui";
|
|
9
9
|
|
|
10
10
|
// src/components/type-selector/constants.tsx
|
|
@@ -416,7 +416,10 @@ var JsonSchemaUtils;
|
|
|
416
416
|
properties: Object.entries(jsonSchema.properties || {}).sort((a, b) => (get(a?.[1], "extra.index") || 0) - (get(b?.[1], "extra.index") || 0)).map(([key, _property]) => ({
|
|
417
417
|
key,
|
|
418
418
|
type: schemaToAST(_property),
|
|
419
|
-
meta: {
|
|
419
|
+
meta: {
|
|
420
|
+
title: _property.title,
|
|
421
|
+
description: _property.description
|
|
422
|
+
}
|
|
420
423
|
}))
|
|
421
424
|
});
|
|
422
425
|
case "array":
|
|
@@ -472,7 +475,16 @@ var JsonSchemaUtils;
|
|
|
472
475
|
return {
|
|
473
476
|
type: "object",
|
|
474
477
|
properties: drilldown ? Object.fromEntries(
|
|
475
|
-
|
|
478
|
+
typeAST.properties.map((property) => {
|
|
479
|
+
const schema = astToSchema(property.type);
|
|
480
|
+
if (property.meta?.title && schema) {
|
|
481
|
+
schema.title = property.meta.title;
|
|
482
|
+
}
|
|
483
|
+
if (property.meta?.description && schema) {
|
|
484
|
+
schema.description = property.meta.description;
|
|
485
|
+
}
|
|
486
|
+
return [property.key, schema];
|
|
487
|
+
})
|
|
476
488
|
) : {}
|
|
477
489
|
};
|
|
478
490
|
}
|
|
@@ -512,7 +524,7 @@ var JsonSchemaUtils;
|
|
|
512
524
|
// src/components/variable-selector/use-variable-tree.tsx
|
|
513
525
|
function useVariableTree(params) {
|
|
514
526
|
const { includeSchema, excludeSchema } = params;
|
|
515
|
-
const
|
|
527
|
+
const variables = useAvailableVariables();
|
|
516
528
|
const getVariableTypeIcon = useCallback((variable) => {
|
|
517
529
|
if (variable.meta?.icon) {
|
|
518
530
|
if (typeof variable.meta.icon === "string") {
|
|
@@ -563,16 +575,26 @@ function useVariableTree(params) {
|
|
|
563
575
|
rootMeta: parentFields[0]?.meta
|
|
564
576
|
};
|
|
565
577
|
};
|
|
566
|
-
return [...
|
|
578
|
+
return [...variables.slice(0).reverse()].map((_variable) => renderVariable(_variable)).filter(Boolean);
|
|
567
579
|
}
|
|
568
580
|
|
|
569
581
|
// src/components/variable-selector/styles.tsx
|
|
570
582
|
import styled from "styled-components";
|
|
571
583
|
import { Tag, TreeSelect } from "@douyinfe/semi-ui";
|
|
572
|
-
var UIRootTitle = styled.
|
|
584
|
+
var UIRootTitle = styled.div`
|
|
573
585
|
margin-right: 4px;
|
|
586
|
+
min-width: 20px;
|
|
587
|
+
overflow: hidden;
|
|
588
|
+
text-overflow: ellipsis;
|
|
589
|
+
white-space: nowrap;
|
|
574
590
|
color: var(--semi-color-text-2);
|
|
575
591
|
`;
|
|
592
|
+
var UIVarName = styled.div`
|
|
593
|
+
overflow: hidden;
|
|
594
|
+
text-overflow: ellipsis;
|
|
595
|
+
white-space: nowrap;
|
|
596
|
+
min-width: 50%;
|
|
597
|
+
`;
|
|
576
598
|
var UITag = styled(Tag)`
|
|
577
599
|
width: 100%;
|
|
578
600
|
display: flex;
|
|
@@ -673,7 +695,7 @@ var VariableSelector = ({
|
|
|
673
695
|
onClose: () => onChange(void 0)
|
|
674
696
|
},
|
|
675
697
|
/* @__PURE__ */ React3.createElement(UIRootTitle, null, _option.rootMeta?.title ? `${_option.rootMeta?.title} -` : null),
|
|
676
|
-
_option.label
|
|
698
|
+
/* @__PURE__ */ React3.createElement(UIVarName, null, _option.label)
|
|
677
699
|
);
|
|
678
700
|
},
|
|
679
701
|
showClear: false,
|
|
@@ -1123,14 +1145,14 @@ function ConstantInput(props) {
|
|
|
1123
1145
|
() => [...defaultStrategies, ...extraStrategies || []],
|
|
1124
1146
|
[extraStrategies]
|
|
1125
1147
|
);
|
|
1126
|
-
const
|
|
1148
|
+
const Renderer2 = useMemo4(() => {
|
|
1127
1149
|
const strategy = strategies.find((_strategy) => _strategy.hit(schema));
|
|
1128
1150
|
return strategy?.Renderer;
|
|
1129
1151
|
}, [strategies, schema]);
|
|
1130
|
-
if (!
|
|
1152
|
+
if (!Renderer2) {
|
|
1131
1153
|
return /* @__PURE__ */ React6.createElement(Input, { size: "small", disabled: true, placeholder: "Unsupported type" });
|
|
1132
1154
|
}
|
|
1133
|
-
return /* @__PURE__ */ React6.createElement(
|
|
1155
|
+
return /* @__PURE__ */ React6.createElement(Renderer2, { value, onChange, readonly, ...rest });
|
|
1134
1156
|
}
|
|
1135
1157
|
|
|
1136
1158
|
// src/components/json-schema-editor/default-value.tsx
|
|
@@ -1438,6 +1460,8 @@ var UIContainer2 = styled3.div`
|
|
|
1438
1460
|
`;
|
|
1439
1461
|
var UIMain = styled3.div`
|
|
1440
1462
|
flex-grow: 1;
|
|
1463
|
+
overflow: hidden;
|
|
1464
|
+
min-width: 0;
|
|
1441
1465
|
|
|
1442
1466
|
& .semi-tree-select,
|
|
1443
1467
|
& .semi-input-number,
|
|
@@ -1467,6 +1491,7 @@ function DynamicValueInput({
|
|
|
1467
1491
|
return /* @__PURE__ */ React11.createElement(
|
|
1468
1492
|
VariableSelector,
|
|
1469
1493
|
{
|
|
1494
|
+
style: { width: "100%" },
|
|
1470
1495
|
value: value?.content,
|
|
1471
1496
|
onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : void 0),
|
|
1472
1497
|
includeSchema,
|
|
@@ -1527,7 +1552,7 @@ var UIValues = styled4.div`
|
|
|
1527
1552
|
|
|
1528
1553
|
// src/components/condition-row/hooks/useRule.ts
|
|
1529
1554
|
import { useMemo as useMemo7 } from "react";
|
|
1530
|
-
import { useScopeAvailable
|
|
1555
|
+
import { useScopeAvailable } from "@flowgram.ai/editor";
|
|
1531
1556
|
|
|
1532
1557
|
// src/components/condition-row/constants.ts
|
|
1533
1558
|
var rules = {
|
|
@@ -1715,7 +1740,7 @@ function formatNewRefToLegacyRef(value) {
|
|
|
1715
1740
|
|
|
1716
1741
|
// src/components/condition-row/hooks/useRule.ts
|
|
1717
1742
|
function useRule(left) {
|
|
1718
|
-
const available =
|
|
1743
|
+
const available = useScopeAvailable();
|
|
1719
1744
|
const variable = useMemo7(() => {
|
|
1720
1745
|
if (!left) return void 0;
|
|
1721
1746
|
return available.getByKeyPath(left.content);
|
|
@@ -1795,6 +1820,350 @@ function ConditionRow({ style, value, onChange, readonly }) {
|
|
|
1795
1820
|
) : /* @__PURE__ */ React13.createElement(Input3, { size: "small", disabled: true, value: opConfig?.rightDisplay || "Empty" }))));
|
|
1796
1821
|
}
|
|
1797
1822
|
|
|
1823
|
+
// src/components/batch-outputs/index.tsx
|
|
1824
|
+
import React14 from "react";
|
|
1825
|
+
import { Button as Button4, Input as Input4 } from "@douyinfe/semi-ui";
|
|
1826
|
+
import { IconDelete, IconPlus as IconPlus2 } from "@douyinfe/semi-icons";
|
|
1827
|
+
|
|
1828
|
+
// src/components/batch-outputs/use-list.ts
|
|
1829
|
+
import { useEffect as useEffect3, useState as useState5 } from "react";
|
|
1830
|
+
import { difference } from "lodash";
|
|
1831
|
+
var _id2 = 0;
|
|
1832
|
+
function genId2() {
|
|
1833
|
+
return _id2++;
|
|
1834
|
+
}
|
|
1835
|
+
function useList({ value, onChange }) {
|
|
1836
|
+
const [list, setList] = useState5([]);
|
|
1837
|
+
useEffect3(() => {
|
|
1838
|
+
setList((_prevList) => {
|
|
1839
|
+
const newKeys = Object.keys(value || {});
|
|
1840
|
+
const oldKeys = _prevList.map((item) => item.key).filter(Boolean);
|
|
1841
|
+
const addKeys = difference(newKeys, oldKeys);
|
|
1842
|
+
return _prevList.filter((item) => !item.key || newKeys.includes(item.key)).map((item) => ({
|
|
1843
|
+
id: item.id,
|
|
1844
|
+
key: item.key,
|
|
1845
|
+
value: item.key ? value?.[item.key] : void 0
|
|
1846
|
+
})).concat(
|
|
1847
|
+
addKeys.map((_key) => ({
|
|
1848
|
+
id: genId2(),
|
|
1849
|
+
key: _key,
|
|
1850
|
+
value: value?.[_key]
|
|
1851
|
+
}))
|
|
1852
|
+
);
|
|
1853
|
+
});
|
|
1854
|
+
}, [value]);
|
|
1855
|
+
const add = () => {
|
|
1856
|
+
setList((prevList) => [
|
|
1857
|
+
...prevList,
|
|
1858
|
+
{
|
|
1859
|
+
id: genId2()
|
|
1860
|
+
}
|
|
1861
|
+
]);
|
|
1862
|
+
};
|
|
1863
|
+
const update = (item) => {
|
|
1864
|
+
setList((prevList) => {
|
|
1865
|
+
const nextList = prevList.map((_item) => {
|
|
1866
|
+
if (_item.id === item.id) {
|
|
1867
|
+
return item;
|
|
1868
|
+
}
|
|
1869
|
+
return _item;
|
|
1870
|
+
});
|
|
1871
|
+
onChange(
|
|
1872
|
+
Object.fromEntries(
|
|
1873
|
+
nextList.filter((item2) => item2.key).map((item2) => [item2.key, item2.value])
|
|
1874
|
+
)
|
|
1875
|
+
);
|
|
1876
|
+
return nextList;
|
|
1877
|
+
});
|
|
1878
|
+
};
|
|
1879
|
+
const remove = (itemId) => {
|
|
1880
|
+
setList((prevList) => {
|
|
1881
|
+
const nextList = prevList.filter((_item) => _item.id !== itemId);
|
|
1882
|
+
onChange(
|
|
1883
|
+
Object.fromEntries(
|
|
1884
|
+
nextList.filter((item) => item.key).map((item) => [item.key, item.value])
|
|
1885
|
+
)
|
|
1886
|
+
);
|
|
1887
|
+
return nextList;
|
|
1888
|
+
});
|
|
1889
|
+
};
|
|
1890
|
+
return { list, add, update, remove };
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
// src/components/batch-outputs/styles.tsx
|
|
1894
|
+
import styled5 from "styled-components";
|
|
1895
|
+
var UIRows = styled5.div`
|
|
1896
|
+
display: flex;
|
|
1897
|
+
flex-direction: column;
|
|
1898
|
+
gap: 10px;
|
|
1899
|
+
margin-bottom: 10px;
|
|
1900
|
+
`;
|
|
1901
|
+
var UIRow2 = styled5.div`
|
|
1902
|
+
display: flex;
|
|
1903
|
+
align-items: center;
|
|
1904
|
+
gap: 5px;
|
|
1905
|
+
`;
|
|
1906
|
+
|
|
1907
|
+
// src/components/batch-outputs/index.tsx
|
|
1908
|
+
function BatchOutputs(props) {
|
|
1909
|
+
const { readonly, style } = props;
|
|
1910
|
+
const { list, add, update, remove } = useList(props);
|
|
1911
|
+
return /* @__PURE__ */ React14.createElement("div", null, /* @__PURE__ */ React14.createElement(UIRows, { style }, list.map((item) => /* @__PURE__ */ React14.createElement(UIRow2, { key: item.id }, /* @__PURE__ */ React14.createElement(
|
|
1912
|
+
Input4,
|
|
1913
|
+
{
|
|
1914
|
+
style: { width: 100 },
|
|
1915
|
+
disabled: readonly,
|
|
1916
|
+
size: "small",
|
|
1917
|
+
value: item.key,
|
|
1918
|
+
onChange: (v) => update({ ...item, key: v })
|
|
1919
|
+
}
|
|
1920
|
+
), /* @__PURE__ */ React14.createElement(
|
|
1921
|
+
VariableSelector,
|
|
1922
|
+
{
|
|
1923
|
+
style: { flexGrow: 1 },
|
|
1924
|
+
readonly,
|
|
1925
|
+
value: item.value?.content,
|
|
1926
|
+
onChange: (v) => update({
|
|
1927
|
+
...item,
|
|
1928
|
+
value: {
|
|
1929
|
+
type: "ref",
|
|
1930
|
+
content: v
|
|
1931
|
+
}
|
|
1932
|
+
})
|
|
1933
|
+
}
|
|
1934
|
+
), /* @__PURE__ */ React14.createElement(
|
|
1935
|
+
Button4,
|
|
1936
|
+
{
|
|
1937
|
+
disabled: readonly,
|
|
1938
|
+
icon: /* @__PURE__ */ React14.createElement(IconDelete, null),
|
|
1939
|
+
size: "small",
|
|
1940
|
+
onClick: () => remove(item.id)
|
|
1941
|
+
}
|
|
1942
|
+
)))), /* @__PURE__ */ React14.createElement(Button4, { disabled: readonly, icon: /* @__PURE__ */ React14.createElement(IconPlus2, null), size: "small", onClick: add }, "Add"));
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
// src/components/prompt-editor/index.tsx
|
|
1946
|
+
import React15 from "react";
|
|
1947
|
+
import { Renderer, EditorProvider } from "@coze-editor/editor/react";
|
|
1948
|
+
import preset from "@coze-editor/editor/preset-prompt";
|
|
1949
|
+
|
|
1950
|
+
// src/components/prompt-editor/styles.tsx
|
|
1951
|
+
import styled6, { css as css2 } from "styled-components";
|
|
1952
|
+
var UIContainer4 = styled6.div`
|
|
1953
|
+
background-color: var(--semi-color-fill-0);
|
|
1954
|
+
padding-left: 10px;
|
|
1955
|
+
padding-right: 6px;
|
|
1956
|
+
|
|
1957
|
+
${({ $hasError }) => $hasError && css2`
|
|
1958
|
+
border: 1px solid var(--semi-color-danger-6);
|
|
1959
|
+
`}
|
|
1960
|
+
`;
|
|
1961
|
+
|
|
1962
|
+
// src/components/prompt-editor/extensions/markdown.tsx
|
|
1963
|
+
import { useLayoutEffect } from "react";
|
|
1964
|
+
import { useInjector } from "@coze-editor/editor/react";
|
|
1965
|
+
import { astDecorator } from "@coze-editor/editor";
|
|
1966
|
+
import { EditorView } from "@codemirror/view";
|
|
1967
|
+
function MarkdownHighlight() {
|
|
1968
|
+
const injector = useInjector();
|
|
1969
|
+
useLayoutEffect(
|
|
1970
|
+
() => injector.inject([
|
|
1971
|
+
astDecorator.whole.of((cursor) => {
|
|
1972
|
+
if (cursor.name.startsWith("ATXHeading")) {
|
|
1973
|
+
return {
|
|
1974
|
+
type: "className",
|
|
1975
|
+
className: "heading"
|
|
1976
|
+
};
|
|
1977
|
+
}
|
|
1978
|
+
if (cursor.name === "Emphasis") {
|
|
1979
|
+
return {
|
|
1980
|
+
type: "className",
|
|
1981
|
+
className: "emphasis"
|
|
1982
|
+
};
|
|
1983
|
+
}
|
|
1984
|
+
if (cursor.name === "StrongEmphasis") {
|
|
1985
|
+
return {
|
|
1986
|
+
type: "className",
|
|
1987
|
+
className: "strong-emphasis"
|
|
1988
|
+
};
|
|
1989
|
+
}
|
|
1990
|
+
if (cursor.name === "ListMark" || cursor.name === "QuoteMark") {
|
|
1991
|
+
return {
|
|
1992
|
+
type: "className",
|
|
1993
|
+
className: "mark"
|
|
1994
|
+
};
|
|
1995
|
+
}
|
|
1996
|
+
}),
|
|
1997
|
+
EditorView.theme({
|
|
1998
|
+
".heading": {
|
|
1999
|
+
color: "#00818C",
|
|
2000
|
+
fontWeight: "bold"
|
|
2001
|
+
},
|
|
2002
|
+
".emphasis": {
|
|
2003
|
+
fontStyle: "italic"
|
|
2004
|
+
},
|
|
2005
|
+
".strong-emphasis": {
|
|
2006
|
+
fontWeight: "bold"
|
|
2007
|
+
},
|
|
2008
|
+
".mark": {
|
|
2009
|
+
color: "#4E40E5"
|
|
2010
|
+
}
|
|
2011
|
+
})
|
|
2012
|
+
]),
|
|
2013
|
+
[injector]
|
|
2014
|
+
);
|
|
2015
|
+
return null;
|
|
2016
|
+
}
|
|
2017
|
+
var markdown_default = MarkdownHighlight;
|
|
2018
|
+
|
|
2019
|
+
// src/components/prompt-editor/extensions/language-support.tsx
|
|
2020
|
+
import { useLayoutEffect as useLayoutEffect2 } from "react";
|
|
2021
|
+
import { useInjector as useInjector2 } from "@coze-editor/editor/react";
|
|
2022
|
+
import { languageSupport } from "@coze-editor/editor/preset-prompt";
|
|
2023
|
+
function LanguageSupport() {
|
|
2024
|
+
const injector = useInjector2();
|
|
2025
|
+
useLayoutEffect2(() => injector.inject([languageSupport]), [injector]);
|
|
2026
|
+
return null;
|
|
2027
|
+
}
|
|
2028
|
+
var language_support_default = LanguageSupport;
|
|
2029
|
+
|
|
2030
|
+
// src/components/prompt-editor/extensions/jinja.tsx
|
|
2031
|
+
import { useLayoutEffect as useLayoutEffect3 } from "react";
|
|
2032
|
+
import { useInjector as useInjector3 } from "@coze-editor/editor/react";
|
|
2033
|
+
import { astDecorator as astDecorator2 } from "@coze-editor/editor";
|
|
2034
|
+
import { EditorView as EditorView2 } from "@codemirror/view";
|
|
2035
|
+
function JinjaHighlight() {
|
|
2036
|
+
const injector = useInjector3();
|
|
2037
|
+
useLayoutEffect3(
|
|
2038
|
+
() => injector.inject([
|
|
2039
|
+
astDecorator2.whole.of((cursor) => {
|
|
2040
|
+
if (cursor.name === "JinjaStatementStart" || cursor.name === "JinjaStatementEnd") {
|
|
2041
|
+
return {
|
|
2042
|
+
type: "className",
|
|
2043
|
+
className: "jinja-statement-bracket"
|
|
2044
|
+
};
|
|
2045
|
+
}
|
|
2046
|
+
if (cursor.name === "JinjaComment") {
|
|
2047
|
+
return {
|
|
2048
|
+
type: "className",
|
|
2049
|
+
className: "jinja-comment"
|
|
2050
|
+
};
|
|
2051
|
+
}
|
|
2052
|
+
if (cursor.name === "JinjaExpression") {
|
|
2053
|
+
return {
|
|
2054
|
+
type: "className",
|
|
2055
|
+
className: "jinja-expression"
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
}),
|
|
2059
|
+
EditorView2.theme({
|
|
2060
|
+
".jinja-statement-bracket": {
|
|
2061
|
+
color: "#D1009D"
|
|
2062
|
+
},
|
|
2063
|
+
".jinja-comment": {
|
|
2064
|
+
color: "#0607094D"
|
|
2065
|
+
},
|
|
2066
|
+
".jinja-expression": {
|
|
2067
|
+
color: "#4E40E5"
|
|
2068
|
+
}
|
|
2069
|
+
})
|
|
2070
|
+
]),
|
|
2071
|
+
[injector]
|
|
2072
|
+
);
|
|
2073
|
+
return null;
|
|
2074
|
+
}
|
|
2075
|
+
var jinja_default = JinjaHighlight;
|
|
2076
|
+
|
|
2077
|
+
// src/components/prompt-editor/index.tsx
|
|
2078
|
+
function PromptEditor(props) {
|
|
2079
|
+
const { value, onChange, readonly, style, hasError, children } = props || {};
|
|
2080
|
+
return /* @__PURE__ */ React15.createElement(UIContainer4, { $hasError: hasError, style }, /* @__PURE__ */ React15.createElement(EditorProvider, null, /* @__PURE__ */ React15.createElement(
|
|
2081
|
+
Renderer,
|
|
2082
|
+
{
|
|
2083
|
+
plugins: preset,
|
|
2084
|
+
defaultValue: String(value?.content),
|
|
2085
|
+
options: {
|
|
2086
|
+
readOnly: readonly,
|
|
2087
|
+
editable: !readonly
|
|
2088
|
+
},
|
|
2089
|
+
onChange: (e) => {
|
|
2090
|
+
onChange({ type: "template", content: e.value });
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
), /* @__PURE__ */ React15.createElement(markdown_default, null), /* @__PURE__ */ React15.createElement(language_support_default, null), /* @__PURE__ */ React15.createElement(jinja_default, null), children));
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
// src/components/prompt-editor-with-variables/index.tsx
|
|
2097
|
+
import React17 from "react";
|
|
2098
|
+
|
|
2099
|
+
// src/components/prompt-editor-with-variables/extensions/variable.tsx
|
|
2100
|
+
import React16, { useEffect as useEffect4, useState as useState6 } from "react";
|
|
2101
|
+
import { Popover, Tree } from "@douyinfe/semi-ui";
|
|
2102
|
+
import {
|
|
2103
|
+
Mention,
|
|
2104
|
+
getCurrentMentionReplaceRange,
|
|
2105
|
+
useEditor,
|
|
2106
|
+
PositionMirror
|
|
2107
|
+
} from "@coze-editor/editor/react";
|
|
2108
|
+
function Variable() {
|
|
2109
|
+
const [posKey, setPosKey] = useState6("");
|
|
2110
|
+
const [visible, setVisible] = useState6(false);
|
|
2111
|
+
const [position, setPosition] = useState6(-1);
|
|
2112
|
+
const editor = useEditor();
|
|
2113
|
+
function insert(variablePath) {
|
|
2114
|
+
const range = getCurrentMentionReplaceRange(editor.$view.state);
|
|
2115
|
+
if (!range) {
|
|
2116
|
+
return;
|
|
2117
|
+
}
|
|
2118
|
+
editor.replaceText({
|
|
2119
|
+
...range,
|
|
2120
|
+
text: "{{" + variablePath + "}}"
|
|
2121
|
+
});
|
|
2122
|
+
setVisible(false);
|
|
2123
|
+
}
|
|
2124
|
+
function handleOpenChange(e) {
|
|
2125
|
+
setPosition(e.state.selection.main.head);
|
|
2126
|
+
setVisible(e.value);
|
|
2127
|
+
}
|
|
2128
|
+
useEffect4(() => {
|
|
2129
|
+
if (!editor) {
|
|
2130
|
+
return;
|
|
2131
|
+
}
|
|
2132
|
+
}, [editor, visible]);
|
|
2133
|
+
const treeData = useVariableTree({});
|
|
2134
|
+
return /* @__PURE__ */ React16.createElement(React16.Fragment, null, /* @__PURE__ */ React16.createElement(Mention, { triggerCharacters: ["{", "{}"], onOpenChange: handleOpenChange }), /* @__PURE__ */ React16.createElement(
|
|
2135
|
+
Popover,
|
|
2136
|
+
{
|
|
2137
|
+
visible,
|
|
2138
|
+
trigger: "custom",
|
|
2139
|
+
position: "topLeft",
|
|
2140
|
+
rePosKey: posKey,
|
|
2141
|
+
content: /* @__PURE__ */ React16.createElement("div", { style: { width: 300 } }, /* @__PURE__ */ React16.createElement(
|
|
2142
|
+
Tree,
|
|
2143
|
+
{
|
|
2144
|
+
treeData,
|
|
2145
|
+
onSelect: (v) => {
|
|
2146
|
+
insert(v);
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
))
|
|
2150
|
+
},
|
|
2151
|
+
/* @__PURE__ */ React16.createElement(
|
|
2152
|
+
PositionMirror,
|
|
2153
|
+
{
|
|
2154
|
+
position,
|
|
2155
|
+
onChange: () => setPosKey(String(Math.random()))
|
|
2156
|
+
}
|
|
2157
|
+
)
|
|
2158
|
+
));
|
|
2159
|
+
}
|
|
2160
|
+
var variable_default = Variable;
|
|
2161
|
+
|
|
2162
|
+
// src/components/prompt-editor-with-variables/index.tsx
|
|
2163
|
+
function PromptEditorWithVariables(props) {
|
|
2164
|
+
return /* @__PURE__ */ React17.createElement(PromptEditor, { ...props }, /* @__PURE__ */ React17.createElement(variable_default, null));
|
|
2165
|
+
}
|
|
2166
|
+
|
|
1798
2167
|
// src/effects/provide-batch-input/index.ts
|
|
1799
2168
|
import {
|
|
1800
2169
|
ASTFactory as ASTFactory2,
|
|
@@ -1837,7 +2206,6 @@ import {
|
|
|
1837
2206
|
getNodeForm as getNodeForm2
|
|
1838
2207
|
} from "@flowgram.ai/editor";
|
|
1839
2208
|
var provideBatchOutputsEffect = createEffectFromVariableProvider2({
|
|
1840
|
-
private: true,
|
|
1841
2209
|
parse: (value, ctx) => [
|
|
1842
2210
|
ASTFactory3.createVariableDeclaration({
|
|
1843
2211
|
key: `${ctx.node.id}`,
|
|
@@ -1960,18 +2328,97 @@ var syncVariableTitle = [
|
|
|
1960
2328
|
}
|
|
1961
2329
|
}
|
|
1962
2330
|
];
|
|
2331
|
+
|
|
2332
|
+
// src/form-plugins/batch-outputs-plugin/index.ts
|
|
2333
|
+
import {
|
|
2334
|
+
ASTFactory as ASTFactory5,
|
|
2335
|
+
createEffectFromVariableProvider as createEffectFromVariableProvider4,
|
|
2336
|
+
defineFormPluginCreator,
|
|
2337
|
+
getNodeForm as getNodeForm4,
|
|
2338
|
+
getNodePrivateScope,
|
|
2339
|
+
getNodeScope,
|
|
2340
|
+
ScopeChainTransformService,
|
|
2341
|
+
FlowNodeScopeType
|
|
2342
|
+
} from "@flowgram.ai/editor";
|
|
2343
|
+
var provideBatchOutputsEffect2 = createEffectFromVariableProvider4({
|
|
2344
|
+
parse: (value, ctx) => [
|
|
2345
|
+
ASTFactory5.createVariableDeclaration({
|
|
2346
|
+
key: `${ctx.node.id}`,
|
|
2347
|
+
meta: {
|
|
2348
|
+
title: getNodeForm4(ctx.node)?.getValueIn("title"),
|
|
2349
|
+
icon: ctx.node.getNodeRegistry().info?.icon
|
|
2350
|
+
},
|
|
2351
|
+
type: ASTFactory5.createObject({
|
|
2352
|
+
properties: Object.entries(value).map(
|
|
2353
|
+
([_key, value2]) => ASTFactory5.createProperty({
|
|
2354
|
+
key: _key,
|
|
2355
|
+
initializer: ASTFactory5.createWrapArrayExpression({
|
|
2356
|
+
wrapFor: ASTFactory5.createKeyPathExpression({
|
|
2357
|
+
keyPath: value2?.content || []
|
|
2358
|
+
})
|
|
2359
|
+
})
|
|
2360
|
+
})
|
|
2361
|
+
)
|
|
2362
|
+
})
|
|
2363
|
+
})
|
|
2364
|
+
]
|
|
2365
|
+
});
|
|
2366
|
+
var createBatchOutputsFormPlugin = defineFormPluginCreator({
|
|
2367
|
+
name: "batch-outputs-plugin",
|
|
2368
|
+
onSetupFormMeta({ mergeEffect }, { outputKey }) {
|
|
2369
|
+
mergeEffect({
|
|
2370
|
+
[outputKey]: provideBatchOutputsEffect2
|
|
2371
|
+
});
|
|
2372
|
+
},
|
|
2373
|
+
onInit(ctx, { outputKey }) {
|
|
2374
|
+
const chainTransformService = ctx.node.getService(ScopeChainTransformService);
|
|
2375
|
+
const batchNodeType = ctx.node.flowNodeType;
|
|
2376
|
+
const transformerId = `${batchNodeType}-outputs`;
|
|
2377
|
+
if (chainTransformService.hasTransformer(transformerId)) {
|
|
2378
|
+
return;
|
|
2379
|
+
}
|
|
2380
|
+
chainTransformService.registerTransformer(transformerId, {
|
|
2381
|
+
transformCovers: (covers, ctx2) => {
|
|
2382
|
+
const node = ctx2.scope.meta?.node;
|
|
2383
|
+
if (node?.parent?.flowNodeType === batchNodeType) {
|
|
2384
|
+
return [...covers, getNodeScope(node.parent)];
|
|
2385
|
+
}
|
|
2386
|
+
return covers;
|
|
2387
|
+
},
|
|
2388
|
+
transformDeps(scopes, ctx2) {
|
|
2389
|
+
const scopeMeta = ctx2.scope.meta;
|
|
2390
|
+
if (scopeMeta?.type === FlowNodeScopeType.private) {
|
|
2391
|
+
return scopes;
|
|
2392
|
+
}
|
|
2393
|
+
const node = scopeMeta?.node;
|
|
2394
|
+
if (node?.flowNodeType === batchNodeType) {
|
|
2395
|
+
const childBlocks = node.blocks;
|
|
2396
|
+
return [
|
|
2397
|
+
getNodePrivateScope(node),
|
|
2398
|
+
...childBlocks.map((_childBlock) => getNodeScope(_childBlock))
|
|
2399
|
+
];
|
|
2400
|
+
}
|
|
2401
|
+
return scopes;
|
|
2402
|
+
}
|
|
2403
|
+
});
|
|
2404
|
+
}
|
|
2405
|
+
});
|
|
1963
2406
|
export {
|
|
1964
2407
|
ArrayIcons,
|
|
2408
|
+
BatchOutputs,
|
|
1965
2409
|
BatchVariableSelector,
|
|
1966
2410
|
ConditionRow,
|
|
1967
2411
|
ConstantInput,
|
|
1968
2412
|
DynamicValueInput,
|
|
1969
2413
|
JsonSchemaEditor,
|
|
1970
2414
|
JsonSchemaUtils,
|
|
2415
|
+
PromptEditor,
|
|
2416
|
+
PromptEditorWithVariables,
|
|
1971
2417
|
TypeSelector,
|
|
1972
2418
|
VariableSelector,
|
|
1973
2419
|
VariableTypeIcons,
|
|
1974
2420
|
autoRenameRefEffect,
|
|
2421
|
+
createBatchOutputsFormPlugin,
|
|
1975
2422
|
formatLegacyRefOnInit,
|
|
1976
2423
|
formatLegacyRefOnSubmit,
|
|
1977
2424
|
formatLegacyRefToNewRef,
|
|
@@ -1984,6 +2431,7 @@ export {
|
|
|
1984
2431
|
provideBatchInputEffect,
|
|
1985
2432
|
provideBatchOutputsEffect,
|
|
1986
2433
|
provideJsonSchemaOutputs,
|
|
1987
|
-
syncVariableTitle
|
|
2434
|
+
syncVariableTitle,
|
|
2435
|
+
useVariableTree
|
|
1988
2436
|
};
|
|
1989
2437
|
//# sourceMappingURL=index.js.map
|