@donglegeyu/company-ui 1.2.18 → 1.2.21

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.
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import type { FormInstance } from 'antd';
3
3
  import './index.scss';
4
- export interface FormField {
4
+ export interface FormFieldItem {
5
5
  name: string;
6
6
  label: string;
7
7
  type: 'input' | 'select' | 'textarea' | 'input-number';
@@ -16,6 +16,12 @@ export interface FormField {
16
16
  required?: boolean;
17
17
  rows?: number;
18
18
  }
19
+ export interface FormFieldGroup {
20
+ type: 'compact';
21
+ label: string;
22
+ children: FormFieldItem[];
23
+ }
24
+ export type FormField = FormFieldItem | FormFieldGroup;
19
25
  export interface BaseInfoFormProps {
20
26
  value: Record<string, any>;
21
27
  fields: FormField[];
@@ -68,8 +68,9 @@ var BaseInfoForm = (0, import_react.forwardRef)(({
68
68
  const currentFormValues = form.getFieldsValue();
69
69
  const diff = {};
70
70
  for (const k of Object.keys(value)) {
71
- if (value[k] !== currentFormValues[k]) {
72
- diff[k] = value[k];
71
+ const v = value[k] === "" ? void 0 : value[k];
72
+ if (v !== currentFormValues[k]) {
73
+ diff[k] = v;
73
74
  }
74
75
  }
75
76
  if (Object.keys(diff).length > 0) {
@@ -77,12 +78,19 @@ var BaseInfoForm = (0, import_react.forwardRef)(({
77
78
  }
78
79
  }
79
80
  }, [value, form]);
81
+ const normalizeValue = (val) => {
82
+ const result = {};
83
+ for (const k of Object.keys(val)) {
84
+ result[k] = val[k] === "" ? void 0 : val[k];
85
+ }
86
+ return result;
87
+ };
80
88
  const handleValuesChange = (_changedValues, allValues) => {
81
89
  const key = Object.keys(_changedValues)[0];
82
90
  if (key) {
83
- onFieldChange == null ? void 0 : onFieldChange(key, _changedValues[key]);
91
+ onFieldChange == null ? void 0 : onFieldChange(key, _changedValues[key] === "" ? void 0 : _changedValues[key]);
84
92
  }
85
- onChange == null ? void 0 : onChange(allValues);
93
+ onChange == null ? void 0 : onChange(normalizeValue(allValues));
86
94
  };
87
95
  (0, import_react.useImperativeHandle)(ref, () => ({
88
96
  validate: () => form.validateFields().then(() => true).catch(() => false),
@@ -142,20 +150,34 @@ var BaseInfoForm = (0, import_react.forwardRef)(({
142
150
  import_basic_components.CompanyForm,
143
151
  {
144
152
  form,
145
- initialValues: value,
153
+ initialValues: normalizeValue(value),
146
154
  layout,
147
155
  onValuesChange: handleValuesChange,
148
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Row, { gutter: 24, children: fields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Col, { span: getColSpan(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
149
- import_basic_components.CompanyForm.Item,
150
- {
151
- label: field.label,
152
- name: field.name,
153
- rules: field.rules,
154
- required: field.required,
155
- className: field.type === "textarea" ? "label-top" : void 0,
156
- children: renderField(field)
156
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Row, { gutter: 24, children: fields.map((field, index) => {
157
+ if (field.type === "compact") {
158
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Col, { span: getColSpan(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_basic_components.CompanyForm.Item, { label: field.label, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Space.Compact, { style: { width: "100%" }, children: field.children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
159
+ import_basic_components.CompanyForm.Item,
160
+ {
161
+ name: child.name,
162
+ noStyle: true,
163
+ rules: child.rules,
164
+ children: renderField(child)
165
+ },
166
+ child.name
167
+ )) }) }) }, `compact-${index}`);
157
168
  }
158
- ) }, field.name)) })
169
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Col, { span: getColSpan(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
170
+ import_basic_components.CompanyForm.Item,
171
+ {
172
+ label: field.label,
173
+ name: field.name,
174
+ rules: field.rules,
175
+ required: field.required,
176
+ className: field.type === "textarea" ? "label-top" : void 0,
177
+ children: renderField(field)
178
+ }
179
+ ) }, field.name);
180
+ }) })
159
181
  }
160
182
  )
161
183
  }
@@ -6,7 +6,7 @@ export { default as PageTitle } from "./PageTitle";
6
6
  export { default as FormFooterActions } from "./FormFooterActions";
7
7
  export { default as SectionTitle } from "./SectionTitle";
8
8
  export { default as BaseInfoForm } from "./BaseInfoForm";
9
- export type { FormField, BaseInfoFormProps, BaseInfoFormRef } from "./BaseInfoForm";
9
+ export type { FormField, FormFieldItem, FormFieldGroup, BaseInfoFormProps, BaseInfoFormRef } from "./BaseInfoForm";
10
10
  export { default as ColorScale } from "./ColorScale";
11
11
  export { default as AccessibilityChecker } from "./AccessibilityChecker";
12
12
  export { default as EllipsisText } from "./EllipsisText";
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import type { FormInstance } from 'antd';
3
3
  import './index.scss';
4
- export interface FormField {
4
+ export interface FormFieldItem {
5
5
  name: string;
6
6
  label: string;
7
7
  type: 'input' | 'select' | 'textarea' | 'input-number';
@@ -16,6 +16,12 @@ export interface FormField {
16
16
  required?: boolean;
17
17
  rows?: number;
18
18
  }
19
+ export interface FormFieldGroup {
20
+ type: 'compact';
21
+ label: string;
22
+ children: FormFieldItem[];
23
+ }
24
+ export type FormField = FormFieldItem | FormFieldGroup;
19
25
  export interface BaseInfoFormProps {
20
26
  value: Record<string, any>;
21
27
  fields: FormField[];
@@ -9,7 +9,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
9
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
11
  import { forwardRef, useImperativeHandle, useRef, useEffect, useState } from 'react';
12
- import { Row, Col } from 'antd';
12
+ import { Row, Col, Space } from 'antd';
13
13
  import { CompanyForm, CompanyInput, CompanySelect, CompanyInputNumber } from "../../basic-components";
14
14
  import "./index.scss";
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -59,8 +59,9 @@ var BaseInfoForm = /*#__PURE__*/forwardRef(function (_ref, ref) {
59
59
  var diff = {};
60
60
  for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
61
61
  var k = _Object$keys[_i];
62
- if (value[k] !== currentFormValues[k]) {
63
- diff[k] = value[k];
62
+ var v = value[k] === '' ? undefined : value[k];
63
+ if (v !== currentFormValues[k]) {
64
+ diff[k] = v;
64
65
  }
65
66
  }
66
67
  if (Object.keys(diff).length > 0) {
@@ -68,12 +69,20 @@ var BaseInfoForm = /*#__PURE__*/forwardRef(function (_ref, ref) {
68
69
  }
69
70
  }
70
71
  }, [value, form]);
72
+ var normalizeValue = function normalizeValue(val) {
73
+ var result = {};
74
+ for (var _i2 = 0, _Object$keys2 = Object.keys(val); _i2 < _Object$keys2.length; _i2++) {
75
+ var k = _Object$keys2[_i2];
76
+ result[k] = val[k] === '' ? undefined : val[k];
77
+ }
78
+ return result;
79
+ };
71
80
  var handleValuesChange = function handleValuesChange(_changedValues, allValues) {
72
81
  var key = Object.keys(_changedValues)[0];
73
82
  if (key) {
74
- onFieldChange === null || onFieldChange === void 0 || onFieldChange(key, _changedValues[key]);
83
+ onFieldChange === null || onFieldChange === void 0 || onFieldChange(key, _changedValues[key] === '' ? undefined : _changedValues[key]);
75
84
  }
76
- onChange === null || onChange === void 0 || onChange(allValues);
85
+ onChange === null || onChange === void 0 || onChange(normalizeValue(allValues));
77
86
  };
78
87
  useImperativeHandle(ref, function () {
79
88
  return {
@@ -132,12 +141,33 @@ var BaseInfoForm = /*#__PURE__*/forwardRef(function (_ref, ref) {
132
141
  style: _defineProperty({}, '--company-label-max-width', "".concat(labelMaxWidth, "em")),
133
142
  children: /*#__PURE__*/_jsx(CompanyForm, {
134
143
  form: form,
135
- initialValues: value,
144
+ initialValues: normalizeValue(value),
136
145
  layout: layout,
137
146
  onValuesChange: handleValuesChange,
138
147
  children: /*#__PURE__*/_jsx(Row, {
139
148
  gutter: 24,
140
- children: fields.map(function (field) {
149
+ children: fields.map(function (field, index) {
150
+ if (field.type === 'compact') {
151
+ return /*#__PURE__*/_jsx(Col, {
152
+ span: getColSpan(),
153
+ children: /*#__PURE__*/_jsx(CompanyForm.Item, {
154
+ label: field.label,
155
+ children: /*#__PURE__*/_jsx(Space.Compact, {
156
+ style: {
157
+ width: '100%'
158
+ },
159
+ children: field.children.map(function (child) {
160
+ return /*#__PURE__*/_jsx(CompanyForm.Item, {
161
+ name: child.name,
162
+ noStyle: true,
163
+ rules: child.rules,
164
+ children: renderField(child)
165
+ }, child.name);
166
+ })
167
+ })
168
+ })
169
+ }, "compact-".concat(index));
170
+ }
141
171
  return /*#__PURE__*/_jsx(Col, {
142
172
  span: getColSpan(),
143
173
  children: /*#__PURE__*/_jsx(CompanyForm.Item, {
@@ -6,7 +6,7 @@ export { default as PageTitle } from "./PageTitle";
6
6
  export { default as FormFooterActions } from "./FormFooterActions";
7
7
  export { default as SectionTitle } from "./SectionTitle";
8
8
  export { default as BaseInfoForm } from "./BaseInfoForm";
9
- export type { FormField, BaseInfoFormProps, BaseInfoFormRef } from "./BaseInfoForm";
9
+ export type { FormField, FormFieldItem, FormFieldGroup, BaseInfoFormProps, BaseInfoFormRef } from "./BaseInfoForm";
10
10
  export { default as ColorScale } from "./ColorScale";
11
11
  export { default as AccessibilityChecker } from "./AccessibilityChecker";
12
12
  export { default as EllipsisText } from "./EllipsisText";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@donglegeyu/company-ui",
3
- "version": "1.2.18",
3
+ "version": "1.2.21",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/es/index.js",
6
6
  "types": "dist/es/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "dev": "dumi dev",
19
19
  "build": "father build",
20
20
  "type-check": "tsc --noEmit",
21
- "prepublishOnly": "npm run build"
21
+ "prepublishOnly": "bash scripts/check-clean.sh && npm run build"
22
22
  },
23
23
  "keywords": [
24
24
  "antd",