react-intlayer 4.0.3 → 4.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/UI/ContentSelector.cjs +2 -2
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs +11 -5
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/PoweredByMeta.cjs +9 -4
- package/dist/cjs/client/PoweredByMeta.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +13 -3
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +61 -7
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/renderContentEditor.cjs +3 -23
- 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 +2 -2
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +13 -8
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/PoweredByMeta.mjs +9 -4
- package/dist/esm/client/PoweredByMeta.mjs.map +1 -1
- package/dist/esm/client/index.mjs +10 -10
- package/dist/esm/client/t.mjs +2 -2
- package/dist/esm/client/useContent.mjs +2 -2
- package/dist/esm/client/useDictionary.mjs +2 -2
- package/dist/esm/client/useIntlayer.mjs +2 -2
- package/dist/esm/client/useIntlayerAsync.mjs +3 -3
- package/dist/esm/client/useLocale.mjs +2 -2
- package/dist/esm/client/useLocaleBase.mjs +1 -1
- package/dist/esm/client/useTraduction.mjs +2 -2
- package/dist/esm/editor/ContentSelectorWrapper.mjs +19 -8
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +60 -9
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +2 -2
- 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 +2 -2
- package/dist/esm/getIntlayerAsync.mjs.map +1 -1
- package/dist/esm/index.mjs +4 -4
- package/dist/esm/processDictionary/index.mjs +2 -2
- package/dist/esm/recursiveTransformContent.mjs +32 -0
- package/dist/esm/recursiveTransformContent.mjs.map +1 -0
- package/dist/esm/server/IntlayerServerProvider.mjs +1 -1
- package/dist/esm/server/getLocaleTranslation.mjs +2 -2
- package/dist/esm/server/index.mjs +6 -6
- package/dist/esm/server/t.mjs +3 -3
- package/dist/esm/server/useDictionary.mjs +3 -3
- package/dist/esm/server/useIntlayer.mjs +3 -3
- package/dist/esm/server/useTraduction.mjs +3 -3
- package/dist/types/client/IntlayerProvider.d.ts +0 -3
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/PoweredByMeta.d.ts.map +1 -1
- 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/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 -15
- package/dist/cjs/UI/PressableSpan/index.cjs +0 -23
- package/dist/cjs/UI/PressableSpan/index.cjs.map +0 -1
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +0 -59
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +0 -1
- package/dist/esm/UI/PressableSpan/index.mjs +0 -2
- package/dist/esm/UI/PressableSpan/index.mjs.map +0 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +0 -35
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +0 -1
- package/dist/types/UI/PressableSpan/index.d.ts +0 -2
- package/dist/types/UI/PressableSpan/index.d.ts.map +0 -1
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +0 -6
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +0 -1
|
@@ -24,7 +24,7 @@ __export(ContentSelector_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(ContentSelector_exports);
|
|
25
25
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
26
|
var import_react = require("react");
|
|
27
|
-
const DEFAULT_PRESS_DETECT_DURATION =
|
|
27
|
+
const DEFAULT_PRESS_DETECT_DURATION = 250;
|
|
28
28
|
const ContentSelector = ({
|
|
29
29
|
children,
|
|
30
30
|
onPress: onSelect,
|
|
@@ -99,7 +99,7 @@ const ContentSelector = ({
|
|
|
99
99
|
outlineOffset: "4px",
|
|
100
100
|
outlineStyle: "solid",
|
|
101
101
|
outlineColor: isSelectingProp || isSelectingState || isHovered ? "inherit" : "transparent",
|
|
102
|
-
transition: "all
|
|
102
|
+
transition: "all 100ms 50ms ease-in-out"
|
|
103
103
|
},
|
|
104
104
|
role: "button",
|
|
105
105
|
tabIndex: 0,
|
|
@@ -1 +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 =
|
|
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 = 250;\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 100ms 50ms 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,kBAAk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AAc;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":[]}
|
|
@@ -26,23 +26,25 @@ __export(IntlayerProvider_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(IntlayerProvider_exports);
|
|
27
27
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
28
|
var import_client = require("@intlayer/config/client");
|
|
29
|
+
var import_editor_react = require("@intlayer/editor-react");
|
|
29
30
|
var import_react = require("react");
|
|
30
|
-
var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
31
31
|
var import_IntlayerEditorProvider = require('../editor/IntlayerEditorProvider.cjs');
|
|
32
32
|
var import_PoweredByMeta = require('./PoweredByMeta.cjs');
|
|
33
|
+
var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
33
34
|
const IntlayerClientContext = (0, import_react.createContext)({
|
|
34
35
|
locale: import_useLocaleCookie.localeCookie ?? (0, import_client.getConfiguration)().internationalization.defaultLocale,
|
|
35
36
|
setLocale: () => null
|
|
36
37
|
});
|
|
37
38
|
const useIntlayerContext = () => (0, import_react.useContext)(IntlayerClientContext);
|
|
38
|
-
const
|
|
39
|
+
const IntlayerProviderContent = ({
|
|
39
40
|
locale,
|
|
40
41
|
children,
|
|
41
42
|
setLocale: setLocaleProp
|
|
42
43
|
}) => {
|
|
43
44
|
const { internationalization } = (0, import_client.getConfiguration)();
|
|
44
45
|
const { defaultLocale, locales: availableLocales } = internationalization;
|
|
45
|
-
const [currentLocale, setCurrentLocale] = (0,
|
|
46
|
+
const [currentLocale, setCurrentLocale] = (0, import_editor_react.useCrossFrameState)(
|
|
47
|
+
"INTLAYER_CURRENT_LOCALE",
|
|
46
48
|
locale ?? import_useLocaleCookie.localeCookie ?? defaultLocale
|
|
47
49
|
);
|
|
48
50
|
const setLocaleBase = (0, import_react.useCallback)(
|
|
@@ -57,16 +59,20 @@ const IntlayerProvider = ({
|
|
|
57
59
|
},
|
|
58
60
|
[availableLocales, currentLocale, locale]
|
|
59
61
|
);
|
|
60
|
-
const setLocale =
|
|
62
|
+
const setLocale = (0, import_react.useMemo)(
|
|
63
|
+
() => setLocaleProp ?? setLocaleBase,
|
|
64
|
+
[setLocaleProp, setLocaleBase]
|
|
65
|
+
);
|
|
61
66
|
const value = (0, import_react.useMemo)(
|
|
62
67
|
() => ({ locale: currentLocale, setLocale }),
|
|
63
68
|
[currentLocale, setLocale]
|
|
64
69
|
);
|
|
65
70
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(IntlayerClientContext.Provider, { value, children: [
|
|
66
71
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_PoweredByMeta.PoweredByMeta, {}),
|
|
67
|
-
|
|
72
|
+
children
|
|
68
73
|
] });
|
|
69
74
|
};
|
|
75
|
+
const IntlayerProvider = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_IntlayerEditorProvider.IntlayerEditorProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlayerProviderContent, { ...props }) });
|
|
70
76
|
// Annotate the CommonJS export names for ESM import in node:
|
|
71
77
|
0 && (module.exports = {
|
|
72
78
|
IntlayerClientContext,
|
|
@@ -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 {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport { useCrossFrameState } from '@intlayer/editor-react';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { PoweredByMeta } from './PoweredByMeta';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\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 */\nconst IntlayerProviderContent: 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] = useCrossFrameState(\n 'INTLAYER_CURRENT_LOCALE',\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 = useMemo(\n () => setLocaleProp ?? setLocaleBase,\n [setLocaleProp, setLocaleBase]\n );\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <PoweredByMeta />\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\nexport const IntlayerProvider: FC<IntlayerProviderProps> = (props) => (\n <IntlayerEditorProvider>\n <IntlayerProviderContent {...props} />\n </IntlayerEditorProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkFI;AAhFJ,oBAA+C;AAC/C,0BAAmC;AACnC,mBAQO;AACP,oCAAuC;AACvC,2BAA8B;AAC9B,6BAA8C;AAUvC,MAAM,4BAAwB,4BAA6B;AAAA,EAChE,QAAQ,2CAAgB,gCAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,UAAM,yBAAW,qBAAqB;AAUxE,MAAM,0BAAqD,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;AAAA,IACA,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,gBAAY;AAAA,IAChB,MAAM,iBAAiB;AAAA,IACvB,CAAC,eAAe,aAAa;AAAA,EAC/B;AAEA,QAAM,YAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAU;AAAA,IAC1C,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,6CAAC,sBAAsB,UAAtB,EAA+B,OAC9B;AAAA,gDAAC,sCAAc;AAAA,IACd;AAAA,KACH;AAEJ;AAEO,MAAM,mBAA8C,CAAC,UAC1D,4CAAC,wDACC,sDAAC,2BAAyB,GAAG,OAAO,GACtC;","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
|
};
|
|
@@ -1 +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 const metaTag = document.createElement('meta');\n
|
|
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":[]}
|
|
@@ -24,10 +24,10 @@ __export(ContentSelectorWrapper_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(ContentSelectorWrapper_exports);
|
|
25
25
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
26
|
var import_core = require("@intlayer/core");
|
|
27
|
-
var import_react = require("react");
|
|
28
27
|
var import_editor_react = require("@intlayer/editor-react");
|
|
28
|
+
var import_react = require("react");
|
|
29
29
|
var import_ContentSelector = require('../UI/ContentSelector.cjs');
|
|
30
|
-
const
|
|
30
|
+
const ContentSelectorWrapperContent = ({
|
|
31
31
|
children,
|
|
32
32
|
dictionaryKey,
|
|
33
33
|
dictionaryPath,
|
|
@@ -50,7 +50,7 @@ const ContentSelectorWrapper = ({
|
|
|
50
50
|
[dictionaryKey, dictionaryPath, keyPath, setFocusedContent]
|
|
51
51
|
);
|
|
52
52
|
const isSelected = (0, import_react.useMemo)(
|
|
53
|
-
() => ((focusedContent?.keyPath?.length ?? 0) > 0 && (0, import_core.isSameKeyPath)(focusedContent?.keyPath ?? [], keyPath)) ?? false,
|
|
53
|
+
() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && (0, import_core.isSameKeyPath)(focusedContent?.keyPath ?? [], keyPath)) ?? false,
|
|
54
54
|
[focusedContent, keyPath]
|
|
55
55
|
);
|
|
56
56
|
(0, import_react.useEffect)(() => {
|
|
@@ -62,6 +62,16 @@ const ContentSelectorWrapper = ({
|
|
|
62
62
|
}, [editedValue, focusedContent, children]);
|
|
63
63
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ContentSelector.ContentSelector, { onPress: handleSelect, isSelecting: isSelected, ...props, children: displayedChildren });
|
|
64
64
|
};
|
|
65
|
+
const ContentSelectorWrapper = ({
|
|
66
|
+
children,
|
|
67
|
+
...props
|
|
68
|
+
}) => {
|
|
69
|
+
const { enabled } = (0, import_editor_react.useEditorEnabled)();
|
|
70
|
+
if (enabled) {
|
|
71
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContentSelectorWrapperContent, { ...props, children });
|
|
72
|
+
}
|
|
73
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
74
|
+
};
|
|
65
75
|
// Annotate the CommonJS export names for ESM import in node:
|
|
66
76
|
0 && (module.exports = {
|
|
67
77
|
ContentSelectorWrapper
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { isSameKeyPath, type KeyPath } from '@intlayer/core';\nimport {\n useCallback,\n useEffect,\n useState,\n useMemo,\n type FC,\n type ReactNode,\n HTMLAttributes,\n} from 'react';\nimport {
|
|
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\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n dictionaryPath,\n keyPath,\n ...props\n}) => {\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 return (\n <ContentSelector onPress={handleSelect} isSelecting={isSelected} {...props}>\n {displayedChildren}\n </ContentSelector>\n );\n};\n\nexport const ContentSelectorWrapper: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n\n if (enabled) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return <>{children}</>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2EI;AAzEJ,kBAA4C;AAC5C,0B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
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, {
|
|
@@ -23,15 +34,58 @@ __export(IntlayerEditorProvider_exports, {
|
|
|
23
34
|
module.exports = __toCommonJS(IntlayerEditorProvider_exports);
|
|
24
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
36
|
var import_client = require("@intlayer/config/client");
|
|
37
|
+
var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
|
|
26
38
|
var import_editor_react = require("@intlayer/editor-react");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
const IntlayerEditorHooksEnabled = () => {
|
|
41
|
+
(0, import_editor_react.useCrossURLPathState)(void 0, {
|
|
42
|
+
receive: false,
|
|
43
|
+
emit: true
|
|
44
|
+
});
|
|
45
|
+
const [, setConfiguration] = (0, import_editor_react.useConfigurationState)();
|
|
46
|
+
(0, import_react.useEffect)(() => {
|
|
47
|
+
const config = (0, import_client.getConfiguration)();
|
|
48
|
+
setConfiguration(config);
|
|
49
|
+
}, [setConfiguration]);
|
|
50
|
+
const { setLocaleDictionaries } = (0, import_editor_react.useDictionariesRecordActions)();
|
|
51
|
+
(0, import_react.useEffect)(() => {
|
|
52
|
+
setLocaleDictionaries(import_dictionaries_entry.default);
|
|
53
|
+
}, [setLocaleDictionaries]);
|
|
54
|
+
(0, import_editor_react.useIframeClickInterceptor)();
|
|
55
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
|
|
56
|
+
};
|
|
57
|
+
const IntlayerEditorHook = () => {
|
|
58
|
+
const { enabled } = (0, import_editor_react.useEditorEnabled)();
|
|
59
|
+
return enabled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlayerEditorHooksEnabled, {}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
|
|
60
|
+
};
|
|
30
61
|
const IntlayerEditorProvider = ({ children }) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
62
|
+
const { editor } = (0, import_client.getConfiguration)();
|
|
63
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
64
|
+
import_editor_react.EditorProvider,
|
|
65
|
+
{
|
|
66
|
+
postMessage: (data) => {
|
|
67
|
+
if (typeof window === "undefined") return;
|
|
68
|
+
window?.postMessage(
|
|
69
|
+
data,
|
|
70
|
+
// Use to restrict the origin of the editor for security reasons.
|
|
71
|
+
// Correspond to the current application URL to synchronize the locales states.
|
|
72
|
+
editor.applicationURL
|
|
73
|
+
);
|
|
74
|
+
window.parent?.postMessage(
|
|
75
|
+
data,
|
|
76
|
+
// Use to restrict the origin of the editor for security reasons.
|
|
77
|
+
// Correspond to the current editor URL.
|
|
78
|
+
editor.editorURL
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
allowedOrigins: [editor.editorURL, editor.applicationURL],
|
|
82
|
+
mode: "client",
|
|
83
|
+
children: [
|
|
84
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlayerEditorHook, {}),
|
|
85
|
+
children
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
);
|
|
35
89
|
};
|
|
36
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
91
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\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 {\n EditorProvider,\n useCrossURLPathState,\n useDictionariesRecordActions,\n useConfigurationState,\n useIframeClickInterceptor,\n useEditorEnabled,\n} from '@intlayer/editor-react';\nimport { useEffect, type FC, type PropsWithChildren } from 'react';\n\nconst IntlayerEditorHooksEnabled: 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] = useConfigurationState();\n\n useEffect(() => {\n const config = getConfiguration();\n setConfiguration(config);\n }, [setConfiguration]);\n\n /**\n * Locale Dictionaries Messages\n */\n const { setLocaleDictionaries } = useDictionariesRecordActions();\n\n useEffect(() => {\n setLocaleDictionaries(dictionaries);\n }, [setLocaleDictionaries]);\n\n /**\n * Click Messages\n */\n useIframeClickInterceptor();\n\n return <></>;\n};\n\nconst IntlayerEditorHook: FC = () => {\n const { enabled } = useEditorEnabled();\n\n return enabled ? <IntlayerEditorHooksEnabled /> : <></>;\n};\n\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => {\n const { editor } = getConfiguration();\n\n return (\n <EditorProvider\n postMessage={(data: any) => {\n if (typeof window === 'undefined') return;\n\n window?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the current application URL to synchronize the locales states.\n editor.applicationURL\n );\n window.parent?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the current editor URL.\n editor.editorURL\n );\n }}\n allowedOrigins={[editor.editorURL, editor.applicationURL]}\n mode=\"client\"\n >\n <IntlayerEditorHook />\n {children}\n </EditorProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsDS;AAlDT,oBAAiC;AAMjC,gCAAyB;AACzB,0BAOO;AACP,mBAA2D;AAE3D,MAAM,6BAAiC,MAAM;AAI3C,gDAAqB,QAAW;AAAA,IAC9B,SAAS;AAAA,IACT,MAAM;AAAA,EACR,CAAC;AAKD,QAAM,CAAC,EAAE,gBAAgB,QAAI,2CAAsB;AAEnD,8BAAU,MAAM;AACd,UAAM,aAAS,gCAAiB;AAChC,qBAAiB,MAAM;AAAA,EACzB,GAAG,CAAC,gBAAgB,CAAC;AAKrB,QAAM,EAAE,sBAAsB,QAAI,kDAA6B;AAE/D,8BAAU,MAAM;AACd,0BAAsB,0BAAAA,OAAY;AAAA,EACpC,GAAG,CAAC,qBAAqB,CAAC;AAK1B,qDAA0B;AAE1B,SAAO,2EAAE;AACX;AAEA,MAAM,qBAAyB,MAAM;AACnC,QAAM,EAAE,QAAQ,QAAI,sCAAiB;AAErC,SAAO,UAAU,4CAAC,8BAA2B,IAAK,2EAAE;AACtD;AAEO,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,QAAM,EAAE,OAAO,QAAI,gCAAiB;AAEpC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAa,CAAC,SAAc;AAC1B,YAAI,OAAO,WAAW,YAAa;AAEnC,gBAAQ;AAAA,UACN;AAAA;AAAA;AAAA,UAGA,OAAO;AAAA,QACT;AACA,eAAO,QAAQ;AAAA,UACb;AAAA;AAAA;AAAA,UAGA,OAAO;AAAA,QACT;AAAA,MACF;AAAA,MACA,gBAAgB,CAAC,OAAO,WAAW,OAAO,cAAc;AAAA,MACxD,MAAK;AAAA,MAEL;AAAA,oDAAC,sBAAmB;AAAA,QACnB;AAAA;AAAA;AAAA,EACH;AAEJ;","names":["dictionaries"]}
|
|
@@ -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 import_client = require("@intlayer/config/client");
|
|
26
25
|
var import_ContentSelectorWrapper = require('./ContentSelectorWrapper.cjs');
|
|
27
|
-
const {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const IntlayerEditorElement = ({
|
|
31
|
-
content,
|
|
32
|
-
isContentSelectable,
|
|
33
|
-
...props
|
|
34
|
-
}) => {
|
|
35
|
-
if (enabled && isContentSelectable) {
|
|
36
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ContentSelectorWrapper.ContentSelectorWrapper, { ...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 };
|
|
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":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
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, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var recursiveTransformContent_exports = {};
|
|
20
|
+
__export(recursiveTransformContent_exports, {
|
|
21
|
+
recursiveTransformContent: () => recursiveTransformContent
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(recursiveTransformContent_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
var import_renderContentEditor = require('./editor/renderContentEditor.cjs');
|
|
26
|
+
const recursiveTransformContent = (value, isRenderEditor = false) => {
|
|
27
|
+
if (typeof value === "function") {
|
|
28
|
+
return (props) => recursiveTransformContent(value(props), isRenderEditor);
|
|
29
|
+
} else if (typeof value === "object") {
|
|
30
|
+
if (typeof value.dictionaryKey !== "undefined") {
|
|
31
|
+
if (isRenderEditor) {
|
|
32
|
+
return (0, import_renderContentEditor.renderIntlayerEditor)(value);
|
|
33
|
+
}
|
|
34
|
+
return value.content;
|
|
35
|
+
} else if (Array.isArray(value)) {
|
|
36
|
+
return value.map((el) => recursiveTransformContent(el, isRenderEditor));
|
|
37
|
+
} else if ((0, import_react.isValidElement)(value)) {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
return Object.entries(value).reduce(
|
|
41
|
+
(acc, [key, value2]) => ({
|
|
42
|
+
...acc,
|
|
43
|
+
[key]: recursiveTransformContent(value2, isRenderEditor)
|
|
44
|
+
}),
|
|
45
|
+
{}
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
};
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
recursiveTransformContent
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=recursiveTransformContent.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/recursiveTransformContent.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Locales } from '@intlayer/config';\nimport type { NodeType } from '@intlayer/core';\nimport { isValidElement, type ReactNode } from 'react';\nimport {\n type IntlayerNode,\n renderIntlayerEditor,\n} from './editor/renderContentEditor';\n\ntype TransformNodeType<T, L extends Locales, R extends boolean> = T extends {\n [NodeType.Enumeration]: { '1': any };\n}\n ? (\n quantity: number\n ) => DeepTransformContent<T[NodeType.Enumeration]['1'], L, R>\n : T extends {\n [NodeType.Translation]: object;\n }\n ? L extends keyof T[NodeType.Translation]\n ? DeepTransformContent<T[NodeType.Translation][L], L, R>\n : never\n : T;\n\nexport type DeepTransformContent<\n T,\n L extends Locales,\n R extends boolean,\n> = T extends object // Check if the property is an object\n ? T extends (infer U)[] // If it's an array, infer the type of array elements\n ? DeepTransformContent<U, L, R>[] // Apply DeepTransformContent recursively to each element of the array\n : T extends {\n nodeType: NodeType | string;\n }\n ? TransformNodeType<T, L, R>\n : T extends { _owner: any; key: any; props: any; ref: any }\n ? ReactNode\n : {\n [K in keyof T]: DeepTransformContent<T[K], L, R>;\n }\n : T extends undefined\n ? never\n : R extends true\n ? IntlayerNode<T>\n : T;\n\n/**\n * Go through the object. If a object has a keyPath, render the intlayer editor if editor enabled.\n */\nexport const recursiveTransformContent = (\n value: any,\n isRenderEditor = false\n): object => {\n if (typeof value === 'function') {\n return (props: any) =>\n recursiveTransformContent(value(props), isRenderEditor);\n } else if (typeof value === 'object') {\n if (typeof value.dictionaryKey !== 'undefined') {\n if (isRenderEditor) {\n return renderIntlayerEditor(value);\n }\n return value.content;\n } else if (Array.isArray(value)) {\n return value.map((el) => recursiveTransformContent(el, isRenderEditor));\n } else if (isValidElement(value)) {\n return value;\n }\n\n return Object.entries(value).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: recursiveTransformContent(value, isRenderEditor),\n }),\n {} as object\n );\n }\n\n return value;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA+C;AAC/C,iCAGO;AAyCA,MAAM,4BAA4B,CACvC,OACA,iBAAiB,UACN;AACX,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,CAAC,UACN,0BAA0B,MAAM,KAAK,GAAG,cAAc;AAAA,EAC1D,WAAW,OAAO,UAAU,UAAU;AACpC,QAAI,OAAO,MAAM,kBAAkB,aAAa;AAC9C,UAAI,gBAAgB;AAClB,mBAAO,iDAAqB,KAAK;AAAA,MACnC;AACA,aAAO,MAAM;AAAA,IACf,WAAW,MAAM,QAAQ,KAAK,GAAG;AAC/B,aAAO,MAAM,IAAI,CAAC,OAAO,0BAA0B,IAAI,cAAc,CAAC;AAAA,IACxE,eAAW,6BAAe,KAAK,GAAG;AAChC,aAAO;AAAA,IACT;AAEA,WAAO,OAAO,QAAQ,KAAK,EAAE;AAAA,MAC3B,CAAC,KAAK,CAAC,KAAKA,MAAK,OAAO;AAAA,QACtB,GAAG;AAAA,QACH,CAAC,GAAG,GAAG,0BAA0BA,QAAO,cAAc;AAAA,MACxD;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":["value"]}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
useRef,
|
|
7
7
|
useCallback
|
|
8
8
|
} from "react";
|
|
9
|
-
const DEFAULT_PRESS_DETECT_DURATION =
|
|
9
|
+
const DEFAULT_PRESS_DETECT_DURATION = 250;
|
|
10
10
|
const ContentSelector = ({
|
|
11
11
|
children,
|
|
12
12
|
onPress: onSelect,
|
|
@@ -81,7 +81,7 @@ const ContentSelector = ({
|
|
|
81
81
|
outlineOffset: "4px",
|
|
82
82
|
outlineStyle: "solid",
|
|
83
83
|
outlineColor: isSelectingProp || isSelectingState || isHovered ? "inherit" : "transparent",
|
|
84
|
-
transition: "all
|
|
84
|
+
transition: "all 100ms 50ms ease-in-out"
|
|
85
85
|
},
|
|
86
86
|
role: "button",
|
|
87
87
|
tabIndex: 0,
|
|
@@ -1 +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 =
|
|
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 = 250;\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 100ms 50ms 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":";AAqGI;AAnGJ;AAAA,EACE;A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