vanilla-intlayer 8.7.14 → 8.9.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/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/client/index.cjs +24 -1
- package/dist/cjs/client/installIntlayer.cjs +98 -1
- package/dist/cjs/client/installIntlayer.cjs.map +1 -0
- package/dist/cjs/client/useDictionary.cjs +59 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -0
- package/dist/cjs/client/useDictionaryDynamic.cjs +93 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -0
- package/dist/cjs/client/useIntlayer.cjs +65 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -0
- package/dist/cjs/client/useLocale.cjs +58 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -0
- package/dist/cjs/client/useLocaleStorage.cjs +51 -1
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -0
- package/dist/cjs/client/useRewriteURL.cjs +46 -1
- package/dist/cjs/client/useRewriteURL.cjs.map +1 -0
- package/dist/cjs/editor/useEditor.cjs +49 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -0
- package/dist/cjs/format/index.cjs +20 -1
- package/dist/cjs/format/useCompact.cjs +17 -1
- package/dist/cjs/format/useCompact.cjs.map +1 -0
- package/dist/cjs/format/useCurrency.cjs +17 -1
- package/dist/cjs/format/useCurrency.cjs.map +1 -0
- package/dist/cjs/format/useDate.cjs +26 -1
- package/dist/cjs/format/useDate.cjs.map +1 -0
- package/dist/cjs/format/useIntl.cjs +44 -1
- package/dist/cjs/format/useIntl.cjs.map +1 -0
- package/dist/cjs/format/useList.cjs +17 -1
- package/dist/cjs/format/useList.cjs.map +1 -0
- package/dist/cjs/format/useNumber.cjs +20 -1
- package/dist/cjs/format/useNumber.cjs.map +1 -0
- package/dist/cjs/format/usePercentage.cjs +17 -1
- package/dist/cjs/format/usePercentage.cjs.map +1 -0
- package/dist/cjs/format/useRelativeTime.cjs +17 -1
- package/dist/cjs/format/useRelativeTime.cjs.map +1 -0
- package/dist/cjs/format/useUnit.cjs +17 -1
- package/dist/cjs/format/useUnit.cjs.map +1 -0
- package/dist/cjs/getDictionary.cjs +11 -1
- package/dist/cjs/getDictionary.cjs.map +1 -0
- package/dist/cjs/getIntlayer.cjs +11 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -0
- package/dist/cjs/html/HTMLRenderer.cjs +22 -1
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -0
- package/dist/cjs/html/index.cjs +9 -1
- package/dist/cjs/html/installIntlayerHTML.cjs +91 -1
- package/dist/cjs/html/installIntlayerHTML.cjs.map +1 -0
- package/dist/cjs/html/types.cjs +0 -1
- package/dist/cjs/index.cjs +37 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +41 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -0
- package/dist/cjs/markdown/compiler.cjs +37 -1
- package/dist/cjs/markdown/compiler.cjs.map +1 -0
- package/dist/cjs/markdown/index.cjs +11 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs +98 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs.map +1 -0
- package/dist/cjs/markdown/runtime.cjs +87 -1
- package/dist/cjs/markdown/runtime.cjs.map +1 -0
- package/dist/cjs/plugins.cjs +240 -1
- package/dist/cjs/plugins.cjs.map +1 -0
- package/dist/cjs/renderIntlayerNode.cjs +44 -1
- package/dist/cjs/renderIntlayerNode.cjs.map +1 -0
- package/dist/esm/client/index.mjs +9 -8
- package/dist/esm/client/installIntlayer.mjs +93 -2
- package/dist/esm/client/installIntlayer.mjs.map +1 -0
- package/dist/esm/client/useDictionary.mjs +55 -8
- package/dist/esm/client/useDictionary.mjs.map +1 -0
- package/dist/esm/client/useDictionaryDynamic.mjs +82 -28
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -0
- package/dist/esm/client/useIntlayer.mjs +61 -8
- package/dist/esm/client/useIntlayer.mjs.map +1 -0
- package/dist/esm/client/useLocale.mjs +51 -17
- package/dist/esm/client/useLocale.mjs.map +1 -0
- package/dist/esm/client/useLocaleStorage.mjs +39 -13
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -0
- package/dist/esm/client/useRewriteURL.mjs +40 -12
- package/dist/esm/client/useRewriteURL.mjs.map +1 -0
- package/dist/esm/editor/useEditor.mjs +47 -2
- package/dist/esm/editor/useEditor.mjs.map +1 -0
- package/dist/esm/format/index.mjs +11 -10
- package/dist/esm/format/useCompact.mjs +11 -8
- package/dist/esm/format/useCompact.mjs.map +1 -0
- package/dist/esm/format/useCurrency.mjs +11 -8
- package/dist/esm/format/useCurrency.mjs.map +1 -0
- package/dist/esm/format/useDate.mjs +18 -12
- package/dist/esm/format/useDate.mjs.map +1 -0
- package/dist/esm/format/useIntl.mjs +36 -8
- package/dist/esm/format/useIntl.mjs.map +1 -0
- package/dist/esm/format/useList.mjs +11 -8
- package/dist/esm/format/useList.mjs.map +1 -0
- package/dist/esm/format/useNumber.mjs +14 -8
- package/dist/esm/format/useNumber.mjs.map +1 -0
- package/dist/esm/format/usePercentage.mjs +11 -8
- package/dist/esm/format/usePercentage.mjs.map +1 -0
- package/dist/esm/format/useRelativeTime.mjs +11 -8
- package/dist/esm/format/useRelativeTime.mjs.map +1 -0
- package/dist/esm/format/useUnit.mjs +11 -8
- package/dist/esm/format/useUnit.mjs.map +1 -0
- package/dist/esm/getDictionary.mjs +7 -4
- package/dist/esm/getDictionary.mjs.map +1 -0
- package/dist/esm/getIntlayer.mjs +7 -4
- package/dist/esm/getIntlayer.mjs.map +1 -0
- package/dist/esm/html/HTMLRenderer.mjs +17 -5
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -0
- package/dist/esm/html/index.mjs +4 -3
- package/dist/esm/html/installIntlayerHTML.mjs +81 -13
- package/dist/esm/html/installIntlayerHTML.mjs.map +1 -0
- package/dist/esm/index.mjs +13 -12
- package/dist/esm/markdown/MarkdownRenderer.mjs +36 -16
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -0
- package/dist/esm/markdown/compiler.mjs +28 -4
- package/dist/esm/markdown/compiler.mjs.map +1 -0
- package/dist/esm/markdown/index.mjs +5 -4
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +86 -23
- package/dist/esm/markdown/installIntlayerMarkdown.mjs.map +1 -0
- package/dist/esm/markdown/runtime.mjs +60 -28
- package/dist/esm/markdown/runtime.mjs.map +1 -0
- package/dist/esm/plugins.mjs +187 -133
- package/dist/esm/plugins.mjs.map +1 -0
- package/dist/esm/renderIntlayerNode.mjs +32 -15
- package/dist/esm/renderIntlayerNode.mjs.map +1 -0
- package/dist/types/client/index.d.ts +8 -0
- package/dist/{client → types/client}/installIntlayer.d.ts +27 -20
- package/dist/types/client/installIntlayer.d.ts.map +1 -0
- package/dist/{client → types/client}/useDictionary.d.ts +22 -17
- package/dist/types/client/useDictionary.d.ts.map +1 -0
- package/dist/{client → types/client}/useDictionaryDynamic.d.ts +10 -5
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
- package/dist/{client → types/client}/useIntlayer.d.ts +9 -4
- package/dist/types/client/useIntlayer.d.ts.map +1 -0
- package/dist/{client → types/client}/useLocale.d.ts +14 -10
- package/dist/types/client/useLocale.d.ts.map +1 -0
- package/dist/types/client/useLocaleStorage.d.ts +37 -0
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -0
- package/dist/{client → types/client}/useRewriteURL.d.ts +5 -1
- package/dist/types/client/useRewriteURL.d.ts.map +1 -0
- package/dist/{editor → types/editor}/useEditor.d.ts +5 -1
- package/dist/types/editor/useEditor.d.ts.map +1 -0
- package/dist/types/format/index.d.ts +10 -0
- package/dist/types/format/useCompact.d.ts +7 -0
- package/dist/types/format/useCompact.d.ts.map +1 -0
- package/dist/types/format/useCurrency.d.ts +7 -0
- package/dist/types/format/useCurrency.d.ts.map +1 -0
- package/dist/types/format/useDate.d.ts +10 -0
- package/dist/types/format/useDate.d.ts.map +1 -0
- package/dist/{format → types/format}/useIntl.d.ts +10 -5
- package/dist/types/format/useIntl.d.ts.map +1 -0
- package/dist/types/format/useList.d.ts +7 -0
- package/dist/types/format/useList.d.ts.map +1 -0
- package/dist/types/format/useNumber.d.ts +10 -0
- package/dist/types/format/useNumber.d.ts.map +1 -0
- package/dist/types/format/usePercentage.d.ts +7 -0
- package/dist/types/format/usePercentage.d.ts.map +1 -0
- package/dist/types/format/useRelativeTime.d.ts +7 -0
- package/dist/types/format/useRelativeTime.d.ts.map +1 -0
- package/dist/types/format/useUnit.d.ts +7 -0
- package/dist/types/format/useUnit.d.ts.map +1 -0
- package/dist/types/getDictionary.d.ts +9 -0
- package/dist/types/getDictionary.d.ts.map +1 -0
- package/dist/types/getIntlayer.d.ts +8 -0
- package/dist/types/getIntlayer.d.ts.map +1 -0
- package/dist/types/html/HTMLRenderer.d.ts +21 -0
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -0
- package/dist/types/html/index.d.ts +4 -0
- package/dist/{html → types/html}/installIntlayerHTML.d.ts +18 -13
- package/dist/types/html/installIntlayerHTML.d.ts.map +1 -0
- package/dist/{html → types/html}/types.d.ts +12 -14
- package/dist/types/html/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts +32 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
- package/dist/types/markdown/compiler.d.ts +23 -0
- package/dist/types/markdown/compiler.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +4 -0
- package/dist/types/markdown/installIntlayerMarkdown.d.ts +71 -0
- package/dist/types/markdown/installIntlayerMarkdown.d.ts.map +1 -0
- package/dist/types/markdown/runtime.d.ts +16 -0
- package/dist/types/markdown/runtime.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +80 -0
- package/dist/types/plugins.d.ts.map +1 -0
- package/dist/types/renderIntlayerNode.d.ts +31 -0
- package/dist/types/renderIntlayerNode.d.ts.map +1 -0
- package/package.json +10 -13
- package/dist/client/index.d.ts +0 -7
- package/dist/client/useLocaleStorage.d.ts +0 -31
- package/dist/format/index.d.ts +0 -9
- package/dist/format/useCompact.d.ts +0 -2
- package/dist/format/useCurrency.d.ts +0 -2
- package/dist/format/useDate.d.ts +0 -5
- package/dist/format/useList.d.ts +0 -2
- package/dist/format/useNumber.d.ts +0 -5
- package/dist/format/usePercentage.d.ts +0 -2
- package/dist/format/useRelativeTime.d.ts +0 -2
- package/dist/format/useUnit.d.ts +0 -2
- package/dist/getDictionary.d.ts +0 -4
- package/dist/getIntlayer.d.ts +0 -3
- package/dist/html/HTMLRenderer.d.ts +0 -14
- package/dist/html/index.d.ts +0 -3
- package/dist/index.d.ts +0 -11
- package/dist/installIntlayer-C99qMzFH.mjs +0 -47
- package/dist/installIntlayer-CxkE8IxM.js +0 -1
- package/dist/markdown/MarkdownRenderer.d.ts +0 -22
- package/dist/markdown/compiler.d.ts +0 -19
- package/dist/markdown/index.d.ts +0 -3
- package/dist/markdown/installIntlayerMarkdown.d.ts +0 -70
- package/dist/markdown/runtime.d.ts +0 -12
- package/dist/plugins-Bp8aaTny.js +0 -1
- package/dist/plugins.d.ts +0 -78
- package/dist/renderIntlayerNode.d.ts +0 -22
package/dist/esm/plugins.mjs
CHANGED
|
@@ -1,178 +1,232 @@
|
|
|
1
|
-
import { renderIntlayerNode
|
|
2
|
-
import { conditionPlugin
|
|
3
|
-
import { editor
|
|
4
|
-
import { compileWithOptions
|
|
5
|
-
import * as
|
|
1
|
+
import { renderIntlayerNode } from "./renderIntlayerNode.mjs";
|
|
2
|
+
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, getHTML, nestedPlugin, pluralPlugin, splitInsertionTemplate, translationPlugin } from "@intlayer/core/interpreter";
|
|
3
|
+
import { editor, internationalization } from "@intlayer/config/built";
|
|
4
|
+
import { compileWithOptions, getMarkdownMetadata } from "@intlayer/core/markdown";
|
|
5
|
+
import * as NodeTypes from "@intlayer/types/nodeType";
|
|
6
|
+
|
|
6
7
|
//#region src/plugins.ts
|
|
7
|
-
|
|
8
|
+
const escapeHtmlAttr = (str) => str.replace(/&/g, "&").replace(/"/g, """);
|
|
9
|
+
const escapeHtmlText = (str) => str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
10
|
+
const intlayerNodePlugins = {
|
|
8
11
|
id: "intlayer-node-plugin",
|
|
9
|
-
canHandle: (
|
|
10
|
-
transform: (
|
|
11
|
-
if (process.env
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
|
|
13
|
+
transform: (_node, { children, keyPath, dictionaryKey, ...rest }) => {
|
|
14
|
+
if (process.env["INTLAYER_EDITOR_ENABLED"] !== "false" && editor.enabled) {
|
|
15
|
+
const rawStr = String(children ?? "");
|
|
16
|
+
const keyPathJson = JSON.stringify(keyPath ?? []);
|
|
17
|
+
const dictKey = String(dictionaryKey ?? "");
|
|
18
|
+
/**
|
|
19
|
+
* In editor mode, string coercion returns the wrapper HTML so that
|
|
20
|
+
* `element.innerHTML = content.title` automatically inserts the
|
|
21
|
+
* `<intlayer-content-selector-wrapper>` into the DOM.
|
|
22
|
+
*/
|
|
23
|
+
const htmlStr = `<intlayer-content-selector-wrapper key-path="${escapeHtmlAttr(keyPathJson)}" dictionary-key="${escapeHtmlAttr(dictKey)}">${escapeHtmlText(rawStr)}</intlayer-content-selector-wrapper>`;
|
|
24
|
+
return renderIntlayerNode({
|
|
25
|
+
...rest,
|
|
26
|
+
value: children,
|
|
27
|
+
children: htmlStr,
|
|
28
|
+
keyPath,
|
|
29
|
+
dictionaryKey,
|
|
19
30
|
additionalProps: { toElement: () => {
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
const wrapper = document.createElement("intlayer-content-selector-wrapper");
|
|
32
|
+
wrapper.setAttribute("key-path", keyPathJson);
|
|
33
|
+
wrapper.setAttribute("dictionary-key", dictKey);
|
|
34
|
+
wrapper.textContent = rawStr;
|
|
35
|
+
return wrapper;
|
|
22
36
|
} }
|
|
23
37
|
});
|
|
24
38
|
}
|
|
25
|
-
return
|
|
26
|
-
...
|
|
27
|
-
value:
|
|
28
|
-
children
|
|
39
|
+
return renderIntlayerNode({
|
|
40
|
+
...rest,
|
|
41
|
+
value: children,
|
|
42
|
+
children
|
|
29
43
|
});
|
|
30
44
|
}
|
|
31
|
-
}
|
|
45
|
+
};
|
|
46
|
+
const insertionPlugin = process.env["INTLAYER_NODE_TYPE_INSERTION"] === "false" ? fallbackPlugin : {
|
|
32
47
|
id: "insertion-plugin",
|
|
33
|
-
canHandle: (
|
|
34
|
-
transform: (
|
|
35
|
-
|
|
48
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.INSERTION,
|
|
49
|
+
transform: (node, props, deepTransformNode) => {
|
|
50
|
+
const newKeyPath = [...props.keyPath, { type: NodeTypes.INSERTION }];
|
|
51
|
+
const children = node[NodeTypes.INSERTION];
|
|
52
|
+
const insertionStringPlugin = {
|
|
36
53
|
id: "insertion-string-plugin",
|
|
37
|
-
canHandle: (
|
|
38
|
-
transform: (
|
|
39
|
-
|
|
40
|
-
...
|
|
41
|
-
children:
|
|
42
|
-
plugins: (
|
|
54
|
+
canHandle: (node) => typeof node === "string",
|
|
55
|
+
transform: (node, subProps, deepTransformNode) => {
|
|
56
|
+
const transformedResult = deepTransformNode(node, {
|
|
57
|
+
...subProps,
|
|
58
|
+
children: node,
|
|
59
|
+
plugins: (props.plugins ?? []).filter((plugin) => plugin.id !== "intlayer-node-plugin")
|
|
43
60
|
});
|
|
44
|
-
return (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
return (values) => {
|
|
62
|
+
const result = splitInsertionTemplate(transformedResult, values);
|
|
63
|
+
const resultStr = result.isSimple ? result.parts : result.parts.join("");
|
|
64
|
+
return deepTransformNode(resultStr, {
|
|
65
|
+
...subProps,
|
|
66
|
+
plugins: props.plugins,
|
|
67
|
+
children: resultStr
|
|
50
68
|
});
|
|
51
69
|
};
|
|
52
70
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
71
|
+
};
|
|
72
|
+
const transformed = deepTransformNode(children, {
|
|
73
|
+
...props,
|
|
74
|
+
children,
|
|
75
|
+
keyPath: newKeyPath,
|
|
76
|
+
plugins: [insertionStringPlugin, ...props.plugins ?? []]
|
|
58
77
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return typeof
|
|
62
|
-
}
|
|
78
|
+
if (typeof children === "object" && children !== null && "nodeType" in children && [NodeTypes.ENUMERATION, NodeTypes.CONDITION].includes(children.nodeType)) return (values) => (arg) => {
|
|
79
|
+
const inner = transformed(arg);
|
|
80
|
+
return typeof inner === "function" ? inner(values) : inner;
|
|
81
|
+
};
|
|
82
|
+
return transformed;
|
|
63
83
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
84
|
+
};
|
|
85
|
+
/** ---------------------------------------------
|
|
86
|
+
* MARKDOWN PLUGIN
|
|
87
|
+
* --------------------------------------------- */
|
|
88
|
+
const vanillaRuntime = {
|
|
89
|
+
createElement: (tag, props, ...children) => {
|
|
90
|
+
const attrs = Object.entries(props || {}).filter(([key]) => key !== "children" && key !== "key" && key !== "_innerHTML").map(([key, value]) => `${key}="${value}"`).join(" ");
|
|
91
|
+
const innerHTML = props?._innerHTML;
|
|
92
|
+
const childrenStr = innerHTML !== void 0 ? innerHTML : children.flat(Infinity).join("");
|
|
93
|
+
return `<${tag}${attrs ? ` ${attrs}` : ""}>${childrenStr}</${tag}>`;
|
|
68
94
|
},
|
|
69
|
-
normalizeProps: (
|
|
70
|
-
|
|
71
|
-
for (
|
|
72
|
-
|
|
95
|
+
normalizeProps: (_tag, props) => {
|
|
96
|
+
const normalized = {};
|
|
97
|
+
for (const [key, value] of Object.entries(props)) if (key === "className") normalized.class = value;
|
|
98
|
+
else if (key === "htmlFor") normalized.for = value;
|
|
99
|
+
else if (key === "dangerouslySetInnerHTML" && value?.__html) normalized._innerHTML = value.__html;
|
|
100
|
+
else normalized[key] = value;
|
|
101
|
+
return normalized;
|
|
73
102
|
}
|
|
74
|
-
}
|
|
103
|
+
};
|
|
104
|
+
const markdownStringPlugin = process.env["INTLAYER_NODE_TYPE_MARKDOWN"] === "false" ? fallbackPlugin : {
|
|
75
105
|
id: "markdown-string-plugin",
|
|
76
|
-
canHandle: (
|
|
77
|
-
transform: (
|
|
78
|
-
|
|
106
|
+
canHandle: (node) => typeof node === "string",
|
|
107
|
+
transform: (node, props, deepTransformNode) => {
|
|
108
|
+
const { plugins: _plugins, ...rest } = props;
|
|
109
|
+
const metadataNodes = deepTransformNode(getMarkdownMetadata(node) ?? {}, {
|
|
79
110
|
plugins: [{
|
|
80
111
|
id: "markdown-metadata-plugin",
|
|
81
|
-
canHandle: (
|
|
82
|
-
transform: (
|
|
83
|
-
...
|
|
84
|
-
value:
|
|
85
|
-
children:
|
|
112
|
+
canHandle: (metadataNode) => typeof metadataNode === "string" || typeof metadataNode === "number" || typeof metadataNode === "boolean" || !metadataNode,
|
|
113
|
+
transform: (metadataNode, subProps) => renderIntlayerNode({
|
|
114
|
+
...subProps,
|
|
115
|
+
value: metadataNode,
|
|
116
|
+
children: node
|
|
86
117
|
})
|
|
87
118
|
}],
|
|
88
|
-
dictionaryKey:
|
|
119
|
+
dictionaryKey: rest.dictionaryKey,
|
|
89
120
|
keyPath: []
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
121
|
+
});
|
|
122
|
+
const compile = (components = {}) => compileWithOptions(node, {
|
|
123
|
+
...vanillaRuntime,
|
|
124
|
+
createElement: (tag, props, ...children) => {
|
|
125
|
+
const override = components[tag];
|
|
126
|
+
if (typeof override === "function") return override({
|
|
127
|
+
...props,
|
|
128
|
+
children: children.join("")
|
|
129
|
+
});
|
|
130
|
+
return vanillaRuntime.createElement(tag, props, ...children);
|
|
98
131
|
}
|
|
99
|
-
}, {})
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
132
|
+
}, {});
|
|
133
|
+
const value = compile();
|
|
134
|
+
let children = node;
|
|
135
|
+
if (process.env["INTLAYER_EDITOR_ENABLED"] !== "false" && editor.enabled) {
|
|
136
|
+
const keyPathJson = JSON.stringify(props.keyPath ?? []);
|
|
137
|
+
const dictKey = String(props.dictionaryKey ?? "");
|
|
138
|
+
children = `<intlayer-content-selector-wrapper key-path="${escapeHtmlAttr(keyPathJson)}" dictionary-key="${escapeHtmlAttr(dictKey)}">${escapeHtmlText(value)}</intlayer-content-selector-wrapper>`;
|
|
103
139
|
}
|
|
104
|
-
return
|
|
105
|
-
...
|
|
106
|
-
value
|
|
107
|
-
children
|
|
140
|
+
return renderIntlayerNode({
|
|
141
|
+
...props,
|
|
142
|
+
value,
|
|
143
|
+
children,
|
|
108
144
|
additionalProps: {
|
|
109
|
-
metadata:
|
|
110
|
-
use: (
|
|
145
|
+
metadata: metadataNodes,
|
|
146
|
+
use: (components) => compile(components)
|
|
111
147
|
}
|
|
112
148
|
});
|
|
113
149
|
}
|
|
114
|
-
}
|
|
150
|
+
};
|
|
151
|
+
const markdownPlugin = process.env["INTLAYER_NODE_TYPE_MARKDOWN"] === "false" ? fallbackPlugin : {
|
|
115
152
|
id: "markdown-plugin",
|
|
116
|
-
canHandle: (
|
|
117
|
-
transform: (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
153
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.MARKDOWN,
|
|
154
|
+
transform: (node, props, deepTransformNode) => {
|
|
155
|
+
const newKeyPath = [...props.keyPath, { type: NodeTypes.MARKDOWN }];
|
|
156
|
+
const children = node[NodeTypes.MARKDOWN];
|
|
157
|
+
return deepTransformNode(children, {
|
|
158
|
+
...props,
|
|
159
|
+
children,
|
|
160
|
+
keyPath: newKeyPath,
|
|
161
|
+
plugins: [markdownStringPlugin, ...props.plugins ?? []]
|
|
124
162
|
});
|
|
125
163
|
}
|
|
126
|
-
}
|
|
164
|
+
};
|
|
165
|
+
const htmlPlugin = process.env["INTLAYER_NODE_TYPE_HTML"] === "false" ? fallbackPlugin : {
|
|
127
166
|
id: "html-plugin",
|
|
128
|
-
canHandle: (
|
|
129
|
-
transform: (
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
167
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.HTML,
|
|
168
|
+
transform: (node, props) => {
|
|
169
|
+
const htmlStr = node[NodeTypes.HTML];
|
|
170
|
+
const use = (components = {}) => {
|
|
171
|
+
const result = getHTML(htmlStr, new Proxy(components, { get(target, prop) {
|
|
172
|
+
if (typeof prop === "string" && prop in target) {
|
|
173
|
+
const Component = target[prop];
|
|
174
|
+
return (props) => {
|
|
175
|
+
const children = Array.isArray(props.children) ? props.children.join("") : props.children;
|
|
176
|
+
return Component({
|
|
177
|
+
...props,
|
|
178
|
+
children
|
|
139
179
|
});
|
|
140
180
|
};
|
|
141
181
|
}
|
|
142
|
-
if (typeof
|
|
143
|
-
|
|
144
|
-
|
|
182
|
+
if (typeof prop === "string" && /^[a-z][a-z0-9]*$/.test(prop)) return (props) => {
|
|
183
|
+
const attrs = Object.entries(props).filter(([key]) => key !== "children" && key !== "key").map(([key, value]) => `${key}="${value}"`).join(" ");
|
|
184
|
+
const children = Array.isArray(props.children) ? props.children.join("") : props.children;
|
|
185
|
+
return `<${prop}${attrs ? ` ${attrs}` : ""}>${children}</${prop}>`;
|
|
145
186
|
};
|
|
146
187
|
} }));
|
|
147
|
-
return Array.isArray(
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
188
|
+
return Array.isArray(result) ? result.join("") : result;
|
|
189
|
+
};
|
|
190
|
+
const value = use();
|
|
191
|
+
let children = htmlStr;
|
|
192
|
+
if (process.env["INTLAYER_EDITOR_ENABLED"] !== "false" && editor.enabled) {
|
|
193
|
+
const keyPathJson = JSON.stringify(props.keyPath ?? []);
|
|
194
|
+
const dictKey = String(props.dictionaryKey ?? "");
|
|
195
|
+
children = `<intlayer-content-selector-wrapper key-path="${escapeHtmlAttr(keyPathJson)}" dictionary-key="${escapeHtmlAttr(dictKey)}">${escapeHtmlText(value)}</intlayer-content-selector-wrapper>`;
|
|
152
196
|
}
|
|
153
|
-
return
|
|
154
|
-
...
|
|
155
|
-
value
|
|
156
|
-
children
|
|
157
|
-
additionalProps: { use: (
|
|
197
|
+
return renderIntlayerNode({
|
|
198
|
+
...props,
|
|
199
|
+
value,
|
|
200
|
+
children,
|
|
201
|
+
additionalProps: { use: (components) => use(components) }
|
|
158
202
|
});
|
|
159
203
|
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
204
|
+
};
|
|
205
|
+
const pluginsCache = /* @__PURE__ */ new Map();
|
|
206
|
+
/**
|
|
207
|
+
* Get the plugins array for Vanilla content transformation.
|
|
208
|
+
* This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.
|
|
209
|
+
*/
|
|
210
|
+
const getPlugins = (locale, fallback = true) => {
|
|
211
|
+
const cacheKey = `${locale ?? internationalization.defaultLocale}_${fallback}`;
|
|
212
|
+
if (pluginsCache.has(cacheKey)) return pluginsCache.get(cacheKey);
|
|
213
|
+
const plugins = [
|
|
214
|
+
translationPlugin(locale ?? internationalization.defaultLocale, fallback ? internationalization.defaultLocale : void 0),
|
|
215
|
+
enumerationPlugin,
|
|
216
|
+
pluralPlugin(locale ?? internationalization.defaultLocale),
|
|
217
|
+
conditionPlugin,
|
|
218
|
+
nestedPlugin(locale ?? internationalization.defaultLocale),
|
|
219
|
+
filePlugin,
|
|
220
|
+
genderPlugin,
|
|
221
|
+
intlayerNodePlugins,
|
|
222
|
+
insertionPlugin,
|
|
223
|
+
markdownPlugin,
|
|
224
|
+
htmlPlugin
|
|
174
225
|
];
|
|
175
|
-
|
|
226
|
+
pluginsCache.set(cacheKey, plugins);
|
|
227
|
+
return plugins;
|
|
176
228
|
};
|
|
229
|
+
|
|
177
230
|
//#endregion
|
|
178
|
-
export {
|
|
231
|
+
export { getPlugins, htmlPlugin, insertionPlugin, intlayerNodePlugins, markdownPlugin, markdownStringPlugin };
|
|
232
|
+
//# sourceMappingURL=plugins.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.mjs","names":[],"sources":["../../src/plugins.ts"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n getHTML,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n splitInsertionTemplate,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport {\n compileWithOptions,\n getMarkdownMetadata,\n} from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type { HTMLComponents } from './html/types';\nimport {\n type IntlayerNode as IntlayerNodeCore,\n renderIntlayerNode,\n} from './renderIntlayerNode';\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\nexport type IntlayerNode<T, P = {}> = IntlayerNodeCore<T> & P;\n\nconst escapeHtmlAttr = (str: string): string =>\n str.replace(/&/g, '&').replace(/\"/g, '"');\n\nconst escapeHtmlText = (str: string): string =>\n str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, { children, keyPath, dictionaryKey, ...rest }) => {\n if (process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' && editor.enabled) {\n const rawStr = String(children ?? '');\n const keyPathJson = JSON.stringify(keyPath ?? []);\n const dictKey = String(dictionaryKey ?? '');\n\n /**\n * In editor mode, string coercion returns the wrapper HTML so that\n * `element.innerHTML = content.title` automatically inserts the\n * `<intlayer-content-selector-wrapper>` into the DOM.\n */\n const htmlStr = `<intlayer-content-selector-wrapper key-path=\"${escapeHtmlAttr(keyPathJson)}\" dictionary-key=\"${escapeHtmlAttr(dictKey)}\">${escapeHtmlText(rawStr)}</intlayer-content-selector-wrapper>`;\n\n return renderIntlayerNode({\n ...rest,\n value: children as string,\n children: htmlStr,\n keyPath,\n dictionaryKey,\n additionalProps: {\n toElement: (): HTMLElement => {\n const wrapper = document.createElement(\n 'intlayer-content-selector-wrapper'\n );\n wrapper.setAttribute('key-path', keyPathJson);\n wrapper.setAttribute('dictionary-key', dictKey);\n wrapper.textContent = rawStr;\n return wrapper;\n },\n },\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: children as string,\n children,\n });\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, _S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly (infer F)[];\n}\n ? <V extends { [K in Extract<F, string>]: string | number }>(\n values: V\n ) => I extends string ? IntlayerNode<string> : DeepTransformContent<I, L>\n : never;\n\nexport const insertionPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_INSERTION'] === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n { type: NodeTypes.INSERTION },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: (props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const result = splitInsertionTemplate(\n transformedResult,\n values\n );\n const resultStr = result.isSimple\n ? (result.parts as string)\n : (result.parts as string[]).join('');\n\n return deepTransformNode(resultStr, {\n ...subProps,\n plugins: props.plugins,\n children: resultStr,\n });\n };\n },\n };\n\n const transformed = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n if (\n typeof children === 'object' &&\n children !== null &&\n 'nodeType' in children &&\n (\n [NodeTypes.ENUMERATION, NodeTypes.CONDITION] as NodeType[]\n ).includes(children.nodeType as NodeType)\n ) {\n return (values: any) => (arg: any) => {\n const inner = (transformed as (a: any) => any)(arg);\n return typeof inner === 'function' ? inner(values) : inner;\n };\n }\n\n return transformed;\n },\n };\n\n/** ---------------------------------------------\n * MARKDOWN PLUGIN\n * --------------------------------------------- */\n\nconst vanillaRuntime = {\n createElement: (tag: string, props: any, ...children: any[]) => {\n const attrs = Object.entries(props || {})\n .filter(\n ([key]) => key !== 'children' && key !== 'key' && key !== '_innerHTML'\n )\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ');\n const innerHTML = props?._innerHTML;\n const childrenStr =\n innerHTML !== undefined ? innerHTML : children.flat(Infinity).join('');\n return `<${tag}${attrs ? ` ${attrs}` : ''}>${childrenStr}</${tag}>`;\n },\n normalizeProps: (_tag: string, props: Record<string, any>) => {\n const normalized: Record<string, any> = {};\n for (const [key, value] of Object.entries(props)) {\n if (key === 'className') {\n normalized.class = value;\n } else if (key === 'htmlFor') {\n normalized.for = value;\n } else if (key === 'dangerouslySetInnerHTML' && (value as any)?.__html) {\n normalized._innerHTML = (value as any).__html;\n } else {\n normalized[key] = value;\n }\n }\n return normalized;\n },\n};\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n /** Returns the rendered markdown; render with .use(). */\n use: (components?: HTMLComponents<'permissive', {}>) => string;\n }\n >\n : never;\n\nexport const markdownStringPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const { plugins: _plugins, ...rest } = props;\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, subProps) =>\n renderIntlayerNode({\n ...subProps,\n value: metadataNode,\n children: node,\n }),\n };\n\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const compile = (components: any = {}) =>\n compileWithOptions(\n node,\n {\n ...vanillaRuntime,\n createElement: (tag: any, props: any, ...children: any[]) => {\n const override = components[tag];\n if (typeof override === 'function') {\n return override({ ...props, children: children.join('') });\n }\n return vanillaRuntime.createElement(tag, props, ...children);\n },\n },\n {}\n ) as any;\n\n const value = compile();\n let children = node;\n\n if (\n process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' &&\n editor.enabled\n ) {\n const keyPathJson = JSON.stringify(props.keyPath ?? []);\n const dictKey = String(props.dictionaryKey ?? '');\n children = `<intlayer-content-selector-wrapper key-path=\"${escapeHtmlAttr(keyPathJson)}\" dictionary-key=\"${escapeHtmlAttr(dictKey)}\">${escapeHtmlText(value)}</intlayer-content-selector-wrapper>`;\n }\n\n return renderIntlayerNode({\n ...props,\n value,\n children,\n additionalProps: {\n metadata: metadataNodes,\n use: (components?: any) => compile(components),\n },\n }) as any;\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n metadata?: infer U;\n tags?: infer U;\n}\n ? {\n use: (components?: HTMLComponents<'permissive', U>) => IntlayerNode<M>;\n metadata: DeepTransformContent<U>;\n }\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n { type: NodeTypes.MARKDOWN },\n ];\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? {\n use: (components?: HTMLComponents<'permissive', U>) => IntlayerNode<I>;\n }\n : never;\n\nexport const htmlPlugin: Plugins =\n process.env['INTLAYER_NODE_TYPE_HTML'] === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n transform: (node: HTMLContent<string>, props) => {\n const htmlStr = node[NodeTypes.HTML];\n\n const use = (components: Record<string, any> = {}) => {\n const wrappedComponents = new Proxy(components, {\n get(target, prop) {\n if (typeof prop === 'string' && prop in target) {\n const Component = target[prop];\n return (props: any) => {\n const children = Array.isArray(props.children)\n ? props.children.join('')\n : props.children;\n return Component({ ...props, children });\n };\n }\n if (typeof prop === 'string' && /^[a-z][a-z0-9]*$/.test(prop)) {\n return (props: any) => {\n const attrs = Object.entries(props)\n .filter(([key]) => key !== 'children' && key !== 'key')\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ');\n const children = Array.isArray(props.children)\n ? props.children.join('')\n : props.children;\n return `<${prop}${attrs ? ` ${attrs}` : ''}>${children}</${prop}>`;\n };\n }\n return undefined;\n },\n });\n\n const result = getHTML(htmlStr, wrappedComponents as any);\n return Array.isArray(result) ? result.join('') : result;\n };\n\n const value = use();\n let children = htmlStr;\n\n if (\n process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' &&\n editor.enabled\n ) {\n const keyPathJson = JSON.stringify(props.keyPath ?? []);\n const dictKey = String(props.dictionaryKey ?? '');\n children = `<intlayer-content-selector-wrapper key-path=\"${escapeHtmlAttr(keyPathJson)}\" dictionary-key=\"${escapeHtmlAttr(dictKey)}\">${escapeHtmlText(value)}</intlayer-content-selector-wrapper>`;\n }\n\n return renderIntlayerNode({\n ...props,\n value,\n children,\n additionalProps: {\n use: (components?: any) => use(components),\n },\n });\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport interface IInterpreterPluginVanilla<T, S, L extends LocalesValues> {\n vanillaIntlayerNode: IntlayerNodeCond<T>;\n vanillaInsertion: InsertionCond<T, S, L>;\n vanillaMarkdown: MarkdownCond<T>;\n vanillaHtml: HTMLPluginCond<T>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the `vanilla-intlayer` plugins will override the types of `intlayer` functions.\n * Use `getIntlayer` from `vanilla-intlayer` (not from `intlayer`) to get properly typed\n * `IntlayerNode` wrappers with `.value` access on string/number content.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion'\n> & {\n vanillaIntlayerNode: true;\n vanillaInsertion: true;\n vanillaMarkdown: true;\n vanillaHtml: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for Vanilla content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(locale ?? internationalization.defaultLocale),\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n intlayerNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;AAgDA,MAAM,kBAAkB,QACtB,IAAI,QAAQ,MAAM,QAAQ,CAAC,QAAQ,MAAM,SAAS;AAEpD,MAAM,kBAAkB,QACtB,IAAI,QAAQ,M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= value;
|
|
4
|
+
const displayOverride = typeof children === "string" && children !== String(value ?? "") ? children : null;
|
|
5
|
+
const node = {
|
|
6
|
+
toString: () => displayOverride ?? String(_value ?? ""),
|
|
7
|
+
valueOf: () => _value,
|
|
8
|
+
[Symbol.toPrimitive]: () => displayOverride ?? _value,
|
|
9
|
+
toJSON: () => _value,
|
|
8
10
|
get raw() {
|
|
9
|
-
return
|
|
11
|
+
return _value;
|
|
10
12
|
},
|
|
11
|
-
set raw(
|
|
12
|
-
|
|
13
|
+
set raw(value) {
|
|
14
|
+
_value = value;
|
|
13
15
|
},
|
|
14
16
|
get value() {
|
|
15
|
-
return
|
|
17
|
+
return _value;
|
|
16
18
|
},
|
|
17
|
-
__update(
|
|
18
|
-
|
|
19
|
+
__update(next) {
|
|
20
|
+
_value = next?.raw ?? next?.value ?? next;
|
|
19
21
|
},
|
|
20
|
-
...
|
|
22
|
+
...additionalProps
|
|
21
23
|
};
|
|
22
|
-
|
|
24
|
+
if (_value !== null && _value !== void 0) {
|
|
25
|
+
const valObj = Object(_value);
|
|
26
|
+
const proto = Object.getPrototypeOf(valObj);
|
|
27
|
+
for (const prop of Object.getOwnPropertyNames(proto)) {
|
|
28
|
+
if (prop === "constructor" || prop in node) continue;
|
|
29
|
+
const valProp = valObj[prop];
|
|
30
|
+
if (typeof valProp === "function") Object.defineProperty(node, prop, {
|
|
31
|
+
value: valProp.bind(_value),
|
|
32
|
+
writable: true,
|
|
33
|
+
configurable: true
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return node;
|
|
23
38
|
};
|
|
39
|
+
|
|
24
40
|
//#endregion
|
|
25
|
-
export {
|
|
41
|
+
export { renderIntlayerNode };
|
|
42
|
+
//# sourceMappingURL=renderIntlayerNode.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderIntlayerNode.mjs","names":[],"sources":["../../src/renderIntlayerNode.ts"],"sourcesContent":["import type { ResolvedEditor } from '@intlayer/types/module_augmentation';\n\nexport type IntlayerNode<T = string> = ResolvedEditor<\n T & {\n raw: T;\n value: T;\n toString: () => string;\n valueOf: () => T;\n toJSON: () => T;\n __update: (next: IntlayerNode<T>) => void;\n },\n {\n raw: T;\n value: T;\n toString: () => string;\n valueOf: () => T;\n toJSON: () => T;\n __update: (next: IntlayerNode<T>) => void;\n }\n> &\n T;\n\nexport const renderIntlayerNode = <\n T, // Broadened to support arrays, numbers, objects, etc.\n>({\n value,\n children,\n additionalProps = {},\n}: {\n value: T;\n children?: any;\n additionalProps?: Record<string, unknown>;\n [key: string]: unknown;\n}): IntlayerNode<T> => {\n let _value = value;\n\n // When children is a string that differs from value, it acts as a display\n // override (e.g. editor HTML wrapper). Otherwise toString/toPrimitive reflect\n // the live _value so that __update propagates.\n const displayOverride =\n typeof children === 'string' && children !== String(value ?? '')\n ? children\n : null;\n\n const node = {\n toString: () => displayOverride ?? String(_value ?? ''),\n valueOf: () => _value,\n [Symbol.toPrimitive]: () => displayOverride ?? _value,\n toJSON: () => _value,\n\n get raw() {\n return _value;\n },\n set raw(value: T) {\n _value = value;\n },\n\n get value() {\n return _value;\n },\n\n __update(next: any) {\n _value = next?.raw ?? next?.value ?? next;\n },\n\n ...additionalProps,\n };\n\n // Delegate native methods from the underlying value (any type) to node.\n if (_value !== null && _value !== undefined) {\n const valObj = Object(_value); // Safely boxes primitives (e.g., 50 -> Number object)\n const proto = Object.getPrototypeOf(valObj);\n for (const prop of Object.getOwnPropertyNames(proto)) {\n if (prop === 'constructor' || prop in node) continue;\n const valProp = valObj[prop]; // read from instance so length/index values are correct\n if (typeof valProp === 'function') {\n Object.defineProperty(node, prop, {\n value: valProp.bind(_value),\n writable: true,\n configurable: true,\n });\n }\n }\n }\n\n return node as unknown as IntlayerNode<T>;\n};\n"],"mappings":";AAsBA,MAAa,sBAEX,EACA,OACA,UACA,kBAAkB,EAAE,OAMC;CACrB,IAAI,SAAS;CAKb,MAAM,kBACJ,OAAO,aAAa,YAAY,aAAa,OAAO,SAAS,GAAG,GAC5D,WACA;CAEN,MAAM,OAAO;EACX,gBAAgB,mBAAmB,OAAO,UAAU,GAAG;EACvD,eAAe;GACd,OAAO,oBAAoB,mBAAmB;EAC/C,cAAc;EAEd,IAAI,MAAM;AACR,UAAO;;EAET,IAAI,IAAI,OAAU;AAChB,YAAS;;EAGX,IAAI,QAAQ;AACV,UAAO;;EAGT,SAAS,MAAW;AAClB,YAAS,MAAM,OAAO,MAAM,SAAS;;EAGvC,GAAG;EACJ;AAGD,KAAI,WAAW,QAAQ,WAAW,QAAW;EAC3C,MAAM,SAAS,OAAO,OAAO;EAC7B,MAAM,QAAQ,OAAO,eAAe,OAAO;AAC3C,OAAK,MAAM,QAAQ,OAAO,oBAAoB,MAAM,EAAE;AACpD,OAAI,SAAS,iBAAiB,QAAQ,KAAM;GAC5C,MAAM,UAAU,OAAO;AACvB,OAAI,OAAO,YAAY,WACrB,QAAO,eAAe,MAAM,MAAM;IAChC,OAAO,QAAQ,KAAK,OAAO;IAC3B,UAAU;IACV,cAAc;IACf,CAAC;;;AAKR,QAAO"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IntlayerClient, createIntlayerClient, getIntlayerClient, installIntlayer } from "./installIntlayer.js";
|
|
2
|
+
import { WithOnChange, useDictionary } from "./useDictionary.js";
|
|
3
|
+
import { useDictionaryDynamic } from "./useDictionaryDynamic.js";
|
|
4
|
+
import { useIntlayer } from "./useIntlayer.js";
|
|
5
|
+
import { useLocale } from "./useLocale.js";
|
|
6
|
+
import { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./useLocaleStorage.js";
|
|
7
|
+
import { useRewriteURL } from "./useRewriteURL.js";
|
|
8
|
+
export { IntlayerClient, WithOnChange, createIntlayerClient, getIntlayerClient, installIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage, useRewriteURL };
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import { LocalesValues } from
|
|
1
|
+
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
|
+
|
|
3
|
+
//#region src/client/installIntlayer.d.ts
|
|
2
4
|
type LocaleListener = (locale: LocalesValues) => void;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
declare class IntlayerClient {
|
|
6
|
+
private _locale;
|
|
7
|
+
private _listeners;
|
|
8
|
+
isCookieEnabled: boolean;
|
|
9
|
+
constructor(locale?: LocalesValues, isCookieEnabled?: boolean);
|
|
10
|
+
get locale(): LocalesValues;
|
|
11
|
+
setLocale(newLocale: LocalesValues): void;
|
|
12
|
+
subscribe(listener: LocaleListener): () => void;
|
|
13
|
+
/**
|
|
14
|
+
* Fire all listeners with the current locale without changing it.
|
|
15
|
+
* Used to trigger re-renders after async data loads.
|
|
16
|
+
*/
|
|
17
|
+
notify(): void;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* Create and return a single IntlayerClient instance.
|
|
19
21
|
*/
|
|
20
|
-
|
|
22
|
+
declare const createIntlayerClient: (locale?: LocalesValues, isCookieEnabled?: boolean) => IntlayerClient;
|
|
21
23
|
/**
|
|
22
24
|
* Get the current IntlayerClient instance, creating one with defaults if needed.
|
|
23
25
|
*/
|
|
24
|
-
|
|
26
|
+
declare const getIntlayerClient: () => IntlayerClient;
|
|
25
27
|
/**
|
|
26
28
|
* Install Intlayer into your vanilla JS application.
|
|
27
29
|
*
|
|
@@ -51,8 +53,13 @@ export declare const getIntlayerClient: () => IntlayerClient;
|
|
|
51
53
|
* installIntlayer('en');
|
|
52
54
|
* ```
|
|
53
55
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
declare const installIntlayer: ({
|
|
57
|
+
locale,
|
|
58
|
+
isCookieEnabled
|
|
59
|
+
}?: {
|
|
60
|
+
locale?: LocalesValues;
|
|
61
|
+
isCookieEnabled?: boolean;
|
|
57
62
|
}) => IntlayerClient;
|
|
58
|
-
|
|
63
|
+
//#endregion
|
|
64
|
+
export { IntlayerClient, createIntlayerClient, getIntlayerClient, installIntlayer };
|
|
65
|
+
//# sourceMappingURL=installIntlayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installIntlayer.d.ts","names":[],"sources":["../../../src/client/installIntlayer.ts"],"mappings":";;;KAKK,cAAA,IAAkB,MAAA,EAAQ,aAAA;AAAA,cAElB,cAAA;EAAA,QACH,OAAA;EAAA,QACA,UAAA;EACR,eAAA;cAEY,MAAA,GAAS,aAAA,EAAe,eAAA;EAAA,IAUhC,MAAA,CAAA,GAAU,aAAA;EAId,SAAA,CAAU,SAAA,EAAW,aAAA;EAOrB,SAAA,CAAU,QAAA,EAAU,cAAA;;;;;EAWpB,MAAA,CAAA;AAAA;;;;cAeW,oBAAA,GACX,MAAA,GAAS,aAAA,EACT,eAAA,eACC,cAAA;;;;cAUU,iBAAA,QAAwB,cAAA;;;;;;;;;;;;AAbrC;;;;;;;;;;AAaA;;;;;AAoCA;;;cAAa,eAAA;EAAmB,MAAA;EAAA;AAAA;EAI9B,MAAA,GAAS,aAAA;EACT,eAAA;AAAA,MACO,cAAA"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DeclaredLocales, LocalesValues } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { DeepTransformContent } from "../plugins.js";
|
|
2
|
+
import { DeclaredLocales, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
|
+
import { Dictionary } from "@intlayer/types/dictionary";
|
|
4
|
+
|
|
5
|
+
//#region src/client/useDictionary.d.ts
|
|
6
|
+
type WithOnChange<T> = T & {
|
|
7
|
+
/**
|
|
8
|
+
* Subscribe to locale changes. The callback receives the fresh content
|
|
9
|
+
* whenever the active locale changes. Returns the content object itself
|
|
10
|
+
* for convenient one-liner patterns:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const content = useDictionary(myDict).onChange((c) => {
|
|
14
|
+
* document.querySelector('p')!.textContent = String(c.greeting);
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
onChange: (callback: <T extends Dictionary, L extends LocalesValues>(content: DeepTransformContent<T['content'], L>) => void) => WithOnChange<T>;
|
|
17
19
|
};
|
|
18
20
|
/**
|
|
19
21
|
* Get the translated content for a raw dictionary object and optionally
|
|
@@ -54,4 +56,7 @@ export type WithOnChange<T> = T & {
|
|
|
54
56
|
* document.querySelector('p').textContent = String(content.greeting);
|
|
55
57
|
* ```
|
|
56
58
|
*/
|
|
57
|
-
|
|
59
|
+
declare const useDictionary: <T extends Dictionary, L extends LocalesValues = DeclaredLocales>(dictionary: T, locale?: L) => WithOnChange<DeepTransformContent<T["content"], L>>;
|
|
60
|
+
//#endregion
|
|
61
|
+
export { WithOnChange, useDictionary };
|
|
62
|
+
//# sourceMappingURL=useDictionary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionary.d.ts","names":[],"sources":["../../../src/client/useDictionary.ts"],"mappings":";;;;;KASY,YAAA,MAAkB,CAAA;;AAA9B;;;;;;;;;;EAYE,QAAA,GACE,QAAA,aAAqB,UAAA,YAAsB,aAAA,EACzC,OAAA,EAAS,oBAAA,CAAqB,CAAA,aAAc,CAAA,eAE3C,YAAA,CAAa,CAAA;AAAA;;;;;;;;;;;;;;;;;;AA0CpB;;;;;;;;;;;;;;;;;;;;;;cAAa,aAAA,aACD,UAAA,YACA,aAAA,GAAgB,eAAA,EAE1B,UAAA,EAAY,CAAA,EACZ,MAAA,GAAS,CAAA,KACR,YAAA,CAAa,oBAAA,CAAqB,CAAA,aAAc,CAAA"}
|