@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/index.js CHANGED
@@ -1874,7 +1874,15 @@ function ConditionRow({ style, value, onChange, readonly }) {
1874
1874
  schema: targetSchema,
1875
1875
  onChange: (v) => onChange({ ...value, right: v })
1876
1876
  }
1877
- ) : /* @__PURE__ */ import_react15.default.createElement(import_semi_ui9.Input, { size: "small", disabled: true, value: opConfig?.rightDisplay || "Empty" }))));
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
+ ))));
1878
1886
  }
1879
1887
 
1880
1888
  // src/components/batch-outputs/index.tsx
@@ -2151,13 +2159,13 @@ function PromptEditor(props) {
2151
2159
  }
2152
2160
 
2153
2161
  // src/components/prompt-editor-with-variables/index.tsx
2154
- var import_react28 = __toESM(require("react"));
2162
+ var import_react30 = __toESM(require("react"));
2155
2163
 
2156
- // src/components/prompt-editor-with-variables/extensions/variable.tsx
2164
+ // src/components/prompt-editor-with-variables/extensions/variable-tree.tsx
2157
2165
  var import_react26 = __toESM(require("react"));
2158
2166
  var import_semi_ui11 = require("@douyinfe/semi-ui");
2159
2167
  var import_react27 = require("@coze-editor/editor/react");
2160
- function Variable() {
2168
+ function VariableTree() {
2161
2169
  const [posKey, setPosKey] = (0, import_react26.useState)("");
2162
2170
  const [visible, setVisible] = (0, import_react26.useState)(false);
2163
2171
  const [position, setPosition] = (0, import_react26.useState)(-1);
@@ -2183,7 +2191,7 @@ function Variable() {
2183
2191
  }
2184
2192
  }, [editor, visible]);
2185
2193
  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(
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(
2187
2195
  import_semi_ui11.Popover,
2188
2196
  {
2189
2197
  visible,
@@ -2209,37 +2217,185 @@ function Variable() {
2209
2217
  )
2210
2218
  ));
2211
2219
  }
2212
- var variable_default = Variable;
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
+ }
2213
2369
 
2214
2370
  // src/components/prompt-editor-with-variables/index.tsx
2215
2371
  function PromptEditorWithVariables(props) {
2216
- return /* @__PURE__ */ import_react28.default.createElement(PromptEditor, { ...props }, /* @__PURE__ */ import_react28.default.createElement(variable_default, null));
2372
+ return /* @__PURE__ */ import_react30.default.createElement(PromptEditor, { ...props }, /* @__PURE__ */ import_react30.default.createElement(VariableTree, null), /* @__PURE__ */ import_react30.default.createElement(VariableTagInject, null));
2217
2373
  }
2218
2374
 
2219
2375
  // src/effects/provide-batch-input/index.ts
