jrs-react 1.2.3 → 1.2.5

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
@@ -7086,7 +7086,7 @@ const StyledJRTable = styled.div`
7086
7086
 
7087
7087
  th{
7088
7088
  position: relative;
7089
- height:32px;
7089
+ height:24px;
7090
7090
  padding: 4px;
7091
7091
  background: linear-gradient(180deg, rgba(227, 227, 226, 1) 0%, rgba(255, 255, 255, 1) 25%, rgba(210, 210, 210, 1) 100%);
7092
7092
  box-shadow: 2px 2px 2px 0 #ffffffd6 inset, -1px -1px 2px 0px #8a847dbf inset;
@@ -7411,6 +7411,432 @@ class JRTable extends JRFrame {
7411
7411
  }
7412
7412
  }
7413
7413
 
7414
+ const StyleJRFields = styled.main`
7415
+ --column-bd-color:#cccccc;
7416
+ --column-b-color:unset;
7417
+ --column-b-hover-color:#ffffff;
7418
+
7419
+ flex-direction: column;
7420
+ flex:1;
7421
+ overflow: overlay;
7422
+
7423
+ color:#525252;
7424
+
7425
+ >.jr-grid{
7426
+ .jr-column{
7427
+ > .label{
7428
+ color:#525252;
7429
+ text-wrap: nowrap;
7430
+ padding: 3px 8px;
7431
+ font-weight: bold;
7432
+ }
7433
+ > .jr-column-value{
7434
+ }
7435
+ }
7436
+ }
7437
+ `;
7438
+
7439
+ function checkMap(_name, inputValue, mapValue, nameList) {
7440
+ if (nameList.length) {
7441
+ const name = nameList.shift();
7442
+ if (typeof mapValue[name] != 'object') {
7443
+ mapValue[name] = {};
7444
+ }
7445
+ checkMap(_name, inputValue, mapValue[name], nameList);
7446
+ } else {
7447
+ mapValue[_name] = inputValue;
7448
+ }
7449
+ }
7450
+ styled.div`
7451
+ overflow: auto;
7452
+ flex:1;
7453
+ `;
7454
+ const StyledGrid = styled.div`
7455
+ display: grid;
7456
+ grid: ${({
7457
+ grid,
7458
+ cols,
7459
+ children
7460
+ }) => grid ? grid : `auto / ${Array(cols ?? 1).fill().map(() => "1fr").join(" ")}`};
7461
+
7462
+ gap: ${({
7463
+ $gap
7464
+ }) => $gap};
7465
+ `;
7466
+ styled.div`
7467
+ `;
7468
+ const StyledColumn = styled.div`
7469
+ flex:1;
7470
+ display: grid;
7471
+
7472
+ ${({
7473
+ $layout,
7474
+ $labelWidth,
7475
+ $hasLabel,
7476
+ $valueWidth
7477
+ }) => {
7478
+ if ($layout == 'v') {
7479
+ return `grid: auto 1fr / 1fr;`;
7480
+ } else {
7481
+ return `grid: 1fr / ${$hasLabel ? $labelWidth : ''} ${$valueWidth};`;
7482
+ }
7483
+ }}
7484
+ `;
7485
+ const StyledColumnLabel = styled.label`
7486
+ ${({
7487
+ $layout
7488
+ }) => {
7489
+ if ($layout == 'v') {
7490
+ return `text-align: start;`;
7491
+ } else {
7492
+ return `text-align: end;`;
7493
+ }
7494
+ }}
7495
+
7496
+ ${({
7497
+ $required
7498
+ }) => {
7499
+ if ($required !== undefined && $required) return `
7500
+ &:not(:empty)::before{
7501
+ padding-right:4px;
7502
+ color:red;
7503
+ content:'*';
7504
+ }
7505
+ `;
7506
+ }}
7507
+
7508
+ ${({
7509
+ $colon
7510
+ }) => {
7511
+ if ($colon) {
7512
+ return `
7513
+ &:not(:empty)::after{
7514
+ content:'${$colon}';
7515
+ }
7516
+ `;
7517
+ }
7518
+ }}
7519
+
7520
+ `;
7521
+ const StyledColumnValue = styled.main`
7522
+ flex:1;
7523
+ Xdisplay:flex;
7524
+ flex-direction: column;
7525
+ overflow: hidden;
7526
+
7527
+ text-align: start;
7528
+ ${({
7529
+ $validateValue
7530
+ }) => {
7531
+ if ($validateValue != null) {
7532
+ return `
7533
+ > * {
7534
+ xborder:1px solid red;
7535
+ }
7536
+ `;
7537
+ }
7538
+ }}
7539
+ `;
7540
+
7541
+ // String.prototype.valueString = function (value = {}) {
7542
+ // return Array.from(new Set(this.match(/[^{}]+(?=})/g))).reduce((aco, name) => {
7543
+ // return aco.replace(new RegExp(`\\{${name}\\}`, "g"), value[name] ?? `{${name}}`);
7544
+ // }, String(this));
7545
+ // };
7546
+
7547
+ const valueString = (str = '', value = {}) => {
7548
+ return Array.from(new Set(str.match(/[^{}]+(?=})/g))).reduce((aco, name) => {
7549
+ return aco.replace(new RegExp(`\\{${name}\\}`, "g"), value?.[name] ?? `{${name}}`);
7550
+ }, String(str));
7551
+ };
7552
+ const ColumnMessage = ({
7553
+ value = {},
7554
+ record
7555
+ }) => {
7556
+ if (value.isValid === false) {
7557
+ return valueString(value.msg, record);
7558
+ }
7559
+ };
7560
+ const StyledColumnFooter = styled.div`
7561
+ &:empty{
7562
+ display: none;
7563
+ }
7564
+ ${({
7565
+ $layout
7566
+ }) => {
7567
+ if ($layout == 'v') {
7568
+ return ``;
7569
+ } else {
7570
+ return `grid-column-start:2;`;
7571
+ }
7572
+ }}
7573
+ height:25px;
7574
+ color:#ff6060;
7575
+
7576
+ display: flex;
7577
+ justify-content: space-between;
7578
+
7579
+ .left:{
7580
+ xflex:1;
7581
+ }
7582
+ .right{
7583
+ color:gray;
7584
+ xflex:1;
7585
+ }
7586
+ `;
7587
+ function requiredValidator({
7588
+ value
7589
+ }) {
7590
+ if (value == null || value == '') {
7591
+ return {
7592
+ msg: this.msg ?? 'This is required'
7593
+ };
7594
+ }
7595
+ }
7596
+ class JRFields extends JRFrame {
7597
+ UNSAFE_componentWillMount() {
7598
+ this.#initValidateValue();
7599
+ }
7600
+ reset() {
7601
+ this.clearValidateValue();
7602
+ super.reset();
7603
+ }
7604
+ setValue(value, reset) {
7605
+ super.setValue(value, reset);
7606
+ if (reset) {
7607
+ this.clearValidateValue();
7608
+ }
7609
+ }
7610
+ //-----------------------------------------------------------------------------------
7611
+ #findValidator(acc, fullname, {
7612
+ required,
7613
+ ...column
7614
+ }) {
7615
+ const _required = required;
7616
+ if (required == true || required?.value) {
7617
+ acc[fullname] = {
7618
+ isValid: null,
7619
+ validators: [requiredValidator.bind(_required)]
7620
+ };
7621
+ }
7622
+ }
7623
+ #loopColumnsForValidateValue(no, _fullnameList, columns, tab, result) {
7624
+ const validateValue = columns?.reduce((acc, {
7625
+ name,
7626
+ type,
7627
+ columns,
7628
+ ...column
7629
+ }, index) => {
7630
+ no += 1;
7631
+ const fullnameList = name ? [..._fullnameList, name] : _fullnameList;
7632
+ const fullname = fullnameList.join('.');
7633
+ this.#findValidator(acc, fullname, column);
7634
+ if (type == null && columns) {
7635
+ this.#loopColumnsForValidateValue(no, fullnameList, columns, `${tab}\t`, result);
7636
+ }
7637
+ return acc;
7638
+ }, result);
7639
+ return validateValue;
7640
+ }
7641
+ clearValidateValue() {
7642
+ Object.values(this.getValidateValue()).forEach(v => v.isValid = null);
7643
+ }
7644
+ #initValidateValue() {
7645
+ const columns = this.getColumns();
7646
+ const validateValue = this.#loopColumnsForValidateValue(0, this.props.dataSourceName ? [this.props.dataSourceName] : [], columns, '', {});
7647
+ this.setState({
7648
+ validateValue
7649
+ });
7650
+ }
7651
+ #exeValidateConfig(validateConfig, value, record) {
7652
+ validateConfig.isValid = true;
7653
+ for (var i = 0; i < validateConfig.validators.length; i++) {
7654
+ const result = validateConfig.validators[i]({
7655
+ value,
7656
+ record
7657
+ });
7658
+ if (result) {
7659
+ validateConfig.isValid = false;
7660
+ validateConfig.msg = result.msg;
7661
+ break;
7662
+ }
7663
+ }
7664
+ }
7665
+ validateFields() {
7666
+ console.clear();
7667
+ Object.entries(this.getValidateValue()).filter(([fullname, validateConfig]) => validateConfig.isValid != true).forEach(([fullname, validateConfig]) => {
7668
+ this.#exeValidateConfig(validateConfig, this.getValue(fullname), this.getValue());
7669
+ });
7670
+ this.setState({
7671
+ validateValue: this.getValidateValue()
7672
+ });
7673
+ }
7674
+ get validateValueFrom() {
7675
+ return this.props.validateValue === undefined ? 'state' : 'props';
7676
+ }
7677
+ getValidateValue(fullname) {
7678
+ if (fullname === undefined) {
7679
+ return this[this.validateValueFrom]?.validateValue;
7680
+ } else {
7681
+ return this[this.validateValueFrom]?.validateValue?.[fullname];
7682
+ }
7683
+ }
7684
+ setValidateValue(validateValue) {
7685
+ if (this.props.setValidateValue) {
7686
+ this.props.setValidateValue(validateValue);
7687
+ } else {
7688
+ this.setState({
7689
+ validateValue
7690
+ });
7691
+ }
7692
+ }
7693
+ createValidator({
7694
+ required
7695
+ }) {
7696
+ const validators = [];
7697
+ if (required === true && required.value) {
7698
+ validators.push(requiredValidator);
7699
+ }
7700
+ return validators;
7701
+ }
7702
+ //--------------------------------------------------------------------------------------
7703
+ get columnsFrom() {
7704
+ return this.props.initColumns !== undefined ? 'state' : 'props';
7705
+ }
7706
+ getColumns() {
7707
+ return this[this.columnsFrom]?.columns;
7708
+ }
7709
+ //-------------------------------------------------------------------------------------------
7710
+
7711
+ get colon() {
7712
+ return this.props.labelProps?.colon === undefined ? ':' : this.props.labelProps?.colon;
7713
+ }
7714
+ createColumn(parentValue, {
7715
+ type,
7716
+ name,
7717
+ colSpan,
7718
+ rowSpan,
7719
+ style,
7720
+ typeStyle: _typeStyle,
7721
+ required,
7722
+ ...column
7723
+ }, index, parentName, fullname) {
7724
+ const value = name ? parentValue?.[name] : parentValue;
7725
+ const gap = column.gap ?? this.props.gap;
7726
+ const label = column.label;
7727
+ const _style = flexType(style, this, {}, {});
7728
+ if (colSpan) _style.gridColumn = `span ${colSpan}`;
7729
+ if (rowSpan) _style.gridRow = `span ${rowSpan}`;
7730
+ let content;
7731
+ this.createValidator({
7732
+ required,
7733
+ column
7734
+ });
7735
+ const fn = fullname.join('.');
7736
+ const onChange = inputValue => {
7737
+ const targetValue = inputValue?.target?.value ?? inputValue;
7738
+ try {
7739
+ parentValue[name] = targetValue;
7740
+ this.setValue({
7741
+ ...this.getValue()
7742
+ });
7743
+ } catch (e) {
7744
+ const _value = this.getValue() ?? {};
7745
+ checkMap(name, targetValue, _value, [...parentName]);
7746
+ this.setValue(_value);
7747
+ }
7748
+ if (this.getValidateValue()[fn]) this.#exeValidateConfig(this.getValidateValue()[fn], targetValue, this.getValue());
7749
+ };
7750
+ const _parentName = [...parentName];
7751
+ if (name !== undefined) {
7752
+ _parentName.push(name);
7753
+ }
7754
+ if (type) {
7755
+ const typeStyle = flexType(_typeStyle, this, null);
7756
+ content = /*#__PURE__*/React.createElement(StyledColumnValue, {
7757
+ className: 'jr-column-value',
7758
+ style: {
7759
+ gridColumn: label == null ? 'span 2' : null
7760
+ }
7761
+ }, /*#__PURE__*/React.createElement(type, {
7762
+ value: value,
7763
+ onChange,
7764
+ record: parentValue,
7765
+ style: {
7766
+ width: '100%',
7767
+ ...typeStyle
7768
+ },
7769
+ ...column
7770
+ }));
7771
+ } else if (column.columns) {
7772
+ content = /*#__PURE__*/React.createElement(StyledGrid, {
7773
+ cols: column.cols,
7774
+ className: 'jr-grid',
7775
+ $gap: gap
7776
+ }, this.createColumns(value, column.columns, _parentName, fullname));
7777
+ } else if (name || column.render) {
7778
+ content = /*#__PURE__*/React.createElement(StyledColumnValue, {
7779
+ className: 'jr-column-value',
7780
+ style: {
7781
+ gridColumn: label == null ? 'span 2' : null,
7782
+ padding: column.render ? '4px 0' : null
7783
+ }
7784
+ }, column.render ? column.render.bind(this)({
7785
+ onChange,
7786
+ value: value,
7787
+ record: this.getValue()
7788
+ }) : typeof value === 'object' ? JSON.stringify(value) : value);
7789
+ }
7790
+ const layout = column.labelProps?.layout === undefined ? this.props.labelProps?.layout : column.labelProps?.layout;
7791
+ return /*#__PURE__*/React.createElement(StyledColumn, {
7792
+ $layout: layout,
7793
+ $hasLabel: label != null,
7794
+ key: `f${index}`,
7795
+ style: _style,
7796
+ className: 'jr-column',
7797
+ $labelWidth: column.labelProps?.width ?? this.props.labelProps?.width ?? '120px',
7798
+ $valueWidth: column.valueProps?.width ?? this.props.valueProps?.width ?? '1fr'
7799
+ }, label != null && /*#__PURE__*/React.createElement(StyledColumnLabel, {
7800
+ $required: required,
7801
+ className: 'label',
7802
+ $layout: layout,
7803
+ $colon: column.labelProps?.colon === undefined ? this.colon : column.labelProps?.colon
7804
+ }, label), content, this.props.debugMode && /*#__PURE__*/React.createElement(StyledColumnFooter, null, /*#__PURE__*/React.createElement("div", {
7805
+ className: "left"
7806
+ }, /*#__PURE__*/React.createElement(ColumnMessage, {
7807
+ value: this.getValidateValue(_parentName.join('.')),
7808
+ record: this.getValue()
7809
+ })), /*#__PURE__*/React.createElement("div", {
7810
+ className: "right"
7811
+ }))
7812
+ // validateValue?.[name]!==undefined && <StyledColumnFooter $layout={layout}>
7813
+ // {/* {validateValue?.[name]?.$message} */}
7814
+ // <ColumnMessage value={validateValue?.[name]}/>
7815
+ // </StyledColumnFooter>
7816
+ );
7817
+ }
7818
+ createColumns(parentValue, columns, parentName, fullname) {
7819
+ return columns?.map((column, index) => {
7820
+ return this.createColumn(parentValue, column, index, parentName, column.name ? [...fullname, column.name] : fullname);
7821
+ });
7822
+ }
7823
+ renderMe() {
7824
+ return /*#__PURE__*/React.createElement(StyleJRFields, {
7825
+ className: 'jr-fields',
7826
+ style: this.props.typeStyle
7827
+ }, /*#__PURE__*/React.createElement(StyledGrid, {
7828
+ cols: this.props.cols,
7829
+ style: this.props.gridStyle,
7830
+ className: 'jr-grid',
7831
+ $gap: this.props.gap ?? '8px'
7832
+ }, 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] : [])));
7833
+ }
7834
+
7835
+ // render(){
7836
+ // return this.renderMe()
7837
+ // }
7838
+ }
7839
+
7414
7840
  const StyledJRFrame = styled.div`
