amis 1.4.2-beta.13 → 1.4.2-beta.18
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/lib/Schema.d.ts +4 -3
- package/lib/Schema.js.map +1 -1
- package/lib/components/Alert2.d.ts +26 -21
- package/lib/components/Alert2.js +11 -4
- package/lib/components/Alert2.js.map +2 -2
- package/lib/components/AssociatedSelection.js +2 -2
- package/lib/components/AssociatedSelection.js.map +2 -2
- package/lib/components/Button.js +1 -1
- package/lib/components/Button.js.map +2 -2
- package/lib/components/Checkbox.d.ts +20 -20
- package/lib/components/Collapse.d.ts +51 -23
- package/lib/components/Collapse.js +70 -11
- package/lib/components/Collapse.js.map +2 -2
- package/lib/components/CollapseGroup.d.ts +88 -0
- package/lib/components/CollapseGroup.js +81 -0
- package/lib/components/CollapseGroup.js.map +13 -0
- package/lib/components/ColorPicker.d.ts +5 -1
- package/lib/components/ColorPicker.js +17 -4
- package/lib/components/ColorPicker.js.map +2 -2
- package/lib/components/Editor.d.ts +84 -84
- package/lib/components/GridNav.d.ts +52 -0
- package/lib/components/GridNav.js +123 -0
- package/lib/components/GridNav.js.map +13 -0
- package/lib/components/ListGroup.d.ts +21 -21
- package/lib/components/Overlay.js +5 -0
- package/lib/components/Overlay.js.map +2 -2
- package/lib/components/PopOver.d.ts +1 -0
- package/lib/components/PopOver.js +12 -1
- package/lib/components/PopOver.js.map +2 -2
- package/lib/components/Tabs.d.ts +20 -20
- package/lib/components/TabsTransfer.d.ts +84 -84
- package/lib/components/Toast.d.ts +90 -87
- package/lib/components/Toast.js +15 -5
- package/lib/components/Toast.js.map +2 -2
- package/lib/components/Transfer.d.ts +84 -84
- package/lib/components/TransferDropDown.d.ts +84 -84
- package/lib/components/Tree.d.ts +115 -84
- package/lib/components/Tree.js +183 -30
- package/lib/components/Tree.js.map +2 -2
- package/lib/components/condition-builder/Field.js +2 -3
- package/lib/components/condition-builder/Field.js.map +2 -2
- package/lib/components/icons.js +8 -0
- package/lib/components/icons.js.map +2 -2
- package/lib/envOverwrite.d.ts +1 -1
- package/lib/envOverwrite.js +24 -9
- package/lib/envOverwrite.js.map +2 -2
- package/lib/factory.d.ts +11 -1
- package/lib/factory.js +31 -4
- package/lib/factory.js.map +2 -2
- package/lib/icons/alert-danger.js +7 -0
- package/lib/icons/alert-info.js +7 -0
- package/lib/icons/alert-success.js +7 -0
- package/lib/icons/alert-warning.js +7 -0
- package/lib/icons/drag-bar.js +10 -3
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +2 -2
- package/lib/renderers/Alert.d.ts +21 -1
- package/lib/renderers/Alert.js.map +2 -2
- package/lib/renderers/Card.d.ts +1 -0
- package/lib/renderers/Card.js +7 -2
- package/lib/renderers/Card.js.map +2 -2
- package/lib/renderers/Collapse.d.ts +25 -20
- package/lib/renderers/Collapse.js +10 -73
- package/lib/renderers/Collapse.js.map +2 -2
- package/lib/renderers/CollapseGroup.d.ts +42 -0
- package/lib/renderers/CollapseGroup.js +33 -0
- package/lib/renderers/CollapseGroup.js.map +13 -0
- package/lib/renderers/Form/ConditionBuilder.js +2 -2
- package/lib/renderers/Form/ConditionBuilder.js.map +2 -2
- package/lib/renderers/Form/InputCity.d.ts +84 -84
- package/lib/renderers/Form/InputColor.d.ts +2 -1
- package/lib/renderers/Form/InputColor.js +1 -1
- package/lib/renderers/Form/InputColor.js.map +2 -2
- package/lib/renderers/Form/Item.js +2 -1
- package/lib/renderers/Form/Item.js.map +2 -2
- package/lib/renderers/GridNav.d.ts +99 -0
- package/lib/renderers/GridNav.js +82 -0
- package/lib/renderers/GridNav.js.map +13 -0
- package/lib/renderers/Page.d.ts +18 -0
- package/lib/renderers/Page.js +53 -9
- package/lib/renderers/Page.js.map +2 -2
- package/lib/store/formItem.js +44 -4
- package/lib/store/formItem.js.map +2 -2
- package/lib/themes/ang-ie11.css +324 -49
- package/lib/themes/ang.css +324 -49
- package/lib/themes/ang.css.map +1 -1
- package/lib/themes/antd-ie11.css +324 -49
- package/lib/themes/antd.css +324 -49
- package/lib/themes/antd.css.map +1 -1
- package/lib/themes/cxd-ie11.css +331 -58
- package/lib/themes/cxd.css +331 -58
- package/lib/themes/cxd.css.map +1 -1
- package/lib/themes/dark-ie11.css +324 -49
- package/lib/themes/dark.css +324 -49
- package/lib/themes/dark.css.map +1 -1
- package/lib/themes/default.css +331 -58
- package/lib/themes/default.css.map +1 -1
- package/lib/types.d.ts +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/api.d.ts +1 -0
- package/lib/utils/api.js +77 -6
- package/lib/utils/api.js.map +2 -2
- package/lib/utils/helper.d.ts +8 -0
- package/lib/utils/helper.js +33 -2
- package/lib/utils/helper.js.map +2 -2
- package/lib/utils/tpl-builtin.js +5 -0
- package/lib/utils/tpl-builtin.js.map +2 -2
- package/package.json +1 -1
- package/schema.json +365 -49
- package/scss/_properties.scss +2 -1
- package/scss/components/_alert.scss +28 -5
- package/scss/components/_anchor-nav.scss +1 -0
- package/scss/components/_button.scss +5 -0
- package/scss/components/_card.scss +1 -1
- package/scss/components/_collapse-group.scss +15 -0
- package/scss/components/_collapse.scss +33 -23
- package/scss/components/_grid-nav.scss +128 -0
- package/scss/components/_nav.scss +2 -7
- package/scss/components/_page.scss +35 -2
- package/scss/components/_spinner.scss +5 -4
- package/scss/components/_table.scss +6 -0
- package/scss/components/_toast.scss +41 -11
- package/scss/components/form/_color.scss +32 -3
- package/scss/components/form/_combo.scss +4 -0
- package/scss/components/form/_fieldset.scss +1 -0
- package/scss/components/form/_transfer.scss +1 -0
- package/scss/components/form/_tree.scss +42 -0
- package/scss/themes/_common.scss +2 -0
- package/scss/themes/_cxd-variables.scss +9 -4
- package/scss/themes/cxd.scss +1 -7
- package/sdk/ang-ie11.css +375 -53
- package/sdk/ang.css +377 -53
- package/sdk/antd-ie11.css +375 -53
- package/sdk/antd.css +377 -53
- package/sdk/charts.js +13 -13
- package/sdk/color-picker.js +69 -65
- package/sdk/cropperjs.js +2 -2
- package/sdk/cxd-ie11.css +379 -60
- package/sdk/cxd.css +384 -62
- package/sdk/dark-ie11.css +375 -53
- package/sdk/dark.css +377 -53
- package/sdk/exceljs.js +1 -1
- package/sdk/markdown.js +69 -69
- package/sdk/papaparse.js +1 -1
- package/sdk/renderers/Form/CityDB.js +1 -1
- package/sdk/rest.js +16 -20
- package/sdk/rich-text.js +62 -62
- package/sdk/sdk-ie11.css +379 -60
- package/sdk/sdk.css +384 -62
- package/sdk/sdk.js +1215 -1173
- package/sdk/thirds/hls.js/hls.js +1 -1
- package/sdk/thirds/mpegts.js/mpegts.js +1 -1
- package/sdk/tinymce.js +57 -57
- package/src/Schema.ts +5 -1
- package/src/components/Alert2.tsx +32 -4
- package/src/components/AssociatedSelection.tsx +3 -1
- package/src/components/Button.tsx +1 -0
- package/src/components/Collapse.tsx +139 -20
- package/src/components/CollapseGroup.tsx +130 -0
- package/src/components/ColorPicker.tsx +32 -10
- package/src/components/GridNav.tsx +233 -0
- package/src/components/Overlay.tsx +6 -0
- package/src/components/PopOver.tsx +15 -1
- package/src/components/Toast.tsx +48 -21
- package/src/components/Tree.tsx +194 -8
- package/src/components/condition-builder/Field.tsx +3 -1
- package/src/components/icons.tsx +8 -0
- package/src/envOverwrite.ts +20 -7
- package/src/factory.tsx +52 -6
- package/src/icons/alert-danger.svg +1 -0
- package/src/icons/alert-info.svg +1 -0
- package/src/icons/alert-success.svg +1 -0
- package/src/icons/alert-warning.svg +1 -0
- package/src/icons/drag-bar.svg +12 -6
- package/src/index.tsx +2 -0
- package/src/renderers/Alert.tsx +31 -1
- package/src/renderers/Card.tsx +13 -2
- package/src/renderers/Collapse.tsx +70 -117
- package/src/renderers/CollapseGroup.tsx +80 -0
- package/src/renderers/Form/ConditionBuilder.tsx +2 -2
- package/src/renderers/Form/InputColor.tsx +4 -2
- package/src/renderers/GridNav.tsx +204 -0
- package/src/renderers/Page.tsx +62 -1
- package/src/store/formItem.ts +94 -2
- package/src/types.ts +1 -1
- package/src/utils/api.ts +93 -6
- package/src/utils/helper.ts +33 -0
- package/src/utils/tpl-builtin.ts +6 -0
- package/tsconfig-for-declaration.json +1 -1
package/src/components/Tree.tsx
CHANGED
@@ -24,6 +24,20 @@ import Checkbox from './Checkbox';
|
|
24
24
|
import {LocaleProps, localeable} from '../locale';
|
25
25
|
import Spinner from './Spinner';
|
26
26
|
|
27
|
+
interface IDropIndicator {
|
28
|
+
left: number;
|
29
|
+
top: number;
|
30
|
+
width: number;
|
31
|
+
height?: number;
|
32
|
+
}
|
33
|
+
|
34
|
+
export interface IDropInfo {
|
35
|
+
dragNode: Option | null;
|
36
|
+
node: Option;
|
37
|
+
position: 'top' | 'bottom' | 'self';
|
38
|
+
indicator: IDropIndicator;
|
39
|
+
}
|
40
|
+
|
27
41
|
interface TreeSelectorProps extends ThemeProps, LocaleProps {
|
28
42
|
highlightTxt?: string;
|
29
43
|
|
@@ -97,6 +111,8 @@ interface TreeSelectorProps extends ThemeProps, LocaleProps {
|
|
97
111
|
onDelete?: (value: Option) => void;
|
98
112
|
onDeferLoad?: (option: Option) => void;
|
99
113
|
onExpandTree?: (nodePathArr: any[]) => void;
|
114
|
+
draggable?: boolean;
|
115
|
+
onMove?: (dropInfo: IDropInfo) => void;
|
100
116
|
}
|
101
117
|
|
102
118
|
interface TreeSelectorState {
|
@@ -106,6 +122,9 @@ interface TreeSelectorState {
|
|
106
122
|
isAdding: boolean;
|
107
123
|
isEditing: boolean;
|
108
124
|
editingItem: Option | null;
|
125
|
+
|
126
|
+
// 拖拽指示器
|
127
|
+
dropIndicator?: IDropIndicator;
|
109
128
|
}
|
110
129
|
|
111
130
|
export class TreeSelector extends React.Component<
|
@@ -146,6 +165,16 @@ export class TreeSelector extends React.Component<
|
|
146
165
|
};
|
147
166
|
|
148
167
|
unfolded: WeakMap<Object, boolean> = new WeakMap();
|
168
|
+
dragNode: Option | null;
|
169
|
+
dropInfo: IDropInfo | null;
|
170
|
+
startPoint: {
|
171
|
+
x: number;
|
172
|
+
y: number;
|
173
|
+
} = {
|
174
|
+
x: 0,
|
175
|
+
y: 0
|
176
|
+
};
|
177
|
+
root = React.createRef<HTMLDivElement>();
|
149
178
|
|
150
179
|
constructor(props: TreeSelectorProps) {
|
151
180
|
super(props);
|
@@ -168,7 +197,8 @@ export class TreeSelector extends React.Component<
|
|
168
197
|
addingParent: null,
|
169
198
|
isAdding: false,
|
170
199
|
isEditing: false,
|
171
|
-
editingItem: null
|
200
|
+
editingItem: null,
|
201
|
+
dropIndicator: undefined
|
172
202
|
};
|
173
203
|
|
174
204
|
this.syncUnFolded(props);
|
@@ -603,6 +633,129 @@ export class TreeSelector extends React.Component<
|
|
603
633
|
);
|
604
634
|
}
|
605
635
|
|
636
|
+
getOffsetPosition(element: HTMLElement) {
|
637
|
+
let left = 0;
|
638
|
+
let top = 0;
|
639
|
+
|
640
|
+
while (element.offsetParent) {
|
641
|
+
left += element.offsetLeft;
|
642
|
+
top += element.offsetTop;
|
643
|
+
element = element.offsetParent as HTMLElement;
|
644
|
+
}
|
645
|
+
return {left, top};
|
646
|
+
}
|
647
|
+
|
648
|
+
@autobind
|
649
|
+
getDropInfo(e: React.DragEvent<Element>, node: Option): IDropInfo {
|
650
|
+
let rect = e.currentTarget.getBoundingClientRect();
|
651
|
+
|
652
|
+
const dragNode = this.dragNode;
|
653
|
+
const deltaX = Math.min(50, rect.width * 0.3);
|
654
|
+
const gap = node?.children?.length ? 0 : 16;
|
655
|
+
|
656
|
+
// 计算相对位置
|
657
|
+
let offset = this.getOffsetPosition(this.root.current!);
|
658
|
+
let targetOffset = this.getOffsetPosition(e.currentTarget as HTMLElement);
|
659
|
+
let left = targetOffset.left - offset.left;
|
660
|
+
let top = targetOffset.top - offset.top;
|
661
|
+
|
662
|
+
let {clientX, clientY} = e;
|
663
|
+
|
664
|
+
let position: IDropInfo['position'] =
|
665
|
+
clientY >= rect.top + rect.height / 2 ? 'bottom' : 'top';
|
666
|
+
let indicator;
|
667
|
+
if (position === 'bottom' && clientX >= this.startPoint.x + deltaX) {
|
668
|
+
position = 'self';
|
669
|
+
indicator = {
|
670
|
+
top: top,
|
671
|
+
left: left,
|
672
|
+
width: rect.width,
|
673
|
+
height: rect.height
|
674
|
+
};
|
675
|
+
} else {
|
676
|
+
indicator = {
|
677
|
+
top: position === 'bottom' ? top + rect.height : top,
|
678
|
+
left: left + gap,
|
679
|
+
width: rect.width - gap
|
680
|
+
};
|
681
|
+
}
|
682
|
+
|
683
|
+
return {
|
684
|
+
node,
|
685
|
+
dragNode,
|
686
|
+
position,
|
687
|
+
indicator
|
688
|
+
};
|
689
|
+
}
|
690
|
+
|
691
|
+
@autobind
|
692
|
+
updateDropIndicator(e: React.DragEvent<Element>, node: Option) {
|
693
|
+
const gap = node?.children?.length ? 0 : 16;
|
694
|
+
this.dropInfo = this.getDropInfo(e, node);
|
695
|
+
let {dragNode, indicator} = this.dropInfo;
|
696
|
+
if (node === dragNode) {
|
697
|
+
this.setState({dropIndicator: undefined});
|
698
|
+
return;
|
699
|
+
}
|
700
|
+
this.setState({
|
701
|
+
dropIndicator: indicator
|
702
|
+
});
|
703
|
+
}
|
704
|
+
|
705
|
+
@autobind
|
706
|
+
onDragStart(node: Option) {
|
707
|
+
let draggable = this.props.draggable;
|
708
|
+
return (e: React.DragEvent<Element>) => {
|
709
|
+
if (draggable) {
|
710
|
+
e.dataTransfer.effectAllowed = 'copyMove';
|
711
|
+
|
712
|
+
this.dragNode = node;
|
713
|
+
this.dropInfo = null;
|
714
|
+
this.startPoint = {
|
715
|
+
x: e.clientX,
|
716
|
+
y: e.clientY
|
717
|
+
};
|
718
|
+
|
719
|
+
if (node?.children?.length) {
|
720
|
+
this.unfolded.set(node, false);
|
721
|
+
this.forceUpdate();
|
722
|
+
}
|
723
|
+
} else {
|
724
|
+
this.dragNode = null;
|
725
|
+
this.dropInfo = null;
|
726
|
+
}
|
727
|
+
e.stopPropagation();
|
728
|
+
};
|
729
|
+
}
|
730
|
+
|
731
|
+
@autobind
|
732
|
+
onDragOver(node: Option) {
|
733
|
+
return (e: React.DragEvent<Element>) => {
|
734
|
+
if (!this.dragNode) {
|
735
|
+
return;
|
736
|
+
}
|
737
|
+
this.updateDropIndicator(e, node);
|
738
|
+
e.preventDefault();
|
739
|
+
};
|
740
|
+
}
|
741
|
+
|
742
|
+
@autobind
|
743
|
+
onDragEnd(dragNode: Option) {
|
744
|
+
return (e: React.DragEvent<Element>) => {
|
745
|
+
this.setState({
|
746
|
+
dropIndicator: undefined
|
747
|
+
});
|
748
|
+
let node = this.dropInfo?.node;
|
749
|
+
if (!this.dropInfo || !node || dragNode === node) {
|
750
|
+
return;
|
751
|
+
}
|
752
|
+
this.props.onMove?.(this.dropInfo);
|
753
|
+
this.dragNode = null;
|
754
|
+
this.dropInfo = null;
|
755
|
+
e.preventDefault();
|
756
|
+
};
|
757
|
+
}
|
758
|
+
|
606
759
|
@autobind
|
607
760
|
renderList(
|
608
761
|
list: Options,
|
@@ -633,7 +786,8 @@ export class TreeSelector extends React.Component<
|
|
633
786
|
createTip,
|
634
787
|
editTip,
|
635
788
|
removeTip,
|
636
|
-
translate: __
|
789
|
+
translate: __,
|
790
|
+
draggable
|
637
791
|
} = this.props;
|
638
792
|
const {
|
639
793
|
value: stateValue,
|
@@ -729,7 +883,17 @@ export class TreeSelector extends React.Component<
|
|
729
883
|
'is-checked': checked,
|
730
884
|
'is-disabled': nodeDisabled
|
731
885
|
})}
|
886
|
+
draggable={draggable}
|
887
|
+
onDragStart={this.onDragStart(item)}
|
888
|
+
onDragOver={this.onDragOver(item)}
|
889
|
+
onDragEnd={this.onDragEnd(item)}
|
732
890
|
>
|
891
|
+
{draggable && (
|
892
|
+
<a className={cx('Tree-itemDrager drag-bar')}>
|
893
|
+
<Icon icon="drag-bar" className="icon" />
|
894
|
+
</a>
|
895
|
+
)}
|
896
|
+
|
733
897
|
{item.loading ? (
|
734
898
|
<Spinner
|
735
899
|
size="sm"
|
@@ -756,7 +920,7 @@ export class TreeSelector extends React.Component<
|
|
756
920
|
<i
|
757
921
|
className={cx(
|
758
922
|
`Tree-itemIcon ${
|
759
|
-
|
923
|
+
childrenItems ? 'Tree-folderIcon' : 'Tree-leafIcon'
|
760
924
|
}`
|
761
925
|
)}
|
762
926
|
onClick={() =>
|
@@ -766,9 +930,11 @@ export class TreeSelector extends React.Component<
|
|
766
930
|
: this.handleSelect(item))
|
767
931
|
}
|
768
932
|
>
|
769
|
-
{getIcon(iconValue)
|
770
|
-
|
771
|
-
|
933
|
+
{getIcon(iconValue) ? (
|
934
|
+
<Icon icon={iconValue} className="icon" />
|
935
|
+
) : (
|
936
|
+
<i className={iconValue}></i>
|
937
|
+
)}
|
772
938
|
</i>
|
773
939
|
) : null}
|
774
940
|
|
@@ -872,10 +1038,19 @@ export class TreeSelector extends React.Component<
|
|
872
1038
|
rootCreatable,
|
873
1039
|
rootCreateTip,
|
874
1040
|
disabled,
|
1041
|
+
draggable,
|
875
1042
|
translate: __
|
876
1043
|
} = this.props;
|
877
1044
|
let options = this.props.options;
|
878
|
-
const {
|
1045
|
+
const {
|
1046
|
+
value,
|
1047
|
+
isAdding,
|
1048
|
+
addingParent,
|
1049
|
+
isEditing,
|
1050
|
+
inputValue,
|
1051
|
+
dropIndicator
|
1052
|
+
} = this.state;
|
1053
|
+
|
879
1054
|
let addBtn = null;
|
880
1055
|
|
881
1056
|
if (creatable && rootCreatable !== false && hideRoot) {
|
@@ -896,8 +1071,10 @@ export class TreeSelector extends React.Component<
|
|
896
1071
|
<div
|
897
1072
|
className={cx(`Tree ${className || ''}`, {
|
898
1073
|
'Tree--outline': showOutline,
|
899
|
-
'is-disabled': disabled
|
1074
|
+
'is-disabled': disabled,
|
1075
|
+
'is-draggable': draggable
|
900
1076
|
})}
|
1077
|
+
ref={this.root}
|
901
1078
|
>
|
902
1079
|
{(options && options.length) || addBtn || hideRoot === false ? (
|
903
1080
|
<ul className={cx('Tree-list')}>
|
@@ -957,6 +1134,15 @@ export class TreeSelector extends React.Component<
|
|
957
1134
|
) : (
|
958
1135
|
<div className={cx('Tree-placeholder')}>{placeholder}</div>
|
959
1136
|
)}
|
1137
|
+
|
1138
|
+
{dropIndicator && (
|
1139
|
+
<div
|
1140
|
+
className={cx('Tree-dropIndicator', {
|
1141
|
+
'Tree-dropIndicator--hover': !!dropIndicator.height
|
1142
|
+
})}
|
1143
|
+
style={dropIndicator}
|
1144
|
+
/>
|
1145
|
+
)}
|
960
1146
|
</div>
|
961
1147
|
);
|
962
1148
|
}
|
@@ -96,7 +96,9 @@ export class ConditionField extends React.Component<
|
|
96
96
|
options={this.state.options}
|
97
97
|
value={[value]}
|
98
98
|
option2value={option2value}
|
99
|
-
onChange={(
|
99
|
+
onChange={(value: any) =>
|
100
|
+
onChange(Array.isArray(value) ? value[0] : value)
|
101
|
+
}
|
100
102
|
/>
|
101
103
|
</>
|
102
104
|
)}
|
package/src/components/icons.tsx
CHANGED
@@ -70,6 +70,10 @@ import ExpandAltIcon from '../icons/expand-alt.svg';
|
|
70
70
|
import CompressAltIcon from '../icons/compress-alt.svg';
|
71
71
|
import TransparentIcon from '../icons/transparent.svg';
|
72
72
|
import LoadingOutline from '../icons/loading-outline.svg';
|
73
|
+
import AlertSuccess from '../icons/alert-success.svg';
|
74
|
+
import AlertInfo from '../icons/alert-info.svg';
|
75
|
+
import AlertWarning from '../icons/alert-warning.svg';
|
76
|
+
import AlertDanger from '../icons/alert-danger.svg';
|
73
77
|
|
74
78
|
// 兼容原来的用法,后续不直接试用。
|
75
79
|
|
@@ -166,6 +170,10 @@ registerIcon('expand-alt', ExpandAltIcon);
|
|
166
170
|
registerIcon('compress-alt', CompressAltIcon);
|
167
171
|
registerIcon('transparent', TransparentIcon);
|
168
172
|
registerIcon('loading-outline', LoadingOutline);
|
173
|
+
registerIcon('alert-success', AlertSuccess);
|
174
|
+
registerIcon('alert-info', AlertInfo);
|
175
|
+
registerIcon('alert-warning', AlertWarning);
|
176
|
+
registerIcon('alert-danger', AlertDanger);
|
169
177
|
|
170
178
|
export function Icon({
|
171
179
|
icon,
|
package/src/envOverwrite.ts
CHANGED
@@ -4,18 +4,31 @@
|
|
4
4
|
|
5
5
|
import {SchemaNode, Schema} from './types';
|
6
6
|
import {RendererProps, RendererConfig, addSchemaFilter} from './factory';
|
7
|
+
import {findObjectsWithKey} from './utils/helper';
|
7
8
|
const isMobile = (window as any).matchMedia?.('(max-width: 768px)').matches
|
8
9
|
? true
|
9
10
|
: false;
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
// 这里不能用 addSchemaFilter 是因为还需要更深层的替换,比如 select 里的 options
|
13
|
+
export const envOverwrite = (schema: any, locale?: string) => {
|
14
|
+
if (schema.mobile && isMobile) {
|
15
|
+
Object.assign(schema, schema.mobile);
|
16
|
+
delete schema.mobile;
|
14
17
|
}
|
15
18
|
|
16
|
-
if (
|
17
|
-
|
19
|
+
if (locale) {
|
20
|
+
let schemaNodes = findObjectsWithKey(schema, locale);
|
21
|
+
for (let schemaNode of schemaNodes) {
|
22
|
+
Object.assign(schemaNode, schemaNode[locale]);
|
23
|
+
delete schemaNode[locale];
|
24
|
+
}
|
18
25
|
}
|
19
26
|
|
20
|
-
|
21
|
-
|
27
|
+
if (isMobile) {
|
28
|
+
let schemaNodes = findObjectsWithKey(schema, 'mobile');
|
29
|
+
for (let schemaNode of schemaNodes) {
|
30
|
+
Object.assign(schemaNode, schemaNode['mobile']);
|
31
|
+
delete schemaNode['mobile'];
|
32
|
+
}
|
33
|
+
}
|
34
|
+
};
|
package/src/factory.tsx
CHANGED
@@ -3,7 +3,14 @@ import {RendererStore, IRendererStore, IIRendererStore} from './store/index';
|
|
3
3
|
import {getEnv, destroy} from 'mobx-state-tree';
|
4
4
|
import {wrapFetcher} from './utils/api';
|
5
5
|
import {normalizeLink} from './utils/normalizeLink';
|
6
|
-
import {
|
6
|
+
import {
|
7
|
+
findIndex,
|
8
|
+
isObject,
|
9
|
+
JSONTraverse,
|
10
|
+
promisify,
|
11
|
+
qsparse,
|
12
|
+
string2regExp
|
13
|
+
} from './utils/helper';
|
7
14
|
import {
|
8
15
|
Api,
|
9
16
|
fetcherResult,
|
@@ -25,6 +32,7 @@ import {getDefaultLocale, makeTranslator, LocaleProps} from './locale';
|
|
25
32
|
import ScopedRootRenderer, {RootRenderProps} from './Root';
|
26
33
|
import {HocStoreFactory} from './WithStore';
|
27
34
|
import {EnvContext, RendererEnv} from './env';
|
35
|
+
import {envOverwrite} from './envOverwrite';
|
28
36
|
|
29
37
|
export interface TestFunc {
|
30
38
|
(
|
@@ -127,12 +135,20 @@ export interface RenderOptions {
|
|
127
135
|
affixOffsetTop?: number;
|
128
136
|
affixOffsetBottom?: number;
|
129
137
|
richTextToken?: string;
|
138
|
+
/**
|
139
|
+
* 替换文本,用于实现 URL 替换、语言替换等
|
140
|
+
*/
|
141
|
+
replaceText?: {[propName: string]: any};
|
142
|
+
/**
|
143
|
+
* 文本替换的黑名单,因为属性太多了所以改成黑名单的 fangs
|
144
|
+
*/
|
145
|
+
replaceTextIgnoreKeys?: String[];
|
130
146
|
[propName: string]: any;
|
131
147
|
}
|
132
148
|
|
133
149
|
export interface fetcherConfig {
|
134
150
|
url: string;
|
135
|
-
method?: 'get' | 'post' | 'put' | 'patch' | 'delete';
|
151
|
+
method?: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'jsonp';
|
136
152
|
data?: any;
|
137
153
|
config?: any;
|
138
154
|
}
|
@@ -275,19 +291,19 @@ const defaultOptions: RenderOptions = {
|
|
275
291
|
},
|
276
292
|
isCancel() {
|
277
293
|
console.error(
|
278
|
-
'Please
|
294
|
+
'Please implement isCancel. see https://baidu.gitee.io/amis/docs/start/getting-started#%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97'
|
279
295
|
);
|
280
296
|
return false;
|
281
297
|
},
|
282
298
|
updateLocation() {
|
283
299
|
console.error(
|
284
|
-
'Please
|
300
|
+
'Please implement updateLocation. see https://baidu.gitee.io/amis/docs/start/getting-started#%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97'
|
285
301
|
);
|
286
302
|
},
|
287
303
|
alert,
|
288
304
|
confirm,
|
289
305
|
notify: (type, msg, conf) =>
|
290
|
-
toast[type] ? toast[type](msg) : console.warn('[Notify]', type, msg),
|
306
|
+
toast[type] ? toast[type](msg, conf) : console.warn('[Notify]', type, msg),
|
291
307
|
|
292
308
|
jumpTo: (to: string, action?: any) => {
|
293
309
|
if (to === 'goBack') {
|
@@ -335,7 +351,15 @@ const defaultOptions: RenderOptions = {
|
|
335
351
|
},
|
336
352
|
// 用于跟踪用户在界面中的各种操作
|
337
353
|
tracker(eventTrack: EventTrack, props: PlainObject) {},
|
338
|
-
rendererResolver: resolveRenderer
|
354
|
+
rendererResolver: resolveRenderer,
|
355
|
+
replaceTextIgnoreKeys: [
|
356
|
+
'type',
|
357
|
+
'name',
|
358
|
+
'mode',
|
359
|
+
'target',
|
360
|
+
'reload',
|
361
|
+
'persistData'
|
362
|
+
]
|
339
363
|
};
|
340
364
|
let stores: {
|
341
365
|
[propName: string]: IRendererStore;
|
@@ -355,6 +379,9 @@ export function render(
|
|
355
379
|
const translate = props.translate || makeTranslator(locale);
|
356
380
|
let store = stores[options.session || 'global'];
|
357
381
|
|
382
|
+
// 根据环境覆盖 schema,这个要在最前面做,不然就无法覆盖 validations
|
383
|
+
envOverwrite(schema, locale);
|
384
|
+
|
358
385
|
if (!store) {
|
359
386
|
options = {
|
360
387
|
...defaultOptions,
|
@@ -387,6 +414,25 @@ export function render(
|
|
387
414
|
env.locale = locale;
|
388
415
|
}
|
389
416
|
|
417
|
+
// 进行文本替换
|
418
|
+
if (env.replaceText && isObject(env.replaceText)) {
|
419
|
+
const replaceKeys = Object.keys(env.replaceText);
|
420
|
+
replaceKeys.sort().reverse(); // 避免用户将短的放前面
|
421
|
+
const replaceTextIgnoreKeys = new Set(env.replaceTextIgnoreKeys || []);
|
422
|
+
JSONTraverse(schema, (value: any, key: string, object: any) => {
|
423
|
+
if (typeof value === 'string' && !replaceTextIgnoreKeys.has(key)) {
|
424
|
+
for (const replaceKey of replaceKeys) {
|
425
|
+
if (~value.indexOf(replaceKey)) {
|
426
|
+
object[key] = value.replaceAll(
|
427
|
+
replaceKey,
|
428
|
+
env.replaceText[replaceKey]
|
429
|
+
);
|
430
|
+
}
|
431
|
+
}
|
432
|
+
}
|
433
|
+
});
|
434
|
+
}
|
435
|
+
|
390
436
|
return (
|
391
437
|
<EnvContext.Provider value={env}>
|
392
438
|
<ScopedRootRenderer
|
@@ -0,0 +1 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" width="16px" fill="currentColor"><path d="M667.904 704.32L508.992 546.56l-157.888 158.912-45.376-45.056 157.824-158.976L304.64 343.488l45.12-45.376 158.912 157.824 157.888-158.848 45.44 45.056L553.984 501.12l158.976 157.888-45.12 45.44zM510.528 64a448 448 0 1 0 2.944 896 448 448 0 0 0-2.944-896z" fill="#E8684A"></path></svg>
|
@@ -0,0 +1 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" width="16px" fill="currentColor"><path d="M512 64A448 448 0 1 1 512 960 448 448 0 0 1 512 64z m32 354.944h-64V768h64V418.944zM512 256a38.4 38.4 0 1 0-0.128 76.672A38.4 38.4 0 0 0 512 256z" fill="#2468F2"></path></svg>
|
@@ -0,0 +1 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" width="16px" fill="currentColor"><path d="M449.856 706.56l-45.44-45.056 0.128-0.064L268.16 526.016l45.12-45.44 136.32 135.488 270.592-272.384 45.376 45.056-315.712 317.888zM510.528 64A448 448 0 1 0 960 510.528 448 448 0 0 0 510.528 64z" fill="#0BC286"></path></svg>
|
@@ -0,0 +1 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" width="16px" fill="currentColor"><path d="M512 64A448 448 0 1 1 512 960 448 448 0 0 1 512 64z m0 627.2A38.4 38.4 0 1 0 512 768a38.4 38.4 0 0 0 0-76.8zM544 256h-64v349.12h64V256z" fill="#FFB200"></path></svg>
|
package/src/icons/drag-bar.svg
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
<
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
3
|
+
<g transform="translate(5.000000, 1.000000)" stroke-width="1" stroke="currentColor">
|
4
|
+
<circle cx="1" cy="1" r="1"></circle>
|
5
|
+
<circle cx="5" cy="1" r="1"></circle>
|
6
|
+
<circle cx="1" cy="5" r="1"></circle>
|
7
|
+
<circle cx="5" cy="5" r="1"></circle>
|
8
|
+
<circle cx="1" cy="9" r="1"></circle>
|
9
|
+
<circle cx="5" cy="9" r="1"></circle>
|
10
|
+
<circle cx="1" cy="13" r="1"></circle>
|
11
|
+
<circle cx="5" cy="13" r="1"></circle>
|
6
12
|
</g>
|
7
|
-
</svg>
|
13
|
+
</svg>
|
package/src/index.tsx
CHANGED
@@ -56,6 +56,7 @@ import './renderers/Form/ButtonToolbar';
|
|
56
56
|
import './renderers/Breadcrumb';
|
57
57
|
import './renderers/DropDownButton';
|
58
58
|
import './renderers/Collapse';
|
59
|
+
import './renderers/CollapseGroup';
|
59
60
|
import './renderers/Color';
|
60
61
|
import './renderers/CRUD';
|
61
62
|
import './renderers/Pagination';
|
@@ -167,6 +168,7 @@ import './renderers/Markdown';
|
|
167
168
|
import './renderers/TableView';
|
168
169
|
import './renderers/Code';
|
169
170
|
import './renderers/WebComponent';
|
171
|
+
import './renderers/GridNav';
|
170
172
|
|
171
173
|
import Scoped, {ScopedContext} from './Scoped';
|
172
174
|
|
package/src/renderers/Alert.tsx
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
import {Renderer, RendererProps} from '../factory';
|
2
2
|
import React from 'react';
|
3
3
|
import Alert, {AlertProps} from '../components/Alert2';
|
4
|
-
import {
|
4
|
+
import {
|
5
|
+
BaseSchema,
|
6
|
+
SchemaObject,
|
7
|
+
SchemaCollection,
|
8
|
+
SchemaIcon
|
9
|
+
} from '../Schema';
|
5
10
|
|
6
11
|
/**
|
7
12
|
* Alert 提示渲染器。
|
@@ -13,6 +18,11 @@ export interface AlertSchema extends BaseSchema {
|
|
13
18
|
*/
|
14
19
|
type: 'alert';
|
15
20
|
|
21
|
+
/**
|
22
|
+
* 提示框标题
|
23
|
+
*/
|
24
|
+
title?: string;
|
25
|
+
|
16
26
|
/**
|
17
27
|
* 内容区域
|
18
28
|
*/
|
@@ -27,6 +37,26 @@ export interface AlertSchema extends BaseSchema {
|
|
27
37
|
* 是否显示关闭按钮
|
28
38
|
*/
|
29
39
|
showCloseButton?: boolean;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* 关闭按钮CSS类名
|
43
|
+
*/
|
44
|
+
closeButtonClassName?: string;
|
45
|
+
|
46
|
+
/**
|
47
|
+
* 是否显示ICON
|
48
|
+
*/
|
49
|
+
showIcon?: boolean;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* 左侧图标
|
53
|
+
*/
|
54
|
+
icon?: SchemaIcon;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* 图标CSS类名
|
58
|
+
*/
|
59
|
+
iconClassName?: string;
|
30
60
|
}
|
31
61
|
|
32
62
|
@Renderer({
|
package/src/renderers/Card.tsx
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import {findDOMNode} from 'react-dom';
|
3
3
|
import {Renderer, RendererProps} from '../factory';
|
4
|
-
import {SchemaNode, Schema, Action} from '../types';
|
4
|
+
import {SchemaNode, Schema, Action, PlainObject} from '../types';
|
5
5
|
import {filter, evalExpression} from '../utils/tpl';
|
6
6
|
import cx from 'classnames';
|
7
7
|
import Checkbox from '../components/Checkbox';
|
@@ -11,7 +11,8 @@ import {
|
|
11
11
|
isVisible,
|
12
12
|
isDisabled,
|
13
13
|
noop,
|
14
|
-
isClickOnInput
|
14
|
+
isClickOnInput,
|
15
|
+
hashCode
|
15
16
|
} from '../utils/helper';
|
16
17
|
import {resolveVariable} from '../utils/tpl-builtin';
|
17
18
|
import QuickEdit, {SchemaQuickEdit} from './QuickEdit';
|
@@ -128,6 +129,7 @@ export interface CardSchema extends BaseSchema {
|
|
128
129
|
avatar?: SchemaUrlPath;
|
129
130
|
|
130
131
|
avatarText?: SchemaTpl;
|
132
|
+
avatarTextBackground?: String[];
|
131
133
|
avatarTextClassName?: SchemaClassName;
|
132
134
|
|
133
135
|
/**
|
@@ -485,6 +487,7 @@ export class Card extends React.Component<CardProps> {
|
|
485
487
|
highlight: highlightTpl,
|
486
488
|
avatar: avatarTpl,
|
487
489
|
avatarText: avatarTextTpl,
|
490
|
+
avatarTextBackground,
|
488
491
|
title: titleTpl,
|
489
492
|
subTitle: subTitleTpl,
|
490
493
|
subTitlePlaceholder,
|
@@ -500,6 +503,13 @@ export class Card extends React.Component<CardProps> {
|
|
500
503
|
const title = filter(titleTpl, data);
|
501
504
|
const subTitle = filter(subTitleTpl, data);
|
502
505
|
const desc = filter(header?.description || descTpl, data);
|
506
|
+
const avatarTextStyle: PlainObject = {};
|
507
|
+
if (avatarText && avatarTextBackground && avatarTextBackground.length) {
|
508
|
+
avatarTextStyle['background'] =
|
509
|
+
avatarTextBackground[
|
510
|
+
Math.abs(hashCode(avatarText)) % avatarTextBackground.length
|
511
|
+
];
|
512
|
+
}
|
503
513
|
|
504
514
|
heading = (
|
505
515
|
<div className={cx('Card-heading', header?.className)}>
|
@@ -524,6 +534,7 @@ export class Card extends React.Component<CardProps> {
|
|
524
534
|
'Card-avtarText',
|
525
535
|
header?.avatarTextClassName || avatarTextClassName
|
526
536
|
)}
|
537
|
+
style={avatarTextStyle}
|
527
538
|
>
|
528
539
|
{avatarText}
|
529
540
|
</span>
|