@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/dist/index.js
CHANGED
|
@@ -31,16 +31,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
ArrayIcons: () => ArrayIcons,
|
|
34
|
+
BatchOutputs: () => BatchOutputs,
|
|
34
35
|
BatchVariableSelector: () => BatchVariableSelector,
|
|
35
36
|
ConditionRow: () => ConditionRow,
|
|
36
37
|
ConstantInput: () => ConstantInput,
|
|
37
38
|
DynamicValueInput: () => DynamicValueInput,
|
|
38
39
|
JsonSchemaEditor: () => JsonSchemaEditor,
|
|
39
40
|
JsonSchemaUtils: () => JsonSchemaUtils,
|
|
41
|
+
PromptEditor: () => PromptEditor,
|
|
42
|
+
PromptEditorWithVariables: () => PromptEditorWithVariables,
|
|
40
43
|
TypeSelector: () => TypeSelector,
|
|
41
44
|
VariableSelector: () => VariableSelector,
|
|
42
45
|
VariableTypeIcons: () => VariableTypeIcons,
|
|
43
46
|
autoRenameRefEffect: () => autoRenameRefEffect,
|
|
47
|
+
createBatchOutputsFormPlugin: () => createBatchOutputsFormPlugin,
|
|
44
48
|
formatLegacyRefOnInit: () => formatLegacyRefOnInit,
|
|
45
49
|
formatLegacyRefOnSubmit: () => formatLegacyRefOnSubmit,
|
|
46
50
|
formatLegacyRefToNewRef: () => formatLegacyRefToNewRef,
|
|
@@ -53,7 +57,8 @@ __export(src_exports, {
|
|
|
53
57
|
provideBatchInputEffect: () => provideBatchInputEffect,
|
|
54
58
|
provideBatchOutputsEffect: () => provideBatchOutputsEffect,
|
|
55
59
|
provideJsonSchemaOutputs: () => provideJsonSchemaOutputs,
|
|
56
|
-
syncVariableTitle: () => syncVariableTitle
|
|
60
|
+
syncVariableTitle: () => syncVariableTitle,
|
|
61
|
+
useVariableTree: () => useVariableTree
|
|
57
62
|
});
|
|
58
63
|
module.exports = __toCommonJS(src_exports);
|
|
59
64
|
|
|
@@ -475,7 +480,10 @@ var JsonSchemaUtils;
|
|
|
475
480
|
properties: Object.entries(jsonSchema.properties || {}).sort((a, b) => ((0, import_lodash.get)(a?.[1], "extra.index") || 0) - ((0, import_lodash.get)(b?.[1], "extra.index") || 0)).map(([key, _property]) => ({
|
|
476
481
|
key,
|
|
477
482
|
type: schemaToAST(_property),
|
|
478
|
-
meta: {
|
|
483
|
+
meta: {
|
|
484
|
+
title: _property.title,
|
|
485
|
+
description: _property.description
|
|
486
|
+
}
|
|
479
487
|
}))
|
|
480
488
|
});
|
|
481
489
|
case "array":
|
|
@@ -531,7 +539,16 @@ var JsonSchemaUtils;
|
|
|
531
539
|
return {
|
|
532
540
|
type: "object",
|
|
533
541
|
properties: drilldown ? Object.fromEntries(
|
|
534
|
-
|
|
542
|
+
typeAST.properties.map((property) => {
|
|
543
|
+
const schema = astToSchema(property.type);
|
|
544
|
+
if (property.meta?.title && schema) {
|
|
545
|
+
schema.title = property.meta.title;
|
|
546
|
+
}
|
|
547
|
+
if (property.meta?.description && schema) {
|
|
548
|
+
schema.description = property.meta.description;
|
|
549
|
+
}
|
|
550
|
+
return [property.key, schema];
|
|
551
|
+
})
|
|
535
552
|
) : {}
|
|
536
553
|
};
|
|
537
554
|
}
|
|
@@ -571,7 +588,7 @@ var JsonSchemaUtils;
|
|
|
571
588
|
// src/components/variable-selector/use-variable-tree.tsx
|
|
572
589
|
function useVariableTree(params) {
|
|
573
590
|
const { includeSchema, excludeSchema } = params;
|
|
574
|
-
const
|
|
591
|
+
const variables = (0, import_editor2.useAvailableVariables)();
|
|
575
592
|
const getVariableTypeIcon = (0, import_react2.useCallback)((variable) => {
|
|
576
593
|
if (variable.meta?.icon) {
|
|
577
594
|
if (typeof variable.meta.icon === "string") {
|
|
@@ -622,16 +639,26 @@ function useVariableTree(params) {
|
|
|
622
639
|
rootMeta: parentFields[0]?.meta
|
|
623
640
|
};
|
|
624
641
|
};
|
|
625
|
-
return [...
|
|
642
|
+
return [...variables.slice(0).reverse()].map((_variable) => renderVariable(_variable)).filter(Boolean);
|
|
626
643
|
}
|
|
627
644
|
|
|
628
645
|
// src/components/variable-selector/styles.tsx
|
|
629
646
|
var import_styled_components = __toESM(require("styled-components"));
|
|
630
647
|
var import_semi_ui2 = require("@douyinfe/semi-ui");
|
|
631
|
-
var UIRootTitle = import_styled_components.default.
|
|
648
|
+
var UIRootTitle = import_styled_components.default.div`
|
|
632
649
|
margin-right: 4px;
|
|
650
|
+
min-width: 20px;
|
|
651
|
+
overflow: hidden;
|
|
652
|
+
text-overflow: ellipsis;
|
|
653
|
+
white-space: nowrap;
|
|
633
654
|
color: var(--semi-color-text-2);
|
|
634
655
|
`;
|
|
656
|
+
var UIVarName = import_styled_components.default.div`
|
|
657
|
+
overflow: hidden;
|
|
658
|
+
text-overflow: ellipsis;
|
|
659
|
+
white-space: nowrap;
|
|
660
|
+
min-width: 50%;
|
|
661
|
+
`;
|
|
635
662
|
var UITag = (0, import_styled_components.default)(import_semi_ui2.Tag)`
|
|
636
663
|
width: 100%;
|
|
637
664
|
display: flex;
|
|
@@ -732,7 +759,7 @@ var VariableSelector = ({
|
|
|
732
759
|
onClose: () => onChange(void 0)
|
|
733
760
|
},
|
|
734
761
|
/* @__PURE__ */ import_react3.default.createElement(UIRootTitle, null, _option.rootMeta?.title ? `${_option.rootMeta?.title} -` : null),
|
|
735
|
-
_option.label
|
|
762
|
+
/* @__PURE__ */ import_react3.default.createElement(UIVarName, null, _option.label)
|
|
736
763
|
);
|
|
737
764
|
},
|
|
738
765
|
showClear: false,
|
|
@@ -1175,14 +1202,14 @@ function ConstantInput(props) {
|
|
|
1175
1202
|
() => [...defaultStrategies, ...extraStrategies || []],
|
|
1176
1203
|
[extraStrategies]
|
|
1177
1204
|
);
|
|
1178
|
-
const
|
|
1205
|
+
const Renderer2 = (0, import_react7.useMemo)(() => {
|
|
1179
1206
|
const strategy = strategies.find((_strategy) => _strategy.hit(schema));
|
|
1180
1207
|
return strategy?.Renderer;
|
|
1181
1208
|
}, [strategies, schema]);
|
|
1182
|
-
if (!
|
|
1209
|
+
if (!Renderer2) {
|
|
1183
1210
|
return /* @__PURE__ */ import_react7.default.createElement(import_semi_ui4.Input, { size: "small", disabled: true, placeholder: "Unsupported type" });
|
|
1184
1211
|
}
|
|
1185
|
-
return /* @__PURE__ */ import_react7.default.createElement(
|
|
1212
|
+
return /* @__PURE__ */ import_react7.default.createElement(Renderer2, { value, onChange, readonly, ...rest });
|
|
1186
1213
|
}
|
|
1187
1214
|
|
|
1188
1215
|
// src/components/json-schema-editor/default-value.tsx
|
|
@@ -1490,6 +1517,8 @@ var UIContainer2 = import_styled_components3.default.div`
|
|
|
1490
1517
|
`;
|
|
1491
1518
|
var UIMain = import_styled_components3.default.div`
|
|
1492
1519
|
flex-grow: 1;
|
|
1520
|
+
overflow: hidden;
|
|
1521
|
+
min-width: 0;
|
|
1493
1522
|
|
|
1494
1523
|
& .semi-tree-select,
|
|
1495
1524
|
& .semi-input-number,
|
|
@@ -1519,6 +1548,7 @@ function DynamicValueInput({
|
|
|
1519
1548
|
return /* @__PURE__ */ import_react12.default.createElement(
|
|
1520
1549
|
VariableSelector,
|
|
1521
1550
|
{
|
|
1551
|
+
style: { width: "100%" },
|
|
1522
1552
|
value: value?.content,
|
|
1523
1553
|
onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : void 0),
|
|
1524
1554
|
includeSchema,
|
|
@@ -1847,30 +1877,369 @@ function ConditionRow({ style, value, onChange, readonly }) {
|
|
|
1847
1877
|
) : /* @__PURE__ */ import_react15.default.createElement(import_semi_ui9.Input, { size: "small", disabled: true, value: opConfig?.rightDisplay || "Empty" }))));
|
|
1848
1878
|
}
|
|
1849
1879
|
|
|
1880
|
+
// src/components/batch-outputs/index.tsx
|
|
1881
|
+
var import_react17 = __toESM(require("react"));
|
|
1882
|
+
var import_semi_ui10 = require("@douyinfe/semi-ui");
|
|
1883
|
+
var import_semi_icons8 = require("@douyinfe/semi-icons");
|
|
1884
|
+
|
|
1885
|
+
// src/components/batch-outputs/use-list.ts
|
|
1886
|
+
var import_react16 = require("react");
|
|
1887
|
+
var import_lodash3 = require("lodash");
|
|
1888
|
+
var _id2 = 0;
|
|
1889
|
+
function genId2() {
|
|
1890
|
+
return _id2++;
|
|
1891
|
+
}
|
|
1892
|
+
function useList({ value, onChange }) {
|
|
1893
|
+
const [list, setList] = (0, import_react16.useState)([]);
|
|
1894
|
+
(0, import_react16.useEffect)(() => {
|
|
1895
|
+
setList((_prevList) => {
|
|
1896
|
+
const newKeys = Object.keys(value || {});
|
|
1897
|
+
const oldKeys = _prevList.map((item) => item.key).filter(Boolean);
|
|
1898
|
+
const addKeys = (0, import_lodash3.difference)(newKeys, oldKeys);
|
|
1899
|
+
return _prevList.filter((item) => !item.key || newKeys.includes(item.key)).map((item) => ({
|
|
1900
|
+
id: item.id,
|
|
1901
|
+
key: item.key,
|
|
1902
|
+
value: item.key ? value?.[item.key] : void 0
|
|
1903
|
+
})).concat(
|
|
1904
|
+
addKeys.map((_key) => ({
|
|
1905
|
+
id: genId2(),
|
|
1906
|
+
key: _key,
|
|
1907
|
+
value: value?.[_key]
|
|
1908
|
+
}))
|
|
1909
|
+
);
|
|
1910
|
+
});
|
|
1911
|
+
}, [value]);
|
|
1912
|
+
const add = () => {
|
|
1913
|
+
setList((prevList) => [
|
|
1914
|
+
...prevList,
|
|
1915
|
+
{
|
|
1916
|
+
id: genId2()
|
|
1917
|
+
}
|
|
1918
|
+
]);
|
|
1919
|
+
};
|
|
1920
|
+
const update = (item) => {
|
|
1921
|
+
setList((prevList) => {
|
|
1922
|
+
const nextList = prevList.map((_item) => {
|
|
1923
|
+
if (_item.id === item.id) {
|
|
1924
|
+
return item;
|
|
1925
|
+
}
|
|
1926
|
+
return _item;
|
|
1927
|
+
});
|
|
1928
|
+
onChange(
|
|
1929
|
+
Object.fromEntries(
|
|
1930
|
+
nextList.filter((item2) => item2.key).map((item2) => [item2.key, item2.value])
|
|
1931
|
+
)
|
|
1932
|
+
);
|
|
1933
|
+
return nextList;
|
|
1934
|
+
});
|
|
1935
|
+
};
|
|
1936
|
+
const remove = (itemId) => {
|
|
1937
|
+
setList((prevList) => {
|
|
1938
|
+
const nextList = prevList.filter((_item) => _item.id !== itemId);
|
|
1939
|
+
onChange(
|
|
1940
|
+
Object.fromEntries(
|
|
1941
|
+
nextList.filter((item) => item.key).map((item) => [item.key, item.value])
|
|
1942
|
+
)
|
|
1943
|
+
);
|
|
1944
|
+
return nextList;
|
|
1945
|
+
});
|
|
1946
|
+
};
|
|
1947
|
+
return { list, add, update, remove };
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
// src/components/batch-outputs/styles.tsx
|
|
1951
|
+
var import_styled_components5 = __toESM(require("styled-components"));
|
|
1952
|
+
var UIRows = import_styled_components5.default.div`
|
|
1953
|
+
display: flex;
|
|
1954
|
+
flex-direction: column;
|
|
1955
|
+
gap: 10px;
|
|
1956
|
+
margin-bottom: 10px;
|
|
1957
|
+
`;
|
|
1958
|
+
var UIRow2 = import_styled_components5.default.div`
|
|
1959
|
+
display: flex;
|
|
1960
|
+
align-items: center;
|
|
1961
|
+
gap: 5px;
|
|
1962
|
+
`;
|
|
1963
|
+
|
|
1964
|
+
// src/components/batch-outputs/index.tsx
|
|
1965
|
+
function BatchOutputs(props) {
|
|
1966
|
+
const { readonly, style } = props;
|
|
1967
|
+
const { list, add, update, remove } = useList(props);
|
|
1968
|
+
return /* @__PURE__ */ import_react17.default.createElement("div", null, /* @__PURE__ */ import_react17.default.createElement(UIRows, { style }, list.map((item) => /* @__PURE__ */ import_react17.default.createElement(UIRow2, { key: item.id }, /* @__PURE__ */ import_react17.default.createElement(
|
|
1969
|
+
import_semi_ui10.Input,
|
|
1970
|
+
{
|
|
1971
|
+
style: { width: 100 },
|
|
1972
|
+
disabled: readonly,
|
|
1973
|
+
size: "small",
|
|
1974
|
+
value: item.key,
|
|
1975
|
+
onChange: (v) => update({ ...item, key: v })
|
|
1976
|
+
}
|
|
1977
|
+
), /* @__PURE__ */ import_react17.default.createElement(
|
|
1978
|
+
VariableSelector,
|
|
1979
|
+
{
|
|
1980
|
+
style: { flexGrow: 1 },
|
|
1981
|
+
readonly,
|
|
1982
|
+
value: item.value?.content,
|
|
1983
|
+
onChange: (v) => update({
|
|
1984
|
+
...item,
|
|
1985
|
+
value: {
|
|
1986
|
+
type: "ref",
|
|
1987
|
+
content: v
|
|
1988
|
+
}
|
|
1989
|
+
})
|
|
1990
|
+
}
|
|
1991
|
+
), /* @__PURE__ */ import_react17.default.createElement(
|
|
1992
|
+
import_semi_ui10.Button,
|
|
1993
|
+
{
|
|
1994
|
+
disabled: readonly,
|
|
1995
|
+
icon: /* @__PURE__ */ import_react17.default.createElement(import_semi_icons8.IconDelete, null),
|
|
1996
|
+
size: "small",
|
|
1997
|
+
onClick: () => remove(item.id)
|
|
1998
|
+
}
|
|
1999
|
+
)))), /* @__PURE__ */ import_react17.default.createElement(import_semi_ui10.Button, { disabled: readonly, icon: /* @__PURE__ */ import_react17.default.createElement(import_semi_icons8.IconPlus, null), size: "small", onClick: add }, "Add"));
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
// src/components/prompt-editor/index.tsx
|
|
2003
|
+
var import_react24 = __toESM(require("react"));
|
|
2004
|
+
var import_react25 = require("@coze-editor/editor/react");
|
|
2005
|
+
var import_preset_prompt2 = __toESM(require("@coze-editor/editor/preset-prompt"));
|
|
2006
|
+
|
|
2007
|
+
// src/components/prompt-editor/styles.tsx
|
|
2008
|
+
var import_styled_components6 = __toESM(require("styled-components"));
|
|
2009
|
+
var UIContainer4 = import_styled_components6.default.div`
|
|
2010
|
+
background-color: var(--semi-color-fill-0);
|
|
2011
|
+
padding-left: 10px;
|
|
2012
|
+
padding-right: 6px;
|
|
2013
|
+
|
|
2014
|
+
${({ $hasError }) => $hasError && import_styled_components6.css`
|
|
2015
|
+
border: 1px solid var(--semi-color-danger-6);
|
|
2016
|
+
`}
|
|
2017
|
+
`;
|
|
2018
|
+
|
|
2019
|
+
// src/components/prompt-editor/extensions/markdown.tsx
|
|
2020
|
+
var import_react18 = require("react");
|
|
2021
|
+
var import_react19 = require("@coze-editor/editor/react");
|
|
2022
|
+
var import_editor5 = require("@coze-editor/editor");
|
|
2023
|
+
var import_view = require("@codemirror/view");
|
|
2024
|
+
function MarkdownHighlight() {
|
|
2025
|
+
const injector = (0, import_react19.useInjector)();
|
|
2026
|
+
(0, import_react18.useLayoutEffect)(
|
|
2027
|
+
() => injector.inject([
|
|
2028
|
+
import_editor5.astDecorator.whole.of((cursor) => {
|
|
2029
|
+
if (cursor.name.startsWith("ATXHeading")) {
|
|
2030
|
+
return {
|
|
2031
|
+
type: "className",
|
|
2032
|
+
className: "heading"
|
|
2033
|
+
};
|
|
2034
|
+
}
|
|
2035
|
+
if (cursor.name === "Emphasis") {
|
|
2036
|
+
return {
|
|
2037
|
+
type: "className",
|
|
2038
|
+
className: "emphasis"
|
|
2039
|
+
};
|
|
2040
|
+
}
|
|
2041
|
+
if (cursor.name === "StrongEmphasis") {
|
|
2042
|
+
return {
|
|
2043
|
+
type: "className",
|
|
2044
|
+
className: "strong-emphasis"
|
|
2045
|
+
};
|
|
2046
|
+
}
|
|
2047
|
+
if (cursor.name === "ListMark" || cursor.name === "QuoteMark") {
|
|
2048
|
+
return {
|
|
2049
|
+
type: "className",
|
|
2050
|
+
className: "mark"
|
|
2051
|
+
};
|
|
2052
|
+
}
|
|
2053
|
+
}),
|
|
2054
|
+
import_view.EditorView.theme({
|
|
2055
|
+
".heading": {
|
|
2056
|
+
color: "#00818C",
|
|
2057
|
+
fontWeight: "bold"
|
|
2058
|
+
},
|
|
2059
|
+
".emphasis": {
|
|
2060
|
+
fontStyle: "italic"
|
|
2061
|
+
},
|
|
2062
|
+
".strong-emphasis": {
|
|
2063
|
+
fontWeight: "bold"
|
|
2064
|
+
},
|
|
2065
|
+
".mark": {
|
|
2066
|
+
color: "#4E40E5"
|
|
2067
|
+
}
|
|
2068
|
+
})
|
|
2069
|
+
]),
|
|
2070
|
+
[injector]
|
|
2071
|
+
);
|
|
2072
|
+
return null;
|
|
2073
|
+
}
|
|
2074
|
+
var markdown_default = MarkdownHighlight;
|
|
2075
|
+
|
|
2076
|
+
// src/components/prompt-editor/extensions/language-support.tsx
|
|
2077
|
+
var import_react20 = require("react");
|
|
2078
|
+
var import_react21 = require("@coze-editor/editor/react");
|
|
2079
|
+
var import_preset_prompt = require("@coze-editor/editor/preset-prompt");
|
|
2080
|
+
function LanguageSupport() {
|
|
2081
|
+
const injector = (0, import_react21.useInjector)();
|
|
2082
|
+
(0, import_react20.useLayoutEffect)(() => injector.inject([import_preset_prompt.languageSupport]), [injector]);
|
|
2083
|
+
return null;
|
|
2084
|
+
}
|
|
2085
|
+
var language_support_default = LanguageSupport;
|
|
2086
|
+
|
|
2087
|
+
// src/components/prompt-editor/extensions/jinja.tsx
|
|
2088
|
+
var import_react22 = require("react");
|
|
2089
|
+
var import_react23 = require("@coze-editor/editor/react");
|
|
2090
|
+
var import_editor6 = require("@coze-editor/editor");
|
|
2091
|
+
var import_view2 = require("@codemirror/view");
|
|
2092
|
+
function JinjaHighlight() {
|
|
2093
|
+
const injector = (0, import_react23.useInjector)();
|
|
2094
|
+
(0, import_react22.useLayoutEffect)(
|
|
2095
|
+
() => injector.inject([
|
|
2096
|
+
import_editor6.astDecorator.whole.of((cursor) => {
|
|
2097
|
+
if (cursor.name === "JinjaStatementStart" || cursor.name === "JinjaStatementEnd") {
|
|
2098
|
+
return {
|
|
2099
|
+
type: "className",
|
|
2100
|
+
className: "jinja-statement-bracket"
|
|
2101
|
+
};
|
|
2102
|
+
}
|
|
2103
|
+
if (cursor.name === "JinjaComment") {
|
|
2104
|
+
return {
|
|
2105
|
+
type: "className",
|
|
2106
|
+
className: "jinja-comment"
|
|
2107
|
+
};
|
|
2108
|
+
}
|
|
2109
|
+
if (cursor.name === "JinjaExpression") {
|
|
2110
|
+
return {
|
|
2111
|
+
type: "className",
|
|
2112
|
+
className: "jinja-expression"
|
|
2113
|
+
};
|
|
2114
|
+
}
|
|
2115
|
+
}),
|
|
2116
|
+
import_view2.EditorView.theme({
|
|
2117
|
+
".jinja-statement-bracket": {
|
|
2118
|
+
color: "#D1009D"
|
|
2119
|
+
},
|
|
2120
|
+
".jinja-comment": {
|
|
2121
|
+
color: "#0607094D"
|
|
2122
|
+
},
|
|
2123
|
+
".jinja-expression": {
|
|
2124
|
+
color: "#4E40E5"
|
|
2125
|
+
}
|
|
2126
|
+
})
|
|
2127
|
+
]),
|
|
2128
|
+
[injector]
|
|
2129
|
+
);
|
|
2130
|
+
return null;
|
|
2131
|
+
}
|
|
2132
|
+
var jinja_default = JinjaHighlight;
|
|
2133
|
+
|
|
2134
|
+
// src/components/prompt-editor/index.tsx
|
|
2135
|
+
function PromptEditor(props) {
|
|
2136
|
+
const { value, onChange, readonly, style, hasError, children } = props || {};
|
|
2137
|
+
return /* @__PURE__ */ import_react24.default.createElement(UIContainer4, { $hasError: hasError, style }, /* @__PURE__ */ import_react24.default.createElement(import_react25.EditorProvider, null, /* @__PURE__ */ import_react24.default.createElement(
|
|
2138
|
+
import_react25.Renderer,
|
|
2139
|
+
{
|
|
2140
|
+
plugins: import_preset_prompt2.default,
|
|
2141
|
+
defaultValue: String(value?.content),
|
|
2142
|
+
options: {
|
|
2143
|
+
readOnly: readonly,
|
|
2144
|
+
editable: !readonly
|
|
2145
|
+
},
|
|
2146
|
+
onChange: (e) => {
|
|
2147
|
+
onChange({ type: "template", content: e.value });
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
), /* @__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));
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
// src/components/prompt-editor-with-variables/index.tsx
|
|
2154
|
+
var import_react28 = __toESM(require("react"));
|
|
2155
|
+
|
|
2156
|
+
// src/components/prompt-editor-with-variables/extensions/variable.tsx
|
|
2157
|
+
var import_react26 = __toESM(require("react"));
|
|
2158
|
+
var import_semi_ui11 = require("@douyinfe/semi-ui");
|
|
2159
|
+
var import_react27 = require("@coze-editor/editor/react");
|
|
2160
|
+
function Variable() {
|
|
2161
|
+
const [posKey, setPosKey] = (0, import_react26.useState)("");
|
|
2162
|
+
const [visible, setVisible] = (0, import_react26.useState)(false);
|
|
2163
|
+
const [position, setPosition] = (0, import_react26.useState)(-1);
|
|
2164
|
+
const editor = (0, import_react27.useEditor)();
|
|
2165
|
+
function insert(variablePath) {
|
|
2166
|
+
const range = (0, import_react27.getCurrentMentionReplaceRange)(editor.$view.state);
|
|
2167
|
+
if (!range) {
|
|
2168
|
+
return;
|
|
2169
|
+
}
|
|
2170
|
+
editor.replaceText({
|
|
2171
|
+
...range,
|
|
2172
|
+
text: "{{" + variablePath + "}}"
|
|
2173
|
+
});
|
|
2174
|
+
setVisible(false);
|
|
2175
|
+
}
|
|
2176
|
+
function handleOpenChange(e) {
|
|
2177
|
+
setPosition(e.state.selection.main.head);
|
|
2178
|
+
setVisible(e.value);
|
|
2179
|
+
}
|
|
2180
|
+
(0, import_react26.useEffect)(() => {
|
|
2181
|
+
if (!editor) {
|
|
2182
|
+
return;
|
|
2183
|
+
}
|
|
2184
|
+
}, [editor, visible]);
|
|
2185
|
+
const treeData = useVariableTree({});
|
|
2186
|
+
return /* @__PURE__ */ import_react26.default.createElement(import_react26.default.Fragment, null, /* @__PURE__ */ import_react26.default.createElement(import_react27.Mention, { triggerCharacters: ["{", "{}"], onOpenChange: handleOpenChange }), /* @__PURE__ */ import_react26.default.createElement(
|
|
2187
|
+
import_semi_ui11.Popover,
|
|
2188
|
+
{
|
|
2189
|
+
visible,
|
|
2190
|
+
trigger: "custom",
|
|
2191
|
+
position: "topLeft",
|
|
2192
|
+
rePosKey: posKey,
|
|
2193
|
+
content: /* @__PURE__ */ import_react26.default.createElement("div", { style: { width: 300 } }, /* @__PURE__ */ import_react26.default.createElement(
|
|
2194
|
+
import_semi_ui11.Tree,
|
|
2195
|
+
{
|
|
2196
|
+
treeData,
|
|
2197
|
+
onSelect: (v) => {
|
|
2198
|
+
insert(v);
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
))
|
|
2202
|
+
},
|
|
2203
|
+
/* @__PURE__ */ import_react26.default.createElement(
|
|
2204
|
+
import_react27.PositionMirror,
|
|
2205
|
+
{
|
|
2206
|
+
position,
|
|
2207
|
+
onChange: () => setPosKey(String(Math.random()))
|
|
2208
|
+
}
|
|
2209
|
+
)
|
|
2210
|
+
));
|
|
2211
|
+
}
|
|
2212
|
+
var variable_default = Variable;
|
|
2213
|
+
|
|
2214
|
+
// src/components/prompt-editor-with-variables/index.tsx
|
|
2215
|
+
function PromptEditorWithVariables(props) {
|
|
2216
|
+
return /* @__PURE__ */ import_react28.default.createElement(PromptEditor, { ...props }, /* @__PURE__ */ import_react28.default.createElement(variable_default, null));
|
|
2217
|
+
}
|
|
2218
|
+
|
|
1850
2219
|
// src/effects/provide-batch-input/index.ts
|
|
1851
|
-
var
|
|
1852
|
-
var provideBatchInputEffect = (0,
|
|
2220
|
+
var import_editor7 = require("@flowgram.ai/editor");
|
|
2221
|
+
var provideBatchInputEffect = (0, import_editor7.createEffectFromVariableProvider)({
|
|
1853
2222
|
private: true,
|
|
1854
2223
|
parse: (value, ctx) => [
|
|
1855
|
-
|
|
2224
|
+
import_editor7.ASTFactory.createVariableDeclaration({
|
|
1856
2225
|
key: `${ctx.node.id}_locals`,
|
|
1857
2226
|
meta: {
|
|
1858
|
-
title: (0,
|
|
2227
|
+
title: (0, import_editor7.getNodeForm)(ctx.node)?.getValueIn("title"),
|
|
1859
2228
|
icon: ctx.node.getNodeRegistry().info?.icon
|
|
1860
2229
|
},
|
|
1861
|
-
type:
|
|
2230
|
+
type: import_editor7.ASTFactory.createObject({
|
|
1862
2231
|
properties: [
|
|
1863
|
-
|
|
2232
|
+
import_editor7.ASTFactory.createProperty({
|
|
1864
2233
|
key: "item",
|
|
1865
|
-
initializer:
|
|
1866
|
-
enumerateFor:
|
|
2234
|
+
initializer: import_editor7.ASTFactory.createEnumerateExpression({
|
|
2235
|
+
enumerateFor: import_editor7.ASTFactory.createKeyPathExpression({
|
|
1867
2236
|
keyPath: value.content || []
|
|
1868
2237
|
})
|
|
1869
2238
|
})
|
|
1870
2239
|
}),
|
|
1871
|
-
|
|
2240
|
+
import_editor7.ASTFactory.createProperty({
|
|
1872
2241
|
key: "index",
|
|
1873
|
-
type:
|
|
2242
|
+
type: import_editor7.ASTFactory.createNumber()
|
|
1874
2243
|
})
|
|
1875
2244
|
]
|
|
1876
2245
|
})
|
|
@@ -1879,22 +2248,21 @@ var provideBatchInputEffect = (0, import_editor5.createEffectFromVariableProvide
|
|
|
1879
2248
|
});
|
|
1880
2249
|
|
|
1881
2250
|
// src/effects/provide-batch-outputs/index.ts
|
|
1882
|
-
var
|
|
1883
|
-
var provideBatchOutputsEffect = (0,
|
|
1884
|
-
private: true,
|
|
2251
|
+
var import_editor8 = require("@flowgram.ai/editor");
|
|
2252
|
+
var provideBatchOutputsEffect = (0, import_editor8.createEffectFromVariableProvider)({
|
|
1885
2253
|
parse: (value, ctx) => [
|
|
1886
|
-
|
|
2254
|
+
import_editor8.ASTFactory.createVariableDeclaration({
|
|
1887
2255
|
key: `${ctx.node.id}`,
|
|
1888
2256
|
meta: {
|
|
1889
|
-
title: (0,
|
|
2257
|
+
title: (0, import_editor8.getNodeForm)(ctx.node)?.getValueIn("title"),
|
|
1890
2258
|
icon: ctx.node.getNodeRegistry().info?.icon
|
|
1891
2259
|
},
|
|
1892
|
-
type:
|
|
2260
|
+
type: import_editor8.ASTFactory.createObject({
|
|
1893
2261
|
properties: Object.entries(value).map(
|
|
1894
|
-
([_key, value2]) =>
|
|
2262
|
+
([_key, value2]) => import_editor8.ASTFactory.createProperty({
|
|
1895
2263
|
key: _key,
|
|
1896
|
-
initializer:
|
|
1897
|
-
wrapFor:
|
|
2264
|
+
initializer: import_editor8.ASTFactory.createWrapArrayExpression({
|
|
2265
|
+
wrapFor: import_editor8.ASTFactory.createKeyPathExpression({
|
|
1898
2266
|
keyPath: value2.content || []
|
|
1899
2267
|
})
|
|
1900
2268
|
})
|
|
@@ -1906,14 +2274,14 @@ var provideBatchOutputsEffect = (0, import_editor6.createEffectFromVariableProvi
|
|
|
1906
2274
|
});
|
|
1907
2275
|
|
|
1908
2276
|
// src/effects/auto-rename-ref/index.ts
|
|
1909
|
-
var
|
|
1910
|
-
var
|
|
2277
|
+
var import_lodash4 = require("lodash");
|
|
2278
|
+
var import_editor9 = require("@flowgram.ai/editor");
|
|
1911
2279
|
var autoRenameRefEffect = [
|
|
1912
2280
|
{
|
|
1913
|
-
event:
|
|
2281
|
+
event: import_editor9.DataEvent.onValueInit,
|
|
1914
2282
|
effect: (params) => {
|
|
1915
2283
|
const { context, form, name } = params;
|
|
1916
|
-
const renameService = context.node.getService(
|
|
2284
|
+
const renameService = context.node.getService(import_editor9.VariableFieldKeyRenameService);
|
|
1917
2285
|
const disposable = renameService.onRename(({ before, after }) => {
|
|
1918
2286
|
const beforeKeyPath = [
|
|
1919
2287
|
...before.parentFields.map((_field) => _field.key).reverse(),
|
|
@@ -1943,7 +2311,7 @@ function isRef(value) {
|
|
|
1943
2311
|
return value?.type === "ref" && Array.isArray(value?.content) && typeof value?.content[0] === "string";
|
|
1944
2312
|
}
|
|
1945
2313
|
function traverseRef(name, value, cb) {
|
|
1946
|
-
if ((0,
|
|
2314
|
+
if ((0, import_lodash4.isObject)(value)) {
|
|
1947
2315
|
if (isRef(value)) {
|
|
1948
2316
|
cb(name, value);
|
|
1949
2317
|
return;
|
|
@@ -1953,7 +2321,7 @@ function traverseRef(name, value, cb) {
|
|
|
1953
2321
|
});
|
|
1954
2322
|
return;
|
|
1955
2323
|
}
|
|
1956
|
-
if ((0,
|
|
2324
|
+
if ((0, import_lodash4.isArray)(value)) {
|
|
1957
2325
|
value.forEach((_value, idx) => {
|
|
1958
2326
|
traverseRef(`${name}[${idx}]`, _value, cb);
|
|
1959
2327
|
});
|
|
@@ -1963,13 +2331,13 @@ function traverseRef(name, value, cb) {
|
|
|
1963
2331
|
}
|
|
1964
2332
|
|
|
1965
2333
|
// src/effects/provide-json-schema-outputs/index.ts
|
|
1966
|
-
var
|
|
1967
|
-
var provideJsonSchemaOutputs = (0,
|
|
2334
|
+
var import_editor10 = require("@flowgram.ai/editor");
|
|
2335
|
+
var provideJsonSchemaOutputs = (0, import_editor10.createEffectFromVariableProvider)({
|
|
1968
2336
|
parse: (value, ctx) => [
|
|
1969
|
-
|
|
2337
|
+
import_editor10.ASTFactory.createVariableDeclaration({
|
|
1970
2338
|
key: `${ctx.node.id}`,
|
|
1971
2339
|
meta: {
|
|
1972
|
-
title: (0,
|
|
2340
|
+
title: (0, import_editor10.getNodeForm)(ctx.node)?.getValueIn("title") || ctx.node.id,
|
|
1973
2341
|
icon: ctx.node.getNodeRegistry().info?.icon
|
|
1974
2342
|
},
|
|
1975
2343
|
type: JsonSchemaUtils.schemaToAST(value)
|
|
@@ -1978,12 +2346,12 @@ var provideJsonSchemaOutputs = (0, import_editor8.createEffectFromVariableProvid
|
|
|
1978
2346
|
});
|
|
1979
2347
|
|
|
1980
2348
|
// src/effects/sync-variable-title/index.ts
|
|
1981
|
-
var
|
|
2349
|
+
var import_editor11 = require("@flowgram.ai/editor");
|
|
1982
2350
|
var syncVariableTitle = [
|
|
1983
2351
|
{
|
|
1984
|
-
event:
|
|
2352
|
+
event: import_editor11.DataEvent.onValueChange,
|
|
1985
2353
|
effect: ({ value, context }) => {
|
|
1986
|
-
context.node.getData(
|
|
2354
|
+
context.node.getData(import_editor11.FlowNodeVariableData).allScopes.forEach((_scope) => {
|
|
1987
2355
|
_scope.output.variables.forEach((_var) => {
|
|
1988
2356
|
_var.updateMeta({
|
|
1989
2357
|
title: value || context.node.id,
|
|
@@ -1994,19 +2362,89 @@ var syncVariableTitle = [
|
|
|
1994
2362
|
}
|
|
1995
2363
|
}
|
|
1996
2364
|
];
|
|
2365
|
+
|
|
2366
|
+
// src/form-plugins/batch-outputs-plugin/index.ts
|
|
2367
|
+
var import_editor12 = require("@flowgram.ai/editor");
|
|
2368
|
+
var provideBatchOutputsEffect2 = (0, import_editor12.createEffectFromVariableProvider)({
|
|
2369
|
+
parse: (value, ctx) => [
|
|
2370
|
+
import_editor12.ASTFactory.createVariableDeclaration({
|
|
2371
|
+
key: `${ctx.node.id}`,
|
|
2372
|
+
meta: {
|
|
2373
|
+
title: (0, import_editor12.getNodeForm)(ctx.node)?.getValueIn("title"),
|
|
2374
|
+
icon: ctx.node.getNodeRegistry().info?.icon
|
|
2375
|
+
},
|
|
2376
|
+
type: import_editor12.ASTFactory.createObject({
|
|
2377
|
+
properties: Object.entries(value).map(
|
|
2378
|
+
([_key, value2]) => import_editor12.ASTFactory.createProperty({
|
|
2379
|
+
key: _key,
|
|
2380
|
+
initializer: import_editor12.ASTFactory.createWrapArrayExpression({
|
|
2381
|
+
wrapFor: import_editor12.ASTFactory.createKeyPathExpression({
|
|
2382
|
+
keyPath: value2?.content || []
|
|
2383
|
+
})
|
|
2384
|
+
})
|
|
2385
|
+
})
|
|
2386
|
+
)
|
|
2387
|
+
})
|
|
2388
|
+
})
|
|
2389
|
+
]
|
|
2390
|
+
});
|
|
2391
|
+
var createBatchOutputsFormPlugin = (0, import_editor12.defineFormPluginCreator)({
|
|
2392
|
+
name: "batch-outputs-plugin",
|
|
2393
|
+
onSetupFormMeta({ mergeEffect }, { outputKey }) {
|
|
2394
|
+
mergeEffect({
|
|
2395
|
+
[outputKey]: provideBatchOutputsEffect2
|
|
2396
|
+
});
|
|
2397
|
+
},
|
|
2398
|
+
onInit(ctx, { outputKey }) {
|
|
2399
|
+
const chainTransformService = ctx.node.getService(import_editor12.ScopeChainTransformService);
|
|
2400
|
+
const batchNodeType = ctx.node.flowNodeType;
|
|
2401
|
+
const transformerId = `${batchNodeType}-outputs`;
|
|
2402
|
+
if (chainTransformService.hasTransformer(transformerId)) {
|
|
2403
|
+
return;
|
|
2404
|
+
}
|
|
2405
|
+
chainTransformService.registerTransformer(transformerId, {
|
|
2406
|
+
transformCovers: (covers, ctx2) => {
|
|
2407
|
+
const node = ctx2.scope.meta?.node;
|
|
2408
|
+
if (node?.parent?.flowNodeType === batchNodeType) {
|
|
2409
|
+
return [...covers, (0, import_editor12.getNodeScope)(node.parent)];
|
|
2410
|
+
}
|
|
2411
|
+
return covers;
|
|
2412
|
+
},
|
|
2413
|
+
transformDeps(scopes, ctx2) {
|
|
2414
|
+
const scopeMeta = ctx2.scope.meta;
|
|
2415
|
+
if (scopeMeta?.type === import_editor12.FlowNodeScopeType.private) {
|
|
2416
|
+
return scopes;
|
|
2417
|
+
}
|
|
2418
|
+
const node = scopeMeta?.node;
|
|
2419
|
+
if (node?.flowNodeType === batchNodeType) {
|
|
2420
|
+
const childBlocks = node.blocks;
|
|
2421
|
+
return [
|
|
2422
|
+
(0, import_editor12.getNodePrivateScope)(node),
|
|
2423
|
+
...childBlocks.map((_childBlock) => (0, import_editor12.getNodeScope)(_childBlock))
|
|
2424
|
+
];
|
|
2425
|
+
}
|
|
2426
|
+
return scopes;
|
|
2427
|
+
}
|
|
2428
|
+
});
|
|
2429
|
+
}
|
|
2430
|
+
});
|
|
1997
2431
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1998
2432
|
0 && (module.exports = {
|
|
1999
2433
|
ArrayIcons,
|
|
2434
|
+
BatchOutputs,
|
|
2000
2435
|
BatchVariableSelector,
|
|
2001
2436
|
ConditionRow,
|
|
2002
2437
|
ConstantInput,
|
|
2003
2438
|
DynamicValueInput,
|
|
2004
2439
|
JsonSchemaEditor,
|
|
2005
2440
|
JsonSchemaUtils,
|
|
2441
|
+
PromptEditor,
|
|
2442
|
+
PromptEditorWithVariables,
|
|
2006
2443
|
TypeSelector,
|
|
2007
2444
|
VariableSelector,
|
|
2008
2445
|
VariableTypeIcons,
|
|
2009
2446
|
autoRenameRefEffect,
|
|
2447
|
+
createBatchOutputsFormPlugin,
|
|
2010
2448
|
formatLegacyRefOnInit,
|
|
2011
2449
|
formatLegacyRefOnSubmit,
|
|
2012
2450
|
formatLegacyRefToNewRef,
|
|
@@ -2019,6 +2457,7 @@ var syncVariableTitle = [
|
|
|
2019
2457
|
provideBatchInputEffect,
|
|
2020
2458
|
provideBatchOutputsEffect,
|
|
2021
2459
|
provideJsonSchemaOutputs,
|
|
2022
|
-
syncVariableTitle
|
|
2460
|
+
syncVariableTitle,
|
|
2461
|
+
useVariableTree
|
|
2023
2462
|
});
|
|
2024
2463
|
//# sourceMappingURL=index.js.map
|