svelte-intlayer 8.6.0 → 8.6.1
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/plugins.js +180 -168
- package/package.json +6 -6
package/dist/plugins.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import configuration from '@intlayer/config/built';
|
|
2
|
-
import { conditionPlugin, enumerationPlugin, filePlugin, genderPlugin, nestedPlugin, translationPlugin, } from '@intlayer/core/interpreter';
|
|
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';
|
|
@@ -27,17 +27,21 @@ void Promise.all([
|
|
|
27
27
|
* Basic Intlayer node plugins for content handling
|
|
28
28
|
* These handle the core content transformation logic
|
|
29
29
|
*/
|
|
30
|
-
export const intlayerNodePlugins =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
typeof node === '
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
export const intlayerNodePlugins = process.env.INTLAYER_NODE_TYPE_INTLAYER_NODE === 'false'
|
|
31
|
+
? fallbackPlugin
|
|
32
|
+
: {
|
|
33
|
+
id: 'intlayer-node-plugin',
|
|
34
|
+
canHandle: (node) => typeof node === 'bigint' ||
|
|
35
|
+
typeof node === 'string' ||
|
|
36
|
+
typeof node === 'number',
|
|
37
|
+
transform: (node, { children, ...rest }) => renderIntlayerNode({
|
|
38
|
+
value: children ?? node,
|
|
39
|
+
component: configuration.editor.enabled
|
|
40
|
+
? ContentSelector
|
|
41
|
+
: undefined,
|
|
42
|
+
props: rest,
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
41
45
|
/**
|
|
42
46
|
* Svelte-specific node plugins for handling basic content types
|
|
43
47
|
* These plugins handle strings, numbers, and bigints in Svelte applications
|
|
@@ -93,171 +97,179 @@ const splitAndJoinInsertion = (template, values) => {
|
|
|
93
97
|
return parts;
|
|
94
98
|
};
|
|
95
99
|
/** Insertion plugin for Svelte. Handles component insertion. */
|
|
96
|
-
export const insertionPlugin =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
plugins: [
|
|
116
|
-
...(props.plugins ?? []).filter((plugin) => plugin.id !== 'intlayer-node-plugin'),
|
|
117
|
-
],
|
|
118
|
-
});
|
|
119
|
-
return (values) => {
|
|
120
|
-
const result = splitAndJoinInsertion(transformedResult, values);
|
|
121
|
-
return deepTransformNode(result, {
|
|
100
|
+
export const insertionPlugin = process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'
|
|
101
|
+
? fallbackPlugin
|
|
102
|
+
: {
|
|
103
|
+
id: 'insertion-plugin',
|
|
104
|
+
canHandle: (node) => typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,
|
|
105
|
+
transform: (node, props, deepTransformNode) => {
|
|
106
|
+
const newKeyPath = [
|
|
107
|
+
...props.keyPath,
|
|
108
|
+
{
|
|
109
|
+
type: NodeTypes.INSERTION,
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
const children = node[NodeTypes.INSERTION];
|
|
113
|
+
/** Insertion string plugin. Replaces string node with a component that render the insertion. */
|
|
114
|
+
const insertionStringPlugin = {
|
|
115
|
+
id: 'insertion-string-plugin',
|
|
116
|
+
canHandle: (node) => typeof node === 'string',
|
|
117
|
+
transform: (node, subProps, deepTransformNode) => {
|
|
118
|
+
const transformedResult = deepTransformNode(node, {
|
|
122
119
|
...subProps,
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
children: node,
|
|
121
|
+
plugins: [
|
|
122
|
+
...(props.plugins ?? []).filter((plugin) => plugin.id !== 'intlayer-node-plugin'),
|
|
123
|
+
],
|
|
125
124
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
});
|
|
135
|
-
if (typeof children === 'object' &&
|
|
136
|
-
children !== null &&
|
|
137
|
-
'nodeType' in children &&
|
|
138
|
-
[NodeTypes.ENUMERATION, NodeTypes.CONDITION].includes(children.nodeType)) {
|
|
139
|
-
return (values) => (arg) => {
|
|
140
|
-
const func = result;
|
|
141
|
-
const inner = func(arg);
|
|
142
|
-
if (typeof inner === 'function') {
|
|
143
|
-
return inner(values);
|
|
144
|
-
}
|
|
145
|
-
return inner;
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
return result;
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
/** Markdown string plugin. Replaces string node with a component that render the markdown. */
|
|
152
|
-
export const markdownStringPlugin = {
|
|
153
|
-
id: 'markdown-string-plugin',
|
|
154
|
-
canHandle: (node) => typeof node === 'string',
|
|
155
|
-
transform: (node, props, deepTransformNode) => {
|
|
156
|
-
const { ...rest } = props;
|
|
157
|
-
const metadata = _getMarkdownMetadata?.(node) ?? {};
|
|
158
|
-
const metadataPlugins = {
|
|
159
|
-
id: 'markdown-metadata-plugin',
|
|
160
|
-
canHandle: (metadataNode) => typeof metadataNode === 'string' ||
|
|
161
|
-
typeof metadataNode === 'number' ||
|
|
162
|
-
typeof metadataNode === 'boolean' ||
|
|
163
|
-
!metadataNode,
|
|
164
|
-
transform: (metadataNode, props) => renderIntlayerNode({
|
|
165
|
-
value: metadataNode,
|
|
166
|
-
component: configuration.editor.enabled
|
|
167
|
-
? (_MarkdownMetadataWithSelector ?? _MarkdownMetadataRenderer)
|
|
168
|
-
: _MarkdownMetadataRenderer,
|
|
169
|
-
props: {
|
|
170
|
-
...rest,
|
|
171
|
-
value: node, // The full markdown string
|
|
172
|
-
metadataKeyPath: props.keyPath,
|
|
173
|
-
},
|
|
174
|
-
}),
|
|
175
|
-
};
|
|
176
|
-
// Transform metadata while keeping the same structure
|
|
177
|
-
const metadataNodes = deepTransformNode(metadata, {
|
|
178
|
-
plugins: [metadataPlugins],
|
|
179
|
-
dictionaryKey: rest.dictionaryKey,
|
|
180
|
-
keyPath: [],
|
|
181
|
-
}) ?? {};
|
|
182
|
-
const render = (components) => {
|
|
183
|
-
const nodeResult = renderIntlayerNode({
|
|
184
|
-
value: node,
|
|
185
|
-
component: configuration.editor.enabled
|
|
186
|
-
? (_MarkdownWithSelector ?? _MarkdownRenderer)
|
|
187
|
-
: _MarkdownRenderer,
|
|
188
|
-
props: {
|
|
189
|
-
...rest,
|
|
190
|
-
value: node,
|
|
191
|
-
...components,
|
|
192
|
-
},
|
|
193
|
-
additionalProps: {
|
|
194
|
-
metadata: metadataNodes,
|
|
125
|
+
return (values) => {
|
|
126
|
+
const result = splitAndJoinInsertion(transformedResult, values);
|
|
127
|
+
return deepTransformNode(result, {
|
|
128
|
+
...subProps,
|
|
129
|
+
plugins: props.plugins,
|
|
130
|
+
children: result,
|
|
131
|
+
});
|
|
132
|
+
};
|
|
195
133
|
},
|
|
134
|
+
};
|
|
135
|
+
const result = deepTransformNode(children, {
|
|
136
|
+
...props,
|
|
137
|
+
children,
|
|
138
|
+
keyPath: newKeyPath,
|
|
139
|
+
plugins: [insertionStringPlugin, ...(props.plugins ?? [])],
|
|
196
140
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return (newComponents) => render(newComponents);
|
|
141
|
+
if (typeof children === 'object' &&
|
|
142
|
+
children !== null &&
|
|
143
|
+
'nodeType' in children &&
|
|
144
|
+
[NodeTypes.ENUMERATION, NodeTypes.CONDITION].includes(children.nodeType)) {
|
|
145
|
+
return (values) => (arg) => {
|
|
146
|
+
const func = result;
|
|
147
|
+
const inner = func(arg);
|
|
148
|
+
if (typeof inner === 'function') {
|
|
149
|
+
return inner(values);
|
|
207
150
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
151
|
+
return inner;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
/** Markdown string plugin. Replaces string node with a component that render the markdown. */
|
|
158
|
+
export const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'
|
|
159
|
+
? fallbackPlugin
|
|
160
|
+
: {
|
|
161
|
+
id: 'markdown-string-plugin',
|
|
162
|
+
canHandle: (node) => typeof node === 'string',
|
|
163
|
+
transform: (node, props, deepTransformNode) => {
|
|
164
|
+
const { ...rest } = props;
|
|
165
|
+
const metadata = _getMarkdownMetadata?.(node) ?? {};
|
|
166
|
+
const metadataPlugins = {
|
|
167
|
+
id: 'markdown-metadata-plugin',
|
|
168
|
+
canHandle: (metadataNode) => typeof metadataNode === 'string' ||
|
|
169
|
+
typeof metadataNode === 'number' ||
|
|
170
|
+
typeof metadataNode === 'boolean' ||
|
|
171
|
+
!metadataNode,
|
|
172
|
+
transform: (metadataNode, props) => renderIntlayerNode({
|
|
173
|
+
value: metadataNode,
|
|
174
|
+
component: configuration.editor.enabled
|
|
175
|
+
? (_MarkdownMetadataWithSelector ?? _MarkdownMetadataRenderer)
|
|
176
|
+
: _MarkdownMetadataRenderer,
|
|
177
|
+
props: {
|
|
178
|
+
...rest,
|
|
179
|
+
value: node, // The full markdown string
|
|
180
|
+
metadataKeyPath: props.keyPath,
|
|
181
|
+
},
|
|
182
|
+
}),
|
|
183
|
+
};
|
|
184
|
+
// Transform metadata while keeping the same structure
|
|
185
|
+
const metadataNodes = deepTransformNode(metadata, {
|
|
186
|
+
plugins: [metadataPlugins],
|
|
187
|
+
dictionaryKey: rest.dictionaryKey,
|
|
188
|
+
keyPath: [],
|
|
189
|
+
}) ?? {};
|
|
190
|
+
const render = (components) => {
|
|
191
|
+
const nodeResult = renderIntlayerNode({
|
|
192
|
+
value: node,
|
|
193
|
+
component: configuration.editor.enabled
|
|
194
|
+
? (_MarkdownWithSelector ?? _MarkdownRenderer)
|
|
195
|
+
: _MarkdownRenderer,
|
|
196
|
+
props: {
|
|
197
|
+
...rest,
|
|
198
|
+
value: node,
|
|
199
|
+
...components,
|
|
200
|
+
},
|
|
201
|
+
additionalProps: {
|
|
202
|
+
metadata: metadataNodes,
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
return new Proxy(nodeResult, {
|
|
206
|
+
get(target, prop, receiver) {
|
|
207
|
+
if (prop === 'value') {
|
|
208
|
+
return node;
|
|
209
|
+
}
|
|
210
|
+
if (prop === 'metadata') {
|
|
211
|
+
return metadataNodes;
|
|
212
|
+
}
|
|
213
|
+
if (prop === 'use') {
|
|
214
|
+
return (newComponents) => render(newComponents);
|
|
215
|
+
}
|
|
216
|
+
if (prop === 'toString') {
|
|
217
|
+
return () => _compile?.(node, { runtime: _svelteHtmlRuntime, components: components }, {}) ?? node;
|
|
218
|
+
}
|
|
219
|
+
return Reflect.get(target, prop, receiver);
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
return render();
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
export const markdownPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'
|
|
227
|
+
? fallbackPlugin
|
|
228
|
+
: {
|
|
229
|
+
id: 'markdown-plugin',
|
|
230
|
+
canHandle: (node) => typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,
|
|
231
|
+
transform: (node, props, deepTransformNode) => {
|
|
232
|
+
const newKeyPath = [
|
|
233
|
+
...props.keyPath,
|
|
234
|
+
{
|
|
235
|
+
type: NodeTypes.MARKDOWN,
|
|
212
236
|
},
|
|
237
|
+
];
|
|
238
|
+
const children = node[NodeTypes.MARKDOWN];
|
|
239
|
+
return deepTransformNode(children, {
|
|
240
|
+
...props,
|
|
241
|
+
children,
|
|
242
|
+
keyPath: newKeyPath,
|
|
243
|
+
plugins: [markdownStringPlugin, ...(props.plugins ?? [])],
|
|
213
244
|
});
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
export const markdownPlugin = {
|
|
219
|
-
id: 'markdown-plugin',
|
|
220
|
-
canHandle: (node) => typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,
|
|
221
|
-
transform: (node, props, deepTransformNode) => {
|
|
222
|
-
const newKeyPath = [
|
|
223
|
-
...props.keyPath,
|
|
224
|
-
{
|
|
225
|
-
type: NodeTypes.MARKDOWN,
|
|
226
|
-
},
|
|
227
|
-
];
|
|
228
|
-
const children = node[NodeTypes.MARKDOWN];
|
|
229
|
-
return deepTransformNode(children, {
|
|
230
|
-
...props,
|
|
231
|
-
children,
|
|
232
|
-
keyPath: newKeyPath,
|
|
233
|
-
plugins: [markdownStringPlugin, ...(props.plugins ?? [])],
|
|
234
|
-
});
|
|
235
|
-
},
|
|
236
|
-
};
|
|
245
|
+
},
|
|
246
|
+
};
|
|
237
247
|
/** HTML plugin. Replaces node with a function that takes components => HTMLElement[]. */
|
|
238
|
-
export const htmlPlugin =
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
component: HTMLRenderer,
|
|
249
|
-
props: {
|
|
248
|
+
export const htmlPlugin = process.env.INTLAYER_NODE_TYPE_HTML === 'false'
|
|
249
|
+
? fallbackPlugin
|
|
250
|
+
: {
|
|
251
|
+
id: 'html-plugin',
|
|
252
|
+
canHandle: (node) => typeof node === 'object' && node?.nodeType === NodeTypes.HTML,
|
|
253
|
+
transform: (node, props) => {
|
|
254
|
+
const htmlString = node[NodeTypes.HTML];
|
|
255
|
+
const _tags = node.tags ?? [];
|
|
256
|
+
// Type-safe render function that accepts properly typed components
|
|
257
|
+
const render = (userComponents = {}) => renderIntlayerNode({
|
|
250
258
|
...props,
|
|
251
259
|
value: htmlString,
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
260
|
+
component: HTMLRenderer,
|
|
261
|
+
props: {
|
|
262
|
+
...props,
|
|
263
|
+
value: htmlString,
|
|
264
|
+
components: userComponents,
|
|
265
|
+
},
|
|
266
|
+
additionalProps: {
|
|
267
|
+
use: (components) => render(components),
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
return render();
|
|
271
|
+
},
|
|
272
|
+
};
|
|
261
273
|
/**
|
|
262
274
|
* Get the plugins array for Svelte content transformation.
|
|
263
275
|
* This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.
|
|
@@ -274,4 +286,4 @@ export const getPlugins = (locale, fallback = true) => [
|
|
|
274
286
|
insertionPlugin,
|
|
275
287
|
markdownPlugin,
|
|
276
288
|
htmlPlugin,
|
|
277
|
-
];
|
|
289
|
+
].filter(Boolean);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-intlayer",
|
|
3
|
-
"version": "8.6.
|
|
3
|
+
"version": "8.6.1",
|
|
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.1",
|
|
86
|
+
"@intlayer/config": "8.6.1",
|
|
87
|
+
"@intlayer/core": "8.6.1",
|
|
88
|
+
"@intlayer/editor": "8.6.1",
|
|
89
|
+
"@intlayer/types": "8.6.1"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@sveltejs/adapter-auto": "7.0.1",
|