@flowgram.ai/form-materials 0.2.18 → 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 CHANGED
@@ -1817,7 +1817,15 @@ function ConditionRow({ style, value, onChange, readonly }) {
1817
1817
  schema: targetSchema,
1818
1818
  onChange: (v) => onChange({ ...value, right: v })
1819
1819
  }
1820
- ) : /* @__PURE__ */ React13.createElement(Input3, { size: "small", disabled: true, value: opConfig?.rightDisplay || "Empty" }))));
1820
+ ) : /* @__PURE__ */ React13.createElement(
1821
+ Input3,
1822
+ {
1823
+ size: "small",
1824
+ disabled: true,
1825
+ style: { pointerEvents: "none" },
1826
+ value: opConfig?.rightDisplay || "Empty"
1827
+ }
1828
+ ))));
1821
1829
  }
1822
1830
 
1823
1831
  // src/components/batch-outputs/index.tsx
@@ -2094,9 +2102,9 @@ function PromptEditor(props) {
2094
2102
  }
2095
2103
 
2096
2104
  // src/components/prompt-editor-with-variables/index.tsx
2097
- import React17 from "react";
2105
+ import React18 from "react";
2098
2106
 
2099
- // src/components/prompt-editor-with-variables/extensions/variable.tsx
2107
+ // src/components/prompt-editor-with-variables/extensions/variable-tree.tsx
2100
2108
  import React16, { useEffect as useEffect4, useState as useState6 } from "react";
2101
2109
  import { Popover, Tree } from "@douyinfe/semi-ui";
