@flowgram.ai/form-materials 0.4.3 → 0.4.5

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 CHANGED
@@ -72,17 +72,6 @@ program
72
72
  let { packagesToInstall } = copyMaterial(material, projectInfo);
73
73
 
74
74
  // 4. Install the dependencies
75
- packagesToInstall = packagesToInstall.map((_pkg) => {
76
- if (
77
- _pkg.startsWith(`@flowgram.ai/`) &&
78
- projectInfo.flowgramVersion !== 'workspace:*' &&
79
- !_pkg.endsWith(`@${projectInfo.flowgramVersion}`)
80
- ) {
81
- return `${_pkg}@${projectInfo.flowgramVersion}`;
82
- }
83
- return _pkg;
84
- });
85
-
86
75
  console.log(chalk.bold('These npm dependencies will be added to your project'));
87
76
  console.log(packagesToInstall);
88
77
  installDependencies(packagesToInstall, projectInfo);
package/bin/materials.ts CHANGED
@@ -61,12 +61,21 @@ export function listAllMaterials(): Material[] {
61
61
  return _materials;
62
62
  }
63
63
 
64
+ export const getFormMaterialDependencies = (): Record<string, string> => {
65
+ const packageJsonPath: string = path.join(__dirname, '..', 'package.json');
66
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
67
+
68
+ return packageJson.dependencies;
69
+ };
70
+
64
71
  export const copyMaterial = (
65
72
  material: Material,
66
73
  projectInfo: ProjectInfo
67
74
  ): {
68
75
  packagesToInstall: string[];
69
76
  } => {
77
+ const formMaterialDependencies = getFormMaterialDependencies();
78
+
70
79
  const sourceDir: string = material.path;
71
80
  const materialRoot: string = path.join(
72
81
  projectInfo.projectPath,
@@ -92,10 +101,28 @@ export const copyMaterial = (
92
101
  { ...importDeclaration, source: '@flowgram.ai/form-materials' },
93
102
  ])
94
103
  );
104
+ if (projectInfo.flowgramVersion !== 'workspace:*') {
105
+ packagesToInstall.add(`@flowgram.ai/form-materials@${projectInfo.flowgramVersion}`);
106
+ continue;
107
+ }
95
108
  packagesToInstall.add('@flowgram.ai/form-materials');
96
109
  } else if (!source.startsWith('.') && !source.startsWith('react')) {
97
- // check if is third party npm packages
98
- packagesToInstall.add(source);
110
+ // check if is in form material dependencies
111
+ const [dep, version] =
112
+ Object.entries(formMaterialDependencies).find(([_key]) => source.startsWith(_key)) ||
113
+ [];
114
+ if (!dep) {
115
+ continue;
116
+ }
117
+ if (version === 'workspace:*') {
118
+ if (projectInfo.flowgramVersion !== 'workspace:*') {
119
+ packagesToInstall.add(`${dep}@${projectInfo.flowgramVersion}`);
120
+ } else {
121
+ packagesToInstall.add(dep);
122
+ }
123
+ } else {
124
+ packagesToInstall.add(`${dep}@${version}`);
125
+ }
99
126
  }
100
127
  }
101
128
  }
package/dist/esm/index.js CHANGED
@@ -245,6 +245,23 @@ var FlowValueUtils;
245
245
  FlowValueUtils2.inferJsonSchema = inferJsonSchema;
246
246
  })(FlowValueUtils || (FlowValueUtils = {}));
247
247
 
248
+ // src/shared/polyfill-create-root/index.tsx
249
+ import * as ReactDOM from "react-dom";
250
+ var unstableCreateRoot = (dom) => ({
251
+ render(children) {
252
+ ReactDOM.render(children, dom);
253
+ },
254
+ unmount() {
255
+ ReactDOM.unmountComponentAtNode(dom);
256
+ }
257
+ });
258
+ function polyfillCreateRoot(dom) {
259
+ return unstableCreateRoot(dom);
260
+ }
261
+ function unstableSetCreateRoot(createRoot) {
262
+ unstableCreateRoot = createRoot;
263
+ }
264
+
248
265
  // src/components/variable-selector/use-variable-tree.tsx
