react-intlayer 1.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/LICENSE +21 -0
- package/dist/cjs/ContentEditor/ContentEditor.cjs +113 -0
- package/dist/cjs/ContentEditor/ContentEditor.cjs.map +1 -0
- package/dist/cjs/ContentEditor/ContentEditor.d.ts +8 -0
- package/dist/cjs/ContentEditor/contentRender.cjs +45 -0
- package/dist/cjs/ContentEditor/contentRender.cjs.map +1 -0
- package/dist/cjs/ContentEditor/contentRender.d.ts +3 -0
- package/dist/cjs/ContentEditor/index.cjs +41 -0
- package/dist/cjs/ContentEditor/index.cjs.map +1 -0
- package/dist/cjs/ContentEditor/index.d.ts +3 -0
- package/dist/cjs/LocaleContextProvider.cjs +49 -0
- package/dist/cjs/LocaleContextProvider.cjs.map +1 -0
- package/dist/cjs/LocaleContextProvider.d.ts +10 -0
- package/dist/cjs/client/LocaleClientContextProvider.cjs +54 -0
- package/dist/cjs/client/LocaleClientContextProvider.cjs.map +1 -0
- package/dist/cjs/client/LocaleClientContextProvider.d.ts +20 -0
- package/dist/cjs/client/index.cjs +56 -0
- package/dist/cjs/client/index.cjs.map +1 -0
- package/dist/cjs/client/index.d.ts +19 -0
- package/dist/cjs/client/useContent.cjs +44 -0
- package/dist/cjs/client/useContent.cjs.map +1 -0
- package/dist/cjs/client/useContent.d.ts +12 -0
- package/dist/cjs/client/useIntlayer.cjs +44 -0
- package/dist/cjs/client/useIntlayer.cjs.map +1 -0
- package/dist/cjs/client/useIntlayer.d.ts +7 -0
- package/dist/cjs/client/useLocale.cjs +55 -0
- package/dist/cjs/client/useLocale.cjs.map +1 -0
- package/dist/cjs/client/useLocale.d.ts +10 -0
- package/dist/cjs/client/useLocaleCookie.cjs +70 -0
- package/dist/cjs/client/useLocaleCookie.cjs.map +1 -0
- package/dist/cjs/client/useLocaleCookie.d.ts +10 -0
- package/dist/cjs/client/useTraduction.cjs +42 -0
- package/dist/cjs/client/useTraduction.cjs.map +1 -0
- package/dist/cjs/client/useTraduction.d.ts +7 -0
- package/dist/cjs/getEnumeration.cjs +45 -0
- package/dist/cjs/getEnumeration.cjs.map +1 -0
- package/dist/cjs/getEnumeration.d.ts +8 -0
- package/dist/cjs/getTranslation.cjs +47 -0
- package/dist/cjs/getTranslation.cjs.map +1 -0
- package/dist/cjs/getTranslation.d.ts +9 -0
- package/dist/cjs/index.cjs +53 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +20 -0
- package/dist/cjs/processDictionary/contentDictionary.d.cjs +21 -0
- package/dist/cjs/processDictionary/contentDictionary.d.cjs.map +1 -0
- package/dist/cjs/processDictionary/contentDictionary.d.d.ts +32 -0
- package/dist/cjs/processDictionary/index.cjs +82 -0
- package/dist/cjs/processDictionary/index.cjs.map +1 -0
- package/dist/cjs/processDictionary/index.d.ts +22 -0
- package/dist/cjs/server/LocaleServerContextProvider.cjs +49 -0
- package/dist/cjs/server/LocaleServerContextProvider.cjs.map +1 -0
- package/dist/cjs/server/LocaleServerContextProvider.d.ts +34 -0
- package/dist/cjs/server/getLocaleTranslation.cjs +50 -0
- package/dist/cjs/server/getLocaleTranslation.cjs.map +1 -0
- package/dist/cjs/server/getLocaleTranslation.d.ts +11 -0
- package/dist/cjs/server/index.cjs +49 -0
- package/dist/cjs/server/index.cjs.map +1 -0
- package/dist/cjs/server/index.d.ts +13 -0
- package/dist/cjs/server/serverContext.cjs +81 -0
- package/dist/cjs/server/serverContext.cjs.map +1 -0
- package/dist/cjs/server/serverContext.d.ts +43 -0
- package/dist/cjs/server/useIntlayer.cjs +44 -0
- package/dist/cjs/server/useIntlayer.cjs.map +1 -0
- package/dist/cjs/server/useIntlayer.d.ts +7 -0
- package/dist/cjs/server/useTraduction.cjs +42 -0
- package/dist/cjs/server/useTraduction.cjs.map +1 -0
- package/dist/cjs/server/useTraduction.d.ts +7 -0
- package/dist/cjs/useIntlayerBase.cjs +56 -0
- package/dist/cjs/useIntlayerBase.cjs.map +1 -0
- package/dist/cjs/useIntlayerBase.d.ts +23 -0
- package/dist/esm/ContentEditor/ContentEditor.d.mts +8 -0
- package/dist/esm/ContentEditor/ContentEditor.mjs +82 -0
- package/dist/esm/ContentEditor/ContentEditor.mjs.map +1 -0
- package/dist/esm/ContentEditor/contentRender.d.mts +3 -0
- package/dist/esm/ContentEditor/contentRender.mjs +11 -0
- package/dist/esm/ContentEditor/contentRender.mjs.map +1 -0
- package/dist/esm/ContentEditor/index.d.mts +3 -0
- package/dist/esm/ContentEditor/index.mjs +3 -0
- package/dist/esm/ContentEditor/index.mjs.map +1 -0
- package/dist/esm/LocaleContextProvider.d.mts +10 -0
- package/dist/esm/LocaleContextProvider.mjs +15 -0
- package/dist/esm/LocaleContextProvider.mjs.map +1 -0
- package/dist/esm/client/LocaleClientContextProvider.d.mts +20 -0
- package/dist/esm/client/LocaleClientContextProvider.mjs +16 -0
- package/dist/esm/client/LocaleClientContextProvider.mjs.map +1 -0
- package/dist/esm/client/index.d.mts +19 -0
- package/dist/esm/client/index.mjs +25 -0
- package/dist/esm/client/index.mjs.map +1 -0
- package/dist/esm/client/useContent.d.mts +12 -0
- package/dist/esm/client/useContent.mjs +13 -0
- package/dist/esm/client/useContent.mjs.map +1 -0
- package/dist/esm/client/useIntlayer.d.mts +7 -0
- package/dist/esm/client/useIntlayer.mjs +11 -0
- package/dist/esm/client/useIntlayer.mjs.map +1 -0
- package/dist/esm/client/useLocale.d.mts +10 -0
- package/dist/esm/client/useLocale.mjs +21 -0
- package/dist/esm/client/useLocale.mjs.map +1 -0
- package/dist/esm/client/useLocaleCookie.d.mts +10 -0
- package/dist/esm/client/useLocaleCookie.mjs +20 -0
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -0
- package/dist/esm/client/useTraduction.d.mts +7 -0
- package/dist/esm/client/useTraduction.mjs +9 -0
- package/dist/esm/client/useTraduction.mjs.map +1 -0
- package/dist/esm/getEnumeration.d.mts +8 -0
- package/dist/esm/getEnumeration.mjs +11 -0
- package/dist/esm/getEnumeration.mjs.map +1 -0
- package/dist/esm/getTranslation.d.mts +9 -0
- package/dist/esm/getTranslation.mjs +16 -0
- package/dist/esm/getTranslation.mjs.map +1 -0
- package/dist/esm/index.d.mts +20 -0
- package/dist/esm/index.mjs +25 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/processDictionary/contentDictionary.d.d.mts +32 -0
- package/dist/esm/processDictionary/contentDictionary.d.mjs +1 -0
- package/dist/esm/processDictionary/contentDictionary.d.mjs.map +1 -0
- package/dist/esm/processDictionary/index.d.mts +22 -0
- package/dist/esm/processDictionary/index.mjs +43 -0
- package/dist/esm/processDictionary/index.mjs.map +1 -0
- package/dist/esm/server/LocaleServerContextProvider.d.mts +34 -0
- package/dist/esm/server/LocaleServerContextProvider.mjs +14 -0
- package/dist/esm/server/LocaleServerContextProvider.mjs.map +1 -0
- package/dist/esm/server/getLocaleTranslation.d.mts +11 -0
- package/dist/esm/server/getLocaleTranslation.mjs +17 -0
- package/dist/esm/server/getLocaleTranslation.mjs.map +1 -0
- package/dist/esm/server/index.d.mts +13 -0
- package/dist/esm/server/index.mjs +17 -0
- package/dist/esm/server/index.mjs.map +1 -0
- package/dist/esm/server/serverContext.d.mts +43 -0
- package/dist/esm/server/serverContext.mjs +33 -0
- package/dist/esm/server/serverContext.mjs.map +1 -0
- package/dist/esm/server/useIntlayer.d.mts +7 -0
- package/dist/esm/server/useIntlayer.mjs +9 -0
- package/dist/esm/server/useIntlayer.mjs.map +1 -0
- package/dist/esm/server/useTraduction.d.mts +7 -0
- package/dist/esm/server/useTraduction.mjs +9 -0
- package/dist/esm/server/useTraduction.mjs.map +1 -0
- package/dist/esm/useIntlayerBase.d.mts +23 -0
- package/dist/esm/useIntlayerBase.mjs +8 -0
- package/dist/esm/useIntlayerBase.mjs.map +1 -0
- package/package.json +95 -0
- package/src/ContentEditor/ContentEditor.tsx +116 -0
- package/src/ContentEditor/contentRender.tsx +11 -0
- package/src/ContentEditor/index.tsx +2 -0
- package/src/LocaleContextProvider.tsx +26 -0
- package/src/client/LocaleClientContextProvider.tsx +35 -0
- package/src/client/index.ts +14 -0
- package/src/client/useContent.ts +17 -0
- package/src/client/useIntlayer.ts +20 -0
- package/src/client/useLocale.ts +19 -0
- package/src/client/useLocaleCookie.ts +27 -0
- package/src/client/useTraduction.ts +12 -0
- package/src/getEnumeration.ts +18 -0
- package/src/getTranslation.ts +24 -0
- package/src/index.ts +14 -0
- package/src/processDictionary/contentDictionary.d.ts +27 -0
- package/src/processDictionary/index.ts +97 -0
- package/src/server/LocaleServerContextProvider.tsx +24 -0
- package/src/server/getLocaleTranslation.ts +19 -0
- package/src/server/index.ts +8 -0
- package/src/server/serverContext.ts +85 -0
- package/src/server/useIntlayer.ts +17 -0
- package/src/server/useTraduction.ts +13 -0
- package/src/useIntlayerBase.ts +32 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as react from "react";
|
|
2
|
+
import { PropsWithChildren, FC } from "react";
|
|
3
|
+
import { Locales } from "@intlayer/config/client";
|
|
4
|
+
|
|
5
|
+
declare const LocaleServerContext: {
|
|
6
|
+
Provider: ({
|
|
7
|
+
children,
|
|
8
|
+
value,
|
|
9
|
+
}: {
|
|
10
|
+
children: react.ReactNode;
|
|
11
|
+
value: Locales;
|
|
12
|
+
}) => react.ReactNode;
|
|
13
|
+
Consumer: ({
|
|
14
|
+
children,
|
|
15
|
+
}: {
|
|
16
|
+
children: (context: Locales | undefined) => react.ReactNode;
|
|
17
|
+
}) => react.ReactNode;
|
|
18
|
+
_storage: () => {
|
|
19
|
+
value: Locales | undefined;
|
|
20
|
+
};
|
|
21
|
+
_defaultValue: Locales | undefined;
|
|
22
|
+
};
|
|
23
|
+
declare const locale: Locales | undefined;
|
|
24
|
+
type LocaleServerContextProviderProps = PropsWithChildren & {
|
|
25
|
+
locale: Locales;
|
|
26
|
+
};
|
|
27
|
+
declare const LocaleServerContextProvider: FC<LocaleServerContextProviderProps>;
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
LocaleServerContext,
|
|
31
|
+
LocaleServerContextProvider,
|
|
32
|
+
type LocaleServerContextProviderProps,
|
|
33
|
+
locale,
|
|
34
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var getLocaleTranslation_exports = {};
|
|
24
|
+
__export(getLocaleTranslation_exports, {
|
|
25
|
+
getLocaleTranslation: () => getLocaleTranslation,
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(getLocaleTranslation_exports);
|
|
28
|
+
var import_client = require("@intlayer/config/client");
|
|
29
|
+
var import_core = require("@intlayer/core");
|
|
30
|
+
var import_LocaleServerContextProvider = require("./LocaleServerContextProvider.cjs");
|
|
31
|
+
var import_serverContext = require("./serverContext.cjs");
|
|
32
|
+
const getLocaleTranslation = (languageContent) => {
|
|
33
|
+
const locale = (0, import_serverContext.getServerContext)(
|
|
34
|
+
import_LocaleServerContextProvider.LocaleServerContext
|
|
35
|
+
);
|
|
36
|
+
const content = (0, import_core.getTranslationContent)(
|
|
37
|
+
languageContent,
|
|
38
|
+
locale ?? import_client.intlayerIntlConfiguration.defaultLocale
|
|
39
|
+
);
|
|
40
|
+
return {
|
|
41
|
+
locale,
|
|
42
|
+
content,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 &&
|
|
47
|
+
(module.exports = {
|
|
48
|
+
getLocaleTranslation,
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=getLocaleTranslation.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/getLocaleTranslation.ts"],"sourcesContent":["import { intlayerIntlConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { LocaleServerContext } from './LocaleServerContextProvider';\nimport { getServerContext } from './serverContext';\n\nexport const getLocaleTranslation = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const locale = getServerContext(LocaleServerContext);\n const content = getTranslationContent<Content>(\n languageContent,\n locale ?? intlayerIntlConfiguration.defaultLocale\n );\n\n return {\n locale,\n content,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAC1C,kBAA4D;AAC5D,yCAAoC;AACpC,2BAAiC;AAE1B,MAAM,uBAAuB,CAClC,oBACG;AACH,QAAM,aAAS,uCAAiB,sDAAmB;AACnD,QAAM,cAAU;AAAA,IACd;AAAA,IACA,UAAU,wCAA0B;AAAA,EACtC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as _intlayer_config_client from "@intlayer/config/client";
|
|
2
|
+
import { LanguageContent } from "@intlayer/core";
|
|
3
|
+
|
|
4
|
+
declare const getLocaleTranslation: <Content>(
|
|
5
|
+
languageContent: LanguageContent<Content>
|
|
6
|
+
) => {
|
|
7
|
+
locale: _intlayer_config_client.Locales | undefined;
|
|
8
|
+
content: Content;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { getLocaleTranslation };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var server_exports = {};
|
|
24
|
+
__export(server_exports, {
|
|
25
|
+
LocaleServerContext: () =>
|
|
26
|
+
import_LocaleServerContextProvider.LocaleServerContext,
|
|
27
|
+
LocaleServerContextProvider: () =>
|
|
28
|
+
import_LocaleServerContextProvider.LocaleServerContextProvider,
|
|
29
|
+
getLocaleContent: () => import_getLocaleTranslation.getLocaleTranslation,
|
|
30
|
+
locale: () => import_LocaleServerContextProvider.locale,
|
|
31
|
+
useIntlayer: () => import_useIntlayer.useIntlayer,
|
|
32
|
+
useTraduction: () => import_useTraduction.useTraduction,
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(server_exports);
|
|
35
|
+
var import_getLocaleTranslation = require("./getLocaleTranslation.cjs");
|
|
36
|
+
var import_useTraduction = require("./useTraduction.cjs");
|
|
37
|
+
var import_LocaleServerContextProvider = require("./LocaleServerContextProvider.cjs");
|
|
38
|
+
var import_useIntlayer = require("./useIntlayer.cjs");
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 &&
|
|
41
|
+
(module.exports = {
|
|
42
|
+
LocaleServerContext,
|
|
43
|
+
LocaleServerContextProvider,
|
|
44
|
+
getLocaleContent,
|
|
45
|
+
locale,
|
|
46
|
+
useIntlayer,
|
|
47
|
+
useTraduction,
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation';\nexport { useTraduction } from './useTraduction';\nexport {\n LocaleServerContext,\n locale,\n LocaleServerContextProvider,\n} from './LocaleServerContextProvider';\nexport { useIntlayer } from './useIntlayer';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAyD;AACzD,2BAA8B;AAC9B,yCAIO;AACP,yBAA4B;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { getLocaleTranslation as getLocaleContent } from "./getLocaleTranslation.js";
|
|
2
|
+
export { useTraduction } from "./useTraduction.js";
|
|
3
|
+
export {
|
|
4
|
+
LocaleServerContext,
|
|
5
|
+
LocaleServerContextProvider,
|
|
6
|
+
locale,
|
|
7
|
+
} from "./LocaleServerContextProvider.js";
|
|
8
|
+
export { useIntlayer } from "./useIntlayer.js";
|
|
9
|
+
import "@intlayer/config/client";
|
|
10
|
+
import "@intlayer/core";
|
|
11
|
+
import "react";
|
|
12
|
+
import "../useIntlayerBase.js";
|
|
13
|
+
import "intlayer";
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (
|
|
24
|
+
(target = mod != null ? __create(__getProtoOf(mod)) : {}),
|
|
25
|
+
__copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule
|
|
31
|
+
? __defProp(target, "default", { value: mod, enumerable: true })
|
|
32
|
+
: target,
|
|
33
|
+
mod
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
var __toCommonJS = (mod) =>
|
|
37
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var serverContext_exports = {};
|
|
39
|
+
__export(serverContext_exports, {
|
|
40
|
+
createServerContext: () => createServerContext,
|
|
41
|
+
getServerContext: () => getServerContext,
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(serverContext_exports);
|
|
44
|
+
var import_react = __toESM(require("react"));
|
|
45
|
+
const cacheFallback = () => () => ({ value: void 0 });
|
|
46
|
+
const createServerContext = (defaultValue) => {
|
|
47
|
+
throwInClient();
|
|
48
|
+
const cache = import_react.default.cache ?? cacheFallback;
|
|
49
|
+
const getCache = cache(() => ({
|
|
50
|
+
value: void 0,
|
|
51
|
+
}));
|
|
52
|
+
return {
|
|
53
|
+
Provider: ({ children, value }) => {
|
|
54
|
+
getCache().value = value;
|
|
55
|
+
return children;
|
|
56
|
+
},
|
|
57
|
+
Consumer: ({ children }) => {
|
|
58
|
+
const store = getCache();
|
|
59
|
+
return children(store ? store.value : defaultValue);
|
|
60
|
+
},
|
|
61
|
+
_storage: getCache,
|
|
62
|
+
_defaultValue: defaultValue,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const getServerContext = ({ _storage, _defaultValue }) => {
|
|
66
|
+
const store = _storage();
|
|
67
|
+
if (!store) return _defaultValue;
|
|
68
|
+
return store.value;
|
|
69
|
+
};
|
|
70
|
+
const throwInClient = () => {
|
|
71
|
+
if (typeof window !== "undefined") {
|
|
72
|
+
throw new Error(`createServerContext only works in Server Components`);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 &&
|
|
77
|
+
(module.exports = {
|
|
78
|
+
createServerContext,
|
|
79
|
+
getServerContext,
|
|
80
|
+
});
|
|
81
|
+
//# sourceMappingURL=serverContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/serverContext.ts"],"sourcesContent":["/**\n * Creates a new datastore for a given server context.\n * Attempts to closely mimic the `createContext` API.\n *\n * @example\n * const LocaleServerContext = createServerContext<string | null>(null);\n *\n * <LocaleServerContext.Provider value={locale}>\n * {children}\n * </LocaleServerContext.Provider>\n */\n\nimport react from 'react';\n\ntype CacheType<T> = () => { value: T | undefined };\n\nconst cacheFallback = () => () => ({ value: undefined });\n\nexport const createServerContext = <T>(defaultValue?: T): ServerContext<T> => {\n throwInClient();\n\n const cache = react.cache<CacheType<T>> ?? cacheFallback;\n\n const getCache = cache(() => ({\n value: undefined,\n }));\n\n return {\n Provider: ({ children, value }) => {\n getCache().value = value;\n return children;\n },\n Consumer: ({ children }) => {\n const store = getCache();\n return children(store ? store.value : defaultValue);\n },\n _storage: getCache,\n _defaultValue: defaultValue,\n };\n};\n\n/**\n * Fetches a value present in a given server context.\n * Attempts to closely mimic the `useContext` API.\n *\n * @example\n * getServerContext(LocaleServerContext);\n */\nexport const getServerContext = <T>({\n _storage,\n _defaultValue,\n}: ServerContext<T>) => {\n // throwInClient();\n const store = _storage();\n if (!store) return _defaultValue;\n return store.value;\n};\n\ntype ServerContext<T> = {\n Provider: ({\n children,\n value,\n }: {\n children: React.ReactNode;\n value: T;\n }) => React.ReactNode;\n Consumer: ({\n children,\n }: {\n children: (context: T | undefined) => React.ReactNode;\n }) => React.ReactNode;\n _storage: () => { value: T | undefined };\n _defaultValue: T | undefined;\n};\n\n/**\n * Throws if called within a client component environment.\n * Useful to help prevent mistakes.\n */\nconst throwInClient = (): void | never => {\n // If window.document is defined we're in a client component\n if (typeof window !== 'undefined') {\n throw new Error(`createServerContext only works in Server Components`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,mBAAkB;AAIlB,MAAM,gBAAgB,MAAM,OAAO,EAAE,OAAO,OAAU;AAE/C,MAAM,sBAAsB,CAAI,iBAAuC;AAC5E,gBAAc;AAEd,QAAM,QAAQ,aAAAA,QAAM,SAAuB;AAE3C,QAAM,WAAW,MAAM,OAAO;AAAA,IAC5B,OAAO;AAAA,EACT,EAAE;AAEF,SAAO;AAAA,IACL,UAAU,CAAC,EAAE,UAAU,MAAM,MAAM;AACjC,eAAS,EAAE,QAAQ;AACnB,aAAO;AAAA,IACT;AAAA,IACA,UAAU,CAAC,EAAE,SAAS,MAAM;AAC1B,YAAM,QAAQ,SAAS;AACvB,aAAO,SAAS,QAAQ,MAAM,QAAQ,YAAY;AAAA,IACpD;AAAA,IACA,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AACF;AASO,MAAM,mBAAmB,CAAI;AAAA,EAClC;AAAA,EACA;AACF,MAAwB;AAEtB,QAAM,QAAQ,SAAS;AACvB,MAAI,CAAC;AAAO,WAAO;AACnB,SAAO,MAAM;AACf;AAuBA,MAAM,gBAAgB,MAAoB;AAExC,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACF;","names":["react"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new datastore for a given server context.
|
|
3
|
+
* Attempts to closely mimic the `createContext` API.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const LocaleServerContext = createServerContext<string | null>(null);
|
|
7
|
+
*
|
|
8
|
+
* <LocaleServerContext.Provider value={locale}>
|
|
9
|
+
* {children}
|
|
10
|
+
* </LocaleServerContext.Provider>
|
|
11
|
+
*/
|
|
12
|
+
declare const createServerContext: <T>(defaultValue?: T) => ServerContext<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Fetches a value present in a given server context.
|
|
15
|
+
* Attempts to closely mimic the `useContext` API.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* getServerContext(LocaleServerContext);
|
|
19
|
+
*/
|
|
20
|
+
declare const getServerContext: <T>({
|
|
21
|
+
_storage,
|
|
22
|
+
_defaultValue,
|
|
23
|
+
}: ServerContext<T>) => T | undefined;
|
|
24
|
+
type ServerContext<T> = {
|
|
25
|
+
Provider: ({
|
|
26
|
+
children,
|
|
27
|
+
value,
|
|
28
|
+
}: {
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
value: T;
|
|
31
|
+
}) => React.ReactNode;
|
|
32
|
+
Consumer: ({
|
|
33
|
+
children,
|
|
34
|
+
}: {
|
|
35
|
+
children: (context: T | undefined) => React.ReactNode;
|
|
36
|
+
}) => React.ReactNode;
|
|
37
|
+
_storage: () => {
|
|
38
|
+
value: T | undefined;
|
|
39
|
+
};
|
|
40
|
+
_defaultValue: T | undefined;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { createServerContext, getServerContext };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var useIntlayer_exports = {};
|
|
24
|
+
__export(useIntlayer_exports, {
|
|
25
|
+
useIntlayer: () => useIntlayer,
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(useIntlayer_exports);
|
|
28
|
+
var import_useIntlayerBase = require("../useIntlayerBase.cjs");
|
|
29
|
+
var import_LocaleServerContextProvider = require("./LocaleServerContextProvider.cjs");
|
|
30
|
+
var import_serverContext = require("./serverContext.cjs");
|
|
31
|
+
const useIntlayer = (id, locale) => {
|
|
32
|
+
const localeTarget =
|
|
33
|
+
locale ??
|
|
34
|
+
(0, import_serverContext.getServerContext)(
|
|
35
|
+
import_LocaleServerContextProvider.LocaleServerContext
|
|
36
|
+
);
|
|
37
|
+
return (0, import_useIntlayerBase.useIntlayerBase)(id, localeTarget);
|
|
38
|
+
};
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 &&
|
|
41
|
+
(module.exports = {
|
|
42
|
+
useIntlayer,
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=useIntlayer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport {\n type DictionaryKeys,\n useIntlayerBase,\n type UseIntlayer,\n} from '../useIntlayerBase';\nimport { LocaleServerContext } from './LocaleServerContextProvider';\nimport { getServerContext } from './serverContext';\n\nexport const useIntlayer: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const localeTarget = locale ?? getServerContext<Locales>(LocaleServerContext);\n\n return useIntlayerBase(id, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,6BAIO;AACP,yCAAoC;AACpC,2BAAiC;AAE1B,MAAM,cAA2B,CACtC,IACA,WACG;AACH,QAAM,eAAe,cAAU,uCAA0B,sDAAmB;AAE5E,aAAO,wCAAgB,IAAI,YAAY;AACzC;","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var useTraduction_exports = {};
|
|
24
|
+
__export(useTraduction_exports, {
|
|
25
|
+
useTraduction: () => useTraduction,
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(useTraduction_exports);
|
|
28
|
+
var import_getTranslation = require("../getTranslation.cjs");
|
|
29
|
+
var import_LocaleServerContextProvider = require("./LocaleServerContextProvider.cjs");
|
|
30
|
+
var import_serverContext = require("./serverContext.cjs");
|
|
31
|
+
const useTraduction = (languageContent) => {
|
|
32
|
+
const locale = (0, import_serverContext.getServerContext)(
|
|
33
|
+
import_LocaleServerContextProvider.LocaleServerContext
|
|
34
|
+
);
|
|
35
|
+
return (0, import_getTranslation.getTranslation)(languageContent, locale);
|
|
36
|
+
};
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 &&
|
|
39
|
+
(module.exports = {
|
|
40
|
+
useTraduction,
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=useTraduction.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/useTraduction.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { LanguageContent } from '@intlayer/core';\nimport { getTranslation } from '../getTranslation';\nimport { LocaleServerContext } from './LocaleServerContextProvider';\nimport { getServerContext } from './serverContext';\n\nexport const useTraduction = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const locale = getServerContext<Locales>(LocaleServerContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,4BAA+B;AAC/B,yCAAoC;AACpC,2BAAiC;AAE1B,MAAM,gBAAgB,CAC3B,oBACG;AACH,QAAM,aAAS,uCAA0B,sDAAmB;AAE5D,aAAO,sCAAe,iBAAiB,MAAM;AAC/C;","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (
|
|
24
|
+
(target = mod != null ? __create(__getProtoOf(mod)) : {}),
|
|
25
|
+
__copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule
|
|
31
|
+
? __defProp(target, "default", { value: mod, enumerable: true })
|
|
32
|
+
: target,
|
|
33
|
+
mod
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
var __toCommonJS = (mod) =>
|
|
37
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var useIntlayerBase_exports = {};
|
|
39
|
+
__export(useIntlayerBase_exports, {
|
|
40
|
+
useIntlayerBase: () => useIntlayerBase,
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(useIntlayerBase_exports);
|
|
43
|
+
var import_dictionaries_entry = __toESM(
|
|
44
|
+
require("@intlayer/dictionaries-entry")
|
|
45
|
+
);
|
|
46
|
+
var import_processDictionary = require("./processDictionary/index.cjs");
|
|
47
|
+
const useIntlayerBase = (id, locale) => {
|
|
48
|
+
const dictionary = import_dictionaries_entry.default[id];
|
|
49
|
+
return (0, import_processDictionary.processDictionary)(dictionary, locale);
|
|
50
|
+
};
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 &&
|
|
53
|
+
(module.exports = {
|
|
54
|
+
useIntlayerBase,
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=useIntlayerBase.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useIntlayerBase.ts"],"sourcesContent":["/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport type { Locales } from '@intlayer/config/client';\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { Content } from './processDictionary/contentDictionary';\nimport { processDictionary } from './processDictionary/index';\n\nexport type StringFallback<T> = T extends never ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\nexport type UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => IntlayerDictionaryTypesConnector[T];\n\nexport const useIntlayerBase: UseIntlayer = <T extends DictionaryKeys>(\n id: T,\n locale?: Locales\n) => {\n const dictionary: Content = dictionaries[id];\n\n return processDictionary(\n dictionary,\n locale\n ) as IntlayerDictionaryTypesConnector[T];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,gCAAyB;AAGzB,+BAAkC;AAY3B,MAAM,kBAA+B,CAC1C,IACA,WACG;AACH,QAAM,aAAsB,0BAAAA,QAAa,EAAE;AAE3C,aAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["dictionaries"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Locales } from "@intlayer/config/client";
|
|
2
|
+
import { IntlayerDictionaryTypesConnector } from "intlayer";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.
|
|
6
|
+
* Using an external package allow to alias it in the bundle configuration (such as webpack).
|
|
7
|
+
* The alias allow hot reload the app (such as nextjs) on any dictionary change.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
type StringFallback<T> = T extends never ? string : T;
|
|
11
|
+
type DictionaryKeys = StringFallback<keyof IntlayerDictionaryTypesConnector>;
|
|
12
|
+
type UseIntlayer = <T extends DictionaryKeys>(
|
|
13
|
+
id: T,
|
|
14
|
+
locale?: Locales
|
|
15
|
+
) => IntlayerDictionaryTypesConnector[T];
|
|
16
|
+
declare const useIntlayerBase: UseIntlayer;
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
type DictionaryKeys,
|
|
20
|
+
type StringFallback,
|
|
21
|
+
type UseIntlayer,
|
|
22
|
+
useIntlayerBase,
|
|
23
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useState, useRef, useCallback } from "react";
|
|
4
|
+
const PRESS_DETECT_DURATION = 500;
|
|
5
|
+
const ContentEditor = ({ children }) => {
|
|
6
|
+
const divRef = useRef(null);
|
|
7
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
8
|
+
const pressTimerRef = useRef(null);
|
|
9
|
+
const handleOnLongPress = () => {
|
|
10
|
+
setIsEditing(true);
|
|
11
|
+
};
|
|
12
|
+
const startPressTimer = () => {
|
|
13
|
+
pressTimerRef.current = setTimeout(() => {
|
|
14
|
+
handleOnLongPress();
|
|
15
|
+
}, PRESS_DETECT_DURATION);
|
|
16
|
+
};
|
|
17
|
+
const clearPressTimer = () => {
|
|
18
|
+
if (pressTimerRef.current) {
|
|
19
|
+
clearTimeout(pressTimerRef.current);
|
|
20
|
+
pressTimerRef.current = null;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const handleMouseDown = () => {
|
|
24
|
+
clearPressTimer();
|
|
25
|
+
startPressTimer();
|
|
26
|
+
};
|
|
27
|
+
const handleMouseUp = () => {
|
|
28
|
+
clearPressTimer();
|
|
29
|
+
};
|
|
30
|
+
const handleClickOutside = useCallback(
|
|
31
|
+
(event) => {
|
|
32
|
+
if (divRef.current && !divRef.current.contains(event.target)) {
|
|
33
|
+
setIsEditing(false);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
[divRef]
|
|
37
|
+
);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
40
|
+
return () => {
|
|
41
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
42
|
+
clearPressTimer();
|
|
43
|
+
};
|
|
44
|
+
}, [handleClickOutside]);
|
|
45
|
+
const handleOnClick = (e) => {
|
|
46
|
+
if (isEditing) {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
e.stopPropagation();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const handleOnBlur = () => {
|
|
52
|
+
setIsEditing(false);
|
|
53
|
+
};
|
|
54
|
+
const onContentChange = (_e) => {};
|
|
55
|
+
return /* @__PURE__ */ jsx("div", {
|
|
56
|
+
role: "textbox",
|
|
57
|
+
tabIndex: 0,
|
|
58
|
+
onKeyUp: () => null,
|
|
59
|
+
contentEditable: isEditing,
|
|
60
|
+
onInput: onContentChange,
|
|
61
|
+
onClick: handleOnClick,
|
|
62
|
+
onMouseDown: handleMouseDown,
|
|
63
|
+
onMouseUp: handleMouseUp,
|
|
64
|
+
onMouseLeave: handleMouseUp,
|
|
65
|
+
onTouchStart: handleMouseDown,
|
|
66
|
+
onTouchEnd: handleMouseUp,
|
|
67
|
+
onTouchCancel: handleMouseUp,
|
|
68
|
+
onBlur: handleOnBlur,
|
|
69
|
+
suppressContentEditableWarning: true,
|
|
70
|
+
style: isEditing
|
|
71
|
+
? {
|
|
72
|
+
backgroundColor: "transparent",
|
|
73
|
+
cursor: "text",
|
|
74
|
+
display: "inline",
|
|
75
|
+
}
|
|
76
|
+
: { cursor: "pointer", display: "inline" },
|
|
77
|
+
ref: divRef,
|
|
78
|
+
children,
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
export { ContentEditor };
|
|
82
|
+
//# sourceMappingURL=ContentEditor.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ContentEditor/ContentEditor.tsx"],"sourcesContent":["'use client';\n\nimport {\n useEffect,\n useState,\n useRef,\n useCallback,\n type FC,\n type MouseEventHandler,\n} from 'react';\n\ntype ContentEditorProps = {\n children?: string;\n};\n\nconst PRESS_DETECT_DURATION = 500;\n\nexport const ContentEditor: FC<ContentEditorProps> = ({ children }) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isEditing, setIsEditing] = useState(false);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const handleOnLongPress = () => {\n setIsEditing(true);\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, PRESS_DETECT_DURATION);\n };\n\n const clearPressTimer = () => {\n if (pressTimerRef.current) {\n clearTimeout(pressTimerRef.current);\n pressTimerRef.current = null;\n }\n };\n\n const handleMouseDown = () => {\n clearPressTimer(); // Ensure any previous timer is cleared\n startPressTimer();\n };\n\n const handleMouseUp = () => {\n clearPressTimer();\n };\n\n // Use useCallback to ensure the function identity remains stable\n const handleClickOutside = useCallback(\n (event: MouseEvent) => {\n if (divRef.current && !divRef.current.contains(event.target as Node)) {\n setIsEditing(false);\n }\n },\n [divRef]\n );\n\n useEffect(() => {\n // Attach click outside listener\n document.addEventListener('mousedown', handleClickOutside);\n\n return () => {\n // Cleanup\n document.removeEventListener('mousedown', handleClickOutside);\n clearPressTimer(); // Ensure to clear the timer when component unmounts\n };\n }, [handleClickOutside]);\n\n const handleOnClick: MouseEventHandler<HTMLDivElement> = (e) => {\n if (isEditing) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsEditing(false);\n };\n\n const onContentChange = (_e: React.FormEvent<HTMLDivElement>) => {\n // console.log(e.currentTarget.textContent);\n };\n\n return (\n <div\n role=\"textbox\"\n tabIndex={0}\n onKeyUp={() => null}\n contentEditable={isEditing}\n onInput={onContentChange}\n onClick={handleOnClick}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n onTouchStart={handleMouseDown}\n onTouchEnd={handleMouseUp}\n onTouchCancel={handleMouseUp}\n onBlur={handleOnBlur}\n suppressContentEditableWarning={true} // To suppress the warning for controlled components\n style={\n isEditing\n ? {\n backgroundColor: 'transparent',\n cursor: 'text',\n display: 'inline',\n }\n : { cursor: 'pointer', display: 'inline' }\n }\n ref={divRef}\n >\n {children}\n </div>\n );\n};\n"],"mappings":";AAsFI;AApFJ;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAMP,MAAM,wBAAwB;AAEvB,MAAM,gBAAwC,CAAC,EAAE,SAAS,MAAM;AACrE,QAAM,SAAS,OAAuB,IAAI;AAC1C,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,QAAM,gBAAgB,OAA6C,IAAI;AAEvE,QAAM,oBAAoB,MAAM;AAC9B,iBAAa,IAAI;AAAA,EACnB;AAEA,QAAM,kBAAkB,MAAM;AAC5B,kBAAc,UAAU,WAAW,MAAM;AACvC,wBAAkB;AAAA,IACpB,GAAG,qBAAqB;AAAA,EAC1B;AAEA,QAAM,kBAAkB,MAAM;AAC5B,QAAI,cAAc,SAAS;AACzB,mBAAa,cAAc,OAAO;AAClC,oBAAc,UAAU;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,kBAAkB,MAAM;AAC5B,oBAAgB;AAChB,oBAAgB;AAAA,EAClB;AAEA,QAAM,gBAAgB,MAAM;AAC1B,oBAAgB;AAAA,EAClB;AAGA,QAAM,qBAAqB;AAAA,IACzB,CAAC,UAAsB;AACrB,UAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,SAAS,MAAM,MAAc,GAAG;AACpE,qBAAa,KAAK;AAAA,MACpB;AAAA,IACF;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AAEA,YAAU,MAAM;AAEd,aAAS,iBAAiB,aAAa,kBAAkB;AAEzD,WAAO,MAAM;AAEX,eAAS,oBAAoB,aAAa,kBAAkB;AAC5D,sBAAgB;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,kBAAkB,CAAC;AAEvB,QAAM,gBAAmD,CAAC,MAAM;AAC9D,QAAI,WAAW;AACb,QAAE,eAAe;AACjB,QAAE,gBAAgB;AAAA,IACpB;AAAA,EACF;AAEA,QAAM,eAAe,MAAM;AAEzB,iBAAa,KAAK;AAAA,EACpB;AAEA,QAAM,kBAAkB,CAAC,OAAwC;AAAA,EAEjE;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,UAAU;AAAA,MACV,SAAS,MAAM;AAAA,MACf,iBAAiB;AAAA,MACjB,SAAS;AAAA,MACT,SAAS;AAAA,MACT,aAAa;AAAA,MACb,WAAW;AAAA,MACX,cAAc;AAAA,MACd,cAAc;AAAA,MACd,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,QAAQ;AAAA,MACR,gCAAgC;AAAA,MAChC,OACE,YACI;AAAA,QACE,iBAAiB;AAAA,QACjB,QAAQ;AAAA,QACR,SAAS;AAAA,MACX,IACA,EAAE,QAAQ,WAAW,SAAS,SAAS;AAAA,MAE7C,KAAK;AAAA,MAEJ;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ContentEditor } from "./ContentEditor.mjs";
|
|
3
|
+
const contentRender = (content) => {
|
|
4
|
+
const isEditable = process.env.NODE_ENV === "development";
|
|
5
|
+
if (isEditable && ContentEditor) {
|
|
6
|
+
return /* @__PURE__ */ jsx(ContentEditor, { children: content });
|
|
7
|
+
}
|
|
8
|
+
return content;
|
|
9
|
+
};
|
|
10
|
+
export { contentRender };
|
|
11
|
+
//# sourceMappingURL=contentRender.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ContentEditor/contentRender.tsx"],"sourcesContent":["import { ContentEditor } from './ContentEditor';\n\nexport const contentRender = (content: string) => {\n const isEditable = process.env.NODE_ENV === 'development';\n\n if (isEditable && ContentEditor) {\n return (<ContentEditor>{content}</ContentEditor>) as unknown as string;\n }\n\n return content;\n};\n"],"mappings":"AAMY;AANZ,SAAS,qBAAqB;AAEvB,MAAM,gBAAgB,CAAC,YAAoB;AAChD,QAAM,aAAa,QAAQ,IAAI,aAAa;AAE5C,MAAI,cAAc,eAAe;AAC/B,WAAQ,oBAAC,iBAAe,mBAAQ;AAAA,EAClC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ContentEditor/index.tsx"],"sourcesContent":["export * from './ContentEditor';\nexport * from './contentRender';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { LocaleClientContextProviderProps } from "./client/LocaleClientContextProvider.mjs";
|
|
3
|
+
import { LocaleServerContextProviderProps } from "./server/LocaleServerContextProvider.mjs";
|
|
4
|
+
import "@intlayer/config/client";
|
|
5
|
+
|
|
6
|
+
type LocaleContextProviderProps = LocaleClientContextProviderProps &
|
|
7
|
+
LocaleServerContextProviderProps;
|
|
8
|
+
declare const LocaleContextProvider: FC<LocaleContextProviderProps>;
|
|
9
|
+
|
|
10
|
+
export { LocaleContextProvider };
|