react-intlayer 4.0.0 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -193
- package/dist/cjs/UI/ContentSelector.cjs +126 -0
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -0
- package/dist/cjs/UI/PressableSpan/index.cjs +23 -0
- package/dist/cjs/UI/PressableSpan/index.cjs.map +1 -0
- package/dist/cjs/client/IntlayerProvider.cjs +5 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/{utils/PoweredByMeta/index.cjs → client/PoweredByMeta.cjs} +1 -1
- package/dist/cjs/client/PoweredByMeta.cjs.map +1 -0
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +39 -2
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +11 -6
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +0 -2
- package/dist/cjs/editor/index.cjs.map +1 -1
- package/dist/cjs/editor/renderContentEditor.cjs +2 -2
- package/dist/cjs/editor/renderContentEditor.cjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +107 -0
- package/dist/esm/UI/ContentSelector.mjs.map +1 -0
- package/dist/esm/UI/PressableSpan/index.mjs +2 -0
- package/dist/esm/UI/PressableSpan/index.mjs.map +1 -0
- package/dist/esm/client/IntlayerProvider.mjs +6 -2
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/{utils/PoweredByMeta/index.mjs → client/PoweredByMeta.mjs} +1 -1
- package/dist/esm/client/PoweredByMeta.mjs.map +1 -0
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +48 -3
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +12 -7
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +0 -1
- package/dist/esm/editor/index.mjs.map +1 -1
- package/dist/esm/editor/renderContentEditor.mjs +2 -2
- package/dist/esm/editor/renderContentEditor.mjs.map +1 -1
- package/dist/types/UI/ContentSelector.d.ts +10 -0
- package/dist/types/UI/ContentSelector.d.ts.map +1 -0
- package/dist/types/UI/PressableSpan/index.d.ts +2 -0
- package/dist/types/UI/PressableSpan/index.d.ts.map +1 -0
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/{utils/PoweredByMeta/index.d.ts → client/PoweredByMeta.d.ts} +1 -1
- package/dist/types/client/PoweredByMeta.d.ts.map +1 -0
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts +5 -3
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
- package/dist/types/editor/index.d.ts +0 -1
- package/dist/types/editor/index.d.ts.map +1 -1
- package/package.json +16 -23
- package/dist/cjs/editor/ContentSelectorConnector.cjs +0 -58
- package/dist/cjs/editor/ContentSelectorConnector.cjs.map +0 -1
- package/dist/cjs/utils/PoweredByMeta/index.cjs.map +0 -1
- package/dist/esm/editor/ContentSelectorConnector.mjs +0 -38
- package/dist/esm/editor/ContentSelectorConnector.mjs.map +0 -1
- package/dist/esm/utils/PoweredByMeta/index.mjs.map +0 -1
- package/dist/types/editor/ContentSelectorConnector.d.ts +0 -14
- package/dist/types/editor/ContentSelectorConnector.d.ts.map +0 -1
- package/dist/types/utils/PoweredByMeta/index.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { isSameKeyPath, type KeyPath } from '@intlayer/core';\nimport {\n 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":[]}
|
|
@@ -22,12 +22,17 @@ __export(IntlayerEditorProvider_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(IntlayerEditorProvider_exports);
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
var import_client = require("@intlayer/config/client");
|
|
26
|
+
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;
|
|
35
|
+
};
|
|
31
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
37
|
0 && (module.exports = {
|
|
33
38
|
IntlayerEditorProvider
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["import { FC, PropsWithChildren } from 'react';\nimport {
|
|
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":[]}
|
|
@@ -16,12 +16,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var editor_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(editor_exports);
|
|
18
18
|
__reExport(editor_exports, require('./ContentSelectorWrapper.cjs'), module.exports);
|
|
19
|
-
__reExport(editor_exports, require('./ContentSelectorConnector.cjs'), module.exports);
|
|
20
19
|
__reExport(editor_exports, require('./renderContentEditor.cjs'), module.exports);
|
|
21
20
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
21
|
0 && (module.exports = {
|
|
23
22
|
...require('./ContentSelectorWrapper.cjs'),
|
|
24
|
-
...require('./ContentSelectorConnector.cjs'),
|
|
25
23
|
...require('./renderContentEditor.cjs')
|
|
26
24
|
});
|
|
27
25
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/index.ts"],"sourcesContent":["export * from './ContentSelectorWrapper';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/index.ts"],"sourcesContent":["export * from './ContentSelectorWrapper';\nexport * from './renderContentEditor';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,2BAAc,qCAAd;AACA,2BAAc,kCADd;","names":[]}
|
|
@@ -23,7 +23,7 @@ __export(renderContentEditor_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(renderContentEditor_exports);
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
25
|
var import_client = require("@intlayer/config/client");
|
|
26
|
-
var
|
|
26
|
+
var import_ContentSelectorWrapper = require('./ContentSelectorWrapper.cjs');
|
|
27
27
|
const {
|
|
28
28
|
editor: { enabled }
|
|
29
29
|
} = (0, import_client.getConfiguration)();
|
|
@@ -33,7 +33,7 @@ const IntlayerEditorElement = ({
|
|
|
33
33
|
...props
|
|
34
34
|
}) => {
|
|
35
35
|
if (enabled && isContentSelectable) {
|
|
36
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
36
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ContentSelectorWrapper.ContentSelectorWrapper, { ...props, children: content });
|
|
37
37
|
}
|
|
38
38
|
return content;
|
|
39
39
|
};
|
|
@@ -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 {
|
|
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":[]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
useEffect,
|
|
5
|
+
useState,
|
|
6
|
+
useRef,
|
|
7
|
+
useCallback
|
|
8
|
+
} from "react";
|
|
9
|
+
const DEFAULT_PRESS_DETECT_DURATION = 400;
|
|
10
|
+
const ContentSelector = ({
|
|
11
|
+
children,
|
|
12
|
+
onPress: onSelect,
|
|
13
|
+
onClickOutside: onUnselect,
|
|
14
|
+
pressDuration = DEFAULT_PRESS_DETECT_DURATION,
|
|
15
|
+
isSelecting: isSelectingProp,
|
|
16
|
+
...props
|
|
17
|
+
}) => {
|
|
18
|
+
const divRef = useRef(null);
|
|
19
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
20
|
+
const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);
|
|
21
|
+
const pressTimerRef = useRef(null);
|
|
22
|
+
const handleOnLongPress = () => {
|
|
23
|
+
setIsSelectingState(true);
|
|
24
|
+
onSelect();
|
|
25
|
+
};
|
|
26
|
+
const startPressTimer = () => {
|
|
27
|
+
pressTimerRef.current = setTimeout(() => {
|
|
28
|
+
handleOnLongPress();
|
|
29
|
+
}, pressDuration);
|
|
30
|
+
};
|
|
31
|
+
const clearPressTimer = () => {
|
|
32
|
+
if (pressTimerRef.current) {
|
|
33
|
+
clearTimeout(pressTimerRef.current);
|
|
34
|
+
pressTimerRef.current = null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const handleMouseDown = () => {
|
|
38
|
+
clearPressTimer();
|
|
39
|
+
startPressTimer();
|
|
40
|
+
};
|
|
41
|
+
const handleMouseEnter = () => {
|
|
42
|
+
setIsHovered(true);
|
|
43
|
+
};
|
|
44
|
+
const handleMouseUp = () => {
|
|
45
|
+
setIsHovered(false);
|
|
46
|
+
clearPressTimer();
|
|
47
|
+
};
|
|
48
|
+
const handleClickOutside = useCallback(
|
|
49
|
+
(event) => {
|
|
50
|
+
if (divRef.current && !divRef.current.contains(event.target)) {
|
|
51
|
+
setIsSelectingState(false);
|
|
52
|
+
onUnselect?.();
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
[onUnselect]
|
|
56
|
+
);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
59
|
+
return () => {
|
|
60
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
61
|
+
};
|
|
62
|
+
}, [handleClickOutside]);
|
|
63
|
+
const handleOnClick = (e) => {
|
|
64
|
+
if (isSelectingState) {
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
e.stopPropagation();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const handleOnBlur = () => {
|
|
70
|
+
setIsSelectingState(false);
|
|
71
|
+
};
|
|
72
|
+
return /* @__PURE__ */ jsx(
|
|
73
|
+
"span",
|
|
74
|
+
{
|
|
75
|
+
style: {
|
|
76
|
+
display: "inline",
|
|
77
|
+
cursor: "pointer",
|
|
78
|
+
userSelect: "none",
|
|
79
|
+
borderRadius: "0.375rem",
|
|
80
|
+
outlineWidth: "2px",
|
|
81
|
+
outlineOffset: "4px",
|
|
82
|
+
outlineStyle: "solid",
|
|
83
|
+
outlineColor: isSelectingProp || isSelectingState || isHovered ? "inherit" : "transparent",
|
|
84
|
+
transition: "all 200ms 100ms ease-in-out"
|
|
85
|
+
},
|
|
86
|
+
role: "button",
|
|
87
|
+
tabIndex: 0,
|
|
88
|
+
onKeyUp: () => null,
|
|
89
|
+
onClick: handleOnClick,
|
|
90
|
+
onMouseDown: handleMouseDown,
|
|
91
|
+
onMouseUp: handleMouseUp,
|
|
92
|
+
onMouseLeave: handleMouseUp,
|
|
93
|
+
onTouchStart: handleMouseDown,
|
|
94
|
+
onTouchEnd: handleMouseUp,
|
|
95
|
+
onTouchCancel: handleMouseUp,
|
|
96
|
+
onBlur: handleOnBlur,
|
|
97
|
+
onMouseEnter: handleMouseEnter,
|
|
98
|
+
ref: divRef,
|
|
99
|
+
...props,
|
|
100
|
+
children
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
export {
|
|
105
|
+
ContentSelector
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=ContentSelector.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport {\n useEffect,\n useState,\n useRef,\n useCallback,\n type FC,\n type MouseEventHandler,\n type HTMLAttributes,\n} from 'react';\n\nconst DEFAULT_PRESS_DETECT_DURATION = 400;\n\ntype ContentSelectorProps = {\n onPress: () => void;\n onClickOutside?: () => void;\n pressDuration?: number;\n isSelecting?: boolean;\n} & HTMLAttributes<HTMLDivElement>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n onPress: onSelect,\n onClickOutside: onUnselect,\n pressDuration = DEFAULT_PRESS_DETECT_DURATION,\n isSelecting: isSelectingProp,\n ...props\n}) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isHovered, setIsHovered] = useState(false);\n const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const handleOnLongPress = () => {\n setIsSelectingState(true);\n onSelect();\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, pressDuration);\n };\n\n const clearPressTimer = () => {\n if (pressTimerRef.current) {\n clearTimeout(pressTimerRef.current);\n pressTimerRef.current = null;\n }\n };\n\n const handleMouseDown = () => {\n clearPressTimer(); // Ensure any previous timer is cleared\n startPressTimer();\n };\n\n const handleMouseEnter = () => {\n setIsHovered(true);\n };\n\n const handleMouseUp = () => {\n setIsHovered(false);\n clearPressTimer();\n };\n\n // Use useCallback to ensure the function identity remains stable\n const handleClickOutside = useCallback(\n (event: MouseEvent) => {\n if (divRef.current && !divRef.current.contains(event.target as Node)) {\n setIsSelectingState(false);\n onUnselect?.();\n }\n },\n [onUnselect]\n );\n\n useEffect(() => {\n // Attach click outside listener\n document.addEventListener('mousedown', handleClickOutside);\n\n return () => {\n // Cleanup\n document.removeEventListener('mousedown', handleClickOutside);\n // clearPressTimer(); // Ensure to clear the timer when component unmounts\n };\n }, [handleClickOutside]);\n\n const handleOnClick: MouseEventHandler<HTMLDivElement> = (e) => {\n if (isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsSelectingState(false);\n };\n\n return (\n <span\n style={{\n display: 'inline',\n cursor: 'pointer',\n userSelect: 'none',\n borderRadius: '0.375rem',\n outlineWidth: '2px',\n outlineOffset: '4px',\n outlineStyle: 'solid',\n outlineColor:\n isSelectingProp || isSelectingState || isHovered\n ? 'inherit'\n : 'transparent',\n transition: 'all 200ms 100ms ease-in-out',\n }}\n role=\"button\"\n tabIndex={0}\n onKeyUp={() => null}\n onClick={handleOnClick}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n onTouchStart={handleMouseDown}\n onTouchEnd={handleMouseUp}\n onTouchCancel={handleMouseUp}\n onBlur={handleOnBlur}\n onMouseEnter={handleMouseEnter}\n ref={divRef}\n {...props}\n >\n {children}\n </span>\n );\n};\n"],"mappings":";AAqGI;AAnGJ;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;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,SAAS,OAAuB,IAAI;AAC1C,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAAS,eAAe;AACxE,QAAM,gBAAgB,OAA6C,IAAI;AAEvE,QAAM,oBAAoB,MAAM;AAC9B,wBAAoB,IAAI;AACxB,aAAS;AAAA,EACX;AAEA,QAAM,kBAAkB,MAAM;AAC5B,kBAAc,UAAU,WAAW,MAAM;AACvC,wBAAkB;AAAA,IACpB,GAAG,aAAa;AAAA,EAClB;AAEA,QAAM,kBAAkB,MAAM;AAC5B,QAAI,cAAc,SAAS;AACzB,mBAAa,cAAc,OAAO;AAClC,oBAAc,UAAU;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,kBAAkB,MAAM;AAC5B,oBAAgB;AAChB,oBAAgB;AAAA,EAClB;AAEA,QAAM,mBAAmB,MAAM;AAC7B,iBAAa,IAAI;AAAA,EACnB;AAEA,QAAM,gBAAgB,MAAM;AAC1B,iBAAa,KAAK;AAClB,oBAAgB;AAAA,EAClB;AAGA,QAAM,qBAAqB;AAAA,IACzB,CAAC,UAAsB;AACrB,UAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,SAAS,MAAM,MAAc,GAAG;AACpE,4BAAoB,KAAK;AACzB,qBAAa;AAAA,MACf;AAAA,IACF;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,YAAU,MAAM;AAEd,aAAS,iBAAiB,aAAa,kBAAkB;AAEzD,WAAO,MAAM;AAEX,eAAS,oBAAoB,aAAa,kBAAkB;AAAA,IAE9D;AAAA,EACF,GAAG,CAAC,kBAAkB,CAAC;AAEvB,QAAM,gBAAmD,CAAC,MAAM;AAC9D,QAAI,kBAAkB;AACpB,QAAE,eAAe;AACjB,QAAE,gBAAgB;AAAA,IACpB;AAAA,EACF;AAEA,QAAM,eAAe,MAAM;AAEzB,wBAAoB,KAAK;AAAA,EAC3B;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,cAAc;AAAA,QACd,eAAe;AAAA,QACf,cAAc;AAAA,QACd,cACE,mBAAmB,oBAAoB,YACnC,YACA;AAAA,QACN,YAAY;AAAA,MACd;AAAA,MACA,MAAK;AAAA,MACL,UAAU;AAAA,MACV,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,MACT,aAAa;AAAA,MACb,WAAW;AAAA,MACX,cAAc;AAAA,MACd,cAAc;AAAA,MACd,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,QAAQ;AAAA,MACR,cAAc;AAAA,MACd,KAAK;AAAA,MACJ,GAAG;AAAA,MAEH;AAAA;AAAA,EACH;AAEJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/UI/PressableSpan/index.ts"],"sourcesContent":["export * from '../ContentSelector';\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { getConfiguration } from "@intlayer/config/client";
|
|
4
4
|
import {
|
|
5
5
|
createContext,
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from "react";
|
|
11
11
|
import { localeCookie, setLocaleCookie } from './useLocaleCookie.mjs';
|
|
12
12
|
import { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider.mjs';
|
|
13
|
+
import { PoweredByMeta } from './PoweredByMeta.mjs';
|
|
13
14
|
const IntlayerClientContext = createContext({
|
|
14
15
|
locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,
|
|
15
16
|
setLocale: () => null
|
|
@@ -42,7 +43,10 @@ const IntlayerProvider = ({
|
|
|
42
43
|
() => ({ locale: currentLocale, setLocale }),
|
|
43
44
|
[currentLocale, setLocale]
|
|
44
45
|
);
|
|
45
|
-
return /* @__PURE__ */
|
|
46
|
+
return /* @__PURE__ */ jsxs(IntlayerClientContext.Provider, { value, children: [
|
|
47
|
+
/* @__PURE__ */ jsx(PoweredByMeta, {}),
|
|
48
|
+
/* @__PURE__ */ jsx(IntlayerEditorProvider, { children })
|
|
49
|
+
] });
|
|
46
50
|
};
|
|
47
51
|
export {
|
|
48
52
|
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 { localeCookie, setLocaleCookie } from './useLocaleCookie';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\n\ntype IntlayerValue = {\n locale: Locales;\n setLocale: (newLocale: Locales) => void;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = PropsWithChildren & {\n locale?: Locales;\n setLocale?: (locale: Locales) => void;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n}) => {\n const { internationalization } = getConfiguration();\n const { defaultLocale, locales: availableLocales } = internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocaleBase = useCallback(\n (newLocale: Locales) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale]\n );\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale: setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <IntlayerEditorProvider>{children}</IntlayerEditorProvider>\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { PoweredByMeta } from './PoweredByMeta';\n\ntype IntlayerValue = {\n locale: Locales;\n setLocale: (newLocale: Locales) => void;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = PropsWithChildren & {\n locale?: Locales;\n setLocale?: (locale: Locales) => void;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n}) => {\n const { internationalization } = getConfiguration();\n const { defaultLocale, locales: availableLocales } = internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocaleBase = useCallback(\n (newLocale: Locales) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale]\n );\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale: setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <PoweredByMeta />\n <IntlayerEditorProvider>{children}</IntlayerEditorProvider>\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";AA6EI,SACE,KADF;AA3EJ,SAAS,wBAAsC;AAC/C;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,uBAAuB;AAC9C,SAAS,8BAA8B;AACvC,SAAS,qBAAqB;AAUvB,MAAM,wBAAwB,cAA6B;AAAA,EAChE,QAAQ,gBAAgB,iBAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,MAAM,WAAW,qBAAqB;AAUjE,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA;AAAA,EACA,WAAW;AACb,MAAM;AACJ,QAAM,EAAE,qBAAqB,IAAI,iBAAiB;AAClD,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAAI;AAErD,QAAM,CAAC,eAAe,gBAAgB,IAAI;AAAA,IACxC,UAAU,gBAAgB;AAAA,EAC5B;AAEA,QAAM,gBAAgB;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,sBAAgB,SAAS;AAAA,IAC3B;AAAA,IACA,CAAC,kBAAkB,eAAe,MAAM;AAAA,EAC1C;AAEA,QAAM,YAAY,iBAAiB;AAEnC,QAAM,QAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAqB;AAAA,IACrD,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,qBAAC,sBAAsB,UAAtB,EAA+B,OAC9B;AAAA,wBAAC,iBAAc;AAAA,IACf,oBAAC,0BAAwB,UAAS;AAAA,KACpC;AAEJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/PoweredByMeta.ts"],"sourcesContent":["'use client';\n\nimport { type FC, useEffect } from 'react';\n\nexport const PoweredByMeta: FC = () => {\n if (process.env.NODE_ENV !== 'production') return null;\n\n useEffect(() => {\n 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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\n// @ts-ignore @intlayer/backend is not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config/client';\n// @ts-ignore @intlayer/design-system not build yet\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionary = async (\n dictionaryKey: string\n): Promise<DictionaryAPI> => {\n try {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n return distantDictionary;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":"AAAA,SAAS,sBAAsB;AAG/B,SAAS,wBAAwB;AAM1B,MAAM,yBAAyB,OACpC,
|
|
1
|
+
{"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\n// @ts-ignore @intlayer/backend is not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config/client';\n// @ts-ignore @intlayer/design-system not build yet\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionary = async (\n dictionaryKey: string\n): Promise<DictionaryAPI | undefined> => {\n try {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n return distantDictionary;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":"AAAA,SAAS,sBAAsB;AAG/B,SAAS,wBAAwB;AAM1B,MAAM,yBAAyB,OACpC,kBACuC;AACvC,MAAI;AACF,UAAM,SAAS,iBAAiB;AAChC,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,UAAM,cAAc,eAAe,QAAW,MAAM;AAEpD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;AAGlD,UAAM,sBAAsB,MAAM,YAAY,WAAW;AAAA,MACvD;AAAA,MACA;AAAA,MACA;AAAA,QACE,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,MAC1D;AAAA,IACF;AAEA,UAAM,oBAAoB,oBAAoB;AAE9C,QAAI,CAAC,mBAAmB;AACtB,YAAM,IAAI,MAAM,cAAc,aAAa,sBAAsB;AAAA,IACnE;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,7 +1,52 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { isSameKeyPath } from "@intlayer/core";
|
|
4
|
+
import {
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useState,
|
|
8
|
+
useMemo
|
|
9
|
+
} from "react";
|
|
10
|
+
import {
|
|
11
|
+
useFocusDictionary,
|
|
12
|
+
useEditedContentActions
|
|
13
|
+
} from "@intlayer/editor-react";
|
|
14
|
+
import { ContentSelector } from '../UI/ContentSelector.mjs';
|
|
2
15
|
const ContentSelectorWrapper = ({
|
|
3
|
-
children
|
|
4
|
-
|
|
16
|
+
children,
|
|
17
|
+
dictionaryKey,
|
|
18
|
+
dictionaryPath,
|
|
19
|
+
keyPath,
|
|
20
|
+
...props
|
|
21
|
+
}) => {
|
|
22
|
+
const { focusedContent, setFocusedContent } = useFocusDictionary();
|
|
23
|
+
const { getEditedContentValue } = useEditedContentActions();
|
|
24
|
+
const editedValue = useMemo(
|
|
25
|
+
() => getEditedContentValue(dictionaryKey, keyPath),
|
|
26
|
+
[dictionaryKey, keyPath, getEditedContentValue]
|
|
27
|
+
);
|
|
28
|
+
const [displayedChildren, setDisplayedChildren] = useState(children);
|
|
29
|
+
const handleSelect = useCallback(
|
|
30
|
+
() => setFocusedContent({
|
|
31
|
+
dictionaryKey,
|
|
32
|
+
dictionaryPath,
|
|
33
|
+
keyPath
|
|
34
|
+
}),
|
|
35
|
+
[dictionaryKey, dictionaryPath, keyPath, setFocusedContent]
|
|
36
|
+
);
|
|
37
|
+
const isSelected = useMemo(
|
|
38
|
+
() => ((focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ?? false,
|
|
39
|
+
[focusedContent, keyPath]
|
|
40
|
+
);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (editedValue && typeof editedValue === "string") {
|
|
43
|
+
setDisplayedChildren(editedValue);
|
|
44
|
+
} else {
|
|
45
|
+
setDisplayedChildren(children);
|
|
46
|
+
}
|
|
47
|
+
}, [editedValue, focusedContent, children]);
|
|
48
|
+
return /* @__PURE__ */ jsx(ContentSelector, { onPress: handleSelect, isSelecting: isSelected, ...props, children: displayedChildren });
|
|
49
|
+
};
|
|
5
50
|
export {
|
|
6
51
|
ContentSelectorWrapper
|
|
7
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { isSameKeyPath, type KeyPath } from '@intlayer/core';\nimport {\n 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,10 +1,15 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
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;
|
|
12
|
+
};
|
|
8
13
|
export {
|
|
9
14
|
IntlayerEditorProvider
|
|
10
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["import { FC, PropsWithChildren } from 'react';\nimport {
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/index.ts"],"sourcesContent":["export * from './ContentSelectorWrapper';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/index.ts"],"sourcesContent":["export * from './ContentSelectorWrapper';\nexport * from './renderContentEditor';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { getConfiguration } from "@intlayer/config/client";
|
|
3
|
-
import {
|
|
3
|
+
import { ContentSelectorWrapper } from './ContentSelectorWrapper.mjs';
|
|
4
4
|
const {
|
|
5
5
|
editor: { enabled }
|
|
6
6
|
} = getConfiguration();
|
|
@@ -10,7 +10,7 @@ const IntlayerEditorElement = ({
|
|
|
10
10
|
...props
|
|
11
11
|
}) => {
|
|
12
12
|
if (enabled && isContentSelectable) {
|
|
13
|
-
return /* @__PURE__ */ jsx(
|
|
13
|
+
return /* @__PURE__ */ jsx(ContentSelectorWrapper, { ...props, children: content });
|
|
14
14
|
}
|
|
15
15
|
return content;
|
|
16
16
|
};
|
|
@@ -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 {
|
|
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":"AAwBM;AAxBN,SAAS,wBAAwB;AAGjC,SAAS,8BAA8B;AAEvC,MAAM;AAAA,EACJ,QAAQ,EAAE,QAAQ;AACpB,IAAI,iBAAiB;AAUrB,MAAM,wBAAwD,CAAC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,MAAI,WAAW,qBAAqB;AAClC,WACE,oBAAC,0BAAwB,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":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type FC, type HTMLAttributes } from 'react';
|
|
2
|
+
type ContentSelectorProps = {
|
|
3
|
+
onPress: () => void;
|
|
4
|
+
onClickOutside?: () => void;
|
|
5
|
+
pressDuration?: number;
|
|
6
|
+
isSelecting?: boolean;
|
|
7
|
+
} & HTMLAttributes<HTMLDivElement>;
|
|
8
|
+
export declare const ContentSelector: FC<ContentSelectorProps>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=ContentSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentSelector.d.ts","sourceRoot":"","sources":["../../../src/UI/ContentSelector.tsx"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,EAAE,EAEP,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AAIf,KAAK,oBAAoB,GAAG;IAC1B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;AAEnC,eAAO,MAAM,eAAe,EAAE,EAAE,CAAC,oBAAoB,CAiHpD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/UI/PressableSpan/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.d.ts","sourceRoot":"","sources":["../../../src/client/IntlayerProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAoB,KAAK,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EACL,KAAK,iBAAiB,EAItB,KAAK,EAAE,EAGR,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.d.ts","sourceRoot":"","sources":["../../../src/client/IntlayerProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAoB,KAAK,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EACL,KAAK,iBAAiB,EAItB,KAAK,EAAE,EAGR,MAAM,OAAO,CAAC;AAKf,KAAK,aAAa,GAAG;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,wCAGhC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB,qBAA0C,CAAC;AAE1E,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,GAAG;IACtD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CACvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC,qBAAqB,CAwCtD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PoweredByMeta.d.ts","sourceRoot":"","sources":["../../../src/client/PoweredByMeta.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAa,MAAM,OAAO,CAAC;AAE3C,eAAO,MAAM,aAAa,EAAE,EAW3B,CAAC"}
|
|
@@ -2,5 +2,5 @@ import { type DictionaryAPI } from '@intlayer/backend';
|
|
|
2
2
|
/**
|
|
3
3
|
* Fetch distant dictionary
|
|
4
4
|
*/
|
|
5
|
-
export declare const fetchDistantDictionary: (dictionaryKey: string) => Promise<DictionaryAPI>;
|
|
5
|
+
export declare const fetchDistantDictionary: (dictionaryKey: string) => Promise<DictionaryAPI | undefined>;
|
|
6
6
|
//# sourceMappingURL=fetchDistantDictionary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchDistantDictionary.d.ts","sourceRoot":"","sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIvD;;GAEG;AACH,eAAO,MAAM,sBAAsB,kBAClB,MAAM,KACpB,OAAO,CAAC,aAAa,
|
|
1
|
+
{"version":3,"file":"fetchDistantDictionary.d.ts","sourceRoot":"","sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIvD;;GAEG;AACH,eAAO,MAAM,sBAAsB,kBAClB,MAAM,KACpB,OAAO,CAAC,aAAa,GAAG,SAAS,CAoCnC,CAAC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type KeyPath } from '@intlayer/core';
|
|
2
|
-
import { type
|
|
3
|
-
|
|
2
|
+
import { type FC, HTMLAttributes } from 'react';
|
|
3
|
+
type ContentData = {
|
|
4
4
|
dictionaryKey: string;
|
|
5
5
|
dictionaryPath: string;
|
|
6
6
|
keyPath: KeyPath[];
|
|
7
|
-
}
|
|
7
|
+
};
|
|
8
|
+
export type ContentSelectorWrapperProps = ContentData & HTMLAttributes<HTMLDivElement>;
|
|
8
9
|
export declare const ContentSelectorWrapper: FC<ContentSelectorWrapperProps>;
|
|
10
|
+
export {};
|
|
9
11
|
//# sourceMappingURL=ContentSelectorWrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelectorWrapper.d.ts","sourceRoot":"","sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContentSelectorWrapper.d.ts","sourceRoot":"","sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAKL,KAAK,EAAE,EAEP,cAAc,EACf,MAAM,OAAO,CAAC;AAOf,KAAK,WAAW,GAAG;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,OAAO,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,WAAW,GACnD,cAAc,CAAC,cAAc,CAAC,CAAC;AAEjC,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,2BAA2B,CAkDlE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerEditorProvider.d.ts","sourceRoot":"","sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"IntlayerEditorProvider.d.ts","sourceRoot":"","sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAQ9C,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,iBAAiB,CAMxD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/editor/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/editor/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intlayer",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "Easily internationalize i18n your React applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"intlayer",
|
|
8
8
|
"data",
|
|
@@ -70,23 +70,18 @@
|
|
|
70
70
|
"./package.json"
|
|
71
71
|
],
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"cross-spawn": "^7.0.6",
|
|
74
73
|
"js-cookie": "^3.0.5",
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"@intlayer/
|
|
78
|
-
"@intlayer/
|
|
79
|
-
"@intlayer/
|
|
80
|
-
"@intlayer/api": "4.0.0",
|
|
81
|
-
"@intlayer/dictionaries-entry": "4.0.0",
|
|
82
|
-
"@intlayer/webpack": "4.0.0"
|
|
74
|
+
"@intlayer/core": "4.0.3",
|
|
75
|
+
"@intlayer/config": "4.0.3",
|
|
76
|
+
"@intlayer/dictionaries-entry": "4.0.3",
|
|
77
|
+
"@intlayer/api": "4.0.3",
|
|
78
|
+
"@intlayer/editor-react": "4.0.3"
|
|
83
79
|
},
|
|
84
80
|
"devDependencies": {
|
|
85
81
|
"@craco/types": "^7.1.0",
|
|
86
82
|
"@types/js-cookie": "^3.0.6",
|
|
87
83
|
"@types/node": "^22.10.6",
|
|
88
84
|
"@types/react": "^18.3.1",
|
|
89
|
-
"@types/webpack": "^5.28.5",
|
|
90
85
|
"@typescript-eslint/parser": "^8.20.0",
|
|
91
86
|
"concurrently": "^9.1.2",
|
|
92
87
|
"eslint": "^9.18.0",
|
|
@@ -97,23 +92,21 @@
|
|
|
97
92
|
"tsc-alias": "^1.8.10",
|
|
98
93
|
"tsup": "^8.3.5",
|
|
99
94
|
"typescript": "^5.7.3",
|
|
100
|
-
"@intlayer/backend": "4.0.
|
|
101
|
-
"@utils/eslint-config": "1.0.4",
|
|
95
|
+
"@intlayer/backend": "4.0.3",
|
|
102
96
|
"@utils/ts-config": "1.0.4",
|
|
103
|
-
"@utils/
|
|
104
|
-
"@utils/tsup-config": "1.0.4"
|
|
97
|
+
"@utils/eslint-config": "1.0.4",
|
|
98
|
+
"@utils/tsup-config": "1.0.4",
|
|
99
|
+
"@utils/ts-config-types": "1.0.4"
|
|
105
100
|
},
|
|
106
101
|
"peerDependencies": {
|
|
107
102
|
"react": ">=16.0.0",
|
|
108
103
|
"react-dom": ">=16.0.0",
|
|
109
104
|
"vite": ">=4.0.0",
|
|
110
|
-
"
|
|
111
|
-
"@intlayer/
|
|
112
|
-
"@intlayer/
|
|
113
|
-
"intlayer": "4.0.
|
|
114
|
-
"@intlayer/
|
|
115
|
-
"@intlayer/core": "4.0.0",
|
|
116
|
-
"@intlayer/config": "4.0.0"
|
|
105
|
+
"@intlayer/config": "4.0.3",
|
|
106
|
+
"@intlayer/dictionaries-entry": "4.0.3",
|
|
107
|
+
"@intlayer/core": "4.0.3",
|
|
108
|
+
"intlayer": "4.0.3",
|
|
109
|
+
"@intlayer/editor-react": "4.0.3"
|
|
117
110
|
},
|
|
118
111
|
"engines": {
|
|
119
112
|
"node": ">=14.18"
|