ag-common 0.0.65 → 0.0.69
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/api/helpers/api.js +7 -2
- package/dist/ui/components/DropdownList/index.js +2 -1
- package/dist/ui/components/TextEdit/TextEdit.d.ts +10 -4
- package/dist/ui/components/TextEdit/TextEdit.js +27 -17
- package/dist/ui/components/TextEdit/common.js +0 -1
- package/dist/ui/helpers/index.d.ts +1 -0
- package/dist/ui/helpers/index.js +1 -0
- package/dist/ui/helpers/useContextMenu.d.ts +7 -0
- package/dist/ui/helpers/useContextMenu.js +35 -0
- package/package.json +4 -4
package/dist/api/helpers/api.js
CHANGED
|
@@ -34,14 +34,19 @@ const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
|
|
|
34
34
|
};
|
|
35
35
|
exports.returnCode = returnCode;
|
|
36
36
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
const stripPKs = (r,
|
|
37
|
+
const stripPKs = (r,
|
|
38
|
+
/**
|
|
39
|
+
* default true
|
|
40
|
+
* if true, will keep PK
|
|
41
|
+
*/
|
|
42
|
+
excludePK = true) => {
|
|
38
43
|
if (!r) {
|
|
39
44
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
45
|
return null;
|
|
41
46
|
}
|
|
42
47
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
43
48
|
// @ts-ignore
|
|
44
|
-
const { PK, PK1, PK2, PK3, PK4, PK5, L1, L2, L3, L4, L5, L6
|
|
49
|
+
const { PK, PK1, PK2, PK3, PK4, PK5, L1, L2, L3, L4, L5, L6 } = r, rest = __rest(r, ["PK", "PK1", "PK2", "PK3", "PK4", "PK5", "L1", "L2", "L3", "L4", "L5", "L6"]);
|
|
45
50
|
if (!excludePK) {
|
|
46
51
|
//@ts-ignore
|
|
47
52
|
rest.PK = PK;
|
|
@@ -120,10 +120,11 @@ function DropdownList({ options, value, onChange, placeholder, className, render
|
|
|
120
120
|
setOpen(!open);
|
|
121
121
|
} },
|
|
122
122
|
react_1.default.createElement(SItems, { open: open, style: style }, open &&
|
|
123
|
-
options.map((s, i) => (react_1.default.createElement(SItem, { key: renderF(s), selected: s === state, onClick: () => {
|
|
123
|
+
options.map((s, i) => (react_1.default.createElement(SItem, { key: renderF(s), selected: s === state, onClick: (e) => {
|
|
124
124
|
if (s !== state) {
|
|
125
125
|
onChange(s, i);
|
|
126
126
|
}
|
|
127
|
+
e.preventDefault();
|
|
127
128
|
} }, renderF(s))))),
|
|
128
129
|
children || (react_1.default.createElement(Icon_1.Icon, { width: "2rem", height: "2rem", onClick: (e) => {
|
|
129
130
|
e.stopPropagation();
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
2
|
+
import { StyledComponent } from 'styled-components';
|
|
3
|
+
export declare const ValueReadonly: StyledComponent<"div", any, {}, never>;
|
|
4
|
+
export declare const TextEdit: ({ defaultValue, defaultEditing, onSubmit, disableEdit, placeholder, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, className, singleLine, }: {
|
|
4
5
|
singleLine?: boolean | undefined;
|
|
5
6
|
className?: string | undefined;
|
|
6
7
|
defaultValue: string;
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* if truthy will enable. if focus is true, will also focus on open
|
|
10
|
+
*/
|
|
11
|
+
defaultEditing?: {
|
|
12
|
+
focus: boolean;
|
|
13
|
+
} | undefined;
|
|
8
14
|
onSubmit: (val: string) => void;
|
|
9
|
-
|
|
15
|
+
disableEdit?: boolean | undefined;
|
|
10
16
|
placeholder?: string | undefined;
|
|
11
17
|
onEditingChange?: ((editing: boolean) => void) | undefined;
|
|
12
18
|
onClickOutsideWithNoValue?: (() => void) | undefined;
|
|
@@ -18,16 +18,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
22
|
exports.TextEdit = exports.ValueReadonly = void 0;
|
|
26
23
|
/* eslint-disable jsx-a11y/no-onchange */
|
|
27
24
|
const react_1 = __importStar(require("react"));
|
|
28
25
|
const images_1 = require("./images");
|
|
29
26
|
const common_1 = require("./common");
|
|
30
|
-
const styled_components_1 =
|
|
27
|
+
const styled_components_1 = __importStar(require("styled-components"));
|
|
31
28
|
const useOnClickOutside_1 = require("../../helpers/useOnClickOutside");
|
|
32
29
|
const common_2 = require("../../styles/common");
|
|
33
30
|
exports.ValueReadonly = styled_components_1.default.div `
|
|
@@ -35,17 +32,24 @@ exports.ValueReadonly = styled_components_1.default.div `
|
|
|
35
32
|
word-break: break-word;
|
|
36
33
|
flex-basis: calc(100% - 3rem);
|
|
37
34
|
`;
|
|
38
|
-
const
|
|
35
|
+
const basecss = (0, styled_components_1.css) `
|
|
36
|
+
outline: none;
|
|
39
37
|
border: 0;
|
|
40
38
|
word-break: break-word;
|
|
41
39
|
${common_1.valueCss};
|
|
42
40
|
resize: none;
|
|
43
41
|
overflow: hidden;
|
|
44
42
|
background-color: white;
|
|
43
|
+
`;
|
|
44
|
+
const ValueTextArea = styled_components_1.default.textarea `
|
|
45
|
+
${basecss}
|
|
45
46
|
&[data-editing='true'] {
|
|
46
47
|
min-height: 5rem;
|
|
47
48
|
}
|
|
48
49
|
`;
|
|
50
|
+
const ValueTextBox = styled_components_1.default.input `
|
|
51
|
+
${basecss}
|
|
52
|
+
`;
|
|
49
53
|
const ValueBoxEdit = (0, styled_components_1.default)(common_1.ValueBox) `
|
|
50
54
|
border: solid 1px #ccc;
|
|
51
55
|
`;
|
|
@@ -61,18 +65,18 @@ const Icon = styled_components_1.default.div `
|
|
|
61
65
|
filter: saturate(3);
|
|
62
66
|
}
|
|
63
67
|
`;
|
|
64
|
-
const TextEdit = ({ defaultValue, defaultEditing
|
|
68
|
+
const TextEdit = ({ defaultValue, defaultEditing, onSubmit, disableEdit = false, placeholder, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, className, singleLine = false, }) => {
|
|
65
69
|
const ref = (0, react_1.useRef)(null);
|
|
66
70
|
const taref = (0, react_1.useRef)(null);
|
|
67
71
|
const [value, setValue] = (0, react_1.useState)(defaultValue);
|
|
68
|
-
const [editing, setEditingRaw] = (0, react_1.useState)(defaultEditing);
|
|
72
|
+
const [editing, setEditingRaw] = (0, react_1.useState)(!!defaultEditing);
|
|
69
73
|
const valueChange = value !== defaultValue;
|
|
70
74
|
(0, useOnClickOutside_1.useOnClickOutside)({ ref, moveMouseOutside: false }, () => {
|
|
71
75
|
if (valueChange) {
|
|
72
76
|
onSubmit(value);
|
|
73
77
|
}
|
|
74
78
|
else {
|
|
75
|
-
if (
|
|
79
|
+
if (!disableEdit && editing && defaultEditing) {
|
|
76
80
|
return;
|
|
77
81
|
}
|
|
78
82
|
if (onClickOutsideWithNoValue) {
|
|
@@ -89,20 +93,19 @@ const TextEdit = ({ defaultValue, defaultEditing = false, onSubmit, canEdit = tr
|
|
|
89
93
|
};
|
|
90
94
|
(0, react_1.useEffect)(() => {
|
|
91
95
|
setValue(defaultValue);
|
|
92
|
-
//setEditing(false);
|
|
93
96
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
97
|
}, [defaultValue]);
|
|
95
98
|
(0, react_1.useEffect)(() => {
|
|
96
|
-
if (defaultEditing && taref.current) {
|
|
99
|
+
if ((defaultEditing === null || defaultEditing === void 0 ? void 0 : defaultEditing.focus) && taref.current) {
|
|
97
100
|
taref.current.focus();
|
|
98
101
|
}
|
|
99
|
-
setEditing(defaultEditing);
|
|
102
|
+
setEditing(!!defaultEditing);
|
|
100
103
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
101
104
|
}, [defaultEditing]);
|
|
102
|
-
if (!editing ||
|
|
105
|
+
if (!editing || disableEdit) {
|
|
103
106
|
return (react_1.default.createElement(common_1.ValueBox, Object.assign({}, common_2.noDrag, { className: className, "data-editing": "false", onClick: () => onClickNotEditing === null || onClickNotEditing === void 0 ? void 0 : onClickNotEditing(), "data-pointer": onClickNotEditing ? 'true' : 'false' }),
|
|
104
107
|
react_1.default.createElement(exports.ValueReadonly, { "data-type": "text" }, value),
|
|
105
|
-
react_1.default.createElement(Right, null,
|
|
108
|
+
react_1.default.createElement(Right, null, !disableEdit && (react_1.default.createElement(Icon, { style: common_1.iconRight, onClick: (e) => {
|
|
106
109
|
e.stopPropagation();
|
|
107
110
|
setEditing(true);
|
|
108
111
|
} },
|
|
@@ -111,13 +114,20 @@ const TextEdit = ({ defaultValue, defaultEditing = false, onSubmit, canEdit = tr
|
|
|
111
114
|
if (!open) {
|
|
112
115
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
113
116
|
}
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
118
|
+
const Comp = singleLine
|
|
119
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
+
ValueTextBox
|
|
121
|
+
: ValueTextArea;
|
|
122
|
+
return (react_1.default.createElement(ValueBoxEdit, Object.assign({ "data-editing": "true" }, common_2.noDrag, {
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
|
+
ref: ref, tabIndex: editing ? 0 : undefined, className: className }),
|
|
125
|
+
react_1.default.createElement(Comp, { "data-editing": "true", "data-valuechange": valueChange.toString(), ref: taref, "data-type": "text", value: value, onChange: (v) => setValue(v.currentTarget.value), placeholder: placeholder, rows: singleLine ? 1 : undefined, onKeyDown: (e) => singleLine && e.code.endsWith('Enter') && onSubmit(value) && false }),
|
|
116
126
|
react_1.default.createElement(Right, null,
|
|
117
127
|
valueChange && (react_1.default.createElement(Icon, { style: common_1.iconLeft, onClick: () => valueChange && onSubmit(value) },
|
|
118
128
|
react_1.default.createElement(images_1.SaveIcon, null))),
|
|
119
|
-
(valueChange || editing !== defaultEditing) && (react_1.default.createElement(Icon, { style: common_1.iconRight, onClick: () => {
|
|
120
|
-
setEditing(defaultEditing);
|
|
129
|
+
(valueChange || editing !== !!defaultEditing) && (react_1.default.createElement(Icon, { style: common_1.iconRight, onClick: () => {
|
|
130
|
+
setEditing(!!defaultEditing);
|
|
121
131
|
setValue(defaultValue);
|
|
122
132
|
} },
|
|
123
133
|
react_1.default.createElement(images_1.UndoIcon, null))))));
|
|
@@ -13,6 +13,7 @@ export * from './mutex';
|
|
|
13
13
|
export * from './mutexData';
|
|
14
14
|
export * from './plural';
|
|
15
15
|
export * from './routes';
|
|
16
|
+
export * from './useContextMenu';
|
|
16
17
|
export * from './useLocalStorage';
|
|
17
18
|
export * from './useLockBodyScroll';
|
|
18
19
|
export * from './useOnClickOutside';
|
package/dist/ui/helpers/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __exportStar(require("./mutex"), exports);
|
|
|
25
25
|
__exportStar(require("./mutexData"), exports);
|
|
26
26
|
__exportStar(require("./plural"), exports);
|
|
27
27
|
__exportStar(require("./routes"), exports);
|
|
28
|
+
__exportStar(require("./useContextMenu"), exports);
|
|
28
29
|
__exportStar(require("./useLocalStorage"), exports);
|
|
29
30
|
__exportStar(require("./useLockBodyScroll"), exports);
|
|
30
31
|
__exportStar(require("./useOnClickOutside"), exports);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useContextMenu = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useContextMenu = ({ ref, }) => {
|
|
6
|
+
const [xPos, setXPos] = (0, react_1.useState)('0px');
|
|
7
|
+
const [yPos, setYPos] = (0, react_1.useState)('0px');
|
|
8
|
+
const [showMenu, setShowMenu] = (0, react_1.useState)(false);
|
|
9
|
+
const handleContextMenu = (0, react_1.useCallback)((e) => {
|
|
10
|
+
var _a;
|
|
11
|
+
if (!((_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
e.preventDefault();
|
|
15
|
+
setXPos(`${e.pageX}px`);
|
|
16
|
+
setYPos(`${e.pageY}px`);
|
|
17
|
+
setShowMenu(true);
|
|
18
|
+
}, [ref]);
|
|
19
|
+
const handleClick = (0, react_1.useCallback)(() => {
|
|
20
|
+
if (!showMenu) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
setShowMenu(false);
|
|
24
|
+
}, [showMenu]);
|
|
25
|
+
(0, react_1.useEffect)(() => {
|
|
26
|
+
document.addEventListener('click', handleClick);
|
|
27
|
+
document.addEventListener('contextmenu', handleContextMenu);
|
|
28
|
+
return () => {
|
|
29
|
+
document.addEventListener('click', handleClick);
|
|
30
|
+
document.removeEventListener('contextmenu', handleContextMenu);
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
return { xPos, yPos, showMenu };
|
|
34
|
+
};
|
|
35
|
+
exports.useContextMenu = useContextMenu;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.69",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"aws-cdk-lib": "2.7.0",
|
|
17
|
-
"aws-sdk": "2.
|
|
17
|
+
"aws-sdk": "2.1058.0",
|
|
18
18
|
"axios": "0.24.0",
|
|
19
19
|
"constructs": "10.0.32",
|
|
20
20
|
"jsonwebtoken": "8.5.1",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"typescript": "4.5.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/jsonwebtoken": "8.5.
|
|
31
|
-
"@types/node": "17.0.
|
|
30
|
+
"@types/jsonwebtoken": "8.5.8",
|
|
31
|
+
"@types/node": "17.0.9",
|
|
32
32
|
"@types/react": "17.0.38",
|
|
33
33
|
"@types/react-dom": "17.0.11",
|
|
34
34
|
"@types/styled-components": "5.1.20",
|