preact-intlayer 9.6.0 → 9.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -10,16 +10,24 @@ let preact_hooks = require("preact/hooks");
|
|
|
10
10
|
* the editor always knows which locale the app is displaying.
|
|
11
11
|
*/
|
|
12
12
|
const useEditor = () => {
|
|
13
|
-
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
13
|
+
const { locale, setLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
14
14
|
const managerRef = (0, preact_hooks.useRef)(null);
|
|
15
|
+
const setLocaleRef = (0, preact_hooks.useRef)(setLocale);
|
|
16
|
+
setLocaleRef.current = setLocale;
|
|
15
17
|
(0, preact_hooks.useEffect)(() => {
|
|
16
18
|
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_editor_isEnabled.isEnabled) return;
|
|
19
|
+
let unsubscribeLocaleRequest = null;
|
|
20
|
+
let isStopped = false;
|
|
17
21
|
import("@intlayer/editor").then(({ initEditorClient }) => {
|
|
22
|
+
if (isStopped) return;
|
|
18
23
|
const manager = initEditorClient();
|
|
19
24
|
managerRef.current = manager;
|
|
20
25
|
if (locale) manager.currentLocale.set(locale);
|
|
26
|
+
unsubscribeLocaleRequest = manager.onLocaleChangeRequested((requestedLocale) => setLocaleRef.current?.(requestedLocale));
|
|
21
27
|
}).catch(() => {});
|
|
22
28
|
return () => {
|
|
29
|
+
isStopped = true;
|
|
30
|
+
unsubscribeLocaleRequest?.();
|
|
23
31
|
managerRef.current = null;
|
|
24
32
|
import("@intlayer/editor").then(({ stopEditorClient }) => {
|
|
25
33
|
stopEditorClient();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditor.cjs","names":["useContext","IntlayerClientContext","useRef","isEnabled"],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["import type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'preact/hooks';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initialises the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n const managerRef = useRef<EditorStateManager | null>(null);\n\n useEffect(() => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n import('@intlayer/editor')\n .then(({ initEditorClient }) => {\n const manager = initEditorClient();\n managerRef.current = manager;\n\n if (locale) manager.currentLocale.set(locale as Locale);\n })\n .catch(() => {});\n\n return () => {\n managerRef.current = null;\n import('@intlayer/editor')\n .then(({ stopEditorClient }) => {\n stopEditorClient();\n })\n .catch(() => {});\n };\n }, []);\n\n useEffect(() => {\n if (\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !locale ||\n !managerRef.current\n )\n return;\n\n managerRef.current.currentLocale.set(locale as Locale);\n }, [locale]);\n};\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,kBAAkB;CAC7B,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"useEditor.cjs","names":["useContext","IntlayerClientContext","useRef","isEnabled"],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["import type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'preact/hooks';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initialises the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext) ?? {};\n const managerRef = useRef<EditorStateManager | null>(null);\n // Read through a ref: the subscription outlives the render that created it\n const setLocaleRef = useRef(setLocale);\n setLocaleRef.current = setLocale;\n\n useEffect(() => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n let unsubscribeLocaleRequest: (() => void) | null = null;\n let isStopped = false;\n\n import('@intlayer/editor')\n .then(({ initEditorClient }) => {\n if (isStopped) return;\n\n const manager = initEditorClient();\n managerRef.current = manager;\n\n if (locale) manager.currentLocale.set(locale as Locale);\n\n unsubscribeLocaleRequest = manager.onLocaleChangeRequested(\n (requestedLocale) => setLocaleRef.current?.(requestedLocale)\n );\n })\n .catch(() => {});\n\n return () => {\n isStopped = true;\n unsubscribeLocaleRequest?.();\n managerRef.current = null;\n import('@intlayer/editor')\n .then(({ stopEditorClient }) => {\n stopEditorClient();\n })\n .catch(() => {});\n };\n }, []);\n\n useEffect(() => {\n if (\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !locale ||\n !managerRef.current\n )\n return;\n\n managerRef.current.currentLocale.set(locale as Locale);\n }, [locale]);\n};\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,kBAAkB;CAC7B,MAAM,EAAE,QAAQ,kBAAcA,yBAAWC,qDAAqB,KAAK,CAAC;CACpE,MAAM,iBAAaC,qBAAkC,IAAI;CAEzD,MAAM,mBAAeA,qBAAO,SAAS;CACrC,aAAa,UAAU;CAEvB,kCAAgB;EACd,IAAI,QAAQ,IAAI,4BAA4B,WAAW,CAACC,sCAAW;EAEnE,IAAI,2BAAgD;EACpD,IAAI,YAAY;EAEhB,OAAO,mBAAmB,CACvB,MAAM,EAAE,uBAAuB;GAC9B,IAAI,WAAW;GAEf,MAAM,UAAU,iBAAiB;GACjC,WAAW,UAAU;GAErB,IAAI,QAAQ,QAAQ,cAAc,IAAI,MAAgB;GAEtD,2BAA2B,QAAQ,yBAChC,oBAAoB,aAAa,UAAU,eAAe,CAC7D;EACF,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EAEjB,aAAa;GACX,YAAY;GACZ,2BAA2B;GAC3B,WAAW,UAAU;GACrB,OAAO,mBAAmB,CACvB,MAAM,EAAE,uBAAuB;IAC9B,iBAAiB;GACnB,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EACnB;CACF,GAAG,CAAC,CAAC;CAEL,kCAAgB;EACd,IACE,QAAQ,IAAI,4BAA4B,WACxC,CAAC,UACD,CAAC,WAAW,SAEZ;EAEF,WAAW,QAAQ,cAAc,IAAI,MAAgB;CACvD,GAAG,CAAC,MAAM,CAAC;AACb"}
|
|
@@ -9,16 +9,24 @@ import { useContext, useEffect, useRef } from "preact/hooks";
|
|
|
9
9
|
* the editor always knows which locale the app is displaying.
|
|
10
10
|
*/
|
|
11
11
|
const useEditor = () => {
|
|
12
|
-
const { locale } = useContext(IntlayerClientContext) ?? {};
|
|
12
|
+
const { locale, setLocale } = useContext(IntlayerClientContext) ?? {};
|
|
13
13
|
const managerRef = useRef(null);
|
|
14
|
+
const setLocaleRef = useRef(setLocale);
|
|
15
|
+
setLocaleRef.current = setLocale;
|
|
14
16
|
useEffect(() => {
|
|
15
17
|
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !isEnabled) return;
|
|
18
|
+
let unsubscribeLocaleRequest = null;
|
|
19
|
+
let isStopped = false;
|
|
16
20
|
import("@intlayer/editor").then(({ initEditorClient }) => {
|
|
21
|
+
if (isStopped) return;
|
|
17
22
|
const manager = initEditorClient();
|
|
18
23
|
managerRef.current = manager;
|
|
19
24
|
if (locale) manager.currentLocale.set(locale);
|
|
25
|
+
unsubscribeLocaleRequest = manager.onLocaleChangeRequested((requestedLocale) => setLocaleRef.current?.(requestedLocale));
|
|
20
26
|
}).catch(() => {});
|
|
21
27
|
return () => {
|
|
28
|
+
isStopped = true;
|
|
29
|
+
unsubscribeLocaleRequest?.();
|
|
22
30
|
managerRef.current = null;
|
|
23
31
|
import("@intlayer/editor").then(({ stopEditorClient }) => {
|
|
24
32
|
stopEditorClient();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditor.mjs","names":[],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["import type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'preact/hooks';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initialises the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n const managerRef = useRef<EditorStateManager | null>(null);\n\n useEffect(() => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n import('@intlayer/editor')\n .then(({ initEditorClient }) => {\n const manager = initEditorClient();\n managerRef.current = manager;\n\n if (locale) manager.currentLocale.set(locale as Locale);\n })\n .catch(() => {});\n\n return () => {\n managerRef.current = null;\n import('@intlayer/editor')\n .then(({ stopEditorClient }) => {\n stopEditorClient();\n })\n .catch(() => {});\n };\n }, []);\n\n useEffect(() => {\n if (\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !locale ||\n !managerRef.current\n )\n return;\n\n managerRef.current.currentLocale.set(locale as Locale);\n }, [locale]);\n};\n"],"mappings":";;;;;;;;;;AAWA,MAAa,kBAAkB;CAC7B,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"useEditor.mjs","names":[],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["import type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'preact/hooks';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initialises the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext) ?? {};\n const managerRef = useRef<EditorStateManager | null>(null);\n // Read through a ref: the subscription outlives the render that created it\n const setLocaleRef = useRef(setLocale);\n setLocaleRef.current = setLocale;\n\n useEffect(() => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n let unsubscribeLocaleRequest: (() => void) | null = null;\n let isStopped = false;\n\n import('@intlayer/editor')\n .then(({ initEditorClient }) => {\n if (isStopped) return;\n\n const manager = initEditorClient();\n managerRef.current = manager;\n\n if (locale) manager.currentLocale.set(locale as Locale);\n\n unsubscribeLocaleRequest = manager.onLocaleChangeRequested(\n (requestedLocale) => setLocaleRef.current?.(requestedLocale)\n );\n })\n .catch(() => {});\n\n return () => {\n isStopped = true;\n unsubscribeLocaleRequest?.();\n managerRef.current = null;\n import('@intlayer/editor')\n .then(({ stopEditorClient }) => {\n stopEditorClient();\n })\n .catch(() => {});\n };\n }, []);\n\n useEffect(() => {\n if (\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !locale ||\n !managerRef.current\n )\n return;\n\n managerRef.current.currentLocale.set(locale as Locale);\n }, [locale]);\n};\n"],"mappings":";;;;;;;;;;AAWA,MAAa,kBAAkB;CAC7B,MAAM,EAAE,QAAQ,cAAc,WAAW,qBAAqB,KAAK,CAAC;CACpE,MAAM,aAAa,OAAkC,IAAI;CAEzD,MAAM,eAAe,OAAO,SAAS;CACrC,aAAa,UAAU;CAEvB,gBAAgB;EACd,IAAI,QAAQ,IAAI,4BAA4B,WAAW,CAAC,WAAW;EAEnE,IAAI,2BAAgD;EACpD,IAAI,YAAY;EAEhB,OAAO,mBAAmB,CACvB,MAAM,EAAE,uBAAuB;GAC9B,IAAI,WAAW;GAEf,MAAM,UAAU,iBAAiB;GACjC,WAAW,UAAU;GAErB,IAAI,QAAQ,QAAQ,cAAc,IAAI,MAAgB;GAEtD,2BAA2B,QAAQ,yBAChC,oBAAoB,aAAa,UAAU,eAAe,CAC7D;EACF,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EAEjB,aAAa;GACX,YAAY;GACZ,2BAA2B;GAC3B,WAAW,UAAU;GACrB,OAAO,mBAAmB,CACvB,MAAM,EAAE,uBAAuB;IAC9B,iBAAiB;GACnB,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EACnB;CACF,GAAG,CAAC,CAAC;CAEL,gBAAgB;EACd,IACE,QAAQ,IAAI,4BAA4B,WACxC,CAAC,UACD,CAAC,WAAW,SAEZ;EAEF,WAAW,QAAQ,cAAc,IAAI,MAAgB;CACvD,GAAG,CAAC,MAAM,CAAC;AACb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "preact-intlayer",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.7.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your Preact applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -101,19 +101,19 @@
|
|
|
101
101
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
102
102
|
},
|
|
103
103
|
"dependencies": {
|
|
104
|
-
"@intlayer/api": "9.
|
|
105
|
-
"@intlayer/config": "9.
|
|
106
|
-
"@intlayer/core": "9.
|
|
107
|
-
"@intlayer/editor": "9.
|
|
108
|
-
"@intlayer/engine": "9.
|
|
109
|
-
"@intlayer/types": "9.
|
|
104
|
+
"@intlayer/api": "9.7.0",
|
|
105
|
+
"@intlayer/config": "9.7.0",
|
|
106
|
+
"@intlayer/core": "9.7.0",
|
|
107
|
+
"@intlayer/editor": "9.7.0",
|
|
108
|
+
"@intlayer/engine": "9.7.0",
|
|
109
|
+
"@intlayer/types": "9.7.0"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
|
-
"@types/node": "^
|
|
112
|
+
"@types/node": "^26",
|
|
113
113
|
"@utils/ts-config": "1.0.4",
|
|
114
114
|
"@utils/ts-config-types": "1.0.4",
|
|
115
115
|
"@utils/tsdown-config": "1.0.4",
|
|
116
|
-
"preact": "
|
|
116
|
+
"preact": "11.0.0",
|
|
117
117
|
"rimraf": "6.1.3",
|
|
118
118
|
"tsdown": "0.23.0",
|
|
119
119
|
"typescript": "7.0.2",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"preact": ">=8.0.0"
|
|
124
124
|
},
|
|
125
125
|
"optionalDependencies": {
|
|
126
|
-
"@intlayer/analytics": "9.
|
|
126
|
+
"@intlayer/analytics": "9.7.0"
|
|
127
127
|
},
|
|
128
128
|
"engines": {
|
|
129
129
|
"node": ">=14.18"
|