@flowgram.ai/form-materials 0.2.22 → 0.2.23
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/index.ts +6 -1
- package/bin/materials.ts +15 -1
- package/dist/esm/index.js +93 -21
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +79 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/code-editor/index.tsx +32 -2
- package/src/components/code-editor/theme/light.ts +1 -1
- package/src/components/json-editor-with-variables/index.tsx +47 -1
- package/src/components/json-schema-editor/config.json +10 -2
- package/src/components/prompt-editor/index.tsx +14 -2
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +12 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React$1 from 'react';
|
|
2
2
|
import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
3
|
+
import { InferValues } from '@coze-editor/editor/react';
|
|
4
|
+
import preset from '@coze-editor/editor/preset-code';
|
|
3
5
|
import { EffectOptions, ASTNodeJSON, ASTNode, BaseType, FormPluginCreator } from '@flowgram.ai/editor';
|
|
4
6
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
5
7
|
|
|
@@ -299,13 +301,19 @@ declare function PromptEditorWithInputs({ inputsValues, ...restProps }: PropsTyp
|
|
|
299
301
|
* SPDX-License-Identifier: MIT
|
|
300
302
|
*/
|
|
301
303
|
|
|
304
|
+
type Preset = typeof preset;
|
|
305
|
+
type Options = Partial<InferValues<Preset[number]>>;
|
|
302
306
|
interface CodeEditorPropsType extends React$1.PropsWithChildren<{}> {
|
|
303
307
|
value?: string;
|
|
304
308
|
onChange?: (value: string) => void;
|
|
305
309
|
languageId: 'python' | 'typescript' | 'shell' | 'json';
|
|
306
310
|
theme?: 'dark' | 'light';
|
|
311
|
+
placeholder?: string;
|
|
312
|
+
activeLinePlaceholder?: string;
|
|
313
|
+
readonly?: boolean;
|
|
314
|
+
options?: Options;
|
|
307
315
|
}
|
|
308
|
-
declare function CodeEditor({ value, onChange, languageId, theme, children, }: CodeEditorPropsType): React$1.JSX.Element;
|
|
316
|
+
declare function CodeEditor({ value, onChange, languageId, theme, children, placeholder, activeLinePlaceholder, options, readonly, }: CodeEditorPropsType): React$1.JSX.Element;
|
|
309
317
|
|
|
310
318
|
/**
|
|
311
319
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React$1 from 'react';
|
|
2
2
|
import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
3
|
+
import { InferValues } from '@coze-editor/editor/react';
|
|
4
|
+
import preset from '@coze-editor/editor/preset-code';
|
|
3
5
|
import { EffectOptions, ASTNodeJSON, ASTNode, BaseType, FormPluginCreator } from '@flowgram.ai/editor';
|
|
4
6
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
5
7
|
|
|
@@ -299,13 +301,19 @@ declare function PromptEditorWithInputs({ inputsValues, ...restProps }: PropsTyp
|
|
|
299
301
|
* SPDX-License-Identifier: MIT
|
|
300
302
|
*/
|
|
301
303
|
|
|
304
|
+
type Preset = typeof preset;
|
|
305
|
+
type Options = Partial<InferValues<Preset[number]>>;
|
|
302
306
|
interface CodeEditorPropsType extends React$1.PropsWithChildren<{}> {
|
|
303
307
|
value?: string;
|
|
304
308
|
onChange?: (value: string) => void;
|
|
305
309
|
languageId: 'python' | 'typescript' | 'shell' | 'json';
|
|
306
310
|
theme?: 'dark' | 'light';
|
|
311
|
+
placeholder?: string;
|
|
312
|
+
activeLinePlaceholder?: string;
|
|
313
|
+
readonly?: boolean;
|
|
314
|
+
options?: Options;
|
|
307
315
|
}
|
|
308
|
-
declare function CodeEditor({ value, onChange, languageId, theme, children, }: CodeEditorPropsType): React$1.JSX.Element;
|
|
316
|
+
declare function CodeEditor({ value, onChange, languageId, theme, children, placeholder, activeLinePlaceholder, options, readonly, }: CodeEditorPropsType): React$1.JSX.Element;
|
|
309
317
|
|
|
310
318
|
/**
|
|
311
319
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
package/dist/index.js
CHANGED
|
@@ -2154,9 +2154,18 @@ function PromptEditor(props) {
|
|
|
2154
2154
|
hasError,
|
|
2155
2155
|
children
|
|
2156
2156
|
} = props || {};
|
|
2157
|
+
const editorRef = (0, import_react24.useRef)(null);
|
|
2158
|
+
(0, import_react24.useEffect)(() => {
|
|
2159
|
+
if (editorRef.current?.getValue() !== value?.content) {
|
|
2160
|
+
editorRef.current?.setValue(String(value?.content || ""));
|
|
2161
|
+
}
|
|
2162
|
+
}, [value]);
|
|
2157
2163
|
return /* @__PURE__ */ import_react24.default.createElement(UIContainer4, { $hasError: hasError, style }, /* @__PURE__ */ import_react24.default.createElement(import_react25.EditorProvider, null, /* @__PURE__ */ import_react24.default.createElement(
|
|
2158
2164
|
import_react25.Renderer,
|
|
2159
2165
|
{
|
|
2166
|
+
didMount: (editor) => {
|
|
2167
|
+
editorRef.current = editor;
|
|
2168
|
+
},
|
|
2160
2169
|
plugins: import_preset_prompt2.default,
|
|
2161
2170
|
defaultValue: String(value?.content),
|
|
2162
2171
|
options: {
|
|
@@ -2232,8 +2241,8 @@ function VariableTree() {
|
|
|
2232
2241
|
}
|
|
2233
2242
|
|
|
2234
2243
|
// src/components/prompt-editor-with-variables/extensions/variable-tag.tsx
|
|
2244
|
+
var import_react_dom = __toESM(require("react-dom"));
|
|
2235
2245
|
var import_react28 = __toESM(require("react"));
|
|
2236
|
-
var import_client = require("react-dom/client");
|
|
2237
2246
|
var import_lodash4 = require("lodash");
|
|
2238
2247
|
var import_editor7 = require("@flowgram.ai/editor");
|
|
2239
2248
|
var import_semi_ui13 = require("@douyinfe/semi-ui");
|
|
@@ -2292,9 +2301,12 @@ var VariableTagWidget = class extends import_view3.WidgetType {
|
|
|
2292
2301
|
this.keyPath = keyPath;
|
|
2293
2302
|
this.scope = scope;
|
|
2294
2303
|
}
|
|
2304
|
+
renderReact(jsx) {
|
|
2305
|
+
import_react_dom.default.render(jsx, this.rootDOM);
|
|
2306
|
+
}
|
|
2295
2307
|
renderVariable(v) {
|
|
2296
2308
|
if (!v) {
|
|
2297
|
-
this.
|
|
2309
|
+
this.renderReact(
|
|
2298
2310
|
/* @__PURE__ */ import_react28.default.createElement(UITag2, { prefixIcon: /* @__PURE__ */ import_react28.default.createElement(import_semi_icons9.IconIssueStroked, null), color: "amber" }, "Unknown")
|
|
2299
2311
|
);
|
|
2300
2312
|
return;
|
|
@@ -2302,7 +2314,7 @@ var VariableTagWidget = class extends import_view3.WidgetType {
|
|
|
2302
2314
|
const rootField = (0, import_lodash4.last)(v.parentFields);
|
|
2303
2315
|
const rootTitle = /* @__PURE__ */ import_react28.default.createElement(UIRootTitle2, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
|
|
2304
2316
|
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
2305
|
-
this.
|
|
2317
|
+
this.renderReact(
|
|
2306
2318
|
/* @__PURE__ */ import_react28.default.createElement(
|
|
2307
2319
|
import_semi_ui13.Popover,
|
|
2308
2320
|
{
|
|
@@ -2314,10 +2326,10 @@ var VariableTagWidget = class extends import_view3.WidgetType {
|
|
|
2314
2326
|
}
|
|
2315
2327
|
toDOM(view) {
|
|
2316
2328
|
const dom = document.createElement("span");
|
|
2317
|
-
this.
|
|
2329
|
+
this.rootDOM = dom;
|
|
2318
2330
|
this.toDispose.push(
|
|
2319
2331
|
import_editor7.Disposable.create(() => {
|
|
2320
|
-
|
|
2332
|
+
import_react_dom.default.unmountComponentAtNode(this.rootDOM);
|
|
2321
2333
|
})
|
|
2322
2334
|
);
|
|
2323
2335
|
this.toDispose.push(
|
|
@@ -2563,7 +2575,7 @@ var lightTheme = (0, import_preset_code.createTheme)({
|
|
|
2563
2575
|
gutterBorderColor: "transparent",
|
|
2564
2576
|
gutterBorderWidth: 0,
|
|
2565
2577
|
lineHighlight: "#f0f0f0",
|
|
2566
|
-
bracketColors: ["#
|
|
2578
|
+
bracketColors: ["#FFD700", "#DD99FF", "#78B0FF"],
|
|
2567
2579
|
tooltip: {
|
|
2568
2580
|
backgroundColor: "#f0f0f0",
|
|
2569
2581
|
color: "#000",
|
|
@@ -2793,9 +2805,18 @@ function CodeEditor({
|
|
|
2793
2805
|
onChange,
|
|
2794
2806
|
languageId = "python",
|
|
2795
2807
|
theme = "light",
|
|
2796
|
-
children
|
|
2808
|
+
children,
|
|
2809
|
+
placeholder,
|
|
2810
|
+
activeLinePlaceholder,
|
|
2811
|
+
options: options2,
|
|
2812
|
+
readonly
|
|
2797
2813
|
}) {
|
|
2798
2814
|
const editorRef = (0, import_react35.useRef)(null);
|
|
2815
|
+
(0, import_react35.useEffect)(() => {
|
|
2816
|
+
if (editorRef.current?.getValue() !== value) {
|
|
2817
|
+
editorRef.current?.setValue(String(value || ""));
|
|
2818
|
+
}
|
|
2819
|
+
}, [value]);
|
|
2799
2820
|
return /* @__PURE__ */ import_react35.default.createElement(import_react36.EditorProvider, null, /* @__PURE__ */ import_react35.default.createElement(
|
|
2800
2821
|
OriginCodeEditor,
|
|
2801
2822
|
{
|
|
@@ -2803,19 +2824,25 @@ function CodeEditor({
|
|
|
2803
2824
|
options: {
|
|
2804
2825
|
uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
|
|
2805
2826
|
languageId,
|
|
2806
|
-
theme
|
|
2827
|
+
theme,
|
|
2828
|
+
placeholder,
|
|
2829
|
+
readOnly: readonly,
|
|
2830
|
+
editable: !readonly,
|
|
2831
|
+
...options2 || {}
|
|
2807
2832
|
},
|
|
2808
2833
|
didMount: (editor) => {
|
|
2809
2834
|
editorRef.current = editor;
|
|
2810
2835
|
},
|
|
2811
2836
|
onChange: (e) => onChange?.(e.value)
|
|
2812
2837
|
},
|
|
2838
|
+
activeLinePlaceholder && /* @__PURE__ */ import_react35.default.createElement(import_react36.ActiveLinePlaceholder, null, activeLinePlaceholder),
|
|
2813
2839
|
children
|
|
2814
2840
|
));
|
|
2815
2841
|
}
|
|
2816
2842
|
|
|
2817
2843
|
// src/components/json-editor-with-variables/index.tsx
|
|
2818
2844
|
var import_react41 = __toESM(require("react"));
|
|
2845
|
+
var import_preset_code6 = require("@coze-editor/editor/preset-code");
|
|
2819
2846
|
|
|
2820
2847
|
// src/components/json-editor-with-variables/extensions/variable-tree.tsx
|
|
2821
2848
|
var import_react37 = __toESM(require("react"));
|
|
@@ -2876,7 +2903,7 @@ function VariableTree2() {
|
|
|
2876
2903
|
|
|
2877
2904
|
// src/components/json-editor-with-variables/extensions/variable-tag.tsx
|
|
2878
2905
|
var import_react39 = __toESM(require("react"));
|
|
2879
|
-
var
|
|
2906
|
+
var import_client = require("react-dom/client");
|
|
2880
2907
|
var import_lodash6 = require("lodash");
|
|
2881
2908
|
var import_editor10 = require("@flowgram.ai/editor");
|
|
2882
2909
|
var import_semi_ui18 = require("@douyinfe/semi-ui");
|
|
@@ -2957,7 +2984,7 @@ var VariableTagWidget2 = class extends import_view5.WidgetType {
|
|
|
2957
2984
|
}
|
|
2958
2985
|
toDOM(view) {
|
|
2959
2986
|
const dom = document.createElement("span");
|
|
2960
|
-
this.root = (0,
|
|
2987
|
+
this.root = (0, import_client.createRoot)(dom);
|
|
2961
2988
|
this.toDispose.push(
|
|
2962
2989
|
import_editor10.Disposable.create(() => {
|
|
2963
2990
|
this.root.unmount();
|
|
@@ -3024,8 +3051,49 @@ function VariableTagInject2() {
|
|
|
3024
3051
|
}
|
|
3025
3052
|
|
|
3026
3053
|
// src/components/json-editor-with-variables/index.tsx
|
|
3054
|
+
function findAllMatches(inputString, regex) {
|
|
3055
|
+
const globalRegex = new RegExp(
|
|
3056
|
+
regex,
|
|
3057
|
+
regex.flags.includes("g") ? regex.flags : regex.flags + "g"
|
|
3058
|
+
);
|
|
3059
|
+
let match;
|
|
3060
|
+
const matches = [];
|
|
3061
|
+
while ((match = globalRegex.exec(inputString)) !== null) {
|
|
3062
|
+
if (match.index === globalRegex.lastIndex) {
|
|
3063
|
+
globalRegex.lastIndex++;
|
|
3064
|
+
}
|
|
3065
|
+
matches.push({
|
|
3066
|
+
match: match[0],
|
|
3067
|
+
range: [match.index, match.index + match[0].length]
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
return matches;
|
|
3071
|
+
}
|
|
3072
|
+
var transformer = (0, import_preset_code6.transformerCreator)((text) => {
|
|
3073
|
+
const originalSource = text.toString();
|
|
3074
|
+
const matches = findAllMatches(originalSource, /\{\{([^\}]*)\}\}/g);
|
|
3075
|
+
if (matches.length > 0) {
|
|
3076
|
+
matches.forEach(({ range }) => {
|
|
3077
|
+
text.replaceRange(range[0], range[1], "null");
|
|
3078
|
+
});
|
|
3079
|
+
}
|
|
3080
|
+
return text;
|
|
3081
|
+
});
|
|
3027
3082
|
function JsonEditorWithVariables(props) {
|
|
3028
|
-
return /* @__PURE__ */ import_react41.default.createElement(
|
|
3083
|
+
return /* @__PURE__ */ import_react41.default.createElement(
|
|
3084
|
+
CodeEditor,
|
|
3085
|
+
{
|
|
3086
|
+
languageId: "json",
|
|
3087
|
+
activeLinePlaceholder: "Press '@' to Select variable",
|
|
3088
|
+
...props,
|
|
3089
|
+
options: {
|
|
3090
|
+
transformer,
|
|
3091
|
+
...props.options || {}
|
|
3092
|
+
}
|
|
3093
|
+
},
|
|
3094
|
+
/* @__PURE__ */ import_react41.default.createElement(VariableTree2, null),
|
|
3095
|
+
/* @__PURE__ */ import_react41.default.createElement(VariableTagInject2, null)
|
|
3096
|
+
);
|
|
3029
3097
|
}
|
|
3030
3098
|
|
|
3031
3099
|
// src/effects/provide-batch-input/index.ts
|