svelte-intlayer 8.5.2 → 8.6.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/IntlayerNodeWrapper.svelte +2 -3
- package/dist/client/useLocaleStorage.js +3 -3
- package/dist/format/useNumber.d.ts +1 -1
- package/dist/format/usePercentage.d.ts +1 -1
- package/dist/html/index.d.ts +1 -1
- package/dist/html/index.js +39 -1
- package/dist/plugins.d.ts +3 -0
- package/dist/plugins.js +20 -84
- package/package.json +9 -9
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { localeStorageOptions } from '@intlayer/core/localization';
|
|
2
|
-
import {
|
|
2
|
+
import { getLocaleFromStorageClient, LocaleStorageClient, setLocaleInStorageClient as setLocaleInStorageCore, } from '@intlayer/core/utils';
|
|
3
3
|
import { readable } from 'svelte/store';
|
|
4
4
|
/**
|
|
5
5
|
* Get the locale cookie
|
|
6
6
|
*/
|
|
7
|
-
export const localeInStorage =
|
|
7
|
+
export const localeInStorage = getLocaleFromStorageClient(localeStorageOptions);
|
|
8
8
|
/**
|
|
9
9
|
* @deprecated Use localeInStorage instead
|
|
10
10
|
*
|
|
@@ -28,7 +28,7 @@ export const setLocaleCookie = setLocaleInStorage;
|
|
|
28
28
|
* Composable that provides the locale storage and a function to set it
|
|
29
29
|
*/
|
|
30
30
|
export const useLocaleStorage = (isCookieEnabled) => {
|
|
31
|
-
const storage =
|
|
31
|
+
const storage = LocaleStorageClient({
|
|
32
32
|
...localeStorageOptions,
|
|
33
33
|
isCookieEnabled,
|
|
34
34
|
});
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* @returns {import('svelte/store').Readable<(...args: Parameters<typeof number>) => string>}
|
|
5
5
|
* A store containing a number formatting function bound to the active locale.
|
|
6
6
|
*/
|
|
7
|
-
export declare const useNumber: () => import("svelte/store").Readable<(value: string | number,
|
|
7
|
+
export declare const useNumber: () => import("svelte/store").Readable<(value: string | number, args_1?: (Intl.NumberFormatOptions & {
|
|
8
8
|
locale?: import("@intlayer/types/module_augmentation").LocalesValues;
|
|
9
9
|
}) | undefined) => string>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const usePercentage: () => import("svelte/store").Readable<(value: string | number,
|
|
1
|
+
export declare const usePercentage: () => import("svelte/store").Readable<(value: string | number, args_1?: (Intl.NumberFormatOptions & {
|
|
2
2
|
locale?: import("@intlayer/types/module_augmentation").LocalesValues;
|
|
3
3
|
}) | undefined) => string>;
|
package/dist/html/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type RenderHTMLOptions } from './context';
|
|
2
|
-
export { getHTMLContext, type
|
|
2
|
+
export { getHTMLContext, type RenderHTMLOptions, setHTMLContext, setHTMLContext as setIntlayerHTML, } from './context';
|
|
3
3
|
export { default as HTMLProvider } from './HTMLProvider.svelte';
|
|
4
4
|
export { default as HTMLRenderer } from './HTMLRenderer.svelte';
|
|
5
5
|
export type RenderHTMLProps = RenderHTMLOptions;
|
package/dist/html/index.js
CHANGED
|
@@ -4,7 +4,45 @@ export { getHTMLContext, setHTMLContext, setHTMLContext as setIntlayerHTML, } fr
|
|
|
4
4
|
export { default as HTMLProvider } from './HTMLProvider.svelte';
|
|
5
5
|
export { default as HTMLRenderer } from './HTMLRenderer.svelte';
|
|
6
6
|
export const renderHTML = (html, options = {}) => {
|
|
7
|
-
|
|
7
|
+
const components = options.components || {};
|
|
8
|
+
// Proxy handles standard HTML tags lazily without a hardcoded list
|
|
9
|
+
const wrappedComponents = new Proxy(components, {
|
|
10
|
+
get(target, prop) {
|
|
11
|
+
if (typeof prop === 'string' && prop in target) {
|
|
12
|
+
return target[prop];
|
|
13
|
+
}
|
|
14
|
+
// Fallback: Lazily generate a wrapper for standard lowercase HTML tags
|
|
15
|
+
if (typeof prop === 'string' &&
|
|
16
|
+
/^[a-z][a-z0-9]*$/.test(prop) &&
|
|
17
|
+
typeof document !== 'undefined') {
|
|
18
|
+
return ({ children = [], ...props }) => {
|
|
19
|
+
const element = document.createElement(prop);
|
|
20
|
+
// Apply props as attributes
|
|
21
|
+
for (const [key, value] of Object.entries(props)) {
|
|
22
|
+
if (key.startsWith('on') && typeof value === 'function') {
|
|
23
|
+
const eventName = key.slice(2).toLowerCase();
|
|
24
|
+
element.addEventListener(eventName, value);
|
|
25
|
+
}
|
|
26
|
+
else if (value !== undefined && value !== null) {
|
|
27
|
+
element.setAttribute(key, String(value));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Append children
|
|
31
|
+
for (const child of children) {
|
|
32
|
+
if (typeof child === 'string') {
|
|
33
|
+
element.appendChild(document.createTextNode(child));
|
|
34
|
+
}
|
|
35
|
+
else if (child instanceof Node) {
|
|
36
|
+
element.appendChild(child);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return element;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
return getHTML(html, wrappedComponents);
|
|
8
46
|
};
|
|
9
47
|
export const useHTMLRenderer = (options = {}) => {
|
|
10
48
|
const context = getHTMLContext();
|
package/dist/plugins.d.ts
CHANGED
|
@@ -60,6 +60,9 @@ export type MarkdownCond<T, _S, L extends LocalesValues> = T extends {
|
|
|
60
60
|
metadata: DeepTransformContent<U, L>;
|
|
61
61
|
} & any : never;
|
|
62
62
|
export declare const markdownPlugin: Plugins;
|
|
63
|
+
/** ---------------------------------------------
|
|
64
|
+
* HTML PLUGIN
|
|
65
|
+
* --------------------------------------------- */
|
|
63
66
|
export type HTMLPluginCond<T> = T extends {
|
|
64
67
|
nodeType: NodeType | string;
|
|
65
68
|
[NodeTypes.HTML]: infer I;
|
package/dist/plugins.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import configuration from '@intlayer/config/built';
|
|
2
|
-
import { conditionPlugin, enumerationPlugin, filePlugin, genderPlugin,
|
|
3
|
-
import { HTML_TAGS, } from '@intlayer/core/transpiler';
|
|
4
|
-
import { isEnabled } from '@intlayer/editor/isEnabled';
|
|
2
|
+
import { conditionPlugin, enumerationPlugin, filePlugin, genderPlugin, nestedPlugin, translationPlugin, } from '@intlayer/core/interpreter';
|
|
5
3
|
import * as NodeTypes from '@intlayer/types/nodeType';
|
|
6
4
|
import { default as ContentSelector } from './editor/ContentSelector.svelte';
|
|
5
|
+
import { HTMLRenderer } from './html/index';
|
|
7
6
|
import { renderIntlayerNode } from './renderIntlayerNode';
|
|
8
7
|
// Lazy pre-load heavy modules — creates separate code-split chunks
|
|
9
8
|
let _getMarkdownMetadata = null;
|
|
@@ -35,7 +34,7 @@ export const intlayerNodePlugins = {
|
|
|
35
34
|
typeof node === 'number',
|
|
36
35
|
transform: (node, { children, ...rest }) => renderIntlayerNode({
|
|
37
36
|
value: children ?? node,
|
|
38
|
-
component:
|
|
37
|
+
component: configuration.editor.enabled ? ContentSelector : undefined,
|
|
39
38
|
props: rest,
|
|
40
39
|
}),
|
|
41
40
|
};
|
|
@@ -164,7 +163,7 @@ export const markdownStringPlugin = {
|
|
|
164
163
|
!metadataNode,
|
|
165
164
|
transform: (metadataNode, props) => renderIntlayerNode({
|
|
166
165
|
value: metadataNode,
|
|
167
|
-
component:
|
|
166
|
+
component: configuration.editor.enabled
|
|
168
167
|
? (_MarkdownMetadataWithSelector ?? _MarkdownMetadataRenderer)
|
|
169
168
|
: _MarkdownMetadataRenderer,
|
|
170
169
|
props: {
|
|
@@ -183,7 +182,7 @@ export const markdownStringPlugin = {
|
|
|
183
182
|
const render = (components) => {
|
|
184
183
|
const nodeResult = renderIntlayerNode({
|
|
185
184
|
value: node,
|
|
186
|
-
component:
|
|
185
|
+
component: configuration.editor.enabled
|
|
187
186
|
? (_MarkdownWithSelector ?? _MarkdownRenderer)
|
|
188
187
|
: _MarkdownRenderer,
|
|
189
188
|
props: {
|
|
@@ -235,90 +234,27 @@ export const markdownPlugin = {
|
|
|
235
234
|
});
|
|
236
235
|
},
|
|
237
236
|
};
|
|
238
|
-
/**
|
|
239
|
-
* Create default HTML tag components using DOM API.
|
|
240
|
-
* Each component creates the corresponding HTML element with its props and children.
|
|
241
|
-
* Note: This approach works in browser environments.
|
|
242
|
-
*/
|
|
243
|
-
const createDefaultHTMLComponents = () => {
|
|
244
|
-
const components = {};
|
|
245
|
-
for (const tag of HTML_TAGS) {
|
|
246
|
-
components[tag] = ({ children = [], ...props }) => {
|
|
247
|
-
const element = document.createElement(tag);
|
|
248
|
-
// Apply props as attributes
|
|
249
|
-
for (const [key, value] of Object.entries(props)) {
|
|
250
|
-
if (key.startsWith('on') && typeof value === 'function') {
|
|
251
|
-
// Handle event listeners
|
|
252
|
-
const eventName = key.slice(2).toLowerCase();
|
|
253
|
-
element.addEventListener(eventName, value);
|
|
254
|
-
}
|
|
255
|
-
else if (value !== undefined && value !== null) {
|
|
256
|
-
element.setAttribute(key, String(value));
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
// Append children
|
|
260
|
-
for (const child of children) {
|
|
261
|
-
if (typeof child === 'string') {
|
|
262
|
-
element.appendChild(document.createTextNode(child));
|
|
263
|
-
}
|
|
264
|
-
else if (child instanceof Node) {
|
|
265
|
-
element.appendChild(child);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return element;
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
return components;
|
|
272
|
-
};
|
|
273
|
-
let defaultHTMLComponents = null;
|
|
274
|
-
const getDefaultHTMLComponents = () => {
|
|
275
|
-
if (typeof document === 'undefined') {
|
|
276
|
-
// SSR fallback: return empty object, user must provide all components
|
|
277
|
-
return {};
|
|
278
|
-
}
|
|
279
|
-
if (!defaultHTMLComponents) {
|
|
280
|
-
defaultHTMLComponents = createDefaultHTMLComponents();
|
|
281
|
-
}
|
|
282
|
-
return defaultHTMLComponents;
|
|
283
|
-
};
|
|
284
237
|
/** HTML plugin. Replaces node with a function that takes components => HTMLElement[]. */
|
|
285
238
|
export const htmlPlugin = {
|
|
286
239
|
id: 'html-plugin',
|
|
287
240
|
canHandle: (node) => typeof node === 'object' && node?.nodeType === NodeTypes.HTML,
|
|
288
|
-
transform: (node) => {
|
|
241
|
+
transform: (node, props) => {
|
|
289
242
|
const htmlString = node[NodeTypes.HTML];
|
|
290
243
|
const _tags = node.tags ?? [];
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
return typeof result === 'string'
|
|
306
|
-
? result
|
|
307
|
-
: result.outerHTML || String(result);
|
|
308
|
-
};
|
|
309
|
-
const target = typeof result === 'object' && result !== null ? result : {};
|
|
310
|
-
return new Proxy(target, {
|
|
311
|
-
get(t, prop) {
|
|
312
|
-
if (prop === 'toString')
|
|
313
|
-
return toStringFn;
|
|
314
|
-
if (prop === 'use')
|
|
315
|
-
return (userComponents) => render(userComponents);
|
|
316
|
-
if (prop === 'value')
|
|
317
|
-
return htmlString;
|
|
318
|
-
return t[prop] ?? result[prop];
|
|
319
|
-
},
|
|
320
|
-
});
|
|
321
|
-
};
|
|
244
|
+
// Type-safe render function that accepts properly typed components
|
|
245
|
+
const render = (userComponents = {}) => renderIntlayerNode({
|
|
246
|
+
...props,
|
|
247
|
+
value: htmlString,
|
|
248
|
+
component: HTMLRenderer,
|
|
249
|
+
props: {
|
|
250
|
+
...props,
|
|
251
|
+
value: htmlString,
|
|
252
|
+
components: userComponents,
|
|
253
|
+
},
|
|
254
|
+
additionalProps: {
|
|
255
|
+
use: (components) => render(components),
|
|
256
|
+
},
|
|
257
|
+
});
|
|
322
258
|
return render();
|
|
323
259
|
},
|
|
324
260
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-intlayer",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.0",
|
|
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.
|
|
86
|
-
"@intlayer/config": "8.
|
|
87
|
-
"@intlayer/core": "8.
|
|
88
|
-
"@intlayer/editor": "8.
|
|
89
|
-
"@intlayer/types": "8.
|
|
85
|
+
"@intlayer/api": "8.6.0",
|
|
86
|
+
"@intlayer/config": "8.6.0",
|
|
87
|
+
"@intlayer/core": "8.6.0",
|
|
88
|
+
"@intlayer/editor": "8.6.0",
|
|
89
|
+
"@intlayer/types": "8.6.0"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@sveltejs/adapter-auto": "7.0.1",
|
|
@@ -99,10 +99,10 @@
|
|
|
99
99
|
"rimraf": "6.1.3",
|
|
100
100
|
"svelte": "5.55.0",
|
|
101
101
|
"svelte-check": "4.4.5",
|
|
102
|
-
"tsdown": "0.21.
|
|
102
|
+
"tsdown": "0.21.7",
|
|
103
103
|
"typescript": "6.0.2",
|
|
104
|
-
"vite": "8.0.
|
|
105
|
-
"vitest": "4.1.
|
|
104
|
+
"vite": "8.0.3",
|
|
105
|
+
"vitest": "4.1.2"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
108
|
"svelte": ">=5.0.0"
|