@chayns-components/textstring 5.0.0-beta.997 → 5.0.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/lib/cjs/components/textstring/Textstring.js +1 -2
- package/lib/cjs/components/textstring/Textstring.js.map +1 -1
- package/lib/cjs/components/textstring/types.js +4 -0
- package/lib/cjs/components/textstring-provider/TextstringProvider.js +1 -2
- package/lib/cjs/components/textstring-provider/TextstringProvider.js.map +1 -1
- package/lib/cjs/index.js +6 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types/textstring.js +4 -0
- package/lib/cjs/utils/textstring.js +23 -2
- package/lib/cjs/utils/textstring.js.map +1 -1
- package/lib/esm/components/textstring/Textstring.js +9 -10
- package/lib/esm/components/textstring/Textstring.js.map +1 -1
- package/lib/esm/components/textstring/types.js +1 -1
- package/lib/esm/components/textstring-provider/TextstringProvider.js +5 -6
- package/lib/esm/components/textstring-provider/TextstringProvider.js.map +1 -1
- package/lib/esm/hooks/useTextstringValue.js +4 -5
- package/lib/esm/hooks/useTextstringValue.js.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types/textstring.js +1 -1
- package/lib/esm/utils/textstring.js +32 -15
- package/lib/esm/utils/textstring.js.map +1 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/utils/textstring.d.ts +11 -0
- package/package.json +18 -17
|
@@ -8,8 +8,7 @@ var _core = require("@chayns-components/core");
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _useTextstringValue = require("../../hooks/useTextstringValue");
|
|
10
10
|
var _textstring = require("../../utils/textstring");
|
|
11
|
-
function
|
|
12
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (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 (const 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); }
|
|
13
12
|
const Textstring = ({
|
|
14
13
|
children,
|
|
15
14
|
childrenClassName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Textstring.js","names":["_core","require","_react","_interopRequireWildcard","_useTextstringValue","_textstring","
|
|
1
|
+
{"version":3,"file":"Textstring.js","names":["_core","require","_react","_interopRequireWildcard","_useTextstringValue","_textstring","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","Textstring","children","childrenClassName","childrenStyles","childrenTagName","isTextstringHTML","replacements","textstring","text","useTextstringValue","childrenOnClickFunction","props","onClick","handleClick","useCallback","event","ctrlKey","isTobitEmployee","then","inGroup","selectLanguageToChange","textstringName","name","React","cloneElement","dangerouslySetInnerHTML","__html","undefined","createElement","className","trim","style","displayName","_default","exports"],"sources":["../../../../src/components/textstring/Textstring.tsx"],"sourcesContent":["import { isTobitEmployee } from '@chayns-components/core';\nimport React, {\n CSSProperties,\n FC,\n MouseEvent,\n ReactHTML,\n useCallback,\n type ReactElement,\n} from 'react';\nimport { useTextstringValue } from '../../hooks/useTextstringValue';\nimport { selectLanguageToChange } from '../../utils/textstring';\nimport type { ITextstring, TextstringReplacement } from './types';\n\nexport type TextstringProps = {\n /**\n * The element that the text should be displayed in.\n */\n children?: ReactElement;\n /**\n * The class name of the HTML element that the text should be displayed in. Only used if `children` is not set.\n */\n childrenClassName?: string;\n /**\n * The styles of the HTML element that the text should be displayed in. Only used if `children` is not set.\n */\n childrenStyles?: CSSProperties;\n /**\n * The tag of the HTML element that the text should be displayed in. Only used if `children` is not set.\n */\n childrenTagName?: keyof ReactHTML;\n /**\n * Whether the textstring contains HTML elements and should be displayed as HTML.\n */\n isTextstringHTML?: boolean;\n /**\n * Replacement values for the textstring.\n */\n replacements?: TextstringReplacement;\n /**\n * The text that should be displayed.\n */\n textstring: ITextstring;\n};\n\nconst Textstring: FC<TextstringProps> = ({\n children,\n childrenClassName,\n childrenStyles,\n childrenTagName,\n isTextstringHTML,\n replacements,\n textstring,\n}) => {\n const text = useTextstringValue({ textstring, replacements });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const childrenOnClickFunction = children?.props.onClick as\n | ((event: MouseEvent<HTMLElement>) => void)\n | undefined;\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLElement>) => {\n if (event.ctrlKey) {\n void isTobitEmployee().then((inGroup) => {\n if (inGroup) {\n selectLanguageToChange({\n textstringName: textstring.name,\n });\n }\n });\n } else if (typeof childrenOnClickFunction === 'function') {\n childrenOnClickFunction(event);\n }\n },\n [childrenOnClickFunction, textstring.name],\n );\n\n if (children) {\n return React.cloneElement(\n children,\n {\n dangerouslySetInnerHTML: isTextstringHTML ? { __html: text } : undefined,\n onClick: handleClick,\n },\n isTextstringHTML ? undefined : text,\n );\n }\n\n // eslint-disable-next-line react/no-danger-with-children\n return React.createElement(\n childrenTagName || 'span',\n {\n dangerouslySetInnerHTML: isTextstringHTML ? { __html: text } : undefined,\n className: `${childrenClassName || ''} notranslate`.trim(),\n onClick: handleClick,\n style: childrenStyles,\n },\n isTextstringHTML ? undefined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IACpBkB,KAAK,EAAE5B;EACX,CAAC,EACDE,gBAAgB,GAAGsB,SAAS,GAAGnB,IACnC,CAAC;AACL,CAAC;AAEDR,UAAU,CAACgC,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA3C,OAAA,GAEvBS,UAAU","ignoreList":[]}
|
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = exports.TextstringContext = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _textstring = require("../../utils/textstring");
|
|
9
|
-
function
|
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (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 (const 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); }
|
|
11
10
|
const TextstringContext = exports.TextstringContext = /*#__PURE__*/(0, _react.createContext)({});
|
|
12
11
|
const TextstringProvider = ({
|
|
13
12
|
children,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextstringProvider.js","names":["_react","_interopRequireWildcard","require","_textstring","
|
|
1
|
+
{"version":3,"file":"TextstringProvider.js","names":["_react","_interopRequireWildcard","require","_textstring","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","TextstringContext","exports","createContext","TextstringProvider","children","libraryName","language","textstrings","setTextstrings","useState","useEffect","loadData","textstringResult","loadLibrary","prevTextstrings","window","Textstrings","createElement","Provider","value","displayName","_default"],"sources":["../../../../src/components/textstring-provider/TextstringProvider.tsx"],"sourcesContent":["import React, { createContext, FC, ReactNode, useEffect, useState } from 'react';\nimport type { TextstringValue } from '../../types/textstring';\nimport { loadLibrary } from '../../utils/textstring';\n\nexport const TextstringContext = createContext<TextstringValue>({});\n\nexport type TextstringProviderProps = {\n /**\n * The element that should use the library.\n */\n children?: ReactNode;\n /**\n * The language that should be used.\n */\n language: string;\n /**\n * The name of the library.\n */\n libraryName: string;\n};\n\nconst TextstringProvider: FC<TextstringProviderProps> = ({ children, libraryName, language }) => {\n const [textstrings, setTextstrings] = useState<TextstringValue>({});\n\n useEffect(() => {\n const loadData = async () => {\n const textstringResult = await loadLibrary({ libraryName, language });\n\n if (textstringResult) {\n const prevTextstrings = window.Textstrings;\n\n window.Textstrings = {\n ...prevTextstrings,\n [libraryName]: textstringResult,\n };\n\n setTextstrings(textstringResult);\n }\n };\n\n void loadData();\n }, [language, libraryName]);\n\n return <TextstringContext.Provider value={textstrings}>{children}</TextstringContext.Provider>;\n};\n\nTextstringProvider.displayName = 'TextstringProvider';\n\nexport default TextstringProvider;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AAAqD,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAA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;MAAS,CAAC,CAAC;MAErE,IAAIM,gBAAgB,EAAE;QAClB,MAAME,eAAe,GAAGC,MAAM,CAACC,WAAW;QAE1CD,MAAM,CAACC,WAAW,GAAG;UACjB,GAAGF,eAAe;UAClB,CAACT,WAAW,GAAGO;QACnB,CAAC;QAEDJ,cAAc,CAACI,gBAAgB,CAAC;MACpC;IACJ,CAAC;IAED,KAAKD,QAAQ,CAAC,CAAC;EACnB,CAAC,EAAE,CAACL,QAAQ,EAAED,WAAW,CAAC,CAAC;EAE3B,oBAAO5B,MAAA,CAAAc,OAAA,CAAA0B,aAAA,CAACjB,iBAAiB,CAACkB,QAAQ;IAACC,KAAK,EAAEZ;EAAY,GAAEH,QAAqC,CAAC;AAClG,CAAC;AAEDD,kBAAkB,CAACiB,WAAW,GAAG,oBAAoB;AAAC,IAAAC,QAAA,GAAApB,OAAA,CAAAV,OAAA,GAEvCY,kBAAkB","ignoreList":[]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "getTextstringValue", {
|
|
|
21
21
|
return _textstring.getTextstringValue;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "initTextstrings", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _textstring.initTextstrings;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
24
30
|
Object.defineProperty(exports, "useTextstringValue", {
|
|
25
31
|
enumerable: true,
|
|
26
32
|
get: function () {
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_TextstringProvider","_interopRequireDefault","require","_Textstring","_useTextstringValue","_textstring","e","__esModule","default"],"sources":["../../src/index.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nexport { default as TextstringProvider } from './components/textstring-provider/TextstringProvider';\nexport { default as Textstring } from './components/textstring/Textstring';\nexport type { ITextstring, TextstringReplacement } from './components/textstring/types';\nexport { useTextstringValue } from './hooks/useTextstringValue';\nexport { getTextstringValue } from './utils/textstring';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["_TextstringProvider","_interopRequireDefault","require","_Textstring","_useTextstringValue","_textstring","e","__esModule","default"],"sources":["../../src/index.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nexport { default as TextstringProvider } from './components/textstring-provider/TextstringProvider';\nexport { default as Textstring } from './components/textstring/Textstring';\nexport type { ITextstring, TextstringReplacement } from './components/textstring/types';\nexport { useTextstringValue } from './hooks/useTextstringValue';\nexport { getTextstringValue, initTextstrings } from './utils/textstring';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAAA,mBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAAyE,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.selectLanguageToChange = exports.loadLibrary = exports.getTextstringValue = void 0;
|
|
6
|
+
exports.selectLanguageToChange = exports.loadLibrary = exports.initTextstrings = exports.getTextstringValue = void 0;
|
|
7
7
|
var _chaynsApi = require("chayns-api");
|
|
8
8
|
const loadLibrary = async ({
|
|
9
9
|
language,
|
|
@@ -33,6 +33,24 @@ const selectLanguageToChange = ({
|
|
|
33
33
|
});
|
|
34
34
|
};
|
|
35
35
|
exports.selectLanguageToChange = selectLanguageToChange;
|
|
36
|
+
const initTextstrings = ({
|
|
37
|
+
libraryName,
|
|
38
|
+
language
|
|
39
|
+
}) => {
|
|
40
|
+
void loadLibrary({
|
|
41
|
+
libraryName,
|
|
42
|
+
language
|
|
43
|
+
}).then(result => {
|
|
44
|
+
if (result) {
|
|
45
|
+
const prevTextstrings = window.Textstrings;
|
|
46
|
+
window.Textstrings = {
|
|
47
|
+
...prevTextstrings,
|
|
48
|
+
[libraryName]: result
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
exports.initTextstrings = initTextstrings;
|
|
36
54
|
const getTextstringValue = ({
|
|
37
55
|
libraryName,
|
|
38
56
|
textstring,
|
|
@@ -41,7 +59,10 @@ const getTextstringValue = ({
|
|
|
41
59
|
var _window$Textstrings;
|
|
42
60
|
const textstrings = typeof window !== 'undefined' ? (_window$Textstrings = window.Textstrings) === null || _window$Textstrings === void 0 ? void 0 : _window$Textstrings[libraryName] : undefined;
|
|
43
61
|
if (!textstrings) {
|
|
44
|
-
|
|
62
|
+
if (!replacements) {
|
|
63
|
+
return textstring.fallback;
|
|
64
|
+
}
|
|
65
|
+
return Object.keys(replacements).reduce((current, key) => current.replace(new RegExp(key, 'g'), replacements[key] || ''), textstring.fallback);
|
|
45
66
|
}
|
|
46
67
|
const value = textstrings[textstring.name] ?? textstring.fallback;
|
|
47
68
|
if (!replacements) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textstring.js","names":["_chaynsApi","require","loadLibrary","language","libraryName","response","fetch","status","json","exports","selectLanguageToChange","textstringName","dialog","iFrame","url","buttons","input","textstring","
|
|
1
|
+
{"version":3,"file":"textstring.js","names":["_chaynsApi","require","loadLibrary","language","libraryName","response","fetch","status","json","exports","selectLanguageToChange","textstringName","dialog","iFrame","url","buttons","input","textstring","initTextstrings","then","result","prevTextstrings","window","Textstrings","getTextstringValue","replacements","_window$Textstrings","textstrings","undefined","fallback","Object","keys","reduce","current","key","replace","RegExp","value","name"],"sources":["../../../src/utils/textstring.ts"],"sourcesContent":["import { dialog } from 'chayns-api';\nimport type { ITextstring, TextstringReplacement } from '../components/textstring/types';\nimport type { TextstringValue } from '../types/textstring';\n\ninterface LoadLibraryOptions {\n libraryName: string;\n language: string;\n}\n\nexport const loadLibrary = async ({ language, libraryName }: LoadLibraryOptions) => {\n const response = await fetch(\n `https://webapi.tobit.com/TextstringService/v1.0/LangStrings/${libraryName}?language=${language}`,\n );\n\n if (response.status !== 200) {\n return null;\n }\n\n return (await response.json()) as TextstringValue;\n};\n\ninterface SelectLanguageToChangeOptions {\n textstringName: string;\n}\n\nexport const selectLanguageToChange = ({ textstringName }: SelectLanguageToChangeOptions) => {\n // Note: the page is in v4\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n void dialog.iFrame({\n url: 'https://tapp-staging.chayns-static.space/text-string-tapp/v1/iframe-edit.html',\n buttons: [],\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n input: { textstring: textstringName },\n });\n};\n\ninterface InitTextstringsOptions {\n /**\n * The language that should be used.\n */\n language: string;\n /**\n * The name of the library.\n */\n libraryName: string;\n}\n\nexport const initTextstrings = ({ libraryName, language }: InitTextstringsOptions) => {\n void loadLibrary({ libraryName, language }).then((result) => {\n if (result) {\n const prevTextstrings = window.Textstrings;\n\n window.Textstrings = {\n ...prevTextstrings,\n [libraryName]: result,\n };\n }\n });\n};\n\ninterface GetTextstringValueOptions {\n textstring: ITextstring;\n libraryName: string;\n replacements?: TextstringReplacement;\n}\n\nexport const getTextstringValue = ({\n libraryName,\n textstring,\n replacements,\n}: GetTextstringValueOptions): string => {\n const textstrings =\n typeof window !== 'undefined' ? window.Textstrings?.[libraryName] : undefined;\n\n if (!textstrings) {\n if (!replacements) {\n return textstring.fallback;\n }\n\n return Object.keys(replacements).reduce(\n (current, key) =>\n current.replace(new RegExp(key, 'g'), <string>replacements[key] || ''),\n textstring.fallback,\n );\n }\n\n const value = textstrings[textstring.name] ?? textstring.fallback;\n\n if (!replacements) {\n return value;\n }\n\n return Object.keys(replacements).reduce(\n (current, key) => current.replace(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;EACrC,MAAMC,WAAW,GACb,OAAOL,MAAM,KAAK,WAAW,IAAAI,mBAAA,GAAGJ,MAAM,CAACC,WAAW,cAAAG,mBAAA,uBAAlBA,mBAAA,CAAqBtB,WAAW,CAAC,GAAGwB,SAAS;EAEjF,IAAI,CAACD,WAAW,EAAE;IACd,IAAI,CAACF,YAAY,EAAE;MACf,OAAOR,UAAU,CAACY,QAAQ;IAC9B;IAEA,OAAOC,MAAM,CAACC,IAAI,CAACN,YAAY,CAAC,CAACO,MAAM,CACnC,CAACC,OAAO,EAAEC,GAAG,KACTD,OAAO,CAACE,OAAO,CAAC,IAAIC,MAAM,CAACF,GAAG,EAAE,GAAG,CAAC,EAAUT,YAAY,CAACS,GAAG,CAAC,IAAI,EAAE,CAAC,EAC1EjB,UAAU,CAACY,QACf,CAAC;EACL;EAEA,MAAMQ,KAAK,GAAGV,WAAW,CAACV,UAAU,CAACqB,IAAI,CAAC,IAAIrB,UAAU,CAACY,QAAQ;EAEjE,IAAI,CAACJ,YAAY,EAAE;IACf,OAAOY,KAAK;EAChB;EAEA,OAAOP,MAAM,CAACC,IAAI,CAACN,YAAY,CAAC,CAACO,MAAM,CACnC,CAACC,OAAO,EAAEC,GAAG,KAAKD,OAAO,CAACE,OAAO,CAAC,IAAIC,MAAM,CAACF,GAAG,EAAE,GAAG,CAAC,EAAUT,YAAY,CAACS,GAAG,CAAC,IAAI,EAAE,CAAC,EACxFG,KACJ,CAAC;AACL,CAAC;AAAC5B,OAAA,CAAAe,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -2,16 +2,15 @@ import { isTobitEmployee } from '@chayns-components/core';
|
|
|
2
2
|
import React, { useCallback } from 'react';
|
|
3
3
|
import { useTextstringValue } from '../../hooks/useTextstringValue';
|
|
4
4
|
import { selectLanguageToChange } from '../../utils/textstring';
|
|
5
|
-
const Textstring =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} = _ref;
|
|
5
|
+
const Textstring = ({
|
|
6
|
+
children,
|
|
7
|
+
childrenClassName,
|
|
8
|
+
childrenStyles,
|
|
9
|
+
childrenTagName,
|
|
10
|
+
isTextstringHTML,
|
|
11
|
+
replacements,
|
|
12
|
+
textstring
|
|
13
|
+
}) => {
|
|
15
14
|
const text = useTextstringValue({
|
|
16
15
|
textstring,
|
|
17
16
|
replacements
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Textstring.js","names":["isTobitEmployee","React","useCallback","useTextstringValue","selectLanguageToChange","Textstring","
|
|
1
|
+
{"version":3,"file":"Textstring.js","names":["isTobitEmployee","React","useCallback","useTextstringValue","selectLanguageToChange","Textstring","children","childrenClassName","childrenStyles","childrenTagName","isTextstringHTML","replacements","textstring","text","childrenOnClickFunction","props","onClick","handleClick","event","ctrlKey","then","inGroup","textstringName","name","cloneElement","dangerouslySetInnerHTML","__html","undefined","createElement","className","trim","style","displayName"],"sources":["../../../../src/components/textstring/Textstring.tsx"],"sourcesContent":["import { isTobitEmployee } from '@chayns-components/core';\nimport React, {\n CSSProperties,\n FC,\n MouseEvent,\n ReactHTML,\n useCallback,\n type ReactElement,\n} from 'react';\nimport { useTextstringValue } from '../../hooks/useTextstringValue';\nimport { selectLanguageToChange } from '../../utils/textstring';\nimport type { ITextstring, TextstringReplacement } from './types';\n\nexport type TextstringProps = {\n /**\n * The element that the text should be displayed in.\n */\n children?: ReactElement;\n /**\n * The class name of the HTML element that the text should be displayed in. Only used if `children` is not set.\n */\n childrenClassName?: string;\n /**\n * The styles of the HTML element that the text should be displayed in. Only used if `children` is not set.\n */\n childrenStyles?: CSSProperties;\n /**\n * The tag of the HTML element that the text should be displayed in. Only used if `children` is not set.\n */\n childrenTagName?: keyof ReactHTML;\n /**\n * Whether the textstring contains HTML elements and should be displayed as HTML.\n */\n isTextstringHTML?: boolean;\n /**\n * Replacement values for the textstring.\n */\n replacements?: TextstringReplacement;\n /**\n * The text that should be displayed.\n */\n textstring: ITextstring;\n};\n\nconst Textstring: FC<TextstringProps> = ({\n children,\n childrenClassName,\n childrenStyles,\n childrenTagName,\n isTextstringHTML,\n replacements,\n textstring,\n}) => {\n const text = useTextstringValue({ textstring, replacements });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const childrenOnClickFunction = children?.props.onClick as\n | ((event: MouseEvent<HTMLElement>) => void)\n | undefined;\n\n const handleClick = useCallback(\n (event: MouseEvent<HTMLElement>) => {\n if (event.ctrlKey) {\n void isTobitEmployee().then((inGroup) => {\n if (inGroup) {\n selectLanguageToChange({\n textstringName: textstring.name,\n });\n }\n });\n } else if (typeof childrenOnClickFunction === 'function') {\n childrenOnClickFunction(event);\n }\n },\n [childrenOnClickFunction, textstring.name],\n );\n\n if (children) {\n return React.cloneElement(\n children,\n {\n dangerouslySetInnerHTML: isTextstringHTML ? { __html: text } : undefined,\n onClick: handleClick,\n },\n isTextstringHTML ? undefined : text,\n );\n }\n\n // eslint-disable-next-line react/no-danger-with-children\n return React.createElement(\n childrenTagName || 'span',\n {\n dangerouslySetInnerHTML: isTextstringHTML ? { __html: text } : undefined,\n className: `${childrenClassName || ''} notranslate`.trim(),\n onClick: handleClick,\n style: childrenStyles,\n },\n isTextstringHTML ? undefined : text,\n );\n};\n\nTextstring.displayName = 'Textstring';\n\nexport default Textstring;\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,yBAAyB;AACzD,OAAOC,KAAK,IAKRC,WAAW,QAER,OAAO;AACd,SAASC,kBAAkB,QAAQ,gCAAgC;AACnE,SAASC,sBAAsB,QAAQ,wBAAwB;AAkC/D,MAAMC,UAA+B,GAAGA,CAAC;EACrCC,QAAQ;EACRC,iBAAiB;EACjBC,cAAc;EACdC,eAAe;EACfC,gBAAgB;EAChBC,YAAY;EACZC;AACJ,CAAC,KAAK;EACF,MAAMC,IAAI,GAAGV,kBAAkB,CAAC;IAAES,UAAU;IAAED;EAAa,CAAC,CAAC;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
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import React, { createContext, useEffect, useState } from 'react';
|
|
2
2
|
import { loadLibrary } from '../../utils/textstring';
|
|
3
3
|
export const TextstringContext = /*#__PURE__*/createContext({});
|
|
4
|
-
const TextstringProvider =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} = _ref;
|
|
4
|
+
const TextstringProvider = ({
|
|
5
|
+
children,
|
|
6
|
+
libraryName,
|
|
7
|
+
language
|
|
8
|
+
}) => {
|
|
10
9
|
const [textstrings, setTextstrings] = useState({});
|
|
11
10
|
useEffect(() => {
|
|
12
11
|
const loadData = async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextstringProvider.js","names":["React","createContext","useEffect","useState","loadLibrary","TextstringContext","TextstringProvider","
|
|
1
|
+
{"version":3,"file":"TextstringProvider.js","names":["React","createContext","useEffect","useState","loadLibrary","TextstringContext","TextstringProvider","children","libraryName","language","textstrings","setTextstrings","loadData","textstringResult","prevTextstrings","window","Textstrings","createElement","Provider","value","displayName"],"sources":["../../../../src/components/textstring-provider/TextstringProvider.tsx"],"sourcesContent":["import React, { createContext, FC, ReactNode, useEffect, useState } from 'react';\nimport type { TextstringValue } from '../../types/textstring';\nimport { loadLibrary } from '../../utils/textstring';\n\nexport const TextstringContext = createContext<TextstringValue>({});\n\nexport type TextstringProviderProps = {\n /**\n * The element that should use the library.\n */\n children?: ReactNode;\n /**\n * The language that should be used.\n */\n language: string;\n /**\n * The name of the library.\n */\n libraryName: string;\n};\n\nconst TextstringProvider: FC<TextstringProviderProps> = ({ children, libraryName, language }) => {\n const [textstrings, setTextstrings] = useState<TextstringValue>({});\n\n useEffect(() => {\n const loadData = async () => {\n const textstringResult = await loadLibrary({ libraryName, language });\n\n if (textstringResult) {\n const prevTextstrings = window.Textstrings;\n\n window.Textstrings = {\n ...prevTextstrings,\n [libraryName]: textstringResult,\n };\n\n setTextstrings(textstringResult);\n }\n };\n\n void loadData();\n }, [language, libraryName]);\n\n return <TextstringContext.Provider value={textstrings}>{children}</TextstringContext.Provider>;\n};\n\nTextstringProvider.displayName = 'TextstringProvider';\n\nexport default TextstringProvider;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,aAAa,EAAiBC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAEhF,SAASC,WAAW,QAAQ,wBAAwB;AAEpD,OAAO,MAAMC,iBAAiB,gBAAGJ,aAAa,CAAkB,CAAC,CAAC,CAAC;AAiBnE,MAAMK,kBAA+C,GAAGA,CAAC;EAAEC,QAAQ;EAAEC,WAAW;EAAEC;AAAS,CAAC,KAAK;EAC7F,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGR,QAAQ,CAAkB,CAAC,CAAC,CAAC;EAEnED,SAAS,CAAC,MAAM;IACZ,MAAMU,QAAQ,GAAG,MAAAA,CAAA,KAAY;MACzB,MAAMC,gBAAgB,GAAG,MAAMT,WAAW,CAAC;QAAEI,WAAW;QAAEC;MAAS,CAAC,CAAC;MAErE,IAAII,gBAAgB,EAAE;QAClB,MAAMC,eAAe,GAAGC,MAAM,CAACC,WAAW;QAE1CD,MAAM,CAACC,WAAW,GAAG;UACjB,GAAGF,eAAe;UAClB,CAACN,WAAW,GAAGK;QACnB,CAAC;QAEDF,cAAc,CAACE,gBAAgB,CAAC;MACpC;IACJ,CAAC;IAED,KAAKD,QAAQ,CAAC,CAAC;EACnB,CAAC,EAAE,CAACH,QAAQ,EAAED,WAAW,CAAC,CAAC;EAE3B,oBAAOR,KAAA,CAAAiB,aAAA,CAACZ,iBAAiB,CAACa,QAAQ;IAACC,KAAK,EAAET;EAAY,GAAEH,QAAqC,CAAC;AAClG,CAAC;AAEDD,kBAAkB,CAACc,WAAW,GAAG,oBAAoB;AAErD,eAAed,kBAAkB","ignoreList":[]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import { TextstringContext } from '../components/textstring-provider/TextstringProvider';
|
|
3
|
-
export const useTextstringValue =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} = _ref;
|
|
3
|
+
export const useTextstringValue = ({
|
|
4
|
+
replacements,
|
|
5
|
+
textstring
|
|
6
|
+
}) => {
|
|
8
7
|
const textstrings = useContext(TextstringContext);
|
|
9
8
|
const value = textstrings[textstring.name] ?? textstring.fallback;
|
|
10
9
|
if (!replacements) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTextstringValue.js","names":["useContext","TextstringContext","useTextstringValue","
|
|
1
|
+
{"version":3,"file":"useTextstringValue.js","names":["useContext","TextstringContext","useTextstringValue","replacements","textstring","textstrings","value","name","fallback","Object","keys","reduce","current","key","replace","RegExp"],"sources":["../../../src/hooks/useTextstringValue.ts"],"sourcesContent":["import { useContext } from 'react';\nimport { TextstringContext } from '../components/textstring-provider/TextstringProvider';\nimport type { ITextstring, TextstringReplacement } from '../components/textstring/types';\n\nexport interface UseTextstringValue {\n textstring: ITextstring;\n replacements?: TextstringReplacement;\n}\n\nexport const useTextstringValue = ({ replacements, textstring }: UseTextstringValue) => {\n const textstrings = useContext(TextstringContext);\n\n const value = textstrings[textstring.name] ?? textstring.fallback;\n\n if (!replacements) {\n return value;\n }\n\n return Object.keys(replacements).reduce(\n (current, key) => current.replace(new RegExp(key, 'g'), <string>replacements[key] || ''),\n value,\n );\n};\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAClC,SAASC,iBAAiB,QAAQ,sDAAsD;AAQxF,OAAO,MAAMC,kBAAkB,GAAGA,CAAC;EAAEC,YAAY;EAAEC;AAA+B,CAAC,KAAK;EACpF,MAAMC,WAAW,GAAGL,UAAU,CAACC,iBAAiB,CAAC;EAEjD,MAAMK,KAAK,GAAGD,WAAW,CAACD,UAAU,CAACG,IAAI,CAAC,IAAIH,UAAU,CAACI,QAAQ;EAEjE,IAAI,CAACL,YAAY,EAAE;IACf,OAAOG,KAAK;EAChB;EAEA,OAAOG,MAAM,CAACC,IAAI,CAACP,YAAY,CAAC,CAACQ,MAAM,CACnC,CAACC,OAAO,EAAEC,GAAG,KAAKD,OAAO,CAACE,OAAO,CAAC,IAAIC,MAAM,CAACF,GAAG,EAAE,GAAG,CAAC,EAAUV,YAAY,CAACU,GAAG,CAAC,IAAI,EAAE,CAAC,EACxFP,KACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
package/lib/esm/index.js
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
export { default as TextstringProvider } from './components/textstring-provider/TextstringProvider';
|
|
4
4
|
export { default as Textstring } from './components/textstring/Textstring';
|
|
5
5
|
export { useTextstringValue } from './hooks/useTextstringValue';
|
|
6
|
-
export { getTextstringValue } from './utils/textstring';
|
|
6
|
+
export { getTextstringValue, initTextstrings } from './utils/textstring';
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["default","TextstringProvider","Textstring","useTextstringValue","getTextstringValue"],"sources":["../../src/index.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nexport { default as TextstringProvider } from './components/textstring-provider/TextstringProvider';\nexport { default as Textstring } from './components/textstring/Textstring';\nexport type { ITextstring, TextstringReplacement } from './components/textstring/types';\nexport { useTextstringValue } from './hooks/useTextstringValue';\nexport { getTextstringValue } from './utils/textstring';\n"],"mappings":"AAAA;;AAEA,SAASA,OAAO,IAAIC,kBAAkB,QAAQ,qDAAqD;AACnG,SAASD,OAAO,IAAIE,UAAU,QAAQ,oCAAoC;AAE1E,SAASC,kBAAkB,QAAQ,4BAA4B;AAC/D,SAASC,kBAAkB,QAAQ,oBAAoB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","TextstringProvider","Textstring","useTextstringValue","getTextstringValue","initTextstrings"],"sources":["../../src/index.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nexport { default as TextstringProvider } from './components/textstring-provider/TextstringProvider';\nexport { default as Textstring } from './components/textstring/Textstring';\nexport type { ITextstring, TextstringReplacement } from './components/textstring/types';\nexport { useTextstringValue } from './hooks/useTextstringValue';\nexport { getTextstringValue, initTextstrings } from './utils/textstring';\n"],"mappings":"AAAA;;AAEA,SAASA,OAAO,IAAIC,kBAAkB,QAAQ,qDAAqD;AACnG,SAASD,OAAO,IAAIE,UAAU,QAAQ,oCAAoC;AAE1E,SAASC,kBAAkB,QAAQ,4BAA4B;AAC/D,SAASC,kBAAkB,EAAEC,eAAe,QAAQ,oBAAoB","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=textstring.js.map
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { dialog } from 'chayns-api';
|
|
2
|
-
export const loadLibrary = async
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} = _ref;
|
|
2
|
+
export const loadLibrary = async ({
|
|
3
|
+
language,
|
|
4
|
+
libraryName
|
|
5
|
+
}) => {
|
|
7
6
|
const response = await fetch(`https://webapi.tobit.com/TextstringService/v1.0/LangStrings/${libraryName}?language=${language}`);
|
|
8
7
|
if (response.status !== 200) {
|
|
9
8
|
return null;
|
|
10
9
|
}
|
|
11
10
|
return await response.json();
|
|
12
11
|
};
|
|
13
|
-
export const selectLanguageToChange =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} = _ref2;
|
|
12
|
+
export const selectLanguageToChange = ({
|
|
13
|
+
textstringName
|
|
14
|
+
}) => {
|
|
17
15
|
// Note: the page is in v4
|
|
18
16
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
19
17
|
// @ts-ignore
|
|
@@ -27,15 +25,34 @@ export const selectLanguageToChange = _ref2 => {
|
|
|
27
25
|
}
|
|
28
26
|
});
|
|
29
27
|
};
|
|
30
|
-
export const
|
|
31
|
-
|
|
28
|
+
export const initTextstrings = ({
|
|
29
|
+
libraryName,
|
|
30
|
+
language
|
|
31
|
+
}) => {
|
|
32
|
+
void loadLibrary({
|
|
32
33
|
libraryName,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
language
|
|
35
|
+
}).then(result => {
|
|
36
|
+
if (result) {
|
|
37
|
+
const prevTextstrings = window.Textstrings;
|
|
38
|
+
window.Textstrings = {
|
|
39
|
+
...prevTextstrings,
|
|
40
|
+
[libraryName]: result
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
export const getTextstringValue = ({
|
|
46
|
+
libraryName,
|
|
47
|
+
textstring,
|
|
48
|
+
replacements
|
|
49
|
+
}) => {
|
|
36
50
|
const textstrings = typeof window !== 'undefined' ? window.Textstrings?.[libraryName] : undefined;
|
|
37
51
|
if (!textstrings) {
|
|
38
|
-
|
|
52
|
+
if (!replacements) {
|
|
53
|
+
return textstring.fallback;
|
|
54
|
+
}
|
|
55
|
+
return Object.keys(replacements).reduce((current, key) => current.replace(new RegExp(key, 'g'), replacements[key] || ''), textstring.fallback);
|
|
39
56
|
}
|
|
40
57
|
const value = textstrings[textstring.name] ?? textstring.fallback;
|
|
41
58
|
if (!replacements) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textstring.js","names":["dialog","loadLibrary","
|
|
1
|
+
{"version":3,"file":"textstring.js","names":["dialog","loadLibrary","language","libraryName","response","fetch","status","json","selectLanguageToChange","textstringName","iFrame","url","buttons","input","textstring","initTextstrings","then","result","prevTextstrings","window","Textstrings","getTextstringValue","replacements","textstrings","undefined","fallback","Object","keys","reduce","current","key","replace","RegExp","value","name"],"sources":["../../../src/utils/textstring.ts"],"sourcesContent":["import { dialog } from 'chayns-api';\nimport type { ITextstring, TextstringReplacement } from '../components/textstring/types';\nimport type { TextstringValue } from '../types/textstring';\n\ninterface LoadLibraryOptions {\n libraryName: string;\n language: string;\n}\n\nexport const loadLibrary = async ({ language, libraryName }: LoadLibraryOptions) => {\n const response = await fetch(\n `https://webapi.tobit.com/TextstringService/v1.0/LangStrings/${libraryName}?language=${language}`,\n );\n\n if (response.status !== 200) {\n return null;\n }\n\n return (await response.json()) as TextstringValue;\n};\n\ninterface SelectLanguageToChangeOptions {\n textstringName: string;\n}\n\nexport const selectLanguageToChange = ({ textstringName }: SelectLanguageToChangeOptions) => {\n // Note: the page is in v4\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n void dialog.iFrame({\n url: 'https://tapp-staging.chayns-static.space/text-string-tapp/v1/iframe-edit.html',\n buttons: [],\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n input: { textstring: textstringName },\n });\n};\n\ninterface InitTextstringsOptions {\n /**\n * The language that should be used.\n */\n language: string;\n /**\n * The name of the library.\n */\n libraryName: string;\n}\n\nexport const initTextstrings = ({ libraryName, language }: InitTextstringsOptions) => {\n void loadLibrary({ libraryName, language }).then((result) => {\n if (result) {\n const prevTextstrings = window.Textstrings;\n\n window.Textstrings = {\n ...prevTextstrings,\n [libraryName]: result,\n };\n }\n });\n};\n\ninterface GetTextstringValueOptions {\n textstring: ITextstring;\n libraryName: string;\n replacements?: TextstringReplacement;\n}\n\nexport const getTextstringValue = ({\n libraryName,\n textstring,\n replacements,\n}: GetTextstringValueOptions): string => {\n const textstrings =\n typeof window !== 'undefined' ? window.Textstrings?.[libraryName] : undefined;\n\n if (!textstrings) {\n if (!replacements) {\n return textstring.fallback;\n }\n\n return Object.keys(replacements).reduce(\n (current, key) =>\n current.replace(new RegExp(key, 'g'), <string>replacements[key] || ''),\n textstring.fallback,\n );\n }\n\n const value = textstrings[textstring.name] ?? textstring.fallback;\n\n if (!replacements) {\n return value;\n }\n\n return Object.keys(replacements).reduce(\n (current, key) => current.replace(new RegExp(key, 'g'), <string>replacements[key] || ''),\n value,\n );\n};\n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MACf,OAAOR,UAAU,CAACW,QAAQ;IAC9B;IAEA,OAAOC,MAAM,CAACC,IAAI,CAACL,YAAY,CAAC,CAACM,MAAM,CACnC,CAACC,OAAO,EAAEC,GAAG,KACTD,OAAO,CAACE,OAAO,CAAC,IAAIC,MAAM,CAACF,GAAG,EAAE,GAAG,CAAC,EAAUR,YAAY,CAACQ,GAAG,CAAC,IAAI,EAAE,CAAC,EAC1EhB,UAAU,CAACW,QACf,CAAC;EACL;EAEA,MAAMQ,KAAK,GAAGV,WAAW,CAACT,UAAU,CAACoB,IAAI,CAAC,IAAIpB,UAAU,CAACW,QAAQ;EAEjE,IAAI,CAACH,YAAY,EAAE;IACf,OAAOW,KAAK;EAChB;EAEA,OAAOP,MAAM,CAACC,IAAI,CAACL,YAAY,CAAC,CAACM,MAAM,CACnC,CAACC,OAAO,EAAEC,GAAG,KAAKD,OAAO,CAACE,OAAO,CAAC,IAAIC,MAAM,CAACF,GAAG,EAAE,GAAG,CAAC,EAAUR,YAAY,CAACQ,GAAG,CAAC,IAAI,EAAE,CAAC,EACxFG,KACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { default as TextstringProvider } from './components/textstring-provider/
|
|
|
2
2
|
export { default as Textstring } from './components/textstring/Textstring';
|
|
3
3
|
export type { ITextstring, TextstringReplacement } from './components/textstring/types';
|
|
4
4
|
export { useTextstringValue } from './hooks/useTextstringValue';
|
|
5
|
-
export { getTextstringValue } from './utils/textstring';
|
|
5
|
+
export { getTextstringValue, initTextstrings } from './utils/textstring';
|
|
@@ -9,6 +9,17 @@ interface SelectLanguageToChangeOptions {
|
|
|
9
9
|
textstringName: string;
|
|
10
10
|
}
|
|
11
11
|
export declare const selectLanguageToChange: ({ textstringName }: SelectLanguageToChangeOptions) => void;
|
|
12
|
+
interface InitTextstringsOptions {
|
|
13
|
+
/**
|
|
14
|
+
* The language that should be used.
|
|
15
|
+
*/
|
|
16
|
+
language: string;
|
|
17
|
+
/**
|
|
18
|
+
* The name of the library.
|
|
19
|
+
*/
|
|
20
|
+
libraryName: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const initTextstrings: ({ libraryName, language }: InitTextstringsOptions) => void;
|
|
12
23
|
interface GetTextstringValueOptions {
|
|
13
24
|
textstring: ITextstring;
|
|
14
25
|
libraryName: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/textstring",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": [
|
|
@@ -23,8 +23,9 @@
|
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
25
|
"types": "./lib/types/index.d.ts",
|
|
26
|
+
"node": "./lib/cjs/index.js",
|
|
26
27
|
"require": "./lib/cjs/index.js",
|
|
27
|
-
"
|
|
28
|
+
"default": "./lib/esm/index.js"
|
|
28
29
|
}
|
|
29
30
|
},
|
|
30
31
|
"directories": {
|
|
@@ -51,29 +52,29 @@
|
|
|
51
52
|
"url": "https://github.com/TobitSoftware/chayns-components/issues"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@babel/cli": "^7.
|
|
55
|
-
"@babel/core": "^7.
|
|
56
|
-
"@babel/preset-env": "^7.
|
|
57
|
-
"@babel/preset-react": "^7.
|
|
58
|
-
"@babel/preset-typescript": "^7.
|
|
59
|
-
"@types/react": "^18.3.
|
|
60
|
-
"@types/react-dom": "^18.3.
|
|
61
|
-
"@types/styled-components": "^5.1.
|
|
55
|
+
"@babel/cli": "^7.28.6",
|
|
56
|
+
"@babel/core": "^7.29.0",
|
|
57
|
+
"@babel/preset-env": "^7.29.0",
|
|
58
|
+
"@babel/preset-react": "^7.28.5",
|
|
59
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
60
|
+
"@types/react": "^18.3.28",
|
|
61
|
+
"@types/react-dom": "^18.3.7",
|
|
62
|
+
"@types/styled-components": "^5.1.36",
|
|
62
63
|
"@types/uuid": "^10.0.0",
|
|
63
64
|
"babel-loader": "^9.2.1",
|
|
64
65
|
"cross-env": "^7.0.3",
|
|
65
|
-
"lerna": "^8.
|
|
66
|
+
"lerna": "^8.2.4",
|
|
66
67
|
"react": "^18.3.1",
|
|
67
68
|
"react-dom": "^18.3.1",
|
|
68
|
-
"styled-components": "^6.
|
|
69
|
-
"typescript": "^5.
|
|
69
|
+
"styled-components": "^6.3.9",
|
|
70
|
+
"typescript": "^5.9.3"
|
|
70
71
|
},
|
|
71
72
|
"dependencies": {
|
|
72
|
-
"@chayns-components/core": "^5.0.0
|
|
73
|
+
"@chayns-components/core": "^5.0.0"
|
|
73
74
|
},
|
|
74
75
|
"peerDependencies": {
|
|
75
|
-
"chayns-api": ">=2.
|
|
76
|
-
"
|
|
76
|
+
"chayns-api": ">=2.2.0",
|
|
77
|
+
"motion": ">=12.4.1",
|
|
77
78
|
"react": ">=18.0.0",
|
|
78
79
|
"react-dom": ">=18.0.0",
|
|
79
80
|
"styled-components": ">=5.3.11"
|
|
@@ -81,5 +82,5 @@
|
|
|
81
82
|
"publishConfig": {
|
|
82
83
|
"access": "public"
|
|
83
84
|
},
|
|
84
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "3d554c67b058b3b25e2666a34ee543fea2cad6e2"
|
|
85
86
|
}
|