7415
7841
  display:flex;
7416
7842
  flex:1;
@@ -7510,4 +7936,4 @@ class JRTestReact extends JRSubmit {
7510
7936
  }
7511
7937
  }
7512
7938
 
7513
- export { JRFrame, JRSubmit, JRTable, JRTestReact };
7939
+ export { JRFields, JRFrame, JRSubmit, JRTable, JRTestReact };
package/build/index.js CHANGED
@@ -7094,7 +7094,7 @@ const StyledJRTable = styled__default["default"].div`
7094
7094
 
7095
7095
  th{
7096
7096
  position: relative;
7097
- height:32px;
7097
+ height:24px;
7098
7098
  padding: 4px;
7099
7099
  background: linear-gradient(180deg, rgba(227, 227, 226, 1) 0%, rgba(255, 255, 255, 1) 25%, rgba(210, 210, 210, 1) 100%);
7100
7100
  box-shadow: 2px 2px 2px 0 #ffffffd6 inset, -1px -1px 2px 0px #8a847dbf inset;
@@ -7419,6 +7419,432 @@ 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:unset;
7425
+ --column-b-hover-color:#ffffff;
7426
+
7427
+ flex-direction: column;
7428
+ flex:1;
7429
+ overflow: overlay;
7430
+
7431
+ color:#525252;
7432
+
7433
+ >.jr-grid{
7434
+ .jr-column{
7435
+ > .label{
7436
+ color:#525252;
7437
+ text-wrap: nowrap;
7438
+ padding: 3px 8px;
7439
+ font-weight: bold;
7440
+ }
7441
+ > .jr-column-value{
7442
+ }
7443
+ }
7444
+ }
7445
+ `;
7446
+
7447
+ function checkMap(_name, inputValue, mapValue, nameList) {
7448
+ if (nameList.length) {
7449
+ const name = nameList.shift();
7450
+ if (typeof mapValue[name] != 'object') {
7451
+ mapValue[name] = {};
7452
+ }
7453
+ checkMap(_name, inputValue, mapValue[name], nameList);
7454
+ } else {
7455
+ mapValue[_name] = inputValue;
7456
+ }
7457
+ }
7458
+ styled__default["default"].div`
7459
+ overflow: auto;
7460
+ flex:1;
7461
+ `;
7462
+ const StyledGrid = styled__default["default"].div`
7463
+ display: grid;
7464
+ grid: ${({
7465
+ grid,
7466
+ cols,
7467
+ children
7468
+ }) => grid ? grid : `auto / ${Array(cols ?? 1).fill().map(() => "1fr").join(" ")}`};
7469
+
7470
+ gap: ${({
7471
+ $gap
7472
+ }) => $gap};
7473
+ `;
7474
+ styled__default["default"].div`
7475
+ `;
7476
+ const StyledColumn = styled__default["default"].div`
7477
+ flex:1;
7478
+ display: grid;
7479
+
7480
+ ${({
7481
+ $layout,
7482
+ $labelWidth,
7483
+ $hasLabel,
7484
+ $valueWidth
7485
+ }) => {
7486
+ if ($layout == 'v') {
7487
+ return `grid: auto 1fr / 1fr;`;
7488
+ } else {
7489
+ return `grid: 1fr / ${$hasLabel ? $labelWidth : ''} ${$valueWidth};`;
7490
+ }
7491
+ }}
7492
+ `;
7493
+ const StyledColumnLabel = styled__default["default"].label`
7494
+ ${({
7495
+ $layout
7496
+ }) => {
7497
+ if ($layout == 'v') {
7498
+ return `text-align: start;`;
7499
+ } else {
7500
+ return `text-align: end;`;
7501
+ }
7502
+ }}
7503
+
7504
+ ${({
7505
+ $required
7506
+ }) => {
7507
+ if ($required !== undefined && $required) return `
7508
+ &:not(:empty)::before{
7509
+ padding-right:4px;
7510
+ color:red;
7511
+ content:'*';
7512
+ }
7513
+ `;
7514
+ }}
7515
+
7516
+ ${({
7517
+ $colon
7518
+ }) => {
7519
+ if ($colon) {
7520
+ return `
7521
+ &:not(:empty)::after{
7522
+ content:'${$colon}';
7523
+ }
7524
+ `;
7525
+ }
7526
+ }}
7527
+
7528
+ `;
7529
+ const StyledColumnValue = styled__default["default"].main`
7530
+ flex:1;
7531
+ Xdisplay:flex;
7532
+ flex-direction: column;
7533
+ overflow: hidden;
7534
+
7535
+ text-align: start;
7536
+ ${({
7537
+ $validateValue
7538
+ }) => {
7539
+ if ($validateValue != null) {
7540
+ return `
7541
+ > * {
7542
+ xborder:1px solid red;
7543
+ }
7544
+ `;
7545
+ }
7546
+ }}
7547
+ `;
7548
+
7549
+ // String.prototype.valueString = function (value = {}) {
7550
+ // return Array.from(new Set(this.match(/[^{}]+(?=})/g))).reduce((aco, name) => {
7551
+ // return aco.replace(new RegExp(`\\{${name}\\}`, "g"), value[name] ?? `{${name}}`);
7552
+ // }, String(this));
7553
+ // };
7554
+
7555
+ const valueString = (str = '', value = {}) => {
7556
+ return Array.from(new Set(str.match(/[^{}]+(?=})/g))).reduce((aco, name) => {
7557
+ return aco.replace(new RegExp(`\\{${name}\\}`, "g"), value?.[name] ?? `{${name}}`);
7558
+ }, String(str));
7559
+ };
7560
+ const ColumnMessage = ({
7561
+ value = {},
7562
+ record
7563
+ }) => {
7564
+ if (value.isValid === false) {
7565
+ return valueString(value.msg, record);
7566
+ }
7567
+ };
7568
+ const StyledColumnFooter = styled__default["default"].div`
7569
+ &:empty{
7570
+ display: none;
7571
+ }
7572
+ ${({
7573
+ $layout
7574
+ }) => {
7575
+ if ($layout == 'v') {
7576
+ return ``;
7577
+ } else {
7578
+ return `grid-column-start:2;`;
7579
+ }
7580
+ }}
7581
+ height:25px;
7582
+ color:#ff6060;
7583
+
7584
+ display: flex;
7585
+ justify-content: space-between;
7586
+
7587
+ .left:{
7588
+ xflex:1;
7589
+ }
7590
+ .right{
7591
+ color:gray;
7592
+ xflex:1;
7593
+ }
7594
+ `;
7595
+ function requiredValidator({
7596
+ value
7597
+ }) {
7598
+ if (value == null || value == '') {
7599
+ return {
7600
+ msg: this.msg ?? 'This is required'
7601
+ };
7602
+ }
7603
+ }
7604
+ class JRFields extends JRFrame {
7605
+ UNSAFE_componentWillMount() {
7606
+ this.#initValidateValue();
7607
+ }
7608
+ reset() {
7609
+ this.clearValidateValue();
7610
+ super.reset();
7611
+ }
7612
+ setValue(value, reset) {
7613
+ super.setValue(value, reset);
7614
+ if (reset) {
7615
+ this.clearValidateValue();
7616
+ }
7617
+ }
7618
+ //-----------------------------------------------------------------------------------
7619
+ #findValidator(acc, fullname, {
7620
+ required,
7621
+ ...column
7622
+ }) {
7623
+ const _required = required;
7624
+ if (required == true || required?.value) {
7625
+ acc[fullname] = {
7626
+ isValid: null,
7627
+ validators: [requiredValidator.bind(_required)]
7628
+ };
7629
+ }
7630
+ }
7631
+ #loopColumnsForValidateValue(no, _fullnameList, columns, tab, result) {
7632
+ const validateValue = columns?.reduce((acc, {
7633
+ name,
7634
+ type,
7635
+ columns,
7636
+ ...column
7637
+ }, index) => {
7638
+ no += 1;
7639
+ const fullnameList = name ? [..._fullnameList, name] : _fullnameList;
7640
+ const fullname = fullnameList.join('.');
7641
+ this.#findValidator(acc, fullname, column);
7642
+ if (type == null && columns) {
7643
+ this.#loopColumnsForValidateValue(no, fullnameList, columns, `${tab}\t`, result);
7644
+ }
7645
+ return acc;
7646
+ }, result);
7647
+ return validateValue;
7648
+ }
7649
+ clearValidateValue() {
7650
+ Object.values(this.getValidateValue()).forEach(v => v.isValid = null);
7651
+ }
7652
+ #initValidateValue() {
7653
+ const columns = this.getColumns();
7654
+ const validateValue = this.#loopColumnsForValidateValue(0, this.props.dataSourceName ? [this.props.dataSourceName] : [], columns, '', {});
7655
+ this.setState({
7656
+ validateValue
7657
+ });
7658
+ }
7659
+ #exeValidateConfig(validateConfig, value, record) {
7660
+ validateConfig.isValid = true;
7661
+ for (var i = 0; i < validateConfig.validators.length; i++) {
7662
+ const result = validateConfig.validators[i]({
7663
+ value,
7664
+ record
7665
+ });
7666
+ if (result) {
7667
+ validateConfig.isValid = false;
7668
+ validateConfig.msg = result.msg;
7669
+ break;
7670
+ }
7671
+ }
7672
+ }
7673
+ validateFields() {
7674
+ console.clear();
7675
+ Object.entries(this.getValidateValue()).filter(([fullname, validateConfig]) => validateConfig.isValid != true).forEach(([fullname, validateConfig]) => {
7676
+ this.#exeValidateConfig(validateConfig, this.getValue(fullname), this.getValue());
7677
+ });
7678
+ this.setState({
7679
+ validateValue: this.getValidateValue()
7680
+ });
7681
+ }
7682
+ get validateValueFrom() {
7683
+ return this.props.validateValue === undefined ? 'state' : 'props';
7684
+ }
7685
+ getValidateValue(fullname) {
7686
+ if (fullname === undefined) {
7687
+ return this[this.validateValueFrom]?.validateValue;
7688
+ } else {
7689
+ return this[this.validateValueFrom]?.validateValue?.[fullname];
7690
+ }
7691
+ }
7692
+ setValidateValue(validateValue) {
7693
+ if (this.props.setValidateValue) {
7694
+ this.props.setValidateValue(validateValue);
7695
+ } else {
7696
+ this.setState({
7697
+ validateValue
7698
+ });
7699
+ }
7700
+ }
7701
+ createValidator({
7702
+ required
7703
+ }) {
7704
+ const validators = [];
7705
+ if (required === true && required.value) {
7706
+ validators.push(requiredValidator);
7707
+ }
7708
+ return validators;
7709
+ }
7710
+ //--------------------------------------------------------------------------------------
7711
+ get columnsFrom() {
7712
+ return this.props.initColumns !== undefined ? 'state' : 'props';
7713
+ }
7714
+ getColumns() {
7715
+ return this[this.columnsFrom]?.columns;
7716
+ }
7717
+ //-------------------------------------------------------------------------------------------
7718
+
7719
+ get colon() {
7720
+ return this.props.labelProps?.colon === undefined ? ':' : this.props.labelProps?.colon;
7721
+ }
7722
+ createColumn(parentValue, {
7723
+ type,
7724
+ name,
7725
+ colSpan,
7726
+ rowSpan,
7727
+ style,
7728
+ typeStyle: _typeStyle,
7729
+ required,
7730
+ ...column
7731
+ }, index, parentName, fullname) {
7732
+ const value = name ? parentValue?.[name] : parentValue;
7733
+ const gap = column.gap ?? this.props.gap;
7734
+ const label = column.label;
7735
+ const _style = flexType(style, this, {}, {});
7736
+ if (colSpan) _style.gridColumn = `span ${colSpan}`;
7737
+ if (rowSpan) _style.gridRow = `span ${rowSpan}`;
7738
+ let content;
7739
+ this.createValidator({
7740
+ required,
7741
+ column
7742
+ });
7743
+ const fn = fullname.join('.');
7744
+ const onChange = inputValue => {
7745
+ const targetValue = inputValue?.target?.value ?? inputValue;
7746
+ try {
7747
+ parentValue[name] = targetValue;
7748
+ this.setValue({
7749
+ ...this.getValue()
7750
+ });
7751
+ } catch (e) {
7752
+ const _value = this.getValue() ?? {};
7753
+ checkMap(name, targetValue, _value, [...parentName]);
7754
+ this.setValue(_value);
7755
+ }
7756
+ if (this.getValidateValue()[fn]) this.#exeValidateConfig(this.getValidateValue()[fn], targetValue, this.getValue());
7757
+ };
7758
+ const _parentName = [...parentName];
7759
+ if (name !== undefined) {
7760
+ _parentName.push(name);
7761
+ }
7762
+ if (type) {
7763
+ const typeStyle = flexType(_typeStyle, this, null);
7764
+ content = /*#__PURE__*/React.createElement(StyledColumnValue, {
7765
+ className: 'jr-column-value',
7766
+ style: {
7767
+ gridColumn: label == null ? 'span 2' : null
7768
+ }
7769
+ }, /*#__PURE__*/React.createElement(type, {
7770
+ value: value,
7771
+ onChange,
7772
+ record: parentValue,
7773
+ style: {
7774
+ width: '100%',
7775
+ ...typeStyle
7776
+ },
7777
+ ...column
7778
+ }));
7779
+ } else if (column.columns) {
7780
+ content = /*#__PURE__*/React.createElement(StyledGrid, {
7781
+ cols: column.cols,
7782
+ className: 'jr-grid',
7783
+ $gap: gap
7784
+ }, this.createColumns(value, column.columns, _parentName, fullname));
7785
+ } else if (name || column.render) {
7786
+ content = /*#__PURE__*/React.createElement(StyledColumnValue, {
7787
+ className: 'jr-column-value',
7788
+ style: {
7789
+ gridColumn: label == null ? 'span 2' : null,
7790
+ padding: column.render ? '4px 0' : null
7791
+ }
7792
+ }, column.render ? column.render.bind(this)({
7793
+ onChange,
7794
+ value: value,
7795
+ record: this.getValue()
7796
+ }) : typeof value === 'object' ? JSON.stringify(value) : value);
7797
+ }
7798
+ const layout = column.labelProps?.layout === undefined ? this.props.labelProps?.layout : column.labelProps?.layout;
7799
+ return /*#__PURE__*/React.createElement(StyledColumn, {
7800
+ $layout: layout,
7801
+ $hasLabel: label != null,
7802
+ key: `f${index}`,
7803
+ style: _style,
7804
+ className: 'jr-column',
7805
+ $labelWidth: column.labelProps?.width ?? this.props.labelProps?.width ?? '120px',
7806
+ $valueWidth: column.valueProps?.width ?? this.props.valueProps?.width ?? '1fr'
7807
+ }, label != null && /*#__PURE__*/React.createElement(StyledColumnLabel, {
7808
+ $required: required,
7809
+ className: 'label',
7810
+ $layout: layout,
7811
+ $colon: column.labelProps?.colon === undefined ? this.colon : column.labelProps?.colon
7812
+ }, label), content, this.props.debugMode && /*#__PURE__*/React.createElement(StyledColumnFooter, null, /*#__PURE__*/React.createElement("div", {
7813
+ className: "left"
7814
+ }, /*#__PURE__*/React.createElement(ColumnMessage, {
7815
+ value: this.getValidateValue(_parentName.join('.')),
7816
+ record: this.getValue()
7817
+ })), /*#__PURE__*/React.createElement("div", {
7818
+ className: "right"
7819
+ }))
7820
+ // validateValue?.[name]!==undefined && <StyledColumnFooter $layout={layout}>
7821
+ // {/* {validateValue?.[name]?.$message} */}
7822
+ // <ColumnMessage value={validateValue?.[name]}/>
7823
+ // </StyledColumnFooter>
7824
+ );
7825
+ }
7826
+ createColumns(parentValue, columns, parentName, fullname) {
7827
+ return columns?.map((column, index) => {
7828
+ return this.createColumn(parentValue, column, index, parentName, column.name ? [...fullname, column.name] : fullname);
7829
+ });
7830
+ }
7831
+ renderMe() {
7832
+ return /*#__PURE__*/React.createElement(StyleJRFields, {
7833
+ className: 'jr-fields',
7834
+ style: this.props.typeStyle
7835
+ }, /*#__PURE__*/React.createElement(StyledGrid, {
7836
+ cols: this.props.cols,
7837
+ style: this.props.gridStyle,
7838
+ className: 'jr-grid',
7839
+ $gap: this.props.gap ?? '8px'
7840
+ }, 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] : [])));
7841
+ }
7842
+
7843
+ // render(){
7844
+ // return this.renderMe()
7845
+ // }
7846
+ }
7847
+
7422
7848
  const StyledJRFrame = styled__default["default"].div`
7423
7849
  display:flex;
7424
7850
  flex:1;
@@ -7518,6 +7944,7 @@ class JRTestReact extends JRSubmit {
7518
7944
  }
7519
7945
  }
7520
7946
 
7947
+ exports.JRFields = JRFields;
7521
7948
  exports.JRFrame = JRFrame;
7522
7949
  exports.JRSubmit = JRSubmit;
7523
7950
  exports.JRTable = JRTable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jrs-react",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.es.js",
@@ -0,0 +1,7 @@
1
+ {
2
+ "name":"Joren"
3
+ ,"phone":[
4
+ {"no":"0948272834","name":"中華電信"}
5
+ ,{"no":"0987304555","name":"遠傳"}
6
+ ]
7
+ }
@@ -0,0 +1,18 @@
1
+ [
2
+ {
3
+ "name":"Joren"
4
+ ,"address":{
5
+ "no":"23"
6
+ ,"street":"Jalan Indah"
7
+ ,"country":"Malaysia"
8
+ }
9
+ }
10
+ ,{
11
+ "name":"John"
12
+ ,"address":{
13
+ "no":"36"
14
+ ,"street":"景興路"
15
+ ,"country":"台灣"
16
+ }
17
+ }
18
+ ]
@@ -80,8 +80,9 @@ const StyledColumnLabel=styled.label`
80
80
 
