@flowgram.ai/form-materials 0.2.17 → 0.2.19
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 +423 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +35 -7
- package/dist/index.d.ts +35 -7
- package/dist/index.js +455 -53
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/components/condition-row/index.tsx +6 -1
- package/src/components/dynamic-value-input/index.tsx +1 -0
- package/src/components/dynamic-value-input/styles.tsx +2 -0
- package/src/components/index.ts +2 -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 +12 -0
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +173 -0
- package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +83 -0
- package/src/components/prompt-editor-with-variables/index.tsx +19 -0
- package/src/components/prompt-editor-with-variables/styles.tsx +44 -0
- package/src/components/variable-selector/index.tsx +2 -2
- package/src/components/variable-selector/styles.tsx +12 -1
- package/src/utils/json-schema/index.ts +16 -2
package/dist/index.js
CHANGED
|
@@ -38,6 +38,8 @@ __export(src_exports, {
|
|
|
38
38
|
DynamicValueInput: () => DynamicValueInput,
|
|
39
39
|
JsonSchemaEditor: () => JsonSchemaEditor,
|
|
40
40
|
JsonSchemaUtils: () => JsonSchemaUtils,
|
|
41
|
+
PromptEditor: () => PromptEditor,
|
|
42
|
+
PromptEditorWithVariables: () => PromptEditorWithVariables,
|
|
41
43
|
TypeSelector: () => TypeSelector,
|
|
42
44
|
VariableSelector: () => VariableSelector,
|
|
43
45
|
VariableTypeIcons: () => VariableTypeIcons,
|
|
@@ -478,7 +480,10 @@ var JsonSchemaUtils;
|
|
|
478
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]) => ({
|
|
479
481
|
key,
|
|
480
482
|
type: schemaToAST(_property),
|
|
481
|
-
meta: {
|
|
483
|
+
meta: {
|
|
484
|
+
title: _property.title,
|
|
485
|
+
description: _property.description
|
|
486
|
+
}
|
|
482
487
|
}))
|
|
483
488
|
});
|
|
484
489
|
case "array":
|
|
@@ -534,7 +539,16 @@ var JsonSchemaUtils;
|
|
|
534
539
|
return {
|
|
535
540
|
type: "object",
|
|
536
541
|
properties: drilldown ? Object.fromEntries(
|
|
537
|
-
typeAST.properties.map((property) =>
|
|
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
|
+
})
|
|
538
552
|
) : {}
|
|
539
553
|
};
|
|
540
554
|
}
|
|
@@ -631,10 +645,20 @@ function useVariableTree(params) {
|
|
|
631
645
|
// src/components/variable-selector/styles.tsx
|
|
632
646
|
var import_styled_components = __toESM(require("styled-components"));
|
|
633
647
|
var import_semi_ui2 = require("@douyinfe/semi-ui");
|
|
634
|
-
var UIRootTitle = import_styled_components.default.
|
|
648
|
+
var UIRootTitle = import_styled_components.default.div`
|
|
635
649
|
margin-right: 4px;
|
|
650
|
+
min-width: 20px;
|
|
651
|
+
overflow: hidden;
|
|
652
|
+
text-overflow: ellipsis;
|
|
653
|
+
white-space: nowrap;
|
|
636
654
|
color: var(--semi-color-text-2);
|
|
637
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
|
+
`;
|
|
638
662
|
var UITag = (0, import_styled_components.default)(import_semi_ui2.Tag)`
|
|
639
663
|
width: 100%;
|
|
640
664
|
display: flex;
|
|
@@ -735,7 +759,7 @@ var VariableSelector = ({
|
|
|
735
759
|
onClose: () => onChange(void 0)
|
|
736
760
|
},
|
|
737
761
|
/* @__PURE__ */ import_react3.default.createElement(UIRootTitle, null, _option.rootMeta?.title ? `${_option.rootMeta?.title} -` : null),
|
|
738
|
-
_option.label
|
|
762
|
+
/* @__PURE__ */ import_react3.default.createElement(UIVarName, null, _option.label)
|
|
739
763
|
);
|
|
740
764
|
},
|
|
741
765
|
showClear: false,
|
|
@@ -1178,14 +1202,14 @@ function ConstantInput(props) {
|
|
|
1178
1202
|
() => [...defaultStrategies, ...extraStrategies || []],
|
|
1179
1203
|
[extraStrategies]
|
|
1180
1204
|
);
|
|
1181
|
-
const
|
|
1205
|
+
const Renderer2 = (0, import_react7.useMemo)(() => {
|
|
1182
1206
|
const strategy = strategies.find((_strategy) => _strategy.hit(schema));
|
|
1183
1207
|
return strategy?.Renderer;
|
|
1184
1208
|
}, [strategies, schema]);
|
|
1185
|
-
if (!
|
|
1209
|
+
if (!Renderer2) {
|
|
1186
1210
|
return /* @__PURE__ */ import_react7.default.createElement(import_semi_ui4.Input, { size: "small", disabled: true, placeholder: "Unsupported type" });
|
|
1187
1211
|
}
|
|
1188
|
-
return /* @__PURE__ */ import_react7.default.createElement(
|
|
1212
|
+
return /* @__PURE__ */ import_react7.default.createElement(Renderer2, { value, onChange, readonly, ...rest });
|
|
1189
1213
|
}
|
|
1190
1214
|
|
|
1191
1215
|
// src/components/json-schema-editor/default-value.tsx
|
|
@@ -1493,6 +1517,8 @@ var UIContainer2 = import_styled_components3.default.div`
|
|
|
1493
1517
|
`;
|
|
1494
1518
|
var UIMain = import_styled_components3.default.div`
|
|
1495
1519
|
flex-grow: 1;
|
|
1520
|
+
overflow: hidden;
|
|
1521
|
+
min-width: 0;
|
|
1496
1522
|
|
|
1497
1523
|
& .semi-tree-select,
|
|
1498
1524
|
& .semi-input-number,
|
|
@@ -1522,6 +1548,7 @@ function DynamicValueInput({
|
|
|
1522
1548
|
return /* @__PURE__ */ import_react12.default.createElement(
|
|
1523
1549
|
VariableSelector,
|
|
1524
1550
|
{
|
|
1551
|
+
style: { width: "100%" },
|
|
1525
1552
|
value: value?.content,
|
|
1526
1553
|
onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : void 0),
|
|
1527
1554
|
includeSchema,
|
|
@@ -1847,7 +1874,15 @@ function ConditionRow({ style, value, onChange, readonly }) {
|
|
|
1847
1874
|
schema: targetSchema,
|
|
1848
1875
|
onChange: (v) => onChange({ ...value, right: v })
|
|
1849
1876
|
}
|
|
1850
|
-
) : /* @__PURE__ */ import_react15.default.createElement(
|
|
1877
|
+
) : /* @__PURE__ */ import_react15.default.createElement(
|
|
1878
|
+
import_semi_ui9.Input,
|
|
1879
|
+
{
|
|
1880
|
+
size: "small",
|
|
1881
|
+
disabled: true,
|
|
1882
|
+
style: { pointerEvents: "none" },
|
|
1883
|
+
value: opConfig?.rightDisplay || "Empty"
|
|
1884
|
+
}
|
|
1885
|
+
))));
|
|
1851
1886
|
}
|
|
1852
1887
|
|
|
1853
1888
|
// src/components/batch-outputs/index.tsx
|
|
@@ -1972,30 +2007,395 @@ function BatchOutputs(props) {
|
|
|
1972
2007
|
)))), /* @__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"));
|
|
1973
2008
|
}
|
|
1974
2009
|
|
|
2010
|
+
// src/components/prompt-editor/index.tsx
|
|
2011
|
+
var import_react24 = __toESM(require("react"));
|
|
2012
|
+
var import_react25 = require("@coze-editor/editor/react");
|
|
2013
|
+
var import_preset_prompt2 = __toESM(require("@coze-editor/editor/preset-prompt"));
|
|
2014
|
+
|
|
2015
|
+
// src/components/prompt-editor/styles.tsx
|
|
2016
|
+
var import_styled_components6 = __toESM(require("styled-components"));
|
|
2017
|
+
var UIContainer4 = import_styled_components6.default.div`
|
|
2018
|
+
background-color: var(--semi-color-fill-0);
|
|
2019
|
+
padding-left: 10px;
|
|
2020
|
+
padding-right: 6px;
|
|
2021
|
+
|
|
2022
|
+
${({ $hasError }) => $hasError && import_styled_components6.css`
|
|
2023
|
+
border: 1px solid var(--semi-color-danger-6);
|
|
2024
|
+
`}
|
|
2025
|
+
`;
|
|
2026
|
+
|
|
2027
|
+
// src/components/prompt-editor/extensions/markdown.tsx
|
|
2028
|
+
var import_react18 = require("react");
|
|
2029
|
+
var import_react19 = require("@coze-editor/editor/react");
|
|
2030
|
+
var import_editor5 = require("@coze-editor/editor");
|
|
2031
|
+
var import_view = require("@codemirror/view");
|
|
2032
|
+
function MarkdownHighlight() {
|
|
2033
|
+
const injector = (0, import_react19.useInjector)();
|
|
2034
|
+
(0, import_react18.useLayoutEffect)(
|
|
2035
|
+
() => injector.inject([
|
|
2036
|
+
import_editor5.astDecorator.whole.of((cursor) => {
|
|
2037
|
+
if (cursor.name.startsWith("ATXHeading")) {
|
|
2038
|
+
return {
|
|
2039
|
+
type: "className",
|
|
2040
|
+
className: "heading"
|
|
2041
|
+
};
|
|
2042
|
+
}
|
|
2043
|
+
if (cursor.name === "Emphasis") {
|
|
2044
|
+
return {
|
|
2045
|
+
type: "className",
|
|
2046
|
+
className: "emphasis"
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
if (cursor.name === "StrongEmphasis") {
|
|
2050
|
+
return {
|
|
2051
|
+
type: "className",
|
|
2052
|
+
className: "strong-emphasis"
|
|
2053
|
+
};
|
|
2054
|
+
}
|
|
2055
|
+
if (cursor.name === "ListMark" || cursor.name === "QuoteMark") {
|
|
2056
|
+
return {
|
|
2057
|
+
type: "className",
|
|
2058
|
+
className: "mark"
|
|
2059
|
+
};
|
|
2060
|
+
}
|
|
2061
|
+
}),
|
|
2062
|
+
import_view.EditorView.theme({
|
|
2063
|
+
".heading": {
|
|
2064
|
+
color: "#00818C",
|
|
2065
|
+
fontWeight: "bold"
|
|
2066
|
+
},
|
|
2067
|
+
".emphasis": {
|
|
2068
|
+
fontStyle: "italic"
|
|
2069
|
+
},
|
|
2070
|
+
".strong-emphasis": {
|
|
2071
|
+
fontWeight: "bold"
|
|
2072
|
+
},
|
|
2073
|
+
".mark": {
|
|
2074
|
+
color: "#4E40E5"
|
|
2075
|
+
}
|
|
2076
|
+
})
|
|
2077
|
+
]),
|
|
2078
|
+
[injector]
|
|
2079
|
+
);
|
|
2080
|
+
return null;
|
|
2081
|
+
}
|
|
2082
|
+
var markdown_default = MarkdownHighlight;
|
|
2083
|
+
|
|
2084
|
+
// src/components/prompt-editor/extensions/language-support.tsx
|
|
2085
|
+
var import_react20 = require("react");
|
|
2086
|
+
var import_react21 = require("@coze-editor/editor/react");
|
|
2087
|
+
var import_preset_prompt = require("@coze-editor/editor/preset-prompt");
|
|
2088
|
+
function LanguageSupport() {
|
|
2089
|
+
const injector = (0, import_react21.useInjector)();
|
|
2090
|
+
(0, import_react20.useLayoutEffect)(() => injector.inject([import_preset_prompt.languageSupport]), [injector]);
|
|
2091
|
+
return null;
|
|
2092
|
+
}
|
|
2093
|
+
var language_support_default = LanguageSupport;
|
|
2094
|
+
|
|
2095
|
+
// src/components/prompt-editor/extensions/jinja.tsx
|
|
2096
|
+
var import_react22 = require("react");
|
|
2097
|
+
var import_react23 = require("@coze-editor/editor/react");
|
|
2098
|
+
var import_editor6 = require("@coze-editor/editor");
|
|
2099
|
+
var import_view2 = require("@codemirror/view");
|
|
2100
|
+
function JinjaHighlight() {
|
|
2101
|
+
const injector = (0, import_react23.useInjector)();
|
|
2102
|
+
(0, import_react22.useLayoutEffect)(
|
|
2103
|
+
() => injector.inject([
|
|
2104
|
+
import_editor6.astDecorator.whole.of((cursor) => {
|
|
2105
|
+
if (cursor.name === "JinjaStatementStart" || cursor.name === "JinjaStatementEnd") {
|
|
2106
|
+
return {
|
|
2107
|
+
type: "className",
|
|
2108
|
+
className: "jinja-statement-bracket"
|
|
2109
|
+
};
|
|
2110
|
+
}
|
|
2111
|
+
if (cursor.name === "JinjaComment") {
|
|
2112
|
+
return {
|
|
2113
|
+
type: "className",
|
|
2114
|
+
className: "jinja-comment"
|
|
2115
|
+
};
|
|
2116
|
+
}
|
|
2117
|
+
if (cursor.name === "JinjaExpression") {
|
|
2118
|
+
return {
|
|
2119
|
+
type: "className",
|
|
2120
|
+
className: "jinja-expression"
|
|
2121
|
+
};
|
|
2122
|
+
}
|
|
2123
|
+
}),
|
|
2124
|
+
import_view2.EditorView.theme({
|
|
2125
|
+
".jinja-statement-bracket": {
|
|
2126
|
+
color: "#D1009D"
|
|
2127
|
+
},
|
|
2128
|
+
".jinja-comment": {
|
|
2129
|
+
color: "#0607094D"
|
|
2130
|
+
},
|
|
2131
|
+
".jinja-expression": {
|
|
2132
|
+
color: "#4E40E5"
|
|
2133
|
+
}
|
|
2134
|
+
})
|
|
2135
|
+
]),
|
|
2136
|
+
[injector]
|
|
2137
|
+
);
|
|
2138
|
+
return null;
|
|
2139
|
+
}
|
|
2140
|
+
var jinja_default = JinjaHighlight;
|
|
2141
|
+
|
|
2142
|
+
// src/components/prompt-editor/index.tsx
|
|
2143
|
+
function PromptEditor(props) {
|
|
2144
|
+
const { value, onChange, readonly, style, hasError, children } = props || {};
|
|
2145
|
+
return /* @__PURE__ */ import_react24.default.createElement(UIContainer4, { $hasError: hasError, style }, /* @__PURE__ */ import_react24.default.createElement(import_react25.EditorProvider, null, /* @__PURE__ */ import_react24.default.createElement(
|
|
2146
|
+
import_react25.Renderer,
|
|
2147
|
+
{
|
|
2148
|
+
plugins: import_preset_prompt2.default,
|
|
2149
|
+
defaultValue: String(value?.content),
|
|
2150
|
+
options: {
|
|
2151
|
+
readOnly: readonly,
|
|
2152
|
+
editable: !readonly
|
|
2153
|
+
},
|
|
2154
|
+
onChange: (e) => {
|
|
2155
|
+
onChange({ type: "template", content: e.value });
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
), /* @__PURE__ */ import_react24.default.createElement(markdown_default, null), /* @__PURE__ */ import_react24.default.createElement(language_support_default, null), /* @__PURE__ */ import_react24.default.createElement(jinja_default, null), children));
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
// src/components/prompt-editor-with-variables/index.tsx
|
|
2162
|
+
var import_react30 = __toESM(require("react"));
|
|
2163
|
+
|
|
2164
|
+
// src/components/prompt-editor-with-variables/extensions/variable-tree.tsx
|
|
2165
|
+
var import_react26 = __toESM(require("react"));
|
|
2166
|
+
var import_semi_ui11 = require("@douyinfe/semi-ui");
|
|
2167
|
+
var import_react27 = require("@coze-editor/editor/react");
|
|
2168
|
+
function VariableTree() {
|
|
2169
|
+
const [posKey, setPosKey] = (0, import_react26.useState)("");
|
|
2170
|
+
const [visible, setVisible] = (0, import_react26.useState)(false);
|
|
2171
|
+
const [position, setPosition] = (0, import_react26.useState)(-1);
|
|
2172
|
+
const editor = (0, import_react27.useEditor)();
|
|
2173
|
+
function insert(variablePath) {
|
|
2174
|
+
const range = (0, import_react27.getCurrentMentionReplaceRange)(editor.$view.state);
|
|
2175
|
+
if (!range) {
|
|
2176
|
+
return;
|
|
2177
|
+
}
|
|
2178
|
+
editor.replaceText({
|
|
2179
|
+
...range,
|
|
2180
|
+
text: "{{" + variablePath + "}}"
|
|
2181
|
+
});
|
|
2182
|
+
setVisible(false);
|
|
2183
|
+
}
|
|
2184
|
+
function handleOpenChange(e) {
|
|
2185
|
+
setPosition(e.state.selection.main.head);
|
|
2186
|
+
setVisible(e.value);
|
|
2187
|
+
}
|
|
2188
|
+
(0, import_react26.useEffect)(() => {
|
|
2189
|
+
if (!editor) {
|
|
2190
|
+
return;
|
|
2191
|
+
}
|
|
2192
|
+
}, [editor, visible]);
|
|
2193
|
+
const treeData = useVariableTree({});
|
|
2194
|
+
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(
|
|
2195
|
+
import_semi_ui11.Popover,
|
|
2196
|
+
{
|
|
2197
|
+
visible,
|
|
2198
|
+
trigger: "custom",
|
|
2199
|
+
position: "topLeft",
|
|
2200
|
+
rePosKey: posKey,
|
|
2201
|
+
content: /* @__PURE__ */ import_react26.default.createElement("div", { style: { width: 300 } }, /* @__PURE__ */ import_react26.default.createElement(
|
|
2202
|
+
import_semi_ui11.Tree,
|
|
2203
|
+
{
|
|
2204
|
+
treeData,
|
|
2205
|
+
onSelect: (v) => {
|
|
2206
|
+
insert(v);
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
))
|
|
2210
|
+
},
|
|
2211
|
+
/* @__PURE__ */ import_react26.default.createElement(
|
|
2212
|
+
import_react27.PositionMirror,
|
|
2213
|
+
{
|
|
2214
|
+
position,
|
|
2215
|
+
onChange: () => setPosKey(String(Math.random()))
|
|
2216
|
+
}
|
|
2217
|
+
)
|
|
2218
|
+
));
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
// src/components/prompt-editor-with-variables/extensions/variable-tag.tsx
|
|
2222
|
+
var import_react28 = __toESM(require("react"));
|
|
2223
|
+
var import_client = require("react-dom/client");
|
|
2224
|
+
var import_lodash4 = require("lodash");
|
|
2225
|
+
var import_editor7 = require("@flowgram.ai/editor");
|
|
2226
|
+
var import_semi_ui13 = require("@douyinfe/semi-ui");
|
|
2227
|
+
var import_semi_icons9 = require("@douyinfe/semi-icons");
|
|
2228
|
+
var import_react29 = require("@coze-editor/editor/react");
|
|
2229
|
+
var import_view3 = require("@codemirror/view");
|
|
2230
|
+
|
|
2231
|
+
// src/components/prompt-editor-with-variables/styles.tsx
|
|
2232
|
+
var import_styled_components7 = __toESM(require("styled-components"));
|
|
2233
|
+
var import_semi_ui12 = require("@douyinfe/semi-ui");
|
|
2234
|
+
var UIRootTitle2 = import_styled_components7.default.div`
|
|
2235
|
+
margin-right: 4px;
|
|
2236
|
+
min-width: 20px;
|
|
2237
|
+
overflow: hidden;
|
|
2238
|
+
text-overflow: ellipsis;
|
|
2239
|
+
white-space: nowrap;
|
|
2240
|
+
color: var(--semi-color-text-2);
|
|
2241
|
+
`;
|
|
2242
|
+
var UIVarName2 = import_styled_components7.default.div`
|
|
2243
|
+
overflow: hidden;
|
|
2244
|
+
text-overflow: ellipsis;
|
|
2245
|
+
white-space: nowrap;
|
|
2246
|
+
`;
|
|
2247
|
+
var UITag2 = (0, import_styled_components7.default)(import_semi_ui12.Tag)`
|
|
2248
|
+
display: inline-flex;
|
|
2249
|
+
align-items: center;
|
|
2250
|
+
justify-content: flex-start;
|
|
2251
|
+
max-width: 300px;
|
|
2252
|
+
|
|
2253
|
+
& .semi-tag-content-center {
|
|
2254
|
+
justify-content: flex-start;
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
&.semi-tag {
|
|
2258
|
+
margin: 0 5px;
|
|
2259
|
+
}
|
|
2260
|
+
`;
|
|
2261
|
+
var UIPopoverContent = import_styled_components7.default.div`
|
|
2262
|
+
padding: 10px;
|
|
2263
|
+
display: inline-flex;
|
|
2264
|
+
align-items: center;
|
|
2265
|
+
justify-content: flex-start;
|
|
2266
|
+
`;
|
|
2267
|
+
|
|
2268
|
+
// src/components/prompt-editor-with-variables/extensions/variable-tag.tsx
|
|
2269
|
+
var VariableTagWidget = class extends import_view3.WidgetType {
|
|
2270
|
+
constructor({ keyPath, scope }) {
|
|
2271
|
+
super();
|
|
2272
|
+
this.toDispose = new import_editor7.DisposableCollection();
|
|
2273
|
+
this.renderIcon = (icon) => {
|
|
2274
|
+
if (typeof icon === "string") {
|
|
2275
|
+
return /* @__PURE__ */ import_react28.default.createElement("img", { style: { marginRight: 8 }, width: 12, height: 12, src: icon });
|
|
2276
|
+
}
|
|
2277
|
+
return icon;
|
|
2278
|
+
};
|
|
2279
|
+
this.keyPath = keyPath;
|
|
2280
|
+
this.scope = scope;
|
|
2281
|
+
}
|
|
2282
|
+
renderVariable(v) {
|
|
2283
|
+
if (!v) {
|
|
2284
|
+
this.root.render(
|
|
2285
|
+
/* @__PURE__ */ import_react28.default.createElement(UITag2, { prefixIcon: /* @__PURE__ */ import_react28.default.createElement(import_semi_icons9.IconIssueStroked, null), color: "amber" }, "Unknown")
|
|
2286
|
+
);
|
|
2287
|
+
return;
|
|
2288
|
+
}
|
|
2289
|
+
const rootField = (0, import_lodash4.last)(v.parentFields);
|
|
2290
|
+
const rootTitle = /* @__PURE__ */ import_react28.default.createElement(UIRootTitle2, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
|
|
2291
|
+
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
2292
|
+
this.root.render(
|
|
2293
|
+
/* @__PURE__ */ import_react28.default.createElement(
|
|
2294
|
+
import_semi_ui13.Popover,
|
|
2295
|
+
{
|
|
2296
|
+
content: /* @__PURE__ */ import_react28.default.createElement(UIPopoverContent, null, rootIcon, rootTitle, /* @__PURE__ */ import_react28.default.createElement(UIVarName2, null, v?.keyPath.slice(1).join(".")))
|
|
2297
|
+
},
|
|
2298
|
+
/* @__PURE__ */ import_react28.default.createElement(UITag2, { prefixIcon: rootIcon }, rootTitle, /* @__PURE__ */ import_react28.default.createElement(UIVarName2, null, v?.key))
|
|
2299
|
+
)
|
|
2300
|
+
);
|
|
2301
|
+
}
|
|
2302
|
+
toDOM(view) {
|
|
2303
|
+
const dom = document.createElement("span");
|
|
2304
|
+
this.root = (0, import_client.createRoot)(dom);
|
|
2305
|
+
this.toDispose.push(
|
|
2306
|
+
import_editor7.Disposable.create(() => {
|
|
2307
|
+
this.root.unmount();
|
|
2308
|
+
})
|
|
2309
|
+
);
|
|
2310
|
+
this.toDispose.push(
|
|
2311
|
+
this.scope.available.trackByKeyPath(
|
|
2312
|
+
this.keyPath,
|
|
2313
|
+
(v) => {
|
|
2314
|
+
this.renderVariable(v);
|
|
2315
|
+
},
|
|
2316
|
+
{ triggerOnInit: false }
|
|
2317
|
+
)
|
|
2318
|
+
);
|
|
2319
|
+
this.renderVariable(this.scope.available.getByKeyPath(this.keyPath));
|
|
2320
|
+
return dom;
|
|
2321
|
+
}
|
|
2322
|
+
eq(other) {
|
|
2323
|
+
return (0, import_lodash4.isEqual)(this.keyPath, other.keyPath);
|
|
2324
|
+
}
|
|
2325
|
+
ignoreEvent() {
|
|
2326
|
+
return false;
|
|
2327
|
+
}
|
|
2328
|
+
destroy(dom) {
|
|
2329
|
+
this.toDispose.dispose();
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
function VariableTagInject() {
|
|
2333
|
+
const injector = (0, import_react29.useInjector)();
|
|
2334
|
+
const scope = (0, import_editor7.useCurrentScope)();
|
|
2335
|
+
(0, import_react28.useLayoutEffect)(() => {
|
|
2336
|
+
const atMatcher = new import_view3.MatchDecorator({
|
|
2337
|
+
regexp: /\{\{([^\}]+)\}\}/g,
|
|
2338
|
+
decoration: (match) => import_view3.Decoration.replace({
|
|
2339
|
+
widget: new VariableTagWidget({
|
|
2340
|
+
keyPath: match[1]?.split(".") ?? [],
|
|
2341
|
+
scope
|
|
2342
|
+
})
|
|
2343
|
+
})
|
|
2344
|
+
});
|
|
2345
|
+
return injector.inject([
|
|
2346
|
+
import_view3.ViewPlugin.fromClass(
|
|
2347
|
+
class {
|
|
2348
|
+
constructor(view) {
|
|
2349
|
+
this.view = view;
|
|
2350
|
+
this.decorations = atMatcher.createDeco(view);
|
|
2351
|
+
}
|
|
2352
|
+
update() {
|
|
2353
|
+
this.decorations = atMatcher.createDeco(this.view);
|
|
2354
|
+
}
|
|
2355
|
+
},
|
|
2356
|
+
{
|
|
2357
|
+
decorations: (p) => p.decorations,
|
|
2358
|
+
provide(p) {
|
|
2359
|
+
return import_view3.EditorView.atomicRanges.of(
|
|
2360
|
+
(view) => view.plugin(p)?.decorations ?? import_view3.Decoration.none
|
|
2361
|
+
);
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
)
|
|
2365
|
+
]);
|
|
2366
|
+
}, [injector]);
|
|
2367
|
+
return null;
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
// src/components/prompt-editor-with-variables/index.tsx
|
|
2371
|
+
function PromptEditorWithVariables(props) {
|
|
2372
|
+
return /* @__PURE__ */ import_react30.default.createElement(PromptEditor, { ...props }, /* @__PURE__ */ import_react30.default.createElement(VariableTree, null), /* @__PURE__ */ import_react30.default.createElement(VariableTagInject, null));
|
|
2373
|
+
}
|
|
2374
|
+
|
|
1975
2375
|
// src/effects/provide-batch-input/index.ts
|
|
1976
|
-
var
|
|
1977
|
-
var provideBatchInputEffect = (0,
|
|
2376
|
+
var import_editor8 = require("@flowgram.ai/editor");
|
|
2377
|
+
var provideBatchInputEffect = (0, import_editor8.createEffectFromVariableProvider)({
|
|
1978
2378
|
private: true,
|
|
1979
2379
|
parse: (value, ctx) => [
|
|
1980
|
-
|
|
2380
|
+
import_editor8.ASTFactory.createVariableDeclaration({
|
|
1981
2381
|
key: `${ctx.node.id}_locals`,
|
|
1982
2382
|
meta: {
|
|
1983
|
-
title: (0,
|
|
2383
|
+
title: (0, import_editor8.getNodeForm)(ctx.node)?.getValueIn("title"),
|
|
1984
2384
|
icon: ctx.node.getNodeRegistry().info?.icon
|
|
1985
2385
|
},
|
|
1986
|
-
type:
|
|
2386
|
+
type: import_editor8.ASTFactory.createObject({
|
|
1987
2387
|
properties: [
|
|
1988
|
-
|
|
2388
|
+
import_editor8.ASTFactory.createProperty({
|
|
1989
2389
|
key: "item",
|
|
1990
|
-
initializer:
|
|
1991
|
-
enumerateFor:
|
|
2390
|
+
initializer: import_editor8.ASTFactory.createEnumerateExpression({
|
|
2391
|
+
enumerateFor: import_editor8.ASTFactory.createKeyPathExpression({
|
|
1992
2392
|
keyPath: value.content || []
|
|
1993
2393
|
})
|
|
1994
2394
|
})
|
|
1995
2395
|
}),
|
|
1996
|
-
|
|
2396
|
+
import_editor8.ASTFactory.createProperty({
|
|
1997
2397
|
key: "index",
|
|
1998
|
-
type:
|
|
2398
|
+
type: import_editor8.ASTFactory.createNumber()
|
|
1999
2399
|
})
|
|
2000
2400
|
]
|
|
2001
2401
|
})
|
|
@@ -2004,21 +2404,21 @@ var provideBatchInputEffect = (0, import_editor5.createEffectFromVariableProvide
|
|
|
2004
2404
|
});
|
|
2005
2405
|
|
|
2006
2406
|
// src/effects/provide-batch-outputs/index.ts
|
|
2007
|
-
var
|
|
2008
|
-
var provideBatchOutputsEffect = (0,
|
|
2407
|
+
var import_editor9 = require("@flowgram.ai/editor");
|
|
2408
|
+
var provideBatchOutputsEffect = (0, import_editor9.createEffectFromVariableProvider)({
|
|
2009
2409
|
parse: (value, ctx) => [
|
|
2010
|
-
|
|
2410
|
+
import_editor9.ASTFactory.createVariableDeclaration({
|
|
2011
2411
|
key: `${ctx.node.id}`,
|
|
2012
2412
|
meta: {
|
|
2013
|
-
title: (0,
|
|
2413
|
+
title: (0, import_editor9.getNodeForm)(ctx.node)?.getValueIn("title"),
|
|
2014
2414
|
icon: ctx.node.getNodeRegistry().info?.icon
|
|
2015
2415
|
},
|
|
2016
|
-
type:
|
|
2416
|
+
type: import_editor9.ASTFactory.createObject({
|
|
2017
2417
|
properties: Object.entries(value).map(
|
|
2018
|
-
([_key, value2]) =>
|
|
2418
|
+
([_key, value2]) => import_editor9.ASTFactory.createProperty({
|
|
2019
2419
|
key: _key,
|
|
2020
|
-
initializer:
|
|
2021
|
-
wrapFor:
|
|
2420
|
+
initializer: import_editor9.ASTFactory.createWrapArrayExpression({
|
|
2421
|
+
wrapFor: import_editor9.ASTFactory.createKeyPathExpression({
|
|
2022
2422
|
keyPath: value2.content || []
|
|
2023
2423
|
})
|
|
2024
2424
|
})
|
|
@@ -2030,14 +2430,14 @@ var provideBatchOutputsEffect = (0, import_editor6.createEffectFromVariableProvi
|
|
|
2030
2430
|
});
|
|
2031
2431
|
|
|
2032
2432
|
// src/effects/auto-rename-ref/index.ts
|
|
2033
|
-
var
|
|
2034
|
-
var
|
|
2433
|
+
var import_lodash5 = require("lodash");
|
|
2434
|
+
var import_editor10 = require("@flowgram.ai/editor");
|
|
2035
2435
|
var autoRenameRefEffect = [
|
|
2036
2436
|
{
|
|
2037
|
-
event:
|
|
2437
|
+
event: import_editor10.DataEvent.onValueInit,
|
|
2038
2438
|
effect: (params) => {
|
|
2039
2439
|
const { context, form, name } = params;
|
|
2040
|
-
const renameService = context.node.getService(
|
|
2440
|
+
const renameService = context.node.getService(import_editor10.VariableFieldKeyRenameService);
|
|
2041
2441
|
const disposable = renameService.onRename(({ before, after }) => {
|
|
2042
2442
|
const beforeKeyPath = [
|
|
2043
2443
|
...before.parentFields.map((_field) => _field.key).reverse(),
|
|
@@ -2067,7 +2467,7 @@ function isRef(value) {
|
|
|
2067
2467
|
return value?.type === "ref" && Array.isArray(value?.content) && typeof value?.content[0] === "string";
|
|
2068
2468
|
}
|
|
2069
2469
|
function traverseRef(name, value, cb) {
|
|
2070
|
-
if ((0,
|
|
2470
|
+
if ((0, import_lodash5.isObject)(value)) {
|
|
2071
2471
|
if (isRef(value)) {
|
|
2072
2472
|
cb(name, value);
|
|
2073
2473
|
return;
|
|
@@ -2077,7 +2477,7 @@ function traverseRef(name, value, cb) {
|
|
|
2077
2477
|
});
|
|
2078
2478
|
return;
|
|
2079
2479
|
}
|
|
2080
|
-
if ((0,
|
|
2480
|
+
if ((0, import_lodash5.isArray)(value)) {
|
|
2081
2481
|
value.forEach((_value, idx) => {
|
|
2082
2482
|
traverseRef(`${name}[${idx}]`, _value, cb);
|
|
2083
2483
|
});
|
|
@@ -2087,13 +2487,13 @@ function traverseRef(name, value, cb) {
|
|
|
2087
2487
|
}
|
|
2088
2488
|
|
|
2089
2489
|
// src/effects/provide-json-schema-outputs/index.ts
|
|
2090
|
-
var
|
|
2091
|
-
var provideJsonSchemaOutputs = (0,
|
|
2490
|
+
var import_editor11 = require("@flowgram.ai/editor");
|
|
2491
|
+
var provideJsonSchemaOutputs = (0, import_editor11.createEffectFromVariableProvider)({
|
|
2092
2492
|
parse: (value, ctx) => [
|
|
2093
|
-
|
|
2493
|
+
import_editor11.ASTFactory.createVariableDeclaration({
|
|
2094
2494
|
key: `${ctx.node.id}`,
|
|
2095
2495
|
meta: {
|
|
2096
|
-
title: (0,
|
|
2496
|
+
title: (0, import_editor11.getNodeForm)(ctx.node)?.getValueIn("title") || ctx.node.id,
|
|
2097
2497
|
icon: ctx.node.getNodeRegistry().info?.icon
|
|
2098
2498
|
},
|
|
2099
2499
|
type: JsonSchemaUtils.schemaToAST(value)
|
|
@@ -2102,12 +2502,12 @@ var provideJsonSchemaOutputs = (0, import_editor8.createEffectFromVariableProvid
|
|
|
2102
2502
|
});
|
|
2103
2503
|
|
|
2104
2504
|
// src/effects/sync-variable-title/index.ts
|
|
2105
|
-
var
|
|
2505
|
+
var import_editor12 = require("@flowgram.ai/editor");
|
|
2106
2506
|
var syncVariableTitle = [
|
|
2107
2507
|
{
|
|
2108
|
-
event:
|
|
2508
|
+
event: import_editor12.DataEvent.onValueChange,
|
|
2109
2509
|
effect: ({ value, context }) => {
|
|
2110
|
-
context.node.getData(
|
|
2510
|
+
context.node.getData(import_editor12.FlowNodeVariableData).allScopes.forEach((_scope) => {
|
|
2111
2511
|
_scope.output.variables.forEach((_var) => {
|
|
2112
2512
|
_var.updateMeta({
|
|
2113
2513
|
title: value || context.node.id,
|
|
@@ -2120,21 +2520,21 @@ var syncVariableTitle = [
|
|
|
2120
2520
|
];
|
|
2121
2521
|
|
|
2122
2522
|
// src/form-plugins/batch-outputs-plugin/index.ts
|
|
2123
|
-
var
|
|
2124
|
-
var provideBatchOutputsEffect2 = (0,
|
|
2523
|
+
var import_editor13 = require("@flowgram.ai/editor");
|
|
2524
|
+
var provideBatchOutputsEffect2 = (0, import_editor13.createEffectFromVariableProvider)({
|
|
2125
2525
|
parse: (value, ctx) => [
|
|
2126
|
-
|
|
2526
|
+
import_editor13.ASTFactory.createVariableDeclaration({
|
|
2127
2527
|
key: `${ctx.node.id}`,
|
|
2128
2528
|
meta: {
|
|
2129
|
-
title: (0,
|
|
2529
|
+
title: (0, import_editor13.getNodeForm)(ctx.node)?.getValueIn("title"),
|
|
2130
2530
|
icon: ctx.node.getNodeRegistry().info?.icon
|
|
2131
2531
|
},
|
|
2132
|
-
type:
|
|
2532
|
+
type: import_editor13.ASTFactory.createObject({
|
|
2133
2533
|
properties: Object.entries(value).map(
|
|
2134
|
-
([_key, value2]) =>
|
|
2534
|
+
([_key, value2]) => import_editor13.ASTFactory.createProperty({
|
|
2135
2535
|
key: _key,
|
|
2136
|
-
initializer:
|
|
2137
|
-
wrapFor:
|
|
2536
|
+
initializer: import_editor13.ASTFactory.createWrapArrayExpression({
|
|
2537
|
+
wrapFor: import_editor13.ASTFactory.createKeyPathExpression({
|
|
2138
2538
|
keyPath: value2?.content || []
|
|
2139
2539
|
})
|
|
2140
2540
|
})
|
|
@@ -2144,7 +2544,7 @@ var provideBatchOutputsEffect2 = (0, import_editor10.createEffectFromVariablePro
|
|
|
2144
2544
|
})
|
|
2145
2545
|
]
|
|
2146
2546
|
});
|
|
2147
|
-
var createBatchOutputsFormPlugin = (0,
|
|
2547
|
+
var createBatchOutputsFormPlugin = (0, import_editor13.defineFormPluginCreator)({
|
|
2148
2548
|
name: "batch-outputs-plugin",
|
|
2149
2549
|
onSetupFormMeta({ mergeEffect }, { outputKey }) {
|
|
2150
2550
|
mergeEffect({
|
|
@@ -2152,7 +2552,7 @@ var createBatchOutputsFormPlugin = (0, import_editor10.defineFormPluginCreator)(
|
|
|
2152
2552
|
});
|
|
2153
2553
|
},
|
|
2154
2554
|
onInit(ctx, { outputKey }) {
|
|
2155
|
-
const chainTransformService = ctx.node.getService(
|
|
2555
|
+
const chainTransformService = ctx.node.getService(import_editor13.ScopeChainTransformService);
|
|
2156
2556
|
const batchNodeType = ctx.node.flowNodeType;
|
|
2157
2557
|
const transformerId = `${batchNodeType}-outputs`;
|
|
2158
2558
|
if (chainTransformService.hasTransformer(transformerId)) {
|
|
@@ -2162,21 +2562,21 @@ var createBatchOutputsFormPlugin = (0, import_editor10.defineFormPluginCreator)(
|
|
|
2162
2562
|
transformCovers: (covers, ctx2) => {
|
|
2163
2563
|
const node = ctx2.scope.meta?.node;
|
|
2164
2564
|
if (node?.parent?.flowNodeType === batchNodeType) {
|
|
2165
|
-
return [...covers, (0,
|
|
2565
|
+
return [...covers, (0, import_editor13.getNodeScope)(node.parent)];
|
|
2166
2566
|
}
|
|
2167
2567
|
return covers;
|
|
2168
2568
|
},
|
|
2169
2569
|
transformDeps(scopes, ctx2) {
|
|
2170
2570
|
const scopeMeta = ctx2.scope.meta;
|
|
2171
|
-
if (scopeMeta?.type ===
|
|
2571
|
+
if (scopeMeta?.type === import_editor13.FlowNodeScopeType.private) {
|
|
2172
2572
|
return scopes;
|
|
2173
2573
|
}
|
|
2174
2574
|
const node = scopeMeta?.node;
|
|
2175
2575
|
if (node?.flowNodeType === batchNodeType) {
|
|
2176
2576
|
const childBlocks = node.blocks;
|
|
2177
2577
|
return [
|
|
2178
|
-
(0,
|
|
2179
|
-
...childBlocks.map((_childBlock) => (0,
|
|
2578
|
+
(0, import_editor13.getNodePrivateScope)(node),
|
|
2579
|
+
...childBlocks.map((_childBlock) => (0, import_editor13.getNodeScope)(_childBlock))
|
|
2180
2580
|
];
|
|
2181
2581
|
}
|
|
2182
2582
|
return scopes;
|
|
@@ -2194,6 +2594,8 @@ var createBatchOutputsFormPlugin = (0, import_editor10.defineFormPluginCreator)(
|
|
|
2194
2594
|
DynamicValueInput,
|
|
2195
2595
|
JsonSchemaEditor,
|
|
2196
2596
|
JsonSchemaUtils,
|
|
2597
|
+
PromptEditor,
|
|
2598
|
+
PromptEditorWithVariables,
|
|
2197
2599
|
TypeSelector,
|
|
2198
2600
|
VariableSelector,
|
|
2199
2601
|
VariableTypeIcons,
|