react-intlayer 4.0.2 → 4.0.4
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/README.md +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +126 -0
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -0
- package/dist/cjs/client/IntlayerProvider.cjs +5 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/{utils/PoweredByMeta/index.cjs → client/PoweredByMeta.cjs} +10 -5
- package/dist/cjs/client/PoweredByMeta.cjs.map +1 -0
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +51 -2
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +41 -6
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +0 -2
- package/dist/cjs/editor/index.cjs.map +1 -1
- package/dist/cjs/editor/renderContentEditor.cjs +4 -24
- package/dist/cjs/editor/renderContentEditor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +4 -31
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +2 -2
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/getIntlayerAsync.cjs +2 -2
- package/dist/cjs/getIntlayerAsync.cjs.map +1 -1
- package/dist/cjs/recursiveTransformContent.cjs +54 -0
- package/dist/cjs/recursiveTransformContent.cjs.map +1 -0
- package/dist/esm/UI/ContentSelector.mjs +107 -0
- package/dist/esm/UI/ContentSelector.mjs.map +1 -0
- package/dist/esm/client/IntlayerProvider.mjs +6 -2
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/PoweredByMeta.mjs +21 -0
- package/dist/esm/client/PoweredByMeta.mjs.map +1 -0
- package/dist/esm/editor/ContentSelectorWrapper.mjs +60 -2
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +38 -7
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +0 -1
- package/dist/esm/editor/index.mjs.map +1 -1
- package/dist/esm/editor/renderContentEditor.mjs +6 -24
- package/dist/esm/editor/renderContentEditor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +4 -30
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +2 -2
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/getIntlayerAsync.mjs +1 -1
- package/dist/esm/getIntlayerAsync.mjs.map +1 -1
- package/dist/esm/recursiveTransformContent.mjs +32 -0
- package/dist/esm/recursiveTransformContent.mjs.map +1 -0
- package/dist/types/UI/ContentSelector.d.ts +10 -0
- package/dist/types/UI/ContentSelector.d.ts.map +1 -0
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/{utils/PoweredByMeta/index.d.ts → client/PoweredByMeta.d.ts} +1 -1
- package/dist/types/client/PoweredByMeta.d.ts.map +1 -0
- package/dist/types/editor/ContentSelectorWrapper.d.ts +5 -3
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
- package/dist/types/editor/index.d.ts +0 -1
- package/dist/types/editor/index.d.ts.map +1 -1
- package/dist/types/editor/renderContentEditor.d.ts +5 -9
- package/dist/types/editor/renderContentEditor.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +3 -25
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +3 -3
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/getIntlayerAsync.d.ts.map +1 -1
- package/dist/types/recursiveTransformContent.d.ts +27 -0
- package/dist/types/recursiveTransformContent.d.ts.map +1 -0
- package/package.json +16 -13
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +0 -59
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +0 -1
- package/dist/cjs/editor/ContentSelectorConnector.cjs +0 -58
- package/dist/cjs/editor/ContentSelectorConnector.cjs.map +0 -1
- package/dist/cjs/utils/PoweredByMeta/index.cjs.map +0 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +0 -35
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +0 -1
- package/dist/esm/editor/ContentSelectorConnector.mjs +0 -38
- package/dist/esm/editor/ContentSelectorConnector.mjs.map +0 -1
- package/dist/esm/utils/PoweredByMeta/index.mjs +0 -16
- package/dist/esm/utils/PoweredByMeta/index.mjs.map +0 -1
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +0 -6
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +0 -1
- package/dist/types/editor/ContentSelectorConnector.d.ts +0 -14
- package/dist/types/editor/ContentSelectorConnector.d.ts.map +0 -1
- package/dist/types/utils/PoweredByMeta/index.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
</a>
|
|
18
18
|
</div>
|
|
19
19
|
|
|
20
|
-
# react-intlayer:
|
|
20
|
+
# react-intlayer: Internationalize (i18n) an React application
|
|
21
21
|
|
|
22
22
|
**Intlayer** is a suite of packages designed specifically for JavaScript developers. It is compatible with frameworks like React, React, and Express.js.
|
|
23
23
|
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var ContentSelector_exports = {};
|
|
21
|
+
__export(ContentSelector_exports, {
|
|
22
|
+
ContentSelector: () => ContentSelector
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(ContentSelector_exports);
|
|
25
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
|
+
var import_react = require("react");
|
|
27
|
+
const DEFAULT_PRESS_DETECT_DURATION = 400;
|
|
28
|
+
const ContentSelector = ({
|
|
29
|
+
children,
|
|
30
|
+
onPress: onSelect,
|
|
31
|
+
onClickOutside: onUnselect,
|
|
32
|
+
pressDuration = DEFAULT_PRESS_DETECT_DURATION,
|
|
33
|
+
isSelecting: isSelectingProp,
|
|
34
|
+
...props
|
|
35
|
+
}) => {
|
|
36
|
+
const divRef = (0, import_react.useRef)(null);
|
|
37
|
+
const [isHovered, setIsHovered] = (0, import_react.useState)(false);
|
|
38
|
+
const [isSelectingState, setIsSelectingState] = (0, import_react.useState)(isSelectingProp);
|
|
39
|
+
const pressTimerRef = (0, import_react.useRef)(null);
|
|
40
|
+
const handleOnLongPress = () => {
|
|
41
|
+
setIsSelectingState(true);
|
|
42
|
+
onSelect();
|
|
43
|
+
};
|
|
44
|
+
const startPressTimer = () => {
|
|
45
|
+
pressTimerRef.current = setTimeout(() => {
|
|
46
|
+
handleOnLongPress();
|
|
47
|
+
}, pressDuration);
|
|
48
|
+
};
|
|
49
|
+
const clearPressTimer = () => {
|
|
50
|
+
if (pressTimerRef.current) {
|
|
51
|
+
clearTimeout(pressTimerRef.current);
|
|
52
|
+
pressTimerRef.current = null;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const handleMouseDown = () => {
|
|
56
|
+
clearPressTimer();
|
|
57
|
+
startPressTimer();
|
|
58
|
+
};
|
|
59
|
+
const handleMouseEnter = () => {
|
|
60
|
+
setIsHovered(true);
|
|
61
|
+
};
|
|
62
|
+
const handleMouseUp = () => {
|
|
63
|
+
setIsHovered(false);
|
|
64
|
+
clearPressTimer();
|
|
65
|
+
};
|
|
66
|
+
const handleClickOutside = (0, import_react.useCallback)(
|
|
67
|
+
(event) => {
|
|
68
|
+
if (divRef.current && !divRef.current.contains(event.target)) {
|
|
69
|
+
setIsSelectingState(false);
|
|
70
|
+
onUnselect?.();
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
[onUnselect]
|
|
74
|
+
);
|
|
75
|
+
(0, import_react.useEffect)(() => {
|
|
76
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
77
|
+
return () => {
|
|
78
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
79
|
+
};
|
|
80
|
+
}, [handleClickOutside]);
|
|
81
|
+
const handleOnClick = (e) => {
|
|
82
|
+
if (isSelectingState) {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
e.stopPropagation();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const handleOnBlur = () => {
|
|
88
|
+
setIsSelectingState(false);
|
|
89
|
+
};
|
|
90
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
91
|
+
"span",
|
|
92
|
+
{
|
|
93
|
+
style: {
|
|
94
|
+
display: "inline",
|
|
95
|
+
cursor: "pointer",
|
|
96
|
+
userSelect: "none",
|
|
97
|
+
borderRadius: "0.375rem",
|
|
98
|
+
outlineWidth: "2px",
|
|
99
|
+
outlineOffset: "4px",
|
|
100
|
+
outlineStyle: "solid",
|
|
101
|
+
outlineColor: isSelectingProp || isSelectingState || isHovered ? "inherit" : "transparent",
|
|
102
|
+
transition: "all 200ms 100ms ease-in-out"
|
|
103
|
+
},
|
|
104
|
+
role: "button",
|
|
105
|
+
tabIndex: 0,
|
|
106
|
+
onKeyUp: () => null,
|
|
107
|
+
onClick: handleOnClick,
|
|
108
|
+
onMouseDown: handleMouseDown,
|
|
109
|
+
onMouseUp: handleMouseUp,
|
|
110
|
+
onMouseLeave: handleMouseUp,
|
|
111
|
+
onTouchStart: handleMouseDown,
|
|
112
|
+
onTouchEnd: handleMouseUp,
|
|
113
|
+
onTouchCancel: handleMouseUp,
|
|
114
|
+
onBlur: handleOnBlur,
|
|
115
|
+
onMouseEnter: handleMouseEnter,
|
|
116
|
+
ref: divRef,
|
|
117
|
+
...props,
|
|
118
|
+
children
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
+
0 && (module.exports = {
|
|
124
|
+
ContentSelector
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=ContentSelector.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport {\n useEffect,\n useState,\n useRef,\n useCallback,\n type FC,\n type MouseEventHandler,\n type HTMLAttributes,\n} from 'react';\n\nconst DEFAULT_PRESS_DETECT_DURATION = 400;\n\ntype ContentSelectorProps = {\n onPress: () => void;\n onClickOutside?: () => void;\n pressDuration?: number;\n isSelecting?: boolean;\n} & HTMLAttributes<HTMLDivElement>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n onPress: onSelect,\n onClickOutside: onUnselect,\n pressDuration = DEFAULT_PRESS_DETECT_DURATION,\n isSelecting: isSelectingProp,\n ...props\n}) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isHovered, setIsHovered] = useState(false);\n const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const handleOnLongPress = () => {\n setIsSelectingState(true);\n onSelect();\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, pressDuration);\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 handleMouseEnter = () => {\n setIsHovered(true);\n };\n\n const handleMouseUp = () => {\n setIsHovered(false);\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 setIsSelectingState(false);\n onUnselect?.();\n }\n },\n [onUnselect]\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 (isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsSelectingState(false);\n };\n\n return (\n <span\n style={{\n display: 'inline',\n cursor: 'pointer',\n userSelect: 'none',\n borderRadius: '0.375rem',\n outlineWidth: '2px',\n outlineOffset: '4px',\n outlineStyle: 'solid',\n outlineColor:\n isSelectingProp || isSelectingState || isHovered\n ? 'inherit'\n : 'transparent',\n transition: 'all 200ms 100ms ease-in-out',\n }}\n role=\"button\"\n tabIndex={0}\n onKeyUp={() => null}\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 onMouseEnter={handleMouseEnter}\n ref={divRef}\n {...props}\n >\n {children}\n </span>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqGI;AAnGJ,mBAQO;AAEP,MAAM,gCAAgC;AAS/B,MAAM,kBAA4C,CAAC;AAAA,EACxD;AAAA,EACA,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,GAAG;AACL,MAAM;AACJ,QAAM,aAAS,qBAAuB,IAAI;AAC1C,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAChD,QAAM,CAAC,kBAAkB,mBAAmB,QAAI,uBAAS,eAAe;AACxE,QAAM,oBAAgB,qBAA6C,IAAI;AAEvE,QAAM,oBAAoB,MAAM;AAC9B,wBAAoB,IAAI;AACxB,aAAS;AAAA,EACX;AAEA,QAAM,kBAAkB,MAAM;AAC5B,kBAAc,UAAU,WAAW,MAAM;AACvC,wBAAkB;AAAA,IACpB,GAAG,aAAa;AAAA,EAClB;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,mBAAmB,MAAM;AAC7B,iBAAa,IAAI;AAAA,EACnB;AAEA,QAAM,gBAAgB,MAAM;AAC1B,iBAAa,KAAK;AAClB,oBAAgB;AAAA,EAClB;AAGA,QAAM,yBAAqB;AAAA,IACzB,CAAC,UAAsB;AACrB,UAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,SAAS,MAAM,MAAc,GAAG;AACpE,4BAAoB,KAAK;AACzB,qBAAa;AAAA,MACf;AAAA,IACF;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,8BAAU,MAAM;AAEd,aAAS,iBAAiB,aAAa,kBAAkB;AAEzD,WAAO,MAAM;AAEX,eAAS,oBAAoB,aAAa,kBAAkB;AAAA,IAE9D;AAAA,EACF,GAAG,CAAC,kBAAkB,CAAC;AAEvB,QAAM,gBAAmD,CAAC,MAAM;AAC9D,QAAI,kBAAkB;AACpB,QAAE,eAAe;AACjB,QAAE,gBAAgB;AAAA,IACpB;AAAA,EACF;AAEA,QAAM,eAAe,MAAM;AAEzB,wBAAoB,KAAK;AAAA,EAC3B;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,cAAc;AAAA,QACd,eAAe;AAAA,QACf,cAAc;AAAA,QACd,cACE,mBAAmB,oBAAoB,YACnC,YACA;AAAA,QACN,YAAY;AAAA,MACd;AAAA,MACA,MAAK;AAAA,MACL,UAAU;AAAA,MACV,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,MACT,aAAa;AAAA,MACb,WAAW;AAAA,MACX,cAAc;AAAA,MACd,cAAc;AAAA,MACd,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,QAAQ;AAAA,MACR,cAAc;AAAA,MACd,KAAK;AAAA,MACJ,GAAG;AAAA,MAEH;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
|
@@ -29,6 +29,7 @@ var import_client = require("@intlayer/config/client");
|
|
|
29
29
|
var import_react = require("react");
|
|
30
30
|
var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
31
31
|
var import_IntlayerEditorProvider = require('../editor/IntlayerEditorProvider.cjs');
|
|
32
|
+
var import_PoweredByMeta = require('./PoweredByMeta.cjs');
|
|
32
33
|
const IntlayerClientContext = (0, import_react.createContext)({
|
|
33
34
|
locale: import_useLocaleCookie.localeCookie ?? (0, import_client.getConfiguration)().internationalization.defaultLocale,
|
|
34
35
|
setLocale: () => null
|
|
@@ -61,7 +62,10 @@ const IntlayerProvider = ({
|
|
|
61
62
|
() => ({ locale: currentLocale, setLocale }),
|
|
62
63
|
[currentLocale, setLocale]
|
|
63
64
|
);
|
|
64
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.
|
|
65
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(IntlayerClientContext.Provider, { value, children: [
|
|
66
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_PoweredByMeta.PoweredByMeta, {}),
|
|
67
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_IntlayerEditorProvider.IntlayerEditorProvider, { children })
|
|
68
|
+
] });
|
|
65
69
|
};
|
|
66
70
|
// Annotate the CommonJS export names for ESM import in node:
|
|
67
71
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\n\ntype IntlayerValue = {\n locale: Locales;\n setLocale: (newLocale: Locales) => void;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = PropsWithChildren & {\n locale?: Locales;\n setLocale?: (locale: Locales) => void;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n}) => {\n const { internationalization } = getConfiguration();\n const { defaultLocale, locales: availableLocales } = internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocaleBase = useCallback(\n (newLocale: Locales) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale]\n );\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale: setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <IntlayerEditorProvider>{children}</IntlayerEditorProvider>\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { PoweredByMeta } from './PoweredByMeta';\n\ntype IntlayerValue = {\n locale: Locales;\n setLocale: (newLocale: Locales) => void;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = PropsWithChildren & {\n locale?: Locales;\n setLocale?: (locale: Locales) => void;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n}) => {\n const { internationalization } = getConfiguration();\n const { defaultLocale, locales: availableLocales } = internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocaleBase = useCallback(\n (newLocale: Locales) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale]\n );\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale: setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <PoweredByMeta />\n <IntlayerEditorProvider>{children}</IntlayerEditorProvider>\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6EI;AA3EJ,oBAA+C;AAC/C,mBAQO;AACP,6BAA8C;AAC9C,oCAAuC;AACvC,2BAA8B;AAUvB,MAAM,4BAAwB,4BAA6B;AAAA,EAChE,QAAQ,2CAAgB,gCAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,UAAM,yBAAW,qBAAqB;AAUjE,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA;AAAA,EACA,WAAW;AACb,MAAM;AACJ,QAAM,EAAE,qBAAqB,QAAI,gCAAiB;AAClD,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAAI;AAErD,QAAM,CAAC,eAAe,gBAAgB,QAAI;AAAA,IACxC,UAAU,uCAAgB;AAAA,EAC5B;AAEA,QAAM,oBAAgB;AAAA,IACpB,CAAC,cAAuB;AACtB,UAAI,cAAc,SAAS,MAAM,UAAU,SAAS,EAAG;AAEvD,UAAI,CAAC,iBAAiB,SAAS,SAAS,GAAG;AACzC,gBAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,uBAAiB,SAAS;AAC1B,kDAAgB,SAAS;AAAA,IAC3B;AAAA,IACA,CAAC,kBAAkB,eAAe,MAAM;AAAA,EAC1C;AAEA,QAAM,YAAY,iBAAiB;AAEnC,QAAM,YAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAqB;AAAA,IACrD,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,6CAAC,sBAAsB,UAAtB,EAA+B,OAC9B;AAAA,gDAAC,sCAAc;AAAA,IACf,4CAAC,wDAAwB,UAAS;AAAA,KACpC;AAEJ;","names":[]}
|
|
@@ -26,10 +26,15 @@ var import_react = require("react");
|
|
|
26
26
|
const PoweredByMeta = () => {
|
|
27
27
|
if (process.env.NODE_ENV !== "production") return null;
|
|
28
28
|
(0, import_react.useEffect)(() => {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const existingMeta = document.head.querySelector(
|
|
30
|
+
'meta[name="content-powered-by"]'
|
|
31
|
+
);
|
|
32
|
+
if (!existingMeta) {
|
|
33
|
+
const metaTag = document.createElement("meta");
|
|
34
|
+
metaTag.name = "content-powered-by";
|
|
35
|
+
metaTag.content = "Intlayer - https://intlayer.org";
|
|
36
|
+
document.head.appendChild(metaTag);
|
|
37
|
+
}
|
|
33
38
|
}, []);
|
|
34
39
|
return null;
|
|
35
40
|
};
|
|
@@ -37,4 +42,4 @@ const PoweredByMeta = () => {
|
|
|
37
42
|
0 && (module.exports = {
|
|
38
43
|
PoweredByMeta
|
|
39
44
|
});
|
|
40
|
-
//# sourceMappingURL=
|
|
45
|
+
//# sourceMappingURL=PoweredByMeta.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/PoweredByMeta.ts"],"sourcesContent":["'use client';\n\nimport { type FC, useEffect } from 'react';\n\nexport const PoweredByMeta: FC = () => {\n if (process.env.NODE_ENV !== 'production') return null;\n\n useEffect(() => {\n // Check if the meta tag already exists\n const existingMeta = document.head.querySelector(\n 'meta[name=\"content-powered-by\"]'\n );\n\n if (!existingMeta) {\n const metaTag = document.createElement('meta');\n metaTag.name = 'content-powered-by';\n metaTag.content = 'Intlayer - https://intlayer.org';\n document.head.appendChild(metaTag);\n }\n }, []);\n\n return null; // This component does not render anything visible\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAmC;AAE5B,MAAM,gBAAoB,MAAM;AACrC,MAAI,QAAQ,IAAI,aAAa,aAAc,QAAO;AAElD,8BAAU,MAAM;AAEd,UAAM,eAAe,SAAS,KAAK;AAAA,MACjC;AAAA,IACF;AAEA,QAAI,CAAC,cAAc;AACjB,YAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,cAAQ,OAAO;AACf,cAAQ,UAAU;AAClB,eAAS,KAAK,YAAY,OAAO;AAAA,IACnC;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
"use client";
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -22,9 +23,57 @@ __export(ContentSelectorWrapper_exports, {
|
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(ContentSelectorWrapper_exports);
|
|
24
25
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
|
+
var import_core = require("@intlayer/core");
|
|
27
|
+
var import_editor_react = require("@intlayer/editor-react");
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_ContentSelector = require('../UI/ContentSelector.cjs');
|
|
25
30
|
const ContentSelectorWrapper = ({
|
|
26
|
-
children
|
|
27
|
-
|
|
31
|
+
children,
|
|
32
|
+
dictionaryKey,
|
|
33
|
+
dictionaryPath,
|
|
34
|
+
keyPath,
|
|
35
|
+
...props
|
|
36
|
+
}) => {
|
|
37
|
+
const { enabled } = (0, import_editor_react.useEditorEnabled)();
|
|
38
|
+
const { focusedContent, setFocusedContent } = (0, import_editor_react.useFocusDictionary)();
|
|
39
|
+
const { getEditedContentValue } = (0, import_editor_react.useEditedContentActions)();
|
|
40
|
+
const editedValue = (0, import_react.useMemo)(
|
|
41
|
+
() => getEditedContentValue(dictionaryKey, keyPath),
|
|
42
|
+
[dictionaryKey, keyPath, getEditedContentValue]
|
|
43
|
+
);
|
|
44
|
+
const [displayedChildren, setDisplayedChildren] = (0, import_react.useState)(children);
|
|
45
|
+
const handleSelect = (0, import_react.useCallback)(
|
|
46
|
+
() => setFocusedContent({
|
|
47
|
+
dictionaryKey,
|
|
48
|
+
dictionaryPath,
|
|
49
|
+
keyPath
|
|
50
|
+
}),
|
|
51
|
+
[dictionaryKey, dictionaryPath, keyPath, setFocusedContent]
|
|
52
|
+
);
|
|
53
|
+
const isSelected = (0, import_react.useMemo)(
|
|
54
|
+
() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && (0, import_core.isSameKeyPath)(focusedContent?.keyPath ?? [], keyPath)) ?? false,
|
|
55
|
+
[focusedContent, keyPath]
|
|
56
|
+
);
|
|
57
|
+
(0, import_react.useEffect)(() => {
|
|
58
|
+
if (editedValue && typeof editedValue === "string") {
|
|
59
|
+
setDisplayedChildren(editedValue);
|
|
60
|
+
} else {
|
|
61
|
+
setDisplayedChildren(children);
|
|
62
|
+
}
|
|
63
|
+
}, [editedValue, focusedContent, children]);
|
|
64
|
+
if (enabled) {
|
|
65
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
66
|
+
import_ContentSelector.ContentSelector,
|
|
67
|
+
{
|
|
68
|
+
onPress: handleSelect,
|
|
69
|
+
isSelecting: isSelected,
|
|
70
|
+
...props,
|
|
71
|
+
children: displayedChildren
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
76
|
+
};
|
|
28
77
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
78
|
0 && (module.exports = {
|
|
30
79
|
ContentSelectorWrapper
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { isSameKeyPath, type KeyPath } from '@intlayer/core';\nimport {\n useFocusDictionary,\n useEditedContentActions,\n useEditorEnabled,\n} from '@intlayer/editor-react';\nimport {\n useCallback,\n useEffect,\n useState,\n useMemo,\n type FC,\n type ReactNode,\n HTMLAttributes,\n} from 'react';\nimport { ContentSelector } from '../UI/ContentSelector';\n\ntype ContentData = {\n dictionaryKey: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n};\n\nexport type ContentSelectorWrapperProps = ContentData &\n HTMLAttributes<HTMLDivElement>;\n\nexport const ContentSelectorWrapper: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n dictionaryPath,\n keyPath,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { getEditedContentValue } = useEditedContentActions();\n\n const editedValue = useMemo(\n () => getEditedContentValue(dictionaryKey, keyPath),\n [dictionaryKey, keyPath, getEditedContentValue]\n );\n\n const [displayedChildren, setDisplayedChildren] =\n useState<ReactNode>(children);\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n dictionaryPath,\n keyPath,\n }),\n [dictionaryKey, dictionaryPath, keyPath, setFocusedContent]\n );\n\n const isSelected = useMemo(\n () =>\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ??\n false,\n [focusedContent, keyPath]\n );\n\n useEffect(() => {\n // Use useEffect to avoid 'Text content does not match server-rendered HTML' error\n if (editedValue && typeof editedValue === 'string') {\n setDisplayedChildren(editedValue);\n } else {\n setDisplayedChildren(children);\n }\n }, [editedValue, focusedContent, children]);\n\n if (enabled) {\n return (\n <ContentSelector\n onPress={handleSelect}\n isSelecting={isSelected}\n {...props}\n >\n {displayedChildren}\n </ContentSelector>\n );\n }\n\n return <>{children}</>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA6EM;AA3EN,kBAA4C;AAC5C,0BAIO;AACP,mBAQO;AACP,6BAAgC;AAWzB,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,QAAQ,QAAI,sCAAiB;AACrC,QAAM,EAAE,gBAAgB,kBAAkB,QAAI,wCAAmB;AACjE,QAAM,EAAE,sBAAsB,QAAI,6CAAwB;AAE1D,QAAM,kBAAc;AAAA,IAClB,MAAM,sBAAsB,eAAe,OAAO;AAAA,IAClD,CAAC,eAAe,SAAS,qBAAqB;AAAA,EAChD;AAEA,QAAM,CAAC,mBAAmB,oBAAoB,QAC5C,uBAAoB,QAAQ;AAE9B,QAAM,mBAAe;AAAA,IACnB,MACE,kBAAkB;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,gBAAgB,SAAS,iBAAiB;AAAA,EAC5D;AAEA,QAAM,iBAAa;AAAA,IACjB,OACG,gBAAgB,kBAAkB,kBAChC,gBAAgB,SAAS,UAAU,KAAK,SACzC,2BAAc,gBAAgB,WAAW,CAAC,GAAG,OAAO,MACtD;AAAA,IACF,CAAC,gBAAgB,OAAO;AAAA,EAC1B;AAEA,8BAAU,MAAM;AAEd,QAAI,eAAe,OAAO,gBAAgB,UAAU;AAClD,2BAAqB,WAAW;AAAA,IAClC,OAAO;AACL,2BAAqB,QAAQ;AAAA,IAC/B;AAAA,EACF,GAAG,CAAC,aAAa,gBAAgB,QAAQ,CAAC;AAE1C,MAAI,SAAS;AACX,WACE;AAAA,MAAC;AAAA;AAAA,QACC,SAAS;AAAA,QACT,aAAa;AAAA,QACZ,GAAG;AAAA,QAEH;AAAA;AAAA,IACH;AAAA,EAEJ;AAEA,SAAO,2EAAG,UAAS;AACrB;","names":[]}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
2
4
|
var __defProp = Object.defineProperty;
|
|
3
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
9
|
var __export = (target, all) => {
|
|
7
10
|
for (var name in all)
|
|
@@ -15,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
18
|
}
|
|
16
19
|
return to;
|
|
17
20
|
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
18
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
30
|
var IntlayerEditorProvider_exports = {};
|
|
20
31
|
__export(IntlayerEditorProvider_exports, {
|
|
@@ -22,12 +33,36 @@ __export(IntlayerEditorProvider_exports, {
|
|
|
22
33
|
});
|
|
23
34
|
module.exports = __toCommonJS(IntlayerEditorProvider_exports);
|
|
24
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
var import_client = require("@intlayer/config/client");
|
|
37
|
+
var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
|
|
38
|
+
var import_editor_react = require("@intlayer/editor-react");
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
const IntlayerEditorProviderEnabled = () => {
|
|
41
|
+
(0, import_editor_react.useCrossURLPathState)(void 0, {
|
|
42
|
+
receive: false,
|
|
43
|
+
emit: true
|
|
44
|
+
});
|
|
45
|
+
const { setConfiguration } = (0, import_editor_react.useConfigurationActions)();
|
|
46
|
+
const { setLocaleDictionaries } = (0, import_editor_react.useDictionariesRecordActions)();
|
|
47
|
+
(0, import_react.useEffect)(() => {
|
|
48
|
+
setLocaleDictionaries(import_dictionaries_entry.default);
|
|
49
|
+
const config = (0, import_client.getConfiguration)();
|
|
50
|
+
setConfiguration(config);
|
|
51
|
+
}, [setLocaleDictionaries]);
|
|
52
|
+
(0, import_editor_react.useIframeClickInterceptor)();
|
|
53
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
|
|
54
|
+
};
|
|
55
|
+
const IntlayerEditorProvider = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
56
|
+
import_editor_react.EditorProvider,
|
|
57
|
+
{
|
|
58
|
+
postMessage: (data) => window.parent?.postMessage(data, "*"),
|
|
59
|
+
allowedOrigins: ["*"],
|
|
60
|
+
children: [
|
|
61
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlayerEditorProviderEnabled, {}),
|
|
62
|
+
children
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
);
|
|
31
66
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
67
|
0 && (module.exports = {
|
|
33
68
|
IntlayerEditorProvider
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport {\n EditorProvider,\n useCrossURLPathState,\n useDictionariesRecordActions,\n useConfigurationActions,\n useIframeClickInterceptor,\n} from '@intlayer/editor-react';\nimport { useEffect, type FC, type PropsWithChildren } from 'react';\n\n/**\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 */\nconst IntlayerEditorProviderEnabled: FC = () => {\n /**\n * URL Messages\n */\n useCrossURLPathState(undefined, {\n receive: false,\n emit: true,\n });\n\n /**\n * Configuration Messages\n */\n const { setConfiguration } = useConfigurationActions();\n const { setLocaleDictionaries } = useDictionariesRecordActions();\n\n useEffect(() => {\n setLocaleDictionaries(dictionaries);\n\n const config = getConfiguration();\n setConfiguration(config);\n }, [setLocaleDictionaries]);\n\n /**\n * Click Messages\n */\n useIframeClickInterceptor();\n\n return <></>;\n};\n\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => (\n <EditorProvider\n postMessage={(data) => window.parent?.postMessage(data, '*')}\n allowedOrigins={['*']}\n >\n <IntlayerEditorProviderEnabled />\n {children}\n </EditorProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA6CS;AA3CT,oBAAiC;AACjC,gCAAyB;AACzB,0BAMO;AACP,mBAA2D;AAO3D,MAAM,gCAAoC,MAAM;AAI9C,gDAAqB,QAAW;AAAA,IAC9B,SAAS;AAAA,IACT,MAAM;AAAA,EACR,CAAC;AAKD,QAAM,EAAE,iBAAiB,QAAI,6CAAwB;AACrD,QAAM,EAAE,sBAAsB,QAAI,kDAA6B;AAE/D,8BAAU,MAAM;AACd,0BAAsB,0BAAAA,OAAY;AAElC,UAAM,aAAS,gCAAiB;AAChC,qBAAiB,MAAM;AAAA,EACzB,GAAG,CAAC,qBAAqB,CAAC;AAK1B,qDAA0B;AAE1B,SAAO,2EAAE;AACX;AAEO,MAAM,yBAAgD,CAAC,EAAE,SAAS,MACvE;AAAA,EAAC;AAAA;AAAA,IACC,aAAa,CAAC,SAAS,OAAO,QAAQ,YAAY,MAAM,GAAG;AAAA,IAC3D,gBAAgB,CAAC,GAAG;AAAA,IAEpB;AAAA,kDAAC,iCAA8B;AAAA,MAC9B;AAAA;AAAA;AACH;","names":["dictionaries"]}
|
|
@@ -16,12 +16,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var editor_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(editor_exports);
|
|
18
18
|
__reExport(editor_exports, require('./ContentSelectorWrapper.cjs'), module.exports);
|
|
19
|
-
__reExport(editor_exports, require('./ContentSelectorConnector.cjs'), module.exports);
|
|
20
19
|
__reExport(editor_exports, require('./renderContentEditor.cjs'), module.exports);
|
|
21
20
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
21
|
0 && (module.exports = {
|
|
23
22
|
...require('./ContentSelectorWrapper.cjs'),
|
|
24
|
-
...require('./ContentSelectorConnector.cjs'),
|
|
25
23
|
...require('./renderContentEditor.cjs')
|
|
26
24
|
});
|
|
27
25
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/index.ts"],"sourcesContent":["export * from './ContentSelectorWrapper';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/index.ts"],"sourcesContent":["export * from './ContentSelectorWrapper';\nexport * from './renderContentEditor';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,2BAAc,qCAAd;AACA,2BAAc,kCADd;","names":[]}
|
|
@@ -22,30 +22,10 @@ __export(renderContentEditor_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(renderContentEditor_exports);
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
const {
|
|
28
|
-
|
|
29
|
-
} = (0, import_client.getConfiguration)();
|
|
30
|
-
const IntlayerEditorElement = ({
|
|
31
|
-
content,
|
|
32
|
-
isContentSelectable,
|
|
33
|
-
...props
|
|
34
|
-
}) => {
|
|
35
|
-
if (enabled && isContentSelectable) {
|
|
36
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ContentSelectorConnector.ContentSelectorConnector, { ...props, children: content });
|
|
37
|
-
}
|
|
38
|
-
return content;
|
|
39
|
-
};
|
|
40
|
-
const renderIntlayerEditor = (data, isContentSelectable = true) => {
|
|
41
|
-
const Result = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
42
|
-
IntlayerEditorElement,
|
|
43
|
-
{
|
|
44
|
-
...data,
|
|
45
|
-
isContentSelectable
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
return { ...Result, value: data.content };
|
|
25
|
+
var import_ContentSelectorWrapper = require('./ContentSelectorWrapper.cjs');
|
|
26
|
+
const renderIntlayerEditor = (props) => {
|
|
27
|
+
const Result = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ContentSelectorWrapper.ContentSelectorWrapper, { ...props, children: props.content });
|
|
28
|
+
return { ...Result, value: props.content };
|
|
49
29
|
};
|
|
50
30
|
// Annotate the CommonJS export names for ESM import in node:
|
|
51
31
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport {\n ContentSelectorWrapper,\n type ContentSelectorWrapperProps,\n} from './ContentSelectorWrapper';\n\nexport type IntlayerNode<T = string> = ReactNode & {\n value: T;\n};\n\nexport type RenderIntlayerEditorProps = Omit<\n ContentSelectorWrapperProps,\n 'children'\n> & {\n content: string;\n};\n\nexport const renderIntlayerEditor = (\n props: RenderIntlayerEditorProps\n): IntlayerNode => {\n const Result = (\n <ContentSelectorWrapper {...props}>{props.content}</ContentSelectorWrapper>\n );\n\n return { ...Result, value: props.content };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBI;AApBJ,oCAGO;AAaA,MAAM,uBAAuB,CAClC,UACiB;AACjB,QAAM,SACJ,4CAAC,wDAAwB,GAAG,OAAQ,gBAAM,SAAQ;AAGpD,SAAO,EAAE,GAAG,QAAQ,OAAO,MAAM,QAAQ;AAC3C;","names":[]}
|
|
@@ -18,37 +18,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var getDictionary_exports = {};
|
|
20
20
|
__export(getDictionary_exports, {
|
|
21
|
-
getDictionary: () => getDictionary
|
|
22
|
-
recursiveTransformContent: () => recursiveTransformContent
|
|
21
|
+
getDictionary: () => getDictionary
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(getDictionary_exports);
|
|
25
|
-
var import_react = require("react");
|
|
26
|
-
var import_renderContentEditor = require('./editor/renderContentEditor.cjs');
|
|
27
24
|
var import_processDictionary = require('./processDictionary/index.cjs');
|
|
28
|
-
|
|
29
|
-
if (typeof value === "function") {
|
|
30
|
-
return (props) => recursiveTransformContent(value(props), isRenderEditor);
|
|
31
|
-
} else if (typeof value === "object") {
|
|
32
|
-
if (typeof value.dictionaryKey !== "undefined") {
|
|
33
|
-
if (isRenderEditor) {
|
|
34
|
-
return (0, import_renderContentEditor.renderIntlayerEditor)(value);
|
|
35
|
-
}
|
|
36
|
-
return value.content;
|
|
37
|
-
} else if (Array.isArray(value)) {
|
|
38
|
-
return value.map((el) => recursiveTransformContent(el, isRenderEditor));
|
|
39
|
-
} else if ((0, import_react.isValidElement)(value)) {
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
42
|
-
return Object.entries(value).reduce(
|
|
43
|
-
(acc, [key, value2]) => ({
|
|
44
|
-
...acc,
|
|
45
|
-
[key]: recursiveTransformContent(value2, isRenderEditor)
|
|
46
|
-
}),
|
|
47
|
-
{}
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
return value;
|
|
51
|
-
};
|
|
25
|
+
var import_recursiveTransformContent = require('./recursiveTransformContent.cjs');
|
|
52
26
|
const getDictionary = (dictionary, locale, isRenderEditor = false) => {
|
|
53
27
|
const result = (0, import_processDictionary.processDictionary)(
|
|
54
28
|
dictionary.content,
|
|
@@ -57,14 +31,13 @@ const getDictionary = (dictionary, locale, isRenderEditor = false) => {
|
|
|
57
31
|
[],
|
|
58
32
|
locale
|
|
59
33
|
);
|
|
60
|
-
return recursiveTransformContent(
|
|
34
|
+
return (0, import_recursiveTransformContent.recursiveTransformContent)(
|
|
61
35
|
result,
|
|
62
36
|
isRenderEditor
|
|
63
37
|
);
|
|
64
38
|
};
|
|
65
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
66
40
|
0 && (module.exports = {
|
|
67
|
-
getDictionary
|
|
68
|
-
recursiveTransformContent
|
|
41
|
+
getDictionary
|
|
69
42
|
});
|
|
70
43
|
//# sourceMappingURL=getDictionary.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { DeclarationContent, DictionaryValue } from '@intlayer/core';\nimport { processDictionary } from './processDictionary/index';\nimport {\n DeepTransformContent,\n recursiveTransformContent,\n} from './recursiveTransformContent';\n\ntype DataFromDictionary<\n T extends DeclarationContent,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<T['content'], K, R>;\n\nexport type UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor?: R,\n isContentSelectable?: boolean\n) => DataFromDictionary<T, L, R>;\n\n/**\n * Hook that picks one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getDictionary: UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const result = processDictionary(\n dictionary.content as DictionaryValue,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionary<T, L, R>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,+BAAkC;AAClC,uCAGO;AAwBA,MAAM,gBAA+B,CAK1C,YACA,QACA,iBAAoB,UACjB;AACH,QAAM,aAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,aAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/dist/cjs/getIntlayer.cjs
CHANGED
|
@@ -32,8 +32,8 @@ __export(getIntlayer_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(getIntlayer_exports);
|
|
34
34
|
var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
|
|
35
|
-
var import_getDictionary = require('./getDictionary.cjs');
|
|
36
35
|
var import_processDictionary = require('./processDictionary/index.cjs');
|
|
36
|
+
var import_recursiveTransformContent = require('./recursiveTransformContent.cjs');
|
|
37
37
|
const getIntlayer = (key, locale, isRenderEditor = false) => {
|
|
38
38
|
const dictionary = import_dictionaries_entry.default[key];
|
|
39
39
|
if (!dictionary) {
|
|
@@ -46,7 +46,7 @@ const getIntlayer = (key, locale, isRenderEditor = false) => {
|
|
|
46
46
|
[],
|
|
47
47
|
locale
|
|
48
48
|
);
|
|
49
|
-
return (0,
|
|
49
|
+
return (0, import_recursiveTransformContent.recursiveTransformContent)(
|
|
50
50
|
result,
|
|
51
51
|
isRenderEditor
|
|
52
52
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n/**\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 dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n/**\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 dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport { processDictionary } from './processDictionary/index';\nimport {\n type DeepTransformContent,\n recursiveTransformContent,\n} from './recursiveTransformContent';\n\n/**\n * Provides a fallback to string type if the generic type T is never,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'\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\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\n/**\n * Represents the data type returned by the useIntlayer hook,\n * excluding the 'id' and 'filePath' keys from the dictionary content.\n */\nexport type DataFromDictionaryKey<\n T extends DictionaryKeys,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K, R>;\n\n/**\n * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,\n * and returns the deeply transformed dictionary content.\n *\n */\nexport type UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R,\n isContentSelectable?: boolean\n) => DataFromDictionaryKey<T, L, R>;\n\nexport type UseIntlayerEditable = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R,\n isContentSelectable?: boolean\n) => DataFromDictionaryKey<T, L, R>;\n\nexport const getIntlayer: UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const dictionary: Dictionary = dictionaries[key as keyof typeof dictionaries];\n\n if (!dictionary) {\n throw new Error(`Dictionary ${key} not found`, dictionaries);\n }\n\n const result = processDictionary(\n dictionary.content,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionaryKey<T, L, R>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,gCAAyB;AAEzB,+BAAkC;AAClC,uCAGO;AA6DA,MAAM,cAA2B,CAKtC,KACA,QACA,iBAAoB,UACjB;AACH,QAAM,aAAyB,0BAAAA,QAAa,GAAgC;AAE5E,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,cAAc,GAAG,cAAc,0BAAAA,OAAY;AAAA,EAC7D;AAEA,QAAM,aAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,aAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["dictionaries"]}
|
|
@@ -22,10 +22,10 @@ __export(getIntlayerAsync_exports, {
|
|
|
22
22
|
getIntlayerAsync: () => getIntlayerAsync
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(getIntlayerAsync_exports);
|
|
25
|
-
var
|
|
25
|
+
var import_api = require("@intlayer/api");
|
|
26
26
|
var import_getDictionary = require('./getDictionary.cjs');
|
|
27
27
|
const getIntlayerAsync = async (key, locale, isRenderEditor = true) => {
|
|
28
|
-
const jsonDistantDictionary = await (0,
|
|
28
|
+
const jsonDistantDictionary = await (0, import_api.fetchDistantDictionary)(key);
|
|
29
29
|
if (jsonDistantDictionary) {
|
|
30
30
|
return (0, import_getDictionary.getDictionary)(
|
|
31
31
|
jsonDistantDictionary,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/getIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport { fetchDistantDictionary } from '@intlayer/api';\nimport type { Locales } from '@intlayer/config/client';\nimport { DeclarationContent } from 'intlayer';\nimport { getDictionary } from './getDictionary';\nimport { DictionaryKeys, DataFromDictionaryKey } from './getIntlayer';\n\nexport type GetIntlayerAsync = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => Promise<DataFromDictionaryKey<T, L, R> | null>;\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getIntlayerAsync: GetIntlayerAsync = async <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor = true as R\n) => {\n const jsonDistantDictionary = await fetchDistantDictionary(key);\n\n if (jsonDistantDictionary) {\n return getDictionary(\n jsonDistantDictionary as unknown as DeclarationContent,\n locale,\n isRenderEditor\n ) as DataFromDictionaryKey<T, L, R>;\n }\n\n return null;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAuC;AAGvC,2BAA8B;AAqBvB,MAAM,mBAAqC,OAKhD,KACA,QACA,iBAAiB,SACd;AACH,QAAM,wBAAwB,UAAM,mCAAuB,GAAG;AAE9D,MAAI,uBAAuB;AACzB,eAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|