react-intlayer 4.0.3 → 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.
Files changed (58) hide show
  1. package/dist/cjs/client/PoweredByMeta.cjs +9 -4
  2. package/dist/cjs/client/PoweredByMeta.cjs.map +1 -1
  3. package/dist/cjs/editor/ContentSelectorWrapper.cjs +15 -3
  4. package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
  5. package/dist/cjs/editor/IntlayerEditorProvider.cjs +38 -8
  6. package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
  7. package/dist/cjs/editor/renderContentEditor.cjs +3 -23
  8. package/dist/cjs/editor/renderContentEditor.cjs.map +1 -1
  9. package/dist/cjs/getDictionary.cjs +4 -31
  10. package/dist/cjs/getDictionary.cjs.map +1 -1
  11. package/dist/cjs/getIntlayer.cjs +2 -2
  12. package/dist/cjs/getIntlayer.cjs.map +1 -1
  13. package/dist/cjs/getIntlayerAsync.cjs +2 -2
  14. package/dist/cjs/getIntlayerAsync.cjs.map +1 -1
  15. package/dist/cjs/recursiveTransformContent.cjs +54 -0
  16. package/dist/cjs/recursiveTransformContent.cjs.map +1 -0
  17. package/dist/esm/client/PoweredByMeta.mjs +9 -4
  18. package/dist/esm/client/PoweredByMeta.mjs.map +1 -1
  19. package/dist/esm/editor/ContentSelectorWrapper.mjs +20 -7
  20. package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
  21. package/dist/esm/editor/IntlayerEditorProvider.mjs +36 -10
  22. package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
  23. package/dist/esm/editor/renderContentEditor.mjs +6 -24
  24. package/dist/esm/editor/renderContentEditor.mjs.map +1 -1
  25. package/dist/esm/getDictionary.mjs +4 -30
  26. package/dist/esm/getDictionary.mjs.map +1 -1
  27. package/dist/esm/getIntlayer.mjs +2 -2
  28. package/dist/esm/getIntlayer.mjs.map +1 -1
  29. package/dist/esm/getIntlayerAsync.mjs +1 -1
  30. package/dist/esm/getIntlayerAsync.mjs.map +1 -1
  31. package/dist/esm/recursiveTransformContent.mjs +32 -0
  32. package/dist/esm/recursiveTransformContent.mjs.map +1 -0
  33. package/dist/types/client/PoweredByMeta.d.ts.map +1 -1
  34. package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
  35. package/dist/types/editor/IntlayerEditorProvider.d.ts +1 -1
  36. package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
  37. package/dist/types/editor/renderContentEditor.d.ts +5 -9
  38. package/dist/types/editor/renderContentEditor.d.ts.map +1 -1
  39. package/dist/types/getDictionary.d.ts +3 -25
  40. package/dist/types/getDictionary.d.ts.map +1 -1
  41. package/dist/types/getIntlayer.d.ts +3 -3
  42. package/dist/types/getIntlayer.d.ts.map +1 -1
  43. package/dist/types/getIntlayerAsync.d.ts.map +1 -1
  44. package/dist/types/recursiveTransformContent.d.ts +27 -0
  45. package/dist/types/recursiveTransformContent.d.ts.map +1 -0
  46. package/package.json +15 -14
  47. package/dist/cjs/UI/PressableSpan/index.cjs +0 -23
  48. package/dist/cjs/UI/PressableSpan/index.cjs.map +0 -1
  49. package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +0 -59
  50. package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +0 -1
  51. package/dist/esm/UI/PressableSpan/index.mjs +0 -2
  52. package/dist/esm/UI/PressableSpan/index.mjs.map +0 -1
  53. package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +0 -35
  54. package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +0 -1
  55. package/dist/types/UI/PressableSpan/index.d.ts +0 -2
  56. package/dist/types/UI/PressableSpan/index.d.ts.map +0 -1
  57. package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +0 -6
  58. package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +0 -1
