@hi-ui/schema-fields 4.0.0-experimental.6 → 4.0.0-experimental.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @hi-ui/schema-fields
2
2
 
3
+ ## 4.0.0-experimental.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 346113bd3: 处理 ProTag 产物丢失问题
8
+
3
9
  ## 4.0.0-experimental.6
4
10
 
5
11
  ### Patch Changes
@@ -1,60 +1,8 @@
1
1
  import React from 'react';
2
2
  import { type TagProps } from '@hi-ui/tag';
3
3
  import { ProField, type ProFieldRenderCtx } from '../../../base';
4
+ import type { ColorPreset, BuiltinColorEnum, SCMColorEnumPreset } from './preset';
4
5
  import './index.scss';
5
- type ColorPreset = {
6
- back: TagProps['background'];
7
- fore: TagProps['color'];
8
- };
9
- export declare const colorPreset: {
10
- blue: {
11
- back: string;
12
- fore: string;
13
- };
14
- yellow: {
15
- back: string;
16
- fore: string;
17
- };
18
- green: {
19
- back: string;
20
- fore: string;
21
- };
22
- red: {
23
- back: string;
24
- fore: string;
25
- };
26
- orange: {
27
- back: string;
28
- fore: string;
29
- };
30
- purple: {
31
- back: string;
32
- fore: string;
33
- };
34
- /** 蓝绿色 */ cyan: {
35
- back: string;
36
- fore: string;
37
- };
38
- /** 天蓝色 */ skyblue: {
39
- back: string;
40
- fore: string;
41
- };
42
- /** 深紫色 */ darkPurple: {
43
- back: string;
44
- fore: string;
45
- };
46
- /** 蓝灰色 */ blueGray: {
47
- back: string;
48
- fore: string;
49
- };
50
- /** 中灰色 */ midGray: {
51
- back: string;
52
- fore: string;
53
- };
54
- };
55
- type BuiltinColorEnum = Required<TagProps>['type'];
56
- type SCMColorEnumPreset = keyof typeof colorPreset;
57
- export declare const ColorEnumPreset: SCMColorEnumPreset[];
58
6
  export type ProTagProps = TagProps & {
59
7
  /** 是否显示边框 */
60
8
  bordered?: boolean;
@@ -75,4 +23,3 @@ export declare class ProTag extends ProField {
75
23
  getColor(preset: ValueOf<ProTagProps['colorPreset']>): ColorPreset | undefined;
76
24
  getText(data: string, textMap: ProTagProps['textMap']): {};
77
25
  }
78
- export {};
@@ -7,65 +7,94 @@
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
- import '@babel/runtime/helpers/esm/inheritsLoose';
11
- import 'react';
12
- import '@hi-ui/classname';
13
- import 'lodash-es';
14
- import '@hi-ui/tag';
15
- import '@hi-ui/input';
16
- import '@hi-ui/ellipsis-tooltip';
17
- import '@hi-ui/schema-core';
18
- import '@hi-ui/schema-utils';
19
- import 'tslib';
10
+ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
11
+ import React from 'react';
12
+ import { cx } from '@hi-ui/classname';
13
+ import { omit, isNil } from 'lodash-es';
14
+ import { Tag } from '@hi-ui/tag';
15
+ import { ProField } from '../../../base.js';
16
+ import { ReadonlyWrapper } from '../../../components/span/index.js';
17
+ import { colorPreset } from './preset.js';
20
18
  import './index.scss.js';
21
-
22
- // IPD的标签颜色规范,先记录在这里吧
23
- // https://www.figma.com/design/R7gUHJaKDPSAaWojTrNUe2/%E7%A0%94%E4%BA%A7%E4%BE%9B%E4%B8%9A%E5%8A%A1%E8%AE%BE%E8%AE%A1%E8%A7%84%E8%8C%83-IPD?node-id=2042-50477&node-type=frame&t=uCEcQbmB9uwVVUIQ-0
24
- var colorPreset = {
25
- blue: {
26
- back: '#EDF7FE',
27
- fore: '#0744AD'
28
- },
29
- yellow: {
30
- back: '#FEFCE9',
31
- fore: '#875100'
32
- },
33
- green: {
34
- back: '#EEFEF2',
35
- fore: '#007D3E'
36
- },
37
- red: {
38
- back: '#FEF1EE',
39
- fore: '#B32D36'
40
- },
41
- orange: {
42
- back: '#FEF5EE',
43
- fore: '#B23E1B'
44
- },
45
- purple: {
46
- back: '#F5EEFE',
47
- fore: '#533DAD'
48
- },
49
- /** 蓝绿色 */cyan: {
50
- back: '#ECFEFC',
51
- fore: '#0C737A'
52
- },
53
- /** 天蓝色 */skyblue: {
54
- back: '#ECFCFE',
55
- fore: '#006BB3'
56
- },
57
- /** 深紫色 */darkPurple: {
58
- back: '#EEF2FE',
59
- fore: '#363AB3'
60
- },
61
- /** 蓝灰色 */blueGray: {
62
- back: '#EEF7FE',
63
- fore: '#3C5485'
64
- },
65
- /** 中灰色 */midGray: {
66
- back: '#F2F4F7',
67
- fore: '#1F2733'
19
+ function isInvalidTagData(data) {
20
+ if (isNil(data)) return true;
21
+ if (data === '') return true;
22
+ return false;
23
+ }
24
+ var ProTag = /*#__PURE__*/function (_ProField) {
25
+ _inheritsLoose(ProTag, _ProField);
26
+ function ProTag() {
27
+ return _ProField.apply(this, arguments) || this;
68
28
  }
69
- };
70
- var ColorEnumPreset = Object.keys(colorPreset);
71
- export { ColorEnumPreset, colorPreset };
29
+ var _proto = ProTag.prototype;
30
+ _proto.render = function render(data, ctx) {
31
+ if (isInvalidTagData(data)) return this.dftDom;
32
+ // 统一转换为数组处理
33
+ var dataList = (Array.isArray(data) ? data : [data]).filter(function (el) {
34
+ return !isInvalidTagData(el);
35
+ });
36
+ if (dataList.length === 0) return this.dftDom;
37
+ return this.renderTag(dataList, ctx);
38
+ };
39
+ _proto.renderTag = function renderTag(dataArray, ctx) {
40
+ var _this = this;
41
+ var fieldProps = this.getFieldProps({}, ctx);
42
+ var className = cx(fieldProps.className, {
43
+ 'pro-tag--bordered': fieldProps.bordered
44
+ });
45
+ var tagProps = this.getTagProps(fieldProps);
46
+ return /*#__PURE__*/React.createElement(ReadonlyWrapper, {
47
+ style: {
48
+ gap: 4
49
+ }
50
+ }, dataArray.map(function (data, index) {
51
+ var _a;
52
+ var _preset = (_a = fieldProps.colorPreset) === null || _a === void 0 ? void 0 : _a[data];
53
+ var text = _this.getText(data, fieldProps.textMap);
54
+ // 没有预设颜色,则显示默认Tag样式
55
+ if (!_preset) {
56
+ return /*#__PURE__*/React.createElement("span", {
57
+ key: index
58
+ }, /*#__PURE__*/React.createElement(Tag, Object.assign({
59
+ type: "default"
60
+ }, tagProps, {
61
+ className: className
62
+ }), text));
63
+ }
64
+ // 内置类型
65
+ var type = _this.getType(_preset);
66
+ // 自定义颜色(文字色和背景色)
67
+ var color = _this.getColor(_preset);
68
+ return /*#__PURE__*/React.createElement("span", {
69
+ key: index
70
+ }, /*#__PURE__*/React.createElement(Tag, Object.assign({
71
+ type: type,
72
+ color: color === null || color === void 0 ? void 0 : color.fore,
73
+ background: color === null || color === void 0 ? void 0 : color.back
74
+ }, tagProps, {
75
+ className: className
76
+ }), text));
77
+ }));
78
+ };
79
+ _proto.getTagProps = function getTagProps(props) {
80
+ return omit(props, ['bordered', 'colorPreset']);
81
+ };
82
+ _proto.getType = function getType(preset) {
83
+ if (typeof preset !== 'string') return undefined;
84
+ if (preset in colorPreset) return undefined;
85
+ return preset;
86
+ };
87
+ _proto.getColor = function getColor(preset) {
88
+ if (typeof preset !== 'string') return preset;
89
+ if (preset in colorPreset) return colorPreset[preset];
90
+ return undefined;
91
+ };
92
+ _proto.getText = function getText(data, textMap) {
93
+ var _a, _b;
94
+ if (!textMap) return data;
95
+ if (textMap instanceof Map) return (_a = textMap.get(data)) !== null && _a !== void 0 ? _a : data;
96
+ return (_b = textMap[data]) !== null && _b !== void 0 ? _b : data;
97
+ };
98
+ return ProTag;
99
+ }(ProField);
100
+ export { ProTag };
@@ -0,0 +1,54 @@
1
+ import { type TagProps } from '@hi-ui/tag';
2
+ export type ColorPreset = {
3
+ back: TagProps['background'];
4
+ fore: TagProps['color'];
5
+ };
6
+ export declare const colorPreset: {
7
+ blue: {
8
+ back: string;
9
+ fore: string;
10
+ };
11
+ yellow: {
12
+ back: string;
13
+ fore: string;
14
+ };
15
+ green: {
16
+ back: string;
17
+ fore: string;
18
+ };
19
+ red: {
20
+ back: string;
21
+ fore: string;
22
+ };
23
+ orange: {
24
+ back: string;
25
+ fore: string;
26
+ };
27
+ purple: {
28
+ back: string;
29
+ fore: string;
30
+ };
31
+ /** 蓝绿色 */ cyan: {
32
+ back: string;
33
+ fore: string;
34
+ };
35
+ /** 天蓝色 */ skyblue: {
36
+ back: string;
37
+ fore: string;
38
+ };
39
+ /** 深紫色 */ darkPurple: {
40
+ back: string;
41
+ fore: string;
42
+ };
43
+ /** 蓝灰色 */ blueGray: {
44
+ back: string;
45
+ fore: string;
46
+ };
47
+ /** 中灰色 */ midGray: {
48
+ back: string;
49
+ fore: string;
50
+ };
51
+ };
52
+ export type BuiltinColorEnum = Required<TagProps>['type'];
53
+ export type SCMColorEnumPreset = keyof typeof colorPreset;
54
+ export declare const ColorEnumPreset: SCMColorEnumPreset[];
@@ -0,0 +1,60 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-fields
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-fields#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ // 内部的的标签颜色规范 // TODO 待确认后更新
11
+ var colorPreset = {
12
+ blue: {
13
+ back: '#EDF7FE',
14
+ fore: '#0744AD'
15
+ },
16
+ yellow: {
17
+ back: '#FEFCE9',
18
+ fore: '#875100'
19
+ },
20
+ green: {
21
+ back: '#EEFEF2',
22
+ fore: '#007D3E'
23
+ },
24
+ red: {
25
+ back: '#FEF1EE',
26
+ fore: '#B32D36'
27
+ },
28
+ orange: {
29
+ back: '#FEF5EE',
30
+ fore: '#B23E1B'
31
+ },
32
+ purple: {
33
+ back: '#F5EEFE',
34
+ fore: '#533DAD'
35
+ },
36
+ /** 蓝绿色 */cyan: {
37
+ back: '#ECFEFC',
38
+ fore: '#0C737A'
39
+ },
40
+ /** 天蓝色 */skyblue: {
41
+ back: '#ECFCFE',
42
+ fore: '#006BB3'
43
+ },
44
+ /** 深紫色 */darkPurple: {
45
+ back: '#EEF2FE',
46
+ fore: '#363AB3'
47
+ },
48
+ /** 蓝灰色 */blueGray: {
49
+ back: '#EEF7FE',
50
+ fore: '#3C5485'
51
+ },
52
+ /** 中灰色 */midGray: {
53
+ back: '#F2F4F7',
54
+ fore: '#1F2733'
55
+ }
56
+ // eslint-disable-next-line prettier/prettier
57
+ };
58
+
59
+ var ColorEnumPreset = Object.keys(colorPreset);
60
+ export { ColorEnumPreset, colorPreset };
package/lib/index.d.ts CHANGED
@@ -26,5 +26,5 @@ export * from './components/span';
26
26
  export * from './ctx';
27
27
  export * from './utils';
28
28
  export { DumbInput } from './fields/semantic/text';
29
- export { colorPreset, ColorEnumPreset } from './fields/semantic/tag';
29
+ export { colorPreset, ColorEnumPreset } from './fields/semantic/tag/preset';
30
30
  export * from './editable';
package/lib/index.js CHANGED
@@ -12,7 +12,7 @@ export { ReadonlyWrapper, ReadonlyWrapper as Span } from './components/span/inde
12
12
  export { FieldMapProvider, getFieldRenderFn, matchFieldClass, matchFieldRenderFn, useFieldMap, useMatchFieldClass } from './ctx.js';
13
13
  export { getFieldProps, getFormItemProps, getWrapperProps } from './utils.js';
14
14
  export { DumbInput } from './fields/semantic/text/index.js';
15
- export { ColorEnumPreset, colorPreset } from './fields/semantic/tag/index.js';
15
+ export { ColorEnumPreset, colorPreset } from './fields/semantic/tag/preset.js';
16
16
  export { EditableField } from './editable/index.js';
17
17
  export { getLabel } from './utils/label.js';
18
18
  export { BatchDepUpdate } from './utils/batch-dep-update.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/schema-fields",
3
- "version": "4.0.0-experimental.6",
3
+ "version": "4.0.0-experimental.8",
4
4
  "description": "A sub-package for @hi-ui/schema.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",