249
266
  import React11, { useCallback } from "react";
250
267
  import { JsonSchemaUtils as JsonSchemaUtils3 } from "@flowgram.ai/json-schema";
@@ -365,54 +382,55 @@ import { themes } from "@coze-editor/editor/preset-code";
365
382
  // src/components/code-editor/theme/light.ts
366
383
  import { createTheme, tags as t } from "@coze-editor/editor/preset-code";
367
384
  var colors = {
368
- background: "#F7F7FC",
369
- // syntax
370
- comment: "#000A298A",
371
- key: "#00818C",
372
- string: "#D1009D",
373
- number: "#C74200",
374
- boolean: "#2B57D9",
375
- null: "#2B57D9",
376
- separator: "#0F1529D1"
385
+ background: "#FFFFFF",
386
+ comment: "#6B7280",
387
+ key: "#2563EB",
388
+ variable: "#DC2626",
389
+ string: "#059669",
390
+ number: "#EA580C",
391
+ boolean: "#7C3AED",
392
+ null: "#7C3AED",
393
+ separator: "#374151"
377
394
  };
378
395
  var lightTheme = createTheme({
379
396
  variant: "light",
380
397
  settings: {
381
- background: "#fff",
382
- foreground: "#000",
383
- caret: "#000",
384
- selection: "#d9d9d9",
385
- gutterBackground: "#f0f0f0",
386
- gutterForeground: "#666",
398
+ background: "#FFFFFF",
399
+ foreground: "#1F2937",
400
+ caret: "#2563EB",
401
+ selection: "#E5E7EB",
402
+ gutterBackground: "#F9FAFB",
403
+ gutterForeground: "#6B7280",
387
404
  gutterBorderColor: "transparent",
388
405
  gutterBorderWidth: 0,
389
- lineHighlight: "#e1e1e180",
390
- bracketColors: ["#FFD700", "#DD99FF", "#78B0FF"],
406
+ lineHighlight: "#F3F4F680",
407
+ bracketColors: ["#F59E0B", "#8B5CF6", "#06B6D4"],
391
408
  tooltip: {
392
- backgroundColor: "#f0f0f0",
393
- color: "#000",
394
- border: "1px solid #ccc"
409
+ backgroundColor: "#FFFFFF",
410
+ color: "#1F2937",
411
+ border: "1px solid #E5E7EB",
412
+ boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)"
395
413
  },
396
414
  link: {
397
- color: "#007bff"
415
+ color: "#2563EB"
398
416
  },
399
417
  completionItemHover: {
400
- backgroundColor: "#f0f0f0"
418
+ backgroundColor: "#F3F4F6"
401
419
  },
402
420
  completionItemSelected: {
403
- backgroundColor: "#e0e0e0"
421
+ backgroundColor: "#E5E7EB"
404
422
  },
405
423
  completionItemIcon: {
406
- color: "#333"
424
+ color: "#4B5563"
407
425
  },
408
426
  completionItemLabel: {
409
- color: "#333"
427
+ color: "#1F2937"
410
428
  },
411
429
  completionItemInfo: {
412
- color: "#333"
430
+ color: "#4B5563"
413
431
  },
414
432
  completionItemDetail: {
415
- color: "#666"
433
+ color: "#6B7280"
416
434
  }
417
435
  },
418
436
  styles: [
@@ -425,6 +443,10 @@ var lightTheme = createTheme({
425
443
  tag: [t.propertyName],
426
444
  color: colors.key
427
445
  },
446
+ {
447
+ tag: [t.variableName],
448
+ color: colors.variable
449
+ },
428
450
  {
429
451
  tag: [t.string],
430
452
  color: colors.string
@@ -448,27 +470,44 @@ var lightTheme = createTheme({
448
470
  // markdown
449
471
  {
450
472
  tag: [t.heading],
451
- color: "#3e76ef"
473
+ color: "#2563EB"
452
474
  },
453
475
  {
454
476
  tag: [t.processingInstruction],
455
- color: "#3e76ef"
477
+ color: "#2563EB"
478
+ },
479
+ // js
480
+ {
481
+ tag: [t.definitionKeyword],
482
+ color: "#9333EA"
483
+ },
484
+ {
485
+ tag: [t.modifier],
486
+ color: "#9333EA"
487
+ },
488
+ {
489
+ tag: [t.controlKeyword],
490
+ color: "#9333EA"
491
+ },
492
+ {
493
+ tag: [t.operatorKeyword],
494
+ color: "#9333EA"
456
495
  },
457
496
  // shell
458
497
  // curl
459
498
  {
460
499
  tag: [t.standard(t.variableName)],
461
- color: "#00804A"
500
+ color: "#059669"
462
501
  },
463
502
  // -X
464
503
  {
465
504
  tag: [t.attributeName],
466
- color: "#C74200"
505
+ color: "#EA580C"
467
506
  },
468
507
  // url in string (includes quotes), e.g. "https://..."
469
508
  {
470
509
  tag: [t.special(t.string)],
471
- color: "#2B57D9"
510
+ color: "#2563EB"
472
511
  }
473
512
  ]
474
513
  });
@@ -476,54 +515,55 @@ var lightTheme = createTheme({
476
515
  // src/components/code-editor/theme/dark.ts
477
516
  import { createTheme as createTheme2, tags as t2 } from "@coze-editor/editor/preset-code";
478
517
  var colors2 = {
479
- background: "#151B27",
480
- // syntax
481
- comment: "#FFFFFF63",
482
- key: "#39E5D7",
483
- string: "#FF94D2",
484
- number: "#FF9933",
485
- boolean: "#78B0FF",
486
- null: "#78B0FF",
487
- separator: "#FFFFFFC9"
518
+ background: "#0D1117",
519
+ // syntax - 现代化暗色主题配色
520
+ comment: "#8B949E",
521
+ key: "#7DD3FC",
522
+ variable: "#F472B6",
523
+ string: "#34D399",
524
+ number: "#FBBF24",
525
+ boolean: "#A78BFA",
526
+ null: "#A78BFA",
527
+ separator: "#E6EDF3"
488
528
  };
489
529
  var darkTheme = createTheme2({
490
530
  variant: "dark",
491
531
  settings: {
492
532
  background: colors2.background,
493
- foreground: "#fff",
494
- caret: "#AEAFAD",
495
- selection: "#d9d9d942",
533
+ foreground: "#E6EDF3",
534
+ caret: "#7DD3FC",
535
+ selection: "#264F7833",
496
536
  gutterBackground: colors2.background,
497
- gutterForeground: "#FFFFFF63",
537
+ gutterForeground: "#6E7681",
498
538
  gutterBorderColor: "transparent",
499
539
  gutterBorderWidth: 0,
500
- lineHighlight: "#272e3d36",
501
- bracketColors: ["#FFEF61", "#DD99FF", "#78B0FF"],
540
+ lineHighlight: "#21262D",
541
+ bracketColors: ["#FBBF24", "#A78BFA", "#7DD3FC"],
502
542
  tooltip: {
503
- backgroundColor: "#363D4D",
504
- color: "#fff",
505
- border: "none"
543
+ backgroundColor: "#21262D",
544
+ color: "#E6EDF3",
545
+ border: "1px solid #30363D"
506
546
  },
507
547
  link: {
508
- color: "#4daafc"
548
+ color: "#58A6FF"
509
549
  },
510
550
  completionItemHover: {
511
- backgroundColor: "#FFFFFF0F"
551
+ backgroundColor: "#21262D"
512
552
  },
513
553
  completionItemSelected: {
514
- backgroundColor: "#FFFFFF17"
554
+ backgroundColor: "#1F6EEB"
515
555
  },
516
556
  completionItemIcon: {
517
- color: "#FFFFFFC9"
557
+ color: "#8B949E"
518
558
  },
519
559
  completionItemLabel: {
520
- color: "#FFFFFFC9"
560
+ color: "#E6EDF3"
521
561
  },
522
562
  completionItemInfo: {
523
- color: "#FFFFFFC9"
563
+ color: "#8B949E"
524
564
  },
525
565
  completionItemDetail: {
526
- color: "#FFFFFF63"
566
+ color: "#6E7681"
527
567
  }
528
568
  },
529
569
  styles: [
@@ -556,30 +596,47 @@ var darkTheme = createTheme2({
556
596
  tag: [t2.separator],
557
597
  color: colors2.separator
558
598
  },
599
+ // js
600
+ {
601
+ tag: [t2.definitionKeyword],
602
+ color: "#C084FC"
603
+ },
604
+ {
605
+ tag: [t2.modifier],
606
+ color: "#C084FC"
607
+ },
608
+ {
609
+ tag: [t2.controlKeyword],
610
+ color: "#C084FC"
611
+ },
612
+ {
613
+ tag: [t2.operatorKeyword],
614
+ color: "#C084FC"
615
+ },
559
616
  // markdown
560
617
  {
561
618
  tag: [t2.heading],
562
- color: "#6b6bff"
619
+ color: "#7DD3FC"
563
620
  },
564
621
  {
565
622
  tag: [t2.processingInstruction],
566
- color: "#6b6bff"
623
+ color: "#7DD3FC"
567
624
  },
568
625
  // shell
569
626
  // curl
570
627
  {
571
628
  tag: [t2.standard(t2.variableName)],
572
- color: "#3BEB84"
629
+ color: "#34D399"
573
630
  },
574
631
  // -X
575
632
  {
576
633
  tag: [t2.attributeName],
577
- color: "#FF9933"
634
+ color: "#FBBF24"
578
635
  },
579
636
  // url in string (includes quotes), e.g. "https://..."
580
637
  {
581
638
  tag: [t2.special(t2.string)],
582
- color: "#78B0FF"
639
+ color: "#7DD3FC"
583
640
  }
584
641
  ]
585
642
  });
@@ -1448,7 +1505,7 @@ function PropertyEdit(props) {
1448
1505
  BlurInput,
1449
1506
  {
1450
1507
  disabled: readonly,
1451
- placeholder: config?.placeholder ?? "Input Variable Name",
1508
+ placeholder: config?.placeholder ?? I18n9.t("Input Variable Name"),
1452
1509
  size: "small",
1453
1510
  value: name,
1454
1511
  onChange: (value2) => onChange("name", value2)
@@ -2438,7 +2495,6 @@ function VariableTree() {
2438
2495
  }
2439
2496
 
2440
2497
  // src/components/prompt-editor-with-variables/extensions/variable-tag.tsx
2441
- import ReactDOM from "react-dom";
2442
2498
  import React26, { useLayoutEffect as useLayoutEffect4 } from "react";
2443
2499
  import { isEqual, last } from "lodash";
2444
2500
  import {
@@ -2508,36 +2564,32 @@ var VariableTagWidget = class extends WidgetType {
2508
2564
  this.keyPath = keyPath;
2509
2565
  this.scope = scope;
2510
2566
  }
2511
- renderReact(jsx) {
2512
- ReactDOM.render(jsx, this.rootDOM);
2513
- }
2514
2567
  renderVariable(v) {
2515
2568
  if (!v) {
2516
- this.renderReact(
2569
+ this.root.render(
2517
2570
  /* @__PURE__ */ React26.createElement(UITag2, { prefixIcon: /* @__PURE__ */ React26.createElement(IconIssueStroked2, null), color: "amber" }, "Unknown")
2518
2571
  );
2519
2572
  return;
2520
2573
  }
2521
- const rootField = last(v.parentFields) || v;
2522
- const isRoot = v.parentFields.length === 0;
2523
- const rootTitle = /* @__PURE__ */ React26.createElement(UIRootTitle2, null, rootField?.meta.title ? `${rootField.meta.title} ${isRoot ? "" : "-"} ` : "");
2574
+ const rootField = last(v.parentFields);
2575
+ const rootTitle = /* @__PURE__ */ React26.createElement(UIRootTitle2, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
2524
2576
  const rootIcon = this.renderIcon(rootField?.meta.icon);
2525
- this.renderReact(
2577
+ this.root.render(
2526
2578
  /* @__PURE__ */ React26.createElement(
2527
2579
  Popover3,
2528
2580
  {
2529
2581
  content: /* @__PURE__ */ React26.createElement(UIPopoverContent2, null, rootIcon, rootTitle, /* @__PURE__ */ React26.createElement(UIVarName2, null, v?.keyPath.slice(1).join(".")))
2530
2582
  },
2531
- /* @__PURE__ */ React26.createElement(UITag2, { prefixIcon: rootIcon }, rootTitle, !isRoot && /* @__PURE__ */ React26.createElement(UIVarName2, null, v?.key))
2583
+ /* @__PURE__ */ React26.createElement(UITag2, { prefixIcon: rootIcon }, rootTitle, /* @__PURE__ */ React26.createElement(UIVarName2, null, v?.key))
2532
2584
  )
2533
2585
  );
2534
2586
  }
2535
2587
  toDOM(view) {
2536
2588
  const dom = document.createElement("span");
2537
- this.rootDOM = dom;
2589
+ this.root = polyfillCreateRoot(dom);
2538
2590
  this.toDispose.push(
2539
2591
  Disposable.create(() => {
2540
- ReactDOM.unmountComponentAtNode(this.rootDOM);
2592
+ this.root.unmount();
2541
2593
  })
2542
2594
  );
2543
2595
  this.toDispose.push(
@@ -2827,7 +2879,6 @@ function VariableTree2() {
2827
2879
 
2828
2880
  // src/components/json-editor-with-variables/extensions/variable-tag.tsx
2829
2881
  import React32, { useLayoutEffect as useLayoutEffect5 } from "react";
2830
- import { createRoot } from "react-dom/client";
2831
2882
  import { isEqual as isEqual2, last as last3 } from "lodash";
2832
2883
  import {
2833
2884
  Disposable as Disposable2,
@@ -2918,7 +2969,7 @@ var VariableTagWidget2 = class extends WidgetType2 {
2918
2969
  }
2919
2970
  toDOM(view) {
2920
2971
  const dom = document.createElement("span");
2921
- this.root = createRoot(dom);
2972
+ this.root = polyfillCreateRoot(dom);
2922
2973
  this.toDispose.push(
2923
2974
  Disposable2.create(() => {
2924
2975
  this.root.unmount();
@@ -2985,6 +3036,7 @@ function VariableTagInject2() {
2985
3036
  }
2986
3037
 
2987
3038
  // src/components/json-editor-with-variables/index.tsx
3039
+ import { I18n as I18n13 } from "@flowgram.ai/editor";
2988
3040
  function findAllMatches(inputString, regex) {
2989
3041
  const globalRegex = new RegExp(
2990
3042
  regex,
@@ -3018,7 +3070,7 @@ function JsonEditorWithVariables(props) {
3018
3070
  CodeEditor,
3019
3071
  {
3020
3072
  languageId: "json",
3021
- activeLinePlaceholder: "Press '@' to Select variable",
3073
+ activeLinePlaceholder: I18n13.t("Press '@' to Select variable"),
3022
3074
  ...props,
3023
3075
  options: {
3024
3076
  transformer,
@@ -3032,7 +3084,7 @@ function JsonEditorWithVariables(props) {
3032
3084
 
3033
3085
  // src/components/inputs-values/index.tsx
3034
3086
  import React34 from "react";
3035
- import { I18n as I18n13 } from "@flowgram.ai/editor";
3087
+ import { I18n as I18n14 } from "@flowgram.ai/editor";
3036
3088
  import { Button as Button4, IconButton as IconButton4 } from "@douyinfe/semi-ui";
3037
3089
  import { IconDelete as IconDelete2, IconPlus as IconPlus3 } from "@douyinfe/semi-icons";
3038
3090
 
@@ -3073,7 +3125,7 @@ function InputsValues({
3073
3125
  size: "small",
3074
3126
  value: item.key,
3075
3127
  onChange: (v) => updateKey(item.id, v),
3076
- placeholder: I18n13.t("Input Key")
3128
+ placeholder: I18n14.t("Input Key")
3077
3129
  }
3078
3130
  ), /* @__PURE__ */ React34.createElement(
3079
3131
  InjectDynamicValueInput,
@@ -3110,7 +3162,7 @@ function InputsValues({
3110
3162
  schema: { type: "string" }
3111
3163
  })
3112
3164
  },
3113
- I18n13.t("Add")
3165
+ I18n14.t("Add")
3114
3166
  ));
3115
3167
  }
3116
3168
 
@@ -3509,7 +3561,7 @@ function AssignRows(props) {
3509
3561
 
3510
3562
  // src/components/inputs-values-tree/index.tsx
3511
3563
  import React45 from "react";
3512
- import { I18n as I18n15 } from "@flowgram.ai/editor";
3564
+ import { I18n as I18n16 } from "@flowgram.ai/editor";
3513
3565
  import { Button as Button6 } from "@douyinfe/semi-ui";
3514
3566
  import { IconPlus as IconPlus5 } from "@douyinfe/semi-icons";
3515
3567
 
@@ -3619,7 +3671,7 @@ var IconAddChildren2 = () => /* @__PURE__ */ React43.createElement(Icon4, { size
3619
3671
 
3620
3672
  // src/components/inputs-values-tree/row.tsx
3621
3673
  import React44, { useMemo as useMemo13, useState as useState10 } from "react";
3622
- import { I18n as I18n14 } from "@flowgram.ai/editor";
3674
+ import { I18n as I18n15 } from "@flowgram.ai/editor";
3623
3675
  import { IconButton as IconButton6, Input as Input7 } from "@douyinfe/semi-ui";
3624
3676
  import { IconChevronDown as IconChevronDown2, IconChevronRight as IconChevronRight2, IconDelete as IconDelete3 } from "@douyinfe/semi-icons";
3625
3677
 
@@ -3676,7 +3728,7 @@ var AddObjectChildStrategy = {
3676
3728
  size: "small",
3677
3729
  disabled: true,
3678
3730
  style: { pointerEvents: "none" },
3679
- value: I18n14.t("Configure via child fields")
3731
+ value: I18n15.t("Configure via child fields")
3680
3732
  }
3681
3733
  )
3682
3734
  };
@@ -3717,7 +3769,7 @@ function InputValueRow(props) {
3717
3769
  size: "small",
3718
3770
  value: keyName,
3719
3771
  onChange: (v) => onUpdateKey?.(v),
3720
- placeholder: I18n14.t("Input Key")
3772
+ placeholder: I18n15.t("Input Key")
3721
3773
  }
3722
3774
  ), /* @__PURE__ */ React44.createElement(
3723
3775
  InjectDynamicValueInput,
@@ -3817,7 +3869,7 @@ function InputsValuesTree(props) {
3817
3869
  });
3818
3870
  }
3819
3871
  },
3820
- I18n15.t("Add")
3872
+ I18n16.t("Add")
3821
3873
  ));
3822
3874
  }
3823
3875
 
@@ -4284,10 +4336,12 @@ export {
4284
4336
  listenRefSchemaChange,
4285
4337
  listenRefValueChange,
4286
4338
  parseTypeSelectValue,
4339
+ polyfillCreateRoot,
4287
4340
  provideBatchInputEffect,
4288
4341
  provideBatchOutputsEffect,
4289
4342
  provideJsonSchemaOutputs,
4290
4343
  syncVariableTitle,
4344
+ unstableSetCreateRoot,
4291
4345
  useObjectList,
4292
4346
  useTypeManager,
4293
4347
  useVariableTree,