asab_webui_components 26.1.5 → 26.1.7
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/components/CopyableInput/CopyableInput.js +78 -0
- package/dist/components/CopyableInput/CopyableInput.scss +5 -0
- package/dist/components/DateTime/utils/validateDateTime.js +11 -0
- package/dist/components/DateTime/utils/validateDateTime.jsx +12 -0
- package/dist/index.js +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.CopyableInput = void 0;
|
|
8
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reactI18next = require("react-i18next");
|
|
11
|
+
var _reactstrap = require("reactstrap");
|
|
12
|
+
require("./CopyableInput.scss");
|
|
13
|
+
var _excluded = ["value"];
|
|
14
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
15
|
+
/*
|
|
16
|
+
Read-only text area component that displays a value with a copy button
|
|
17
|
+
|
|
18
|
+
Props:
|
|
19
|
+
value: Component value to be displayed and copied
|
|
20
|
+
...props: Props to pass to the InputGroup child component
|
|
21
|
+
|
|
22
|
+
Usage:
|
|
23
|
+
import { CopyableInput } from 'asab_webui_components';
|
|
24
|
+
|
|
25
|
+
const generatedUrl = 'https://example.com/somesecret?token=c29tZXNlY3JldAo';
|
|
26
|
+
...
|
|
27
|
+
|
|
28
|
+
<CopyableInput
|
|
29
|
+
value={generatedUrl}
|
|
30
|
+
className='my-2'
|
|
31
|
+
/>
|
|
32
|
+
*/
|
|
33
|
+
var CopyableInput = _ref => {
|
|
34
|
+
var {
|
|
35
|
+
value
|
|
36
|
+
} = _ref,
|
|
37
|
+
props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
38
|
+
var {
|
|
39
|
+
t
|
|
40
|
+
} = (0, _reactI18next.useTranslation)();
|
|
41
|
+
var [valueCopied, setValueCopied] = (0, _react.useState)(false);
|
|
42
|
+
var timeoutRef = (0, _react.useRef)(null);
|
|
43
|
+
(0, _react.useEffect)(() => {
|
|
44
|
+
return () => {
|
|
45
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
46
|
+
};
|
|
47
|
+
}, []);
|
|
48
|
+
|
|
49
|
+
// Copy the value to clipboard and change the button label for a short time as a visual feedback
|
|
50
|
+
var copyValue = () => {
|
|
51
|
+
if (!value) {
|
|
52
|
+
console.error('No input value to copy.');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
navigator.clipboard.writeText(value).then(() => {
|
|
56
|
+
setValueCopied(true);
|
|
57
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
58
|
+
timeoutRef.current = setTimeout(() => setValueCopied(false), 3000);
|
|
59
|
+
}).catch(error => {
|
|
60
|
+
console.error('Failed to copy input value: ', error);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
return /*#__PURE__*/_react.default.createElement(_reactstrap.InputGroup, props, /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
|
|
64
|
+
readOnly: true,
|
|
65
|
+
value: value,
|
|
66
|
+
type: "textarea",
|
|
67
|
+
className: "asab-copyable-input"
|
|
68
|
+
}), /*#__PURE__*/_react.default.createElement(_reactstrap.Button, {
|
|
69
|
+
outline: true,
|
|
70
|
+
title: t('General|Copy to clipboard'),
|
|
71
|
+
color: "primary",
|
|
72
|
+
className: "text-nowrap border",
|
|
73
|
+
onClick: copyValue
|
|
74
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
75
|
+
className: valueCopied ? 'bi bi-clipboard-check pe-2' : 'bi bi-clipboard pe-2'
|
|
76
|
+
}), valueCopied ? t('General|Copied!') : t('General|Copy')));
|
|
77
|
+
};
|
|
78
|
+
exports.CopyableInput = CopyableInput;
|
|
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.validateDateTime = validateDateTime;
|
|
7
|
+
// For best performance, create a regular expression only once.
|
|
8
|
+
var n_digits = /^\d+n$/;
|
|
7
9
|
function validateDateTime(value) {
|
|
8
10
|
// Return 'Invalid Date' if the input is null or undefined
|
|
9
11
|
if (value == null) {
|
|
@@ -18,6 +20,15 @@ function validateDateTime(value) {
|
|
|
18
20
|
|
|
19
21
|
// Handle string values
|
|
20
22
|
if (typeof value === 'string') {
|
|
23
|
+
// Check if string ends with 'n' AND verify the entire string consists only of digits followed by 'n'
|
|
24
|
+
if (value.endsWith('n') && n_digits.test(value)) {
|
|
25
|
+
try {
|
|
26
|
+
// Remove the 'n' suffix before converting to BigInt
|
|
27
|
+
return splDatetimeToIso(BigInt(value.slice(0, -1)));
|
|
28
|
+
} catch (_unused) {
|
|
29
|
+
return 'Invalid Date';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
21
32
|
return new Date(value);
|
|
22
33
|
}
|
|
23
34
|
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// For best performance, create a regular expression only once.
|
|
2
|
+
const n_digits = /^\d+n$/;
|
|
3
|
+
|
|
1
4
|
export function validateDateTime(value) {
|
|
2
5
|
// Return 'Invalid Date' if the input is null or undefined
|
|
3
6
|
if (value == null) {
|
|
@@ -12,6 +15,15 @@ export function validateDateTime(value) {
|
|
|
12
15
|
|
|
13
16
|
// Handle string values
|
|
14
17
|
if (typeof value === 'string') {
|
|
18
|
+
// Check if string ends with 'n' AND verify the entire string consists only of digits followed by 'n'
|
|
19
|
+
if (value.endsWith('n') && n_digits.test(value)) {
|
|
20
|
+
try {
|
|
21
|
+
// Remove the 'n' suffix before converting to BigInt
|
|
22
|
+
return splDatetimeToIso(BigInt(value.slice(0, -1)));
|
|
23
|
+
} catch {
|
|
24
|
+
return 'Invalid Date';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
15
27
|
return new Date(value);
|
|
16
28
|
}
|
|
17
29
|
|
package/dist/index.js
CHANGED
|
@@ -52,6 +52,12 @@ Object.defineProperty(exports, "ControlledSwitch", {
|
|
|
52
52
|
return _ControlledSwitch.default;
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
|
+
Object.defineProperty(exports, "CopyableInput", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function get() {
|
|
58
|
+
return _CopyableInput.CopyableInput;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
55
61
|
Object.defineProperty(exports, "DataTable", {
|
|
56
62
|
enumerable: true,
|
|
57
63
|
get: function get() {
|
|
@@ -353,5 +359,6 @@ var _FlowbiteIllustration = require("./components/FlowbiteIllustration.js");
|
|
|
353
359
|
var _PubSubContext = require("./components/Context/PubSubContext");
|
|
354
360
|
var _AppStore = require("./components/Context/store/AppStore.js");
|
|
355
361
|
var _reducerRegistry = require("./components/Context/store/reducer/reducerRegistry.js");
|
|
362
|
+
var _CopyableInput = require("./components/CopyableInput/CopyableInput");
|
|
356
363
|
var _Pagination = _interopRequireDefault(require("./components/DataTable/Pagination"));
|
|
357
364
|
var _DataTable2 = require("./components/DataTable");
|