@enableai-base/core 1.0.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/dist/core.cjs.js +263 -0
- package/dist/core.cjs.prod.js +263 -0
- package/dist/core.d.ts +179 -0
- package/dist/core.esm-bundler.mjs +228 -0
- package/index.js +7 -0
- package/package.json +40 -0
package/dist/core.cjs.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enableai-base/core v1.0.0
|
|
3
|
+
* (c) 2024-present Enableai
|
|
4
|
+
* @license Proprietary
|
|
5
|
+
**/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
var lodash = require('lodash');
|
|
11
|
+
var dayjs = require('dayjs');
|
|
12
|
+
var duration = require('dayjs/plugin/duration');
|
|
13
|
+
|
|
14
|
+
const TableToolType = {
|
|
15
|
+
"TEXT": 28,
|
|
16
|
+
"28": "TEXT",
|
|
17
|
+
"SIMPLE_SELECT": 29,
|
|
18
|
+
"29": "SIMPLE_SELECT",
|
|
19
|
+
"MULTI_SELECT": 30,
|
|
20
|
+
"30": "MULTI_SELECT",
|
|
21
|
+
"NUMBER": 31,
|
|
22
|
+
"31": "NUMBER",
|
|
23
|
+
"ATTACHMENT": 32,
|
|
24
|
+
"32": "ATTACHMENT",
|
|
25
|
+
"LINK": 33,
|
|
26
|
+
"33": "LINK",
|
|
27
|
+
"JSON": 34,
|
|
28
|
+
"34": "JSON",
|
|
29
|
+
"TAG": 35,
|
|
30
|
+
"35": "TAG",
|
|
31
|
+
"DATE": 36,
|
|
32
|
+
"36": "DATE",
|
|
33
|
+
"TIME_LEN": 37,
|
|
34
|
+
"37": "TIME_LEN",
|
|
35
|
+
"USER": 38,
|
|
36
|
+
"38": "USER",
|
|
37
|
+
"DROPDOWN": 39,
|
|
38
|
+
"39": "DROPDOWN"
|
|
39
|
+
};
|
|
40
|
+
const TableColumnInnerType = {
|
|
41
|
+
"CHECKBOX": -1,
|
|
42
|
+
"-1": "CHECKBOX",
|
|
43
|
+
"MORE": -2,
|
|
44
|
+
"-2": "MORE",
|
|
45
|
+
"PLUS": -3,
|
|
46
|
+
"-3": "PLUS",
|
|
47
|
+
"MAIN": -4,
|
|
48
|
+
"-4": "MAIN"
|
|
49
|
+
};
|
|
50
|
+
const TOOL_ICON = {
|
|
51
|
+
[28]: "text",
|
|
52
|
+
[29]: "single",
|
|
53
|
+
[30]: "list",
|
|
54
|
+
[31]: "numbered",
|
|
55
|
+
[32]: "atachment",
|
|
56
|
+
[33]: "hyperlink",
|
|
57
|
+
[34]: "json",
|
|
58
|
+
[35]: "tag",
|
|
59
|
+
[36]: "date",
|
|
60
|
+
[37]: "duration",
|
|
61
|
+
[38]: "personnel",
|
|
62
|
+
[39]: "more"
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const BORDER_COLOR = "rgb(191, 194, 199)";
|
|
66
|
+
const BORDER_SECONDARY_COLOR = "#f0f0f0";
|
|
67
|
+
const COLOR_BG_CELL = "#ffffff";
|
|
68
|
+
const COLOR_BG_CELL_HOVER = "rgb(244,244,244)";
|
|
69
|
+
const COLOR_BORDER_SELECTION = "#1555F0";
|
|
70
|
+
const COLOR_ICON = "rgb(96, 102, 111)";
|
|
71
|
+
const COLOR_BG_OPTION_HOVER = "#1f232914";
|
|
72
|
+
const DEFAULT_FONT_SIZE = 12;
|
|
73
|
+
const HEADER_FONT_SIZE = 14;
|
|
74
|
+
const TABLE_DEFAULT_ROW_HEIGHT = 30;
|
|
75
|
+
const BORDER_LINE_WIDTH = 1;
|
|
76
|
+
const COLOR_LINK = "#1555F0";
|
|
77
|
+
const CUSTOM_CELL_STYLE_HIGHLIGHT = "CUSTOM_CELL_STYLE_HIGHLIGHT";
|
|
78
|
+
const CUSTOM_CELL_STYLE_HIGHLIGHT_STYLE = { bgColor: "#D0DDFC" };
|
|
79
|
+
const CUSTOM_CELL_STYLE = {
|
|
80
|
+
id: CUSTOM_CELL_STYLE_HIGHLIGHT,
|
|
81
|
+
style: CUSTOM_CELL_STYLE_HIGHLIGHT_STYLE
|
|
82
|
+
};
|
|
83
|
+
const CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS = "CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS";
|
|
84
|
+
const CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS_STYLE = {
|
|
85
|
+
bgColor: "#D0DDFC",
|
|
86
|
+
borderColor: COLOR_BORDER_SELECTION,
|
|
87
|
+
borderLineWidth: 3
|
|
88
|
+
};
|
|
89
|
+
const CUSTOM_CELL_FOCUS_STYLE = {
|
|
90
|
+
id: CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS,
|
|
91
|
+
style: CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS_STYLE
|
|
92
|
+
};
|
|
93
|
+
const CUSTOM_CELL_STYLE_FEEDBACK_ERROR = "CUSTOM_CELL_STYLE_FEEDBACK_ERROR";
|
|
94
|
+
const CUSTOM_CELL_STYLE_FEEDBACK_ERROR_STYLE = {
|
|
95
|
+
color: "red"
|
|
96
|
+
};
|
|
97
|
+
const CUSTOM_CELL_FEEDBACK_ERROR_STYLE = {
|
|
98
|
+
id: CUSTOM_CELL_STYLE_FEEDBACK_ERROR,
|
|
99
|
+
style: CUSTOM_CELL_STYLE_FEEDBACK_ERROR_STYLE
|
|
100
|
+
};
|
|
101
|
+
const CUSTOM_STYLE_LIST = [
|
|
102
|
+
CUSTOM_CELL_STYLE_HIGHLIGHT_STYLE,
|
|
103
|
+
CUSTOM_CELL_STYLE_FEEDBACK_ERROR_STYLE,
|
|
104
|
+
CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS_STYLE
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
const FeatureType = {
|
|
108
|
+
"SELECT": "select",
|
|
109
|
+
"TYPE_SELECT": "type_select",
|
|
110
|
+
"MULTI_SELECT": "multi_select",
|
|
111
|
+
"INPUT": "input",
|
|
112
|
+
"NUMBER": "number",
|
|
113
|
+
"SWITCH": "switch",
|
|
114
|
+
"CUSTOM_OPTION": "custom_option",
|
|
115
|
+
"DATE_FORMATE": "date_format",
|
|
116
|
+
"DATE_VALUE": "date_value"
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
function getColorByStr(s) {
|
|
120
|
+
let number = lodash.random(0, 360);
|
|
121
|
+
if (s) {
|
|
122
|
+
const codes = s.split("").map((i) => i.charCodeAt(0));
|
|
123
|
+
number = lodash.sum(codes) % 360;
|
|
124
|
+
}
|
|
125
|
+
return `hsl(${number} 100% 50%)`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const formatValue = (raw, format) => {
|
|
129
|
+
const num = typeof raw === "string" ? parseFloat(raw) : raw;
|
|
130
|
+
if (isNaN(num)) return "";
|
|
131
|
+
switch (format) {
|
|
132
|
+
case "integer":
|
|
133
|
+
return Math.round(num).toString();
|
|
134
|
+
case "thousands_separator":
|
|
135
|
+
return num.toLocaleString("en-US", { maximumFractionDigits: 0 });
|
|
136
|
+
case "thousands_separator_decimal":
|
|
137
|
+
return num.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
138
|
+
case "one_decimal_decimal":
|
|
139
|
+
return num.toFixed(1);
|
|
140
|
+
case "two_decimal_decimal":
|
|
141
|
+
return num.toFixed(2);
|
|
142
|
+
case "three_decimal_decimal":
|
|
143
|
+
return num.toFixed(3);
|
|
144
|
+
case "four_decimal_decimal":
|
|
145
|
+
return num.toFixed(4);
|
|
146
|
+
case "five_decimal_decimal":
|
|
147
|
+
return num.toFixed(5);
|
|
148
|
+
case "six_decimal_decimal":
|
|
149
|
+
return num.toFixed(6);
|
|
150
|
+
case "percentage":
|
|
151
|
+
return `${Math.round(num * 100)}%`;
|
|
152
|
+
case "percentage_decimal":
|
|
153
|
+
return `${(num * 100).toFixed(2)}%`;
|
|
154
|
+
default:
|
|
155
|
+
return String(raw);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
dayjs.extend(duration);
|
|
160
|
+
function getSecondsTime(seconds) {
|
|
161
|
+
return dayjs.duration(typeof seconds === "number" ? seconds : parseInt(seconds), "seconds");
|
|
162
|
+
}
|
|
163
|
+
const formatDuration = (duration2) => {
|
|
164
|
+
const d = dayjs.duration(duration2, "seconds");
|
|
165
|
+
let formatStr = "s\u79D2";
|
|
166
|
+
if (d.minutes()) formatStr = "m\u5206s\u79D2";
|
|
167
|
+
if (d.hours()) formatStr = "H\u5C0F\u65F6m\u5206";
|
|
168
|
+
if (d.days()) formatStr = "D\u5929H\u5C0F\u65F6";
|
|
169
|
+
if (d.months()) formatStr = "M\u6708D\u5929";
|
|
170
|
+
if (d.years()) formatStr = "Y\u5E74M\u6708";
|
|
171
|
+
return d.format(formatStr);
|
|
172
|
+
};
|
|
173
|
+
const formatTime = (millisecond, isMatching = true) => {
|
|
174
|
+
let result = "";
|
|
175
|
+
const copyMillisecond = lodash.cloneDeep(millisecond);
|
|
176
|
+
millisecond /= 1e3;
|
|
177
|
+
const hours = Math.floor(millisecond / 3600);
|
|
178
|
+
const minutes = Math.floor(millisecond % 3600 / 60);
|
|
179
|
+
const seconds = Math.floor(millisecond % 60);
|
|
180
|
+
if (!isMatching && minutes > 0) {
|
|
181
|
+
if (hours > 0 && minutes < 60) return Number((hours + minutes / 60).toFixed(2)) + "\u5C0F\u65F6";
|
|
182
|
+
if (seconds > 0 && seconds < 60) return Number((minutes + seconds / 60).toFixed(2)) + "\u5206\u949F";
|
|
183
|
+
}
|
|
184
|
+
if (isMatching && hours <= 0 && minutes <= 0 && copyMillisecond < 1e3) return "<1\u79D2";
|
|
185
|
+
if (hours > 0) result += `${hours.toString().padStart(2, "")}\u5C0F\u65F6`;
|
|
186
|
+
if (minutes > 0) result += `${minutes.toString().padStart(2, "")}\u5206\u949F`;
|
|
187
|
+
if (seconds > 0) result += `${seconds.toString().padStart(2, "")}\u79D2`;
|
|
188
|
+
return result.trim();
|
|
189
|
+
};
|
|
190
|
+
const durationCalc = (secondsTime, unit) => {
|
|
191
|
+
let result = 0;
|
|
192
|
+
secondsTime = Number(secondsTime);
|
|
193
|
+
const hours = Number((secondsTime / 3600).toFixed(2));
|
|
194
|
+
const minutes = Number((secondsTime % 3600 / 60).toFixed(2));
|
|
195
|
+
const seconds = Number((secondsTime % 60).toFixed(2));
|
|
196
|
+
result = unit === "h" ? hours : unit === "m" ? minutes : seconds;
|
|
197
|
+
return result + "";
|
|
198
|
+
};
|
|
199
|
+
const TZ_LABEL = "GMT+8";
|
|
200
|
+
function parseDateFormat(format) {
|
|
201
|
+
const GMT_SUFFIX = " (GMT+8)";
|
|
202
|
+
if (format.endsWith(GMT_SUFFIX)) {
|
|
203
|
+
return {
|
|
204
|
+
baseFormat: format.replace(GMT_SUFFIX, ""),
|
|
205
|
+
showGmt8: true
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
baseFormat: format,
|
|
210
|
+
showGmt8: false
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function inferShowTimeFromFormat(format) {
|
|
214
|
+
const hasHour = /H|h/.test(format);
|
|
215
|
+
const hasMinute = /m/.test(format);
|
|
216
|
+
const hasSecond = /s/.test(format);
|
|
217
|
+
if (!hasHour && !hasMinute && !hasSecond) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
let timeFormat = "HH";
|
|
221
|
+
if (hasMinute) {
|
|
222
|
+
timeFormat = "HH:mm";
|
|
223
|
+
}
|
|
224
|
+
if (hasSecond) {
|
|
225
|
+
timeFormat = "HH:mm:ss";
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
format: timeFormat
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
exports.BORDER_COLOR = BORDER_COLOR;
|
|
233
|
+
exports.BORDER_LINE_WIDTH = BORDER_LINE_WIDTH;
|
|
234
|
+
exports.BORDER_SECONDARY_COLOR = BORDER_SECONDARY_COLOR;
|
|
235
|
+
exports.COLOR_BG_CELL = COLOR_BG_CELL;
|
|
236
|
+
exports.COLOR_BG_CELL_HOVER = COLOR_BG_CELL_HOVER;
|
|
237
|
+
exports.COLOR_BG_OPTION_HOVER = COLOR_BG_OPTION_HOVER;
|
|
238
|
+
exports.COLOR_BORDER_SELECTION = COLOR_BORDER_SELECTION;
|
|
239
|
+
exports.COLOR_ICON = COLOR_ICON;
|
|
240
|
+
exports.COLOR_LINK = COLOR_LINK;
|
|
241
|
+
exports.CUSTOM_CELL_FEEDBACK_ERROR_STYLE = CUSTOM_CELL_FEEDBACK_ERROR_STYLE;
|
|
242
|
+
exports.CUSTOM_CELL_FOCUS_STYLE = CUSTOM_CELL_FOCUS_STYLE;
|
|
243
|
+
exports.CUSTOM_CELL_STYLE = CUSTOM_CELL_STYLE;
|
|
244
|
+
exports.CUSTOM_CELL_STYLE_FEEDBACK_ERROR = CUSTOM_CELL_STYLE_FEEDBACK_ERROR;
|
|
245
|
+
exports.CUSTOM_CELL_STYLE_HIGHLIGHT = CUSTOM_CELL_STYLE_HIGHLIGHT;
|
|
246
|
+
exports.CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS = CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS;
|
|
247
|
+
exports.CUSTOM_STYLE_LIST = CUSTOM_STYLE_LIST;
|
|
248
|
+
exports.DEFAULT_FONT_SIZE = DEFAULT_FONT_SIZE;
|
|
249
|
+
exports.FeatureType = FeatureType;
|
|
250
|
+
exports.HEADER_FONT_SIZE = HEADER_FONT_SIZE;
|
|
251
|
+
exports.TABLE_DEFAULT_ROW_HEIGHT = TABLE_DEFAULT_ROW_HEIGHT;
|
|
252
|
+
exports.TOOL_ICON = TOOL_ICON;
|
|
253
|
+
exports.TZ_LABEL = TZ_LABEL;
|
|
254
|
+
exports.TableColumnInnerType = TableColumnInnerType;
|
|
255
|
+
exports.TableToolType = TableToolType;
|
|
256
|
+
exports.durationCalc = durationCalc;
|
|
257
|
+
exports.formatDuration = formatDuration;
|
|
258
|
+
exports.formatTime = formatTime;
|
|
259
|
+
exports.formatValue = formatValue;
|
|
260
|
+
exports.getColorByStr = getColorByStr;
|
|
261
|
+
exports.getSecondsTime = getSecondsTime;
|
|
262
|
+
exports.inferShowTimeFromFormat = inferShowTimeFromFormat;
|
|
263
|
+
exports.parseDateFormat = parseDateFormat;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enableai-base/core v1.0.0
|
|
3
|
+
* (c) 2024-present Enableai
|
|
4
|
+
* @license Proprietary
|
|
5
|
+
**/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
var lodash = require('lodash');
|
|
11
|
+
var dayjs = require('dayjs');
|
|
12
|
+
var duration = require('dayjs/plugin/duration');
|
|
13
|
+
|
|
14
|
+
const TableToolType = {
|
|
15
|
+
"TEXT": 28,
|
|
16
|
+
"28": "TEXT",
|
|
17
|
+
"SIMPLE_SELECT": 29,
|
|
18
|
+
"29": "SIMPLE_SELECT",
|
|
19
|
+
"MULTI_SELECT": 30,
|
|
20
|
+
"30": "MULTI_SELECT",
|
|
21
|
+
"NUMBER": 31,
|
|
22
|
+
"31": "NUMBER",
|
|
23
|
+
"ATTACHMENT": 32,
|
|
24
|
+
"32": "ATTACHMENT",
|
|
25
|
+
"LINK": 33,
|
|
26
|
+
"33": "LINK",
|
|
27
|
+
"JSON": 34,
|
|
28
|
+
"34": "JSON",
|
|
29
|
+
"TAG": 35,
|
|
30
|
+
"35": "TAG",
|
|
31
|
+
"DATE": 36,
|
|
32
|
+
"36": "DATE",
|
|
33
|
+
"TIME_LEN": 37,
|
|
34
|
+
"37": "TIME_LEN",
|
|
35
|
+
"USER": 38,
|
|
36
|
+
"38": "USER",
|
|
37
|
+
"DROPDOWN": 39,
|
|
38
|
+
"39": "DROPDOWN"
|
|
39
|
+
};
|
|
40
|
+
const TableColumnInnerType = {
|
|
41
|
+
"CHECKBOX": -1,
|
|
42
|
+
"-1": "CHECKBOX",
|
|
43
|
+
"MORE": -2,
|
|
44
|
+
"-2": "MORE",
|
|
45
|
+
"PLUS": -3,
|
|
46
|
+
"-3": "PLUS",
|
|
47
|
+
"MAIN": -4,
|
|
48
|
+
"-4": "MAIN"
|
|
49
|
+
};
|
|
50
|
+
const TOOL_ICON = {
|
|
51
|
+
[28]: "text",
|
|
52
|
+
[29]: "single",
|
|
53
|
+
[30]: "list",
|
|
54
|
+
[31]: "numbered",
|
|
55
|
+
[32]: "atachment",
|
|
56
|
+
[33]: "hyperlink",
|
|
57
|
+
[34]: "json",
|
|
58
|
+
[35]: "tag",
|
|
59
|
+
[36]: "date",
|
|
60
|
+
[37]: "duration",
|
|
61
|
+
[38]: "personnel",
|
|
62
|
+
[39]: "more"
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const BORDER_COLOR = "rgb(191, 194, 199)";
|
|
66
|
+
const BORDER_SECONDARY_COLOR = "#f0f0f0";
|
|
67
|
+
const COLOR_BG_CELL = "#ffffff";
|
|
68
|
+
const COLOR_BG_CELL_HOVER = "rgb(244,244,244)";
|
|
69
|
+
const COLOR_BORDER_SELECTION = "#1555F0";
|
|
70
|
+
const COLOR_ICON = "rgb(96, 102, 111)";
|
|
71
|
+
const COLOR_BG_OPTION_HOVER = "#1f232914";
|
|
72
|
+
const DEFAULT_FONT_SIZE = 12;
|
|
73
|
+
const HEADER_FONT_SIZE = 14;
|
|
74
|
+
const TABLE_DEFAULT_ROW_HEIGHT = 30;
|
|
75
|
+
const BORDER_LINE_WIDTH = 1;
|
|
76
|
+
const COLOR_LINK = "#1555F0";
|
|
77
|
+
const CUSTOM_CELL_STYLE_HIGHLIGHT = "CUSTOM_CELL_STYLE_HIGHLIGHT";
|
|
78
|
+
const CUSTOM_CELL_STYLE_HIGHLIGHT_STYLE = { bgColor: "#D0DDFC" };
|
|
79
|
+
const CUSTOM_CELL_STYLE = {
|
|
80
|
+
id: CUSTOM_CELL_STYLE_HIGHLIGHT,
|
|
81
|
+
style: CUSTOM_CELL_STYLE_HIGHLIGHT_STYLE
|
|
82
|
+
};
|
|
83
|
+
const CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS = "CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS";
|
|
84
|
+
const CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS_STYLE = {
|
|
85
|
+
bgColor: "#D0DDFC",
|
|
86
|
+
borderColor: COLOR_BORDER_SELECTION,
|
|
87
|
+
borderLineWidth: 3
|
|
88
|
+
};
|
|
89
|
+
const CUSTOM_CELL_FOCUS_STYLE = {
|
|
90
|
+
id: CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS,
|
|
91
|
+
style: CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS_STYLE
|
|
92
|
+
};
|
|
93
|
+
const CUSTOM_CELL_STYLE_FEEDBACK_ERROR = "CUSTOM_CELL_STYLE_FEEDBACK_ERROR";
|
|
94
|
+
const CUSTOM_CELL_STYLE_FEEDBACK_ERROR_STYLE = {
|
|
95
|
+
color: "red"
|
|
96
|
+
};
|
|
97
|
+
const CUSTOM_CELL_FEEDBACK_ERROR_STYLE = {
|
|
98
|
+
id: CUSTOM_CELL_STYLE_FEEDBACK_ERROR,
|
|
99
|
+
style: CUSTOM_CELL_STYLE_FEEDBACK_ERROR_STYLE
|
|
100
|
+
};
|
|
101
|
+
const CUSTOM_STYLE_LIST = [
|
|
102
|
+
CUSTOM_CELL_STYLE_HIGHLIGHT_STYLE,
|
|
103
|
+
CUSTOM_CELL_STYLE_FEEDBACK_ERROR_STYLE,
|
|
104
|
+
CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS_STYLE
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
const FeatureType = {
|
|
108
|
+
"SELECT": "select",
|
|
109
|
+
"TYPE_SELECT": "type_select",
|
|
110
|
+
"MULTI_SELECT": "multi_select",
|
|
111
|
+
"INPUT": "input",
|
|
112
|
+
"NUMBER": "number",
|
|
113
|
+
"SWITCH": "switch",
|
|
114
|
+
"CUSTOM_OPTION": "custom_option",
|
|
115
|
+
"DATE_FORMATE": "date_format",
|
|
116
|
+
"DATE_VALUE": "date_value"
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
function getColorByStr(s) {
|
|
120
|
+
let number = lodash.random(0, 360);
|
|
121
|
+
if (s) {
|
|
122
|
+
const codes = s.split("").map((i) => i.charCodeAt(0));
|
|
123
|
+
number = lodash.sum(codes) % 360;
|
|
124
|
+
}
|
|
125
|
+
return `hsl(${number} 100% 50%)`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const formatValue = (raw, format) => {
|
|
129
|
+
const num = typeof raw === "string" ? parseFloat(raw) : raw;
|
|
130
|
+
if (isNaN(num)) return "";
|
|
131
|
+
switch (format) {
|
|
132
|
+
case "integer":
|
|
133
|
+
return Math.round(num).toString();
|
|
134
|
+
case "thousands_separator":
|
|
135
|
+
return num.toLocaleString("en-US", { maximumFractionDigits: 0 });
|
|
136
|
+
case "thousands_separator_decimal":
|
|
137
|
+
return num.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
138
|
+
case "one_decimal_decimal":
|
|
139
|
+
return num.toFixed(1);
|
|
140
|
+
case "two_decimal_decimal":
|
|
141
|
+
return num.toFixed(2);
|
|
142
|
+
case "three_decimal_decimal":
|
|
143
|
+
return num.toFixed(3);
|
|
144
|
+
case "four_decimal_decimal":
|
|
145
|
+
return num.toFixed(4);
|
|
146
|
+
case "five_decimal_decimal":
|
|
147
|
+
return num.toFixed(5);
|
|
148
|
+
case "six_decimal_decimal":
|
|
149
|
+
return num.toFixed(6);
|
|
150
|
+
case "percentage":
|
|
151
|
+
return `${Math.round(num * 100)}%`;
|
|
152
|
+
case "percentage_decimal":
|
|
153
|
+
return `${(num * 100).toFixed(2)}%`;
|
|
154
|
+
default:
|
|
155
|
+
return String(raw);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
dayjs.extend(duration);
|
|
160
|
+
function getSecondsTime(seconds) {
|
|
161
|
+
return dayjs.duration(typeof seconds === "number" ? seconds : parseInt(seconds), "seconds");
|
|
162
|
+
}
|
|
163
|
+
const formatDuration = (duration2) => {
|
|
164
|
+
const d = dayjs.duration(duration2, "seconds");
|
|
165
|
+
let formatStr = "s\u79D2";
|
|
166
|
+
if (d.minutes()) formatStr = "m\u5206s\u79D2";
|
|
167
|
+
if (d.hours()) formatStr = "H\u5C0F\u65F6m\u5206";
|
|
168
|
+
if (d.days()) formatStr = "D\u5929H\u5C0F\u65F6";
|
|
169
|
+
if (d.months()) formatStr = "M\u6708D\u5929";
|
|
170
|
+
if (d.years()) formatStr = "Y\u5E74M\u6708";
|
|
171
|
+
return d.format(formatStr);
|
|
172
|
+
};
|
|
173
|
+
const formatTime = (millisecond, isMatching = true) => {
|
|
174
|
+
let result = "";
|
|
175
|
+
const copyMillisecond = lodash.cloneDeep(millisecond);
|
|
176
|
+
millisecond /= 1e3;
|
|
177
|
+
const hours = Math.floor(millisecond / 3600);
|
|
178
|
+
const minutes = Math.floor(millisecond % 3600 / 60);
|
|
179
|
+
const seconds = Math.floor(millisecond % 60);
|
|
180
|
+
if (!isMatching && minutes > 0) {
|
|
181
|
+
if (hours > 0 && minutes < 60) return Number((hours + minutes / 60).toFixed(2)) + "\u5C0F\u65F6";
|
|
182
|
+
if (seconds > 0 && seconds < 60) return Number((minutes + seconds / 60).toFixed(2)) + "\u5206\u949F";
|
|
183
|
+
}
|
|
184
|
+
if (isMatching && hours <= 0 && minutes <= 0 && copyMillisecond < 1e3) return "<1\u79D2";
|
|
185
|
+
if (hours > 0) result += `${hours.toString().padStart(2, "")}\u5C0F\u65F6`;
|
|
186
|
+
if (minutes > 0) result += `${minutes.toString().padStart(2, "")}\u5206\u949F`;
|
|
187
|
+
if (seconds > 0) result += `${seconds.toString().padStart(2, "")}\u79D2`;
|
|
188
|
+
return result.trim();
|
|
189
|
+
};
|
|
190
|
+
const durationCalc = (secondsTime, unit) => {
|
|
191
|
+
let result = 0;
|
|
192
|
+
secondsTime = Number(secondsTime);
|
|
193
|
+
const hours = Number((secondsTime / 3600).toFixed(2));
|
|
194
|
+
const minutes = Number((secondsTime % 3600 / 60).toFixed(2));
|
|
195
|
+
const seconds = Number((secondsTime % 60).toFixed(2));
|
|
196
|
+
result = unit === "h" ? hours : unit === "m" ? minutes : seconds;
|
|
197
|
+
return result + "";
|
|
198
|
+
};
|
|
199
|
+
const TZ_LABEL = "GMT+8";
|
|
200
|
+
function parseDateFormat(format) {
|
|
201
|
+
const GMT_SUFFIX = " (GMT+8)";
|
|
202
|
+
if (format.endsWith(GMT_SUFFIX)) {
|
|
203
|
+
return {
|
|
204
|
+
baseFormat: format.replace(GMT_SUFFIX, ""),
|
|
205
|
+
showGmt8: true
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
baseFormat: format,
|
|
210
|
+
showGmt8: false
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function inferShowTimeFromFormat(format) {
|
|
214
|
+
const hasHour = /H|h/.test(format);
|
|
215
|
+
const hasMinute = /m/.test(format);
|
|
216
|
+
const hasSecond = /s/.test(format);
|
|
217
|
+
if (!hasHour && !hasMinute && !hasSecond) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
let timeFormat = "HH";
|
|
221
|
+
if (hasMinute) {
|
|
222
|
+
timeFormat = "HH:mm";
|
|
223
|
+
}
|
|
224
|
+
if (hasSecond) {
|
|
225
|
+
timeFormat = "HH:mm:ss";
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
format: timeFormat
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
exports.BORDER_COLOR = BORDER_COLOR;
|
|
233
|
+
exports.BORDER_LINE_WIDTH = BORDER_LINE_WIDTH;
|
|
234
|
+
exports.BORDER_SECONDARY_COLOR = BORDER_SECONDARY_COLOR;
|
|
235
|
+
exports.COLOR_BG_CELL = COLOR_BG_CELL;
|
|
236
|
+
exports.COLOR_BG_CELL_HOVER = COLOR_BG_CELL_HOVER;
|
|
237
|
+
exports.COLOR_BG_OPTION_HOVER = COLOR_BG_OPTION_HOVER;
|
|
238
|
+
exports.COLOR_BORDER_SELECTION = COLOR_BORDER_SELECTION;
|
|
239
|
+
exports.COLOR_ICON = COLOR_ICON;
|
|
240
|
+
exports.COLOR_LINK = COLOR_LINK;
|
|
241
|
+
exports.CUSTOM_CELL_FEEDBACK_ERROR_STYLE = CUSTOM_CELL_FEEDBACK_ERROR_STYLE;
|
|
242
|
+
exports.CUSTOM_CELL_FOCUS_STYLE = CUSTOM_CELL_FOCUS_STYLE;
|
|
243
|
+
exports.CUSTOM_CELL_STYLE = CUSTOM_CELL_STYLE;
|
|
244
|
+
exports.CUSTOM_CELL_STYLE_FEEDBACK_ERROR = CUSTOM_CELL_STYLE_FEEDBACK_ERROR;
|
|
245
|
+
exports.CUSTOM_CELL_STYLE_HIGHLIGHT = CUSTOM_CELL_STYLE_HIGHLIGHT;
|
|
246
|
+
exports.CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS = CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS;
|
|
247
|
+
exports.CUSTOM_STYLE_LIST = CUSTOM_STYLE_LIST;
|
|
248
|
+
exports.DEFAULT_FONT_SIZE = DEFAULT_FONT_SIZE;
|
|
249
|
+
exports.FeatureType = FeatureType;
|
|
250
|
+
exports.HEADER_FONT_SIZE = HEADER_FONT_SIZE;
|
|
251
|
+
exports.TABLE_DEFAULT_ROW_HEIGHT = TABLE_DEFAULT_ROW_HEIGHT;
|
|
252
|
+
exports.TOOL_ICON = TOOL_ICON;
|
|
253
|
+
exports.TZ_LABEL = TZ_LABEL;
|
|
254
|
+
exports.TableColumnInnerType = TableColumnInnerType;
|
|
255
|
+
exports.TableToolType = TableToolType;
|
|
256
|
+
exports.durationCalc = durationCalc;
|
|
257
|
+
exports.formatDuration = formatDuration;
|
|
258
|
+
exports.formatTime = formatTime;
|
|
259
|
+
exports.formatValue = formatValue;
|
|
260
|
+
exports.getColorByStr = getColorByStr;
|
|
261
|
+
exports.getSecondsTime = getSecondsTime;
|
|
262
|
+
exports.inferShowTimeFromFormat = inferShowTimeFromFormat;
|
|
263
|
+
exports.parseDateFormat = parseDateFormat;
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { RegistryKey } from '@enableai-fonts/font-icon-enableai-base';
|
|
3
|
+
import * as _visactor_vtable_es_ts_types from '@visactor/vtable/es/ts-types';
|
|
4
|
+
import { SelectEditorOption } from '@enableai-base/ui';
|
|
5
|
+
import duration from 'dayjs/plugin/duration';
|
|
6
|
+
|
|
7
|
+
export declare enum TableToolType {
|
|
8
|
+
TEXT = 28,
|
|
9
|
+
SIMPLE_SELECT = 29,
|
|
10
|
+
MULTI_SELECT = 30,
|
|
11
|
+
NUMBER = 31,
|
|
12
|
+
ATTACHMENT = 32,
|
|
13
|
+
LINK = 33,
|
|
14
|
+
JSON = 34,
|
|
15
|
+
TAG = 35,
|
|
16
|
+
DATE = 36,
|
|
17
|
+
TIME_LEN = 37,
|
|
18
|
+
USER = 38,
|
|
19
|
+
DROPDOWN = 39
|
|
20
|
+
}
|
|
21
|
+
export declare enum TableColumnInnerType {
|
|
22
|
+
CHECKBOX = -1,
|
|
23
|
+
MORE = -2,
|
|
24
|
+
PLUS = -3,
|
|
25
|
+
MAIN = -4
|
|
26
|
+
}
|
|
27
|
+
export declare const TOOL_ICON: Record<TableToolType, RegistryKey>;
|
|
28
|
+
|
|
29
|
+
export declare const BORDER_COLOR = "rgb(191, 194, 199)";
|
|
30
|
+
export declare const BORDER_SECONDARY_COLOR = "#f0f0f0";
|
|
31
|
+
export declare const COLOR_BG_CELL = "#ffffff";
|
|
32
|
+
export declare const COLOR_BG_CELL_HOVER = "rgb(244,244,244)";
|
|
33
|
+
export declare const COLOR_BORDER_SELECTION = "#1555F0";
|
|
34
|
+
export declare const COLOR_ICON = "rgb(96, 102, 111)";
|
|
35
|
+
export declare const COLOR_BG_OPTION_HOVER = "#1f232914";
|
|
36
|
+
export declare const DEFAULT_FONT_SIZE = 12;
|
|
37
|
+
export declare const HEADER_FONT_SIZE = 14;
|
|
38
|
+
export declare const TABLE_DEFAULT_ROW_HEIGHT = 30;
|
|
39
|
+
/**
|
|
40
|
+
* border 宽度,只能为1,否则会有问题
|
|
41
|
+
*/
|
|
42
|
+
export declare const BORDER_LINE_WIDTH = 1;
|
|
43
|
+
export declare const COLOR_LINK = "#1555F0";
|
|
44
|
+
export declare const CUSTOM_CELL_STYLE_HIGHLIGHT = "CUSTOM_CELL_STYLE_HIGHLIGHT";
|
|
45
|
+
export declare const CUSTOM_CELL_STYLE: {
|
|
46
|
+
id: string;
|
|
47
|
+
style: _visactor_vtable_es_ts_types.IStyleOption | _visactor_vtable_es_ts_types.ITextStyleOption | _visactor_vtable_es_ts_types.IImageStyleOption | _visactor_vtable_es_ts_types.ProgressBarStyleOption | _visactor_vtable_es_ts_types.CheckboxStyleOption;
|
|
48
|
+
};
|
|
49
|
+
export declare const CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS = "CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS";
|
|
50
|
+
export declare const CUSTOM_CELL_FOCUS_STYLE: {
|
|
51
|
+
id: string;
|
|
52
|
+
style: _visactor_vtable_es_ts_types.IStyleOption | _visactor_vtable_es_ts_types.ITextStyleOption | _visactor_vtable_es_ts_types.IImageStyleOption | _visactor_vtable_es_ts_types.ProgressBarStyleOption | _visactor_vtable_es_ts_types.CheckboxStyleOption;
|
|
53
|
+
};
|
|
54
|
+
export declare const CUSTOM_CELL_STYLE_FEEDBACK_ERROR = "CUSTOM_CELL_STYLE_FEEDBACK_ERROR";
|
|
55
|
+
export declare const CUSTOM_CELL_FEEDBACK_ERROR_STYLE: {
|
|
56
|
+
id: string;
|
|
57
|
+
style: _visactor_vtable_es_ts_types.IStyleOption | _visactor_vtable_es_ts_types.ITextStyleOption | _visactor_vtable_es_ts_types.IImageStyleOption | _visactor_vtable_es_ts_types.ProgressBarStyleOption | _visactor_vtable_es_ts_types.CheckboxStyleOption;
|
|
58
|
+
};
|
|
59
|
+
export type CustomCellStyleKey = typeof CUSTOM_CELL_STYLE_HIGHLIGHT | typeof CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS | typeof CUSTOM_CELL_STYLE_FEEDBACK_ERROR;
|
|
60
|
+
export declare const CUSTOM_STYLE_LIST: _visactor_vtable_es_ts_types.IStyleOption[];
|
|
61
|
+
|
|
62
|
+
export declare enum FeatureType {
|
|
63
|
+
SELECT = "select",
|
|
64
|
+
TYPE_SELECT = "type_select",
|
|
65
|
+
MULTI_SELECT = "multi_select",
|
|
66
|
+
INPUT = "input",
|
|
67
|
+
NUMBER = "number",
|
|
68
|
+
SWITCH = "switch",
|
|
69
|
+
CUSTOM_OPTION = "custom_option",
|
|
70
|
+
DATE_FORMATE = "date_format",
|
|
71
|
+
DATE_VALUE = "date_value"
|
|
72
|
+
}
|
|
73
|
+
export type FeatureValue = {
|
|
74
|
+
[FeatureType.INPUT]: string;
|
|
75
|
+
[FeatureType.SELECT]: number;
|
|
76
|
+
[FeatureType.TYPE_SELECT]: number;
|
|
77
|
+
[FeatureType.MULTI_SELECT]: number[];
|
|
78
|
+
[FeatureType.NUMBER]: number;
|
|
79
|
+
[FeatureType.SWITCH]: boolean;
|
|
80
|
+
[FeatureType.CUSTOM_OPTION]: {
|
|
81
|
+
label: string;
|
|
82
|
+
name: string;
|
|
83
|
+
}[];
|
|
84
|
+
[FeatureType.DATE_FORMATE]: string;
|
|
85
|
+
[FeatureType.DATE_VALUE]: string;
|
|
86
|
+
};
|
|
87
|
+
export type Feature<T extends FeatureType> = {
|
|
88
|
+
name: string;
|
|
89
|
+
label: string;
|
|
90
|
+
type?: T;
|
|
91
|
+
value: FeatureValue[T];
|
|
92
|
+
};
|
|
93
|
+
export type FeatureValues = Record<string, Feature<any>['value']>;
|
|
94
|
+
export type ColumnDefine = {
|
|
95
|
+
field: string;
|
|
96
|
+
title: string;
|
|
97
|
+
freeze?: boolean;
|
|
98
|
+
lock?: boolean;
|
|
99
|
+
tool: TableToolType;
|
|
100
|
+
defaultValue?: FeatureValues[FeatureType];
|
|
101
|
+
options?: SelectEditorOption[];
|
|
102
|
+
request?: (props: any) => Promise<any>;
|
|
103
|
+
fmt?: string;
|
|
104
|
+
};
|
|
105
|
+
export type FilterSelectOptions = {
|
|
106
|
+
value: string;
|
|
107
|
+
label: string;
|
|
108
|
+
[key: string]: any;
|
|
109
|
+
};
|
|
110
|
+
export type PersonItem = {
|
|
111
|
+
label: string;
|
|
112
|
+
value: string;
|
|
113
|
+
avatar?: string;
|
|
114
|
+
};
|
|
115
|
+
export type FilterColumnData = {
|
|
116
|
+
id: string;
|
|
117
|
+
label: string;
|
|
118
|
+
type: number;
|
|
119
|
+
options?: FilterSelectOptions[];
|
|
120
|
+
dateFormat?: string;
|
|
121
|
+
requestPeople?: (value?: string) => Promise<PersonItem[]>;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export type DateFormatType = 'YYYY/MM/DD' | 'YYYY/MM/DD HH:mm (GMT+8)' | 'YYYY-MM-DD' | 'YYYY-MM-DD HH:mm' | 'YYYY-MM-DD HH:mm (GMT+8)' | 'MM-DD' | 'MM/DD/YYYY' | 'DD/MM/YYYY' | 'YYYY/MM/DD HH:mm';
|
|
125
|
+
|
|
126
|
+
export type MenuInfo = {
|
|
127
|
+
key: string;
|
|
128
|
+
keyPath: string[];
|
|
129
|
+
domEvent: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export type NumberFormatType = 'integer' | 'thousands_separator' | 'thousands_separator_decimal' | 'one_decimal_decimal' | 'two_decimal_decimal' | 'three_decimal_decimal' | 'four_decimal_decimal' | 'five_decimal_decimal' | 'six_decimal_decimal' | 'percentage' | 'percentage_decimal';
|
|
133
|
+
|
|
134
|
+
export type TableConfig = {
|
|
135
|
+
customOptions: boolean | {
|
|
136
|
+
multiSelect: boolean;
|
|
137
|
+
};
|
|
138
|
+
numberSelect: boolean;
|
|
139
|
+
file: boolean;
|
|
140
|
+
tag: boolean;
|
|
141
|
+
date: boolean;
|
|
142
|
+
time: boolean;
|
|
143
|
+
people: boolean;
|
|
144
|
+
menu: boolean;
|
|
145
|
+
json: boolean;
|
|
146
|
+
defaultValue: boolean;
|
|
147
|
+
};
|
|
148
|
+
export type ToolConfig = {
|
|
149
|
+
label: string;
|
|
150
|
+
value: number;
|
|
151
|
+
iconfont: string;
|
|
152
|
+
table?: TableConfig;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export declare function getColorByStr(s?: string): string;
|
|
156
|
+
|
|
157
|
+
/** 数值格式化逻辑 */
|
|
158
|
+
export declare const formatValue: (raw: string | number, format: NumberFormatType) => string;
|
|
159
|
+
|
|
160
|
+
export declare function getSecondsTime(seconds: string | number): duration.Duration;
|
|
161
|
+
export declare const formatDuration: (duration: number) => string;
|
|
162
|
+
/**
|
|
163
|
+
* 将毫秒数转换为时分秒
|
|
164
|
+
* @param millisecond 毫秒
|
|
165
|
+
* @param isMatching 是否拼接 时分秒
|
|
166
|
+
*/
|
|
167
|
+
export declare const formatTime: (millisecond: number, isMatching?: boolean) => string;
|
|
168
|
+
export declare const durationCalc: (secondsTime: number, unit: string) => string;
|
|
169
|
+
export declare const TZ_LABEL = "GMT+8";
|
|
170
|
+
export declare function parseDateFormat(format: DateFormatType): {
|
|
171
|
+
baseFormat: string;
|
|
172
|
+
showGmt8: boolean;
|
|
173
|
+
};
|
|
174
|
+
type ShowTimeConfig = false | {
|
|
175
|
+
format: string;
|
|
176
|
+
};
|
|
177
|
+
export declare function inferShowTimeFromFormat(format: string): ShowTimeConfig;
|
|
178
|
+
|
|
179
|
+
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enableai-base/core v1.0.0
|
|
3
|
+
* (c) 2024-present Enableai
|
|
4
|
+
* @license Proprietary
|
|
5
|
+
**/
|
|
6
|
+
import { random, sum, cloneDeep } from 'lodash';
|
|
7
|
+
import dayjs from 'dayjs';
|
|
8
|
+
import duration from 'dayjs/plugin/duration';
|
|
9
|
+
|
|
10
|
+
const TableToolType = {
|
|
11
|
+
"TEXT": 28,
|
|
12
|
+
"28": "TEXT",
|
|
13
|
+
"SIMPLE_SELECT": 29,
|
|
14
|
+
"29": "SIMPLE_SELECT",
|
|
15
|
+
"MULTI_SELECT": 30,
|
|
16
|
+
"30": "MULTI_SELECT",
|
|
17
|
+
"NUMBER": 31,
|
|
18
|
+
"31": "NUMBER",
|
|
19
|
+
"ATTACHMENT": 32,
|
|
20
|
+
"32": "ATTACHMENT",
|
|
21
|
+
"LINK": 33,
|
|
22
|
+
"33": "LINK",
|
|
23
|
+
"JSON": 34,
|
|
24
|
+
"34": "JSON",
|
|
25
|
+
"TAG": 35,
|
|
26
|
+
"35": "TAG",
|
|
27
|
+
"DATE": 36,
|
|
28
|
+
"36": "DATE",
|
|
29
|
+
"TIME_LEN": 37,
|
|
30
|
+
"37": "TIME_LEN",
|
|
31
|
+
"USER": 38,
|
|
32
|
+
"38": "USER",
|
|
33
|
+
"DROPDOWN": 39,
|
|
34
|
+
"39": "DROPDOWN"
|
|
35
|
+
};
|
|
36
|
+
const TableColumnInnerType = {
|
|
37
|
+
"CHECKBOX": -1,
|
|
38
|
+
"-1": "CHECKBOX",
|
|
39
|
+
"MORE": -2,
|
|
40
|
+
"-2": "MORE",
|
|
41
|
+
"PLUS": -3,
|
|
42
|
+
"-3": "PLUS",
|
|
43
|
+
"MAIN": -4,
|
|
44
|
+
"-4": "MAIN"
|
|
45
|
+
};
|
|
46
|
+
const TOOL_ICON = {
|
|
47
|
+
[28]: "text",
|
|
48
|
+
[29]: "single",
|
|
49
|
+
[30]: "list",
|
|
50
|
+
[31]: "numbered",
|
|
51
|
+
[32]: "atachment",
|
|
52
|
+
[33]: "hyperlink",
|
|
53
|
+
[34]: "json",
|
|
54
|
+
[35]: "tag",
|
|
55
|
+
[36]: "date",
|
|
56
|
+
[37]: "duration",
|
|
57
|
+
[38]: "personnel",
|
|
58
|
+
[39]: "more"
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const BORDER_COLOR = "rgb(191, 194, 199)";
|
|
62
|
+
const BORDER_SECONDARY_COLOR = "#f0f0f0";
|
|
63
|
+
const COLOR_BG_CELL = "#ffffff";
|
|
64
|
+
const COLOR_BG_CELL_HOVER = "rgb(244,244,244)";
|
|
65
|
+
const COLOR_BORDER_SELECTION = "#1555F0";
|
|
66
|
+
const COLOR_ICON = "rgb(96, 102, 111)";
|
|
67
|
+
const COLOR_BG_OPTION_HOVER = "#1f232914";
|
|
68
|
+
const DEFAULT_FONT_SIZE = 12;
|
|
69
|
+
const HEADER_FONT_SIZE = 14;
|
|
70
|
+
const TABLE_DEFAULT_ROW_HEIGHT = 30;
|
|
71
|
+
const BORDER_LINE_WIDTH = 1;
|
|
72
|
+
const COLOR_LINK = "#1555F0";
|
|
73
|
+
const CUSTOM_CELL_STYLE_HIGHLIGHT = "CUSTOM_CELL_STYLE_HIGHLIGHT";
|
|
74
|
+
const CUSTOM_CELL_STYLE_HIGHLIGHT_STYLE = { bgColor: "#D0DDFC" };
|
|
75
|
+
const CUSTOM_CELL_STYLE = {
|
|
76
|
+
id: CUSTOM_CELL_STYLE_HIGHLIGHT,
|
|
77
|
+
style: CUSTOM_CELL_STYLE_HIGHLIGHT_STYLE
|
|
78
|
+
};
|
|
79
|
+
const CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS = "CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS";
|
|
80
|
+
const CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS_STYLE = {
|
|
81
|
+
bgColor: "#D0DDFC",
|
|
82
|
+
borderColor: COLOR_BORDER_SELECTION,
|
|
83
|
+
borderLineWidth: 3
|
|
84
|
+
};
|
|
85
|
+
const CUSTOM_CELL_FOCUS_STYLE = {
|
|
86
|
+
id: CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS,
|
|
87
|
+
style: CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS_STYLE
|
|
88
|
+
};
|
|
89
|
+
const CUSTOM_CELL_STYLE_FEEDBACK_ERROR = "CUSTOM_CELL_STYLE_FEEDBACK_ERROR";
|
|
90
|
+
const CUSTOM_CELL_STYLE_FEEDBACK_ERROR_STYLE = {
|
|
91
|
+
color: "red"
|
|
92
|
+
};
|
|
93
|
+
const CUSTOM_CELL_FEEDBACK_ERROR_STYLE = {
|
|
94
|
+
id: CUSTOM_CELL_STYLE_FEEDBACK_ERROR,
|
|
95
|
+
style: CUSTOM_CELL_STYLE_FEEDBACK_ERROR_STYLE
|
|
96
|
+
};
|
|
97
|
+
const CUSTOM_STYLE_LIST = [
|
|
98
|
+
CUSTOM_CELL_STYLE_HIGHLIGHT_STYLE,
|
|
99
|
+
CUSTOM_CELL_STYLE_FEEDBACK_ERROR_STYLE,
|
|
100
|
+
CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS_STYLE
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
const FeatureType = {
|
|
104
|
+
"SELECT": "select",
|
|
105
|
+
"TYPE_SELECT": "type_select",
|
|
106
|
+
"MULTI_SELECT": "multi_select",
|
|
107
|
+
"INPUT": "input",
|
|
108
|
+
"NUMBER": "number",
|
|
109
|
+
"SWITCH": "switch",
|
|
110
|
+
"CUSTOM_OPTION": "custom_option",
|
|
111
|
+
"DATE_FORMATE": "date_format",
|
|
112
|
+
"DATE_VALUE": "date_value"
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
function getColorByStr(s) {
|
|
116
|
+
let number = random(0, 360);
|
|
117
|
+
if (s) {
|
|
118
|
+
const codes = s.split("").map((i) => i.charCodeAt(0));
|
|
119
|
+
number = sum(codes) % 360;
|
|
120
|
+
}
|
|
121
|
+
return `hsl(${number} 100% 50%)`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const formatValue = (raw, format) => {
|
|
125
|
+
const num = typeof raw === "string" ? parseFloat(raw) : raw;
|
|
126
|
+
if (isNaN(num)) return "";
|
|
127
|
+
switch (format) {
|
|
128
|
+
case "integer":
|
|
129
|
+
return Math.round(num).toString();
|
|
130
|
+
case "thousands_separator":
|
|
131
|
+
return num.toLocaleString("en-US", { maximumFractionDigits: 0 });
|
|
132
|
+
case "thousands_separator_decimal":
|
|
133
|
+
return num.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
134
|
+
case "one_decimal_decimal":
|
|
135
|
+
return num.toFixed(1);
|
|
136
|
+
case "two_decimal_decimal":
|
|
137
|
+
return num.toFixed(2);
|
|
138
|
+
case "three_decimal_decimal":
|
|
139
|
+
return num.toFixed(3);
|
|
140
|
+
case "four_decimal_decimal":
|
|
141
|
+
return num.toFixed(4);
|
|
142
|
+
case "five_decimal_decimal":
|
|
143
|
+
return num.toFixed(5);
|
|
144
|
+
case "six_decimal_decimal":
|
|
145
|
+
return num.toFixed(6);
|
|
146
|
+
case "percentage":
|
|
147
|
+
return `${Math.round(num * 100)}%`;
|
|
148
|
+
case "percentage_decimal":
|
|
149
|
+
return `${(num * 100).toFixed(2)}%`;
|
|
150
|
+
default:
|
|
151
|
+
return String(raw);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
dayjs.extend(duration);
|
|
156
|
+
function getSecondsTime(seconds) {
|
|
157
|
+
return dayjs.duration(typeof seconds === "number" ? seconds : parseInt(seconds), "seconds");
|
|
158
|
+
}
|
|
159
|
+
const formatDuration = (duration2) => {
|
|
160
|
+
const d = dayjs.duration(duration2, "seconds");
|
|
161
|
+
let formatStr = "s\u79D2";
|
|
162
|
+
if (d.minutes()) formatStr = "m\u5206s\u79D2";
|
|
163
|
+
if (d.hours()) formatStr = "H\u5C0F\u65F6m\u5206";
|
|
164
|
+
if (d.days()) formatStr = "D\u5929H\u5C0F\u65F6";
|
|
165
|
+
if (d.months()) formatStr = "M\u6708D\u5929";
|
|
166
|
+
if (d.years()) formatStr = "Y\u5E74M\u6708";
|
|
167
|
+
return d.format(formatStr);
|
|
168
|
+
};
|
|
169
|
+
const formatTime = (millisecond, isMatching = true) => {
|
|
170
|
+
let result = "";
|
|
171
|
+
const copyMillisecond = cloneDeep(millisecond);
|
|
172
|
+
millisecond /= 1e3;
|
|
173
|
+
const hours = Math.floor(millisecond / 3600);
|
|
174
|
+
const minutes = Math.floor(millisecond % 3600 / 60);
|
|
175
|
+
const seconds = Math.floor(millisecond % 60);
|
|
176
|
+
if (!isMatching && minutes > 0) {
|
|
177
|
+
if (hours > 0 && minutes < 60) return Number((hours + minutes / 60).toFixed(2)) + "\u5C0F\u65F6";
|
|
178
|
+
if (seconds > 0 && seconds < 60) return Number((minutes + seconds / 60).toFixed(2)) + "\u5206\u949F";
|
|
179
|
+
}
|
|
180
|
+
if (isMatching && hours <= 0 && minutes <= 0 && copyMillisecond < 1e3) return "<1\u79D2";
|
|
181
|
+
if (hours > 0) result += `${hours.toString().padStart(2, "")}\u5C0F\u65F6`;
|
|
182
|
+
if (minutes > 0) result += `${minutes.toString().padStart(2, "")}\u5206\u949F`;
|
|
183
|
+
if (seconds > 0) result += `${seconds.toString().padStart(2, "")}\u79D2`;
|
|
184
|
+
return result.trim();
|
|
185
|
+
};
|
|
186
|
+
const durationCalc = (secondsTime, unit) => {
|
|
187
|
+
let result = 0;
|
|
188
|
+
secondsTime = Number(secondsTime);
|
|
189
|
+
const hours = Number((secondsTime / 3600).toFixed(2));
|
|
190
|
+
const minutes = Number((secondsTime % 3600 / 60).toFixed(2));
|
|
191
|
+
const seconds = Number((secondsTime % 60).toFixed(2));
|
|
192
|
+
result = unit === "h" ? hours : unit === "m" ? minutes : seconds;
|
|
193
|
+
return result + "";
|
|
194
|
+
};
|
|
195
|
+
const TZ_LABEL = "GMT+8";
|
|
196
|
+
function parseDateFormat(format) {
|
|
197
|
+
const GMT_SUFFIX = " (GMT+8)";
|
|
198
|
+
if (format.endsWith(GMT_SUFFIX)) {
|
|
199
|
+
return {
|
|
200
|
+
baseFormat: format.replace(GMT_SUFFIX, ""),
|
|
201
|
+
showGmt8: true
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
baseFormat: format,
|
|
206
|
+
showGmt8: false
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function inferShowTimeFromFormat(format) {
|
|
210
|
+
const hasHour = /H|h/.test(format);
|
|
211
|
+
const hasMinute = /m/.test(format);
|
|
212
|
+
const hasSecond = /s/.test(format);
|
|
213
|
+
if (!hasHour && !hasMinute && !hasSecond) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
let timeFormat = "HH";
|
|
217
|
+
if (hasMinute) {
|
|
218
|
+
timeFormat = "HH:mm";
|
|
219
|
+
}
|
|
220
|
+
if (hasSecond) {
|
|
221
|
+
timeFormat = "HH:mm:ss";
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
format: timeFormat
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { BORDER_COLOR, BORDER_LINE_WIDTH, BORDER_SECONDARY_COLOR, COLOR_BG_CELL, COLOR_BG_CELL_HOVER, COLOR_BG_OPTION_HOVER, COLOR_BORDER_SELECTION, COLOR_ICON, COLOR_LINK, CUSTOM_CELL_FEEDBACK_ERROR_STYLE, CUSTOM_CELL_FOCUS_STYLE, CUSTOM_CELL_STYLE, CUSTOM_CELL_STYLE_FEEDBACK_ERROR, CUSTOM_CELL_STYLE_HIGHLIGHT, CUSTOM_CELL_STYLE_HIGHLIGHT_FOCUS, CUSTOM_STYLE_LIST, DEFAULT_FONT_SIZE, FeatureType, HEADER_FONT_SIZE, TABLE_DEFAULT_ROW_HEIGHT, TOOL_ICON, TZ_LABEL, TableColumnInnerType, TableToolType, durationCalc, formatDuration, formatTime, formatValue, getColorByStr, getSecondsTime, inferShowTimeFromFormat, parseDateFormat };
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@enableai-base/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"order": 1,
|
|
5
|
+
"description": "",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"types": "dist/core.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"index.node.js",
|
|
11
|
+
"index.js"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/core.d.ts",
|
|
16
|
+
"module": "./dist/core.esm-bundler.mjs",
|
|
17
|
+
"import": "./dist/core.esm-bundler.mjs",
|
|
18
|
+
"require": "./index.js"
|
|
19
|
+
},
|
|
20
|
+
"./*": "./*"
|
|
21
|
+
},
|
|
22
|
+
"buildOptions": {
|
|
23
|
+
"name": "core",
|
|
24
|
+
"formats": [
|
|
25
|
+
"esm-bundler",
|
|
26
|
+
"cjs"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"keywords": [],
|
|
30
|
+
"license": "Proprietary",
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@enableai-sdk-common/react-hooks": "workspace:*"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@visactor/vtable": "1.22.10",
|
|
36
|
+
"@enableai-fonts/font-icon-enableai-base": "0.1.3",
|
|
37
|
+
"lodash": "^4.17.21",
|
|
38
|
+
"dayjs": "^1.11.13"
|
|
39
|
+
}
|
|
40
|
+
}
|