@flowgram.ai/form-materials 0.2.21 → 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/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
 
@@ -264,6 +266,8 @@ type PropsType$1 = React$1.PropsWithChildren<{
264
266
  onChange: (value?: IFlowTemplateValue) => void;
265
267
  readonly?: boolean;
266
268
  hasError?: boolean;
269
+ placeholder?: string;
270
+ activeLinePlaceholder?: string;
267
271
  style?: React$1.CSSProperties;
268
272
  }>;
269
273
 
@@ -297,13 +301,19 @@ declare function PromptEditorWithInputs({ inputsValues, ...restProps }: PropsTyp
297
301
  * SPDX-License-Identifier: MIT
298
302
  */
299
303
 
304
+ type Preset = typeof preset;
305
+ type Options = Partial<InferValues<Preset[number]>>;
300
306
  interface CodeEditorPropsType extends React$1.PropsWithChildren<{}> {
301
307
  value?: string;
302
308
  onChange?: (value: string) => void;
303
309
  languageId: 'python' | 'typescript' | 'shell' | 'json';
304
310
  theme?: 'dark' | 'light';
311
+ placeholder?: string;
312
+ activeLinePlaceholder?: string;
313
+ readonly?: boolean;
314
+ options?: Options;
305
315
  }
306
- 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;
307
317
 
308
318
  /**
309
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
 
@@ -264,6 +266,8 @@ type PropsType$1 = React$1.PropsWithChildren<{
264
266
  onChange: (value?: IFlowTemplateValue) => void;
265
267
  readonly?: boolean;
266
268
  hasError?: boolean;
269
+ placeholder?: string;
270
+ activeLinePlaceholder?: string;
267
271
  style?: React$1.CSSProperties;
268
272
  }>;
269
273
 
@@ -297,13 +301,19 @@ declare function PromptEditorWithInputs({ inputsValues, ...restProps }: PropsTyp
297
301
  * SPDX-License-Identifier: MIT
298
302
  */
299
303
 
304
+ type Preset = typeof preset;
305
+ type Options = Partial<InferValues<Preset[number]>>;
300
306
  interface CodeEditorPropsType extends React$1.PropsWithChildren<{}> {
301
307
  value?: string;
302
308
  onChange?: (value: string) => void;
303
309
  languageId: 'python' | 'typescript' | 'shell' | 'json';
304
310
  theme?: 'dark' | 'light';
311
+ placeholder?: string;
312
+ activeLinePlaceholder?: string;
313
+ readonly?: boolean;
314
+ options?: Options;
305
315
  }
306
- 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;
307
317
 
308
318
  /**
309
319
  * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
package/dist/index.js CHANGED
@@ -2144,21 +2144,40 @@ var jinja_default = JinjaHighlight;
2144
2144
 
2145
2145
  // src/components/prompt-editor/index.tsx
2146
2146
  function PromptEditor(props) {
2147
- const { value, onChange, readonly, style, hasError, children } = props || {};
2147
+ const {
2148
+ value,
2149
+ onChange,
2150
+ readonly,
2151
+ placeholder,
2152
+ activeLinePlaceholder,
2153
+ style,
2154
+ hasError,
2155
+ children
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]);
2148
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(
2149
2164
  import_react25.Renderer,
2150
2165
  {
2166
+ didMount: (editor) => {
2167
+ editorRef.current = editor;
2168
+ },
2151
2169
  plugins: import_preset_prompt2.default,
2152
2170
  defaultValue: String(value?.content),
2153
2171
  options: {
2154
2172
  readOnly: readonly,
2155
- editable: !readonly
2173
+ editable: !readonly,
2174
+ placeholder
2156
2175
  },
2157
2176
  onChange: (e) => {
2158
2177
  onChange({ type: "template", content: e.value });
2159
2178
  }
2160
2179
  }
2161
- ), /* @__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));
2180
+ ), activeLinePlaceholder && /* @__PURE__ */ import_react24.default.createElement(import_react25.ActiveLinePlaceholder, null, activeLinePlaceholder), /* @__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));
2162
2181
  }
2163
2182
 
2164
2183
  // src/components/prompt-editor-with-variables/index.tsx
@@ -2222,8 +2241,8 @@ function VariableTree() {
2222
2241
  }
2223
2242
 
2224
2243
  // src/components/prompt-editor-with-variables/extensions/variable-tag.tsx
2244
+ var import_react_dom = __toESM(require("react-dom"));
2225
2245
  var import_react28 = __toESM(require("react"));
2226
- var import_client = require("react-dom/client");
2227
2246
  var import_lodash4 = require("lodash");
2228
2247
  var import_editor7 = require("@flowgram.ai/editor");
2229
2248
  var import_semi_ui13 = require("@douyinfe/semi-ui");
@@ -2282,9 +2301,12 @@ var VariableTagWidget = class extends import_view3.WidgetType {
2282
2301
  this.keyPath = keyPath;
2283
2302
  this.scope = scope;
2284
2303
  }
2304
+ renderReact(jsx) {
2305
+ import_react_dom.default.render(jsx, this.rootDOM);
2306
+ }
2285
2307
  renderVariable(v) {
2286
2308
  if (!v) {
2287
- this.root.render(
2309
+ this.renderReact(
2288
2310
  /* @__PURE__ */ import_react28.default.createElement(UITag2, { prefixIcon: /* @__PURE__ */ import_react28.default.createElement(import_semi_icons9.IconIssueStroked, null), color: "amber" }, "Unknown")
2289
2311
  );
