@flowgram.ai/form-materials 0.1.31 → 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.
- package/bin/materials.js +21 -5
- package/dist/esm/index.js +453 -50
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +161 -29
- package/dist/index.d.ts +161 -29
- package/dist/index.js +463 -54
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/batch-variable-selector/config.json +5 -0
- package/src/components/batch-variable-selector/index.tsx +18 -0
- package/src/components/constant-input/config.json +6 -0
- package/src/components/constant-input/index.tsx +81 -0
- package/src/components/constant-input/types.ts +18 -0
- package/src/components/dynamic-value-input/config.json +5 -0
- package/src/components/dynamic-value-input/index.tsx +77 -0
- package/src/components/dynamic-value-input/styles.tsx +19 -0
- package/src/components/index.ts +6 -3
- package/src/components/json-schema-editor/hooks.tsx +33 -22
- package/src/components/type-selector/index.tsx +5 -2
- package/src/components/type-selector/types.ts +4 -18
- package/src/components/variable-selector/config.json +1 -1
- package/src/components/variable-selector/index.tsx +76 -16
- package/src/components/variable-selector/styles.tsx +43 -0
- package/src/components/variable-selector/use-variable-tree.tsx +29 -7
- package/src/effects/index.ts +2 -0
- package/src/effects/provide-batch-input/config.json +5 -0
- package/src/effects/provide-batch-input/index.ts +38 -0
- package/src/effects/provide-batch-outputs/config.json +5 -0
- package/src/effects/provide-batch-outputs/index.ts +34 -0
- package/src/index.ts +3 -0
- package/src/typings/flow-value/config.json +5 -0
- package/src/typings/flow-value/index.ts +27 -0
- package/src/typings/index.ts +1 -0
- package/src/utils/format-legacy-refs/config.json +5 -0
- package/src/utils/format-legacy-refs/index.ts +153 -0
- package/src/utils/format-legacy-refs/readme.md +38 -0
- 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 {
|
|
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
|
|
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,18 +434,70 @@ function useVariableTree() {
|
|
|
430
434
|
return null;
|
|
431
435
|
}
|
|
432
436
|
}
|
|
433
|
-
const
|
|
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
|
|
436
|
-
label: variable.meta
|
|
437
|
-
value:
|
|
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,
|
|
@@ -449,33 +505,77 @@ var VariableSelector = ({
|
|
|
449
505
|
onChange,
|
|
450
506
|
style,
|
|
451
507
|
readonly = false,
|
|
452
|
-
|
|
508
|
+
includeSchema,
|
|
509
|
+
excludeSchema,
|
|
510
|
+
hasError,
|
|
511
|
+
triggerRender
|
|
453
512
|
}) => {
|
|
454
|
-
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
|
+
};
|
|
455
530
|
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(
|
|
456
|
-
|
|
531
|
+
UITreeSelect,
|
|
457
532
|
{
|
|
458
533
|
dropdownMatchSelectWidth: false,
|
|
459
534
|
disabled: readonly,
|
|
460
535
|
treeData,
|
|
461
536
|
size: "small",
|
|
462
|
-
value,
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
},
|
|
537
|
+
value: treeValue,
|
|
538
|
+
clearIcon: null,
|
|
539
|
+
$error: hasError,
|
|
540
|
+
style,
|
|
467
541
|
validateStatus: hasError ? "error" : void 0,
|
|
468
|
-
onChange: (
|
|
469
|
-
onChange(
|
|
542
|
+
onChange: (_, _config) => {
|
|
543
|
+
onChange(_config.keyPath);
|
|
470
544
|
},
|
|
471
|
-
|
|
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,
|
|
472
572
|
placeholder: config?.placeholder ?? "Select Variable..."
|
|
473
573
|
}
|
|
474
574
|
));
|
|
475
575
|
};
|
|
476
576
|
|
|
477
577
|
// src/components/type-selector/index.tsx
|
|
478
|
-
import React4, { useMemo } from "react";
|
|
578
|
+
import React4, { useMemo as useMemo2 } from "react";
|
|
479
579
|
import { Button, Cascader } from "@douyinfe/semi-ui";
|
|
480
580
|
var getTypeSelectValue = (value) => {
|
|
481
581
|
if (value?.type === "array" && value?.items) {
|
|
@@ -491,13 +591,14 @@ var parseTypeSelectValue = (value) => {
|
|
|
491
591
|
return { type };
|
|
492
592
|
};
|
|
493
593
|
function TypeSelector(props) {
|
|
494
|
-
const { value, onChange } = props;
|
|
495
|
-
const selectValue =
|
|
594
|
+
const { value, onChange, disabled, style } = props;
|
|
595
|
+
const selectValue = useMemo2(() => getTypeSelectValue(value), [value]);
|
|
496
596
|
return /* @__PURE__ */ React4.createElement(
|
|
497
597
|
Cascader,
|
|
498
598
|
{
|
|
599
|
+
disabled,
|
|
499
600
|
size: "small",
|
|
500
|
-
triggerRender: () => /* @__PURE__ */ React4.createElement(Button, { size: "small", style
|
|
601
|
+
triggerRender: () => /* @__PURE__ */ React4.createElement(Button, { size: "small", style }, getSchemaIcon(value)),
|
|
501
602
|
treeData: options,
|
|
502
603
|
value: selectValue,
|
|
503
604
|
leafOnly: true,
|
|
@@ -509,7 +610,7 @@ function TypeSelector(props) {
|
|
|
509
610
|
}
|
|
510
611
|
|
|
511
612
|
// src/components/json-schema-editor/index.tsx
|
|
512
|
-
import React6, { useMemo as
|
|
613
|
+
import React6, { useMemo as useMemo4, useState as useState2 } from "react";
|
|
513
614
|
import { Button as Button2, Checkbox, IconButton, Input } from "@douyinfe/semi-ui";
|
|
514
615
|
import {
|
|
515
616
|
IconExpand,
|
|
@@ -522,35 +623,35 @@ import {
|
|
|
522
623
|
|
|
523
624
|
// src/components/json-schema-editor/styles.tsx
|
|
524
625
|
import React5 from "react";
|
|
525
|
-
import
|
|
626
|
+
import styled2, { css } from "styled-components";
|
|
526
627
|
import Icon3 from "@douyinfe/semi-icons";
|
|
527
|
-
var UIContainer =
|
|
628
|
+
var UIContainer = styled2.div`
|
|
528
629
|
/* & .semi-input {
|
|
529
630
|
background-color: #fff;
|
|
530
631
|
border-radius: 6px;
|
|
531
632
|
height: 24px;
|
|
532
633
|
} */
|
|
533
634
|
`;
|
|
534
|
-
var UIRow =
|
|
635
|
+
var UIRow = styled2.div`
|
|
535
636
|
display: flex;
|
|
536
637
|
align-items: center;
|
|
537
638
|
gap: 6px;
|
|
538
639
|
`;
|
|
539
|
-
var UICollapseTrigger =
|
|
640
|
+
var UICollapseTrigger = styled2.div`
|
|
540
641
|
cursor: pointer;
|
|
541
642
|
margin-right: 5px;
|
|
542
643
|
`;
|
|
543
|
-
var UIExpandDetail =
|
|
644
|
+
var UIExpandDetail = styled2.div`
|
|
544
645
|
display: flex;
|
|
545
646
|
flex-direction: column;
|
|
546
647
|
`;
|
|
547
|
-
var UILabel =
|
|
648
|
+
var UILabel = styled2.div`
|
|
548
649
|
font-size: 12px;
|
|
549
650
|
color: #999;
|
|
550
651
|
font-weight: 400;
|
|
551
652
|
margin-bottom: 2px;
|
|
552
653
|
`;
|
|
553
|
-
var UIProperties =
|
|
654
|
+
var UIProperties = styled2.div`
|
|
554
655
|
display: grid;
|
|
555
656
|
grid-template-columns: auto 1fr;
|
|
556
657
|
|
|
@@ -559,7 +660,7 @@ var UIProperties = styled.div`
|
|
|
559
660
|
margin-top: 10px;
|
|
560
661
|
`}
|
|
561
662
|
`;
|
|
562
|
-
var UIPropertyLeft =
|
|
663
|
+
var UIPropertyLeft = styled2.div`
|
|
563
664
|
grid-column: 1;
|
|
564
665
|
position: relative;
|
|
565
666
|
|
|
@@ -589,7 +690,7 @@ var UIPropertyLeft = styled.div`
|
|
|
589
690
|
}
|
|
590
691
|
`}
|
|
591
692
|
`;
|
|
592
|
-
var UIPropertyRight =
|
|
693
|
+
var UIPropertyRight = styled2.div`
|
|
593
694
|
grid-column: 2;
|
|
594
695
|
margin-bottom: 10px;
|
|
595
696
|
|
|
@@ -597,7 +698,7 @@ var UIPropertyRight = styled.div`
|
|
|
597
698
|
margin-bottom: 0px;
|
|
598
699
|
}
|
|
599
700
|
`;
|
|
600
|
-
var UIPropertyMain =
|
|
701
|
+
var UIPropertyMain = styled2.div`
|
|
601
702
|
display: flex;
|
|
602
703
|
flex-direction: column;
|
|
603
704
|
gap: 10px;
|
|
@@ -608,19 +709,19 @@ var UIPropertyMain = styled.div`
|
|
|
608
709
|
border-radius: 4px;
|
|
609
710
|
`}
|
|
610
711
|
`;
|
|
611
|
-
var UICollapsible =
|
|
712
|
+
var UICollapsible = styled2.div`
|
|
612
713
|
display: none;
|
|
613
714
|
|
|
614
715
|
${({ $collapse }) => $collapse && css`
|
|
615
716
|
display: block;
|
|
616
717
|
`}
|
|
617
718
|
`;
|
|
618
|
-
var UIName =
|
|
719
|
+
var UIName = styled2.div`
|
|
619
720
|
flex-grow: 1;
|
|
620
721
|
`;
|
|
621
|
-
var UIType =
|
|
622
|
-
var UIRequired =
|
|
623
|
-
var UIActions =
|
|
722
|
+
var UIType = styled2.div``;
|
|
723
|
+
var UIRequired = styled2.div``;
|
|
724
|
+
var UIActions = styled2.div`
|
|
624
725
|
white-space: nowrap;
|
|
625
726
|
`;
|
|
626
727
|
var iconAddChildrenSvg = /* @__PURE__ */ React5.createElement(
|
|
@@ -646,7 +747,7 @@ var iconAddChildrenSvg = /* @__PURE__ */ React5.createElement(
|
|
|
646
747
|
var IconAddChildren = () => /* @__PURE__ */ React5.createElement(Icon3, { size: "small", svg: iconAddChildrenSvg });
|
|
647
748
|
|
|
648
749
|
// src/components/json-schema-editor/hooks.tsx
|
|
649
|
-
import { useEffect, useMemo as
|
|
750
|
+
import { useEffect, useMemo as useMemo3, useRef, useState } from "react";
|
|
650
751
|
var _id = 0;
|
|
651
752
|
function genId() {
|
|
652
753
|
return _id++;
|
|
@@ -661,15 +762,19 @@ function getDrilldownSchema(value, path) {
|
|
|
661
762
|
return { schema: value, path };
|
|
662
763
|
}
|
|
663
764
|
function usePropertiesEdit(value, onChange) {
|
|
664
|
-
const drilldown =
|
|
765
|
+
const drilldown = useMemo3(() => getDrilldownSchema(value), [value, value?.type, value?.items]);
|
|
665
766
|
const isDrilldownObject = drilldown.schema?.type === "object";
|
|
666
|
-
const initPropertyList =
|
|
667
|
-
() => isDrilldownObject ? Object.entries(drilldown.schema?.properties || {}).map(
|
|
668
|
-
([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) => ({
|
|
669
770
|
key: genId(),
|
|
670
771
|
name,
|
|
671
772
|
isPropertyRequired: drilldown.schema?.required?.includes(name) || false,
|
|
672
|
-
..._value
|
|
773
|
+
..._value,
|
|
774
|
+
extra: {
|
|
775
|
+
..._value.extra || {},
|
|
776
|
+
index
|
|
777
|
+
}
|
|
673
778
|
})
|
|
674
779
|
) : [],
|
|
675
780
|
[isDrilldownObject]
|
|
@@ -685,7 +790,7 @@ function usePropertiesEdit(value, onChange) {
|
|
|
685
790
|
nameMap.set(_property.name, _property);
|
|
686
791
|
}
|
|
687
792
|
}
|
|
688
|
-
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]) => {
|
|
689
794
|
const _property = nameMap.get(name);
|
|
690
795
|
if (_property) {
|
|
691
796
|
return {
|
|
@@ -731,7 +836,10 @@ function usePropertiesEdit(value, onChange) {
|
|
|
731
836
|
});
|
|
732
837
|
};
|
|
733
838
|
const onAddProperty = () => {
|
|
734
|
-
updatePropertyList((_list) => [
|
|
839
|
+
updatePropertyList((_list) => [
|
|
840
|
+
..._list,
|
|
841
|
+
{ key: genId(), name: "", type: "string", extra: { index: _list.length + 1 } }
|
|
842
|
+
]);
|
|
735
843
|
};
|
|
736
844
|
const onRemoveProperty = (key) => {
|
|
737
845
|
updatePropertyList((_list) => _list.filter((_property) => _property.key !== key));
|
|
@@ -782,7 +890,7 @@ function PropertyEdit(props) {
|
|
|
782
890
|
const [expand, setExpand] = useState2(false);
|
|
783
891
|
const [collapse, setCollapse] = useState2(false);
|
|
784
892
|
const { name, type, items, description, isPropertyRequired } = value || {};
|
|
785
|
-
const typeSelectorValue =
|
|
893
|
+
const typeSelectorValue = useMemo4(() => ({ type, items }), [type, items]);
|
|
786
894
|
const { propertyList, isDrilldownObject, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(value, onChangeProps);
|
|
787
895
|
const onChange = (key, _value) => {
|
|
788
896
|
onChangeProps?.({
|
|
@@ -868,11 +976,306 @@ function PropertyEdit(props) {
|
|
|
868
976
|
}
|
|
869
977
|
))))));
|
|
870
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
|
+
}
|
|
871
1260
|
export {
|
|
872
1261
|
ArrayIcons,
|
|
1262
|
+
BatchVariableSelector,
|
|
1263
|
+
ConstantInput,
|
|
1264
|
+
DynamicValueInput,
|
|
873
1265
|
JsonSchemaEditor,
|
|
874
1266
|
TypeSelector,
|
|
875
1267
|
VariableSelector,
|
|
876
|
-
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
|
|
877
1280
|
};
|
|
878
1281
|
//# sourceMappingURL=index.js.map
|