ag-common 0.0.218 → 0.0.221
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/common/helpers/i18n.d.ts +4 -1
- package/dist/common/helpers/i18n.js +14 -2
- package/dist/ui/components/TextEdit/TextEdit.d.ts +2 -52
- package/dist/ui/components/TextEdit/TextEdit.js +6 -2
- package/dist/ui/components/TextEdit/types.d.ts +62 -0
- package/dist/ui/components/TextEdit/types.js +2 -0
- package/dist/ui/helpers/index.d.ts +0 -1
- package/dist/ui/helpers/index.js +0 -1
- package/package.json +1 -1
- package/dist/ui/helpers/lang.d.ts +0 -4
- package/dist/ui/helpers/lang.js +0 -22
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare type TLangExceptEn = 'id' | 'vi' | '
|
|
1
|
+
declare type TLangExceptEn = 'id' | 'vi' | 'pt';
|
|
2
2
|
export declare type TLang = TLangExceptEn | 'en';
|
|
3
3
|
export declare const AllLang: TLang[];
|
|
4
4
|
/**
|
|
@@ -11,4 +11,7 @@ export declare type TResource = {
|
|
|
11
11
|
};
|
|
12
12
|
export declare const getValidatedLang: (raw: string) => TLang;
|
|
13
13
|
export declare const t: (res: TResource, lang: TLang) => string;
|
|
14
|
+
export declare const useTranslation: <T extends {
|
|
15
|
+
[a: string]: TResource;
|
|
16
|
+
}>(texts: T, lang: TLang) => (lineText: keyof T) => string;
|
|
14
17
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.t = exports.getValidatedLang = exports.AllLang = void 0;
|
|
4
|
-
exports.AllLang = ['en', 'id', 'vi', '
|
|
3
|
+
exports.useTranslation = exports.t = exports.getValidatedLang = exports.AllLang = void 0;
|
|
4
|
+
exports.AllLang = ['en', 'id', 'vi', 'pt'];
|
|
5
5
|
const getValidatedLang = (raw) => {
|
|
6
6
|
const f = exports.AllLang.find((l) => l === raw);
|
|
7
7
|
if (!f) {
|
|
@@ -18,3 +18,15 @@ const t = (res, lang) => {
|
|
|
18
18
|
return (_a = res[lang]) !== null && _a !== void 0 ? _a : res.en;
|
|
19
19
|
};
|
|
20
20
|
exports.t = t;
|
|
21
|
+
const useTranslation = (texts, lang) => {
|
|
22
|
+
const ret = (lineText) => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const v1 = (_a = texts[lineText]) === null || _a === void 0 ? void 0 : _a[lang];
|
|
25
|
+
if (v1 || v1 === null) {
|
|
26
|
+
return v1 !== null && v1 !== void 0 ? v1 : '';
|
|
27
|
+
}
|
|
28
|
+
return (_b = texts[lineText].en) !== null && _b !== void 0 ? _b : '???';
|
|
29
|
+
};
|
|
30
|
+
return ret;
|
|
31
|
+
};
|
|
32
|
+
exports.useTranslation = useTranslation;
|
|
@@ -1,55 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { ITextEdit } from './types';
|
|
2
3
|
import { StyledComponent } from 'styled-components';
|
|
3
4
|
export declare const ValueReadonly: StyledComponent<"div", any, {}, never>;
|
|
4
|
-
export declare const TextEdit: ({ defaultValue, defaultEditing, disableEdit, placeholder, className, singleLine, noGrow, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo, onEscape, }:
|
|
5
|
-
/**
|
|
6
|
-
* forces single row input style. will also enable 'Enter' to auto submit
|
|
7
|
-
*/
|
|
8
|
-
singleLine?: boolean | undefined;
|
|
9
|
-
className?: string | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* default value of field. default empty
|
|
12
|
-
*/
|
|
13
|
-
defaultValue?: string | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* if truthy will enable text edit mode by default. if focus is true, will also focus on open
|
|
16
|
-
*/
|
|
17
|
-
defaultEditing?: {
|
|
18
|
-
focus?: boolean | undefined;
|
|
19
|
-
} | undefined;
|
|
20
|
-
onSubmit: (val: string, enterPressed: boolean) => void;
|
|
21
|
-
/**
|
|
22
|
-
* disable edit text functionality
|
|
23
|
-
*/
|
|
24
|
-
disableEdit?: boolean | undefined;
|
|
25
|
-
placeholder?: string | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* when the user edits or unselects edit
|
|
28
|
-
*/
|
|
29
|
-
onEditingChange?: ((editing: boolean) => void) | undefined;
|
|
30
|
-
/**
|
|
31
|
-
* if null will disable click outside
|
|
32
|
-
*/
|
|
33
|
-
onClickOutsideWithNoValue?: (() => void) | null | undefined;
|
|
34
|
-
onClickNotEditing?: (() => void) | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* if true, will not grow. default false
|
|
37
|
-
*/
|
|
38
|
-
noGrow?: boolean | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* will set these attributes directly on element. can put data-* here
|
|
41
|
-
*/
|
|
42
|
-
attributes?: Record<string, string | number | boolean> | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* optional content at the left of the box
|
|
45
|
-
*/
|
|
46
|
-
leftContent?: JSX.Element | undefined;
|
|
47
|
-
/**
|
|
48
|
-
* if true, will add undo button after changes. if false, will submit after every keypress. default true
|
|
49
|
-
*/
|
|
50
|
-
allowUndo?: boolean | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* will call on user pressed escape
|
|
53
|
-
*/
|
|
54
|
-
onEscape?: (() => void) | undefined;
|
|
55
|
-
}) => JSX.Element;
|
|
5
|
+
export declare const TextEdit: ({ defaultValue, defaultEditing, disableEdit, placeholder, className, singleLine, noGrow, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo, onEscape, maxLength, onKeyDown, }: ITextEdit) => JSX.Element;
|
|
@@ -73,7 +73,7 @@ const Icon = styled_components_1.default.div `
|
|
|
73
73
|
filter: saturate(3);
|
|
74
74
|
}
|
|
75
75
|
`;
|
|
76
|
-
const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, placeholder, className, singleLine = false, noGrow = false, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo = true, onEscape, }) => {
|
|
76
|
+
const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, placeholder, className, singleLine = false, noGrow = false, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo = true, onEscape, maxLength, onKeyDown, }) => {
|
|
77
77
|
const ref = (0, react_1.useRef)(null);
|
|
78
78
|
const taref = (0, react_1.useRef)(null);
|
|
79
79
|
const [value, setValue] = (0, react_1.useState)(defaultValue);
|
|
@@ -138,7 +138,11 @@ const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, plac
|
|
|
138
138
|
if (!allowUndo) {
|
|
139
139
|
onSubmit(v.currentTarget.value, false);
|
|
140
140
|
}
|
|
141
|
-
}, placeholder: placeholder, rows: singleLine ? 1 : undefined, onKeyDown: (e) => {
|
|
141
|
+
}, placeholder: placeholder, rows: singleLine ? 1 : undefined, maxLength: maxLength, onKeyDown: (e) => {
|
|
142
|
+
if ((onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e)) === false) {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
142
146
|
if (singleLine && e.code.endsWith('Enter')) {
|
|
143
147
|
onSubmit(value, true);
|
|
144
148
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface ITextEdit {
|
|
3
|
+
/**
|
|
4
|
+
* forces single row input style. will also enable 'Enter' to auto submit
|
|
5
|
+
*/
|
|
6
|
+
singleLine?: boolean;
|
|
7
|
+
className?: string;
|
|
8
|
+
/**
|
|
9
|
+
* default value of field. default empty
|
|
10
|
+
*/
|
|
11
|
+
defaultValue?: string;
|
|
12
|
+
/**
|
|
13
|
+
* if truthy will enable text edit mode by default. if focus is true, will also focus on open
|
|
14
|
+
*/
|
|
15
|
+
defaultEditing?: {
|
|
16
|
+
focus?: boolean;
|
|
17
|
+
};
|
|
18
|
+
onSubmit: (val: string,
|
|
19
|
+
/**
|
|
20
|
+
* if true, was passed by pressing Enter
|
|
21
|
+
*/
|
|
22
|
+
enterPressed: boolean) => void;
|
|
23
|
+
/**
|
|
24
|
+
* disable edit text functionality
|
|
25
|
+
*/
|
|
26
|
+
disableEdit?: boolean;
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
/**
|
|
29
|
+
* when the user edits or unselects edit
|
|
30
|
+
*/
|
|
31
|
+
onEditingChange?: (editing: boolean) => void;
|
|
32
|
+
/**
|
|
33
|
+
* if null will disable click outside
|
|
34
|
+
*/
|
|
35
|
+
onClickOutsideWithNoValue?: (() => void) | null;
|
|
36
|
+
onClickNotEditing?: () => void;
|
|
37
|
+
/**
|
|
38
|
+
* if true, will not grow. default false
|
|
39
|
+
*/
|
|
40
|
+
noGrow?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* will set these attributes directly on element. can put data-* here
|
|
43
|
+
*/
|
|
44
|
+
attributes?: Record<string, string | number | boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* optional content at the left of the box
|
|
47
|
+
*/
|
|
48
|
+
leftContent?: JSX.Element;
|
|
49
|
+
/**
|
|
50
|
+
* if true, will add undo button after changes. if false, will submit after every keypress. default true
|
|
51
|
+
*/
|
|
52
|
+
allowUndo?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* will call on user pressed escape
|
|
55
|
+
*/
|
|
56
|
+
onEscape?: () => void;
|
|
57
|
+
maxLength?: number;
|
|
58
|
+
/**
|
|
59
|
+
* if provided and return false, will cancel keydown
|
|
60
|
+
*/
|
|
61
|
+
onKeyDown?: (e: React.KeyboardEvent<HTMLTextAreaElement>) => boolean;
|
|
62
|
+
}
|
package/dist/ui/helpers/index.js
CHANGED
|
@@ -24,7 +24,6 @@ __exportStar(require("./debounce"), exports);
|
|
|
24
24
|
__exportStar(require("./dom"), exports);
|
|
25
25
|
__exportStar(require("./extractAttributes"), exports);
|
|
26
26
|
__exportStar(require("./jwt"), exports);
|
|
27
|
-
__exportStar(require("./lang"), exports);
|
|
28
27
|
__exportStar(require("./plural"), exports);
|
|
29
28
|
__exportStar(require("./routes"), exports);
|
|
30
29
|
__exportStar(require("./serviceWorker"), exports);
|
package/package.json
CHANGED
package/dist/ui/helpers/lang.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useTranslation = void 0;
|
|
4
|
-
const useTranslation = (texts, lang) => {
|
|
5
|
-
const ret = (lineText) => {
|
|
6
|
-
var _a;
|
|
7
|
-
let v1 = (_a = texts[lineText]) === null || _a === void 0 ? void 0 : _a[lang];
|
|
8
|
-
const missing = v1 === undefined;
|
|
9
|
-
if (missing) {
|
|
10
|
-
v1 = texts[lineText].en;
|
|
11
|
-
}
|
|
12
|
-
if (missing) {
|
|
13
|
-
return '???';
|
|
14
|
-
}
|
|
15
|
-
if (v1 === undefined || v1 === null) {
|
|
16
|
-
return '???';
|
|
17
|
-
}
|
|
18
|
-
return v1;
|
|
19
|
-
};
|
|
20
|
-
return ret;
|
|
21
|
-
};
|
|
22
|
-
exports.useTranslation = useTranslation;
|