@fixefy/fixefy-ui-utils 0.0.1
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-cjs/commander/commander.jsx +284 -0
- package/dist-cjs/commander/index.js +4 -0
- package/dist-cjs/constants/index.js +87 -0
- package/dist-cjs/package.json +3 -0
- package/dist-cjs/page_context/index.js +494 -0
- package/dist-es/commander/commander.jsx +254 -0
- package/dist-es/commander/index.js +1 -0
- package/dist-es/constants/index.js +84 -0
- package/dist-es/package.json +3 -0
- package/dist-es/page_context/index.js +511 -0
- package/dist-types/commander/commander.d.ts +33 -0
- package/dist-types/commander/index.d.ts +1 -0
- package/dist-types/constants/index.d.ts +6 -0
- package/dist-types/page_context/index.d.ts +248 -0
- package/package.json +60 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getScoreColor = exports.useStatePromisify = exports.trimRuleCode = exports.toWords = exports.toPascalCase = exports.toInitials = exports.toCurrency = exports.toCamelCaseString = exports.toCamelCase = exports.titleCase = exports.normalizeStringBodyRaw = exports.normalizeTimestamp = exports.nest = exports.makeString = exports.lineString = exports.isValidTimestamp = exports.isInServer = exports.getVal = exports.getStringValueByValueType = exports.getNormalizationKeyForEntity = exports.formatNumberWithCommas = exports.determineIconByEvent = exports.convertToString = exports.copyToClipboard = exports.buildCode = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fixefy_numeric_1 = tslib_1.__importDefault(require("@fixefy/fixefy-numeric"));
|
|
6
|
+
const date_fns_1 = require("date-fns");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
function buildCode(obj, level = 0, name) {
|
|
10
|
+
const toRender = [];
|
|
11
|
+
const keys = Object.keys(obj);
|
|
12
|
+
if (keys.length < 1) {
|
|
13
|
+
toRender.push(lineString(level, name) + "{}");
|
|
14
|
+
return toRender;
|
|
15
|
+
}
|
|
16
|
+
toRender.push(lineString(level, name) + "{");
|
|
17
|
+
keys.forEach((key) => {
|
|
18
|
+
if (key === "__typename")
|
|
19
|
+
return;
|
|
20
|
+
if (typeof obj[key] === "object" && obj[key] !== null) {
|
|
21
|
+
toRender.push(...buildCode(obj[key], level + 1, key));
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const val = getVal(obj[key]);
|
|
25
|
+
toRender.push(lineString(level + 1, key) + val);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
toRender.push(lineString(level) + "}");
|
|
29
|
+
return toRender;
|
|
30
|
+
}
|
|
31
|
+
exports.buildCode = buildCode;
|
|
32
|
+
const copyToClipboard = (str) => {
|
|
33
|
+
if (window == undefined)
|
|
34
|
+
return;
|
|
35
|
+
const el = document.createElement("textarea");
|
|
36
|
+
el.value = str;
|
|
37
|
+
el.setAttribute("readonly", "");
|
|
38
|
+
el.style.position = "absolute";
|
|
39
|
+
el.style.left = "-9999px";
|
|
40
|
+
document.body.appendChild(el);
|
|
41
|
+
el.select();
|
|
42
|
+
document.execCommand("copy");
|
|
43
|
+
document.body.removeChild(el);
|
|
44
|
+
};
|
|
45
|
+
exports.copyToClipboard = copyToClipboard;
|
|
46
|
+
function convertToString(input) {
|
|
47
|
+
if (input) {
|
|
48
|
+
return typeof input === "string" ? input : String(input);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.convertToString = convertToString;
|
|
52
|
+
const determineIconByEvent = (event) => {
|
|
53
|
+
let rv;
|
|
54
|
+
if (event) {
|
|
55
|
+
switch (event.type) {
|
|
56
|
+
case "charged":
|
|
57
|
+
rv = "../../static/images/transactions/billing.svg";
|
|
58
|
+
break;
|
|
59
|
+
case "packed":
|
|
60
|
+
rv = "../../static/images/transactions/system.svg";
|
|
61
|
+
break;
|
|
62
|
+
default:
|
|
63
|
+
rv = "../../static/images/transactions/user.svg";
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return rv;
|
|
68
|
+
};
|
|
69
|
+
exports.determineIconByEvent = determineIconByEvent;
|
|
70
|
+
function formatNumberWithCommas(number) {
|
|
71
|
+
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
72
|
+
}
|
|
73
|
+
exports.formatNumberWithCommas = formatNumberWithCommas;
|
|
74
|
+
function getNormalizationKeyForEntity(entity_type) {
|
|
75
|
+
let rv;
|
|
76
|
+
switch (entity_type.toLowerCase()) {
|
|
77
|
+
case constants_1.EntityTypes.User:
|
|
78
|
+
rv = "username";
|
|
79
|
+
break;
|
|
80
|
+
case constants_1.EntityTypes.Pricing:
|
|
81
|
+
rv = "value";
|
|
82
|
+
break;
|
|
83
|
+
case constants_1.EntityTypes.Metadata:
|
|
84
|
+
rv = "title";
|
|
85
|
+
break;
|
|
86
|
+
case constants_1.EntityTypes.Transaction:
|
|
87
|
+
case constants_1.EntityTypes.Transmission:
|
|
88
|
+
rv = "readable_id";
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
rv = "title";
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
return rv;
|
|
95
|
+
}
|
|
96
|
+
exports.getNormalizationKeyForEntity = getNormalizationKeyForEntity;
|
|
97
|
+
const getStringValueByValueType = ({ value, name }) => {
|
|
98
|
+
let rv;
|
|
99
|
+
switch (typeof value) {
|
|
100
|
+
case "boolean":
|
|
101
|
+
rv = value === true ? "YES" : "NO";
|
|
102
|
+
break;
|
|
103
|
+
case "number":
|
|
104
|
+
if ((0, exports.isValidTimestamp)(value)) {
|
|
105
|
+
rv = normalizeTimestamp(value, false);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
let _rv = Number(value) === value && value % 1 === 0 ? value : value.toFixed(2);
|
|
109
|
+
if (name === "variance") {
|
|
110
|
+
_rv = (_rv * 100).toFixed(1);
|
|
111
|
+
rv = `${_rv}%`;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
rv = _rv;
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
case "object":
|
|
118
|
+
if (Array.isArray(value)) {
|
|
119
|
+
rv = value.join(", ");
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
const entity_type = value && value.__typename && value.__typename.toLowerCase();
|
|
123
|
+
rv = titleCase(value[getNormalizationKeyForEntity(entity_type)]);
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
case "string":
|
|
127
|
+
rv = titleCase(value);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
return rv;
|
|
131
|
+
};
|
|
132
|
+
exports.getStringValueByValueType = getStringValueByValueType;
|
|
133
|
+
function getVal(val) {
|
|
134
|
+
if (typeof val === "number")
|
|
135
|
+
return val;
|
|
136
|
+
if (typeof val === "string")
|
|
137
|
+
return `"${val}"`;
|
|
138
|
+
return val;
|
|
139
|
+
}
|
|
140
|
+
exports.getVal = getVal;
|
|
141
|
+
const isInServer = () => typeof window === "undefined";
|
|
142
|
+
exports.isInServer = isInServer;
|
|
143
|
+
const isValidTimestamp = (_timestamp) => {
|
|
144
|
+
const parsedNumber = typeof _timestamp == "string" ? parseInt(_timestamp) : _timestamp;
|
|
145
|
+
const newTimestamp = new Date(parsedNumber).getTime();
|
|
146
|
+
const rv = fixefy_numeric_1.default.isFloat(newTimestamp) && newTimestamp.toString().length >= 10;
|
|
147
|
+
return rv;
|
|
148
|
+
};
|
|
149
|
+
exports.isValidTimestamp = isValidTimestamp;
|
|
150
|
+
function lineString(level, name) {
|
|
151
|
+
let str = "";
|
|
152
|
+
for (let i = 0; i < level; i++) {
|
|
153
|
+
str += " ";
|
|
154
|
+
}
|
|
155
|
+
if (name) {
|
|
156
|
+
str += name + ": ";
|
|
157
|
+
}
|
|
158
|
+
return str;
|
|
159
|
+
}
|
|
160
|
+
exports.lineString = lineString;
|
|
161
|
+
function makeString(len = 5) {
|
|
162
|
+
var text = "";
|
|
163
|
+
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
164
|
+
for (var i = 0; i < len; i++)
|
|
165
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
166
|
+
return text;
|
|
167
|
+
}
|
|
168
|
+
exports.makeString = makeString;
|
|
169
|
+
const nest = ({ items }) => {
|
|
170
|
+
let mappedArray = Object.create(null);
|
|
171
|
+
items.forEach((item) => (mappedArray[item.id] = Object.assign(Object.assign({}, item), { children: [] })));
|
|
172
|
+
let nestedArray = [];
|
|
173
|
+
items.forEach((item) => {
|
|
174
|
+
if (item) {
|
|
175
|
+
if (item.parent)
|
|
176
|
+
mappedArray[item.parent] &&
|
|
177
|
+
mappedArray[item.parent].children.push(mappedArray[item.id]);
|
|
178
|
+
else
|
|
179
|
+
nestedArray.push(mappedArray[item.id]);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return nestedArray;
|
|
183
|
+
};
|
|
184
|
+
exports.nest = nest;
|
|
185
|
+
function normalizeTimestamp(timestamp, options) {
|
|
186
|
+
const { dateOnly, format: _format } = options || {};
|
|
187
|
+
const _timestamp = typeof timestamp == "string" ? parseInt(timestamp) : timestamp;
|
|
188
|
+
const rv = (0, date_fns_1.format)(new Date(_timestamp), _format ? _format : dateOnly ? "dd/MM/yyyy" : "dd/MM/yyyy hh:mm");
|
|
189
|
+
return rv;
|
|
190
|
+
}
|
|
191
|
+
exports.normalizeTimestamp = normalizeTimestamp;
|
|
192
|
+
function normalizeStringBodyRaw(key, body) {
|
|
193
|
+
return typeof body[key] === "string" && (key === "body" || key === "raw")
|
|
194
|
+
? JSON.parse(body[key])
|
|
195
|
+
: body[key];
|
|
196
|
+
}
|
|
197
|
+
exports.normalizeStringBodyRaw = normalizeStringBodyRaw;
|
|
198
|
+
function titleCase(str = "") {
|
|
199
|
+
return str && toPascalCase(str.toString(), true);
|
|
200
|
+
}
|
|
201
|
+
exports.titleCase = titleCase;
|
|
202
|
+
function toCamelCase(inputArray) {
|
|
203
|
+
var _a;
|
|
204
|
+
let result = "";
|
|
205
|
+
for (let i = 0, len = (_a = inputArray === null || inputArray === void 0 ? void 0 : inputArray.length) !== null && _a !== void 0 ? _a : 0; i < len; i++) {
|
|
206
|
+
let currentStr = inputArray === null || inputArray === void 0 ? void 0 : inputArray.at(i);
|
|
207
|
+
let tempStr = currentStr.toLowerCase();
|
|
208
|
+
if (i != 0) {
|
|
209
|
+
tempStr = tempStr.substr(0, 1).toUpperCase() + tempStr.substr(1);
|
|
210
|
+
}
|
|
211
|
+
result += tempStr;
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
exports.toCamelCase = toCamelCase;
|
|
216
|
+
function toCamelCaseString(input) {
|
|
217
|
+
const words = toWords(input);
|
|
218
|
+
return toCamelCase(words);
|
|
219
|
+
}
|
|
220
|
+
exports.toCamelCaseString = toCamelCaseString;
|
|
221
|
+
const toCurrency = (input) => {
|
|
222
|
+
return input ? input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : input;
|
|
223
|
+
};
|
|
224
|
+
exports.toCurrency = toCurrency;
|
|
225
|
+
const toInitials = (str) => {
|
|
226
|
+
if (str === "")
|
|
227
|
+
return str;
|
|
228
|
+
var matches = str.match(/\b(\w)/g);
|
|
229
|
+
return matches === null || matches === void 0 ? void 0 : matches.join("").toUpperCase();
|
|
230
|
+
};
|
|
231
|
+
exports.toInitials = toInitials;
|
|
232
|
+
function toPascalCase(string, title = false) {
|
|
233
|
+
return (string &&
|
|
234
|
+
string.replace(/(_[a-z])?(^[a-z])?(_|\s[a-z])?/g, ($1) => $1.toUpperCase().replace("_", title ? " " : "")));
|
|
235
|
+
}
|
|
236
|
+
exports.toPascalCase = toPascalCase;
|
|
237
|
+
function toWords(input) {
|
|
238
|
+
input = convertToString(input);
|
|
239
|
+
const regex = /[A-Z\xC0-\xD6\xD8-\xDE]?[a-z\xDF-\xF6\xF8-\xFF]+|[A-Z\xC0-\xD6\xD8-\xDE]+(?![a-z\xDF-\xF6\xF8-\xFF])|\d+/g;
|
|
240
|
+
return input === null || input === void 0 ? void 0 : input.match(regex);
|
|
241
|
+
}
|
|
242
|
+
exports.toWords = toWords;
|
|
243
|
+
function trimRuleCode(input) {
|
|
244
|
+
const stringefied = typeof input == "string" ? input : JSON.stringify(input);
|
|
245
|
+
let match = stringefied.substring(stringefied.indexOf("{") + 1, stringefied.lastIndexOf("}"));
|
|
246
|
+
return match ? match : "";
|
|
247
|
+
}
|
|
248
|
+
exports.trimRuleCode = trimRuleCode;
|
|
249
|
+
const useStatePromisify = (_state) => {
|
|
250
|
+
const [state, setState] = (0, react_1.useState)(_state);
|
|
251
|
+
const resolverRef = (0, react_1.useRef)(null);
|
|
252
|
+
(0, react_1.useEffect)(() => {
|
|
253
|
+
if (resolverRef.current) {
|
|
254
|
+
resolverRef.current(state);
|
|
255
|
+
resolverRef.current = null;
|
|
256
|
+
}
|
|
257
|
+
}, [resolverRef.current, state]);
|
|
258
|
+
const handleSetState = (0, react_1.useCallback)((stateAction) => {
|
|
259
|
+
setState(stateAction);
|
|
260
|
+
return new Promise((resolve) => {
|
|
261
|
+
resolverRef.current = resolve;
|
|
262
|
+
});
|
|
263
|
+
}, [setState]);
|
|
264
|
+
return [state, handleSetState];
|
|
265
|
+
};
|
|
266
|
+
exports.useStatePromisify = useStatePromisify;
|
|
267
|
+
const getScoreColor = (value) => {
|
|
268
|
+
if (value <= 20) {
|
|
269
|
+
return "bad";
|
|
270
|
+
}
|
|
271
|
+
else if (value <= 40) {
|
|
272
|
+
return "low";
|
|
273
|
+
}
|
|
274
|
+
else if (value <= 60) {
|
|
275
|
+
return "medium";
|
|
276
|
+
}
|
|
277
|
+
else if (value <= 80) {
|
|
278
|
+
return "high";
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
return "excellent";
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
exports.getScoreColor = getScoreColor;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InputTypes = exports.FilterOperatorType = exports.EntityTypes = exports.DataTypes = exports.ComponentTypes = exports.ColumnInputTypes = void 0;
|
|
4
|
+
exports.ColumnInputTypes = {
|
|
5
|
+
Array: "array",
|
|
6
|
+
Avatar: "avatar",
|
|
7
|
+
Country: "country",
|
|
8
|
+
Currency: "currency",
|
|
9
|
+
Date: "date",
|
|
10
|
+
Done: "done",
|
|
11
|
+
ID: "id",
|
|
12
|
+
IncoTerm: "incoterm",
|
|
13
|
+
Link: "link",
|
|
14
|
+
Percentage: "percentage",
|
|
15
|
+
Price: "price",
|
|
16
|
+
Progress: "progress",
|
|
17
|
+
Score: "score",
|
|
18
|
+
Status: "status",
|
|
19
|
+
String: "string",
|
|
20
|
+
Measure: "measure",
|
|
21
|
+
};
|
|
22
|
+
exports.ComponentTypes = {
|
|
23
|
+
ActionTrey: "action_trey",
|
|
24
|
+
AsyncDropdown: "async_dropdown",
|
|
25
|
+
Chip: "chip",
|
|
26
|
+
ClickableLabel: "clickable_label",
|
|
27
|
+
CollapsableDropdown: "collapsable_dropdown",
|
|
28
|
+
Container: "container",
|
|
29
|
+
DateRange: "date_range",
|
|
30
|
+
Dropdown: "dropdown",
|
|
31
|
+
Label: "label",
|
|
32
|
+
Modal: "modal",
|
|
33
|
+
RangeSlider: "range_slider",
|
|
34
|
+
TableColumn: "table_column",
|
|
35
|
+
Textfield: "textfield",
|
|
36
|
+
StaticDropdown: "static_dropdown",
|
|
37
|
+
dropdownOptions: "dropdownOptions",
|
|
38
|
+
clear: "clear",
|
|
39
|
+
};
|
|
40
|
+
exports.DataTypes = {
|
|
41
|
+
CSV: "csv",
|
|
42
|
+
EDI: "edi",
|
|
43
|
+
JSON: "json",
|
|
44
|
+
PDF: "pdf",
|
|
45
|
+
XLS: "xls",
|
|
46
|
+
XML: "xml",
|
|
47
|
+
};
|
|
48
|
+
exports.EntityTypes = {
|
|
49
|
+
Block: "block",
|
|
50
|
+
Charge: "charge",
|
|
51
|
+
Contract: "contract",
|
|
52
|
+
Event: "event",
|
|
53
|
+
Metadata: "metadata",
|
|
54
|
+
Notification: "notification",
|
|
55
|
+
Pricing: "pricing",
|
|
56
|
+
Service: "service",
|
|
57
|
+
Structure: "structure",
|
|
58
|
+
Transaction: "transaction",
|
|
59
|
+
Transmission: "transmission",
|
|
60
|
+
User: "user",
|
|
61
|
+
Workspace: "workspace",
|
|
62
|
+
};
|
|
63
|
+
exports.FilterOperatorType = {
|
|
64
|
+
Contains: "contains",
|
|
65
|
+
NotContains: "NotContains",
|
|
66
|
+
Equals: "equals",
|
|
67
|
+
EndsWith: "endsWith",
|
|
68
|
+
IsAfter: "after",
|
|
69
|
+
IsBefore: "before",
|
|
70
|
+
Is: "is",
|
|
71
|
+
IsNot: "not",
|
|
72
|
+
In: "in",
|
|
73
|
+
NotIn: "notIn",
|
|
74
|
+
StartsWith: "startsWith",
|
|
75
|
+
GreaterThan: ">",
|
|
76
|
+
GreaterThanEqual: ">=",
|
|
77
|
+
LessThan: "<",
|
|
78
|
+
LessThanEqual: "<=",
|
|
79
|
+
};
|
|
80
|
+
exports.InputTypes = {
|
|
81
|
+
Currency: "currency",
|
|
82
|
+
Date: "date",
|
|
83
|
+
Link: "link",
|
|
84
|
+
Password: "password",
|
|
85
|
+
Percent: "percent",
|
|
86
|
+
Text: "text",
|
|
87
|
+
};
|