vue-intlayer 5.3.13 → 5.4.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.
- package/dist/ContentSelector.vue_vue_type_script_setup_true_lang-Dfu1ALQx.mjs +71 -0
- package/dist/ContentSelector.vue_vue_type_script_setup_true_lang-OSRmjq5b.js +1 -0
- package/dist/ContentSelectorWrapper.vue_vue_type_script_setup_true_lang-BML9iRiS.mjs +45 -0
- package/dist/ContentSelectorWrapper.vue_vue_type_script_setup_true_lang-CE_1sBPk.js +1 -0
- package/dist/EditedContentRenderer.vue_vue_type_script_setup_true_lang-CvPgk7Z3.mjs +39 -0
- package/dist/EditedContentRenderer.vue_vue_type_script_setup_true_lang-Yqrgst_y.js +1 -0
- package/dist/cjs/UI/ContentSelector.cjs +1 -0
- package/dist/cjs/client/computedProxy.cjs +1 -0
- package/dist/cjs/client/index.cjs +1 -0
- package/dist/cjs/client/installIntlayer.cjs +1 -0
- package/dist/cjs/client/useDictionary.cjs +1 -0
- package/dist/cjs/client/useIntlayer.cjs +1 -0
- package/dist/cjs/client/useLocale.cjs +1 -0
- package/dist/cjs/client/useLocaleCookie.cjs +1 -0
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +1 -0
- package/dist/cjs/editor/EditedContentRenderer.cjs +1 -0
- package/dist/cjs/editor/EditorSelectorRenderer.cjs +1 -0
- package/dist/cjs/editor/changedContent.cjs +1 -0
- package/dist/cjs/editor/communicator.cjs +1 -0
- package/dist/cjs/editor/configuration.cjs +1 -0
- package/dist/cjs/editor/createSharedComposable.cjs +1 -0
- package/dist/cjs/editor/dictionariesRecord.cjs +1 -0
- package/dist/cjs/editor/editedContent.cjs +1 -0
- package/dist/cjs/editor/editorEnabled.cjs +1 -0
- package/dist/cjs/editor/editorLocale.cjs +1 -0
- package/dist/cjs/editor/focusDictionary.cjs +1 -0
- package/dist/cjs/editor/index.cjs +1 -0
- package/dist/cjs/editor/installIntlayerEditor.cjs +1 -0
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs +1 -0
- package/dist/cjs/editor/useCrossFrameState.cjs +1 -0
- package/dist/cjs/editor/useCrossURLPathState.cjs +1 -0
- package/dist/cjs/editor/useEditedContentRenderer.cjs +1 -0
- package/dist/cjs/editor/useEditor.cjs +1 -0
- package/dist/cjs/editor/useIframeClickInterceptor.cjs +1 -0
- package/dist/cjs/getDictionary.cjs +1 -0
- package/dist/cjs/getIntlayer.cjs +1 -0
- package/dist/cjs/index.cjs +1 -25
- package/dist/cjs/markdown/index.cjs +1 -0
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs +1 -0
- package/dist/cjs/plugins.cjs +1 -0
- package/dist/cjs/renderIntlayerNode.cjs +1 -0
- package/dist/cjs/server/IntlayerServerProvider.cjs +1 -0
- package/dist/cjs/server/index.cjs +1 -0
- package/dist/cjs/server/serverContext.cjs +1 -0
- package/dist/cjs/server/t.cjs +1 -0
- package/dist/cjs/server/useDictionary.cjs +1 -0
- package/dist/cjs/server/useIntlayer.cjs +1 -0
- package/dist/esm/UI/ContentSelector.mjs +4 -0
- package/dist/esm/client/computedProxy.mjs +24 -0
- package/dist/esm/client/index.mjs +12 -0
- package/dist/esm/client/installIntlayer.mjs +28 -0
- package/dist/esm/client/useDictionary.mjs +16 -0
- package/dist/esm/client/useIntlayer.mjs +14 -0
- package/dist/esm/client/useLocale.mjs +33 -0
- package/dist/esm/client/useLocaleCookie.mjs +19 -0
- package/dist/esm/editor/ContentSelectorWrapper.mjs +4 -0
- package/dist/esm/editor/EditedContentRenderer.mjs +4 -0
- package/dist/esm/editor/EditorSelectorRenderer.mjs +39 -0
- package/dist/esm/editor/changedContent.mjs +21 -0
- package/dist/esm/editor/communicator.mjs +37 -0
- package/dist/esm/editor/configuration.mjs +13 -0
- package/dist/esm/editor/createSharedComposable.mjs +15 -0
- package/dist/esm/editor/dictionariesRecord.mjs +49 -0
- package/dist/esm/editor/editedContent.mjs +43 -0
- package/dist/esm/editor/editorEnabled.mjs +36 -0
- package/dist/esm/editor/editorLocale.mjs +29 -0
- package/dist/esm/editor/focusDictionary.mjs +39 -0
- package/dist/esm/editor/index.mjs +6 -0
- package/dist/esm/editor/installIntlayerEditor.mjs +18 -0
- package/dist/esm/editor/useCrossFrameMessageListener.mjs +31 -0
- package/dist/esm/editor/useCrossFrameState.mjs +44 -0
- package/dist/esm/editor/useCrossURLPathState.mjs +26 -0
- package/dist/esm/editor/useEditedContentRenderer.mjs +17 -0
- package/dist/esm/editor/useEditor.mjs +14 -0
- package/dist/esm/editor/useIframeClickInterceptor.mjs +23 -0
- package/dist/esm/getDictionary.mjs +17 -0
- package/dist/esm/getIntlayer.mjs +13 -0
- package/dist/esm/index.mjs +25 -3
- package/dist/esm/markdown/index.mjs +7 -0
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +25 -0
- package/dist/esm/plugins.mjs +90 -0
- package/dist/esm/renderIntlayerNode.mjs +12 -0
- package/dist/esm/server/IntlayerServerProvider.mjs +12 -0
- package/dist/esm/server/index.mjs +16 -0
- package/dist/esm/server/serverContext.mjs +34 -0
- package/dist/esm/server/t.mjs +10 -0
- package/dist/esm/server/useDictionary.mjs +10 -0
- package/dist/esm/server/useIntlayer.mjs +10 -0
- package/dist/types/UI/ContentSelector.vue.d.ts +33 -0
- package/dist/types/UI/ContentSelector.vue.d.ts.map +1 -0
- package/dist/types/client/computedProxy.d.ts +3 -0
- package/dist/types/client/computedProxy.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +5 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/client/installIntlayer.d.ts +16 -0
- package/dist/types/client/installIntlayer.d.ts.map +1 -0
- package/dist/types/client/useDictionary.d.ts +5 -0
- package/dist/types/client/useDictionary.d.ts.map +1 -0
- package/dist/types/client/useIntlayer.d.ts +11 -0
- package/dist/types/client/useIntlayer.d.ts.map +1 -0
- package/dist/types/client/useLocale.d.ts +16 -0
- package/dist/types/client/useLocale.d.ts.map +1 -0
- package/dist/types/client/useLocaleCookie.d.ts +17 -0
- package/dist/types/client/useLocaleCookie.d.ts.map +1 -0
- package/dist/types/editor/ContentSelectorWrapper.vue.d.ts +26 -0
- package/dist/types/editor/ContentSelectorWrapper.vue.d.ts.map +1 -0
- package/dist/types/editor/changedContent.d.ts +15 -0
- package/dist/types/editor/changedContent.d.ts.map +1 -0
- package/dist/types/editor/communicator.d.ts +28 -0
- package/dist/types/editor/communicator.d.ts.map +1 -0
- package/dist/types/editor/configuration.d.ts +2 -0
- package/dist/types/editor/configuration.d.ts.map +1 -0
- package/dist/types/editor/createSharedComposable.d.ts +13 -0
- package/dist/types/editor/createSharedComposable.d.ts.map +1 -0
- package/dist/types/editor/dictionariesRecord.d.ts +16 -0
- package/dist/types/editor/dictionariesRecord.d.ts.map +1 -0
- package/dist/types/editor/editedContent.d.ts +19 -0
- package/dist/types/editor/editedContent.d.ts.map +1 -0
- package/dist/types/editor/editorEnabled.d.ts +16 -0
- package/dist/types/editor/editorEnabled.d.ts.map +1 -0
- package/dist/types/editor/editorLocale.d.ts +3 -0
- package/dist/types/editor/editorLocale.d.ts.map +1 -0
- package/dist/types/editor/focusDictionary.d.ts +24 -0
- package/dist/types/editor/focusDictionary.d.ts.map +1 -0
- package/dist/types/editor/index.d.ts +3 -0
- package/dist/types/editor/index.d.ts.map +1 -0
- package/dist/types/editor/installIntlayerEditor.d.ts +15 -0
- package/dist/types/editor/installIntlayerEditor.d.ts.map +1 -0
- package/dist/types/editor/useCrossFrameMessageListener.d.ts +11 -0
- package/dist/types/editor/useCrossFrameMessageListener.d.ts.map +1 -0
- package/dist/types/editor/useCrossFrameState.d.ts +24 -0
- package/dist/types/editor/useCrossFrameState.d.ts.map +1 -0
- package/dist/types/editor/useCrossURLPathState.d.ts +16 -0
- package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -0
- package/dist/types/editor/useEditedContentRenderer.d.ts +10 -0
- package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -0
- package/dist/types/editor/useEditor.d.ts +2 -0
- package/dist/types/editor/useEditor.d.ts.map +1 -0
- package/dist/types/editor/useIframeClickInterceptor.d.ts +11 -0
- package/dist/types/editor/useIframeClickInterceptor.d.ts.map +1 -0
- package/dist/types/getDictionary.d.ts +5 -0
- package/dist/types/getDictionary.d.ts.map +1 -0
- package/dist/types/getIntlayer.d.ts +5 -0
- package/dist/types/getIntlayer.d.ts.map +1 -0
- package/dist/types/index.d.ts +10 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/index.d.ts +2 -0
- package/dist/types/markdown/index.d.ts.map +1 -0
- package/dist/types/markdown/installIntlayerMarkdown.d.ts +17 -0
- package/dist/types/markdown/installIntlayerMarkdown.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +46 -0
- package/dist/types/plugins.d.ts.map +1 -0
- package/dist/types/renderIntlayerNode.d.ts +36 -0
- package/dist/types/renderIntlayerNode.d.ts.map +1 -0
- package/dist/types/server/IntlayerServerProvider.d.ts +38 -0
- package/dist/types/server/IntlayerServerProvider.d.ts.map +1 -0
- package/dist/types/server/index.d.ts +6 -0
- package/dist/types/server/index.d.ts.map +1 -0
- package/dist/types/server/serverContext.d.ts +35 -0
- package/dist/types/server/serverContext.d.ts.map +1 -0
- package/dist/types/server/t.d.ts +24 -0
- package/dist/types/server/t.d.ts.map +1 -0
- package/dist/types/server/useDictionary.d.ts +19 -0
- package/dist/types/server/useDictionary.d.ts.map +1 -0
- package/dist/types/server/useIntlayer.d.ts +16 -0
- package/dist/types/server/useIntlayer.d.ts.map +1 -0
- package/package.json +34 -14
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/intlayerMiddlewarePlugin.cjs +0 -224
- package/dist/cjs/intlayerMiddlewarePlugin.cjs.map +0 -1
- package/dist/cjs/intlayerPlugin.cjs +0 -76
- package/dist/cjs/intlayerPlugin.cjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/intlayerMiddlewarePlugin.mjs +0 -200
- package/dist/esm/intlayerMiddlewarePlugin.mjs.map +0 -1
- package/dist/esm/intlayerPlugin.mjs +0 -52
- package/dist/esm/intlayerPlugin.mjs.map +0 -1
- package/dist/types/intlayerMiddlewarePlugin.d.ts +0 -6
- package/dist/types/intlayerMiddlewarePlugin.d.ts.map +0 -1
- package/dist/types/intlayerPlugin.d.ts +0 -16
- package/dist/types/intlayerPlugin.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getIntlayer.d.ts","sourceRoot":"","sources":["../../src/getIntlayer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,OAAO,EACR,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,gCAAgC,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAChF,OAAO,EACL,oBAAoB,EAGrB,MAAM,WAAW,CAAC;AAEnB,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,aAAa,EAC3E,KAAK,CAAC,EACN,SAAS,CAAC,EACV,oBAAoB,OAAO,EAAE,KAQ0B,oBAAoB,CACzE,gCAAgC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAEjD,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { IInterpreterPluginVue } from './plugins';
|
|
2
|
+
declare module '@intlayer/core' {
|
|
3
|
+
interface IInterpreterPlugin<T, S> extends IInterpreterPluginVue<T> {
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export * from './client';
|
|
7
|
+
export * from './getDictionary';
|
|
8
|
+
export * from './getIntlayer';
|
|
9
|
+
export * from './markdown';
|
|
10
|
+
export * from './plugins';
|
|
3
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElD,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,qBAAqB,CAAC,CAAC,CAAC;KAAG;CACvE;AAED,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/markdown/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { VNodeChild, App } from 'vue';
|
|
2
|
+
export declare const INTLAYER_MARKDOWN_SYMBOL: unique symbol;
|
|
3
|
+
type RenderMarkdownFunction = (markdown: string) => VNodeChild;
|
|
4
|
+
export type IntlayerMarkdownProvider = {
|
|
5
|
+
renderMarkdown: RenderMarkdownFunction;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Create and return a single IntlayerMarkdownProvider instance
|
|
9
|
+
*/
|
|
10
|
+
export declare const createIntlayerMarkdownClient: (renderMarkdown: RenderMarkdownFunction) => IntlayerMarkdownProvider;
|
|
11
|
+
/**
|
|
12
|
+
* Helper to install the IntlayerMarkdown provider into the app
|
|
13
|
+
*/
|
|
14
|
+
export declare const installIntlayerMarkdown: (app: App, renderMarkdown: RenderMarkdownFunction) => void;
|
|
15
|
+
export declare const useMarkdown: () => IntlayerMarkdownProvider;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=installIntlayerMarkdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installIntlayerMarkdown.d.ts","sourceRoot":"","sources":["../../../src/markdown/installIntlayerMarkdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,UAAU,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAEnD,eAAO,MAAM,wBAAwB,eAA6B,CAAC;AAEnE,KAAK,sBAAsB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,UAAU,CAAC;AAO/D,MAAM,MAAM,wBAAwB,GAAG;IACrC,cAAc,EAAE,sBAAsB,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,4BAA4B,GACvC,gBAAgB,sBAAsB,KACrC,wBAQF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAClC,KAAK,GAAG,EACR,gBAAgB,sBAAsB,SAKvC,CAAC;AAEF,eAAO,MAAM,WAAW,gCAavB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { NodeType, DeepTransformContent as DeepTransformContentCore, IInterpreterPluginState as IInterpreterPluginStateCore, Plugins } from '@intlayer/core';
|
|
2
|
+
/** ---------------------------------------------
|
|
3
|
+
* INTLAYER NODE PLUGIN
|
|
4
|
+
* --------------------------------------------- */
|
|
5
|
+
export type IntlayerNodeCond<T> = T extends number | string ? IntlayerNode<T> : never;
|
|
6
|
+
export interface IntlayerNode<T, P = {}> {
|
|
7
|
+
value: T;
|
|
8
|
+
children?: any;
|
|
9
|
+
additionalProps?: P;
|
|
10
|
+
}
|
|
11
|
+
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
|
|
12
|
+
export declare const intlayerNodePlugins: Plugins;
|
|
13
|
+
/**
|
|
14
|
+
* MARKDOWN PLUGIN
|
|
15
|
+
*/
|
|
16
|
+
export type MarkdownStringCond<T> = T extends string ? IntlayerNode<string, {
|
|
17
|
+
metadata: DeepTransformContent<string>;
|
|
18
|
+
}> : never;
|
|
19
|
+
/** Markdown string plugin. Replaces string node with a component that render the markdown. */
|
|
20
|
+
export declare const markdownStringPlugin: Plugins;
|
|
21
|
+
export type MarkdownCond<T> = T extends {
|
|
22
|
+
nodeType: NodeType | string;
|
|
23
|
+
[NodeType.Markdown]: infer M;
|
|
24
|
+
metadata?: infer U;
|
|
25
|
+
} ? IntlayerNode<DeepTransformContent<M>, {
|
|
26
|
+
metadata: DeepTransformContent<U>;
|
|
27
|
+
}> : never;
|
|
28
|
+
export declare const markdownPlugin: Plugins;
|
|
29
|
+
/** ---------------------------------------------
|
|
30
|
+
* PLUGINS RESULT
|
|
31
|
+
* --------------------------------------------- */
|
|
32
|
+
export interface IInterpreterPluginVue<T> {
|
|
33
|
+
intlayerNode: IntlayerNodeCond<T>;
|
|
34
|
+
markdown: MarkdownCond<T>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.
|
|
38
|
+
*
|
|
39
|
+
* Otherwise the the `vue-intlayer` plugins will override the types of `intlayer` functions.
|
|
40
|
+
*/
|
|
41
|
+
export type IInterpreterPluginState = IInterpreterPluginStateCore & {
|
|
42
|
+
intlayerNode: true;
|
|
43
|
+
markdown: true;
|
|
44
|
+
};
|
|
45
|
+
export type DeepTransformContent<T> = DeepTransformContentCore<T, IInterpreterPluginState>;
|
|
46
|
+
//# sourceMappingURL=plugins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../src/plugins.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,QAAQ,EACR,KAAK,oBAAoB,IAAI,wBAAwB,EACrD,KAAK,uBAAuB,IAAI,2BAA2B,EAC3D,KAAK,OAAO,EACb,MAAM,gBAAgB,CAAC;AAMxB;;oDAEoD;AAEpD,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,MAAM,GACvD,YAAY,CAAC,CAAC,CAAC,GACf,KAAK,CAAC;AAEV,MAAM,WAAW,YAAY,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE;IACrC,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,eAAe,CAAC,EAAE,CAAC,CAAC;CACrB;AAED,wFAAwF;AACxF,eAAO,MAAM,mBAAmB,EAAE,OAuBjC,CAAC;AAEF;;GAEG;AAEH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAChD,YAAY,CAAC,MAAM,EAAE;IAAE,QAAQ,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,GAChE,KAAK,CAAC;AAEV,8FAA8F;AAC9F,eAAO,MAAM,oBAAoB,EAAE,OAuDlC,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS;IACtC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC5B,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;CACpB,GACG,YAAY,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE;IAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,GAC5E,KAAK,CAAC;AAEV,eAAO,MAAM,cAAc,EAAE,OAqB5B,CAAC;AAEF;;oDAEoD;AAEpD,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,YAAY,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAClC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG,2BAA2B,GAAG;IAClE,YAAY,EAAE,IAAI,CAAC;IACnB,QAAQ,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,wBAAwB,CAC5D,CAAC,EACD,uBAAuB,CACxB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { NodeProps } from '@intlayer/core';
|
|
2
|
+
import { VNode, VNodeChild } from 'vue';
|
|
3
|
+
export type IntlayerNode<T = NodeProps['children'], AdditionalProps = {}> = {
|
|
4
|
+
value: T;
|
|
5
|
+
render: () => VNode;
|
|
6
|
+
toString: () => T;
|
|
7
|
+
} & AdditionalProps;
|
|
8
|
+
interface RenderIntlayerNodeProps<T> {
|
|
9
|
+
value: T;
|
|
10
|
+
children: VNodeChild | (() => VNodeChild);
|
|
11
|
+
additionalProps?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates a dual-purpose object that acts both as a Vue component (renders a <span>)
|
|
15
|
+
* and a primitive value (returns the raw value when coerced to a string).
|
|
16
|
+
*
|
|
17
|
+
* This is useful when you want a value that can be used in templates both as:
|
|
18
|
+
* - an interpolated string (e.g. `{{ value }}`)
|
|
19
|
+
* - a component tag (e.g. `<value />`)
|
|
20
|
+
*
|
|
21
|
+
* @template T - The type of the primitive text value (string, number, boolean, null, or undefined).
|
|
22
|
+
* @param {T} text - The value to render and stringify.
|
|
23
|
+
* @returns {{
|
|
24
|
+
* render: () => import('vue').VNode,
|
|
25
|
+
* toString: () => T
|
|
26
|
+
* }} An object with `render()` for Vue and `toString()` for string interpolation.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const title = dual('Hello');
|
|
30
|
+
* // In template:
|
|
31
|
+
* // {{ title }} -> "Hello"
|
|
32
|
+
* // <title /> -> <span>Hello</span>
|
|
33
|
+
*/
|
|
34
|
+
export declare const renderIntlayerNode: <T extends number | string | boolean | null | undefined>(props: RenderIntlayerNodeProps<T>) => IntlayerNode<T>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=renderIntlayerNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderIntlayerNode.d.ts","sourceRoot":"","sources":["../../src/renderIntlayerNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAE7C,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,EAAE,eAAe,GAAG,EAAE,IAAI;IAC1E,KAAK,EAAE,CAAC,CAAC;IACT,MAAM,EAAE,MAAM,KAAK,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC,CAAC;CACnB,GAAG,eAAe,CAAC;AAEpB,UAAU,uBAAuB,CAAC,CAAC;IACjC,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,EAAE,UAAU,GAAG,CAAC,MAAM,UAAU,CAAC,CAAC;IAC1C,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,kBAAkB,GAC7B,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,EAEtD,OAAO,uBAAuB,CAAC,CAAC,CAAC,KAChC,YAAY,CAAC,CAAC,CAkBhB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { LocalesValues } from '@intlayer/config/client';
|
|
2
|
+
/**
|
|
3
|
+
* Context that stores the current locale on the server side
|
|
4
|
+
*/
|
|
5
|
+
export declare const IntlayerServerContext: {
|
|
6
|
+
provide: (value: LocalesValues) => void;
|
|
7
|
+
consume: (callback: (value: LocalesValues | undefined) => any) => any;
|
|
8
|
+
_storage: () => {
|
|
9
|
+
value: LocalesValues | undefined;
|
|
10
|
+
};
|
|
11
|
+
_defaultValue: LocalesValues | undefined;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Helper function that provides the current locale to the server context
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // In a server-side entry point
|
|
18
|
+
* provideIntlayerLocale('en-US');
|
|
19
|
+
*/
|
|
20
|
+
export declare const provideIntlayerLocale: (locale?: LocalesValues) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Get the current locale from the server context
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const currentLocale = getIntlayerLocale();
|
|
26
|
+
*/
|
|
27
|
+
export declare const getIntlayerLocale: () => LocalesValues | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Helper that allows consuming the current locale with a callback
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* withIntlayerLocale((locale) => {
|
|
33
|
+
* // Use locale here
|
|
34
|
+
* return someFunction(locale);
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
37
|
+
export declare const withIntlayerLocale: <T>(callback: (locale: LocalesValues | undefined) => T) => T;
|
|
38
|
+
//# sourceMappingURL=IntlayerServerProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlayerServerProvider.d.ts","sourceRoot":"","sources":["../../../src/server/IntlayerServerProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAK7D;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;CACiB,CAAC;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAChC,SAAQ,aAA6B,SAGtC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,QAAO,aAAa,GAAG,SAEpD,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAClC,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,KAAK,CAAC,KACjD,CAEF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { IntlayerServerContext, getIntlayerLocale, provideIntlayerLocale, withIntlayerLocale, } from './IntlayerServerProvider';
|
|
2
|
+
export * from './serverContext';
|
|
3
|
+
export { t } from './t';
|
|
4
|
+
export { useDictionary } from './useDictionary';
|
|
5
|
+
export { useIntlayer } from './useIntlayer';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new datastore for a given server context.
|
|
3
|
+
* Attempts to provide functionality similar to React's context API for Vue SSR.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const IntlayerServer = createServerContext<string | null>(null);
|
|
7
|
+
*
|
|
8
|
+
* // In a server component
|
|
9
|
+
* IntlayerServer.provide(locale);
|
|
10
|
+
*
|
|
11
|
+
* // Retrieve the value
|
|
12
|
+
* const localeValue = getServerContext(IntlayerServer);
|
|
13
|
+
*/
|
|
14
|
+
export declare const createServerContext: <T>(defaultValue?: T) => ServerContext<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Fetches a value present in a given server context.
|
|
17
|
+
* Similar to Vue's inject, but for server components.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* getServerContext(IntlayerServer);
|
|
21
|
+
*/
|
|
22
|
+
export declare const getServerContext: <T>({ _storage, _defaultValue, }: ServerContext<T>) => T | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Type definition for the ServerContext
|
|
25
|
+
*/
|
|
26
|
+
type ServerContext<T> = {
|
|
27
|
+
provide: (value: T) => void;
|
|
28
|
+
consume: (callback: (value: T | undefined) => any) => any;
|
|
29
|
+
_storage: () => {
|
|
30
|
+
value: T | undefined;
|
|
31
|
+
};
|
|
32
|
+
_defaultValue: T | undefined;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=serverContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverContext.d.ts","sourceRoot":"","sources":["../../../src/server/serverContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,eAAO,MAAM,mBAAmB,GAAI,CAAC,EAAE,eAAe,CAAC,KAAG,aAAa,CAAC,CAAC,CAqCxE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,8BAGjC,aAAa,CAAC,CAAC,CAAC,KAAG,CAAC,GAAG,SAKzB,CAAC;AAEF;;GAEG;AACH,KAAK,aAAa,CAAC,CAAC,IAAI;IACtB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,KAAK,GAAG,KAAK,GAAG,CAAC;IAC1D,QAAQ,EAAE,MAAM;QAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAA;KAAE,CAAC;IACzC,aAAa,EAAE,CAAC,GAAG,SAAS,CAAC;CAC9B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { LocalesValues } from '@intlayer/config/client';
|
|
2
|
+
import { LanguageContent } from '@intlayer/core';
|
|
3
|
+
/**
|
|
4
|
+
* On the server side, function to get the translation content based on the locale
|
|
5
|
+
*
|
|
6
|
+
* If no locale is found, it will return the content related to the default locale.
|
|
7
|
+
*
|
|
8
|
+
* Returns either the content editor, or the content itself depending on the configuration.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const content = t({
|
|
13
|
+
* en: 'Hello',
|
|
14
|
+
* fr: 'Bonjour',
|
|
15
|
+
* }, 'fr');
|
|
16
|
+
* // 'Bonjour'
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Using TypeScript:
|
|
20
|
+
* - This function will require each locale to be defined if defined in the project configuration.
|
|
21
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
22
|
+
*/
|
|
23
|
+
export declare const t: <Content = string>(multilangContent: LanguageContent<Content>, locale?: LocalesValues) => Content;
|
|
24
|
+
//# sourceMappingURL=t.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"t.d.ts","sourceRoot":"","sources":["../../../src/server/t.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAItE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,CAAC,GAAI,OAAO,GAAG,MAAM,EAChC,kBAAkB,eAAe,CAAC,OAAO,CAAC,EAC1C,SAAS,aAAa,YAMvB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LocalesValues } from '@intlayer/config/client';
|
|
2
|
+
import { Dictionary } from '@intlayer/core';
|
|
3
|
+
/**
|
|
4
|
+
* On the server side, function that transforms a dictionary and returns the content
|
|
5
|
+
*
|
|
6
|
+
* If the locale is not provided, it will use the locale from the server context
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // With a dictionary object
|
|
10
|
+
* const dictionary = {
|
|
11
|
+
* en: { title: 'Hello' },
|
|
12
|
+
* fr: { title: 'Bonjour' }
|
|
13
|
+
* };
|
|
14
|
+
*
|
|
15
|
+
* // Transform the dictionary for the current locale
|
|
16
|
+
* const localizedDictionary = useDictionary(dictionary);
|
|
17
|
+
*/
|
|
18
|
+
export declare const useDictionary: <T extends Dictionary>(dictionary: T, locale?: LocalesValues) => import('@intlayer/core').DeepTransformContent<T["content"], import('..').IInterpreterPluginState>;
|
|
19
|
+
//# sourceMappingURL=useDictionary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../../src/server/useDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAKjD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,UAAU,EAChD,YAAY,CAAC,EACb,SAAS,aAAa,sGAMvB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LocalesValues } from '@intlayer/config/client';
|
|
2
|
+
import { DictionaryKeys } from '@intlayer/core';
|
|
3
|
+
/**
|
|
4
|
+
* On the server side, function that picks one dictionary by its key and returns the content
|
|
5
|
+
*
|
|
6
|
+
* If the locale is not provided, it will use the locale from the server context
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Server-side component or middleware
|
|
10
|
+
* const dictionary = useIntlayer('homepage');
|
|
11
|
+
*
|
|
12
|
+
* // Access translated strings
|
|
13
|
+
* const title = dictionary.title;
|
|
14
|
+
*/
|
|
15
|
+
export declare const useIntlayer: <T extends DictionaryKeys, K extends LocalesValues>(key: T, locale?: K) => any;
|
|
16
|
+
//# sourceMappingURL=useIntlayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIntlayer.d.ts","sourceRoot":"","sources":["../../../src/server/useIntlayer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAKrD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,aAAa,EAC3E,KAAK,CAAC,EACN,SAAS,CAAC,QAMX,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-intlayer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your Vue applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
"multilingual",
|
|
11
11
|
"i18n",
|
|
12
12
|
"typescript",
|
|
13
|
-
"vue"
|
|
13
|
+
"vue",
|
|
14
|
+
"vite",
|
|
15
|
+
"json"
|
|
14
16
|
],
|
|
15
17
|
"homepage": "https://intlayer.org",
|
|
16
18
|
"bugs": {
|
|
@@ -39,6 +41,16 @@
|
|
|
39
41
|
"require": "./dist/cjs/index.cjs",
|
|
40
42
|
"import": "./dist/esm/index.mjs"
|
|
41
43
|
},
|
|
44
|
+
"./server": {
|
|
45
|
+
"types": "./dist/types/server/index.d.ts",
|
|
46
|
+
"require": "./dist/cjs/server/index.cjs",
|
|
47
|
+
"import": "./dist/esm/server/index.mjs"
|
|
48
|
+
},
|
|
49
|
+
"./editor": {
|
|
50
|
+
"types": "./dist/types/editor/index.d.ts",
|
|
51
|
+
"require": "./dist/cjs/editor/index.cjs",
|
|
52
|
+
"import": "./dist/esm/editor/index.mjs"
|
|
53
|
+
},
|
|
42
54
|
"./package.json": "./package.json"
|
|
43
55
|
},
|
|
44
56
|
"main": "dist/cjs/index.cjs",
|
|
@@ -56,20 +68,28 @@
|
|
|
56
68
|
"./package.json"
|
|
57
69
|
],
|
|
58
70
|
"dependencies": {
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"@intlayer/config": "5.
|
|
71
|
+
"js-cookie": "^3.0.5",
|
|
72
|
+
"uuid": "^11.1.0",
|
|
73
|
+
"@intlayer/config": "5.4.0",
|
|
74
|
+
"@intlayer/dictionaries-entry": "5.4.0",
|
|
75
|
+
"@intlayer/core": "5.4.0",
|
|
76
|
+
"@intlayer/api": "5.4.0",
|
|
77
|
+
"@intlayer/editor": "5.4.0"
|
|
62
78
|
},
|
|
63
79
|
"devDependencies": {
|
|
80
|
+
"@types/js-cookie": "^3.0.6",
|
|
64
81
|
"@types/node": "^22.13.10",
|
|
65
82
|
"@typescript-eslint/parser": "^8.27.0",
|
|
83
|
+
"@vitejs/plugin-vue": "^5.2.2",
|
|
66
84
|
"concurrently": "^9.1.2",
|
|
67
85
|
"eslint": "^9.22.0",
|
|
86
|
+
"fast-glob": "^3.3.3",
|
|
68
87
|
"prettier": "^3.5.3",
|
|
69
88
|
"rimraf": "^6.0.1",
|
|
70
|
-
"tsc-alias": "^1.8.11",
|
|
71
|
-
"tsup": "^8.4.0",
|
|
72
89
|
"typescript": "^5.8.2",
|
|
90
|
+
"vite": "^6.3.1",
|
|
91
|
+
"vite-plugin-dts": "^4.5.3",
|
|
92
|
+
"@intlayer/backend": "5.4.0",
|
|
73
93
|
"@utils/eslint-config": "1.0.4",
|
|
74
94
|
"@utils/ts-config": "1.0.4",
|
|
75
95
|
"@utils/ts-config-types": "1.0.4",
|
|
@@ -77,9 +97,11 @@
|
|
|
77
97
|
},
|
|
78
98
|
"peerDependencies": {
|
|
79
99
|
"vue": "^3.5.13",
|
|
80
|
-
"@intlayer/
|
|
81
|
-
"@intlayer/
|
|
82
|
-
"@intlayer/core": "5.
|
|
100
|
+
"@intlayer/config": "5.4.0",
|
|
101
|
+
"@intlayer/api": "5.4.0",
|
|
102
|
+
"@intlayer/core": "5.4.0",
|
|
103
|
+
"@intlayer/dictionaries-entry": "5.4.0",
|
|
104
|
+
"intlayer": "5.4.0"
|
|
83
105
|
},
|
|
84
106
|
"engines": {
|
|
85
107
|
"node": ">=14.18"
|
|
@@ -88,11 +110,9 @@
|
|
|
88
110
|
"url": "https://github.com/aymericzip/intlayer/issues"
|
|
89
111
|
},
|
|
90
112
|
"scripts": {
|
|
91
|
-
"build": "
|
|
92
|
-
"build:package": "tsup",
|
|
93
|
-
"build:types": "tsc --project ./tsconfig.types.json && tsc-alias --project ./tsconfig.types.json",
|
|
113
|
+
"build": "vite build",
|
|
94
114
|
"clean": "rimraf ./dist",
|
|
95
|
-
"dev": "
|
|
115
|
+
"dev": "vite build --watch",
|
|
96
116
|
"lint": "eslint . --cache",
|
|
97
117
|
"lint:fix": "eslint . --cache --fix",
|
|
98
118
|
"prettier": "prettier . --check",
|
package/dist/cjs/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './intlayerPlugin';\nexport * from './intlayerMiddlewarePlugin';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,6BAAd;AACA,0BAAc,uCADd;","names":[]}
|
|
@@ -1,224 +0,0 @@
|
|
|
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 intlayerMiddlewarePlugin_exports = {};
|
|
20
|
-
__export(intlayerMiddlewarePlugin_exports, {
|
|
21
|
-
intLayerMiddlewarePlugin: () => intLayerMiddlewarePlugin
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(intlayerMiddlewarePlugin_exports);
|
|
24
|
-
var import_url = require("url");
|
|
25
|
-
var import_config = require("@intlayer/config");
|
|
26
|
-
var import_core = require("@intlayer/core");
|
|
27
|
-
const intlayerConfig = (0, import_config.getConfiguration)();
|
|
28
|
-
const { internationalization, middleware } = intlayerConfig;
|
|
29
|
-
const { locales: supportedLocales, defaultLocale } = internationalization;
|
|
30
|
-
const {
|
|
31
|
-
cookieName,
|
|
32
|
-
headerName,
|
|
33
|
-
prefixDefault,
|
|
34
|
-
noPrefix,
|
|
35
|
-
serverSetCookie,
|
|
36
|
-
basePath = ""
|
|
37
|
-
} = middleware;
|
|
38
|
-
const intLayerMiddlewarePlugin = () => {
|
|
39
|
-
return {
|
|
40
|
-
name: "vite-intlayer-middleware-plugin",
|
|
41
|
-
configureServer: (server) => {
|
|
42
|
-
server.middlewares.use((req, res, next) => {
|
|
43
|
-
if (req.url?.startsWith("/node_modules") || req.url?.startsWith("/@") || req.url?.split("?")[0].match(/\.[a-z]+$/i)) {
|
|
44
|
-
return next();
|
|
45
|
-
}
|
|
46
|
-
const parsedUrl = (0, import_url.parse)(req.url ?? "/", true);
|
|
47
|
-
const originalPath = parsedUrl.pathname ?? "/";
|
|
48
|
-
const cookies = parseCookies(req.headers.cookie ?? "");
|
|
49
|
-
const cookieLocale = getValidLocaleFromCookie(cookies[cookieName]);
|
|
50
|
-
const pathLocale = getPathLocale(originalPath);
|
|
51
|
-
if (noPrefix) {
|
|
52
|
-
handleNoPrefix({
|
|
53
|
-
req,
|
|
54
|
-
res,
|
|
55
|
-
next,
|
|
56
|
-
originalPath,
|
|
57
|
-
cookieLocale
|
|
58
|
-
});
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
handlePrefix({
|
|
62
|
-
req,
|
|
63
|
-
res,
|
|
64
|
-
next,
|
|
65
|
-
originalPath,
|
|
66
|
-
pathLocale,
|
|
67
|
-
cookieLocale
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
const parseCookies = (cookieHeader) => {
|
|
74
|
-
return cookieHeader.split(";").reduce(
|
|
75
|
-
(acc, cookie) => {
|
|
76
|
-
const [key, val] = cookie.trim().split("=");
|
|
77
|
-
acc[key] = val;
|
|
78
|
-
return acc;
|
|
79
|
-
},
|
|
80
|
-
{}
|
|
81
|
-
);
|
|
82
|
-
};
|
|
83
|
-
const getValidLocaleFromCookie = (locale) => {
|
|
84
|
-
if (locale && supportedLocales.includes(locale)) {
|
|
85
|
-
return locale;
|
|
86
|
-
}
|
|
87
|
-
return void 0;
|
|
88
|
-
};
|
|
89
|
-
const getPathLocale = (pathname) => {
|
|
90
|
-
const segments = pathname.split("/").filter(Boolean);
|
|
91
|
-
const firstSegment = segments[0];
|
|
92
|
-
if (firstSegment && supportedLocales.includes(firstSegment)) {
|
|
93
|
-
return firstSegment;
|
|
94
|
-
}
|
|
95
|
-
return void 0;
|
|
96
|
-
};
|
|
97
|
-
const redirectUrl = (res, newUrl) => {
|
|
98
|
-
res.writeHead(301, { Location: newUrl });
|
|
99
|
-
return res.end();
|
|
100
|
-
};
|
|
101
|
-
const rewriteUrl = (req, res, newUrl, locale) => {
|
|
102
|
-
req.url = newUrl;
|
|
103
|
-
if (locale && headerName) {
|
|
104
|
-
res.setHeader(headerName, locale);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const constructPath = (locale, currentPath) => {
|
|
108
|
-
const cleanBasePath = basePath.startsWith("/") ? basePath : `/${basePath}`;
|
|
109
|
-
const normalizedBasePath = cleanBasePath === "/" ? "" : cleanBasePath;
|
|
110
|
-
let newPath = `${normalizedBasePath}/${locale}${currentPath}`;
|
|
111
|
-
if (!prefixDefault && locale === defaultLocale) {
|
|
112
|
-
newPath = `${normalizedBasePath}${currentPath}`;
|
|
113
|
-
}
|
|
114
|
-
return newPath;
|
|
115
|
-
};
|
|
116
|
-
const handleNoPrefix = ({
|
|
117
|
-
req,
|
|
118
|
-
res,
|
|
119
|
-
next,
|
|
120
|
-
originalPath,
|
|
121
|
-
cookieLocale
|
|
122
|
-
}) => {
|
|
123
|
-
let locale = cookieLocale ?? defaultLocale;
|
|
124
|
-
if (!cookieLocale) {
|
|
125
|
-
const detectedLocale = (0, import_core.localeDetector)(
|
|
126
|
-
req.headers,
|
|
127
|
-
supportedLocales,
|
|
128
|
-
defaultLocale
|
|
129
|
-
);
|
|
130
|
-
locale = detectedLocale;
|
|
131
|
-
}
|
|
132
|
-
rewriteUrl(req, res, originalPath, locale);
|
|
133
|
-
return next();
|
|
134
|
-
};
|
|
135
|
-
const handlePrefix = ({
|
|
136
|
-
req,
|
|
137
|
-
res,
|
|
138
|
-
next,
|
|
139
|
-
originalPath,
|
|
140
|
-
pathLocale,
|
|
141
|
-
cookieLocale
|
|
142
|
-
}) => {
|
|
143
|
-
if (!pathLocale) {
|
|
144
|
-
handleMissingPathLocale({
|
|
145
|
-
req,
|
|
146
|
-
res,
|
|
147
|
-
next,
|
|
148
|
-
originalPath,
|
|
149
|
-
cookieLocale
|
|
150
|
-
});
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
handleExistingPathLocale({
|
|
154
|
-
req,
|
|
155
|
-
res,
|
|
156
|
-
next,
|
|
157
|
-
originalPath,
|
|
158
|
-
pathLocale,
|
|
159
|
-
cookieLocale
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
const handleMissingPathLocale = ({
|
|
163
|
-
req,
|
|
164
|
-
res,
|
|
165
|
-
next,
|
|
166
|
-
originalPath,
|
|
167
|
-
cookieLocale
|
|
168
|
-
}) => {
|
|
169
|
-
let locale = cookieLocale ?? (0, import_core.localeDetector)(
|
|
170
|
-
req.headers,
|
|
171
|
-
supportedLocales,
|
|
172
|
-
defaultLocale
|
|
173
|
-
);
|
|
174
|
-
if (!supportedLocales.includes(locale)) {
|
|
175
|
-
locale = defaultLocale;
|
|
176
|
-
}
|
|
177
|
-
const newPath = constructPath(locale, originalPath);
|
|
178
|
-
if (prefixDefault || locale !== defaultLocale) {
|
|
179
|
-
return redirectUrl(res, newPath);
|
|
180
|
-
}
|
|
181
|
-
rewriteUrl(req, res, newPath, locale);
|
|
182
|
-
return next();
|
|
183
|
-
};
|
|
184
|
-
const handleExistingPathLocale = ({
|
|
185
|
-
req,
|
|
186
|
-
res,
|
|
187
|
-
next,
|
|
188
|
-
originalPath,
|
|
189
|
-
pathLocale,
|
|
190
|
-
cookieLocale
|
|
191
|
-
}) => {
|
|
192
|
-
if (cookieLocale && cookieLocale !== pathLocale && serverSetCookie !== "always") {
|
|
193
|
-
const newPath = originalPath.replace(`/${pathLocale}`, `/${cookieLocale}`);
|
|
194
|
-
const finalPath = constructPath(cookieLocale, newPath.replace(/^\/+/, "/"));
|
|
195
|
-
return redirectUrl(res, finalPath);
|
|
196
|
-
}
|
|
197
|
-
handleDefaultLocaleRedirect({
|
|
198
|
-
req,
|
|
199
|
-
res,
|
|
200
|
-
next,
|
|
201
|
-
originalPath,
|
|
202
|
-
pathLocale
|
|
203
|
-
});
|
|
204
|
-
};
|
|
205
|
-
const handleDefaultLocaleRedirect = ({
|
|
206
|
-
req,
|
|
207
|
-
res,
|
|
208
|
-
next,
|
|
209
|
-
originalPath,
|
|
210
|
-
pathLocale
|
|
211
|
-
}) => {
|
|
212
|
-
if (!prefixDefault && pathLocale === defaultLocale) {
|
|
213
|
-
const newPath = originalPath.replace(`/${defaultLocale}`, "") ?? "/";
|
|
214
|
-
rewriteUrl(req, res, newPath, pathLocale);
|
|
215
|
-
return next();
|
|
216
|
-
}
|
|
217
|
-
rewriteUrl(req, res, originalPath, pathLocale);
|
|
218
|
-
return next();
|
|
219
|
-
};
|
|
220
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
221
|
-
0 && (module.exports = {
|
|
222
|
-
intLayerMiddlewarePlugin
|
|
223
|
-
});
|
|
224
|
-
//# sourceMappingURL=intlayerMiddlewarePlugin.cjs.map
|