@flowgram.ai/form-materials 0.1.30 → 0.2.0

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.
Files changed (39) hide show
  1. package/bin/materials.js +21 -5
  2. package/dist/esm/index.js +463 -57
  3. package/dist/esm/index.js.map +1 -1
  4. package/dist/index.d.mts +171 -28
  5. package/dist/index.d.ts +171 -28
  6. package/dist/index.js +472 -60
  7. package/dist/index.js.map +1 -1
  8. package/package.json +4 -4
  9. package/src/components/batch-variable-selector/config.json +5 -0
  10. package/src/components/batch-variable-selector/index.tsx +18 -0
  11. package/src/components/constant-input/config.json +6 -0
  12. package/src/components/constant-input/index.tsx +81 -0
  13. package/src/components/constant-input/types.ts +18 -0
  14. package/src/components/dynamic-value-input/config.json +5 -0
  15. package/src/components/dynamic-value-input/index.tsx +77 -0
  16. package/src/components/dynamic-value-input/styles.tsx +19 -0
  17. package/src/components/index.ts +6 -3
  18. package/src/components/json-schema-editor/hooks.tsx +33 -22
  19. package/src/components/json-schema-editor/index.tsx +11 -7
  20. package/src/components/json-schema-editor/types.ts +7 -0
  21. package/src/components/type-selector/index.tsx +5 -2
  22. package/src/components/type-selector/types.ts +4 -18
  23. package/src/components/variable-selector/config.json +1 -1
  24. package/src/components/variable-selector/index.tsx +80 -16
  25. package/src/components/variable-selector/styles.tsx +43 -0
  26. package/src/components/variable-selector/use-variable-tree.tsx +29 -7
  27. package/src/effects/index.ts +2 -0
  28. package/src/effects/provide-batch-input/config.json +5 -0
  29. package/src/effects/provide-batch-input/index.ts +38 -0
  30. package/src/effects/provide-batch-outputs/config.json +5 -0
  31. package/src/effects/provide-batch-outputs/index.ts +34 -0
  32. package/src/index.ts +3 -0
  33. package/src/typings/flow-value/config.json +5 -0
  34. package/src/typings/flow-value/index.ts +27 -0
  35. package/src/typings/index.ts +1 -0
  36. package/src/utils/format-legacy-refs/config.json +5 -0
  37. package/src/utils/format-legacy-refs/index.ts +153 -0
  38. package/src/utils/format-legacy-refs/readme.md +38 -0
  39. package/src/utils/index.ts +1 -0
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/components/variable-selector/index.tsx
2
- import React3 from "react";
3
- import { TreeSelect } from "@douyinfe/semi-ui";
2
+ import React3, { useMemo } from "react";
3
+ import { IconChevronDownStroked, IconIssueStroked } from "@douyinfe/semi-icons";
4
4
 
5
5
  // src/components/variable-selector/use-variable-tree.tsx
6
6
  import React2, { useCallback } from "react";
@@ -397,10 +397,11 @@ var options = [
397
397
  ];
398
398
 
399
399
  // src/components/variable-selector/use-variable-tree.tsx