81
81
  `
82
82
  const StyledColumnValue=styled.main`
83
- Xflex:1;
83
+ flex:1;
84
84
  Xdisplay:flex;
85
+ flex-direction: column;
85
86
  overflow: hidden;
86
87
 
87
88
  text-align: start;
@@ -186,7 +187,6 @@ export default class JRFields extends JRFrame {
186
187
  no+=1
187
188
  const fullnameList=name?[..._fullnameList,name]:_fullnameList
188
189
  const fullname=fullnameList.join('.')
189
- // po(`${no} - ${tab}fn= ${fullname}`)
190
190
  this.#findValidator(acc,fullname,column)
191
191
  if(type==null&&columns){
192
192
  this.#loopColumnsForValidateValue(no,fullnameList,columns,`${tab}\t`,result)
@@ -264,7 +264,8 @@ export default class JRFields extends JRFrame {
264
264
  createColumn(
265
265
  parentValue
266
266
  ,{
267
- type,name,colSpan,rowSpan,style
267
+ type,name,colSpan,rowSpan
268
+ ,style
268
269
  ,typeStyle:_typeStyle
269
270
  ,required
270
271
  ,...column
@@ -273,9 +274,6 @@ export default class JRFields extends JRFrame {
273
274
  ,parentName
274
275
  ,fullname
275
276
  ){
276
- // po('----------------------------------------')
277
- // po('parentName',parentName)
278
- // po('fullname',fullname)
279
277
  const value=name?parentValue?.[name]:parentValue
280
278
 
281
279
  const gap=column.gap??this.props.gap
@@ -283,7 +281,6 @@ export default class JRFields extends JRFrame {
283
281
  const _style=flexType(style,this,{},{})
284
282
  if (colSpan) _style.gridColumn = `span ${colSpan}`
285
283
  if (rowSpan) _style.gridRow = `span ${rowSpan}`
286
- // Object.assign(_style,style)
287
284
 
288
285
 
289
286
  let content
@@ -293,7 +290,6 @@ export default class JRFields extends JRFrame {
293
290
  const fn=fullname.join('.')
294
291
  const onChange=(inputValue)=>{
295
292
  const targetValue=inputValue?.target?.value ?? inputValue
296
- // po('===Form onChange===',targetValue)
297
293
  try{
298
294
  parentValue[name]=targetValue
299
295
  this.setValue({...this.getValue()})
@@ -403,8 +399,8 @@ export default class JRFields extends JRFrame {
403
399
 
404
400
 
405
401
  renderMe(){
406
- return <StyleJRFields className={'jr-fields'}>
407
- <StyledGrid cols={this.props.cols} style={this.props.gridStyle} className={'jr-grid'} $gap={this.props.gap}>
402
+ return <StyleJRFields className={'jr-fields'} style={this.props.typeStyle}>
403
+ <StyledGrid cols={this.props.cols} style={this.props.gridStyle} className={'jr-grid'} $gap={this.props.gap??'8px'}>
408
404
  {
409
405
  this.createColumns(
410
406
  this.props.dataSourceName?this.getValue()?.[this.props.dataSourceName]:this.getValue()
@@ -2,7 +2,7 @@ import styled from "styled-components";
2
2
 
3
3
  export const StyleJRFields=styled.main`
4
4
  --column-bd-color:#cccccc;
5
- --column-b-color:#eeeeee;
5
+ --column-b-color:unset;
6
6
  --column-b-hover-color:#ffffff;
7
7
 
8
8
  flex-direction: column;
@@ -10,21 +10,17 @@ export const StyleJRFields=styled.main`
10
10
  overflow: overlay;
11
11
 
12
12
  color:#525252;
13
- XXXborder: 1px solid #a0a0a0;
14
- background: var(--column-b-color);
15
13
 
16
14
  >.jr-grid{
17
- background:var(--column-b-color);
18
-
19
15
  .jr-column{
20
- padding: 6px;
21
-
22
- label{
16
+ > .label{
23
17
  color:#525252;
24
18
  text-wrap: nowrap;
25
- padding: 4px 10px 4px 0;
19
+ padding: 3px 8px;
26
20
  font-weight: bold;
27
21
  }
22
+ > .jr-column-value{
23
+ }
28
24
  }
29
25
  }
30
26
  `
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import styled from "styled-components";
3
+
4
+
5
+
6
+ const StyledInput=styled.div`
7
+ display:flex;
8
+ `
9
+ export default class JRInput extends React.Component{
10
+ setValue(value){
11
+ this.props?.onChange?.(value)
12
+ }
13
+ render(){
14
+ return <StyledInput>
15
+ {this.input()}
16
+ </StyledInput>
17
+ }
18
+ }
@@ -1,7 +1,17 @@
1
1
  import React from "react";
2
+ import { po } from "../JRUtils";
3
+ import JRInput from "./JRInput";
2
4
 
3
- export default class JRText extends React.Component{
4
- render(){
5
- return <input value={this.props.value}/>
5
+ export default class JRText extends JRInput{
6
+ input(){
7
+ return <input value={this.props.value}
8
+ style={{
9
+ height: '24px'
10
+ ,width: '100%'
11
+ }}
12
+ onChange={(e)=>{
13
+ this.setValue(e.target.value)
14
+ }}
15
+ />
6
16
  }
7
17
  }
@@ -44,7 +44,7 @@ export const StyledJRTable=styled.div`
44
44
 
45
45
  th{
46
46
  position: relative;
47
- height:32px;
47
+ height:24px;
48
48
  padding: 4px;
49
49
  background: linear-gradient(180deg, rgba(227, 227, 226, 1) 0%, rgba(255, 255, 255, 1) 25%, rgba(210, 210, 210, 1) 100%);
50
50
  box-shadow: 2px 2px 2px 0 #ffffffd6 inset, -1px -1px 2px 0px #8a847dbf inset;
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
  }