@lemon-fe/components 1.5.6 → 1.5.7-alpha.0
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/es/data-grid/index.js +7 -1
- package/es/data-grid/typings.d.ts +8 -0
- package/es/data-grid/{utils.d.ts → utils/index.d.ts} +2 -2
- package/es/data-grid/{utils.js → utils/index.js} +3 -3
- package/es/data-grid/utils/text-width.d.ts +1 -0
- package/es/data-grid/utils/text-width.js +79 -0
- package/package.json +2 -2
package/es/data-grid/index.js
CHANGED
|
@@ -57,6 +57,7 @@ import CellRenderer from "./renderer/cell-renderer";
|
|
|
57
57
|
import DetailCellRenderer from "./renderer/detali-cell-renderer";
|
|
58
58
|
import HeaderRenderer from "./renderer/header-renderer";
|
|
59
59
|
import { prefix, getColField, isColumn, withSyncRender, Store, Selection, getDefaultColumnTypes } from "./utils";
|
|
60
|
+
import { getTextWidth } from "./utils/text-width";
|
|
60
61
|
import { GridApi, ColumnApi } from 'ag-grid-community';
|
|
61
62
|
import 'ag-grid-enterprise';
|
|
62
63
|
import { AgGridReact } from 'ag-grid-react';
|
|
@@ -1052,7 +1053,9 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
|
|
|
1052
1053
|
columns = _this$props8$columns === void 0 ? [] : _this$props8$columns,
|
|
1053
1054
|
rowActions = _this$props8.rowActions,
|
|
1054
1055
|
rowSelection = _this$props8.rowSelection,
|
|
1055
|
-
locale = _this$props8.locale
|
|
1056
|
+
locale = _this$props8.locale,
|
|
1057
|
+
enableEstimateInitialColumnWidth = _this$props8.enableEstimateInitialColumnWidth,
|
|
1058
|
+
keepInitialWidthWhenEstimate = _this$props8.keepInitialWidthWhenEstimate;
|
|
1056
1059
|
var leafColIds = [];
|
|
1057
1060
|
var groups = new Map();
|
|
1058
1061
|
var map = function map(cols) {
|
|
@@ -1090,6 +1093,9 @@ var InternalDataGrid = /*#__PURE__*/function (_Component) {
|
|
|
1090
1093
|
} else if (title !== undefined) {
|
|
1091
1094
|
opts.headerName = title.toString();
|
|
1092
1095
|
}
|
|
1096
|
+
if (enableEstimateInitialColumnWidth && opts.headerName && !keepInitialWidthWhenEstimate) {
|
|
1097
|
+
opts.initialWidth = getTextWidth(opts.headerName) * 14 + 36 + (opts.headerComponentParams !== undefined ? 24 : 0);
|
|
1098
|
+
}
|
|
1093
1099
|
|
|
1094
1100
|
// render
|
|
1095
1101
|
if (render !== undefined) {
|
|
@@ -282,4 +282,12 @@ export interface DataGridProps<TData> extends Omit<AgGridReactProps<TData>, 'row
|
|
|
282
282
|
defaultColDef?: ColDef<TData> & {
|
|
283
283
|
useValueFormatterForExport?: boolean;
|
|
284
284
|
};
|
|
285
|
+
/**
|
|
286
|
+
* @depscription 启用预估初始列宽 启用后根据字符长度计算宽度
|
|
287
|
+
*/
|
|
288
|
+
enableEstimateInitialColumnWidth?: boolean;
|
|
289
|
+
/**
|
|
290
|
+
* @depscription 与enableEstimateInitialColumnWidth搭配使用,如果col传入了initialWidth,则不会进行预估初始列宽设置
|
|
291
|
+
*/
|
|
292
|
+
keepInitialWidthWhenEstimate?: boolean;
|
|
285
293
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DataGridLocale } from '
|
|
2
|
-
import type { ColType, ColGroupType, PathType } from '
|
|
1
|
+
import type { DataGridLocale } from '../locale/locale';
|
|
2
|
+
import type { ColType, ColGroupType, PathType } from '../typings';
|
|
3
3
|
import { Subject } from '@lemon-fe/utils';
|
|
4
4
|
import type { ColDef, ColGroupDef } from 'ag-grid-community';
|
|
5
5
|
export declare const prefix: (val?: string | undefined) => string;
|
|
@@ -13,9 +13,9 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
13
13
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
14
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
15
15
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
|
-
import { prefixClassName } from "
|
|
17
|
-
import CellDeleteRender from "
|
|
18
|
-
import CellIndexRender from "
|
|
16
|
+
import { prefixClassName } from "../../utils";
|
|
17
|
+
import CellDeleteRender from "../renderer/cell-delete-renderer";
|
|
18
|
+
import CellIndexRender from "../renderer/cell-index-renderer";
|
|
19
19
|
import { Subject } from '@lemon-fe/utils';
|
|
20
20
|
import { get as _get, set as _set } from 'lodash';
|
|
21
21
|
import moment from 'moment';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTextWidth(text: string): number;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
|
+
export function getTextWidth(text) {
|
|
5
|
+
var width = 0;
|
|
6
|
+
var _iterator = _createForOfIteratorHelper(text),
|
|
7
|
+
_step;
|
|
8
|
+
try {
|
|
9
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
10
|
+
var char = _step.value;
|
|
11
|
+
var code = char.codePointAt(0);
|
|
12
|
+
|
|
13
|
+
// 东南亚文字中的组合音标 / 附加符号不单独占宽
|
|
14
|
+
if (isCombiningMark(code)) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// CJK 中文、日文、韩文及其全角标点 / 符号
|
|
19
|
+
if (isCJK(code) || isCJKSymbol(code) || isFullWidthSymbol(code)) {
|
|
20
|
+
width += 1;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 泰文、高棉文、缅甸文、老挝文;马来文 / 英文使用拉丁字符规则
|
|
25
|
+
if (isSEAComplexScript(code)) {
|
|
26
|
+
width += 1;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 拉丁字母、数字、标点
|
|
31
|
+
width += 0.6;
|
|
32
|
+
}
|
|
33
|
+
} catch (err) {
|
|
34
|
+
_iterator.e(err);
|
|
35
|
+
} finally {
|
|
36
|
+
_iterator.f();
|
|
37
|
+
}
|
|
38
|
+
return width;
|
|
39
|
+
}
|
|
40
|
+
function isCJK(code) {
|
|
41
|
+
return code >= 0x3400 && code <= 0x4dbf ||
|
|
42
|
+
// CJK扩展
|
|
43
|
+
code >= 0x4e00 && code <= 0x9fff ||
|
|
44
|
+
// 中文
|
|
45
|
+
code >= 0x20000 && code <= 0x2ebef ||
|
|
46
|
+
// CJK扩展B-I
|
|
47
|
+
code >= 0x3040 && code <= 0x30ff ||
|
|
48
|
+
// 日文
|
|
49
|
+
code >= 0xac00 && code <= 0xd7af // 韩文
|
|
50
|
+
;
|
|
51
|
+
}
|
|
52
|
+
function isCJKSymbol(code) {
|
|
53
|
+
return code >= 0x3000 && code <= 0x303f;
|
|
54
|
+
}
|
|
55
|
+
function isSEAComplexScript(code) {
|
|
56
|
+
return code >= 0x0e00 && code <= 0x0e7f ||
|
|
57
|
+
// Thai
|
|
58
|
+
code >= 0x1780 && code <= 0x17ff ||
|
|
59
|
+
// Khmer
|
|
60
|
+
code >= 0x1000 && code <= 0x109f ||
|
|
61
|
+
// Myanmar
|
|
62
|
+
code >= 0x0e80 && code <= 0x0eff // Lao
|
|
63
|
+
;
|
|
64
|
+
}
|
|
65
|
+
function isCombiningMark(code) {
|
|
66
|
+
return code >= 0x0300 && code <= 0x036f ||
|
|
67
|
+
// Combining Diacritical Marks
|
|
68
|
+
code === 0x0e31 || code >= 0x0e34 && code <= 0x0e3a || code >= 0x0e47 && code <= 0x0e4e ||
|
|
69
|
+
// Thai vowels and tones
|
|
70
|
+
code === 0x0eb1 || code >= 0x0eb4 && code <= 0x0ebc || code >= 0x0ec8 && code <= 0x0ece ||
|
|
71
|
+
// Lao vowels and tones
|
|
72
|
+
code >= 0x102b && code <= 0x103e ||
|
|
73
|
+
// Myanmar vowel signs and marks
|
|
74
|
+
code >= 0x17b4 && code <= 0x17d3 // Khmer vowel signs and signs
|
|
75
|
+
;
|
|
76
|
+
}
|
|
77
|
+
function isFullWidthSymbol(code) {
|
|
78
|
+
return code >= 0xff01 && code <= 0xff60;
|
|
79
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemon-fe/components",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7-alpha.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"registry": "https://registry.npmjs.org"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "f9d9bc687268ce21388513f69bda29c79f7aa6b6"
|
|
62
62
|
}
|