400
- function useVariableTree() {
400
+ function useVariableTree(params) {
401
+ const { includeSchema, excludeSchema } = params;
401
402
  const available = useScopeAvailable();
402
403
  const getVariableTypeIcon = useCallback((variable) => {
403
- if (variable.meta.icon) {
404
+ if (variable.meta?.icon) {
404
405
  if (typeof variable.meta.icon === "string") {
405
406
  return /* @__PURE__ */ React2.createElement("img", { style: { marginRight: 8 }, width: 12, height: 12, src: variable.meta.icon });
406
407
  }
@@ -423,6 +424,9 @@ function useVariableTree() {
423
424
  }, []);
424
425
  const renderVariable = (variable, parentFields = []) => {
425
426
  let type = variable?.type;
427
+ if (!type) {
428
+ return null;
429
+ }
426
430
  let children;
427
431
  if (ASTMatch.isObject(type)) {
428
432
  children = (type.properties || []).map((_property) => renderVariable(_property, [...parentFields, variable])).filter(Boolean);
@@ -430,51 +434,148 @@ function useVariableTree() {
430
434
  return null;
431
435
  }
432
436
  }
433
- const currPath = [...parentFields.map((_field) => _field.key), variable.key].join(".");
437
+ const keyPath = [...parentFields.map((_field) => _field.key), variable.key];
438
+ const key = keyPath.join(".");
439
+ const isSchemaInclude = includeSchema ? type.isEqualWithJSONSchema(includeSchema) : true;
440
+ const isSchemaExclude = excludeSchema ? type.isEqualWithJSONSchema(excludeSchema) : false;
441
+ const isSchemaMatch = isSchemaInclude && !isSchemaExclude;
442
+ if (!isSchemaMatch && !children?.length) {
443
+ return null;
444
+ }
434
445
  return {
435
- key: currPath,
436
- label: variable.meta.title || variable.key,
437
- value: currPath,
446
+ key,
447
+ label: variable.meta?.title || variable.key,
448
+ value: key,
449
+ keyPath,
438
450
  icon: getVariableTypeIcon(variable),
439
- children
451
+ children,
452
+ disabled: !isSchemaMatch,
453
+ rootMeta: parentFields[0]?.meta
440
454
  };
441
455
  };
442
456
  return [...available.variables.slice(0).reverse()].map((_variable) => renderVariable(_variable)).filter(Boolean);
443
457
  }
444
458
 
459
+ // src/components/variable-selector/styles.tsx
460
+ import styled from "styled-components";
461
+ import { Tag, TreeSelect } from "@douyinfe/semi-ui";
462
+ var UIRootTitle = styled.span`
463
+ margin-right: 4px;
464
+ color: var(--semi-color-text-2);
465
+ `;
466
+ var UITag = styled(Tag)`
467
+ width: 100%;
468
+ display: flex;
469
+ align-items: center;
470
+ justify-content: flex-start;
471
+
472
+ & .semi-tag-content-center {
473
+ justify-content: flex-start;
474
+ }
475
+
476
+ &.semi-tag {
477
+ margin: 0;
478
+ }
479
+ `;
480
+ var UITreeSelect = styled(TreeSelect)`
481
+ outline: ${({ $error }) => $error ? "1px solid red" : "none"};
482
+
483
+ height: 22px;
484
+ min-height: 22px;
485
+ line-height: 22px;
486
+
487
+ & .semi-tree-select-selection {
488
+ padding: 0 2px;
489
+ height: 22px;
490
+ }
491
+
492
+ & .semi-tree-select-selection-content {
493
+ width: 100%;
494
+ }
495
+
496
+ & .semi-tree-select-selection-placeholder {
497
+ padding-left: 10px;
498
+ }
499
+ `;
500
+
445
501
  // src/components/variable-selector/index.tsx
446
502
  var VariableSelector = ({
447
503
  value,
504
+ config,
448
505
  onChange,
449
506
  style,
450
507
  readonly = false,
451
- hasError
508
+ includeSchema,
509
+ excludeSchema,
510
+ hasError,
511
+ triggerRender
452
512
  }) => {
453
- const treeData = useVariableTree();
513
+ const treeData = useVariableTree({ includeSchema, excludeSchema });
514
+ const treeValue = useMemo(() => {
515
+ if (typeof value === "string") {
516
+ console.warn(
517
+ "The Value of VariableSelector is a string, it should be an ARRAY. \n",
518
+ "Please check the value of VariableSelector \n"
519
+ );
520
+ return value;
521
+ }
522
+ return value?.join(".");
523
+ }, [value]);
524
+ const renderIcon = (icon) => {
525
+ if (typeof icon === "string") {
526
+ return /* @__PURE__ */ React3.createElement("img", { style: { marginRight: 8 }, width: 12, height: 12, src: icon });
527
+ }
528
+ return icon;
529
+ };
454
530
  return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(
455
- TreeSelect,
531
+ UITreeSelect,
456
532
  {
457
533
  dropdownMatchSelectWidth: false,
458
534
  disabled: readonly,
459
535
  treeData,
460
536
  size: "small",
461
- value,
462
- style: {
463
- ...style,
464
- outline: hasError ? "1px solid red" : void 0
465
- },
537
+ value: treeValue,
538
+ clearIcon: null,
539
+ $error: hasError,
540
+ style,
466
541
  validateStatus: hasError ? "error" : void 0,
467
- onChange: (option) => {
468
- onChange(option);
542
+ onChange: (_, _config) => {
543
+ onChange(_config.keyPath);
469
544
  },
470
- showClear: true,
471
- placeholder: "Select Variable..."
545
+ renderSelectedItem: (_option) => {
546
+ if (!_option?.keyPath) {
547
+ return /* @__PURE__ */ React3.createElement(
548
+ UITag,
549
+ {
550
+ prefixIcon: /* @__PURE__ */ React3.createElement(IconIssueStroked, null),
551
+ color: "amber",
552
+ closable: !readonly,
553
+ onClose: () => onChange(void 0)
554
+ },
555
+ config?.notFoundContent ?? "Undefined"
556
+ );
557
+ }
558
+ return /* @__PURE__ */ React3.createElement(
559
+ UITag,
560
+ {
561
+ prefixIcon: renderIcon(_option.rootMeta?.icon || _option?.icon),
562
+ closable: !readonly,
563
+ onClose: () => onChange(void 0)
564
+ },
565
+ /* @__PURE__ */ React3.createElement(UIRootTitle, null, _option.rootMeta?.title ? `${_option.rootMeta?.title} -` : null),
566
+ _option.label
567
+ );
568
+ },
569
+ showClear: false,
570
+ arrowIcon: value ? null : /* @__PURE__ */ React3.createElement(IconChevronDownStroked, { size: "small" }),
571
+ triggerRender,
572
+ placeholder: config?.placeholder ?? "Select Variable..."
472
573
  }
473
574
  ));
474
575
  };
475
576
 
476
577
  // src/components/type-selector/index.tsx
477
- import React4, { useMemo } from "react";
578
+ import React4, { useMemo as useMemo2 } from "react";
478
579
  import { Button, Cascader } from "@douyinfe/semi-ui";
479
580
  var getTypeSelectValue = (value) => {
480
581
  if (value?.type === "array" && value?.items) {
@@ -490,13 +591,14 @@ var parseTypeSelectValue = (value) => {
490
591
  return { type };
491
592
  };
492
593
  function TypeSelector(props) {
493
- const { value, onChange } = props;
494
- const selectValue = useMemo(() => getTypeSelectValue(value), [value]);
594
+ const { value, onChange, disabled, style } = props;
595
+ const selectValue = useMemo2(() => getTypeSelectValue(value), [value]);
495
596
  return /* @__PURE__ */ React4.createElement(
496
597
  Cascader,
497
598
  {
599
+ disabled,
498
600
  size: "small",
499
- triggerRender: () => /* @__PURE__ */ React4.createElement(Button, { size: "small", style: { width: 50 } }, getSchemaIcon(value)),
601
+ triggerRender: () => /* @__PURE__ */ React4.createElement(Button, { size: "small", style }, getSchemaIcon(value)),
500
602
  treeData: options,
501
603
  value: selectValue,
502
604
  leafOnly: true,
@@ -508,7 +610,7 @@ function TypeSelector(props) {
508
610
  }
509
611
 
510
612
  // src/components/json-schema-editor/index.tsx
511
- import React6, { useMemo as useMemo3, useState as useState2 } from "react";
613
+ import React6, { useMemo as useMemo4, useState as useState2 } from "react";
512
614
  import { Button as Button2, Checkbox, IconButton, Input } from "@douyinfe/semi-ui";
513
615
  import {
514
616
  IconExpand,
@@ -521,35 +623,35 @@ import {
521
623
 
522
624
  // src/components/json-schema-editor/styles.tsx
523
625
  import React5 from "react";
524
- import styled, { css } from "styled-components";
626
+ import styled2, { css } from "styled-components";
525
627
  import Icon3 from "@douyinfe/semi-icons";
526
- var UIContainer = styled.div`
628
+ var UIContainer = styled2.div`
527
629
  /* & .semi-input {
528
630
  background-color: #fff;
529
631
  border-radius: 6px;
530
632
  height: 24px;
531
633
  } */
532
634
  `;
533
- var UIRow = styled.div`
635
+ var UIRow = styled2.div`
534
636
  display: flex;
535
637
  align-items: center;
536
638
  gap: 6px;
537
639
  `;
538
- var UICollapseTrigger = styled.div`
640
+ var UICollapseTrigger = styled2.div`
539
641
  cursor: pointer;
540
642
  margin-right: 5px;
541
643
  `;
542
- var UIExpandDetail = styled.div`
644
+ var UIExpandDetail = styled2.div`
543
645
  display: flex;
544
646
  flex-direction: column;
545
647
  `;
546
- var UILabel = styled.div`
648
+ var UILabel = styled2.div`
547
649
  font-size: 12px;
548
650
  color: #999;
549
651
  font-weight: 400;
550
652
  margin-bottom: 2px;
551
653
  `;
552
- var UIProperties = styled.div`
654
+ var UIProperties = styled2.div`
553
655
  display: grid;
554
656
  grid-template-columns: auto 1fr;
555
657
 
@@ -558,7 +660,7 @@ var UIProperties = styled.div`
558
660
  margin-top: 10px;
559
661
  `}
560
662
  `;
561
- var UIPropertyLeft = styled.div`
663
+ var UIPropertyLeft = styled2.div`
562
664
  grid-column: 1;
563
665
  position: relative;
564
666
 
@@ -588,7 +690,7 @@ var UIPropertyLeft = styled.div`
588
690
  }
589
691
  `}
590
692
  `;
591
- var UIPropertyRight = styled.div`
693
+ var UIPropertyRight = styled2.div`
592
694
  grid-column: 2;
593
695
  margin-bottom: 10px;
594
696
 
@@ -596,7 +698,7 @@ var UIPropertyRight = styled.div`
596
698
  margin-bottom: 0px;
597
699
  }
598
700
  `;
599
- var UIPropertyMain = styled.div`
701
+ var UIPropertyMain = styled2.div`
600
702
  display: flex;
601
703
  flex-direction: column;
602
704
  gap: 10px;
@@ -607,19 +709,19 @@ var UIPropertyMain = styled.div`
607
709
  border-radius: 4px;
608
710
  `}
609
711
  `;
610
- var UICollapsible = styled.div`
712
+ var UICollapsible = styled2.div`
611
713
  display: none;
612
714
 
613
715
  ${({ $collapse }) => $collapse && css`
614
716
  display: block;
615
717
  `}
616
718
  `;
617
- var UIName = styled.div`
719
+ var UIName = styled2.div`
618
720
  flex-grow: 1;
619
721
  `;
620
- var UIType = styled.div``;
621
- var UIRequired = styled.div``;
622
- var UIActions = styled.div`
722
+ var UIType = styled2.div``;
723
+ var UIRequired = styled2.div``;
724
+ var UIActions = styled2.div`
623
725
  white-space: nowrap;
624
726
  `;
625
727
  var iconAddChildrenSvg = /* @__PURE__ */ React5.createElement(
@@ -645,7 +747,7 @@ var iconAddChildrenSvg = /* @__PURE__ */ React5.createElement(
645
747
  var IconAddChildren = () => /* @__PURE__ */ React5.createElement(Icon3, { size: "small", svg: iconAddChildrenSvg });
646
748
 
647
749
  // src/components/json-schema-editor/hooks.tsx
648
- import { useEffect, useMemo as useMemo2, useRef, useState } from "react";
750
+ import { useEffect, useMemo as useMemo3, useRef, useState } from "react";
649
751
  var _id = 0;
650
752
  function genId() {
651
753
  return _id++;
@@ -660,15 +762,19 @@ function getDrilldownSchema(value, path) {
660
762
  return { schema: value, path };
661
763
  }
662
764
  function usePropertiesEdit(value, onChange) {
663
- const drilldown = useMemo2(() => getDrilldownSchema(value), [value, value?.type, value?.items]);
765
+ const drilldown = useMemo3(() => getDrilldownSchema(value), [value, value?.type, value?.items]);
664
766
  const isDrilldownObject = drilldown.schema?.type === "object";
665
- const initPropertyList = useMemo2(
666
- () => isDrilldownObject ? Object.entries(drilldown.schema?.properties || {}).map(
667
- ([name, _value]) => ({
767
+ const initPropertyList = useMemo3(
768
+ () => isDrilldownObject ? Object.entries(drilldown.schema?.properties || {}).sort(([, a], [, b]) => (a.extra?.index ?? 0) - (b.extra?.index ?? 0)).map(
769
+ ([name, _value], index) => ({
668
770
  key: genId(),
669
771
  name,
670
772
  isPropertyRequired: drilldown.schema?.required?.includes(name) || false,
671
- ..._value
773
+ ..._value,
774
+ extra: {
775
+ ..._value.extra || {},
776
+ index
777
+ }
672
778
  })
673
779
  ) : [],
674
780
  [isDrilldownObject]
@@ -684,7 +790,7 @@ function usePropertiesEdit(value, onChange) {
684
790
  nameMap.set(_property.name, _property);
685
791
  }
686
792
  }
687
- return Object.entries(drilldown.schema?.properties || {}).map(([name, _value]) => {
793
+ return Object.entries(drilldown.schema?.properties || {}).sort(([, a], [, b]) => (a.extra?.index ?? 0) - (b.extra?.index ?? 0)).map(([name, _value]) => {
688
794
  const _property = nameMap.get(name);
689
795
  if (_property) {
690
796
  return {
@@ -730,7 +836,10 @@ function usePropertiesEdit(value, onChange) {
730
836
  });
731
837
  };
732
838
  const onAddProperty = () => {
733
- updatePropertyList((_list) => [..._list, { key: genId(), name: "", type: "string" }]);
839
+ updatePropertyList((_list) => [
840
+ ..._list,
841
+ { key: genId(), name: "", type: "string", extra: { index: _list.length + 1 } }
842
+ ]);
734
843
  };
735
844
  const onRemoveProperty = (key) => {
736
845
  updatePropertyList((_list) => _list.filter((_property) => _property.key !== key));
@@ -756,7 +865,7 @@ function usePropertiesEdit(value, onChange) {
756
865
 
757
866
  // src/components/json-schema-editor/index.tsx
758
867
  function JsonSchemaEditor(props) {
759
- const { value = { type: "object" }, onChange: onChangeProps } = props;
868
+ const { value = { type: "object" }, config = {}, onChange: onChangeProps } = props;
760
869
  const { propertyList, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(
761
870
  value,
762
871
  onChangeProps
@@ -766,6 +875,7 @@ function JsonSchemaEditor(props) {
766
875
  {
767
876
  key: _property.key,
768
877
  value: _property,
878
+ config,
769
879
  onChange: (_v) => {
770
880
  onEditProperty(_property.key, _v);
771
881
  },
@@ -773,14 +883,14 @@ function JsonSchemaEditor(props) {
773
883
  onRemoveProperty(_property.key);
774
884
  }
775
885
  }
776
- ))), /* @__PURE__ */ React6.createElement(Button2, { size: "small", style: { marginTop: 10 }, icon: /* @__PURE__ */ React6.createElement(IconPlus, null), onClick: onAddProperty }, "Add"));
886
+ ))), /* @__PURE__ */ React6.createElement(Button2, { size: "small", style: { marginTop: 10 }, icon: /* @__PURE__ */ React6.createElement(IconPlus, null), onClick: onAddProperty }, config?.addButtonText ?? "Add"));
777
887
  }
778
888
  function PropertyEdit(props) {
779
- const { value, onChange: onChangeProps, onRemove, $isLast, $showLine } = props;
889
+ const { value, config, onChange: onChangeProps, onRemove, $isLast, $showLine } = props;
780
890
  const [expand, setExpand] = useState2(false);
781
891
  const [collapse, setCollapse] = useState2(false);
782
892
  const { name, type, items, description, isPropertyRequired } = value || {};
783
- const typeSelectorValue = useMemo3(() => ({ type, items }), [type, items]);
893
+ const typeSelectorValue = useMemo4(() => ({ type, items }), [type, items]);
784
894
  const { propertyList, isDrilldownObject, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(value, onChangeProps);
785
895
  const onChange = (key, _value) => {
786
896
  onChangeProps?.({
@@ -792,7 +902,7 @@ function PropertyEdit(props) {
792
902
  return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(UIPropertyLeft, { $isLast, $showLine }, showCollapse && /* @__PURE__ */ React6.createElement(UICollapseTrigger, { onClick: () => setCollapse((_collapse) => !_collapse) }, collapse ? /* @__PURE__ */ React6.createElement(IconChevronDown, { size: "small" }) : /* @__PURE__ */ React6.createElement(IconChevronRight, { size: "small" }))), /* @__PURE__ */ React6.createElement(UIPropertyRight, null, /* @__PURE__ */ React6.createElement(UIPropertyMain, { $expand: expand }, /* @__PURE__ */ React6.createElement(UIRow, null, /* @__PURE__ */ React6.createElement(UIName, null, /* @__PURE__ */ React6.createElement(
793
903
  Input,
794
904
  {
795
- placeholder: "Input Variable Name",
905
+ placeholder: config?.placeholder ?? "Input Variable Name",
796
906
  size: "small",
797
907
  value: name,
798
908
  onChange: (value2) => onChange("name", value2)
@@ -841,19 +951,20 @@ function PropertyEdit(props) {
841
951
  icon: /* @__PURE__ */ React6.createElement(IconMinus, { size: "small" }),
842
952
  onClick: onRemove
843
953
  }
844
- ))), expand && /* @__PURE__ */ React6.createElement(UIExpandDetail, null, /* @__PURE__ */ React6.createElement(UILabel, null, "Description"), /* @__PURE__ */ React6.createElement(
954
+ ))), expand && /* @__PURE__ */ React6.createElement(UIExpandDetail, null, /* @__PURE__ */ React6.createElement(UILabel, null, config?.descTitle ?? "Description"), /* @__PURE__ */ React6.createElement(
845
955
  Input,
846
956
  {
847
957
  size: "small",
848
958
  value: description,
849
959
  onChange: (value2) => onChange("description", value2),
850
- placeholder: "Help LLM to understand the property"
960
+ placeholder: config?.descPlaceholder ?? "Help LLM to understand the property"
851
961
  }
852
962
  ))), showCollapse && /* @__PURE__ */ React6.createElement(UICollapsible, { $collapse: collapse }, /* @__PURE__ */ React6.createElement(UIProperties, { $shrink: true }, propertyList.map((_property, index) => /* @__PURE__ */ React6.createElement(
853
963
  PropertyEdit,
854
964
  {
855
965
  key: _property.key,
856
966
  value: _property,
967
+ config,
857
968
  onChange: (_v) => {
858
969
  onEditProperty(_property.key, _v);
859
970
  },
@@ -865,11 +976,306 @@ function PropertyEdit(props) {
865
976
  }
866
977
  ))))));
867
978
  }
979
+
980
+ // src/components/batch-variable-selector/index.tsx
981
+ import React7 from "react";
982
+ import { PrivateScopeProvider } from "@flowgram.ai/editor";
983
+ var batchVariableSchema = {
984
+ type: "array",
985
+ extra: { weak: true }
986
+ };
987
+ function BatchVariableSelector(props) {
988
+ return /* @__PURE__ */ React7.createElement(PrivateScopeProvider, null, /* @__PURE__ */ React7.createElement(VariableSelector, { ...props, includeSchema: batchVariableSchema }));
989
+ }
990
+
991
+ // src/components/constant-input/index.tsx
992
+ import React8, { useMemo as useMemo5 } from "react";
993
+ import { Input as Input2, InputNumber, Select } from "@douyinfe/semi-ui";
994
+ var defaultStrategies = [
995
+ {
996
+ hit: (schema) => schema?.type === "string",
997
+ Renderer: (props) => /* @__PURE__ */ React8.createElement(Input2, { placeholder: "Please Input String", size: "small", disabled: props.readonly, ...props })
998
+ },
999
+ {
1000
+ hit: (schema) => schema?.type === "number",
1001
+ Renderer: (props) => /* @__PURE__ */ React8.createElement(
1002
+ InputNumber,
1003
+ {
1004
+ placeholder: "Please Input Number",
1005
+ size: "small",
1006
+ disabled: props.readonly,
1007
+ hideButtons: true,
1008
+ ...props
1009
+ }
1010
+ )
1011
+ },
1012
+ {
1013
+ hit: (schema) => schema?.type === "integer",
1014
+ Renderer: (props) => /* @__PURE__ */ React8.createElement(
1015
+ InputNumber,
1016
+ {
1017
+ placeholder: "Please Input Integer",
1018
+ size: "small",
1019
+ disabled: props.readonly,
1020
+ hideButtons: true,
1021
+ precision: 0,
1022
+ ...props
1023
+ }
1024
+ )
1025
+ },
1026
+ {
1027
+ hit: (schema) => schema?.type === "boolean",
1028
+ Renderer: (props) => {
1029
+ const { value, onChange, ...rest } = props;
1030
+ return /* @__PURE__ */ React8.createElement(
1031
+ Select,
1032
+ {
1033
+ placeholder: "Please Select Boolean",
1034
+ size: "small",
1035
+ disabled: props.readonly,
1036
+ optionList: [
1037
+ { label: "True", value: 1 },
1038
+ { label: "False", value: 0 }
1039
+ ],
1040
+ value: value ? 1 : 0,
1041
+ onChange: (value2) => onChange?.(!!value2),
1042
+ ...rest
1043
+ }
1044
+ );
1045
+ }
1046
+ }
1047
+ ];
1048
+ function ConstantInput(props) {
1049
+ const { value, onChange, schema, strategies: extraStrategies, readonly, ...rest } = props;
1050
+ const strategies = useMemo5(
1051
+ () => [...defaultStrategies, ...extraStrategies || []],
1052
+ [extraStrategies]
1053
+ );
1054
+ const Renderer = useMemo5(() => {
1055
+ const strategy = strategies.find((_strategy) => _strategy.hit(schema));
1056
+ return strategy?.Renderer;
1057
+ }, [strategies, schema]);
1058
+ if (!Renderer) {
1059
+ return /* @__PURE__ */ React8.createElement(Input2, { size: "small", disabled: true, placeholder: "Unsupported type" });
1060
+ }
1061
+ return /* @__PURE__ */ React8.createElement(Renderer, { value, onChange, readonly, ...rest });
1062
+ }
1063
+
1064
+ // src/components/dynamic-value-input/index.tsx
1065
+ import React9 from "react";
1066
+ import { IconButton as IconButton2 } from "@douyinfe/semi-ui";
1067
+ import { IconSetting } from "@douyinfe/semi-icons";
1068
+
1069
+ // src/components/dynamic-value-input/styles.tsx
1070
+ import styled3 from "styled-components";
1071
+ var UIContainer2 = styled3.div`
1072
+ display: flex;
1073
+ align-items: center;
1074
+ gap: 5px;
1075
+ `;
1076
+ var UIMain = styled3.div`
1077
+ flex-grow: 1;
1078
+
1079
+ & .semi-tree-select,
1080
+ & .semi-input-number,
1081
+ & .semi-select {
1082
+ width: 100%;
1083
+ }
1084
+ `;
1085
+ var UITrigger = styled3.div``;
1086
+
1087
+ // src/components/dynamic-value-input/index.tsx
1088
+ function DynamicValueInput({
1089
+ value,
1090
+ onChange,
1091
+ readonly,
1092
+ style,
1093
+ schema,
1094
+ constantProps
1095
+ }) {
1096
+ const renderMain = () => {
1097
+ if (value?.type === "ref") {
1098
+ return /* @__PURE__ */ React9.createElement(
1099
+ VariableSelector,
1100
+ {
1101
+ value: value?.content,
1102
+ onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : void 0),
1103
+ includeSchema: schema,
1104
+ readonly
1105
+ }
1106
+ );
1107
+ }
1108
+ return /* @__PURE__ */ React9.createElement(
1109
+ ConstantInput,
1110
+ {
1111
+ value: value?.content,
1112
+ onChange: (_v) => onChange({ type: "constant", content: _v }),
1113
+ schema: schema || { type: "string" },
1114
+ readonly,
1115
+ ...constantProps
1116
+ }
1117
+ );
1118
+ };
1119
+ const renderTrigger = () => /* @__PURE__ */ React9.createElement(
1120
+ VariableSelector,
1121
+ {
1122
+ style: { width: "100%" },
1123
+ value: value?.type === "ref" ? value?.content : void 0,
1124
+ onChange: (_v) => onChange({ type: "ref", content: _v }),
1125
+ includeSchema: schema,
1126
+ readonly,
1127
+ triggerRender: () => /* @__PURE__ */ React9.createElement(IconButton2, { disabled: readonly, size: "small", icon: /* @__PURE__ */ React9.createElement(IconSetting, { size: "small" }) })
1128
+ }
1129
+ );
1130
+ return /* @__PURE__ */ React9.createElement(UIContainer2, { style }, /* @__PURE__ */ React9.createElement(UIMain, null, renderMain()), /* @__PURE__ */ React9.createElement(UITrigger, null, renderTrigger()));
1131
+ }
1132
+
1133
+ // src/effects/provide-batch-input/index.ts
1134
+ import {
1135
+ ASTFactory,
1136
+ createEffectFromVariableProvider,
1137
+ getNodeForm
1138
+ } from "@flowgram.ai/editor";
1139
+ var provideBatchInputEffect = createEffectFromVariableProvider({
1140
+ private: true,
1141
+ parse: (value, ctx) => [
1142
+ ASTFactory.createVariableDeclaration({
1143
+ key: `${ctx.node.id}_locals`,
1144
+ meta: {
1145
+ title: getNodeForm(ctx.node)?.getValueIn("title"),
1146
+ icon: ctx.node.getNodeRegistry().info?.icon
1147
+ },
1148
+ type: ASTFactory.createObject({
1149
+ properties: [
1150
+ ASTFactory.createProperty({
1151
+ key: "item",
1152
+ initializer: ASTFactory.createEnumerateExpression({
1153
+ enumerateFor: ASTFactory.createKeyPathExpression({
1154
+ keyPath: value.content || []
1155
+ })
1156
+ })
1157
+ }),
1158
+ ASTFactory.createProperty({
1159
+ key: "index",
1160
+ type: ASTFactory.createNumber()
1161
+ })
1162
+ ]
1163
+ })
1164
+ })
1165
+ ]
1166
+ });
1167
+
1168
+ // src/effects/provide-batch-outputs/index.ts
1169
+ import {
1170
+ ASTFactory as ASTFactory2,
1171
+ createEffectFromVariableProvider as createEffectFromVariableProvider2,
1172
+ getNodeForm as getNodeForm2
1173
+ } from "@flowgram.ai/editor";
1174
+ var provideBatchOutputsEffect = createEffectFromVariableProvider2({
1175
+ private: true,
1176
+ parse: (value, ctx) => [
1177
+ ASTFactory2.createVariableDeclaration({
1178
+ key: `${ctx.node.id}`,
1179
+ meta: {
1180
+ title: getNodeForm2(ctx.node)?.getValueIn("title"),
1181
+ icon: ctx.node.getNodeRegistry().info?.icon
1182
+ },
1183
+ type: ASTFactory2.createObject({
1184
+ properties: Object.entries(value).map(
1185
+ ([_key, value2]) => ASTFactory2.createProperty({
1186
+ key: _key,
1187
+ initializer: ASTFactory2.createWrapArrayExpression({
1188
+ wrapFor: ASTFactory2.createKeyPathExpression({
1189
+ keyPath: value2.content || []
1190
+ })
1191
+ })
1192
+ })
1193
+ )
1194
+ })
1195
+ })
1196
+ ]
1197
+ });
1198
+
1199
+ // src/utils/format-legacy-refs/index.ts
1200
+ import { isObject } from "lodash";
1201
+ function formatLegacyRefOnSubmit(value) {
1202
+ if (isObject(value)) {
1203
+ if (isLegacyFlowRefValueSchema(value)) {
1204
+ return formatLegacyRefToNewRef(value);
1205
+ }
1206
+ return Object.fromEntries(
1207
+ Object.entries(value).map(([key, value2]) => [
1208
+ key,
1209
+ formatLegacyRefOnSubmit(value2)
1210
+ ])
1211
+ );
1212
+ }
1213
+ if (Array.isArray(value)) {
1214
+ return value.map(formatLegacyRefOnSubmit);
1215
+ }
1216
+ return value;
1217
+ }
1218
+ function formatLegacyRefOnInit(value) {
1219
+ if (isObject(value)) {
1220
+ if (isNewFlowRefValueSchema(value)) {
1221
+ return formatNewRefToLegacyRef(value);
1222
+ }
1223
+ return Object.fromEntries(
1224
+ Object.entries(value).map(([key, value2]) => [
1225
+ key,
1226
+ formatLegacyRefOnInit(value2)
1227
+ ])
1228
+ );
1229
+ }
1230
+ if (Array.isArray(value)) {
1231
+ return value.map(formatLegacyRefOnInit);
1232
+ }
1233
+ return value;
1234
+ }
1235
+ function isLegacyFlowRefValueSchema(value) {
1236
+ return isObject(value) && Object.keys(value).length === 2 && value.type === "ref" && typeof value.content === "string";
1237
+ }
1238
+ function isNewFlowRefValueSchema(value) {
1239
+ return isObject(value) && Object.keys(value).length === 2 && value.type === "ref" && Array.isArray(value.content);
1240
+ }
1241
+ function formatLegacyRefToNewRef(value) {
1242
+ const keyPath = value.content.split(".");
1243
+ if (keyPath[1] === "outputs") {
1244
+ return {
1245
+ type: "ref",
1246
+ content: [`${keyPath[0]}.${keyPath[1]}`, ...keyPath.length > 2 ? keyPath.slice(2) : []]
1247
+ };
1248
+ }
1249
+ return {
1250
+ type: "ref",
1251
+ content: keyPath
1252
+ };
1253
+ }
1254
+ function formatNewRefToLegacyRef(value) {
1255
+ return {
1256
+ type: "ref",
1257
+ content: value.content.join(".")
1258
+ };
1259
+ }
868
1260
  export {
869
1261
  ArrayIcons,
1262
+ BatchVariableSelector,
1263
+ ConstantInput,
1264
+ DynamicValueInput,
870
1265
  JsonSchemaEditor,
871
1266
  TypeSelector,
872
1267
  VariableSelector,
873
- VariableTypeIcons
1268
+ VariableTypeIcons,
1269
+ formatLegacyRefOnInit,
1270
+ formatLegacyRefOnSubmit,
1271
+ formatLegacyRefToNewRef,
1272
+ formatNewRefToLegacyRef,
1273
+ getSchemaIcon,
1274
+ getTypeSelectValue,
1275
+ isLegacyFlowRefValueSchema,
1276
+ isNewFlowRefValueSchema,
1277
+ parseTypeSelectValue,
1278
+ provideBatchInputEffect,
1279
+ provideBatchOutputsEffect
874
1280
  };
875
1281
  //# sourceMappingURL=index.js.map