@sap-ux/ui-components 1.1.10 → 1.2.0
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/UITranslationInput/UIFormattedText.d.ts +47 -0
- package/dist/components/UITranslationInput/UIFormattedText.d.ts.map +1 -0
- package/dist/components/UITranslationInput/UIFormattedText.js +122 -0
- package/dist/components/UITranslationInput/UIFormattedText.js.map +1 -0
- package/dist/components/UITranslationInput/UILoadButton.d.ts +53 -0
- package/dist/components/UITranslationInput/UILoadButton.d.ts.map +1 -0
- package/dist/components/UITranslationInput/UILoadButton.js +110 -0
- package/dist/components/UITranslationInput/UILoadButton.js.map +1 -0
- package/dist/components/UITranslationInput/UILoadButton.scss +14 -0
- package/dist/components/UITranslationInput/UITranslationButton.d.ts +25 -0
- package/dist/components/UITranslationInput/UITranslationButton.d.ts.map +1 -0
- package/dist/components/UITranslationInput/UITranslationButton.js +181 -0
- package/dist/components/UITranslationInput/UITranslationButton.js.map +1 -0
- package/dist/components/UITranslationInput/UITranslationButton.types.d.ts +47 -0
- package/dist/components/UITranslationInput/UITranslationButton.types.d.ts.map +1 -0
- package/dist/components/UITranslationInput/UITranslationButton.types.js +16 -0
- package/dist/components/UITranslationInput/UITranslationButton.types.js.map +1 -0
- package/dist/components/UITranslationInput/UITranslationInput.d.ts +14 -0
- package/dist/components/UITranslationInput/UITranslationInput.d.ts.map +1 -0
- package/dist/components/UITranslationInput/UITranslationInput.js +61 -0
- package/dist/components/UITranslationInput/UITranslationInput.js.map +1 -0
- package/dist/components/UITranslationInput/UITranslationInput.scss +40 -0
- package/dist/components/UITranslationInput/UITranslationUtils.d.ts +65 -0
- package/dist/components/UITranslationInput/UITranslationUtils.d.ts.map +1 -0
- package/dist/components/UITranslationInput/UITranslationUtils.js +169 -0
- package/dist/components/UITranslationInput/UITranslationUtils.js.map +1 -0
- package/dist/components/UITranslationInput/defaults.d.ts +3 -0
- package/dist/components/UITranslationInput/defaults.d.ts.map +1 -0
- package/dist/components/UITranslationInput/defaults.js +15 -0
- package/dist/components/UITranslationInput/defaults.js.map +1 -0
- package/dist/components/UITranslationInput/index.d.ts +3 -0
- package/dist/components/UITranslationInput/index.d.ts.map +1 -0
- package/dist/components/UITranslationInput/index.js +15 -0
- package/dist/components/UITranslationInput/index.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/package.json +1 -1
- package/storybook/iframe.html +1 -1
- package/storybook/main.d6cb18b9.iframe.bundle.js +98 -0
- package/storybook/project.json +1 -1
- package/storybook/main.bf7d0307.iframe.bundle.js +0 -97
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
interface MessageTextValues {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
}
|
|
5
|
+
export interface UIFormattedTextProps {
|
|
6
|
+
children: string;
|
|
7
|
+
values?: MessageTextValues;
|
|
8
|
+
}
|
|
9
|
+
interface ParseResult {
|
|
10
|
+
texts: Array<string>;
|
|
11
|
+
bolds: Array<string>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Method separates given text between found values and rest unformatted text.
|
|
15
|
+
*
|
|
16
|
+
* @param text Text to parse.
|
|
17
|
+
* @param values Map with values to search.
|
|
18
|
+
* @returns Object containing separated `texts` and `formatted` arrays.
|
|
19
|
+
*/
|
|
20
|
+
export declare const parseText: (text: string, values: MessageTextValues) => ParseResult;
|
|
21
|
+
/**
|
|
22
|
+
* Method formats text with callback method to provide option to use different markup to highligh matching result in text.
|
|
23
|
+
*
|
|
24
|
+
* @param text Text to parse.
|
|
25
|
+
* @param values Map with values to search.
|
|
26
|
+
* @param cb Callback method to apply text highlight.
|
|
27
|
+
* @returns Array with formatted text parts.
|
|
28
|
+
*/
|
|
29
|
+
export declare function formatTextGeneric<T>(text: string, values: MessageTextValues, cb: (index: number, textPart: string, match?: string) => T): T[];
|
|
30
|
+
/**
|
|
31
|
+
* Method formats string text with replacing matching values with same string without any highlight.
|
|
32
|
+
*
|
|
33
|
+
* @param text Text to parse.
|
|
34
|
+
* @param values Map with values to search.
|
|
35
|
+
* @returns Formatted text string.
|
|
36
|
+
*/
|
|
37
|
+
export declare function formatText(text: string, values: MessageTextValues): string;
|
|
38
|
+
/**
|
|
39
|
+
* Component to show formatted text with highlighting matching entries.
|
|
40
|
+
* Entries with '{{{key}}}' will be replaced with passed value and wrapped in bold.
|
|
41
|
+
*
|
|
42
|
+
* @param props Component properties.
|
|
43
|
+
* @returns Component to render formatted text.
|
|
44
|
+
*/
|
|
45
|
+
export declare function UIFormattedText(props: UIFormattedTextProps): ReactElement;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=UIFormattedText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UIFormattedText.d.ts","sourceRoot":"","sources":["../../../src/components/UITranslationInput/UIFormattedText.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,UAAU,iBAAiB;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC9B;AAED,UAAU,WAAW;IACjB,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACrB,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACxB;AA4BD;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,SAAU,MAAM,UAAU,iBAAiB,KAAG,WA6BnE,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC,GAC3D,CAAC,EAAE,CAUL;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAK1E;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CAgBzE"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UIFormattedText = exports.formatText = exports.formatTextGeneric = exports.parseText = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const PLACEHOLDER_START = '{{{';
|
|
9
|
+
const PLACEHOLDER_END = '}}}';
|
|
10
|
+
/**
|
|
11
|
+
* Method find all matching values.
|
|
12
|
+
*
|
|
13
|
+
* @param text Text to parse.
|
|
14
|
+
* @param values Map with values to search.
|
|
15
|
+
* @returns Array containing matched regex expressions.
|
|
16
|
+
*/
|
|
17
|
+
const matchAllValues = (text, values) => {
|
|
18
|
+
const matches = [];
|
|
19
|
+
for (const key in values) {
|
|
20
|
+
const textWithUrlRegex = `${PLACEHOLDER_START}${key}${PLACEHOLDER_END}`;
|
|
21
|
+
const regex = new RegExp(textWithUrlRegex, 'gi');
|
|
22
|
+
let match = null;
|
|
23
|
+
do {
|
|
24
|
+
match = regex.exec(text);
|
|
25
|
+
if (match) {
|
|
26
|
+
matches.push(match);
|
|
27
|
+
}
|
|
28
|
+
} while (match);
|
|
29
|
+
}
|
|
30
|
+
return matches;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Method separates given text between found values and rest unformatted text.
|
|
34
|
+
*
|
|
35
|
+
* @param text Text to parse.
|
|
36
|
+
* @param values Map with values to search.
|
|
37
|
+
* @returns Object containing separated `texts` and `formatted` arrays.
|
|
38
|
+
*/
|
|
39
|
+
const parseText = (text, values) => {
|
|
40
|
+
const result = {
|
|
41
|
+
texts: [],
|
|
42
|
+
bolds: []
|
|
43
|
+
};
|
|
44
|
+
if (text) {
|
|
45
|
+
const matches = matchAllValues(text, values);
|
|
46
|
+
matches.sort((match1, match2) => match1.index - match2.index);
|
|
47
|
+
let charIndex = 0;
|
|
48
|
+
if (matches.length) {
|
|
49
|
+
for (let i = 0; i < matches.length; i++) {
|
|
50
|
+
const match = matches[i];
|
|
51
|
+
if (match.index === undefined) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const original = match[0];
|
|
55
|
+
const resolvedText = values[original.replace(PLACEHOLDER_START, '').replace(PLACEHOLDER_END, '')];
|
|
56
|
+
result.texts.push(text.substring(charIndex, match.index));
|
|
57
|
+
result.bolds.push(resolvedText);
|
|
58
|
+
charIndex = match.index + original.length;
|
|
59
|
+
if (i === matches.length - 1) {
|
|
60
|
+
result.texts.push(text.substring(charIndex, text.length));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
result.texts.push(text);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
exports.parseText = parseText;
|
|
71
|
+
/**
|
|
72
|
+
* Method formats text with callback method to provide option to use different markup to highligh matching result in text.
|
|
73
|
+
*
|
|
74
|
+
* @param text Text to parse.
|
|
75
|
+
* @param values Map with values to search.
|
|
76
|
+
* @param cb Callback method to apply text highlight.
|
|
77
|
+
* @returns Array with formatted text parts.
|
|
78
|
+
*/
|
|
79
|
+
function formatTextGeneric(text, values, cb) {
|
|
80
|
+
const parseResult = exports.parseText(text, values);
|
|
81
|
+
const result = [];
|
|
82
|
+
for (let i = 0; i < parseResult.texts.length; i++) {
|
|
83
|
+
if (!parseResult.texts[i] && !parseResult.bolds[i]) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
result.push(cb(i, parseResult.texts[i], parseResult.bolds[i]));
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
exports.formatTextGeneric = formatTextGeneric;
|
|
91
|
+
/**
|
|
92
|
+
* Method formats string text with replacing matching values with same string without any highlight.
|
|
93
|
+
*
|
|
94
|
+
* @param text Text to parse.
|
|
95
|
+
* @param values Map with values to search.
|
|
96
|
+
* @returns Formatted text string.
|
|
97
|
+
*/
|
|
98
|
+
function formatText(text, values) {
|
|
99
|
+
const parseResult = formatTextGeneric(text, values, (index, textPart, match) => {
|
|
100
|
+
return match ? textPart + match : textPart;
|
|
101
|
+
});
|
|
102
|
+
return parseResult.join('');
|
|
103
|
+
}
|
|
104
|
+
exports.formatText = formatText;
|
|
105
|
+
/**
|
|
106
|
+
* Component to show formatted text with highlighting matching entries.
|
|
107
|
+
* Entries with '{{{key}}}' will be replaced with passed value and wrapped in bold.
|
|
108
|
+
*
|
|
109
|
+
* @param props Component properties.
|
|
110
|
+
* @returns Component to render formatted text.
|
|
111
|
+
*/
|
|
112
|
+
function UIFormattedText(props) {
|
|
113
|
+
const { children, values = {} } = props;
|
|
114
|
+
const result = formatTextGeneric(children, values, (index, textPart, match) => {
|
|
115
|
+
return (react_1.default.createElement("span", { key: `anchor-${index}` },
|
|
116
|
+
textPart,
|
|
117
|
+
match && react_1.default.createElement("b", null, match)));
|
|
118
|
+
});
|
|
119
|
+
return react_1.default.createElement("div", null, result);
|
|
120
|
+
}
|
|
121
|
+
exports.UIFormattedText = UIFormattedText;
|
|
122
|
+
//# sourceMappingURL=UIFormattedText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UIFormattedText.js","sourceRoot":"","sources":["../../../src/components/UITranslationInput/UIFormattedText.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAiB1B,MAAM,iBAAiB,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,KAAK,CAAC,CAAC,CAAC,EAAE;YAChD,SAAS;SACZ;QACD,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAClE;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAdD,8CAcC;AAED;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,IAAY,EAAE,MAAyB;IAC9D,MAAM,WAAW,GAAG,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,KAAa,EAAE,QAAgB,EAAE,KAAc,EAAE,EAAE;QACpG,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC/C,CAAC,CAAC,CAAC;IACH,OAAO,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChC,CAAC;AALD,gCAKC;AAED;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,KAA2B;IACvD,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC;IACxC,MAAM,MAAM,GAAG,iBAAiB,CAC5B,QAAQ,EACR,MAAM,EACN,CAAC,KAAa,EAAE,QAAgB,EAAE,KAAc,EAAE,EAAE;QAChD,OAAO,CACH,wCAAM,GAAG,EAAE,UAAU,KAAK,EAAE;YACvB,QAAQ;YACR,KAAK,IAAI,yCAAI,KAAK,CAAK,CACrB,CACV,CAAC;IACN,CAAC,CACJ,CAAC;IAEF,OAAO,2CAAM,MAAM,CAAO,CAAC;AAC/B,CAAC;AAhBD,0CAgBC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ButtonProps } from '../UIButton';
|
|
3
|
+
import type { UILoadButtonBusyProps } from './UITranslationButton.types';
|
|
4
|
+
import './UILoadButton.scss';
|
|
5
|
+
export interface UILoadButtonState {
|
|
6
|
+
busy?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare type UILoadButtonProps = ButtonProps & UILoadButtonBusyProps;
|
|
9
|
+
/**
|
|
10
|
+
* Component to render load button with spin indicator.
|
|
11
|
+
*/
|
|
12
|
+
export declare class UILoadButton extends React.Component<UILoadButtonProps, UILoadButtonState> {
|
|
13
|
+
private minLoaderTimer;
|
|
14
|
+
/**
|
|
15
|
+
* Constructor method for load button.
|
|
16
|
+
*
|
|
17
|
+
* @param props Component properties.
|
|
18
|
+
*/
|
|
19
|
+
constructor(props: UILoadButtonProps);
|
|
20
|
+
/**
|
|
21
|
+
* Method handles component update to refresh busy state.
|
|
22
|
+
*
|
|
23
|
+
* @param prevProps Component previous properties.
|
|
24
|
+
*/
|
|
25
|
+
componentDidUpdate(prevProps: UILoadButtonProps): void;
|
|
26
|
+
componentWillUnmount(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Method handles end of minimal waiting time.
|
|
29
|
+
*/
|
|
30
|
+
private handleMinWaitingTime;
|
|
31
|
+
/**
|
|
32
|
+
* Method returns latest busy state by checking current state and props.
|
|
33
|
+
*
|
|
34
|
+
* @param props Current props.
|
|
35
|
+
* @param state Current state.
|
|
36
|
+
* @returns Busy state.
|
|
37
|
+
*/
|
|
38
|
+
private getBusyState;
|
|
39
|
+
/**
|
|
40
|
+
* Method returns minimal waiting time for loader depending on passed 'useMinWaitingTime' property.
|
|
41
|
+
*
|
|
42
|
+
* @returns Minimal waiting time for busy loader.
|
|
43
|
+
*/
|
|
44
|
+
private getMinimalWaitingTime;
|
|
45
|
+
/**
|
|
46
|
+
* Method to render load button component.
|
|
47
|
+
*
|
|
48
|
+
* @returns Load button component.
|
|
49
|
+
*/
|
|
50
|
+
render(): React.ReactElement;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=UILoadButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UILoadButton.d.ts","sourceRoot":"","sources":["../../../src/components/UITranslationInput/UILoadButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEzE,OAAO,qBAAqB,CAAC;AAE7B,MAAM,WAAW,iBAAiB;IAC9B,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,aAAK,iBAAiB,GAAG,WAAW,GAAG,qBAAqB,CAAC;AAE7D;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK,CAAC,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IACnF,OAAO,CAAC,cAAc,CAAiC;IACvD;;;;OAIG;gBACS,KAAK,EAAE,iBAAiB;IAKpC;;;;OAIG;IACH,kBAAkB,CAAC,SAAS,EAAE,iBAAiB,GAAG,IAAI;IAUtD,oBAAoB,IAAI,IAAI;IAM5B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAuBpB;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IAK7B;;;;OAIG;IACH,MAAM,IAAI,KAAK,CAAC,YAAY;CAgB/B"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UILoadButton = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const UIButton_1 = require("../UIButton");
|
|
9
|
+
const UILoader_1 = require("../UILoader");
|
|
10
|
+
require("./UILoadButton.scss");
|
|
11
|
+
/**
|
|
12
|
+
* Component to render load button with spin indicator.
|
|
13
|
+
*/
|
|
14
|
+
class UILoadButton extends react_1.default.Component {
|
|
15
|
+
/**
|
|
16
|
+
* Constructor method for load button.
|
|
17
|
+
*
|
|
18
|
+
* @param props Component properties.
|
|
19
|
+
*/
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(props);
|
|
22
|
+
this.minLoaderTimer = undefined;
|
|
23
|
+
this.state = this.getBusyState(props, {}) || {};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Method handles component update to refresh busy state.
|
|
27
|
+
*
|
|
28
|
+
* @param prevProps Component previous properties.
|
|
29
|
+
*/
|
|
30
|
+
componentDidUpdate(prevProps) {
|
|
31
|
+
if (prevProps.busy === this.props.busy) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const state = this.getBusyState(this.props, this.state);
|
|
35
|
+
if (state) {
|
|
36
|
+
this.setState(state);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
componentWillUnmount() {
|
|
40
|
+
if (this.minLoaderTimer) {
|
|
41
|
+
window.clearTimeout(this.minLoaderTimer);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Method handles end of minimal waiting time.
|
|
46
|
+
*/
|
|
47
|
+
handleMinWaitingTime() {
|
|
48
|
+
this.minLoaderTimer = undefined;
|
|
49
|
+
if (!this.props.busy) {
|
|
50
|
+
// External busy flag is false, but we were waiting for minimal timeout
|
|
51
|
+
this.setState({
|
|
52
|
+
busy: false
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Method returns latest busy state by checking current state and props.
|
|
58
|
+
*
|
|
59
|
+
* @param props Current props.
|
|
60
|
+
* @param state Current state.
|
|
61
|
+
* @returns Busy state.
|
|
62
|
+
*/
|
|
63
|
+
getBusyState(props, state) {
|
|
64
|
+
let newState;
|
|
65
|
+
if (props.busy !== state.busy) {
|
|
66
|
+
if (!props.busy && !this.minLoaderTimer) {
|
|
67
|
+
newState = {
|
|
68
|
+
busy: false
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
else if (props.busy) {
|
|
72
|
+
newState = {
|
|
73
|
+
busy: true
|
|
74
|
+
};
|
|
75
|
+
window.clearTimeout(this.minLoaderTimer);
|
|
76
|
+
if (props.useMinWaitingTime) {
|
|
77
|
+
this.minLoaderTimer = window.setTimeout(this.handleMinWaitingTime.bind(this), this.getMinimalWaitingTime());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return newState;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Method returns minimal waiting time for loader depending on passed 'useMinWaitingTime' property.
|
|
85
|
+
*
|
|
86
|
+
* @returns Minimal waiting time for busy loader.
|
|
87
|
+
*/
|
|
88
|
+
getMinimalWaitingTime() {
|
|
89
|
+
const { useMinWaitingTime } = this.props;
|
|
90
|
+
return !useMinWaitingTime || typeof useMinWaitingTime === 'boolean' ? 500 : useMinWaitingTime;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Method to render load button component.
|
|
94
|
+
*
|
|
95
|
+
* @returns Load button component.
|
|
96
|
+
*/
|
|
97
|
+
render() {
|
|
98
|
+
const { children } = this.props;
|
|
99
|
+
const { busy } = this.state;
|
|
100
|
+
let { className = '' } = this.props;
|
|
101
|
+
const content = busy ? react_1.default.createElement(UILoader_1.UILoader, { className: 'uiLoaderXSmall', labelPosition: 'right' }) : children;
|
|
102
|
+
if (busy) {
|
|
103
|
+
const busyClassName = 'loading-button';
|
|
104
|
+
className = className ? `${className} ${busyClassName}` : busyClassName;
|
|
105
|
+
}
|
|
106
|
+
return (react_1.default.createElement(UIButton_1.UIIconButton, { ...this.props, onClick: busy ? undefined : this.props.onClick, className: className }, content));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.UILoadButton = UILoadButton;
|
|
110
|
+
//# sourceMappingURL=UILoadButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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S,IAAI,aAAa,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC;SAC3E;QACD,OAAO,CACH,8BAAC,uBAAY,OAAK,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,IAC7F,OAAO,CACG,CAClB,CAAC;IACN,CAAC;CACJ;AA3GD,oCA2GC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { UITranslationProps, TranslationButtonStrings } from './UITranslationButton.types';
|
|
3
|
+
import './UITranslationInput.scss';
|
|
4
|
+
export declare enum SuggestValueType {
|
|
5
|
+
Existing = "Existing",
|
|
6
|
+
Update = "Update",
|
|
7
|
+
New = "New"
|
|
8
|
+
}
|
|
9
|
+
interface UITranslationButtonProps extends UITranslationProps {
|
|
10
|
+
onUpdateValue?: (value: string) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Component to render translation button to provide helper callout with i18n generation option.
|
|
14
|
+
*
|
|
15
|
+
* @param props Component properties.
|
|
16
|
+
* @returns Component to render translation button with callout.
|
|
17
|
+
*/
|
|
18
|
+
export declare function UITranslationButton(props: UITranslationButtonProps): ReactElement;
|
|
19
|
+
export declare namespace UITranslationButton {
|
|
20
|
+
var defaultProps: {
|
|
21
|
+
strings: TranslationButtonStrings;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=UITranslationButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UITranslationButton.d.ts","sourceRoot":"","sources":["../../../src/components/UITranslationInput/UITranslationButton.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAK1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAoB,MAAM,6BAA6B,CAAC;AAUlH,OAAO,2BAA2B,CAAC;AAInC,oBAAY,gBAAgB;IACxB,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,GAAG,QAAQ;CACd;AAeD,UAAU,wBAAyB,SAAQ,kBAAkB;IACzD,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C;AAwGD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,YAAY,CAqEjF;yBArEe,mBAAmB"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.UITranslationButton = exports.SuggestValueType = void 0;
|
|
23
|
+
const react_1 = __importStar(require("react"));
|
|
24
|
+
const UIButton_1 = require("../UIButton");
|
|
25
|
+
const UICallout_1 = require("../UICallout");
|
|
26
|
+
const Icons_1 = require("../Icons");
|
|
27
|
+
const defaults_1 = require("./defaults");
|
|
28
|
+
const UITranslationButton_types_1 = require("./UITranslationButton.types");
|
|
29
|
+
const UITranslationUtils_1 = require("./UITranslationUtils");
|
|
30
|
+
require("./UITranslationInput.scss");
|
|
31
|
+
const UIFormattedText_1 = require("./UIFormattedText");
|
|
32
|
+
const UILoadButton_1 = require("./UILoadButton");
|
|
33
|
+
var SuggestValueType;
|
|
34
|
+
(function (SuggestValueType) {
|
|
35
|
+
SuggestValueType["Existing"] = "Existing";
|
|
36
|
+
SuggestValueType["Update"] = "Update";
|
|
37
|
+
SuggestValueType["New"] = "New";
|
|
38
|
+
})(SuggestValueType = exports.SuggestValueType || (exports.SuggestValueType = {}));
|
|
39
|
+
/**
|
|
40
|
+
* Method to resolve button component text strings for passed key.
|
|
41
|
+
* Component has default texts which can be overwritten using property `strings`.
|
|
42
|
+
*
|
|
43
|
+
* @param property Property.
|
|
44
|
+
* @param strings Map with all text properties.
|
|
45
|
+
* @returns Resolved text.
|
|
46
|
+
*/
|
|
47
|
+
const getStringText = (property, strings) => {
|
|
48
|
+
return strings?.[property] || '';
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Method returns suggestion object with message and tooltip based on passed translation button props.
|
|
52
|
+
*
|
|
53
|
+
* @param props Properties of translation button component.
|
|
54
|
+
* @returns Translation suggestion object.
|
|
55
|
+
*/
|
|
56
|
+
const getTranslationSuggestion = (props) => {
|
|
57
|
+
const { value = '', allowedPatterns, entries, strings = defaults_1.defaultTranslationButtonStrings, namingConvention = UITranslationButton_types_1.TranslationKeyGenerator.CamelCase, defaultPattern, i18nPrefix, allowedI18nPrefixes } = props;
|
|
58
|
+
const i18nKey = UITranslationUtils_1.extractI18nKey(value, allowedPatterns, allowedI18nPrefixes || [i18nPrefix]);
|
|
59
|
+
let message = '';
|
|
60
|
+
let tooltip = '';
|
|
61
|
+
let suggest;
|
|
62
|
+
if (i18nKey) {
|
|
63
|
+
// There is already i18n binding as value
|
|
64
|
+
const entry = UITranslationUtils_1.getTranslationByKey(entries, i18nKey);
|
|
65
|
+
if (entry) {
|
|
66
|
+
tooltip = strings.i18nEntryExistsTooltip;
|
|
67
|
+
suggest = {
|
|
68
|
+
entry,
|
|
69
|
+
type: SuggestValueType.Existing,
|
|
70
|
+
icon: Icons_1.UiIcons.WorldArrow
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
message = strings.i18nKeyMissingDescription;
|
|
75
|
+
tooltip = strings.i18nKeyMissingTooltip;
|
|
76
|
+
suggest = {
|
|
77
|
+
entry: {
|
|
78
|
+
key: {
|
|
79
|
+
value: i18nKey
|
|
80
|
+
},
|
|
81
|
+
value: {
|
|
82
|
+
value: i18nKey
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
type: SuggestValueType.New,
|
|
86
|
+
icon: Icons_1.UiIcons.WorldWarning
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Use generation format passed from outside or use default as 'Standard';
|
|
92
|
+
const existingEntry = UITranslationUtils_1.getTranslationByText(entries, value);
|
|
93
|
+
if (existingEntry) {
|
|
94
|
+
message = strings.i18nReplaceWithExistingDescription;
|
|
95
|
+
tooltip = strings.i18nReplaceWithExistingTooltip;
|
|
96
|
+
suggest = {
|
|
97
|
+
entry: existingEntry,
|
|
98
|
+
type: SuggestValueType.Update
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
message = strings.i18nValueMissingDescription;
|
|
103
|
+
tooltip = strings.i18nValueMissingTooltip;
|
|
104
|
+
const key = UITranslationUtils_1.generateI18nKey(value, namingConvention, entries);
|
|
105
|
+
suggest = {
|
|
106
|
+
entry: {
|
|
107
|
+
key: {
|
|
108
|
+
value: key
|
|
109
|
+
},
|
|
110
|
+
value: {
|
|
111
|
+
value
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
type: SuggestValueType.New
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// I18n string to apply for input value
|
|
119
|
+
suggest.i18n = UITranslationUtils_1.applyI18nPattern(suggest.entry.key.value, defaultPattern, i18nPrefix);
|
|
120
|
+
// Format message to show in callout
|
|
121
|
+
const messageValues = {
|
|
122
|
+
key: suggest.entry.key.value,
|
|
123
|
+
value: suggest.entry.value.value,
|
|
124
|
+
i18n: suggest.i18n
|
|
125
|
+
};
|
|
126
|
+
tooltip = UIFormattedText_1.formatText(tooltip, messageValues);
|
|
127
|
+
return {
|
|
128
|
+
message: react_1.default.createElement(UIFormattedText_1.UIFormattedText, { values: messageValues }, message),
|
|
129
|
+
tooltip,
|
|
130
|
+
suggest
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Component to render translation button to provide helper callout with i18n generation option.
|
|
135
|
+
*
|
|
136
|
+
* @param props Component properties.
|
|
137
|
+
* @returns Component to render translation button with callout.
|
|
138
|
+
*/
|
|
139
|
+
function UITranslationButton(props) {
|
|
140
|
+
const { id, strings, value, onCreateNewEntry, onUpdateValue, onShowExistingEntry, busy } = props;
|
|
141
|
+
const [isCalloutVisible, setCalloutVisible] = react_1.useState(false);
|
|
142
|
+
const suggestion = getTranslationSuggestion(props);
|
|
143
|
+
// Callbacks
|
|
144
|
+
const onToggleCallout = react_1.useCallback(() => {
|
|
145
|
+
if (suggestion.suggest?.type === SuggestValueType.Existing) {
|
|
146
|
+
setCalloutVisible(false);
|
|
147
|
+
// Trigger show existing entry callbACK
|
|
148
|
+
onShowExistingEntry?.(suggestion.suggest.entry);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
setCalloutVisible(!isCalloutVisible);
|
|
152
|
+
}
|
|
153
|
+
}, [isCalloutVisible, suggestion]);
|
|
154
|
+
const onAccept = react_1.useCallback(() => {
|
|
155
|
+
if (suggestion.suggest) {
|
|
156
|
+
if (suggestion.suggest.type === SuggestValueType.New) {
|
|
157
|
+
onCreateNewEntry?.(suggestion.suggest.entry);
|
|
158
|
+
}
|
|
159
|
+
if (value !== suggestion.suggest.i18n) {
|
|
160
|
+
onUpdateValue?.(suggestion.suggest.i18n || '');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
setCalloutVisible(false);
|
|
164
|
+
}, [suggestion, onCreateNewEntry, onUpdateValue, value]);
|
|
165
|
+
const onCancel = react_1.useCallback(() => {
|
|
166
|
+
setCalloutVisible(false);
|
|
167
|
+
}, []);
|
|
168
|
+
return (react_1.default.createElement("div", { className: "ui-translatable__button" },
|
|
169
|
+
react_1.default.createElement(UILoadButton_1.UILoadButton, { id: id, disabled: props.disabled ?? false, onClick: onToggleCallout, iconProps: { iconName: suggestion.suggest?.icon || Icons_1.UiIcons.World }, title: suggestion.tooltip, busy: busy?.busy, useMinWaitingTime: busy?.useMinWaitingTime }),
|
|
170
|
+
isCalloutVisible && (react_1.default.createElement(UICallout_1.UICallout, { target: `#${id}`, gapSpace: 5, directionalHint: 6, calloutWidth: 250, calloutMinWidth: 250, beakWidth: 8, isBeakVisible: false, setInitialFocus: true, className: "ui-translatable__callout", onDismiss: () => onToggleCallout(), contentPadding: UICallout_1.UICalloutContentPadding.Standard },
|
|
171
|
+
react_1.default.createElement("div", { className: "ui-translatable__message" },
|
|
172
|
+
suggestion.message,
|
|
173
|
+
react_1.default.createElement("div", { className: "ui-translatable__actions" },
|
|
174
|
+
react_1.default.createElement(UIButton_1.UIDefaultButton, { id: `${id}-button-action-confirm`, primary: true, onClick: onAccept }, getStringText('acceptButtonLabel', strings)),
|
|
175
|
+
react_1.default.createElement(UIButton_1.UIDefaultButton, { id: `${id}-button-action-cancel`, onClick: onCancel }, getStringText('cancelButtonLabel', strings))))))));
|
|
176
|
+
}
|
|
177
|
+
exports.UITranslationButton = UITranslationButton;
|
|
178
|
+
UITranslationButton.defaultProps = {
|
|
179
|
+
strings: defaults_1.defaultTranslationButtonStrings
|
|
180
|
+
};
|
|
181
|
+
//# sourceMappingURL=UITranslationButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UITranslationButton.js","sourceRoot":"","sources":["../../../src/components/UITranslationInput/UITranslationButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAqD;AAErD,0CAA8C;AAC9C,4CAAkE;AAClE,oCAAmC;AACnC,yCAA6D;AAE7D,2EAAsE;AACtE,6DAM8B;AAE9B,qCAAmC;AACnC,uDAAgE;AAChE,iDAA8C;AAE9C,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IACxB,yCAAqB,CAAA;IACrB,qCAAiB,CAAA;IACjB,+BAAW,CAAA;AACf,CAAC,EAJW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAI3B;AAmBD;;;;;;;GAOG;AACH,MAAM,aAAa,GAAG,CAAC,QAAwC,EAAE,OAAkC,EAAU,EAAE;IAC3G,OAAO,OAAO,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;AACrC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAAC,KAA+B,EAAsB,EAAE;IACrF,MAAM,EACF,KAAK,GAAG,EAAE,EACV,eAAe,EACf,OAAO,EACP,OAAO,GAAG,0CAA+B,EACzC,gBAAgB,GAAG,mDAAuB,CAAC,SAAS,EACpD,cAAc,EACd,UAAU,EACV,mBAAmB,EACtB,GAAG,KAAK,CAAC;IACV,MAAM,OAAO,GAAG,mCAAc,CAAC,KAAK,EAAE,eAAe,EAAE,mBAAmB,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5F,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,OAAgC,CAAC;IACrC,IAAI,OAAO,EAAE;QACT,yCAAyC;QACzC,MAAM,KAAK,GAAG,wCAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC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AAe,EAAE,IAAI,EACrB,SAAS,EAAC,0BAA0B,EACpC,SAAS,EAAE,GAAG,EAAE,CAAC,eAAe,EAAE,EAClC,cAAc,EAAE,mCAAuB,CAAC,QAAQ;YAChD,uCAAK,SAAS,EAAC,0BAA0B;gBACpC,UAAU,CAAC,OAAO;gBACnB,uCAAK,SAAS,EAAC,0BAA0B;oBACrC,8BAAC,0BAAe,IAAC,EAAE,EAAE,GAAG,EAAE,wBAAwB,EAAE,OAAO,QAAC,OAAO,EAAE,QAAQ,IACxE,aAAa,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAC9B;oBAClB,8BAAC,0BAAe,IAAC,EAAE,EAAE,GAAG,EAAE,uBAAuB,EAAE,OAAO,EAAE,QAAQ,IAC/D,aAAa,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAC9B,CAChB,CACJ,CACE,CACf,CACC,CACT,CAAC;AACN,CAAC;AArED,kDAqEC;AAED,mBAAmB,CAAC,YAAY,GAAG;IAC/B,OAAO,EAAE,0CAA+B;CAC3C,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface TranslationButtonStrings {
|
|
2
|
+
acceptButtonLabel: string;
|
|
3
|
+
cancelButtonLabel: string;
|
|
4
|
+
i18nEntryExistsTooltip: string;
|
|
5
|
+
i18nKeyMissingTooltip: string;
|
|
6
|
+
i18nKeyMissingDescription: string;
|
|
7
|
+
i18nValueMissingTooltip: string;
|
|
8
|
+
i18nValueMissingDescription: string;
|
|
9
|
+
i18nReplaceWithExistingTooltip: string;
|
|
10
|
+
i18nReplaceWithExistingDescription: string;
|
|
11
|
+
}
|
|
12
|
+
export declare enum TranslationKeyGenerator {
|
|
13
|
+
CamelCase = "CamelCase",
|
|
14
|
+
PascalCase = "PascalCase"
|
|
15
|
+
}
|
|
16
|
+
export declare enum TranslationTextPattern {
|
|
17
|
+
DoubleBracketReplace = "DoubleBracketReplace",
|
|
18
|
+
SingleBracketBinding = "SingleBracketBinding"
|
|
19
|
+
}
|
|
20
|
+
export interface TranslationEntryValue {
|
|
21
|
+
value: string;
|
|
22
|
+
}
|
|
23
|
+
export interface TranslationEntry {
|
|
24
|
+
key: TranslationEntryValue;
|
|
25
|
+
value: TranslationEntryValue;
|
|
26
|
+
}
|
|
27
|
+
export declare type I18nBundle = Record<string, TranslationEntry[]>;
|
|
28
|
+
export interface UITranslationProps {
|
|
29
|
+
value?: string;
|
|
30
|
+
id: string;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
entries: I18nBundle;
|
|
33
|
+
onShowExistingEntry?: (entry: TranslationEntry) => void;
|
|
34
|
+
onCreateNewEntry?: (entry: TranslationEntry) => void;
|
|
35
|
+
namingConvention?: TranslationKeyGenerator;
|
|
36
|
+
busy?: UILoadButtonBusyProps;
|
|
37
|
+
i18nPrefix: string;
|
|
38
|
+
allowedI18nPrefixes?: string[];
|
|
39
|
+
defaultPattern: TranslationTextPattern;
|
|
40
|
+
allowedPatterns: TranslationTextPattern[];
|
|
41
|
+
strings?: TranslationButtonStrings;
|
|
42
|
+
}
|
|
43
|
+
export interface UILoadButtonBusyProps {
|
|
44
|
+
busy?: boolean;
|
|
45
|
+
useMinWaitingTime?: boolean | number;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=UITranslationButton.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UITranslationButton.types.d.ts","sourceRoot":"","sources":["../../../src/components/UITranslationInput/UITranslationButton.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACrC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,yBAAyB,EAAE,MAAM,CAAC;IAClC,uBAAuB,EAAE,MAAM,CAAC;IAChC,2BAA2B,EAAE,MAAM,CAAC;IACpC,8BAA8B,EAAE,MAAM,CAAC;IACvC,kCAA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Generator = void 0;
|
|
4
|
+
var TranslationKeyGenerator;
|
|
5
|
+
(function (TranslationKeyGenerator) {
|
|
6
|
+
TranslationKeyGenerator["CamelCase"] = "CamelCase";
|
|
7
|
+
TranslationKeyGenerator["PascalCase"] = "PascalCase";
|
|
8
|
+
})(TranslationKeyGenerator = exports.TranslationKeyGenerator || (exports.TranslationKeyGenerator = {}));
|
|
9
|
+
var TranslationTextPattern;
|
|
10
|
+
(function (TranslationTextPattern) {
|
|
11
|
+
// Pattern `{{}}`
|
|
12
|
+
TranslationTextPattern["DoubleBracketReplace"] = "DoubleBracketReplace";
|
|
13
|
+
// Pattern `{key>}`
|
|
14
|
+
TranslationTextPattern["SingleBracketBinding"] = "SingleBracketBinding";
|
|
15
|
+
})(TranslationTextPattern = exports.TranslationTextPattern || (exports.TranslationTextPattern = {}));
|
|
16
|
+
//# sourceMappingURL=UITranslationButton.types.js.map
|