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.js CHANGED
@@ -6472,18 +6472,6 @@ class JRSubmit extends React.Component {
6472
6472
  const isSuccess = response.status >= 200 && response.status <= 299;
6473
6473
  this.setRes(isSuccess, response, config);
6474
6474
  this.showMessage(isSuccess, isSuccess ? config.successMessage : config.failedMessage);
6475
-
6476
- // if (isSuccess) {
6477
- // if (config.successMessage) {
6478
- // // msg.success({ message:config.successMessage })
6479
- // // alert(config.successMessage)
6480
- // }
6481
- // } else {
6482
- // if (config.failedMessage) {
6483
- // // msg.error({ message:config.failedMessage })
6484
- // // alert(config.failedMessage)
6485
- // }
6486
- // }
6487
6475
  config.callback?.bind(this)(isSuccess, response, payload);
6488
6476
  };
6489
6477
  showMessage(success, message) {
@@ -7431,6 +7419,441 @@ class JRTable extends JRFrame {
7431
7419
  }
7432
7420
  }
7433
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
+
7434
7857
  const StyledJRFrame = styled__default["default"].div`
7435
7858
  display:flex;
7436
7859
  flex:1;
@@ -7530,6 +7953,7 @@ class JRTestReact extends JRSubmit {
7530
7953
  }
7531
7954
  }
7532
7955
 
7956
+ exports.JRFields = JRFields;
7533
7957
  exports.JRFrame = JRFrame;
7534
7958
  exports.JRSubmit = JRSubmit;
7535
7959
  exports.JRTable = JRTable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jrs-react",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.es.js",