jrs-react 1.1.11 → 1.1.12

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/build/index.js CHANGED
@@ -6058,6 +6058,25 @@ const flexType = (type, me, payload, doElse) => {
6058
6058
  const result = typeof type === 'function' ? type?.bind(me)(payload) : type ?? doElse;
6059
6059
  return result;
6060
6060
  };
6061
+ const whatType = ({
6062
+ type,
6063
+ typeStyle: _typeStyle,
6064
+ render,
6065
+ ...config
6066
+ }, me, doElse) => {
6067
+ if (type) {
6068
+ // const style=flexType(typeStyle,me,{},{})
6069
+ // return 'type'
6070
+ const typeStyle = typeof _typeStyle === 'function' ? _typeStyle?.bind(me)() : _typeStyle;
6071
+ return /*#__PURE__*/React.createElement(type, {
6072
+ style: typeStyle
6073
+ });
6074
+ } else if (render) {
6075
+ return render.bind(me)();
6076
+ } else {
6077
+ return doElse;
6078
+ }
6079
+ };
6061
6080
 
6062
6081
  /******************************************************************************
6063
6082
  Copyright (c) Microsoft Corporation.
@@ -7477,6 +7496,840 @@ class JRFrame extends JRSubmit {
7477
7496
  }
7478
7497
  }
7479
7498
 
7499
+ const StyledSlider = dt.div`
7500
+ position: absolute;
7501
+ top: 0;
7502
+ right: 0;
7503
+ height:100%;
7504
+ width:6px;
7505
+ user-select: none;
7506
+ &.resizing:hover,&.resizing{
7507
+ border-right:1px dashed black;
7508
+ }
7509
+ &:hover{
7510
+ cursor: col-resize;
7511
+ border-right:1px dashed gray;
7512
+ }
7513
+ `;
7514
+ class Slider extends React.Component {
7515
+ constructor() {
7516
+ super();
7517
+ this.sliderRef = /*#__PURE__*/React.createRef();
7518
+ }
7519
+ stop = e => {
7520
+ this.sliderRef.current.classList.remove('resizing');
7521
+ document.body.style.cursor = 'default';
7522
+ window.removeEventListener('mousemove', this.move);
7523
+ window.removeEventListener('mouseup', this.stop);
7524
+ };
7525
+ move = ({
7526
+ clientX
7527
+ }) => {
7528
+ const {
7529
+ th,
7530
+ selectedCols,
7531
+ widthRates
7532
+ } = this.data;
7533
+ const {
7534
+ left
7535
+ } = th.getBoundingClientRect();
7536
+ const min = left + 10;
7537
+ const x = clientX >= min ? clientX : min;
7538
+ const width = x - left;
7539
+ selectedCols.forEach((col, index) => {
7540
+ const _width = Math.round(width / 100 * widthRates[index]);
7541
+ col.style.width = _width + 'px';
7542
+ });
7543
+ };
7544
+ start(thPRef, column) {
7545
+ const selectedCols = [...this.props.table.colGroupRef.current.children].slice(column.columnNo, column.columnNo + (column.colSpan ?? 1));
7546
+ const totalWidth = selectedCols.reduce((aco, {
7547
+ offsetWidth
7548
+ }) => aco + offsetWidth, 0);
7549
+ const widthRates = selectedCols.map(({
7550
+ offsetWidth
7551
+ }) => {
7552
+ return 100 * (offsetWidth / totalWidth);
7553
+ });
7554
+ this.data = {
7555
+ selectedCols,
7556
+ th: thPRef.current,
7557
+ widthRates
7558
+ };
7559
+ this.sliderRef.current.classList.add('resizing');
7560
+ document.body.style.cursor = 'col-resize';
7561
+ window.addEventListener('mousemove', this.move);
7562
+ window.addEventListener('mouseup', this.stop);
7563
+ }
7564
+ render() {
7565
+ const column = this.props.column;
7566
+ return /*#__PURE__*/React.createElement(StyledSlider, {
7567
+ ref: this.sliderRef,
7568
+ onMouseDown: e => {
7569
+ this.start(this.props.thRef, column);
7570
+ }
7571
+ });
7572
+ }
7573
+ }
7574
+
7575
+ const Colgroup = ({
7576
+ leafColumns,
7577
+ colGroupRef
7578
+ }) => {
7579
+ return /*#__PURE__*/React.createElement("colgroup", {
7580
+ ref: colGroupRef
7581
+ }, leafColumns?.map((_column, index) => {
7582
+ const {
7583
+ width,
7584
+ ...column
7585
+ } = _column;
7586
+ const style = {
7587
+ width
7588
+ };
7589
+ return /*#__PURE__*/React.createElement("col", {
7590
+ style: style,
7591
+ key: index
7592
+ });
7593
+ }));
7594
+ };
7595
+ const Ths$1 = ({
7596
+ deep,
7597
+ rowColumn,
7598
+ rowIndex,
7599
+ table
7600
+ }) => {
7601
+ return rowColumn?.map((column, colIndex) => {
7602
+ const thRef = /*#__PURE__*/React.createRef();
7603
+ return /*#__PURE__*/React.createElement("th", {
7604
+ key: colIndex,
7605
+ ref: thRef,
7606
+ colSpan: column.colSpan,
7607
+ rowSpan: column.rowSpan ?? (column.isLeaf && deep > rowIndex ? deep - rowIndex + 1 : null)
7608
+ }, flexType(column.label, table), table.props.resizableColumns === true && /*#__PURE__*/React.createElement(Slider, {
7609
+ table: table,
7610
+ thRef: thRef,
7611
+ column: column
7612
+ }));
7613
+ });
7614
+ };
7615
+ const HeadTrs = ({
7616
+ columns: _columns,
7617
+ trClassName,
7618
+ table
7619
+ }) => {
7620
+ const columns = Array.isArray(_columns?.[0]) ? _columns : [_columns];
7621
+ return columns?.map((rowColumn, rowIndex) => {
7622
+ return /*#__PURE__*/React.createElement("tr", {
7623
+ className: trClassName,
7624
+ key: rowIndex
7625
+ }, /*#__PURE__*/React.createElement(Ths$1, {
7626
+ deep: columns.length - 1,
7627
+ rowColumn: rowColumn,
7628
+ rowIndex: rowIndex,
7629
+ table: table
7630
+ }));
7631
+ });
7632
+ };
7633
+ const THead = ({
7634
+ columns,
7635
+ leafColumns,
7636
+ table
7637
+ }) => {
7638
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement(HeadTrs, {
7639
+ columns: columns,
7640
+ table: table
7641
+ })), /*#__PURE__*/React.createElement(Colgroup, {
7642
+ leafColumns: leafColumns,
7643
+ colGroupRef: table.colGroupRef
7644
+ }));
7645
+ };
7646
+ const FootThs = ({
7647
+ table,
7648
+ groupData,
7649
+ groupIndex,
7650
+ deep,
7651
+ columns,
7652
+ rowIndex
7653
+ }) => {
7654
+ return columns?.map((column, colIndex) => {
7655
+ // let content
7656
+ // if(type){
7657
+ // content='type'
7658
+ // }else if(render){
7659
+
7660
+ // content=render?.bind(table)({groupData,groupIndex,ths:111})
7661
+ // }else{
7662
+ // content=column.label
7663
+ // }
7664
+ let style = flexType(column.style, table, {}, {});
7665
+ const content = whatType(column, table, column.label);
7666
+ return /*#__PURE__*/React.createElement("th", {
7667
+ style: style,
7668
+ colSpan: column.colSpan,
7669
+ rowSpan: column.rowSpan
7670
+ }, content);
7671
+ });
7672
+ };
7673
+ const TFoot = ({
7674
+ table,
7675
+ columns
7676
+ }) => {
7677
+ const trs = columns?.map((rowColumn, rowIndex) => {
7678
+ return /*#__PURE__*/React.createElement("tr", {
7679
+ key: rowIndex
7680
+ }, /*#__PURE__*/React.createElement(FootThs, {
7681
+ columns: rowColumn,
7682
+ table: table
7683
+ }));
7684
+ });
7685
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("tfoot", null, trs));
7686
+ };
7687
+
7688
+ function _extends() {
7689
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
7690
+ for (var e = 1; e < arguments.length; e++) {
7691
+ var t = arguments[e];
7692
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
7693
+ }
7694
+ return n;
7695
+ }, _extends.apply(null, arguments);
7696
+ }
7697
+
7698
+ dt.tbody`
7699
+ th{
7700
+ height:4px;
7701
+ background:#c6c6c6;
7702
+ }
7703
+ `;
7704
+
7705
+ ////////////////////////////////////////////////////////////////////////////
7706
+
7707
+ const Ths = ({
7708
+ table,
7709
+ groupData,
7710
+ groupIndex,
7711
+ deep,
7712
+ rowColumn,
7713
+ rowIndex
7714
+ }) => {
7715
+ return rowColumn?.map(({
7716
+ style: _style,
7717
+ align,
7718
+ type,
7719
+ render,
7720
+ ...column
7721
+ }, colIndex) => {
7722
+ const style = flexType(_style, table, {}, {});
7723
+ let content;
7724
+ if (type) {
7725
+ content = 'type';
7726
+ } else if (render) {
7727
+ content = render?.bind(table)({
7728
+ groupData,
7729
+ groupIndex,
7730
+ ths: 111
7731
+ });
7732
+ } else {
7733
+ content = column.label;
7734
+ }
7735
+ // style.textAlign=align
7736
+ return /*#__PURE__*/React.createElement("th", {
7737
+ key: colIndex,
7738
+ style: {
7739
+ textAlign: align,
7740
+ ...style
7741
+ },
7742
+ colSpan: column.colSpan,
7743
+ rowSpan: column.isLeaf && deep > rowIndex ? deep - rowIndex + 1 : null
7744
+ }, content);
7745
+ });
7746
+ };
7747
+ const GroupColumns = ({
7748
+ table,
7749
+ columns: _columns,
7750
+ trClassName,
7751
+ groupData,
7752
+ tbodyIndex
7753
+ }) => {
7754
+ const columns = Array.isArray(_columns?.[0]) ? _columns : [_columns];
7755
+ return columns?.map((rowColumn, rowIndex) => {
7756
+ return /*#__PURE__*/React.createElement("tr", {
7757
+ className: trClassName,
7758
+ key: rowIndex
7759
+ }, /*#__PURE__*/React.createElement(Ths, {
7760
+ table: table,
7761
+ groupData: groupData,
7762
+ groupIndex: tbodyIndex,
7763
+ deep: columns.length - 1,
7764
+ rowColumn: rowColumn,
7765
+ rowIndex: rowIndex
7766
+ }));
7767
+ });
7768
+ };
7769
+ dt.tr`
7770
+ z-index: 1;
7771
+ XXposition: sticky;
7772
+ XXtop: 50px;
7773
+ th{
7774
+ text-align: left;
7775
+ border:1px solid #222222;
7776
+ }
7777
+ `;
7778
+ const GroupHeader = props => {
7779
+ return /*#__PURE__*/React.createElement(GroupColumns, _extends({
7780
+ trClassName: 'jr-group-header'
7781
+ }, props));
7782
+ };
7783
+ dt.tr`
7784
+ th{
7785
+ border:1px solid #222222;
7786
+ text-align: left;
7787
+ }
7788
+ `;
7789
+ const GroupFooter = props => {
7790
+ return /*#__PURE__*/React.createElement(GroupColumns, _extends({
7791
+ trClassName: 'jr-group-footer'
7792
+ }, props));
7793
+ };
7794
+
7795
+ ////////////////////////////////////////////////////////////////////////////
7796
+ const Td = ({
7797
+ column: _column,
7798
+ record,
7799
+ tbodyIndex,
7800
+ trIndex,
7801
+ tdIndex,
7802
+ table
7803
+ }) => {
7804
+ let content;
7805
+ const {
7806
+ style: _style,
7807
+ align,
7808
+ vAlign = 'baseline',
7809
+ type,
7810
+ typeStyle: _typeStyle,
7811
+ render,
7812
+ setValue,
7813
+ getValue,
7814
+ onChange: _onChange,
7815
+ funcProps,
7816
+ ...column
7817
+ } = _column;
7818
+ const onChange = inputValue => {
7819
+ const targetValue = inputValue?.target?.value ?? inputValue;
7820
+ setValue(record, targetValue);
7821
+ table.setValue(table.getValue());
7822
+ };
7823
+ const value = getValue(record);
7824
+ let style = render ? {} : flexType(_style, table, {
7825
+ value,
7826
+ record
7827
+ }, {});
7828
+ const setStyle = _style => {
7829
+ style = _style;
7830
+ };
7831
+ setStyle.bind(undefined);
7832
+ render?.bind(table);
7833
+ if (type) {
7834
+ const typeStyle = flexType(_typeStyle, table, {
7835
+ record
7836
+ }, {});
7837
+ content = /*#__PURE__*/React.createElement(type, {
7838
+ onChange: _onChange ? e => {
7839
+ _onChange?.bind(undefined)(e, {
7840
+ value,
7841
+ onChange,
7842
+ me: content
7843
+ });
7844
+ } : onChange,
7845
+ value,
7846
+ style: typeStyle,
7847
+ render,
7848
+ ...column,
7849
+ ...funcProps?.bind(undefined)({
7850
+ value
7851
+ })
7852
+ });
7853
+ } else if (render) {
7854
+ content = render({
7855
+ index: trIndex,
7856
+ groupIndex: tbodyIndex,
7857
+ value,
7858
+ record,
7859
+ onChange,
7860
+ setStyle
7861
+ });
7862
+ } else {
7863
+ content = value;
7864
+ }
7865
+ return /*#__PURE__*/React.createElement("td", {
7866
+ colSpan: style.colSpan,
7867
+ rowSpan: style.rowSpan,
7868
+ style: {
7869
+ textAlign: align,
7870
+ verticalAlign: vAlign,
7871
+ ...style
7872
+ },
7873
+ key: tdIndex
7874
+ }, content);
7875
+ };
7876
+ const Tds = ({
7877
+ leafColumns,
7878
+ record,
7879
+ table,
7880
+ tbodyIndex,
7881
+ trIndex
7882
+ }) => {
7883
+ return leafColumns?.map((column, tdIndex) => {
7884
+ return /*#__PURE__*/React.createElement(Td, {
7885
+ column: column,
7886
+ key: tdIndex,
7887
+ record: record,
7888
+ table: table,
7889
+ tbodyIndex: tbodyIndex,
7890
+ trIndex: trIndex,
7891
+ tdIndex: tdIndex
7892
+ });
7893
+ });
7894
+ };
7895
+ ////////////////////////////////////////////////////////////////////////////
7896
+
7897
+ const TBody = ({
7898
+ groupData,
7899
+ groupHeader,
7900
+ leafColumns,
7901
+ groupFooter,
7902
+ table,
7903
+ tbodyIndex
7904
+ }) => {
7905
+ const neededProps = {
7906
+ table,
7907
+ tbodyIndex
7908
+ };
7909
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("tbody", {
7910
+ key: `tbody${tbodyIndex}`
7911
+ }, groupData?.length > 0 && /*#__PURE__*/React.createElement(GroupHeader, _extends({
7912
+ groupData: groupData,
7913
+ columns: groupHeader
7914
+ }, neededProps)), groupData?.map((record, trIndex) => {
7915
+ const onRowClick = table.props.onRowClick?.bind(table);
7916
+ return /*#__PURE__*/React.createElement("tr", {
7917
+ key: trIndex,
7918
+ onClick: () => {
7919
+ onRowClick?.({
7920
+ record,
7921
+ index: trIndex,
7922
+ groupIndex: tbodyIndex
7923
+ });
7924
+ }
7925
+ }, /*#__PURE__*/React.createElement(Tds, _extends({
7926
+ record: record,
7927
+ trIndex: trIndex
7928
+ }, neededProps, {
7929
+ leafColumns: leafColumns
7930
+ })));
7931
+ }), groupData?.length > 0 && /*#__PURE__*/React.createElement(GroupFooter, _extends({
7932
+ groupData: groupData,
7933
+ columns: groupFooter
7934
+ }, neededProps))));
7935
+ };
7936
+ const TBodies = ({
7937
+ groupHeader,
7938
+ leafColumns,
7939
+ groupFooter,
7940
+ dataSource: _dataSource,
7941
+ table
7942
+ }) => {
7943
+ // po('--TBodies--')
7944
+ const isGroupDataType = Array.isArray(_dataSource?.[0]);
7945
+ const dataSource = isGroupDataType ? _dataSource : [_dataSource];
7946
+
7947
+ // po('dataSource',dataSource)
7948
+ return dataSource?.map((groupData, tbodyIndex, c) => {
7949
+ return /*#__PURE__*/React.createElement(TBody, {
7950
+ key: `tbody${tbodyIndex}`,
7951
+ table: table
7952
+ // dataSource={dataSource}
7953
+ // dataGroup={groupData}
7954
+ ,
7955
+ groupData: groupData,
7956
+ tbodyIndex: tbodyIndex,
7957
+ groupHeader: groupHeader,
7958
+ leafColumns: leafColumns,
7959
+ groupFooter: groupFooter
7960
+ });
7961
+ });
7962
+ };
7963
+
7964
+ const StyledJRTable = dt.div`
7965
+ --column-bd-color:#cccccc;
7966
+ --column-b-color:#eeeeee;
7967
+ --column-b-hover-color:#ffffff;
7968
+
7969
+ position: relative;
7970
+ background: var(--column-b-color);
7971
+ border:1px solid var(--column-bd-color);
7972
+
7973
+ display:flex;
7974
+ flex-direction: column;
7975
+ flex:1;
7976
+ overflow: overlay;
7977
+
7978
+
7979
+
7980
+
7981
+ &.row-highlightable{
7982
+ tbody{
7983
+ tr:not(.jr-group-header,.jr-group-footer):hover{
7984
+ background:var(--column-b-hover-color);
7985
+ cursor: pointer;
7986
+ transition: background-color .8s;
7987
+ td{
7988
+ color:black;
7989
+ transition:color .8s;
7990
+ }
7991
+
7992
+ }
7993
+ }
7994
+ }
7995
+
7996
+ table{
7997
+ Xheight: 100%;
7998
+ min-width:100%;
7999
+ width: max-content;
8000
+ border-spacing: 0;
8001
+
8002
+ thead{
8003
+ position: sticky;
8004
+ top: 0;
8005
+
8006
+ th{
8007
+ position: relative;
8008
+ height:32px;
8009
+ padding: 4px;
8010
+ background: linear-gradient(180deg, rgba(227, 227, 226, 1) 0%, rgba(255, 255, 255, 1) 25%, rgba(210, 210, 210, 1) 100%);
8011
+ box-shadow: 2px 2px 2px 0 #ffffffd6 inset, -1px -1px 2px 0px #8a847dbf inset;
8012
+ color: #525252;
8013
+ white-space: nowrap;
8014
+ }
8015
+ }
8016
+
8017
+ tfoot{
8018
+ position: sticky;
8019
+ bottom: -1px;
8020
+
8021
+ Xtr:nth-child(1){
8022
+ th{
8023
+ Xborder-top:1px solid var(--column-bd-color);
8024
+ }
8025
+ }
8026
+ Xth:nth-child(1){
8027
+ Xborder-left:1px solid var(--column-bd-color);
8028
+ }
8029
+
8030
+ th{
8031
+ height:32px;
8032
+ padding: 4px;
8033
+ background: #e4e4e4;
8034
+ xbackground: linear-gradient(180deg, rgba(227, 227, 226, 1) 0%, rgba(255, 255, 255, 1) 25%, rgba(210, 210, 210, 1) 100%);
8035
+ xbox-shadow: 2px 2px 2px 0 #ffffffd6 inset, -1px -1px 2px 0px #8a847dbf inset;
8036
+ color: #525252;
8037
+ white-space: nowrap;
8038
+
8039
+ border-left:2px solid #f4f4f4;
8040
+ border-top:2px solid #f4f4f4;
8041
+ border-right:2px solid var(--column-bd-color);
8042
+ border-bottom:2px solid var(--column-bd-color);
8043
+ }
8044
+ }
8045
+
8046
+ tbody{
8047
+ tr{
8048
+ transition: background .3s linear;
8049
+ background:var(--column-b-color);
8050
+ a:#ededed;
8051
+ th{
8052
+ color:#444444;
8053
+ }
8054
+ td{
8055
+ border-bottom: 1px solid var(--column-bd-color);
8056
+ color:#2e2e2e;
8057
+ padding: 4px;
8058
+ }
8059
+ }
8060
+ tr:hover{
8061
+ background:var(--column-b-hover-color);
8062
+
8063
+ }
8064
+
8065
+ tr.jr-group-header
8066
+ ,tr.jr-group-footer{
8067
+ text-align:left;
8068
+ background:#dddbdb;
8069
+
8070
+ th{
8071
+ border-bottom: 1px solid var(--column-bd-color);
8072
+ border-right: 1px solid var(--column-bd-color);
8073
+ padding: 4px 8px;
8074
+ }
8075
+ }
8076
+ }
8077
+ tbody.empty-tbody{
8078
+ td{
8079
+ border:10px solid red;
8080
+ }
8081
+ }
8082
+ }
8083
+
8084
+
8085
+
8086
+
8087
+ > .empty{
8088
+ user-select: none;
8089
+ color:#848484;
8090
+ height:100%;
8091
+ flex:1;
8092
+ display:flex;
8093
+ justify-content: center;
8094
+ align-items: center;
8095
+ }
8096
+ `;
8097
+
8098
+ const getMapObject = (map, names) => {
8099
+ const name = names.shift(names);
8100
+ if (names.length) {
8101
+ return getMapObject(map?.[name], names);
8102
+ } else {
8103
+ return map;
8104
+ }
8105
+ };
8106
+ const setMapObject = (map, names, value) => {
8107
+ const name = names.shift(names);
8108
+ if (names?.length) {
8109
+ if (typeof map[name] != 'object') {
8110
+ map[name] = {};
8111
+ }
8112
+ setMapObject(map[name], names, value);
8113
+ } else {
8114
+ map[name] = value;
8115
+ }
8116
+ };
8117
+ class JRTable extends JRFrame {
8118
+ constructor(props) {
8119
+ super(props);
8120
+ this.colGroupRef = /*#__PURE__*/React.createRef();
8121
+ }
8122
+ UNSAFE_componentWillMount() {
8123
+ this.setColumns(this.props.columns);
8124
+ }
8125
+
8126
+ //------------------------------------------------------------------------------------
8127
+ getChecked() {
8128
+ return [1, 2, 3, 4];
8129
+ }
8130
+ checkableColumn(props) {
8131
+ return {
8132
+ //方法1
8133
+ render({
8134
+ value,
8135
+ onChange
8136
+ }) {
8137
+ return /*#__PURE__*/React.createElement("checkbox", {
8138
+ checked: value,
8139
+ onChange: e => {
8140
+ onChange(e.target.checked);
8141
+ }
8142
+ });
8143
+ },
8144
+ align: 'center',
8145
+ name: 'checked',
8146
+ ...props
8147
+ };
8148
+ // return {//方法2
8149
+ // type:Checkbox
8150
+ // ,funcProps({value}){
8151
+ // po('fffffffffffff',value)
8152
+ // return {
8153
+ // align:'center'
8154
+ // ,checked:value
8155
+ // }
8156
+ // }
8157
+ // // ,label:'A'
8158
+ // ,onChange(e,{value,onChange,me}){
8159
+ // onChange(e.target.checked)
8160
+ // }
8161
+ // ,...props
8162
+ // }
8163
+ }
8164
+ deletableColumn({
8165
+ name = 'deletable',
8166
+ sendValue,
8167
+ sendName,
8168
+ valueName,
8169
+ ...props
8170
+ }) {
8171
+ return {
8172
+ render({
8173
+ value,
8174
+ onChange
8175
+ }) {
8176
+ return /*#__PURE__*/React.createElement("checkbox", {
8177
+ checked: value,
8178
+ onChange: e => {
8179
+ onChange(e.target.checked);
8180
+ }
8181
+ });
8182
+ },
8183
+ align: 'center',
8184
+ name,
8185
+ label() {
8186
+ return /*#__PURE__*/React.createElement("button", {
8187
+ onClick: () => {
8188
+ const value = this.props.delete.value ?? this.getDataSource()?.filter(record => record[name]).map(record => sendValue ? record[sendValue] : record);
8189
+ const callback = this.props.delete.callback ?? function (a, b, c) {
8190
+ this.reload();
8191
+ };
8192
+ this.delete({
8193
+ value: sendName ? {
8194
+ [sendName]: value
8195
+ } : value,
8196
+ callback,
8197
+ ...props
8198
+ });
8199
+ }
8200
+ }, "\u522A\u9664");
8201
+ },
8202
+ ...props
8203
+ };
8204
+ }
8205
+ initColumn(column, level, result, leafColumns, names, lastColSpan) {
8206
+ const isBranch = column.type === undefined && column?.columns && column?.columns.length;
8207
+ const _names = column.name ? [...names, column.name] : names;
8208
+ if (isBranch) {
8209
+ if (column.label !== null) result[level].push(column);
8210
+ const c = this.initColumns(column.columns, level + (column.label !== null ? 1 : 0) + (column.rowSpan != null ? column.rowSpan - 1 : 0), result, leafColumns, _names, lastColSpan);
8211
+ column.colSpan = c.colSpan;
8212
+ column.columnNo = lastColSpan;
8213
+ return {
8214
+ colSpan: column.colSpan
8215
+ };
8216
+ } else {
8217
+ column.columnNo = lastColSpan;
8218
+ result[level].push({
8219
+ ...column,
8220
+ isLeaf: true
8221
+ });
8222
+ leafColumns.push(column);
8223
+ column.names = _names;
8224
+ if (_names?.length > 1) {
8225
+ column.setValue = function (record, value) {
8226
+ try {
8227
+ getMapObject(record, [..._names])[column.name] = value;
8228
+ } catch {
8229
+ setMapObject(record, [..._names], value);
8230
+ }
8231
+ };
8232
+ column.getValue = function (record) {
8233
+ return _names.reduce((acc, name) => {
8234
+ return acc?.[name];
8235
+ }, record);
8236
+ };
8237
+ } else {
8238
+ column.setValue = function (record, value) {
8239
+ record[column.name] = value;
8240
+ };
8241
+ column.getValue = function (record) {
8242
+ return record[column.name];
8243
+ };
8244
+ }
8245
+ return {
8246
+ colSpan: 1
8247
+ };
8248
+ }
8249
+ }
8250
+ initColumns(columns, level, result, leafColumns, names, lastColSpan) {
8251
+ for (let i = result.length; i <= level; i++) {
8252
+ if (!result[i]) {
8253
+ result.push([]);
8254
+ }
8255
+ }
8256
+ let _lastColSpan = lastColSpan;
8257
+ const childrenLength = columns?.reduce((acc, column) => {
8258
+ const c = this.initColumn(column, level, result, leafColumns, names, _lastColSpan);
8259
+ acc.colSpan += c.colSpan;
8260
+ _lastColSpan += c.colSpan;
8261
+ return acc;
8262
+ }, {
8263
+ colSpan: 0
8264
+ });
8265
+ return childrenLength;
8266
+ }
8267
+ setColumns([..._columns]) {
8268
+ if (this.props.checkable) _columns.unshift(this.checkableColumn(this.props.checkable));
8269
+ if (this.props.deletable) {
8270
+ _columns.unshift(this.deletableColumn(this.props.deletable));
8271
+ }
8272
+ const columns = [];
8273
+ const leafColumns = [];
8274
+ this.initColumns(_columns, 0, columns, leafColumns, [], 0);
8275
+ // po('initColumns',initColumns)
8276
+ this.setState({
8277
+ columns,
8278
+ leafColumns
8279
+ });
8280
+ }
8281
+ //------------------------------------------------------------------------------------
8282
+ setDataSource(dataSource) {}
8283
+ getDataSource() {
8284
+ return this.props.dataSourceName ? this.getValue()?.[this.props.dataSourceName] : this.getValue();
8285
+ }
8286
+ add(record, index = this.getDataSource()?.length ?? 0, group) {
8287
+ //group 還沒有考慮到
8288
+
8289
+ if (this.getDataSource()) {
8290
+ if (group === undefined) {
8291
+ this.getDataSource().splice(index, 0, record); //.push(record)
8292
+ } else {
8293
+ this.getDataSource()[group].splice(index, 0, record); //.push(record)
8294
+ }
8295
+ this.setValue(this.getValue());
8296
+ } else {
8297
+ //未完成. 沒有資料的時候, 要考慮有或沒有dataSourceName的不同處理
8298
+ this.setValue({
8299
+ [this.props.dataSourceName]: [record]
8300
+ });
8301
+ }
8302
+ }
8303
+ noData() {
8304
+ const data = this.getDataSource();
8305
+ return data == null || data.length == 0;
8306
+ }
8307
+ //------------------------------------------------------------------------------------
8308
+ renderMe() {
8309
+ return /*#__PURE__*/React.createElement(StyledJRTable, {
8310
+ className: `${this.props.className ?? ''} jr-table ${this.props.onRowClick ? 'row-highlightable' : ''}`
8311
+ }, /*#__PURE__*/React.createElement("table", {
8312
+ className: 'jr-table-table'
8313
+ }, /*#__PURE__*/React.createElement(TBodies, {
8314
+ table: this,
8315
+ leafColumns: this.state.leafColumns,
8316
+ groupHeader: this.props.groupHeader,
8317
+ groupFooter: this.props.groupFooter,
8318
+ dataSource: this.getDataSource(),
8319
+ onRowClick: this.props.onRowClick
8320
+ }), /*#__PURE__*/React.createElement(TFoot, {
8321
+ columns: this.props.footColumns,
8322
+ table: this
8323
+ }), /*#__PURE__*/React.createElement(THead, {
8324
+ columns: this.state.columns,
8325
+ leafColumns: this.state.leafColumns,
8326
+ table: this
8327
+ })), /*#__PURE__*/React.createElement("div", {
8328
+ className: 'empty'
8329
+ }, this.noData() && '無資料'));
8330
+ }
8331
+ }
8332
+
7480
8333
  function JRTest() {
7481
8334
  return 'I am JRTest string';
7482
8335
  }
@@ -7488,5 +8341,6 @@ class JRTestReact extends React.Component {
7488
8341
 
7489
8342
  exports.JRFrame = JRFrame;
7490
8343
  exports.JRSubmit = JRSubmit;
8344
+ exports.JRTable = JRTable;
7491
8345
  exports.JRTest = JRTest;
7492
8346
  exports.JRTestReact = JRTestReact;