2290
2312
  return;
@@ -2292,7 +2314,7 @@ var VariableTagWidget = class extends import_view3.WidgetType {
2292
2314
  const rootField = (0, import_lodash4.last)(v.parentFields);
2293
2315
  const rootTitle = /* @__PURE__ */ import_react28.default.createElement(UIRootTitle2, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
2294
2316
  const rootIcon = this.renderIcon(rootField?.meta.icon);
2295
- this.root.render(
2317
+ this.renderReact(
2296
2318
  /* @__PURE__ */ import_react28.default.createElement(
2297
2319
  import_semi_ui13.Popover,
2298
2320
  {
@@ -2304,10 +2326,10 @@ var VariableTagWidget = class extends import_view3.WidgetType {
2304
2326
  }
2305
2327
  toDOM(view) {
2306
2328
  const dom = document.createElement("span");
2307
- this.root = (0, import_client.createRoot)(dom);
2329
+ this.rootDOM = dom;
2308
2330
  this.toDispose.push(
2309
2331
  import_editor7.Disposable.create(() => {
2310
- this.root.unmount();
2332
+ import_react_dom.default.unmountComponentAtNode(this.rootDOM);
2311
2333
  })
2312
2334
  );
2313
2335
  this.toDispose.push(
@@ -2553,7 +2575,7 @@ var lightTheme = (0, import_preset_code.createTheme)({
2553
2575
  gutterBorderColor: "transparent",
2554
2576
  gutterBorderWidth: 0,
2555
2577
  lineHighlight: "#f0f0f0",
2556
- bracketColors: ["#FFEF61", "#DD99FF", "#78B0FF"],
2578
+ bracketColors: ["#FFD700", "#DD99FF", "#78B0FF"],
2557
2579
  tooltip: {
2558
2580
  backgroundColor: "#f0f0f0",
2559
2581
  color: "#000",
@@ -2783,9 +2805,18 @@ function CodeEditor({
2783
2805
  onChange,
2784
2806
  languageId = "python",
2785
2807
  theme = "light",
2786
- children
2808
+ children,
2809
+ placeholder,
2810
+ activeLinePlaceholder,
2811
+ options: options2,
2812
+ readonly
2787
2813
  }) {
2788
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]);
2789
2820
  return /* @__PURE__ */ import_react35.default.createElement(import_react36.EditorProvider, null, /* @__PURE__ */ import_react35.default.createElement(
2790
2821
  OriginCodeEditor,
2791
2822
  {
@@ -2793,19 +2824,25 @@ function CodeEditor({
2793
2824
  options: {
2794
2825
  uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
2795
2826
  languageId,
2796
- theme
2827
+ theme,
2828
+ placeholder,
2829
+ readOnly: readonly,
2830
+ editable: !readonly,
2831
+ ...options2 || {}
2797
2832
  },
2798
2833
  didMount: (editor) => {
2799
2834
  editorRef.current = editor;
2800
2835
  },
2801
2836
  onChange: (e) => onChange?.(e.value)
2802
2837
  },
2838
+ activeLinePlaceholder && /* @__PURE__ */ import_react35.default.createElement(import_react36.ActiveLinePlaceholder, null, activeLinePlaceholder),
2803
2839
  children
2804
2840
  ));
2805
2841
  }
2806
2842
 
2807
2843
  // src/components/json-editor-with-variables/index.tsx
2808
2844
  var import_react41 = __toESM(require("react"));
2845
+ var import_preset_code6 = require("@coze-editor/editor/preset-code");
2809
2846
 
2810
2847
  // src/components/json-editor-with-variables/extensions/variable-tree.tsx
2811
2848
  var import_react37 = __toESM(require("react"));
@@ -2866,7 +2903,7 @@ function VariableTree2() {
2866
2903
 
2867
2904
  // src/components/json-editor-with-variables/extensions/variable-tag.tsx
2868
2905
  var import_react39 = __toESM(require("react"));
2869
- var import_client2 = require("react-dom/client");
2906
+ var import_client = require("react-dom/client");
2870
2907
  var import_lodash6 = require("lodash");
2871
2908
  var import_editor10 = require("@flowgram.ai/editor");
2872
2909
  var import_semi_ui18 = require("@douyinfe/semi-ui");
@@ -2947,7 +2984,7 @@ var VariableTagWidget2 = class extends import_view5.WidgetType {
2947
2984
  }
2948
2985
  toDOM(view) {
2949
2986
  const dom = document.createElement("span");
2950
- this.root = (0, import_client2.createRoot)(dom);
2987
+ this.root = (0, import_client.createRoot)(dom);
2951
2988
  this.toDispose.push(
2952
2989
  import_editor10.Disposable.create(() => {
2953
2990
  this.root.unmount();
@@ -3014,8 +3051,49 @@ function VariableTagInject2() {
3014
3051
  }
3015
3052
 
3016
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
+ });
3017
3082
  function JsonEditorWithVariables(props) {
3018
- return /* @__PURE__ */ import_react41.default.createElement(CodeEditor, { languageId: "json", ...props }, /* @__PURE__ */ import_react41.default.createElement(VariableTree2, null), /* @__PURE__ */ import_react41.default.createElement(VariableTagInject2, null));
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
+ );
3019
3097
  }
3020
3098
 
3021
3099
  // src/effects/provide-batch-input/index.ts