jrs-react 1.2.2 → 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 CHANGED
@@ -6464,18 +6464,6 @@ class JRSubmit extends React.Component {
6464
6464
  const isSuccess = response.status >= 200 && response.status <= 299;
6465
6465
  this.setRes(isSuccess, response, config);
6466
6466
  this.showMessage(isSuccess, isSuccess ? config.successMessage : config.failedMessage);
6467
-
6468
- // if (isSuccess) {
6469
- // if (config.successMessage) {
6470
- // // msg.success({ message:config.successMessage })
6471
- // // alert(config.successMessage)
6472
- // }
6473
- // } else {
6474
- // if (config.failedMessage) {
6475
- // // msg.error({ message:config.failedMessage })
6476
- // // alert(config.failedMessage)
6477
- // }
6478
- // }
6479
6467
  config.callback?.bind(this)(isSuccess, response, payload);
6480
6468
  };
6481
6469
  showMessage(success, message) {
@@ -7423,6 +7411,441 @@ class JRTable extends JRFrame {
7423
7411
  }
7424
7412
  }
7425
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
+
7426
7849
  const StyledJRFrame = styled.div`
7427
7850
  display:flex;
7428
7851
  flex:1;
@@ -7522,4 +7945,4 @@ class JRTestReact extends JRSubmit {
7522
7945
  }
7523
7946
  }
7524
7947
 
7525
- export { JRFrame, JRSubmit, JRTable, JRTestReact };
7948
+ export { JRFields, JRFrame, JRSubmit, JRTable, JRTestReact };