ag-common 0.0.62 → 0.0.66
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/ui/components/Chevron/index.d.ts +2 -1
- package/dist/ui/components/Chevron/index.js +1 -1
- 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/mutexData.d.ts +1 -0
- package/dist/ui/helpers/mutexData.js +9 -0
- package/dist/ui/helpers/useContextMenu.d.ts +7 -0
- package/dist/ui/helpers/useContextMenu.js +35 -0
- package/dist/ui/helpers/useOpenApiStore.d.ts +1 -0
- package/dist/ui/helpers/useOpenApiStore.js +3 -1
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export declare const Chevron: ({ down, width, className, colour, }: {
|
|
2
|
+
export declare const Chevron: ({ down, width, className, colour, onToggle, }: {
|
|
3
3
|
colour?: string | undefined;
|
|
4
4
|
className?: string | undefined;
|
|
5
5
|
width?: string | undefined;
|
|
6
6
|
down: boolean;
|
|
7
|
+
onToggle?: (() => void) | undefined;
|
|
7
8
|
}) => JSX.Element;
|
|
@@ -20,6 +20,6 @@ const IconStyled = (0, styled_components_1.default)(Icon_1.Icon) `
|
|
|
20
20
|
`;
|
|
21
21
|
const ChevronIcon = (react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 -256 1792 1792" },
|
|
22
22
|
react_1.default.createElement("path", { d: "M1679.339 301.56q0 53-37 90l-651 651q-38 38-91 38-54 0-90-38l-651-651q-38-36-38-90 0-53 38-91l74-75q39-37 91-37 53 0 90 37l486 486 486-486q37-37 90-37 52 0 91 37l75 75q37 39 37 91z" })));
|
|
23
|
-
const Chevron = ({ down, width = '1.2rem', className, colour = 'black', }) => (react_1.default.createElement(SChevron, { className: className },
|
|
23
|
+
const Chevron = ({ down, width = '1.2rem', className, colour = 'black', onToggle, }) => (react_1.default.createElement(SChevron, { className: className, onClick: () => onToggle === null || onToggle === void 0 ? void 0 : onToggle(), onTouchStart: () => onToggle === null || onToggle === void 0 ? void 0 : onToggle(), onKeyPress: (e) => e.key === 'Enter' && (onToggle === null || onToggle === void 0 ? void 0 : onToggle()) },
|
|
24
24
|
react_1.default.createElement(IconStyled, { flip: down, fill: colour, width: width, height: width }, ChevronIcon)));
|
|
25
25
|
exports.Chevron = Chevron;
|
|
@@ -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);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MutexData = void 0;
|
|
4
4
|
/* eslint-disable class-methods-use-this */
|
|
5
|
+
const _1 = require(".");
|
|
5
6
|
const log_1 = require("../../common/helpers/log");
|
|
6
7
|
const useLocalStorage_1 = require("./useLocalStorage");
|
|
7
8
|
class MutexData {
|
|
@@ -42,5 +43,13 @@ class MutexData {
|
|
|
42
43
|
this.pingSubscribers(key);
|
|
43
44
|
}
|
|
44
45
|
}
|
|
46
|
+
delete(key, updateSubscribers = false) {
|
|
47
|
+
(0, _1.clearLocalStorageItem)(`mutex-${key}`);
|
|
48
|
+
if (updateSubscribers) {
|
|
49
|
+
if (Object.keys(this.subscriptions).length > 0) {
|
|
50
|
+
this.pingSubscribers(key);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
45
54
|
}
|
|
46
55
|
exports.MutexData = MutexData;
|
|
@@ -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;
|
|
@@ -2,6 +2,7 @@ import { AxiosResponse } from 'axios';
|
|
|
2
2
|
import { OverrideAuth } from './callOpenApi';
|
|
3
3
|
import { CacheItems } from './routes';
|
|
4
4
|
import { AxiosWrapper, User } from './jwt';
|
|
5
|
+
export declare const deleteMutexData: (key: string) => void;
|
|
5
6
|
export declare const setMutexData: ({ key, data, ttlSeconds, }: {
|
|
6
7
|
key: string;
|
|
7
8
|
data: any;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.setOpenApiCache = exports.useOpenApiStore = exports.getMutexData = exports.setMutexData = void 0;
|
|
12
|
+
exports.setOpenApiCache = exports.useOpenApiStore = exports.getMutexData = exports.setMutexData = exports.deleteMutexData = void 0;
|
|
13
13
|
const react_1 = require("react");
|
|
14
14
|
const mutex_1 = require("./mutex");
|
|
15
15
|
const mutexData_1 = require("./mutexData");
|
|
@@ -22,6 +22,8 @@ const mutex = new mutex_1.Mutex({
|
|
|
22
22
|
});
|
|
23
23
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
24
|
const mutexData = new mutexData_1.MutexData();
|
|
25
|
+
const deleteMutexData = (key) => mutexData.delete(key);
|
|
26
|
+
exports.deleteMutexData = deleteMutexData;
|
|
25
27
|
const setMutexData = ({ key, data, ttlSeconds = 3600, }) => {
|
|
26
28
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
29
|
const wrap = {
|