jrs-react 1.2.3 → 1.2.4
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.es.js +436 -1
- package/build/index.js +436 -0
- package/package.json +1 -1
- package/src/index.js +2 -1
package/build/index.es.js
CHANGED
|
@@ -7411,6 +7411,441 @@ class JRTable extends JRFrame {
|
|
|
7411
7411
|
}
|
|
7412
7412
|
}
|
|
7413
7413
|
|
|
7414
|
+
const StyleJRFields = styled.main`
|
|
7415
|
+
--column-bd-color:#cccccc;
|
|
7416
|
+
--column-b-color:#eeeeee;
|
|
7417
|
+
--column-b-hover-color:#ffffff;
|
|
7418
|
+
|
|
7419
|
+
flex-direction: column;
|
|
7420
|
+
flex:1;
|
|
7421
|
+
overflow: overlay;
|
|
7422
|
+
|
|
7423
|
+
color:#525252;
|
|
7424
|
+
XXXborder: 1px solid #a0a0a0;
|
|
7425
|
+
background: var(--column-b-color);
|
|
7426
|
+
|
|
7427
|
+
>.jr-grid{
|
|
7428
|
+
background:var(--column-b-color);
|
|
7429
|
+
|
|
7430
|
+
.jr-column{
|
|
7431
|
+
padding: 6px;
|
|
7432
|
+
|
|
7433
|
+
label{
|
|
7434
|
+
color:#525252;
|
|
7435
|
+
text-wrap: nowrap;
|
|
7436
|
+
padding: 4px 10px 4px 0;
|
|
7437
|
+
font-weight: bold;
|
|
7438
|
+
}
|
|
7439
|
+
}
|
|
7440
|
+
}
|
|
7441
|
+
`;
|
|
7442
|
+
|
|
7443
|
+
function checkMap(_name, inputValue, mapValue, nameList) {
|
|
7444
|
+
if (nameList.length) {
|
|
7445
|
+
const name = nameList.shift();
|
|
7446
|
+
if (typeof mapValue[name] != 'object') {
|
|
7447
|
+
mapValue[name] = {};
|
|
7448
|
+
}
|
|
7449
|
+
checkMap(_name, inputValue, mapValue[name], nameList);
|
|
7450
|
+
} else {
|
|
7451
|
+
mapValue[_name] = inputValue;
|
|
7452
|
+
}
|
|
7453
|
+
}
|
|
7454
|
+
styled.div`
|
|
7455
|
+
overflow: auto;
|
|
7456
|
+
flex:1;
|
|
7457
|
+
`;
|
|
7458
|
+
const StyledGrid = styled.div`
|
|
7459
|
+
display: grid;
|
|
7460
|
+
grid: ${({
|
|
7461
|
+
grid,
|
|
7462
|
+
cols,
|
|
7463
|
+
children
|
|
7464
|
+
}) => grid ? grid : `auto / ${Array(cols ?? 1).fill().map(() => "1fr").join(" ")}`};
|
|
7465
|
+
|
|
7466
|
+
gap: ${({
|
|
7467
|
+
$gap
|
|
7468
|
+
}) => $gap};
|
|
7469
|
+
`;
|
|
7470
|
+
styled.div`
|
|
7471
|
+
`;
|
|
7472
|
+
const StyledColumn = styled.div`
|
|
7473
|
+
flex:1;
|
|
7474
|
+
display: grid;
|
|
7475
|
+
|
|
7476
|
+
${({
|
|
7477
|
+
$layout,
|
|
7478
|
+
$labelWidth,
|
|
7479
|
+
$hasLabel,
|
|
7480
|
+
$valueWidth
|
|
7481
|
+
}) => {
|
|
7482
|
+
if ($layout == 'v') {
|
|
7483
|
+
return `grid: auto 1fr / 1fr;`;
|
|
7484
|
+
} else {
|
|
7485
|
+
return `grid: 1fr / ${$hasLabel ? $labelWidth : ''} ${$valueWidth};`;
|
|
7486
|
+
}
|
|
7487
|
+
}}
|
|
7488
|
+
`;
|
|
7489
|
+
const StyledColumnLabel = styled.label`
|
|
7490
|
+
${({
|
|
7491
|
+
$layout
|
|
7492
|
+
}) => {
|
|
7493
|
+
if ($layout == 'v') {
|
|
7494
|
+
return `text-align: start;`;
|
|
7495
|
+
} else {
|
|
7496
|
+
return `text-align: end;`;
|
|
7497
|
+
}
|
|
7498
|
+
}}
|
|
7499
|
+
|
|
7500
|
+
${({
|
|
7501
|
+
$required
|
|
7502
|
+
}) => {
|
|
7503
|
+
if ($required !== undefined && $required) return `
|
|
7504
|
+
&:not(:empty)::before{
|
|
7505
|
+
padding-right:4px;
|
|
7506
|
+
color:red;
|
|
7507
|
+
content:'*';
|
|
7508
|
+
}
|
|
7509
|
+
`;
|
|
7510
|
+
}}
|
|
7511
|
+
|
|
7512
|
+
${({
|
|
7513
|
+
$colon
|
|
7514
|
+
}) => {
|
|
7515
|
+
if ($colon) {
|
|
7516
|
+
return `
|
|
7517
|
+
&:not(:empty)::after{
|
|
7518
|
+
content:'${$colon}';
|
|
7519
|
+
}
|
|
7520
|
+
`;
|
|
7521
|
+
}
|
|
7522
|
+
}}
|
|
7523
|
+
|
|
7524
|
+
`;
|
|
7525
|
+
const StyledColumnValue = styled.main`
|
|
7526
|
+
Xflex:1;
|
|
7527
|
+
Xdisplay:flex;
|
|
7528
|
+
overflow: hidden;
|
|
7529
|
+
|
|
7530
|
+
text-align: start;
|
|
7531
|
+
${({
|
|
7532
|
+
$validateValue
|
|
7533
|
+
}) => {
|
|
7534
|
+
if ($validateValue != null) {
|
|
7535
|
+
return `
|
|
7536
|
+
> * {
|
|
7537
|
+
xborder:1px solid red;
|
|
7538
|
+
}
|
|
7539
|
+
`;
|
|
7540
|
+
}
|
|
7541
|
+
}}
|
|
7542
|
+
`;
|
|
7543
|
+
|
|
7544
|
+
// String.prototype.valueString = function (value = {}) {
|
|
7545
|
+
// return Array.from(new Set(this.match(/[^{}]+(?=})/g))).reduce((aco, name) => {
|
|
7546
|
+
// return aco.replace(new RegExp(`\\{${name}\\}`, "g"), value[name] ?? `{${name}}`);
|
|
7547
|
+
// }, String(this));
|
|
7548
|
+
// };
|
|
7549
|
+
|
|
7550
|
+
const valueString = (str = '', value = {}) => {
|
|
7551
|
+
return Array.from(new Set(str.match(/[^{}]+(?=})/g))).reduce((aco, name) => {
|
|
7552
|
+
return aco.replace(new RegExp(`\\{${name}\\}`, "g"), value?.[name] ?? `{${name}}`);
|
|
7553
|
+
}, String(str));
|
|
7554
|
+
};
|
|
7555
|
+
const ColumnMessage = ({
|
|
7556
|
+
value = {},
|
|
7557
|
+
record
|
|
7558
|
+
}) => {
|
|
7559
|
+
if (value.isValid === false) {
|
|
7560
|
+
return valueString(value.msg, record);
|
|
7561
|
+
}
|
|
7562
|
+
};
|
|
7563
|
+
const StyledColumnFooter = styled.div`
|
|
7564
|
+
&:empty{
|
|
7565
|
+
display: none;
|
|
7566
|
+
}
|
|
7567
|
+
${({
|
|
7568
|
+
$layout
|
|
7569
|
+
}) => {
|
|
7570
|
+
if ($layout == 'v') {
|
|
7571
|
+
return ``;
|
|
7572
|
+
} else {
|
|
7573
|
+
return `grid-column-start:2;`;
|
|
7574
|
+
}
|
|
7575
|
+
}}
|
|
7576
|
+
height:25px;
|
|
7577
|
+
color:#ff6060;
|
|
7578
|
+
|
|
7579
|
+
display: flex;
|
|
7580
|
+
justify-content: space-between;
|
|
7581
|
+
|
|
7582
|
+
.left:{
|
|
7583
|
+
xflex:1;
|
|
7584
|
+
}
|
|
7585
|
+
.right{
|
|
7586
|
+
color:gray;
|
|
7587
|
+
xflex:1;
|
|
7588
|
+
}
|
|
7589
|
+
`;
|
|
7590
|
+
function requiredValidator({
|
|
7591
|
+
value
|
|
7592
|
+
}) {
|
|
7593
|
+
if (value == null || value == '') {
|
|
7594
|
+
return {
|
|
7595
|
+
msg: this.msg ?? 'This is required'
|
|
7596
|
+
};
|
|
7597
|
+
}
|
|
7598
|
+
}
|
|
7599
|
+
class JRFields extends JRFrame {
|
|
7600
|
+
UNSAFE_componentWillMount() {
|
|
7601
|
+
this.#initValidateValue();
|
|
7602
|
+
}
|
|
7603
|
+
reset() {
|
|
7604
|
+
this.clearValidateValue();
|
|
7605
|
+
super.reset();
|
|
7606
|
+
}
|
|
7607
|
+
setValue(value, reset) {
|
|
7608
|
+
super.setValue(value, reset);
|
|
7609
|
+
if (reset) {
|
|
7610
|
+
this.clearValidateValue();
|
|
7611
|
+
}
|
|
7612
|
+
}
|
|
7613
|
+
//-----------------------------------------------------------------------------------
|
|
7614
|
+
#findValidator(acc, fullname, {
|
|
7615
|
+
required,
|
|
7616
|
+
...column
|
|
7617
|
+
}) {
|
|
7618
|
+
const _required = required;
|
|
7619
|
+
if (required == true || required?.value) {
|
|
7620
|
+
acc[fullname] = {
|
|
7621
|
+
isValid: null,
|
|
7622
|
+
validators: [requiredValidator.bind(_required)]
|
|
7623
|
+
};
|
|
7624
|
+
}
|
|
7625
|
+
}
|
|
7626
|
+
#loopColumnsForValidateValue(no, _fullnameList, columns, tab, result) {
|
|
7627
|
+
const validateValue = columns?.reduce((acc, {
|
|
7628
|
+
name,
|
|
7629
|
+
type,
|
|
7630
|
+
columns,
|
|
7631
|
+
...column
|
|
7632
|
+
}, index) => {
|
|
7633
|
+
no += 1;
|
|
7634
|
+
const fullnameList = name ? [..._fullnameList, name] : _fullnameList;
|
|
7635
|
+
const fullname = fullnameList.join('.');
|
|
7636
|
+
// po(`${no} - ${tab}fn= ${fullname}`)
|
|
7637
|
+
this.#findValidator(acc, fullname, column);
|
|
7638
|
+
if (type == null && columns) {
|
|
7639
|
+
this.#loopColumnsForValidateValue(no, fullnameList, columns, `${tab}\t`, result);
|
|
7640
|
+
}
|
|
7641
|
+
return acc;
|
|
7642
|
+
}, result);
|
|
7643
|
+
return validateValue;
|
|
7644
|
+
}
|
|
7645
|
+
clearValidateValue() {
|
|
7646
|
+
Object.values(this.getValidateValue()).forEach(v => v.isValid = null);
|
|
7647
|
+
}
|
|
7648
|
+
#initValidateValue() {
|
|
7649
|
+
const columns = this.getColumns();
|
|
7650
|
+
const validateValue = this.#loopColumnsForValidateValue(0, this.props.dataSourceName ? [this.props.dataSourceName] : [], columns, '', {});
|
|
7651
|
+
this.setState({
|
|
7652
|
+
validateValue
|
|
7653
|
+
});
|
|
7654
|
+
}
|
|
7655
|
+
#exeValidateConfig(validateConfig, value, record) {
|
|
7656
|
+
validateConfig.isValid = true;
|
|
7657
|
+
for (var i = 0; i < validateConfig.validators.length; i++) {
|
|
7658
|
+
const result = validateConfig.validators[i]({
|
|
7659
|
+
value,
|
|
7660
|
+
record
|
|
7661
|
+
});
|
|
7662
|
+
if (result) {
|
|
7663
|
+
validateConfig.isValid = false;
|
|
7664
|
+
validateConfig.msg = result.msg;
|
|
7665
|
+
break;
|
|
7666
|
+
}
|
|
7667
|
+
}
|
|
7668
|
+
}
|
|
7669
|
+
validateFields() {
|
|
7670
|
+
console.clear();
|
|
7671
|
+
Object.entries(this.getValidateValue()).filter(([fullname, validateConfig]) => validateConfig.isValid != true).forEach(([fullname, validateConfig]) => {
|
|
7672
|
+
this.#exeValidateConfig(validateConfig, this.getValue(fullname), this.getValue());
|
|
7673
|
+
});
|
|
7674
|
+
this.setState({
|
|
7675
|
+
validateValue: this.getValidateValue()
|
|
7676
|
+
});
|
|
7677
|
+
}
|
|
7678
|
+
get validateValueFrom() {
|
|
7679
|
+
return this.props.validateValue === undefined ? 'state' : 'props';
|
|
7680
|
+
}
|
|
7681
|
+
getValidateValue(fullname) {
|
|
7682
|
+
if (fullname === undefined) {
|
|
7683
|
+
return this[this.validateValueFrom]?.validateValue;
|
|
7684
|
+
} else {
|
|
7685
|
+
return this[this.validateValueFrom]?.validateValue?.[fullname];
|
|
7686
|
+
}
|
|
7687
|
+
}
|
|
7688
|
+
setValidateValue(validateValue) {
|
|
7689
|
+
if (this.props.setValidateValue) {
|
|
7690
|
+
this.props.setValidateValue(validateValue);
|
|
7691
|
+
} else {
|
|
7692
|
+
this.setState({
|
|
7693
|
+
validateValue
|
|
7694
|
+
});
|
|
7695
|
+
}
|
|
7696
|
+
}
|
|
7697
|
+
createValidator({
|
|
7698
|
+
required
|
|
7699
|
+
}) {
|
|
7700
|
+
const validators = [];
|
|
7701
|
+
if (required === true && required.value) {
|
|
7702
|
+
validators.push(requiredValidator);
|
|
7703
|
+
}
|
|
7704
|
+
return validators;
|
|
7705
|
+
}
|
|
7706
|
+
//--------------------------------------------------------------------------------------
|
|
7707
|
+
get columnsFrom() {
|
|
7708
|
+
return this.props.initColumns !== undefined ? 'state' : 'props';
|
|
7709
|
+
}
|
|
7710
|
+
getColumns() {
|
|
7711
|
+
return this[this.columnsFrom]?.columns;
|
|
7712
|
+
}
|
|
7713
|
+
//-------------------------------------------------------------------------------------------
|
|
7714
|
+
|
|
7715
|
+
get colon() {
|
|
7716
|
+
return this.props.labelProps?.colon === undefined ? ':' : this.props.labelProps?.colon;
|
|
7717
|
+
}
|
|
7718
|
+
createColumn(parentValue, {
|
|
7719
|
+
type,
|
|
7720
|
+
name,
|
|
7721
|
+
colSpan,
|
|
7722
|
+
rowSpan,
|
|
7723
|
+
style,
|
|
7724
|
+
typeStyle: _typeStyle,
|
|
7725
|
+
required,
|
|
7726
|
+
...column
|
|
7727
|
+
}, index, parentName, fullname) {
|
|
7728
|
+
// po('----------------------------------------')
|
|
7729
|
+
// po('parentName',parentName)
|
|
7730
|
+
// po('fullname',fullname)
|
|
7731
|
+
const value = name ? parentValue?.[name] : parentValue;
|
|
7732
|
+
const gap = column.gap ?? this.props.gap;
|
|
7733
|
+
const label = column.label;
|
|
7734
|
+
const _style = flexType(style, this, {}, {});
|
|
7735
|
+
if (colSpan) _style.gridColumn = `span ${colSpan}`;
|
|
7736
|
+
if (rowSpan) _style.gridRow = `span ${rowSpan}`;
|
|
7737
|
+
// Object.assign(_style,style)
|
|
7738
|
+
|
|
7739
|
+
let content;
|
|
7740
|
+
this.createValidator({
|
|
7741
|
+
required,
|
|
7742
|
+
column
|
|
7743
|
+
});
|
|
7744
|
+
const fn = fullname.join('.');
|
|
7745
|
+
const onChange = inputValue => {
|
|
7746
|
+
const targetValue = inputValue?.target?.value ?? inputValue;
|
|
7747
|
+
// po('===Form onChange===',targetValue)
|
|
7748
|
+
try {
|
|
7749
|
+
parentValue[name] = targetValue;
|
|
7750
|
+
this.setValue({
|
|
7751
|
+
...this.getValue()
|
|
7752
|
+
});
|
|
7753
|
+
} catch (e) {
|
|
7754
|
+
const _value = this.getValue() ?? {};
|
|
7755
|
+
checkMap(name, targetValue, _value, [...parentName]);
|
|
7756
|
+
this.setValue(_value);
|
|
7757
|
+
}
|
|
7758
|
+
if (this.getValidateValue()[fn]) this.#exeValidateConfig(this.getValidateValue()[fn], targetValue, this.getValue());
|
|
7759
|
+
};
|
|
7760
|
+
const _parentName = [...parentName];
|
|
7761
|
+
if (name !== undefined) {
|
|
7762
|
+
_parentName.push(name);
|
|
7763
|
+
}
|
|
7764
|
+
if (type) {
|
|
7765
|
+
const typeStyle = flexType(_typeStyle, this, null);
|
|
7766
|
+
content = /*#__PURE__*/React.createElement(StyledColumnValue, {
|
|
7767
|
+
className: 'jr-column-value',
|
|
7768
|
+
style: {
|
|
7769
|
+
gridColumn: label == null ? 'span 2' : null
|
|
7770
|
+
}
|
|
7771
|
+
}, /*#__PURE__*/React.createElement(type, {
|
|
7772
|
+
value: value,
|
|
7773
|
+
onChange,
|
|
7774
|
+
record: parentValue,
|
|
7775
|
+
style: {
|
|
7776
|
+
width: '100%',
|
|
7777
|
+
...typeStyle
|
|
7778
|
+
},
|
|
7779
|
+
...column
|
|
7780
|
+
}));
|
|
7781
|
+
} else if (column.columns) {
|
|
7782
|
+
content = /*#__PURE__*/React.createElement(StyledGrid, {
|
|
7783
|
+
cols: column.cols,
|
|
7784
|
+
className: 'jr-grid',
|
|
7785
|
+
$gap: gap
|
|
7786
|
+
}, this.createColumns(value, column.columns, _parentName, fullname));
|
|
7787
|
+
} else if (name || column.render) {
|
|
7788
|
+
content = /*#__PURE__*/React.createElement(StyledColumnValue, {
|
|
7789
|
+
className: 'jr-column-value',
|
|
7790
|
+
style: {
|
|
7791
|
+
gridColumn: label == null ? 'span 2' : null,
|
|
7792
|
+
padding: column.render ? '4px 0' : null
|
|
7793
|
+
}
|
|
7794
|
+
}, column.render ? column.render.bind(this)({
|
|
7795
|
+
onChange,
|
|
7796
|
+
value: value,
|
|
7797
|
+
record: this.getValue()
|
|
7798
|
+
}) : typeof value === 'object' ? JSON.stringify(value) : value);
|
|
7799
|
+
}
|
|
7800
|
+
const layout = column.labelProps?.layout === undefined ? this.props.labelProps?.layout : column.labelProps?.layout;
|
|
7801
|
+
return /*#__PURE__*/React.createElement(StyledColumn, {
|
|
7802
|
+
$layout: layout,
|
|
7803
|
+
$hasLabel: label != null,
|
|
7804
|
+
key: `f${index}`,
|
|
7805
|
+
style: _style,
|
|
7806
|
+
className: 'jr-column',
|
|
7807
|
+
$labelWidth: column.labelProps?.width ?? this.props.labelProps?.width ?? '120px',
|
|
7808
|
+
$valueWidth: column.valueProps?.width ?? this.props.valueProps?.width ?? '1fr'
|
|
7809
|
+
}, label != null && /*#__PURE__*/React.createElement(StyledColumnLabel, {
|
|
7810
|
+
$required: required,
|
|
7811
|
+
className: 'label',
|
|
7812
|
+
$layout: layout,
|
|
7813
|
+
$colon: column.labelProps?.colon === undefined ? this.colon : column.labelProps?.colon
|
|
7814
|
+
}, label), content, this.props.debugMode && /*#__PURE__*/React.createElement(StyledColumnFooter, null, /*#__PURE__*/React.createElement("div", {
|
|
7815
|
+
className: "left"
|
|
7816
|
+
}, /*#__PURE__*/React.createElement(ColumnMessage, {
|
|
7817
|
+
value: this.getValidateValue(_parentName.join('.')),
|
|
7818
|
+
record: this.getValue()
|
|
7819
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
7820
|
+
className: "right"
|
|
7821
|
+
}))
|
|
7822
|
+
// validateValue?.[name]!==undefined && <StyledColumnFooter $layout={layout}>
|
|
7823
|
+
// {/* {validateValue?.[name]?.$message} */}
|
|
7824
|
+
// <ColumnMessage value={validateValue?.[name]}/>
|
|
7825
|
+
// </StyledColumnFooter>
|
|
7826
|
+
);
|
|
7827
|
+
}
|
|
7828
|
+
createColumns(parentValue, columns, parentName, fullname) {
|
|
7829
|
+
return columns?.map((column, index) => {
|
|
7830
|
+
return this.createColumn(parentValue, column, index, parentName, column.name ? [...fullname, column.name] : fullname);
|
|
7831
|
+
});
|
|
7832
|
+
}
|
|
7833
|
+
renderMe() {
|
|
7834
|
+
return /*#__PURE__*/React.createElement(StyleJRFields, {
|
|
7835
|
+
className: 'jr-fields'
|
|
7836
|
+
}, /*#__PURE__*/React.createElement(StyledGrid, {
|
|
7837
|
+
cols: this.props.cols,
|
|
7838
|
+
style: this.props.gridStyle,
|
|
7839
|
+
className: 'jr-grid',
|
|
7840
|
+
$gap: this.props.gap
|
|
7841
|
+
}, this.createColumns(this.props.dataSourceName ? this.getValue()?.[this.props.dataSourceName] : this.getValue(), this.props.columns, this.props.dataSourceName ? [this.props.dataSourceName] : [], this.props.dataSourceName ? [this.props.dataSourceName] : [])));
|
|
7842
|
+
}
|
|
7843
|
+
|
|
7844
|
+
// render(){
|
|
7845
|
+
// return this.renderMe()
|
|
7846
|
+
// }
|
|
7847
|
+
}
|
|
7848
|
+
|
|
7414
7849
|
const StyledJRFrame = styled.div`
|
|
7415
7850
|
display:flex;
|
|
7416
7851
|
flex:1;
|
|
@@ -7510,4 +7945,4 @@ class JRTestReact extends JRSubmit {
|
|
|
7510
7945
|
}
|
|
7511
7946
|
}
|
|
7512
7947
|
|
|
7513
|
-
export { JRFrame, JRSubmit, JRTable, JRTestReact };
|
|
7948
|
+
export { JRFields, JRFrame, JRSubmit, JRTable, JRTestReact };
|
package/build/index.js
CHANGED
|
@@ -7419,6 +7419,441 @@ class JRTable extends JRFrame {
|
|
|
7419
7419
|
}
|
|
7420
7420
|
}
|
|
7421
7421
|
|
|
7422
|
+
const StyleJRFields = styled__default["default"].main`
|
|
7423
|
+
--column-bd-color:#cccccc;
|
|
7424
|
+
--column-b-color:#eeeeee;
|
|
7425
|
+
--column-b-hover-color:#ffffff;
|
|
7426
|
+
|
|
7427
|
+
flex-direction: column;
|
|
7428
|
+
flex:1;
|
|
7429
|
+
overflow: overlay;
|
|
7430
|
+
|
|
7431
|
+
color:#525252;
|
|
7432
|
+
XXXborder: 1px solid #a0a0a0;
|
|
7433
|
+
background: var(--column-b-color);
|
|
7434
|
+
|
|
7435
|
+
>.jr-grid{
|
|
7436
|
+
background:var(--column-b-color);
|
|
7437
|
+
|
|
7438
|
+
.jr-column{
|
|
7439
|
+
padding: 6px;
|
|
7440
|
+
|
|
7441
|
+
label{
|
|
7442
|
+
color:#525252;
|
|
7443
|
+
text-wrap: nowrap;
|
|
7444
|
+
padding: 4px 10px 4px 0;
|
|
7445
|
+
font-weight: bold;
|
|
7446
|
+
}
|
|
7447
|
+
}
|
|
7448
|
+
}
|
|
7449
|
+
`;
|
|
7450
|
+
|
|
7451
|
+
function checkMap(_name, inputValue, mapValue, nameList) {
|
|
7452
|
+
if (nameList.length) {
|
|
7453
|
+
const name = nameList.shift();
|
|
7454
|
+
if (typeof mapValue[name] != 'object') {
|
|
7455
|
+
mapValue[name] = {};
|
|
7456
|
+
}
|
|
7457
|
+
checkMap(_name, inputValue, mapValue[name], nameList);
|
|
7458
|
+
} else {
|
|
7459
|
+
mapValue[_name] = inputValue;
|
|
7460
|
+
}
|
|
7461
|
+
}
|
|
7462
|
+
styled__default["default"].div`
|
|
7463
|
+
overflow: auto;
|
|
7464
|
+
flex:1;
|
|
7465
|
+
`;
|
|
7466
|
+
const StyledGrid = styled__default["default"].div`
|
|
7467
|
+
display: grid;
|
|
7468
|
+
grid: ${({
|
|
7469
|
+
grid,
|
|
7470
|
+
cols,
|
|
7471
|
+
children
|
|
7472
|
+
}) => grid ? grid : `auto / ${Array(cols ?? 1).fill().map(() => "1fr").join(" ")}`};
|
|
7473
|
+
|
|
7474
|
+
gap: ${({
|
|
7475
|
+
$gap
|
|
7476
|
+
}) => $gap};
|
|
7477
|
+
`;
|
|
7478
|
+
styled__default["default"].div`
|
|
7479
|
+
`;
|
|
7480
|
+
const StyledColumn = styled__default["default"].div`
|
|
7481
|
+
flex:1;
|
|
7482
|
+
display: grid;
|
|
7483
|
+
|
|
7484
|
+
${({
|
|
7485
|
+
$layout,
|
|
7486
|
+
$labelWidth,
|
|
7487
|
+
$hasLabel,
|
|
7488
|
+
$valueWidth
|
|
7489
|
+
}) => {
|
|
7490
|
+
if ($layout == 'v') {
|
|
7491
|
+
return `grid: auto 1fr / 1fr;`;
|
|
7492
|
+
} else {
|
|
7493
|
+
return `grid: 1fr / ${$hasLabel ? $labelWidth : ''} ${$valueWidth};`;
|
|
7494
|
+
}
|
|
7495
|
+
}}
|
|
7496
|
+
`;
|
|
7497
|
+
const StyledColumnLabel = styled__default["default"].label`
|
|
7498
|
+
${({
|
|
7499
|
+
$layout
|
|
7500
|
+
}) => {
|
|
7501
|
+
if ($layout == 'v') {
|
|
7502
|
+
return `text-align: start;`;
|
|
7503
|
+
} else {
|
|
7504
|
+
return `text-align: end;`;
|
|
7505
|
+
}
|
|
7506
|
+
}}
|
|
7507
|
+
|
|
7508
|
+
${({
|
|
7509
|
+
$required
|
|
7510
|
+
}) => {
|
|
7511
|
+
if ($required !== undefined && $required) return `
|
|
7512
|
+
&:not(:empty)::before{
|
|
7513
|
+
padding-right:4px;
|
|
7514
|
+
color:red;
|
|
7515
|
+
content:'*';
|
|
7516
|
+
}
|
|
7517
|
+
`;
|
|
7518
|
+
}}
|
|
7519
|
+
|
|
7520
|
+
${({
|
|
7521
|
+
$colon
|
|
7522
|
+
}) => {
|
|
7523
|
+
if ($colon) {
|
|
7524
|
+
return `
|
|
7525
|
+
&:not(:empty)::after{
|
|
7526
|
+
content:'${$colon}';
|
|
7527
|
+
}
|
|
7528
|
+
`;
|
|
7529
|
+
}
|
|
7530
|
+
}}
|
|
7531
|
+
|
|
7532
|
+
`;
|
|
7533
|
+
const StyledColumnValue = styled__default["default"].main`
|
|
7534
|
+
Xflex:1;
|
|
7535
|
+
Xdisplay:flex;
|
|
7536
|
+
overflow: hidden;
|
|
7537
|
+
|
|
7538
|
+
text-align: start;
|
|
7539
|
+
${({
|
|
7540
|
+
$validateValue
|
|
7541
|
+
}) => {
|
|
7542
|
+
if ($validateValue != null) {
|
|
7543
|
+
return `
|
|
7544
|
+
> * {
|
|
7545
|
+
xborder:1px solid red;
|
|
7546
|
+
}
|
|
7547
|
+
`;
|
|
7548
|
+
}
|
|
7549
|
+
}}
|
|
7550
|
+
`;
|
|
7551
|
+
|
|
7552
|
+
// String.prototype.valueString = function (value = {}) {
|
|
7553
|
+
// return Array.from(new Set(this.match(/[^{}]+(?=})/g))).reduce((aco, name) => {
|
|
7554
|
+
// return aco.replace(new RegExp(`\\{${name}\\}`, "g"), value[name] ?? `{${name}}`);
|
|
7555
|
+
// }, String(this));
|
|
7556
|
+
// };
|
|
7557
|
+
|
|
7558
|
+
const valueString = (str = '', value = {}) => {
|
|
7559
|
+
return Array.from(new Set(str.match(/[^{}]+(?=})/g))).reduce((aco, name) => {
|
|
7560
|
+
return aco.replace(new RegExp(`\\{${name}\\}`, "g"), value?.[name] ?? `{${name}}`);
|
|
7561
|
+
}, String(str));
|
|
7562
|
+
};
|
|
7563
|
+
const ColumnMessage = ({
|
|
7564
|
+
value = {},
|
|
7565
|
+
record
|
|
7566
|
+
}) => {
|
|
7567
|
+
if (value.isValid === false) {
|
|
7568
|
+
return valueString(value.msg, record);
|
|
7569
|
+
}
|
|
7570
|
+
};
|
|
7571
|
+
const StyledColumnFooter = styled__default["default"].div`
|
|
7572
|
+
&:empty{
|
|
7573
|
+
display: none;
|
|
7574
|
+
}
|
|
7575
|
+
${({
|
|
7576
|
+
$layout
|
|
7577
|
+
}) => {
|
|
7578
|
+
if ($layout == 'v') {
|
|
7579
|
+
return ``;
|
|
7580
|
+
} else {
|
|
7581
|
+
return `grid-column-start:2;`;
|
|
7582
|
+
}
|
|
7583
|
+
}}
|
|
7584
|
+
height:25px;
|
|
7585
|
+
color:#ff6060;
|
|
7586
|
+
|
|
7587
|
+
display: flex;
|
|
7588
|
+
justify-content: space-between;
|
|
7589
|
+
|
|
7590
|
+
.left:{
|
|
7591
|
+
xflex:1;
|
|
7592
|
+
}
|
|
7593
|
+
.right{
|
|
7594
|
+
color:gray;
|
|
7595
|
+
xflex:1;
|
|
7596
|
+
}
|
|
7597
|
+
`;
|
|
7598
|
+
function requiredValidator({
|
|
7599
|
+
value
|
|
7600
|
+
}) {
|
|
7601
|
+
if (value == null || value == '') {
|
|
7602
|
+
return {
|
|
7603
|
+
msg: this.msg ?? 'This is required'
|
|
7604
|
+
};
|
|
7605
|
+
}
|
|
7606
|
+
}
|
|
7607
|
+
class JRFields extends JRFrame {
|
|
7608
|
+
UNSAFE_componentWillMount() {
|
|
7609
|
+
this.#initValidateValue();
|
|
7610
|
+
}
|
|
7611
|
+
reset() {
|
|
7612
|
+
this.clearValidateValue();
|
|
7613
|
+
super.reset();
|
|
7614
|
+
}
|
|
7615
|
+
setValue(value, reset) {
|
|
7616
|
+
super.setValue(value, reset);
|
|
7617
|
+
if (reset) {
|
|
7618
|
+
this.clearValidateValue();
|
|
7619
|
+
}
|
|
7620
|
+
}
|
|
7621
|
+
//-----------------------------------------------------------------------------------
|
|
7622
|
+
#findValidator(acc, fullname, {
|
|
7623
|
+
required,
|
|
7624
|
+
...column
|
|
7625
|
+
}) {
|
|
7626
|
+
const _required = required;
|
|
7627
|
+
if (required == true || required?.value) {
|
|
7628
|
+
acc[fullname] = {
|
|
7629
|
+
isValid: null,
|
|
7630
|
+
validators: [requiredValidator.bind(_required)]
|
|
7631
|
+
};
|
|
7632
|
+
}
|
|
7633
|
+
}
|
|
7634
|
+
#loopColumnsForValidateValue(no, _fullnameList, columns, tab, result) {
|
|
7635
|
+
const validateValue = columns?.reduce((acc, {
|
|
7636
|
+
name,
|
|
7637
|
+
type,
|
|
7638
|
+
columns,
|
|
7639
|
+
...column
|
|
7640
|
+
}, index) => {
|
|
7641
|
+
no += 1;
|
|
7642
|
+
const fullnameList = name ? [..._fullnameList, name] : _fullnameList;
|
|
7643
|
+
const fullname = fullnameList.join('.');
|
|
7644
|
+
// po(`${no} - ${tab}fn= ${fullname}`)
|
|
7645
|
+
this.#findValidator(acc, fullname, column);
|
|
7646
|
+
if (type == null && columns) {
|
|
7647
|
+
this.#loopColumnsForValidateValue(no, fullnameList, columns, `${tab}\t`, result);
|
|
7648
|
+
}
|
|
7649
|
+
return acc;
|
|
7650
|
+
}, result);
|
|
7651
|
+
return validateValue;
|
|
7652
|
+
}
|
|
7653
|
+
clearValidateValue() {
|
|
7654
|
+
Object.values(this.getValidateValue()).forEach(v => v.isValid = null);
|
|
7655
|
+
}
|
|
7656
|
+
#initValidateValue() {
|
|
7657
|
+
const columns = this.getColumns();
|
|
7658
|
+
const validateValue = this.#loopColumnsForValidateValue(0, this.props.dataSourceName ? [this.props.dataSourceName] : [], columns, '', {});
|
|
7659
|
+
this.setState({
|
|
7660
|
+
validateValue
|
|
7661
|
+
});
|
|
7662
|
+
}
|
|
7663
|
+
#exeValidateConfig(validateConfig, value, record) {
|
|
7664
|
+
validateConfig.isValid = true;
|
|
7665
|
+
for (var i = 0; i < validateConfig.validators.length; i++) {
|
|
7666
|
+
const result = validateConfig.validators[i]({
|
|
7667
|
+
value,
|
|
7668
|
+
record
|
|
7669
|
+
});
|
|
7670
|
+
if (result) {
|
|
7671
|
+
validateConfig.isValid = false;
|
|
7672
|
+
validateConfig.msg = result.msg;
|
|
7673
|
+
break;
|
|
7674
|
+
}
|
|
7675
|
+
}
|
|
7676
|
+
}
|
|
7677
|
+
validateFields() {
|
|
7678
|
+
console.clear();
|
|
7679
|
+
Object.entries(this.getValidateValue()).filter(([fullname, validateConfig]) => validateConfig.isValid != true).forEach(([fullname, validateConfig]) => {
|
|
7680
|
+
this.#exeValidateConfig(validateConfig, this.getValue(fullname), this.getValue());
|
|
7681
|
+
});
|
|
7682
|
+
this.setState({
|
|
7683
|
+
validateValue: this.getValidateValue()
|
|
7684
|
+
});
|
|
7685
|
+
}
|
|
7686
|
+
get validateValueFrom() {
|
|
7687
|
+
return this.props.validateValue === undefined ? 'state' : 'props';
|
|
7688
|
+
}
|
|
7689
|
+
getValidateValue(fullname) {
|
|
7690
|
+
if (fullname === undefined) {
|
|
7691
|
+
return this[this.validateValueFrom]?.validateValue;
|
|
7692
|
+
} else {
|
|
7693
|
+
return this[this.validateValueFrom]?.validateValue?.[fullname];
|
|
7694
|
+
}
|
|
7695
|
+
}
|
|
7696
|
+
setValidateValue(validateValue) {
|
|
7697
|
+
if (this.props.setValidateValue) {
|
|
7698
|
+
this.props.setValidateValue(validateValue);
|
|
7699
|
+
} else {
|
|
7700
|
+
this.setState({
|
|
7701
|
+
validateValue
|
|
7702
|
+
});
|
|
7703
|
+
}
|
|
7704
|
+
}
|
|
7705
|
+
createValidator({
|
|
7706
|
+
required
|
|
7707
|
+
}) {
|
|
7708
|
+
const validators = [];
|
|
7709
|
+
if (required === true && required.value) {
|
|
7710
|
+
validators.push(requiredValidator);
|
|
7711
|
+
}
|
|
7712
|
+
return validators;
|
|
7713
|
+
}
|
|
7714
|
+
//--------------------------------------------------------------------------------------
|
|
7715
|
+
get columnsFrom() {
|
|
7716
|
+
return this.props.initColumns !== undefined ? 'state' : 'props';
|
|
7717
|
+
}
|
|
7718
|
+
getColumns() {
|
|
7719
|
+
return this[this.columnsFrom]?.columns;
|
|
7720
|
+
}
|
|
7721
|
+
//-------------------------------------------------------------------------------------------
|
|
7722
|
+
|
|
7723
|
+
get colon() {
|
|
7724
|
+
return this.props.labelProps?.colon === undefined ? ':' : this.props.labelProps?.colon;
|
|
7725
|
+
}
|
|
7726
|
+
createColumn(parentValue, {
|
|
7727
|
+
type,
|
|
7728
|
+
name,
|
|
7729
|
+
colSpan,
|
|
7730
|
+
rowSpan,
|
|
7731
|
+
style,
|
|
7732
|
+
typeStyle: _typeStyle,
|
|
7733
|
+
required,
|
|
7734
|
+
...column
|
|
7735
|
+
}, index, parentName, fullname) {
|
|
7736
|
+
// po('----------------------------------------')
|
|
7737
|
+
// po('parentName',parentName)
|
|
7738
|
+
// po('fullname',fullname)
|
|
7739
|
+
const value = name ? parentValue?.[name] : parentValue;
|
|
7740
|
+
const gap = column.gap ?? this.props.gap;
|
|
7741
|
+
const label = column.label;
|
|
7742
|
+
const _style = flexType(style, this, {}, {});
|
|
7743
|
+
if (colSpan) _style.gridColumn = `span ${colSpan}`;
|
|
7744
|
+
if (rowSpan) _style.gridRow = `span ${rowSpan}`;
|
|
7745
|
+
// Object.assign(_style,style)
|
|
7746
|
+
|
|
7747
|
+
let content;
|
|
7748
|
+
this.createValidator({
|
|
7749
|
+
required,
|
|
7750
|
+
column
|
|
7751
|
+
});
|
|
7752
|
+
const fn = fullname.join('.');
|
|
7753
|
+
const onChange = inputValue => {
|
|
7754
|
+
const targetValue = inputValue?.target?.value ?? inputValue;
|
|
7755
|
+
// po('===Form onChange===',targetValue)
|
|
7756
|
+
try {
|
|
7757
|
+
parentValue[name] = targetValue;
|
|
7758
|
+
this.setValue({
|
|
7759
|
+
...this.getValue()
|
|
7760
|
+
});
|
|
7761
|
+
} catch (e) {
|
|
7762
|
+
const _value = this.getValue() ?? {};
|
|
7763
|
+
checkMap(name, targetValue, _value, [...parentName]);
|
|
7764
|
+
this.setValue(_value);
|
|
7765
|
+
}
|
|
7766
|
+
if (this.getValidateValue()[fn]) this.#exeValidateConfig(this.getValidateValue()[fn], targetValue, this.getValue());
|
|
7767
|
+
};
|
|
7768
|
+
const _parentName = [...parentName];
|
|
7769
|
+
if (name !== undefined) {
|
|
7770
|
+
_parentName.push(name);
|
|
7771
|
+
}
|
|
7772
|
+
if (type) {
|
|
7773
|
+
const typeStyle = flexType(_typeStyle, this, null);
|
|
7774
|
+
content = /*#__PURE__*/React.createElement(StyledColumnValue, {
|
|
7775
|
+
className: 'jr-column-value',
|
|
7776
|
+
style: {
|
|
7777
|
+
gridColumn: label == null ? 'span 2' : null
|
|
7778
|
+
}
|
|
7779
|
+
}, /*#__PURE__*/React.createElement(type, {
|
|
7780
|
+
value: value,
|
|
7781
|
+
onChange,
|
|
7782
|
+
record: parentValue,
|
|
7783
|
+
style: {
|
|
7784
|
+
width: '100%',
|
|
7785
|
+
...typeStyle
|
|
7786
|
+
},
|
|
7787
|
+
...column
|
|
7788
|
+
}));
|
|
7789
|
+
} else if (column.columns) {
|
|
7790
|
+
content = /*#__PURE__*/React.createElement(StyledGrid, {
|
|
7791
|
+
cols: column.cols,
|
|
7792
|
+
className: 'jr-grid',
|
|
7793
|
+
$gap: gap
|
|
7794
|
+
}, this.createColumns(value, column.columns, _parentName, fullname));
|
|
7795
|
+
} else if (name || column.render) {
|
|
7796
|
+
content = /*#__PURE__*/React.createElement(StyledColumnValue, {
|
|
7797
|
+
className: 'jr-column-value',
|
|
7798
|
+
style: {
|
|
7799
|
+
gridColumn: label == null ? 'span 2' : null,
|
|
7800
|
+
padding: column.render ? '4px 0' : null
|
|
7801
|
+
}
|
|
7802
|
+
}, column.render ? column.render.bind(this)({
|
|
7803
|
+
onChange,
|
|
7804
|
+
value: value,
|
|
7805
|
+
record: this.getValue()
|
|
7806
|
+
}) : typeof value === 'object' ? JSON.stringify(value) : value);
|
|
7807
|
+
}
|
|
7808
|
+
const layout = column.labelProps?.layout === undefined ? this.props.labelProps?.layout : column.labelProps?.layout;
|
|
7809
|
+
return /*#__PURE__*/React.createElement(StyledColumn, {
|
|
7810
|
+
$layout: layout,
|
|
7811
|
+
$hasLabel: label != null,
|
|
7812
|
+
key: `f${index}`,
|
|
7813
|
+
style: _style,
|
|
7814
|
+
className: 'jr-column',
|
|
7815
|
+
$labelWidth: column.labelProps?.width ?? this.props.labelProps?.width ?? '120px',
|
|
7816
|
+
$valueWidth: column.valueProps?.width ?? this.props.valueProps?.width ?? '1fr'
|
|
7817
|
+
}, label != null && /*#__PURE__*/React.createElement(StyledColumnLabel, {
|
|
7818
|
+
$required: required,
|
|
7819
|
+
className: 'label',
|
|
7820
|
+
$layout: layout,
|
|
7821
|
+
$colon: column.labelProps?.colon === undefined ? this.colon : column.labelProps?.colon
|
|
7822
|
+
}, label), content, this.props.debugMode && /*#__PURE__*/React.createElement(StyledColumnFooter, null, /*#__PURE__*/React.createElement("div", {
|
|
7823
|
+
className: "left"
|
|
7824
|
+
}, /*#__PURE__*/React.createElement(ColumnMessage, {
|
|
7825
|
+
value: this.getValidateValue(_parentName.join('.')),
|
|
7826
|
+
record: this.getValue()
|
|
7827
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
7828
|
+
className: "right"
|
|
7829
|
+
}))
|
|
7830
|
+
// validateValue?.[name]!==undefined && <StyledColumnFooter $layout={layout}>
|
|
7831
|
+
// {/* {validateValue?.[name]?.$message} */}
|
|
7832
|
+
// <ColumnMessage value={validateValue?.[name]}/>
|
|
7833
|
+
// </StyledColumnFooter>
|
|
7834
|
+
);
|
|
7835
|
+
}
|
|
7836
|
+
createColumns(parentValue, columns, parentName, fullname) {
|
|
7837
|
+
return columns?.map((column, index) => {
|
|
7838
|
+
return this.createColumn(parentValue, column, index, parentName, column.name ? [...fullname, column.name] : fullname);
|
|
7839
|
+
});
|
|
7840
|
+
}
|
|
7841
|
+
renderMe() {
|
|
7842
|
+
return /*#__PURE__*/React.createElement(StyleJRFields, {
|
|
7843
|
+
className: 'jr-fields'
|
|
7844
|
+
}, /*#__PURE__*/React.createElement(StyledGrid, {
|
|
7845
|
+
cols: this.props.cols,
|
|
7846
|
+
style: this.props.gridStyle,
|
|
7847
|
+
className: 'jr-grid',
|
|
7848
|
+
$gap: this.props.gap
|
|
7849
|
+
}, this.createColumns(this.props.dataSourceName ? this.getValue()?.[this.props.dataSourceName] : this.getValue(), this.props.columns, this.props.dataSourceName ? [this.props.dataSourceName] : [], this.props.dataSourceName ? [this.props.dataSourceName] : [])));
|
|
7850
|
+
}
|
|
7851
|
+
|
|
7852
|
+
// render(){
|
|
7853
|
+
// return this.renderMe()
|
|
7854
|
+
// }
|
|
7855
|
+
}
|
|
7856
|
+
|
|
7422
7857
|
const StyledJRFrame = styled__default["default"].div`
|
|
7423
7858
|
display:flex;
|
|
7424
7859
|
flex:1;
|
|
@@ -7518,6 +7953,7 @@ class JRTestReact extends JRSubmit {
|
|
|
7518
7953
|
}
|
|
7519
7954
|
}
|
|
7520
7955
|
|
|
7956
|
+
exports.JRFields = JRFields;
|
|
7521
7957
|
exports.JRFrame = JRFrame;
|
|
7522
7958
|
exports.JRSubmit = JRSubmit;
|
|
7523
7959
|
exports.JRTable = JRTable;
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import JRSubmit from './components/JRSubmit'
|
|
2
2
|
import JRFrame from './components/JRFrame/JRFrame'
|
|
3
3
|
import JRTable from './components/JRTable/JRTable'
|
|
4
|
+
import JRFields from './components/JRFields/JRFields'
|
|
4
5
|
import JRTestReact from './components/JRTest'
|
|
5
6
|
export {
|
|
6
7
|
JRTestReact
|
|
7
|
-
,JRSubmit,JRFrame,JRTable
|
|
8
|
+
,JRSubmit,JRFrame,JRTable,JRFields
|
|
8
9
|
}
|