2220
- var import_editor7 = require("@flowgram.ai/editor");
2221
- var provideBatchInputEffect = (0, import_editor7.createEffectFromVariableProvider)({
2376
+ var import_editor8 = require("@flowgram.ai/editor");
2377
+ var provideBatchInputEffect = (0, import_editor8.createEffectFromVariableProvider)({
2222
2378
  private: true,
2223
2379
  parse: (value, ctx) => [
2224
- import_editor7.ASTFactory.createVariableDeclaration({
2380
+ import_editor8.ASTFactory.createVariableDeclaration({
2225
2381
  key: `${ctx.node.id}_locals`,
2226
2382
  meta: {
2227
- title: (0, import_editor7.getNodeForm)(ctx.node)?.getValueIn("title"),
2383
+ title: (0, import_editor8.getNodeForm)(ctx.node)?.getValueIn("title"),
2228
2384
  icon: ctx.node.getNodeRegistry().info?.icon
2229
2385
  },
2230
- type: import_editor7.ASTFactory.createObject({
2386
+ type: import_editor8.ASTFactory.createObject({
2231
2387
  properties: [
2232
- import_editor7.ASTFactory.createProperty({
2388
+ import_editor8.ASTFactory.createProperty({
2233
2389
  key: "item",
2234
- initializer: import_editor7.ASTFactory.createEnumerateExpression({
2235
- enumerateFor: import_editor7.ASTFactory.createKeyPathExpression({
2390
+ initializer: import_editor8.ASTFactory.createEnumerateExpression({
2391
+ enumerateFor: import_editor8.ASTFactory.createKeyPathExpression({
2236
2392
  keyPath: value.content || []
2237
2393
  })
2238
2394
  })
2239
2395
  }),
2240
- import_editor7.ASTFactory.createProperty({
2396
+ import_editor8.ASTFactory.createProperty({
2241
2397
  key: "index",
2242
- type: import_editor7.ASTFactory.createNumber()
2398
+ type: import_editor8.ASTFactory.createNumber()
2243
2399
  })
2244
2400
  ]
2245
2401
  })
@@ -2248,21 +2404,21 @@ var provideBatchInputEffect = (0, import_editor7.createEffectFromVariableProvide
2248
2404
  });
2249
2405
 
2250
2406
  // src/effects/provide-batch-outputs/index.ts
2251
- var import_editor8 = require("@flowgram.ai/editor");
2252
- var provideBatchOutputsEffect = (0, import_editor8.createEffectFromVariableProvider)({
2407
+ var import_editor9 = require("@flowgram.ai/editor");
2408
+ var provideBatchOutputsEffect = (0, import_editor9.createEffectFromVariableProvider)({
2253
2409
  parse: (value, ctx) => [
2254
- import_editor8.ASTFactory.createVariableDeclaration({
2410
+ import_editor9.ASTFactory.createVariableDeclaration({
2255
2411
  key: `${ctx.node.id}`,
2256
2412
  meta: {
2257
- title: (0, import_editor8.getNodeForm)(ctx.node)?.getValueIn("title"),
2413
+ title: (0, import_editor9.getNodeForm)(ctx.node)?.getValueIn("title"),
2258
2414
  icon: ctx.node.getNodeRegistry().info?.icon
2259
2415
  },
2260
- type: import_editor8.ASTFactory.createObject({
2416
+ type: import_editor9.ASTFactory.createObject({
2261
2417
  properties: Object.entries(value).map(
2262
- ([_key, value2]) => import_editor8.ASTFactory.createProperty({
2418
+ ([_key, value2]) => import_editor9.ASTFactory.createProperty({
2263
2419
  key: _key,
2264
- initializer: import_editor8.ASTFactory.createWrapArrayExpression({
2265
- wrapFor: import_editor8.ASTFactory.createKeyPathExpression({
2420
+ initializer: import_editor9.ASTFactory.createWrapArrayExpression({
2421
+ wrapFor: import_editor9.ASTFactory.createKeyPathExpression({
2266
2422
  keyPath: value2.content || []
2267
2423
  })
2268
2424
  })
@@ -2274,14 +2430,14 @@ var provideBatchOutputsEffect = (0, import_editor8.createEffectFromVariableProvi
2274
2430
  });
2275
2431
 
2276
2432
  // src/effects/auto-rename-ref/index.ts
2277
- var import_lodash4 = require("lodash");
2278
- var import_editor9 = require("@flowgram.ai/editor");
2433
+ var import_lodash5 = require("lodash");
2434
+ var import_editor10 = require("@flowgram.ai/editor");
2279
2435
  var autoRenameRefEffect = [
2280
2436
  {
2281
- event: import_editor9.DataEvent.onValueInit,
2437
+ event: import_editor10.DataEvent.onValueInit,
2282
2438
  effect: (params) => {
2283
2439
  const { context, form, name } = params;
2284
- const renameService = context.node.getService(import_editor9.VariableFieldKeyRenameService);
2440
+ const renameService = context.node.getService(import_editor10.VariableFieldKeyRenameService);
2285
2441
  const disposable = renameService.onRename(({ before, after }) => {
2286
2442
  const beforeKeyPath = [
2287
2443
  ...before.parentFields.map((_field) => _field.key).reverse(),
@@ -2311,7 +2467,7 @@ function isRef(value) {
2311
2467
  return value?.type === "ref" && Array.isArray(value?.content) && typeof value?.content[0] === "string";
2312
2468
  }
2313
2469
  function traverseRef(name, value, cb) {
2314
- if ((0, import_lodash4.isObject)(value)) {
2470
+ if ((0, import_lodash5.isObject)(value)) {
2315
2471
  if (isRef(value)) {
2316
2472
  cb(name, value);
2317
2473
  return;
@@ -2321,7 +2477,7 @@ function traverseRef(name, value, cb) {
2321
2477
  });
2322
2478
  return;
2323
2479
  }
2324
- if ((0, import_lodash4.isArray)(value)) {
2480
+ if ((0, import_lodash5.isArray)(value)) {
2325
2481
  value.forEach((_value, idx) => {
2326
2482
  traverseRef(`${name}[${idx}]`, _value, cb);
2327
2483
  });
@@ -2331,13 +2487,13 @@ function traverseRef(name, value, cb) {
2331
2487
  }
2332
2488
 
2333
2489
  // src/effects/provide-json-schema-outputs/index.ts
2334
- var import_editor10 = require("@flowgram.ai/editor");
2335
- var provideJsonSchemaOutputs = (0, import_editor10.createEffectFromVariableProvider)({
2490
+ var import_editor11 = require("@flowgram.ai/editor");
2491
+ var provideJsonSchemaOutputs = (0, import_editor11.createEffectFromVariableProvider)({
2336
2492
  parse: (value, ctx) => [
2337
- import_editor10.ASTFactory.createVariableDeclaration({
2493
+ import_editor11.ASTFactory.createVariableDeclaration({
2338
2494
  key: `${ctx.node.id}`,
2339
2495
  meta: {
2340
- title: (0, import_editor10.getNodeForm)(ctx.node)?.getValueIn("title") || ctx.node.id,
2496
+ title: (0, import_editor11.getNodeForm)(ctx.node)?.getValueIn("title") || ctx.node.id,
2341
2497
  icon: ctx.node.getNodeRegistry().info?.icon
2342
2498
  },
2343
2499
  type: JsonSchemaUtils.schemaToAST(value)
@@ -2346,12 +2502,12 @@ var provideJsonSchemaOutputs = (0, import_editor10.createEffectFromVariableProvi
2346
2502
  });
2347
2503
 
2348
2504
  // src/effects/sync-variable-title/index.ts
2349
- var import_editor11 = require("@flowgram.ai/editor");
2505
+ var import_editor12 = require("@flowgram.ai/editor");
2350
2506
  var syncVariableTitle = [
2351
2507
  {
2352
- event: import_editor11.DataEvent.onValueChange,
2508
+ event: import_editor12.DataEvent.onValueChange,
2353
2509
  effect: ({ value, context }) => {
2354
- context.node.getData(import_editor11.FlowNodeVariableData).allScopes.forEach((_scope) => {
2510
+ context.node.getData(import_editor12.FlowNodeVariableData).allScopes.forEach((_scope) => {
2355
2511
  _scope.output.variables.forEach((_var) => {
2356
2512
  _var.updateMeta({
2357
2513
  title: value || context.node.id,
@@ -2364,21 +2520,21 @@ var syncVariableTitle = [
2364
2520
  ];
2365
2521
 
2366
2522
  // src/form-plugins/batch-outputs-plugin/index.ts
2367
- var import_editor12 = require("@flowgram.ai/editor");
2368
- var provideBatchOutputsEffect2 = (0, import_editor12.createEffectFromVariableProvider)({
2523
+ var import_editor13 = require("@flowgram.ai/editor");
2524
+ var provideBatchOutputsEffect2 = (0, import_editor13.createEffectFromVariableProvider)({
2369
2525
  parse: (value, ctx) => [
2370
- import_editor12.ASTFactory.createVariableDeclaration({
2526
+ import_editor13.ASTFactory.createVariableDeclaration({
2371
2527
  key: `${ctx.node.id}`,
2372
2528
  meta: {
2373
- title: (0, import_editor12.getNodeForm)(ctx.node)?.getValueIn("title"),
2529
+ title: (0, import_editor13.getNodeForm)(ctx.node)?.getValueIn("title"),
2374
2530
  icon: ctx.node.getNodeRegistry().info?.icon
2375
2531
  },
2376
- type: import_editor12.ASTFactory.createObject({
2532
+ type: import_editor13.ASTFactory.createObject({
2377
2533
  properties: Object.entries(value).map(
2378
- ([_key, value2]) => import_editor12.ASTFactory.createProperty({
2534
+ ([_key, value2]) => import_editor13.ASTFactory.createProperty({
2379
2535
  key: _key,
2380
- initializer: import_editor12.ASTFactory.createWrapArrayExpression({
2381
- wrapFor: import_editor12.ASTFactory.createKeyPathExpression({
2536
+ initializer: import_editor13.ASTFactory.createWrapArrayExpression({
2537
+ wrapFor: import_editor13.ASTFactory.createKeyPathExpression({
2382
2538
  keyPath: value2?.content || []
2383
2539
  })
2384
2540
  })
@@ -2388,7 +2544,7 @@ var provideBatchOutputsEffect2 = (0, import_editor12.createEffectFromVariablePro
2388
2544
  })
2389
2545
  ]
2390
2546
  });
2391
- var createBatchOutputsFormPlugin = (0, import_editor12.defineFormPluginCreator)({
2547
+ var createBatchOutputsFormPlugin = (0, import_editor13.defineFormPluginCreator)({
2392
2548
  name: "batch-outputs-plugin",
2393
2549
  onSetupFormMeta({ mergeEffect }, { outputKey }) {
2394
2550
  mergeEffect({
@@ -2396,7 +2552,7 @@ var createBatchOutputsFormPlugin = (0, import_editor12.defineFormPluginCreator)(
2396
2552
  });
2397
2553
  },
2398
2554
  onInit(ctx, { outputKey }) {
2399
- const chainTransformService = ctx.node.getService(import_editor12.ScopeChainTransformService);
2555
+ const chainTransformService = ctx.node.getService(import_editor13.ScopeChainTransformService);
2400
2556
  const batchNodeType = ctx.node.flowNodeType;
2401
2557
  const transformerId = `${batchNodeType}-outputs`;
2402
2558
  if (chainTransformService.hasTransformer(transformerId)) {
@@ -2406,21 +2562,21 @@ var createBatchOutputsFormPlugin = (0, import_editor12.defineFormPluginCreator)(
2406
2562
  transformCovers: (covers, ctx2) => {
2407
2563
  const node = ctx2.scope.meta?.node;
2408
2564
  if (node?.parent?.flowNodeType === batchNodeType) {
2409
- return [...covers, (0, import_editor12.getNodeScope)(node.parent)];
2565
+ return [...covers, (0, import_editor13.getNodeScope)(node.parent)];
2410
2566
  }
2411
2567
  return covers;
2412
2568
  },
2413
2569
  transformDeps(scopes, ctx2) {
2414
2570
  const scopeMeta = ctx2.scope.meta;
2415
- if (scopeMeta?.type === import_editor12.FlowNodeScopeType.private) {
2571
+ if (scopeMeta?.type === import_editor13.FlowNodeScopeType.private) {
2416
2572
  return scopes;
2417
2573
  }
2418
2574
  const node = scopeMeta?.node;
2419
2575
  if (node?.flowNodeType === batchNodeType) {
2420
2576
  const childBlocks = node.blocks;
2421
2577
  return [
2422
- (0, import_editor12.getNodePrivateScope)(node),
2423
- ...childBlocks.map((_childBlock) => (0, import_editor12.getNodeScope)(_childBlock))
2578
+ (0, import_editor13.getNodePrivateScope)(node),
2579
+ ...childBlocks.map((_childBlock) => (0, import_editor13.getNodeScope)(_childBlock))
2424
2580
  ];
2425
2581
  }
2426
2582
  return scopes;