@messagevisor/react 0.0.1 → 0.1.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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/jest.config.js +13 -0
- package/lib/MessagevisorContext.d.ts +21 -0
- package/lib/MessagevisorContext.js +39 -0
- package/lib/MessagevisorContext.js.map +1 -0
- package/lib/MessagevisorProvider.d.ts +12 -0
- package/lib/MessagevisorProvider.js +58 -0
- package/lib/MessagevisorProvider.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +23 -0
- package/lib/index.js.map +1 -0
- package/lib/useMessagevisor.d.ts +20 -0
- package/lib/useMessagevisor.js +106 -0
- package/lib/useMessagevisor.js.map +1 -0
- package/lib/useMessagevisorSnapshot.d.ts +2 -0
- package/lib/useMessagevisorSnapshot.js +77 -0
- package/lib/useMessagevisorSnapshot.js.map +1 -0
- package/lib/useReactiveMessagevisor.d.ts +31 -0
- package/lib/useReactiveMessagevisor.js +141 -0
- package/lib/useReactiveMessagevisor.js.map +1 -0
- package/lib/useRichText.d.ts +13 -0
- package/lib/useRichText.js +112 -0
- package/lib/useRichText.js.map +1 -0
- package/lib/useSdk.d.ts +2 -0
- package/lib/useSdk.js +46 -0
- package/lib/useSdk.js.map +1 -0
- package/package.json +51 -13
- package/src/MessagevisorContext.ts +28 -0
- package/src/MessagevisorProvider.spec.tsx +29 -0
- package/src/MessagevisorProvider.tsx +41 -0
- package/src/index.ts +6 -0
- package/src/testUtils.ts +72 -0
- package/src/useMessagevisor.spec.tsx +425 -0
- package/src/useMessagevisor.ts +115 -0
- package/src/useMessagevisorSnapshot.ts +65 -0
- package/src/useReactiveMessagevisor.spec.tsx +507 -0
- package/src/useReactiveMessagevisor.ts +223 -0
- package/src/useRichText.tsx +116 -0
- package/src/useSdk.spec.tsx +45 -0
- package/src/useSdk.ts +15 -0
- package/tsconfig.cjs.json +11 -0
- package/tsconfig.typecheck.json +4 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [0.1.0](https://github.com/messagevisor/messagevisor/compare/v0.0.2...v0.1.0) (2026-05-31)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @messagevisor/react
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 0.0.2 (2026-05-31)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @messagevisor/react
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fahad Heylaal (https://fahad19.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
package/jest.config.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const base = require("../../jest.config");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
...base,
|
|
5
|
+
rootDir: __dirname,
|
|
6
|
+
testEnvironment: "jsdom",
|
|
7
|
+
testRegex: undefined,
|
|
8
|
+
testMatch: ["<rootDir>/src/**/*.spec.ts", "<rootDir>/src/**/*.spec.tsx"],
|
|
9
|
+
moduleNameMapper: {
|
|
10
|
+
"^@messagevisor/sdk$": "<rootDir>/../sdk/src/index.ts",
|
|
11
|
+
"^@messagevisor/module-icu$": "<rootDir>/../module-icu/src/index.ts",
|
|
12
|
+
},
|
|
13
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { Messagevisor, MessagevisorTranslationSource } from "@messagevisor/sdk";
|
|
3
|
+
import type { MessageKey } from "@messagevisor/types";
|
|
4
|
+
export type RichTextElementHandler = (chunks: React.ReactNode[]) => React.ReactNode;
|
|
5
|
+
export interface MessagevisorProviderModule {
|
|
6
|
+
name?: string;
|
|
7
|
+
transform?: (payload: {
|
|
8
|
+
translation: React.ReactNode;
|
|
9
|
+
locale: string;
|
|
10
|
+
source: MessagevisorTranslationSource;
|
|
11
|
+
messageKey?: MessageKey;
|
|
12
|
+
}) => React.ReactNode | void;
|
|
13
|
+
}
|
|
14
|
+
export interface MessagevisorReactContextValue {
|
|
15
|
+
instance: Messagevisor;
|
|
16
|
+
defaultRichTextElements: Record<string, RichTextElementHandler>;
|
|
17
|
+
wrapRichTextChunksInFragment: boolean;
|
|
18
|
+
modules: MessagevisorProviderModule[];
|
|
19
|
+
textComponent?: React.ElementType;
|
|
20
|
+
}
|
|
21
|
+
export declare const MessagevisorContext: React.Context<MessagevisorReactContextValue>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.MessagevisorContext = void 0;
|
|
37
|
+
var React = __importStar(require("react"));
|
|
38
|
+
exports.MessagevisorContext = React.createContext(undefined);
|
|
39
|
+
//# sourceMappingURL=MessagevisorContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessagevisorContext.js","sourceRoot":"","sources":["../src/MessagevisorContext.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA+B;AAyBlB,QAAA,mBAAmB,GAAG,KAAK,CAAC,aAAa,CACpD,SAAS,CACV,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { Messagevisor } from "@messagevisor/sdk";
|
|
3
|
+
import { type MessagevisorProviderModule, type RichTextElementHandler } from "./MessagevisorContext";
|
|
4
|
+
export interface MessagevisorProviderProps {
|
|
5
|
+
instance: Messagevisor;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
defaultRichTextElements?: Record<string, RichTextElementHandler>;
|
|
8
|
+
wrapRichTextChunksInFragment?: boolean;
|
|
9
|
+
modules?: MessagevisorProviderModule[];
|
|
10
|
+
textComponent?: React.ElementType;
|
|
11
|
+
}
|
|
12
|
+
export declare function MessagevisorProvider(props: MessagevisorProviderProps): React.JSX.Element;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.MessagevisorProvider = MessagevisorProvider;
|
|
37
|
+
var React = __importStar(require("react"));
|
|
38
|
+
var MessagevisorContext_1 = require("./MessagevisorContext");
|
|
39
|
+
function MessagevisorProvider(props) {
|
|
40
|
+
var value = React.useMemo(function () {
|
|
41
|
+
var _a;
|
|
42
|
+
return ({
|
|
43
|
+
instance: props.instance,
|
|
44
|
+
defaultRichTextElements: props.defaultRichTextElements || {},
|
|
45
|
+
wrapRichTextChunksInFragment: (_a = props.wrapRichTextChunksInFragment) !== null && _a !== void 0 ? _a : true,
|
|
46
|
+
modules: props.modules || [],
|
|
47
|
+
textComponent: props.textComponent,
|
|
48
|
+
});
|
|
49
|
+
}, [
|
|
50
|
+
props.instance,
|
|
51
|
+
props.defaultRichTextElements,
|
|
52
|
+
props.wrapRichTextChunksInFragment,
|
|
53
|
+
props.modules,
|
|
54
|
+
props.textComponent,
|
|
55
|
+
]);
|
|
56
|
+
return (React.createElement(MessagevisorContext_1.MessagevisorContext.Provider, { value: value }, props.children));
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=MessagevisorProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessagevisorProvider.js","sourceRoot":"","sources":["../src/MessagevisorProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,oDAqBC;AAxCD,2CAA+B;AAI/B,6DAI+B;AAW/B,SAAgB,oBAAoB,CAAC,KAAgC;IACnE,IAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CACzB;;QAAM,OAAA,CAAC;YACL,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,uBAAuB,EAAE,KAAK,CAAC,uBAAuB,IAAI,EAAE;YAC5D,4BAA4B,EAAE,MAAA,KAAK,CAAC,4BAA4B,mCAAI,IAAI;YACxE,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,EAAE;YAC5B,aAAa,EAAE,KAAK,CAAC,aAAa;SACnC,CAAC,CAAA;KAAA,EACF;QACE,KAAK,CAAC,QAAQ;QACd,KAAK,CAAC,uBAAuB;QAC7B,KAAK,CAAC,4BAA4B;QAClC,KAAK,CAAC,OAAO;QACb,KAAK,CAAC,aAAa;KACpB,CACF,CAAC;IAEF,OAAO,CACL,oBAAC,yCAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAAG,KAAK,CAAC,QAAQ,CAAgC,CAC5F,CAAC;AACJ,CAAC"}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./MessagevisorContext"), exports);
|
|
18
|
+
__exportStar(require("./MessagevisorProvider"), exports);
|
|
19
|
+
__exportStar(require("./useMessagevisor"), exports);
|
|
20
|
+
__exportStar(require("./useMessagevisorSnapshot"), exports);
|
|
21
|
+
__exportStar(require("./useReactiveMessagevisor"), exports);
|
|
22
|
+
__exportStar(require("./useSdk"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,yDAAuC;AACvC,oDAAkC;AAClC,4DAA0C;AAC1C,4DAA0C;AAC1C,2CAAyB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { EvaluationOptions, TranslateOptions, MessagePrimitiveValue, Messagevisor } from "@messagevisor/sdk";
|
|
3
|
+
import type { MessageKey } from "@messagevisor/types";
|
|
4
|
+
import { type ReactRichMessageValues } from "./useRichText";
|
|
5
|
+
declare const BOUND_METHODS: readonly ["formatNumber", "formatNumberToParts", "formatDate", "formatDateToParts", "formatTime", "formatTimeToParts", "formatDateTimeRange", "formatRelativeTime", "formatPlural", "formatList", "formatListToParts", "formatDisplayName", "setLocale", "getLocale", "getDirection", "setContext", "getContext", "setCurrency", "getCurrency", "setTimeZone", "getTimeZone", "setDatafile", "getRevision"];
|
|
6
|
+
export declare const MESSAGEVISOR_METHODS: readonly ["t", "formatMessage", "formatNumber", "formatNumberToParts", "formatDate", "formatDateToParts", "formatTime", "formatTimeToParts", "formatDateTimeRange", "formatRelativeTime", "formatPlural", "formatList", "formatListToParts", "formatDisplayName", "setLocale", "getLocale", "getDirection", "setContext", "getContext", "setCurrency", "getCurrency", "setTimeZone", "getTimeZone", "setDatafile", "getRevision"];
|
|
7
|
+
type ReactTranslationMethod = {
|
|
8
|
+
(messageKey: MessageKey, values?: Record<string, MessagePrimitiveValue>, options?: TranslateOptions): string;
|
|
9
|
+
(messageKey: MessageKey, values: ReactRichMessageValues, options?: TranslateOptions): React.ReactNode;
|
|
10
|
+
};
|
|
11
|
+
type ReactFormatMessageMethod = {
|
|
12
|
+
(message: string, values?: Record<string, MessagePrimitiveValue>, options?: EvaluationOptions): string;
|
|
13
|
+
(message: string, values: ReactRichMessageValues, options?: EvaluationOptions): React.ReactNode;
|
|
14
|
+
};
|
|
15
|
+
export type MessagevisorApi = {
|
|
16
|
+
t: ReactTranslationMethod;
|
|
17
|
+
formatMessage: ReactFormatMessageMethod;
|
|
18
|
+
} & Pick<Messagevisor, (typeof BOUND_METHODS)[number]>;
|
|
19
|
+
export declare function useMessagevisor(): MessagevisorApi;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
36
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
37
|
+
if (ar || !(i in from)) {
|
|
38
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
39
|
+
ar[i] = from[i];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.MESSAGEVISOR_METHODS = void 0;
|
|
46
|
+
exports.useMessagevisor = useMessagevisor;
|
|
47
|
+
var React = __importStar(require("react"));
|
|
48
|
+
var useRichText_1 = require("./useRichText");
|
|
49
|
+
var useSdk_1 = require("./useSdk");
|
|
50
|
+
var BOUND_METHODS = [
|
|
51
|
+
"formatNumber",
|
|
52
|
+
"formatNumberToParts",
|
|
53
|
+
"formatDate",
|
|
54
|
+
"formatDateToParts",
|
|
55
|
+
"formatTime",
|
|
56
|
+
"formatTimeToParts",
|
|
57
|
+
"formatDateTimeRange",
|
|
58
|
+
"formatRelativeTime",
|
|
59
|
+
"formatPlural",
|
|
60
|
+
"formatList",
|
|
61
|
+
"formatListToParts",
|
|
62
|
+
"formatDisplayName",
|
|
63
|
+
"setLocale",
|
|
64
|
+
"getLocale",
|
|
65
|
+
"getDirection",
|
|
66
|
+
"setContext",
|
|
67
|
+
"getContext",
|
|
68
|
+
"setCurrency",
|
|
69
|
+
"getCurrency",
|
|
70
|
+
"setTimeZone",
|
|
71
|
+
"getTimeZone",
|
|
72
|
+
"setDatafile",
|
|
73
|
+
"getRevision",
|
|
74
|
+
];
|
|
75
|
+
exports.MESSAGEVISOR_METHODS = __spreadArray(["t", "formatMessage"], BOUND_METHODS, true);
|
|
76
|
+
function bindMethod(instance, key) {
|
|
77
|
+
return instance[key].bind(instance);
|
|
78
|
+
}
|
|
79
|
+
function useMessagevisor() {
|
|
80
|
+
var sdk = (0, useSdk_1.useSdk)();
|
|
81
|
+
var richText = (0, useRichText_1.useRichText)();
|
|
82
|
+
return React.useMemo(function () {
|
|
83
|
+
var result = {
|
|
84
|
+
t: (function (messageKey, values, options) {
|
|
85
|
+
var message = sdk.getRawTranslation(messageKey, options);
|
|
86
|
+
var translation = sdk.translate(messageKey, richText.mergeValues(values, message), options);
|
|
87
|
+
return richText.wrapResult(richText.runModules(translation, {
|
|
88
|
+
source: "translation",
|
|
89
|
+
messageKey: messageKey,
|
|
90
|
+
}));
|
|
91
|
+
}),
|
|
92
|
+
formatMessage: (function (message, values, options) {
|
|
93
|
+
var translation = sdk.formatMessage(message, richText.mergeValues(values, message), options);
|
|
94
|
+
return richText.wrapResult(richText.runModules(translation, {
|
|
95
|
+
source: "formatMessage",
|
|
96
|
+
}));
|
|
97
|
+
}),
|
|
98
|
+
};
|
|
99
|
+
for (var _i = 0, BOUND_METHODS_1 = BOUND_METHODS; _i < BOUND_METHODS_1.length; _i++) {
|
|
100
|
+
var key = BOUND_METHODS_1[_i];
|
|
101
|
+
result[key] = bindMethod(sdk, key);
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}, [sdk, richText]);
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=useMessagevisor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMessagevisor.js","sourceRoot":"","sources":["../src/useMessagevisor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,0CA0CC;AAlHD,2CAA+B;AAU/B,6CAAkG;AAClG,mCAAkC;AAElC,IAAM,aAAa,GAAG;IACpB,cAAc;IACd,qBAAqB;IACrB,YAAY;IACZ,mBAAmB;IACnB,YAAY;IACZ,mBAAmB;IACnB,qBAAqB;IACrB,oBAAoB;IACpB,cAAc;IACd,YAAY;IACZ,mBAAmB;IACnB,mBAAmB;IACnB,WAAW;IACX,WAAW;IACX,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,aAAa;IACb,aAAa;IACb,aAAa;IACb,aAAa;IACb,aAAa;CACqC,CAAC;AAExC,QAAA,oBAAoB,GAAG,eAAC,GAAG,EAAE,eAAe,GAAK,aAAa,OAAU,CAAC;AA6BtF,SAAS,UAAU,CAA+B,QAAsB,EAAE,GAAM;IAC9E,OAAQ,QAAQ,CAAC,GAAG,CAAmC,CAAC,IAAI,CAAC,QAAQ,CAAoB,CAAC;AAC5F,CAAC;AAED,SAAgB,eAAe;IAC7B,IAAM,GAAG,GAAG,IAAA,eAAM,GAAE,CAAC;IACrB,IAA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
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.useMessagevisorSnapshot = useMessagevisorSnapshot;
|
|
37
|
+
var React = __importStar(require("react"));
|
|
38
|
+
var useSdk_1 = require("./useSdk");
|
|
39
|
+
var useSyncExternalStore = React.useSyncExternalStore ||
|
|
40
|
+
function useSyncExternalStoreFallback(subscribe, getSnapshot) {
|
|
41
|
+
var _a = React.useState(getSnapshot), snapshot = _a[0], setSnapshot = _a[1];
|
|
42
|
+
React.useEffect(function () {
|
|
43
|
+
var handleChange = function () {
|
|
44
|
+
setSnapshot(getSnapshot());
|
|
45
|
+
};
|
|
46
|
+
var unsubscribe = subscribe(handleChange);
|
|
47
|
+
handleChange();
|
|
48
|
+
return unsubscribe;
|
|
49
|
+
}, [subscribe, getSnapshot]);
|
|
50
|
+
return snapshot;
|
|
51
|
+
};
|
|
52
|
+
function useMessagevisorSnapshot() {
|
|
53
|
+
var sdk = (0, useSdk_1.useSdk)();
|
|
54
|
+
var store = React.useMemo(function () {
|
|
55
|
+
var snapshot = sdk.getSnapshot();
|
|
56
|
+
var getSnapshot = function () {
|
|
57
|
+
var nextSnapshot = sdk.getSnapshot();
|
|
58
|
+
if (nextSnapshot.version === snapshot.version) {
|
|
59
|
+
return snapshot;
|
|
60
|
+
}
|
|
61
|
+
snapshot = nextSnapshot;
|
|
62
|
+
return snapshot;
|
|
63
|
+
};
|
|
64
|
+
var subscribe = function (callback) {
|
|
65
|
+
return sdk.subscribe(function () {
|
|
66
|
+
snapshot = sdk.getSnapshot();
|
|
67
|
+
callback();
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
getSnapshot: getSnapshot,
|
|
72
|
+
subscribe: subscribe,
|
|
73
|
+
};
|
|
74
|
+
}, [sdk]);
|
|
75
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=useMessagevisorSnapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMessagevisorSnapshot.js","sourceRoot":"","sources":["../src/useMessagevisorSnapshot.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,0DA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,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEV,OAAO,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { EvaluationOptions, TranslateOptions, MessagePrimitiveValue, Messagevisor } from "@messagevisor/sdk";
|
|
3
|
+
import type { Context, FormatDateTimePresetOptions, FormatNumberPresetOptions, FormatRelativeTimePresetOptions, LocaleDirection, LocaleKey, MessageKey } from "@messagevisor/types";
|
|
4
|
+
import { type ReactRichMessageValues } from "./useRichText";
|
|
5
|
+
export interface LocaleInfo {
|
|
6
|
+
locale: LocaleKey | null;
|
|
7
|
+
direction: LocaleDirection | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare function useLocale(): LocaleKey | null;
|
|
10
|
+
export declare function useDirection(): LocaleDirection | undefined;
|
|
11
|
+
export declare function useLocaleInfo(): LocaleInfo;
|
|
12
|
+
export declare function useMessagevisorContext(): Context;
|
|
13
|
+
export declare function useCurrency(): string | undefined;
|
|
14
|
+
export declare function useTimeZone(): string | undefined;
|
|
15
|
+
export declare function useTranslation(messageKey: MessageKey, values?: Record<string, MessagePrimitiveValue>, options?: TranslateOptions): string;
|
|
16
|
+
export declare function useTranslation(messageKey: MessageKey, values: ReactRichMessageValues, options?: TranslateOptions): React.ReactNode;
|
|
17
|
+
export declare function useFormatMessage(message: string, values?: Record<string, MessagePrimitiveValue>, options?: EvaluationOptions): string;
|
|
18
|
+
export declare function useFormatMessage(message: string, values: ReactRichMessageValues, options?: EvaluationOptions): React.ReactNode;
|
|
19
|
+
export declare function useFormatNumber(value: number, presetOrOptions?: string | FormatNumberPresetOptions, options?: EvaluationOptions): string;
|
|
20
|
+
export declare function useFormatNumberToParts(value: number, presetOrOptions?: string | FormatNumberPresetOptions, options?: EvaluationOptions): Intl.NumberFormatPart[];
|
|
21
|
+
export declare function useFormatDate(value: Date | number | string, presetOrOptions?: string | FormatDateTimePresetOptions, options?: EvaluationOptions): string;
|
|
22
|
+
export declare function useFormatDateToParts(value: Date | number | string, presetOrOptions?: string | FormatDateTimePresetOptions, options?: EvaluationOptions): Intl.DateTimeFormatPart[];
|
|
23
|
+
export declare function useFormatTime(value: Date | number | string, presetOrOptions?: string | FormatDateTimePresetOptions, options?: EvaluationOptions): string;
|
|
24
|
+
export declare function useFormatTimeToParts(value: Date | number | string, presetOrOptions?: string | FormatDateTimePresetOptions, options?: EvaluationOptions): Intl.DateTimeFormatPart[];
|
|
25
|
+
export declare function useFormatDateTimeRange(start: Date | number | string, end: Date | number | string, presetOrOptions?: string | FormatDateTimePresetOptions, options?: EvaluationOptions): string;
|
|
26
|
+
export declare function useFormatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, presetOrOptions?: string | FormatRelativeTimePresetOptions, options?: EvaluationOptions): string;
|
|
27
|
+
export declare function useFormatPlural(value: number, options?: Intl.PluralRulesOptions): Intl.LDMLPluralRule;
|
|
28
|
+
export declare function useFormatList(values: string[], options?: any): any;
|
|
29
|
+
export declare function useFormatListToParts(values: string[], options?: any): any;
|
|
30
|
+
export declare function useFormatDisplayName(value: string, options?: any): any;
|
|
31
|
+
export type ReactiveMessagevisorApi = Pick<Messagevisor, "translate" | "formatMessage" | "formatNumber" | "formatNumberToParts" | "formatDate" | "formatDateToParts" | "formatTime" | "formatTimeToParts" | "formatDateTimeRange" | "formatRelativeTime" | "formatPlural" | "formatList" | "formatListToParts" | "formatDisplayName">;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.useLocale = useLocale;
|
|
37
|
+
exports.useDirection = useDirection;
|
|
38
|
+
exports.useLocaleInfo = useLocaleInfo;
|
|
39
|
+
exports.useMessagevisorContext = useMessagevisorContext;
|
|
40
|
+
exports.useCurrency = useCurrency;
|
|
41
|
+
exports.useTimeZone = useTimeZone;
|
|
42
|
+
exports.useTranslation = useTranslation;
|
|
43
|
+
exports.useFormatMessage = useFormatMessage;
|
|
44
|
+
exports.useFormatNumber = useFormatNumber;
|
|
45
|
+
exports.useFormatNumberToParts = useFormatNumberToParts;
|
|
46
|
+
exports.useFormatDate = useFormatDate;
|
|
47
|
+
exports.useFormatDateToParts = useFormatDateToParts;
|
|
48
|
+
exports.useFormatTime = useFormatTime;
|
|
49
|
+
exports.useFormatTimeToParts = useFormatTimeToParts;
|
|
50
|
+
exports.useFormatDateTimeRange = useFormatDateTimeRange;
|
|
51
|
+
exports.useFormatRelativeTime = useFormatRelativeTime;
|
|
52
|
+
exports.useFormatPlural = useFormatPlural;
|
|
53
|
+
exports.useFormatList = useFormatList;
|
|
54
|
+
exports.useFormatListToParts = useFormatListToParts;
|
|
55
|
+
exports.useFormatDisplayName = useFormatDisplayName;
|
|
56
|
+
var React = __importStar(require("react"));
|
|
57
|
+
var useMessagevisorSnapshot_1 = require("./useMessagevisorSnapshot");
|
|
58
|
+
var useRichText_1 = require("./useRichText");
|
|
59
|
+
var useSdk_1 = require("./useSdk");
|
|
60
|
+
function useReactiveSdk() {
|
|
61
|
+
var sdk = (0, useSdk_1.useSdk)();
|
|
62
|
+
(0, useMessagevisorSnapshot_1.useMessagevisorSnapshot)();
|
|
63
|
+
return sdk;
|
|
64
|
+
}
|
|
65
|
+
function useLocale() {
|
|
66
|
+
return (0, useMessagevisorSnapshot_1.useMessagevisorSnapshot)().locale;
|
|
67
|
+
}
|
|
68
|
+
function useDirection() {
|
|
69
|
+
return (0, useMessagevisorSnapshot_1.useMessagevisorSnapshot)().direction;
|
|
70
|
+
}
|
|
71
|
+
function useLocaleInfo() {
|
|
72
|
+
var snapshot = (0, useMessagevisorSnapshot_1.useMessagevisorSnapshot)();
|
|
73
|
+
return React.useMemo(function () { return ({
|
|
74
|
+
locale: snapshot.locale,
|
|
75
|
+
direction: snapshot.direction,
|
|
76
|
+
}); }, [snapshot.locale, snapshot.direction]);
|
|
77
|
+
}
|
|
78
|
+
function useMessagevisorContext() {
|
|
79
|
+
return (0, useMessagevisorSnapshot_1.useMessagevisorSnapshot)().context;
|
|
80
|
+
}
|
|
81
|
+
function useCurrency() {
|
|
82
|
+
return (0, useMessagevisorSnapshot_1.useMessagevisorSnapshot)().currency;
|
|
83
|
+
}
|
|
84
|
+
function useTimeZone() {
|
|
85
|
+
return (0, useMessagevisorSnapshot_1.useMessagevisorSnapshot)().timeZone;
|
|
86
|
+
}
|
|
87
|
+
function useTranslation(messageKey, values, options) {
|
|
88
|
+
var sdk = useReactiveSdk();
|
|
89
|
+
var richText = (0, useRichText_1.useRichText)();
|
|
90
|
+
var message = sdk.getRawTranslation(messageKey, options);
|
|
91
|
+
var translation = sdk.translate(messageKey, richText.mergeValues(values, message), options);
|
|
92
|
+
return richText.wrapResult(richText.runModules(translation, {
|
|
93
|
+
source: "translation",
|
|
94
|
+
messageKey: messageKey,
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
function useFormatMessage(message, values, options) {
|
|
98
|
+
var sdk = useReactiveSdk();
|
|
99
|
+
var richText = (0, useRichText_1.useRichText)();
|
|
100
|
+
var translation = sdk.formatMessage(message, richText.mergeValues(values, message), options);
|
|
101
|
+
return richText.wrapResult(richText.runModules(translation, {
|
|
102
|
+
source: "formatMessage",
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
function useFormatNumber(value, presetOrOptions, options) {
|
|
106
|
+
return useReactiveSdk().formatNumber(value, presetOrOptions, options);
|
|
107
|
+
}
|
|
108
|
+
function useFormatNumberToParts(value, presetOrOptions, options) {
|
|
109
|
+
return useReactiveSdk().formatNumberToParts(value, presetOrOptions, options);
|
|
110
|
+
}
|
|
111
|
+
function useFormatDate(value, presetOrOptions, options) {
|
|
112
|
+
return useReactiveSdk().formatDate(value, presetOrOptions, options);
|
|
113
|
+
}
|
|
114
|
+
function useFormatDateToParts(value, presetOrOptions, options) {
|
|
115
|
+
return useReactiveSdk().formatDateToParts(value, presetOrOptions, options);
|
|
116
|
+
}
|
|
117
|
+
function useFormatTime(value, presetOrOptions, options) {
|
|
118
|
+
return useReactiveSdk().formatTime(value, presetOrOptions, options);
|
|
119
|
+
}
|
|
120
|
+
function useFormatTimeToParts(value, presetOrOptions, options) {
|
|
121
|
+
return useReactiveSdk().formatTimeToParts(value, presetOrOptions, options);
|
|
122
|
+
}
|
|
123
|
+
function useFormatDateTimeRange(start, end, presetOrOptions, options) {
|
|
124
|
+
return useReactiveSdk().formatDateTimeRange(start, end, presetOrOptions, options);
|
|
125
|
+
}
|
|
126
|
+
function useFormatRelativeTime(value, unit, presetOrOptions, options) {
|
|
127
|
+
return useReactiveSdk().formatRelativeTime(value, unit, presetOrOptions, options);
|
|
128
|
+
}
|
|
129
|
+
function useFormatPlural(value, options) {
|
|
130
|
+
return useReactiveSdk().formatPlural(value, options);
|
|
131
|
+
}
|
|
132
|
+
function useFormatList(values, options) {
|
|
133
|
+
return useReactiveSdk().formatList(values, options);
|
|
134
|
+
}
|
|
135
|
+
function useFormatListToParts(values, options) {
|
|
136
|
+
return useReactiveSdk().formatListToParts(values, options);
|
|
137
|
+
}
|
|
138
|
+
function useFormatDisplayName(value, options) {
|
|
139
|
+
return useReactiveSdk().formatDisplayName(value, options);
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=useReactiveMessagevisor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReactiveMessagevisor.js","sourceRoot":"","sources":["../src/useReactiveMessagevisor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,8BAEC;AAED,oCAEC;AAED,sCAUC;AAED,wDAEC;AAED,kCAEC;AAED,kCAEC;AAYD,wCAoBC;AAYD,4CAcC;AAED,0CAMC;AAED,wDAMC;AAED,sCAMC;AAED,oDAMC;AAED,sCAMC;AAED,oDAMC;AAED,wDAOC;AAED,sDAOC;AAED,0CAEC;AAED,sCAEC;AAED,oDAEC;AAED,oDAEC;AA5MD,2CAA+B;AAkB/B,qEAAoE;AACpE,6CAAkG;AAClG,mCAAkC;AAOlC,SAAS,cAAc;IACrB,IAAM,GAAG,GAA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