@@ -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 metaTag = document.createElement("meta");
30
- metaTag.name = "content-powered-by";
31
- metaTag.content = "Intlayer - https://intlayer.org";
32
- document.head.appendChild(metaTag);
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 metaTag.name = 'content-powered-by';\n metaTag.content = 'Intlayer - https://intlayer.org';\n document.head.appendChild(metaTag);\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;AACd,UAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,YAAQ,OAAO;AACf,YAAQ,UAAU;AAClB,aAAS,KAAK,YAAY,OAAO;AAAA,EACnC,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
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,8 +24,8 @@ __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
30
  const ContentSelectorWrapper = ({
31
31
  children,
@@ -34,6 +34,7 @@ const ContentSelectorWrapper = ({
34
34
  keyPath,
35
35
  ...props
36
36
  }) => {
37
+ const { enabled } = (0, import_editor_react.useEditorEnabled)();
37
38
  const { focusedContent, setFocusedContent } = (0, import_editor_react.useFocusDictionary)();
38
39
  const { getEditedContentValue } = (0, import_editor_react.useEditedContentActions)();
39
40
  const editedValue = (0, import_react.useMemo)(
@@ -50,7 +51,7 @@ const ContentSelectorWrapper = ({
50
51
  [dictionaryKey, dictionaryPath, keyPath, setFocusedContent]
51
52
  );
52
53
  const isSelected = (0, import_react.useMemo)(
53
- () => ((focusedContent?.keyPath?.length ?? 0) > 0 && (0, import_core.isSameKeyPath)(focusedContent?.keyPath ?? [], keyPath)) ?? false,
54
+ () => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && (0, import_core.isSameKeyPath)(focusedContent?.keyPath ?? [], keyPath)) ?? false,
54
55
  [focusedContent, keyPath]
55
56
  );
56
57
  (0, import_react.useEffect)(() => {
@@ -60,7 +61,18 @@ const ContentSelectorWrapper = ({
60
61
  setDisplayedChildren(children);
61
62
  }
62
63
  }, [editedValue, focusedContent, children]);
63
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ContentSelector.ContentSelector, { onPress: handleSelect, isSelecting: isSelected, ...props, children: displayedChildren });
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 });
64
76
  };
65
77
  // Annotate the CommonJS export names for ESM import in node:
66
78
  0 && (module.exports = {
@@ -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 {\n useFocusDictionary,\n useEditedContentActions,\n} from '@intlayer/editor-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 { 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?.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"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyEI;AAvEJ,kBAA4C;AAC5C,mBAQO;AACP,0BAGO;AACP,6BAAgC;AAWzB,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,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,QACI,gBAAgB,SAAS,UAAU,KAAK,SACxC,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,SACE,4CAAC,0CAAgB,SAAS,cAAc,aAAa,YAAa,GAAG,OAClE,6BACH;AAEJ;","names":[]}
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, {
@@ -23,16 +34,35 @@ __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
- const {
28
- editor: { enabled }
29
- } = (0, import_client.getConfiguration)();
30
- const IntlayerEditorProvider = ({ children }) => {
31
- if (enabled) {
32
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_editor_react.EditorProvider, { targetWindow: window, children });
33
- }
34
- return children;
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, {});
35
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
+ );
36
66
  // Annotate the CommonJS export names for ESM import in node:
37
67
  0 && (module.exports = {
38
68
  IntlayerEditorProvider
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["import { FC, PropsWithChildren } from 'react';\nimport { getConfiguration } from '@intlayer/config/client';\nimport { EditorProvider } from '@intlayer/editor-react';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => {\n if (enabled) {\n return <EditorProvider targetWindow={window}>{children}</EditorProvider>;\n }\n\n return children;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUW;AATX,oBAAiC;AACjC,0BAA+B;AAE/B,MAAM;AAAA,EACJ,QAAQ,EAAE,QAAQ;AACpB,QAAI,gCAAiB;AAEd,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,MAAI,SAAS;AACX,WAAO,4CAAC,sCAAe,cAAc,QAAS,UAAS;AAAA,EACzD;AAEA,SAAO;AACT;","names":[]}
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"]}
@@ -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
- editor: { enabled }
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_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 { getConfiguration } from '@intlayer/config/client';\nimport type { KeyPath } from '@intlayer/core';\nimport type { FC, ReactNode } from 'react';\nimport { ContentSelectorWrapper } from './ContentSelectorWrapper';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nexport type IntlayerEditorElementProps = {\n content: string;\n dictionaryKey: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n isContentSelectable: boolean;\n};\n\nconst IntlayerEditorElement: FC<IntlayerEditorElementProps> = ({\n content,\n isContentSelectable,\n ...props\n}) => {\n if (enabled && isContentSelectable) {\n return (\n <ContentSelectorWrapper {...props}>{content}</ContentSelectorWrapper>\n );\n }\n return content;\n};\n\nexport type IntlayerNode<T = string> = ReactNode & {\n value: T;\n};\n\nexport const renderIntlayerEditor = (\n data: IntlayerEditorElementProps,\n isContentSelectable = true\n): IntlayerNode => {\n const Result = (\n <IntlayerEditorElement\n {...data}\n isContentSelectable={isContentSelectable}\n />\n );\n\n return { ...Result, value: data.content };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBM;AAxBN,oBAAiC;AAGjC,oCAAuC;AAEvC,MAAM;AAAA,EACJ,QAAQ,EAAE,QAAQ;AACpB,QAAI,gCAAiB;AAUrB,MAAM,wBAAwD,CAAC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,MAAI,WAAW,qBAAqB;AAClC,WACE,4CAAC,wDAAwB,GAAG,OAAQ,mBAAQ;AAAA,EAEhD;AACA,SAAO;AACT;AAMO,MAAM,uBAAuB,CAClC,MACA,sBAAsB,SACL;AACjB,QAAM,SACJ;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA;AAAA,EACF;AAGF,SAAO,EAAE,GAAG,QAAQ,OAAO,KAAK,QAAQ;AAC1C;","names":[]}
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
- const recursiveTransformContent = (value, isRenderEditor = false) => {
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":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Locales } from '@intlayer/config';\nimport type {\n DeclarationContent,\n DictionaryValue,\n NodeType,\n} from '@intlayer/core';\nimport { isValidElement, type ReactNode } from 'react';\nimport {\n type IntlayerNode,\n renderIntlayerEditor,\n} from './editor/renderContentEditor';\nimport { processDictionary } from './processDictionary/index';\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\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) => 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;AAAA;AAOA,mBAA+C;AAC/C,iCAGO;AACP,+BAAkC;AAyC3B,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;AAuBO,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,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["value"]}
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":[]}
@@ -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, import_getDictionary.recursiveTransformContent)(
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 {\n type DeepTransformContent,\n recursiveTransformContent,\n} from './getDictionary';\nimport { processDictionary } from './processDictionary/index';\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) => 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) => 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,2BAGO;AACP,+BAAkC;AA2D3B,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"]}
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 import_fetchDistantDictionary = require('./distantDictionary/fetchDistantDictionary.cjs');
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, import_fetchDistantDictionary.fetchDistantDictionary)(key);
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 type { Locales } from '@intlayer/config/client';\nimport { DeclarationContent } from 'intlayer';\nimport { fetchDistantDictionary } from './distantDictionary/fetchDistantDictionary';\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;AAIA,oCAAuC;AACvC,2BAA8B;AAqBvB,MAAM,mBAAqC,OAKhD,KACA,QACA,iBAAiB,SACd;AACH,QAAM,wBAAwB,UAAM,sDAAuB,GAAG;AAE9D,MAAI,uBAAuB;AACzB,eAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
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"]}
@@ -3,10 +3,15 @@ import { useEffect } from "react";
3
3
  const PoweredByMeta = () => {
4
4
  if (process.env.NODE_ENV !== "production") return null;
5
5
  useEffect(() => {
6
- const metaTag = document.createElement("meta");
7
- metaTag.name = "content-powered-by";
8
- metaTag.content = "Intlayer - https://intlayer.org";
9
- document.head.appendChild(metaTag);
6
+ const existingMeta = document.head.querySelector(
7
+ 'meta[name="content-powered-by"]'
8
+ );
9
+ if (!existingMeta) {
10
+ const metaTag = document.createElement("meta");
11
+ metaTag.name = "content-powered-by";
12
+ metaTag.content = "Intlayer - https://intlayer.org";
13
+ document.head.appendChild(metaTag);
14
+ }
10
15
  }, []);
11
16
  return null;
12
17
  };
@@ -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 metaTag.name = 'content-powered-by';\n metaTag.content = 'Intlayer - https://intlayer.org';\n document.head.appendChild(metaTag);\n }, []);\n\n return null; // This component does not render anything visible\n};\n"],"mappings":";AAEA,SAAkB,iBAAiB;AAE5B,MAAM,gBAAoB,MAAM;AACrC,MAAI,QAAQ,IAAI,aAAa,aAAc,QAAO;AAElD,YAAU,MAAM;AACd,UAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,YAAQ,OAAO;AACf,YAAQ,UAAU;AAClB,aAAS,KAAK,YAAY,OAAO;AAAA,EACnC,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;","names":[]}
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":";AAEA,SAAkB,iBAAiB;AAE5B,MAAM,gBAAoB,MAAM;AACrC,MAAI,QAAQ,IAAI,aAAa,aAAc,QAAO;AAElD,YAAU,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,16 +1,17 @@
1
1
  "use client";
2
- import { jsx } from "react/jsx-runtime";
2
+ import { Fragment, jsx } from "react/jsx-runtime";
3
3
  import { isSameKeyPath } from "@intlayer/core";
4
+ import {
5
+ useFocusDictionary,
6
+ useEditedContentActions,
7
+ useEditorEnabled
8
+ } from "@intlayer/editor-react";
4
9
  import {
5
10
  useCallback,
6
11
  useEffect,
7
12
  useState,
8
13
  useMemo
9
14
  } from "react";
10
- import {
11
- useFocusDictionary,
12
- useEditedContentActions
13
- } from "@intlayer/editor-react";
14
15
  import { ContentSelector } from '../UI/ContentSelector.mjs';
15
16
  const ContentSelectorWrapper = ({
16
17
  children,
@@ -19,6 +20,7 @@ const ContentSelectorWrapper = ({
19
20
  keyPath,
20
21
  ...props
21
22
  }) => {
23
+ const { enabled } = useEditorEnabled();
22
24
  const { focusedContent, setFocusedContent } = useFocusDictionary();
23
25
  const { getEditedContentValue } = useEditedContentActions();
24
26
  const editedValue = useMemo(
@@ -35,7 +37,7 @@ const ContentSelectorWrapper = ({
35
37
  [dictionaryKey, dictionaryPath, keyPath, setFocusedContent]
36
38
  );
37
39
  const isSelected = useMemo(
38
- () => ((focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ?? false,
40
+ () => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ?? false,
39
41
  [focusedContent, keyPath]
40
42
  );
41
43
  useEffect(() => {
@@ -45,7 +47,18 @@ const ContentSelectorWrapper = ({
45
47
  setDisplayedChildren(children);
46
48
  }
47
49
  }, [editedValue, focusedContent, children]);
48
- return /* @__PURE__ */ jsx(ContentSelector, { onPress: handleSelect, isSelecting: isSelected, ...props, children: displayedChildren });
50
+ if (enabled) {
51
+ return /* @__PURE__ */ jsx(
52
+ ContentSelector,
53
+ {
54
+ onPress: handleSelect,
55
+ isSelecting: isSelected,
56
+ ...props,
57
+ children: displayedChildren
58
+ }
59
+ );
60
+ }
61
+ return /* @__PURE__ */ jsx(Fragment, { children });
49
62
  };
50
63
  export {
51
64
  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 {\n useFocusDictionary,\n useEditedContentActions,\n} from '@intlayer/editor-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 { 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?.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"],"mappings":";AAyEI;AAvEJ,SAAS,qBAAmC;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAWzB,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,gBAAgB,kBAAkB,IAAI,mBAAmB;AACjE,QAAM,EAAE,sBAAsB,IAAI,wBAAwB;AAE1D,QAAM,cAAc;AAAA,IAClB,MAAM,sBAAsB,eAAe,OAAO;AAAA,IAClD,CAAC,eAAe,SAAS,qBAAqB;AAAA,EAChD;AAEA,QAAM,CAAC,mBAAmB,oBAAoB,IAC5C,SAAoB,QAAQ;AAE9B,QAAM,eAAe;AAAA,IACnB,MACE,kBAAkB;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,gBAAgB,SAAS,iBAAiB;AAAA,EAC5D;AAEA,QAAM,aAAa;AAAA,IACjB,QACI,gBAAgB,SAAS,UAAU,KAAK,KACxC,cAAc,gBAAgB,WAAW,CAAC,GAAG,OAAO,MACtD;AAAA,IACF,CAAC,gBAAgB,OAAO;AAAA,EAC1B;AAEA,YAAU,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,SACE,oBAAC,mBAAgB,SAAS,cAAc,aAAa,YAAa,GAAG,OAClE,6BACH;AAEJ;","names":[]}
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":";AA6EM,SAUG,UAVH;AA3EN,SAAS,qBAAmC;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,uBAAuB;AAWzB,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,QAAM,EAAE,gBAAgB,kBAAkB,IAAI,mBAAmB;AACjE,QAAM,EAAE,sBAAsB,IAAI,wBAAwB;AAE1D,QAAM,cAAc;AAAA,IAClB,MAAM,sBAAsB,eAAe,OAAO;AAAA,IAClD,CAAC,eAAe,SAAS,qBAAqB;AAAA,EAChD;AAEA,QAAM,CAAC,mBAAmB,oBAAoB,IAC5C,SAAoB,QAAQ;AAE9B,QAAM,eAAe;AAAA,IACnB,MACE,kBAAkB;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,gBAAgB,SAAS,iBAAiB;AAAA,EAC5D;AAEA,QAAM,aAAa;AAAA,IACjB,OACG,gBAAgB,kBAAkB,kBAChC,gBAAgB,SAAS,UAAU,KAAK,KACzC,cAAc,gBAAgB,WAAW,CAAC,GAAG,OAAO,MACtD;AAAA,IACF,CAAC,gBAAgB,OAAO;AAAA,EAC1B;AAEA,YAAU,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,gCAAG,UAAS;AACrB;","names":[]}
@@ -1,15 +1,41 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
3
  import { getConfiguration } from "@intlayer/config/client";
3
- import { EditorProvider } from "@intlayer/editor-react";
4
- const {
5
- editor: { enabled }
6
- } = getConfiguration();
7
- const IntlayerEditorProvider = ({ children }) => {
8
- if (enabled) {
9
- return /* @__PURE__ */ jsx(EditorProvider, { targetWindow: window, children });
10
- }
11
- return children;
4
+ import dictionaries from "@intlayer/dictionaries-entry";
5
+ import {
6
+ EditorProvider,
7
+ useCrossURLPathState,
8
+ useDictionariesRecordActions,
9
+ useConfigurationActions,
10
+ useIframeClickInterceptor
11
+ } from "@intlayer/editor-react";
12
+ import { useEffect } from "react";
13
+ const IntlayerEditorProviderEnabled = () => {
14
+ useCrossURLPathState(void 0, {
15
+ receive: false,
16
+ emit: true
17
+ });
18
+ const { setConfiguration } = useConfigurationActions();
19
+ const { setLocaleDictionaries } = useDictionariesRecordActions();
20
+ useEffect(() => {
21
+ setLocaleDictionaries(dictionaries);
22
+ const config = getConfiguration();
23
+ setConfiguration(config);
24
+ }, [setLocaleDictionaries]);
25
+ useIframeClickInterceptor();
26
+ return /* @__PURE__ */ jsx(Fragment, {});
12
27
  };
28
+ const IntlayerEditorProvider = ({ children }) => /* @__PURE__ */ jsxs(
29
+ EditorProvider,
30
+ {
31
+ postMessage: (data) => window.parent?.postMessage(data, "*"),
32
+ allowedOrigins: ["*"],
33
+ children: [
34
+ /* @__PURE__ */ jsx(IntlayerEditorProviderEnabled, {}),
35
+ children
36
+ ]
37
+ }
38
+ );
13
39
  export {
14
40
  IntlayerEditorProvider
15
41
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["import { FC, PropsWithChildren } from 'react';\nimport { getConfiguration } from '@intlayer/config/client';\nimport { EditorProvider } from '@intlayer/editor-react';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => {\n if (enabled) {\n return <EditorProvider targetWindow={window}>{children}</EditorProvider>;\n }\n\n return children;\n};\n"],"mappings":"AAUW;AATX,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAE/B,MAAM;AAAA,EACJ,QAAQ,EAAE,QAAQ;AACpB,IAAI,iBAAiB;AAEd,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,MAAI,SAAS;AACX,WAAO,oBAAC,kBAAe,cAAc,QAAS,UAAS;AAAA,EACzD;AAEA,SAAO;AACT;","names":[]}
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":";AA6CS,wBAIP,YAJO;AA3CT,SAAS,wBAAwB;AACjC,OAAO,kBAAkB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAkD;AAO3D,MAAM,gCAAoC,MAAM;AAI9C,uBAAqB,QAAW;AAAA,IAC9B,SAAS;AAAA,IACT,MAAM;AAAA,EACR,CAAC;AAKD,QAAM,EAAE,iBAAiB,IAAI,wBAAwB;AACrD,QAAM,EAAE,sBAAsB,IAAI,6BAA6B;AAE/D,YAAU,MAAM;AACd,0BAAsB,YAAY;AAElC,UAAM,SAAS,iBAAiB;AAChC,qBAAiB,MAAM;AAAA,EACzB,GAAG,CAAC,qBAAqB,CAAC;AAK1B,4BAA0B;AAE1B,SAAO,gCAAE;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,0BAAC,iCAA8B;AAAA,MAC9B;AAAA;AAAA;AACH;","names":[]}