svelte-intlayer 8.6.2 → 8.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/intlayerStore.js +2 -3
- package/dist/client/setupIntlayer.svelte.js +4 -2
- package/dist/client/useLocale.js +2 -2
- package/dist/client/useRewriteURL.js +2 -2
- package/dist/editor/useEditor.js +2 -1
- package/dist/html/HTMLWithSelector.svelte +14 -0
- package/dist/html/HTMLWithSelector.svelte.d.ts +24 -0
- package/dist/plugins.js +39 -14
- package/package.json +6 -6
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { internationalization } from '@intlayer/config/built';
|
|
2
2
|
import { derived, writable } from 'svelte/store';
|
|
3
|
-
const defaultLocale =
|
|
4
|
-
?.defaultLocale;
|
|
3
|
+
const defaultLocale = internationalization?.defaultLocale;
|
|
5
4
|
// Create the main intlayer store
|
|
6
5
|
const createIntlayerStore = () => {
|
|
7
6
|
const { subscribe, set, update } = writable({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { internationalization } from '@intlayer/config/built';
|
|
2
|
+
import { setIntlayerIdentifier } from '@intlayer/config/client';
|
|
2
3
|
import { useEditor } from '../editor/useEditor';
|
|
3
4
|
import { setIntlayerContext } from './intlayerContext';
|
|
4
5
|
import { intlayerStore } from './intlayerStore';
|
|
@@ -20,6 +21,7 @@ import { intlayerStore } from './intlayerStore';
|
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
23
|
export const setupIntlayer = (initialLocale) => {
|
|
24
|
+
setIntlayerIdentifier();
|
|
23
25
|
useEditor();
|
|
24
26
|
// Create Reactive State (Svelte 5)
|
|
25
27
|
// We make the locale a "rune" so updates propagate
|
|
@@ -31,7 +33,7 @@ export const setupIntlayer = (initialLocale) => {
|
|
|
31
33
|
// Define the Context Object
|
|
32
34
|
const contextValue = {
|
|
33
35
|
get locale() {
|
|
34
|
-
return locale ??
|
|
36
|
+
return locale ?? internationalization.defaultLocale;
|
|
35
37
|
},
|
|
36
38
|
setLocale: (newLocale) => {
|
|
37
39
|
locale = newLocale;
|
package/dist/client/useLocale.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { internationalization } from '@intlayer/config/built';
|
|
2
2
|
import { derived } from 'svelte/store';
|
|
3
3
|
import { getIntlayerContext } from './intlayerContext';
|
|
4
4
|
import { intlayerStore } from './intlayerStore';
|
|
@@ -25,7 +25,7 @@ import { setLocaleInStorage } from './useLocaleStorage';
|
|
|
25
25
|
*/
|
|
26
26
|
export const useLocale = ({ isCookieEnabled, onLocaleChange, } = {}) => {
|
|
27
27
|
const context = getIntlayerContext();
|
|
28
|
-
const { defaultLocale, locales: availableLocales } =
|
|
28
|
+
const { defaultLocale, locales: availableLocales } = internationalization ?? {};
|
|
29
29
|
if (context) {
|
|
30
30
|
// Use context if available
|
|
31
31
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { routing } from '@intlayer/config/built';
|
|
2
2
|
import { getRewritePath } from '@intlayer/core/localization';
|
|
3
3
|
import { useLocale } from './useLocale';
|
|
4
4
|
/**
|
|
@@ -7,7 +7,7 @@ import { useLocale } from './useLocale';
|
|
|
7
7
|
*/
|
|
8
8
|
export const useRewriteURL = () => {
|
|
9
9
|
const { locale } = useLocale();
|
|
10
|
-
const rewrite =
|
|
10
|
+
const rewrite = routing?.rewrite;
|
|
11
11
|
if (typeof window !== 'undefined') {
|
|
12
12
|
// We observe locale changes
|
|
13
13
|
locale.subscribe(($locale) => {
|
package/dist/editor/useEditor.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isEnabled } from '@intlayer/editor/isEnabled';
|
|
2
2
|
import { onDestroy, onMount } from 'svelte';
|
|
3
3
|
import { intlayerStore } from '../client/intlayerStore';
|
|
4
|
+
const TREE_SHAKE_EDITOR = process.env['INTLAYER_EDITOR_ENABLED'] === 'false';
|
|
4
5
|
/**
|
|
5
6
|
* Initialises the Intlayer editor client singleton when the editor is enabled.
|
|
6
7
|
* Syncs the current locale from intlayerStore into the editor manager so the
|
|
@@ -11,7 +12,7 @@ import { intlayerStore } from '../client/intlayerStore';
|
|
|
11
12
|
* direct access to the Svelte 5 rune state.
|
|
12
13
|
*/
|
|
13
14
|
export const useEditor = () => {
|
|
14
|
-
if (!isEnabled)
|
|
15
|
+
if (TREE_SHAKE_EDITOR || !isEnabled)
|
|
15
16
|
return;
|
|
16
17
|
let unsubscribeLocale = null;
|
|
17
18
|
onMount(() => {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { KeyPath } from '@intlayer/types/keyPath';
|
|
3
|
+
import ContentSelector from '../editor/ContentSelector.svelte';
|
|
4
|
+
import HTMLRenderer from './HTMLRenderer.svelte';
|
|
5
|
+
|
|
6
|
+
export let dictionaryKey: string;
|
|
7
|
+
export let keyPath: KeyPath[];
|
|
8
|
+
export let value: string;
|
|
9
|
+
export let components: any = {};
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<ContentSelector {dictionaryKey} {keyPath}>
|
|
13
|
+
<HTMLRenderer {value} {components} />
|
|
14
|
+
</ContentSelector>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { KeyPath } from '@intlayer/types/keyPath';
|
|
2
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
+
$$bindings?: Bindings;
|
|
5
|
+
} & Exports;
|
|
6
|
+
(internal: unknown, props: Props & {
|
|
7
|
+
$$events?: Events;
|
|
8
|
+
$$slots?: Slots;
|
|
9
|
+
}): Exports & {
|
|
10
|
+
$set?: any;
|
|
11
|
+
$on?: any;
|
|
12
|
+
};
|
|
13
|
+
z_$$bindings?: Bindings;
|
|
14
|
+
}
|
|
15
|
+
declare const HTMLWithSelector: $$__sveltets_2_IsomorphicComponent<{
|
|
16
|
+
dictionaryKey: string;
|
|
17
|
+
keyPath: KeyPath[];
|
|
18
|
+
value: string;
|
|
19
|
+
components?: any;
|
|
20
|
+
}, {
|
|
21
|
+
[evt: string]: CustomEvent<any>;
|
|
22
|
+
}, {}, {}, string>;
|
|
23
|
+
type HTMLWithSelector = InstanceType<typeof HTMLWithSelector>;
|
|
24
|
+
export default HTMLWithSelector;
|
package/dist/plugins.js
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { editor, internationalization } from '@intlayer/config/built';
|
|
2
2
|
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, nestedPlugin, translationPlugin, } from '@intlayer/core/interpreter';
|
|
3
3
|
import * as NodeTypes from '@intlayer/types/nodeType';
|
|
4
4
|
import { default as ContentSelector } from './editor/ContentSelector.svelte';
|
|
5
5
|
import { HTMLRenderer } from './html/index';
|
|
6
6
|
import { renderIntlayerNode } from './renderIntlayerNode';
|
|
7
|
+
// ── Tree-shake constants ──────────────────────────────────────────────────────
|
|
8
|
+
// When these env vars are injected at build time, bundlers eliminate the
|
|
9
|
+
// branches guarded by these constants.
|
|
10
|
+
/**
|
|
11
|
+
* True when the intlayer node type is explicitly disabled at build time.
|
|
12
|
+
*/
|
|
13
|
+
const TREE_SHAKE_INTLAYER_NODE = process.env['INTLAYER_NODE_TYPE_INTLAYER_NODE'] === 'false';
|
|
14
|
+
/**
|
|
15
|
+
* True when the markdown node type is explicitly disabled at build time.
|
|
16
|
+
*/
|
|
17
|
+
const TREE_SHAKE_MARKDOWN = process.env['INTLAYER_NODE_TYPE_MARKDOWN'] === 'false';
|
|
18
|
+
/**
|
|
19
|
+
* True when the HTML node type is explicitly disabled at build time.
|
|
20
|
+
*/
|
|
21
|
+
const TREE_SHAKE_HTML = process.env['INTLAYER_NODE_TYPE_HTML'] === 'false';
|
|
22
|
+
/**
|
|
23
|
+
* True when the insertion node type is explicitly disabled at build time.
|
|
24
|
+
*/
|
|
25
|
+
const TREE_SHAKE_INSERTION = process.env['INTLAYER_NODE_TYPE_INSERTION'] === 'false';
|
|
26
|
+
/**
|
|
27
|
+
* True when the editor is explicitly disabled at build time.
|
|
28
|
+
*/
|
|
29
|
+
const TREE_SHAKE_EDITOR = process.env['INTLAYER_EDITOR_ENABLED'] === 'false';
|
|
7
30
|
// Lazy pre-load heavy modules — creates separate code-split chunks
|
|
8
31
|
let _getMarkdownMetadata = null;
|
|
9
32
|
let _compile = null;
|
|
@@ -16,18 +39,20 @@ let _MarkdownMetadataWithSelector = null;
|
|
|
16
39
|
let _MarkdownRenderer = null;
|
|
17
40
|
let _MarkdownWithSelector = null;
|
|
18
41
|
let _svelteHtmlRuntime = null;
|
|
42
|
+
let _HTMLWithSelector = null;
|
|
19
43
|
void Promise.all([
|
|
20
44
|
import('./markdown/MarkdownMetadataRenderer.svelte').then((m) => (_MarkdownMetadataRenderer = m.default)),
|
|
21
45
|
import('./markdown/MarkdownMetadataWithSelector.svelte').then((m) => (_MarkdownMetadataWithSelector = m.default)),
|
|
22
46
|
import('./markdown/MarkdownRenderer.svelte').then((m) => (_MarkdownRenderer = m.default)),
|
|
23
47
|
import('./markdown/MarkdownWithSelector.svelte').then((m) => (_MarkdownWithSelector = m.default)),
|
|
48
|
+
import('./html/HTMLWithSelector.svelte').then((m) => (_HTMLWithSelector = m.default)),
|
|
24
49
|
import('./markdown/runtime').then((m) => (_svelteHtmlRuntime = m.svelteHtmlRuntime)),
|
|
25
50
|
]);
|
|
26
51
|
/**
|
|
27
52
|
* Basic Intlayer node plugins for content handling
|
|
28
53
|
* These handle the core content transformation logic
|
|
29
54
|
*/
|
|
30
|
-
export const intlayerNodePlugins =
|
|
55
|
+
export const intlayerNodePlugins = TREE_SHAKE_INTLAYER_NODE
|
|
31
56
|
? fallbackPlugin
|
|
32
57
|
: {
|
|
33
58
|
id: 'intlayer-node-plugin',
|
|
@@ -36,9 +61,7 @@ export const intlayerNodePlugins = process.env.INTLAYER_NODE_TYPE_INTLAYER_NODE
|
|
|
36
61
|
typeof node === 'number',
|
|
37
62
|
transform: (node, { children, ...rest }) => renderIntlayerNode({
|
|
38
63
|
value: children ?? node,
|
|
39
|
-
component:
|
|
40
|
-
? ContentSelector
|
|
41
|
-
: undefined,
|
|
64
|
+
component: !TREE_SHAKE_EDITOR && editor.enabled ? ContentSelector : undefined,
|
|
42
65
|
props: rest,
|
|
43
66
|
}),
|
|
44
67
|
};
|
|
@@ -97,7 +120,7 @@ const splitAndJoinInsertion = (template, values) => {
|
|
|
97
120
|
return parts;
|
|
98
121
|
};
|
|
99
122
|
/** Insertion plugin for Svelte. Handles component insertion. */
|
|
100
|
-
export const insertionPlugin =
|
|
123
|
+
export const insertionPlugin = TREE_SHAKE_INSERTION
|
|
101
124
|
? fallbackPlugin
|
|
102
125
|
: {
|
|
103
126
|
id: 'insertion-plugin',
|
|
@@ -155,7 +178,7 @@ export const insertionPlugin = process.env.INTLAYER_NODE_TYPE_INSERTION === 'fal
|
|
|
155
178
|
},
|
|
156
179
|
};
|
|
157
180
|
/** Markdown string plugin. Replaces string node with a component that render the markdown. */
|
|
158
|
-
export const markdownStringPlugin =
|
|
181
|
+
export const markdownStringPlugin = TREE_SHAKE_MARKDOWN
|
|
159
182
|
? fallbackPlugin
|
|
160
183
|
: {
|
|
161
184
|
id: 'markdown-string-plugin',
|
|
@@ -171,7 +194,7 @@ export const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN ===
|
|
|
171
194
|
!metadataNode,
|
|
172
195
|
transform: (metadataNode, props) => renderIntlayerNode({
|
|
173
196
|
value: metadataNode,
|
|
174
|
-
component:
|
|
197
|
+
component: !TREE_SHAKE_EDITOR && editor.enabled
|
|
175
198
|
? (_MarkdownMetadataWithSelector ?? _MarkdownMetadataRenderer)
|
|
176
199
|
: _MarkdownMetadataRenderer,
|
|
177
200
|
props: {
|
|
@@ -190,7 +213,7 @@ export const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN ===
|
|
|
190
213
|
const render = (components) => {
|
|
191
214
|
const nodeResult = renderIntlayerNode({
|
|
192
215
|
value: node,
|
|
193
|
-
component:
|
|
216
|
+
component: !TREE_SHAKE_EDITOR && editor.enabled
|
|
194
217
|
? (_MarkdownWithSelector ?? _MarkdownRenderer)
|
|
195
218
|
: _MarkdownRenderer,
|
|
196
219
|
props: {
|
|
@@ -223,7 +246,7 @@ export const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN ===
|
|
|
223
246
|
return render();
|
|
224
247
|
},
|
|
225
248
|
};
|
|
226
|
-
export const markdownPlugin =
|
|
249
|
+
export const markdownPlugin = TREE_SHAKE_MARKDOWN
|
|
227
250
|
? fallbackPlugin
|
|
228
251
|
: {
|
|
229
252
|
id: 'markdown-plugin',
|
|
@@ -245,7 +268,7 @@ export const markdownPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false
|
|
|
245
268
|
},
|
|
246
269
|
};
|
|
247
270
|
/** HTML plugin. Replaces node with a function that takes components => HTMLElement[]. */
|
|
248
|
-
export const htmlPlugin =
|
|
271
|
+
export const htmlPlugin = TREE_SHAKE_HTML
|
|
249
272
|
? fallbackPlugin
|
|
250
273
|
: {
|
|
251
274
|
id: 'html-plugin',
|
|
@@ -257,7 +280,9 @@ export const htmlPlugin = process.env.INTLAYER_NODE_TYPE_HTML === 'false'
|
|
|
257
280
|
const render = (userComponents = {}) => renderIntlayerNode({
|
|
258
281
|
...props,
|
|
259
282
|
value: htmlString,
|
|
260
|
-
component:
|
|
283
|
+
component: !TREE_SHAKE_EDITOR && editor.enabled
|
|
284
|
+
? (_HTMLWithSelector ?? HTMLRenderer)
|
|
285
|
+
: HTMLRenderer,
|
|
261
286
|
props: {
|
|
262
287
|
...props,
|
|
263
288
|
value: htmlString,
|
|
@@ -275,10 +300,10 @@ export const htmlPlugin = process.env.INTLAYER_NODE_TYPE_HTML === 'false'
|
|
|
275
300
|
* This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.
|
|
276
301
|
*/
|
|
277
302
|
export const getPlugins = (locale, fallback = true) => [
|
|
278
|
-
translationPlugin(locale ??
|
|
303
|
+
translationPlugin(locale ?? internationalization.defaultLocale, fallback ? internationalization.defaultLocale : undefined),
|
|
279
304
|
enumerationPlugin,
|
|
280
305
|
conditionPlugin,
|
|
281
|
-
nestedPlugin(locale ??
|
|
306
|
+
nestedPlugin(locale ?? internationalization.defaultLocale),
|
|
282
307
|
filePlugin,
|
|
283
308
|
genderPlugin,
|
|
284
309
|
intlayerNodePlugins,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-intlayer",
|
|
3
|
-
"version": "8.6.
|
|
3
|
+
"version": "8.6.4",
|
|
4
4
|
"description": "Easily internationalize i18n your Svelte applications with type-safe multilingual content management.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intlayer",
|
|
@@ -82,11 +82,11 @@
|
|
|
82
82
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@intlayer/api": "8.6.
|
|
86
|
-
"@intlayer/config": "8.6.
|
|
87
|
-
"@intlayer/core": "8.6.
|
|
88
|
-
"@intlayer/editor": "8.6.
|
|
89
|
-
"@intlayer/types": "8.6.
|
|
85
|
+
"@intlayer/api": "8.6.4",
|
|
86
|
+
"@intlayer/config": "8.6.4",
|
|
87
|
+
"@intlayer/core": "8.6.4",
|
|
88
|
+
"@intlayer/editor": "8.6.4",
|
|
89
|
+
"@intlayer/types": "8.6.4"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@sveltejs/adapter-auto": "7.0.1",
|