2102
2110
  import {
@@ -2105,7 +2113,7 @@ import {
2105
2113
  useEditor,
2106
2114
  PositionMirror
2107
2115
  } from "@coze-editor/editor/react";
2108
- function Variable() {
2116
+ function VariableTree() {
2109
2117
  const [posKey, setPosKey] = useState6("");
2110
2118
  const [visible, setVisible] = useState6(false);
2111
2119
  const [position, setPosition] = useState6(-1);
@@ -2131,7 +2139,7 @@ function Variable() {
2131
2139
  }
2132
2140
  }, [editor, visible]);
2133
2141
  const treeData = useVariableTree({});
2134
- return /* @__PURE__ */ React16.createElement(React16.Fragment, null, /* @__PURE__ */ React16.createElement(Mention, { triggerCharacters: ["{", "{}"], onOpenChange: handleOpenChange }), /* @__PURE__ */ React16.createElement(
2142
+ return /* @__PURE__ */ React16.createElement(React16.Fragment, null, /* @__PURE__ */ React16.createElement(Mention, { triggerCharacters: ["{", "{}", "@"], onOpenChange: handleOpenChange }), /* @__PURE__ */ React16.createElement(
2135
2143
  Popover,
2136
2144
  {
2137
2145
  visible,
@@ -2157,11 +2165,169 @@ function Variable() {
2157
2165
  )
2158
2166
  ));
2159
2167
  }
2160
- var variable_default = Variable;
2168
+
2169
+ // src/components/prompt-editor-with-variables/extensions/variable-tag.tsx
2170
+ import React17, { useLayoutEffect as useLayoutEffect4 } from "react";
2171
+ import { createRoot } from "react-dom/client";
2172
+ import { isEqual, last } from "lodash";
2173
+ import {
2174
+ Disposable,
2175
+ DisposableCollection,
2176
+ useCurrentScope
2177
+ } from "@flowgram.ai/editor";
2178
+ import { Popover as Popover2 } from "@douyinfe/semi-ui";
2179
+ import { IconIssueStroked as IconIssueStroked2 } from "@douyinfe/semi-icons";
2180
+ import { useInjector as useInjector4 } from "@coze-editor/editor/react";
2181
+ import {
2182
+ Decoration,
2183
+ EditorView as EditorView3,
2184
+ MatchDecorator,
2185
+ ViewPlugin,
2186
+ WidgetType
2187
+ } from "@codemirror/view";
2188
+
2189
+ // src/components/prompt-editor-with-variables/styles.tsx
2190
+ import styled7 from "styled-components";
2191
+ import { Tag as Tag2 } from "@douyinfe/semi-ui";
2192
+ var UIRootTitle2 = styled7.div`
2193
+ margin-right: 4px;
2194
+ min-width: 20px;
2195
+ overflow: hidden;
2196
+ text-overflow: ellipsis;
2197
+ white-space: nowrap;
2198
+ color: var(--semi-color-text-2);
2199
+ `;
2200
+ var UIVarName2 = styled7.div`
2201
+ overflow: hidden;
2202
+ text-overflow: ellipsis;
2203
+ white-space: nowrap;
2204
+ `;
2205
+ var UITag2 = styled7(Tag2)`
2206
+ display: inline-flex;
2207
+ align-items: center;
2208
+ justify-content: flex-start;
2209
+ max-width: 300px;
2210
+
2211
+ & .semi-tag-content-center {
2212
+ justify-content: flex-start;
2213
+ }
2214
+
2215
+ &.semi-tag {
2216
+ margin: 0 5px;
2217
+ }
2218
+ `;
2219
+ var UIPopoverContent = styled7.div`
2220
+ padding: 10px;
2221
+ display: inline-flex;
2222
+ align-items: center;
2223
+ justify-content: flex-start;
2224
+ `;
2225
+
2226
+ // src/components/prompt-editor-with-variables/extensions/variable-tag.tsx
2227
+ var VariableTagWidget = class extends WidgetType {
2228
+ constructor({ keyPath, scope }) {
2229
+ super();
2230
+ this.toDispose = new DisposableCollection();
2231
+ this.renderIcon = (icon) => {
2232
+ if (typeof icon === "string") {
2233
+ return /* @__PURE__ */ React17.createElement("img", { style: { marginRight: 8 }, width: 12, height: 12, src: icon });
2234
+ }
2235
+ return icon;
2236
+ };
2237
+ this.keyPath = keyPath;
2238
+ this.scope = scope;
2239
+ }
2240
+ renderVariable(v) {
2241
+ if (!v) {
2242
+ this.root.render(
2243
+ /* @__PURE__ */ React17.createElement(UITag2, { prefixIcon: /* @__PURE__ */ React17.createElement(IconIssueStroked2, null), color: "amber" }, "Unknown")
2244
+ );
2245
+ return;
2246
+ }
2247
+ const rootField = last(v.parentFields);
2248
+ const rootTitle = /* @__PURE__ */ React17.createElement(UIRootTitle2, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
2249
+ const rootIcon = this.renderIcon(rootField?.meta.icon);
2250
+ this.root.render(
2251
+ /* @__PURE__ */ React17.createElement(
2252
+ Popover2,
2253
+ {
2254
+ content: /* @__PURE__ */ React17.createElement(UIPopoverContent, null, rootIcon, rootTitle, /* @__PURE__ */ React17.createElement(UIVarName2, null, v?.keyPath.slice(1).join(".")))
2255
+ },
2256
+ /* @__PURE__ */ React17.createElement(UITag2, { prefixIcon: rootIcon }, rootTitle, /* @__PURE__ */ React17.createElement(UIVarName2, null, v?.key))
2257
+ )
2258
+ );
2259
+ }
2260
+ toDOM(view) {
2261
+ const dom = document.createElement("span");
2262
+ this.root = createRoot(dom);
2263
+ this.toDispose.push(
2264
+ Disposable.create(() => {
2265
+ this.root.unmount();
2266
+ })
2267
+ );
2268
+ this.toDispose.push(
2269
+ this.scope.available.trackByKeyPath(
2270
+ this.keyPath,
2271
+ (v) => {
2272
+ this.renderVariable(v);
2273
+ },
2274
+ { triggerOnInit: false }
2275
+ )
2276
+ );
2277
+ this.renderVariable(this.scope.available.getByKeyPath(this.keyPath));
2278
+ return dom;
2279
+ }
2280
+ eq(other) {
2281
+ return isEqual(this.keyPath, other.keyPath);
2282
+ }
2283
+ ignoreEvent() {
2284
+ return false;
2285
+ }
2286
+ destroy(dom) {
2287
+ this.toDispose.dispose();
2288
+ }
2289
+ };
2290
+ function VariableTagInject() {
2291
+ const injector = useInjector4();
2292
+ const scope = useCurrentScope();
2293
+ useLayoutEffect4(() => {
2294
+ const atMatcher = new MatchDecorator({
2295
+ regexp: /\{\{([^\}]+)\}\}/g,
2296
+ decoration: (match) => Decoration.replace({
2297
+ widget: new VariableTagWidget({
2298
+ keyPath: match[1]?.split(".") ?? [],
2299
+ scope
2300
+ })
2301
+ })
2302
+ });
2303
+ return injector.inject([
2304
+ ViewPlugin.fromClass(
2305
+ class {
2306
+ constructor(view) {
2307
+ this.view = view;
2308
+ this.decorations = atMatcher.createDeco(view);
2309
+ }
2310
+ update() {
2311
+ this.decorations = atMatcher.createDeco(this.view);
2312
+ }
2313
+ },
2314
+ {
2315
+ decorations: (p) => p.decorations,
2316
+ provide(p) {
2317
+ return EditorView3.atomicRanges.of(
2318
+ (view) => view.plugin(p)?.decorations ?? Decoration.none
2319
+ );
2320
+ }
2321
+ }
2322
+ )
2323
+ ]);
2324
+ }, [injector]);
2325
+ return null;
2326
+ }
2161
2327
 
2162
2328
  // src/components/prompt-editor-with-variables/index.tsx
2163
2329
  function PromptEditorWithVariables(props) {
2164
- return /* @__PURE__ */ React17.createElement(PromptEditor, { ...props }, /* @__PURE__ */ React17.createElement(variable_default, null));
2330
+ return /* @__PURE__ */ React18.createElement(PromptEditor, { ...props }, /* @__PURE__ */ React18.createElement(VariableTree, null), /* @__PURE__ */ React18.createElement(VariableTagInject, null));
2165
2331
  }
2166
2332
 
2167
2333
  // src/effects/provide-batch-input/index.ts