@intlayer/core 7.6.0-canary.1 → 8.0.0-canary.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/dictionaryManipulator/editDictionaryByKeyPath.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +5 -0
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/index.cjs +56 -2
- package/dist/cjs/interpreter/getContent/deepTransform.cjs +1 -0
- package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/getContent.cjs +2 -2
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs +3 -2
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getEnumeration.cjs.map +1 -1
- package/dist/cjs/interpreter/getHTML.cjs +106 -0
- package/dist/cjs/interpreter/getHTML.cjs.map +1 -0
- package/dist/cjs/interpreter/getInsertion.cjs +3 -1
- package/dist/cjs/interpreter/getInsertion.cjs.map +1 -1
- package/dist/cjs/interpreter/getTranslation.cjs +2 -2
- package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
- package/dist/cjs/interpreter/index.cjs +2 -0
- package/dist/cjs/localization/getBrowserLocale.cjs +1 -1
- package/dist/cjs/localization/getLocale.cjs +4 -3
- package/dist/cjs/localization/getLocale.cjs.map +1 -1
- package/dist/cjs/markdown/compiler.cjs +806 -0
- package/dist/cjs/markdown/compiler.cjs.map +1 -0
- package/dist/cjs/markdown/constants.cjs +334 -0
- package/dist/cjs/markdown/constants.cjs.map +1 -0
- package/dist/cjs/markdown/index.cjs +49 -0
- package/dist/cjs/markdown/parser.cjs +73 -0
- package/dist/cjs/markdown/parser.cjs.map +1 -0
- package/dist/cjs/markdown/renderer.cjs +68 -0
- package/dist/cjs/markdown/renderer.cjs.map +1 -0
- package/dist/cjs/markdown/types.cjs +0 -0
- package/dist/cjs/markdown/utils.cjs +397 -0
- package/dist/cjs/markdown/utils.cjs.map +1 -0
- package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs +15 -0
- package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs.map +1 -0
- package/dist/cjs/transpiler/html/index.cjs +133 -0
- package/dist/cjs/transpiler/html/index.cjs.map +1 -0
- package/dist/cjs/transpiler/index.cjs +3 -0
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs +2 -2
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs.map +1 -1
- package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -1
- package/dist/cjs/utils/intl.cjs +35 -3
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +1 -1
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs +1 -1
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs +5 -0
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getEmptyNode.mjs +1 -1
- package/dist/esm/dictionaryManipulator/getEmptyNode.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +1 -1
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs +1 -1
- package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs +1 -1
- package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/index.mjs +11 -4
- package/dist/esm/interpreter/getContent/deepTransform.mjs +1 -0
- package/dist/esm/interpreter/getContent/deepTransform.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/getContent.mjs +2 -2
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/plugins.mjs +3 -2
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getEnumeration.mjs.map +1 -1
- package/dist/esm/interpreter/getHTML.mjs +105 -0
- package/dist/esm/interpreter/getHTML.mjs.map +1 -0
- package/dist/esm/interpreter/getInsertion.mjs +3 -1
- package/dist/esm/interpreter/getInsertion.mjs.map +1 -1
- package/dist/esm/interpreter/getTranslation.mjs +2 -2
- package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
- package/dist/esm/interpreter/index.mjs +2 -1
- package/dist/esm/localization/getBrowserLocale.mjs +1 -1
- package/dist/esm/localization/getLocale.mjs +2 -1
- package/dist/esm/localization/getLocale.mjs.map +1 -1
- package/dist/esm/markdown/compiler.mjs +804 -0
- package/dist/esm/markdown/compiler.mjs.map +1 -0
- package/dist/esm/markdown/constants.mjs +254 -0
- package/dist/esm/markdown/constants.mjs.map +1 -0
- package/dist/esm/markdown/index.mjs +7 -0
- package/dist/esm/markdown/parser.mjs +73 -0
- package/dist/esm/markdown/parser.mjs.map +1 -0
- package/dist/esm/markdown/renderer.mjs +67 -0
- package/dist/esm/markdown/renderer.mjs.map +1 -0
- package/dist/esm/markdown/types.mjs +0 -0
- package/dist/esm/markdown/utils.mjs +368 -0
- package/dist/esm/markdown/utils.mjs.map +1 -0
- package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs +15 -0
- package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs.map +1 -0
- package/dist/esm/transpiler/html/index.mjs +131 -0
- package/dist/esm/transpiler/html/index.mjs.map +1 -0
- package/dist/esm/transpiler/index.mjs +2 -1
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs +2 -2
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs.map +1 -1
- package/dist/esm/transpiler/insertion/insertion.mjs.map +1 -1
- package/dist/esm/utils/intl.mjs +35 -4
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +11 -10
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +11 -10
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +11 -10
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
- package/dist/types/getStorageAttributes.d.ts.map +1 -1
- package/dist/types/index.d.ts +11 -3
- package/dist/types/interpreter/getContent/getContent.d.ts +1 -1
- package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/index.d.ts +2 -2
- package/dist/types/interpreter/getContent/plugins.d.ts +58 -18
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/interpreter/getEnumeration.d.ts +1 -1
- package/dist/types/interpreter/getHTML.d.ts +14 -0
- package/dist/types/interpreter/getHTML.d.ts.map +1 -0
- package/dist/types/interpreter/getTranslation.d.ts.map +1 -1
- package/dist/types/interpreter/index.d.ts +3 -2
- package/dist/types/localization/getLocale.d.ts.map +1 -1
- package/dist/types/markdown/compiler.d.ts +10 -0
- package/dist/types/markdown/compiler.d.ts.map +1 -0
- package/dist/types/markdown/constants.d.ts +193 -0
- package/dist/types/markdown/constants.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +7 -0
- package/dist/types/markdown/parser.d.ts +17 -0
- package/dist/types/markdown/parser.d.ts.map +1 -0
- package/dist/types/markdown/renderer.d.ts +23 -0
- package/dist/types/markdown/renderer.d.ts.map +1 -0
- package/dist/types/markdown/types.d.ts +367 -0
- package/dist/types/markdown/types.d.ts.map +1 -0
- package/dist/types/markdown/utils.d.ts +141 -0
- package/dist/types/markdown/utils.d.ts.map +1 -0
- package/dist/types/messageFormat/ICU.d.ts.map +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
- package/dist/types/transpiler/html/getHTMLCustomComponents.d.ts +9 -0
- package/dist/types/transpiler/html/getHTMLCustomComponents.d.ts.map +1 -0
- package/dist/types/transpiler/html/index.d.ts +33 -0
- package/dist/types/transpiler/html/index.d.ts.map +1 -0
- package/dist/types/transpiler/index.d.ts +2 -1
- package/dist/types/utils/intl.d.ts +21 -2
- package/dist/types/utils/intl.d.ts.map +1 -1
- package/package.json +15 -7
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_transpiler_html_getHTMLCustomComponents = require('./getHTMLCustomComponents.cjs');
|
|
3
|
+
let _intlayer_types = require("@intlayer/types");
|
|
4
|
+
|
|
5
|
+
//#region src/transpiler/html/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* Function intended to be used to build intlayer dictionaries.
|
|
8
|
+
*
|
|
9
|
+
* Allow to parse HTML/JSX-like strings and replace tags with components during interpretation.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* html('Hello <b>World</b>')
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
const html = (content) => (0, _intlayer_types.formatNodeType)(_intlayer_types.NodeType.HTML, content, { customComponents: require_transpiler_html_getHTMLCustomComponents.getHTMLCustomComponents(content) });
|
|
19
|
+
/**
|
|
20
|
+
* List of standard HTML tags to provide as default components.
|
|
21
|
+
* These allow users to use standard HTML tags in their html() content
|
|
22
|
+
* without having to pass them explicitly.
|
|
23
|
+
*
|
|
24
|
+
* Used by framework-specific plugins (react-intlayer, vue-intlayer, etc.)
|
|
25
|
+
* to create default HTML tag components.
|
|
26
|
+
*/
|
|
27
|
+
const HTML_TAGS = [
|
|
28
|
+
"html",
|
|
29
|
+
"head",
|
|
30
|
+
"body",
|
|
31
|
+
"main",
|
|
32
|
+
"header",
|
|
33
|
+
"footer",
|
|
34
|
+
"nav",
|
|
35
|
+
"aside",
|
|
36
|
+
"article",
|
|
37
|
+
"section",
|
|
38
|
+
"div",
|
|
39
|
+
"span",
|
|
40
|
+
"h1",
|
|
41
|
+
"h2",
|
|
42
|
+
"h3",
|
|
43
|
+
"h4",
|
|
44
|
+
"h5",
|
|
45
|
+
"h6",
|
|
46
|
+
"p",
|
|
47
|
+
"a",
|
|
48
|
+
"strong",
|
|
49
|
+
"b",
|
|
50
|
+
"em",
|
|
51
|
+
"i",
|
|
52
|
+
"u",
|
|
53
|
+
"s",
|
|
54
|
+
"del",
|
|
55
|
+
"ins",
|
|
56
|
+
"mark",
|
|
57
|
+
"small",
|
|
58
|
+
"sub",
|
|
59
|
+
"sup",
|
|
60
|
+
"code",
|
|
61
|
+
"pre",
|
|
62
|
+
"blockquote",
|
|
63
|
+
"q",
|
|
64
|
+
"cite",
|
|
65
|
+
"abbr",
|
|
66
|
+
"address",
|
|
67
|
+
"time",
|
|
68
|
+
"kbd",
|
|
69
|
+
"samp",
|
|
70
|
+
"var",
|
|
71
|
+
"ul",
|
|
72
|
+
"ol",
|
|
73
|
+
"li",
|
|
74
|
+
"dl",
|
|
75
|
+
"dt",
|
|
76
|
+
"dd",
|
|
77
|
+
"table",
|
|
78
|
+
"thead",
|
|
79
|
+
"tbody",
|
|
80
|
+
"tfoot",
|
|
81
|
+
"tr",
|
|
82
|
+
"th",
|
|
83
|
+
"td",
|
|
84
|
+
"caption",
|
|
85
|
+
"colgroup",
|
|
86
|
+
"col",
|
|
87
|
+
"form",
|
|
88
|
+
"input",
|
|
89
|
+
"textarea",
|
|
90
|
+
"button",
|
|
91
|
+
"select",
|
|
92
|
+
"option",
|
|
93
|
+
"optgroup",
|
|
94
|
+
"label",
|
|
95
|
+
"fieldset",
|
|
96
|
+
"legend",
|
|
97
|
+
"datalist",
|
|
98
|
+
"output",
|
|
99
|
+
"progress",
|
|
100
|
+
"meter",
|
|
101
|
+
"img",
|
|
102
|
+
"video",
|
|
103
|
+
"audio",
|
|
104
|
+
"source",
|
|
105
|
+
"track",
|
|
106
|
+
"picture",
|
|
107
|
+
"figure",
|
|
108
|
+
"figcaption",
|
|
109
|
+
"iframe",
|
|
110
|
+
"embed",
|
|
111
|
+
"object",
|
|
112
|
+
"canvas",
|
|
113
|
+
"svg",
|
|
114
|
+
"details",
|
|
115
|
+
"summary",
|
|
116
|
+
"dialog",
|
|
117
|
+
"br",
|
|
118
|
+
"hr",
|
|
119
|
+
"wbr",
|
|
120
|
+
"ruby",
|
|
121
|
+
"rt",
|
|
122
|
+
"rp",
|
|
123
|
+
"bdi",
|
|
124
|
+
"bdo",
|
|
125
|
+
"data",
|
|
126
|
+
"template",
|
|
127
|
+
"slot"
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
exports.HTML_TAGS = HTML_TAGS;
|
|
132
|
+
exports.html = html;
|
|
133
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["NodeType","getHTMLCustomComponents"],"sources":["../../../../src/transpiler/html/index.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\nimport { getHTMLCustomComponents } from './getHTMLCustomComponents';\n\nexport type HTMLContentConstructor<\n Content = string,\n T extends Record<string, any> = {},\n> = TypedNodeModel<NodeType.HTML, Content, T>;\n\nexport type HTMLContent<Content = string> = HTMLContentConstructor<\n Content,\n {\n customComponents: string[];\n }\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to parse HTML/JSX-like strings and replace tags with components during interpretation.\n *\n * Usage:\n *\n * ```ts\n * html('Hello <b>World</b>')\n * ```\n *\n */\nexport const html = (content: string): HTMLContent =>\n formatNodeType(NodeType.HTML, content, {\n customComponents: getHTMLCustomComponents(content),\n });\n\n/**\n * List of standard HTML tags to provide as default components.\n * These allow users to use standard HTML tags in their html() content\n * without having to pass them explicitly.\n *\n * Used by framework-specific plugins (react-intlayer, vue-intlayer, etc.)\n * to create default HTML tag components.\n */\nexport const HTML_TAGS = [\n // Document structure\n 'html',\n 'head',\n 'body',\n 'main',\n 'header',\n 'footer',\n 'nav',\n 'aside',\n 'article',\n 'section',\n 'div',\n 'span',\n // Headings\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n // Text content\n 'p',\n 'a',\n 'strong',\n 'b',\n 'em',\n 'i',\n 'u',\n 's',\n 'del',\n 'ins',\n 'mark',\n 'small',\n 'sub',\n 'sup',\n 'code',\n 'pre',\n 'blockquote',\n 'q',\n 'cite',\n 'abbr',\n 'address',\n 'time',\n 'kbd',\n 'samp',\n 'var',\n // Lists\n 'ul',\n 'ol',\n 'li',\n 'dl',\n 'dt',\n 'dd',\n // Tables\n 'table',\n 'thead',\n 'tbody',\n 'tfoot',\n 'tr',\n 'th',\n 'td',\n 'caption',\n 'colgroup',\n 'col',\n // Forms\n 'form',\n 'input',\n 'textarea',\n 'button',\n 'select',\n 'option',\n 'optgroup',\n 'label',\n 'fieldset',\n 'legend',\n 'datalist',\n 'output',\n 'progress',\n 'meter',\n // Media\n 'img',\n 'video',\n 'audio',\n 'source',\n 'track',\n 'picture',\n 'figure',\n 'figcaption',\n 'iframe',\n 'embed',\n 'object',\n 'canvas',\n 'svg',\n // Interactive\n 'details',\n 'summary',\n 'dialog',\n // Other\n 'br',\n 'hr',\n 'wbr',\n 'ruby',\n 'rt',\n 'rp',\n 'bdi',\n 'bdo',\n 'data',\n 'template',\n 'slot',\n] as const;\n\nexport type HTMLTagDefault = (typeof HTML_TAGS)[number];\n"],"mappings":";;;;;;;;;;;;;;;;;AA2BA,MAAa,QAAQ,gDACJA,yBAAS,MAAM,SAAS,EACrC,kBAAkBC,wEAAwB,QAAQ,EACnD,CAAC;;;;;;;;;AAUJ,MAAa,YAAY;CAEvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_transpiler_condition_condition = require('./condition/condition.cjs');
|
|
2
2
|
const require_transpiler_enumeration_enumeration = require('./enumeration/enumeration.cjs');
|
|
3
3
|
const require_transpiler_gender_gender = require('./gender/gender.cjs');
|
|
4
|
+
const require_transpiler_html_index = require('./html/index.cjs');
|
|
4
5
|
const require_transpiler_insertion_getInsertionValues = require('./insertion/getInsertionValues.cjs');
|
|
5
6
|
const require_transpiler_insertion_insertion = require('./insertion/insertion.cjs');
|
|
6
7
|
const require_transpiler_markdown_getMarkdownMetadata = require('./markdown/getMarkdownMetadata.cjs');
|
|
@@ -8,11 +9,13 @@ const require_transpiler_markdown_markdown = require('./markdown/markdown.cjs');
|
|
|
8
9
|
const require_transpiler_nesting_nesting = require('./nesting/nesting.cjs');
|
|
9
10
|
const require_transpiler_translation_translation = require('./translation/translation.cjs');
|
|
10
11
|
|
|
12
|
+
exports.HTML_TAGS = require_transpiler_html_index.HTML_TAGS;
|
|
11
13
|
exports.cond = require_transpiler_condition_condition.cond;
|
|
12
14
|
exports.enu = require_transpiler_enumeration_enumeration.enu;
|
|
13
15
|
exports.gender = require_transpiler_gender_gender.gender;
|
|
14
16
|
exports.getInsertionValues = require_transpiler_insertion_getInsertionValues.getInsertionValues;
|
|
15
17
|
exports.getMarkdownMetadata = require_transpiler_markdown_getMarkdownMetadata.getMarkdownMetadata;
|
|
18
|
+
exports.html = require_transpiler_html_index.html;
|
|
16
19
|
exports.insert = require_transpiler_insertion_insertion.insert;
|
|
17
20
|
exports.md = require_transpiler_markdown_markdown.md;
|
|
18
21
|
exports.nest = require_transpiler_nesting_nesting.nest;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/transpiler/insertion/getInsertionValues.ts
|
|
3
3
|
const getInsertionValues = (content) => {
|
|
4
|
-
const matches = [...content.matchAll(/{{\s*(
|
|
4
|
+
const matches = [...content.matchAll(/{{\s*(.*?)\s*}}/g)];
|
|
5
5
|
if (matches.length === 0) return [];
|
|
6
|
-
return [...new Set(matches.map((match) => match[1]))];
|
|
6
|
+
return [...new Set(matches.map((match) => match[1].trim()))].filter(Boolean);
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInsertionValues.cjs","names":[],"sources":["../../../../src/transpiler/insertion/getInsertionValues.ts"],"sourcesContent":["export const getInsertionValues = (content: string): string[] => {\n // Regular expression to match {{field}} patterns\n const regex = /{{\\s*(
|
|
1
|
+
{"version":3,"file":"getInsertionValues.cjs","names":[],"sources":["../../../../src/transpiler/insertion/getInsertionValues.ts"],"sourcesContent":["export const getInsertionValues = (content: string): string[] => {\n // Regular expression to match {{field}} patterns\n const regex = /{{\\s*(.*?)\\s*}}/g;\n const matches = [...content.matchAll(regex)];\n\n // If no matches are found, return undefined\n if (matches.length === 0) return [];\n\n // Extract field names from matches and return as an object with the field names\n return [...new Set(matches.map((match) => match[1].trim()))].filter(Boolean);\n};\n"],"mappings":";;AAAA,MAAa,sBAAsB,YAA8B;CAG/D,MAAM,UAAU,CAAC,GAAG,QAAQ,SADd,mBAC6B,CAAC;AAG5C,KAAI,QAAQ,WAAW,EAAG,QAAO,EAAE;AAGnC,QAAO,CAAC,GAAG,IAAI,IAAI,QAAQ,KAAK,UAAU,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertion.cjs","names":["getInsertionValues","NodeType"],"sources":["../../../../src/transpiler/insertion/insertion.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\nimport { getInsertionValues } from './getInsertionValues';\n\nexport type InsertionContentConstructor<\n Content = unknown,\n T extends Record<string, any> = {},\n> = TypedNodeModel<NodeType.Insertion, Content, T>;\n\nexport type InsertionContent<Content = unknown> = InsertionContentConstructor<\n Content,\n {\n fields: string[];\n }\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to identify insertions inside a content.\n *\n * Usage:\n *\n * ```ts\n * insertion('Hi, my name is {{name}} and I am {{age}} years old.')\n * ```\n *\n */\nconst insertion = <Content = unknown>(\n content: Content\n): InsertionContent<Content> => {\n const getInsertions = () => {\n if (typeof content === 'string') {\n return getInsertionValues(content);\n }\n\n let stringContent;\n\n if (typeof content === 'function') {\n stringContent = content();\n } else if (typeof (content as Promise<string>).then === 'function') {\n stringContent = async () =>\n getInsertionValues(await (content as Promise<string>));\n }\n\n if (typeof stringContent === 'string') {\n return getInsertionValues(stringContent);\n }\n\n try {\n return getInsertionValues(JSON.stringify(content));\n } catch (_e) {\n return [];\n }\n };\n\n return formatNodeType(NodeType.Insertion, content, {\n fields: getInsertions(),\n });\n};\n\nexport { insertion as insert };\n"],"mappings":";;;;;;;;;;;;;;;;;AA2BA,MAAM,aACJ,YAC8B;CAC9B,MAAM,sBAAsB;AAC1B,MAAI,OAAO,YAAY,SACrB,QAAOA,mEAAmB,QAAQ;EAGpC,IAAI;AAEJ,MAAI,OAAO,YAAY,WACrB,iBAAgB,SAAS;WAChB,OAAQ,QAA4B,SAAS,WACtD,iBAAgB,YACdA,mEAAmB,MAAO,QAA4B;AAG1D,MAAI,OAAO,kBAAkB,SAC3B,QAAOA,mEAAmB,cAAc;AAG1C,MAAI;AACF,UAAOA,mEAAmB,KAAK,UAAU,QAAQ,CAAC;WAC3C,IAAI;AACX,UAAO,EAAE;;;AAIb,4CAAsBC,yBAAS,WAAW,SAAS,EACjD,QAAQ,eAAe,EACxB,CAAC"}
|
|
1
|
+
{"version":3,"file":"insertion.cjs","names":["getInsertionValues","NodeType"],"sources":["../../../../src/transpiler/insertion/insertion.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\nimport { getInsertionValues } from './getInsertionValues';\n\nexport type InsertionContentConstructor<\n Content = unknown,\n T extends Record<string, any> = {},\n> = TypedNodeModel<NodeType.Insertion, Content, T>;\n\nexport type InsertionContent<Content = unknown> = InsertionContentConstructor<\n Content,\n {\n fields: string[];\n }\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to identify insertions inside a content.\n *\n * Usage:\n *\n * ```ts\n * insertion('Hi, my name is {{name}} and I am {{age}} years old.')\n * ```\n *\n */\nconst insertion = <Content = unknown>(\n content: Content\n): InsertionContent<Content> => {\n const getInsertions = () => {\n if (typeof content === 'string') {\n return getInsertionValues(content);\n }\n\n let stringContent: any;\n\n if (typeof content === 'function') {\n stringContent = content();\n } else if (typeof (content as Promise<string>).then === 'function') {\n stringContent = async () =>\n getInsertionValues(await (content as Promise<string>));\n }\n\n if (typeof stringContent === 'string') {\n return getInsertionValues(stringContent);\n }\n\n try {\n return getInsertionValues(JSON.stringify(content));\n } catch (_e) {\n return [];\n }\n };\n\n return formatNodeType(NodeType.Insertion, content, {\n fields: getInsertions(),\n });\n};\n\nexport { insertion as insert };\n"],"mappings":";;;;;;;;;;;;;;;;;AA2BA,MAAM,aACJ,YAC8B;CAC9B,MAAM,sBAAsB;AAC1B,MAAI,OAAO,YAAY,SACrB,QAAOA,mEAAmB,QAAQ;EAGpC,IAAI;AAEJ,MAAI,OAAO,YAAY,WACrB,iBAAgB,SAAS;WAChB,OAAQ,QAA4B,SAAS,WACtD,iBAAgB,YACdA,mEAAmB,MAAO,QAA4B;AAG1D,MAAI,OAAO,kBAAkB,SAC3B,QAAOA,mEAAmB,cAAc;AAG1C,MAAI;AACF,UAAOA,mEAAmB,KAAK,UAAU,QAAQ,CAAC;WAC3C,IAAI;AACX,UAAO,EAAE;;;AAIb,4CAAsBC,yBAAS,WAAW,SAAS,EACjD,QAAQ,eAAe,EACxB,CAAC"}
|
package/dist/cjs/utils/intl.cjs
CHANGED
|
@@ -19,11 +19,17 @@ const createCachedConstructor = (Ctor) => {
|
|
|
19
19
|
const cache = /* @__PURE__ */ new Map();
|
|
20
20
|
const MAX_CACHE_SIZE = 50;
|
|
21
21
|
function Wrapped(locales, options) {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
let resolvedLocales = locales;
|
|
23
|
+
let resolvedOptions = options;
|
|
24
|
+
if (typeof locales === "object" && !Array.isArray(locales) && locales !== null) {
|
|
25
|
+
resolvedOptions = locales;
|
|
26
|
+
resolvedLocales = locales.locale;
|
|
27
|
+
}
|
|
28
|
+
if (Ctor.name === "DisplayNames" && typeof Intl?.DisplayNames !== "function") {}
|
|
29
|
+
const key = getCacheKey(resolvedLocales, resolvedOptions);
|
|
24
30
|
let instance = cache.get(key);
|
|
25
31
|
if (instance) return instance;
|
|
26
|
-
instance = new Ctor(
|
|
32
|
+
instance = new Ctor(resolvedLocales, resolvedOptions);
|
|
27
33
|
if (cache.size >= MAX_CACHE_SIZE) {
|
|
28
34
|
const oldestKey = cache.keys().next().value;
|
|
29
35
|
if (oldestKey) cache.delete(oldestKey);
|
|
@@ -51,9 +57,35 @@ const createCachedIntl = () => {
|
|
|
51
57
|
} });
|
|
52
58
|
};
|
|
53
59
|
const CachedIntl = createCachedIntl();
|
|
60
|
+
/**
|
|
61
|
+
* Creates a proxied Intl object with a preset locale.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* const intl = bindIntl(Locales.FRENCH);
|
|
65
|
+
* new intl.NumberFormat(undefined, { style: 'currency', currency: 'EUR' }).format(10);
|
|
66
|
+
* // Uses 'fr' automatically
|
|
67
|
+
*/
|
|
68
|
+
const bindIntl = (locale) => {
|
|
69
|
+
return new Proxy(CachedIntl, { get: (target, prop) => {
|
|
70
|
+
const value = Reflect.get(target, prop);
|
|
71
|
+
if (typeof value === "function" && typeof prop === "string" && /^[A-Z]/.test(prop)) return new Proxy(value, {
|
|
72
|
+
construct: (Ctor, args) => {
|
|
73
|
+
let [locales, options] = args;
|
|
74
|
+
if (typeof locales === "object" && !Array.isArray(locales) && locales !== null) {
|
|
75
|
+
options = locales;
|
|
76
|
+
locales = options.locale ?? locale;
|
|
77
|
+
} else if (locales === void 0) locales = locale;
|
|
78
|
+
return new Ctor(locales, options);
|
|
79
|
+
},
|
|
80
|
+
get: (Ctor, key) => Reflect.get(Ctor, key)
|
|
81
|
+
});
|
|
82
|
+
return value;
|
|
83
|
+
} });
|
|
84
|
+
};
|
|
54
85
|
|
|
55
86
|
//#endregion
|
|
56
87
|
exports.CachedIntl = CachedIntl;
|
|
57
88
|
exports.Intl = CachedIntl;
|
|
89
|
+
exports.bindIntl = bindIntl;
|
|
58
90
|
exports.createCachedIntl = createCachedIntl;
|
|
59
91
|
//# sourceMappingURL=intl.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intl.cjs","names":["Locales"],"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { Locales, type LocalesValues } from '@intlayer/types';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (\n ...args: any\n ) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? new (\n locales?: LocalesValues,\n options?: Options\n ) => Instance\n : T extends new (\n locales: any\n ) => infer Instance\n ? new (\n locales?: LocalesValues\n ) => Instance\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// ... (Keep your Type Helper definitions here: IntlConstructors, ReplaceLocaleWithLocalesValues, WrappedIntl) ...\n\n/**\n * Optimized Cache Key Generator\n * 1. Fast path: If no options, just use the locale string.\n * 2. Normal path: JSON.stringify for deterministic object comparison.\n */\nconst getCacheKey = (\n locales: LocalesValues | undefined,\n options: unknown\n): string => {\n const localeKey = locales ? String(locales) : Locales.ENGLISH;\n\n if (!options) return localeKey;\n\n // JSON.stringify is the most robust way to handle nested options objects\n // without a heavy custom hashing function.\n return `${localeKey}|${JSON.stringify(options)}`;\n};\n\n/**\n * Generic wrapper for any `new Intl.*()` constructor.\n */\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n // The cache lives here, inside the closure of the wrapped constructor.\n const cache = new Map<string, InstanceType<T>>();\n const MAX_CACHE_SIZE = 50;\n\n function Wrapped(locales?: LocalesValues, options?: any) {\n // 1. Handle DisplayNames Polyfill warning (Keep your existing logic here)\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n // ... (Your existing polyfill warning logic) ...\n return locales as any;\n }\n\n // 2. Generate Key\n const key = getCacheKey(locales, options);\n\n // 3. Check Cache\n let instance = cache.get(key);\n if (instance) return instance;\n\n // 4. Create New Instance\n instance = new Ctor(locales as never, options as never);\n\n // 5. Smart Eviction (LRU-ish)\n // Map iterates in insertion order. Deleting the first key removes the \"oldest\".\n if (cache.size >= MAX_CACHE_SIZE) {\n const oldestKey = cache.keys().next().value;\n if (oldestKey) cache.delete(oldestKey);\n }\n\n cache.set(key, instance as InstanceType<T>);\n return instance as InstanceType<T>;\n }\n\n // Preserve prototype for `instanceof` checks\n (Wrapped as any).prototype = (Ctor as any).prototype;\n\n return Wrapped as unknown as ReplaceLocaleWithLocalesValues<T>;\n};\n\n/**\n * Factory that turns the global `Intl` into a cached clone.\n */\nexport const createCachedIntl = (): WrappedIntl => {\n // 🔥 CRITICAL OPTIMIZATION:\n // We must cache the *wrapped constructors* themselves.\n // Otherwise, the Proxy creates a new `Wrapped` function (and a new empty Map)\n // on every single property access.\n const constructorCache = new Map<string | symbol, any>();\n\n return new Proxy(Intl as IntlConstructors, {\n get: (target, prop, receiver) => {\n // 1. Fast return if we already wrapped this constructor\n if (constructorCache.has(prop)) {\n return constructorCache.get(prop);\n }\n\n const value = Reflect.get(target, prop, receiver);\n\n // 2. Wrap only Constructors (Heuristic: Function + starts with Uppercase)\n // This prevents wrapping static methods like `Intl.getCanonicalLocales`\n if (\n typeof value === 'function' &&\n typeof prop === 'string' &&\n /^[A-Z]/.test(prop)\n ) {\n const wrapped = createCachedConstructor(value);\n constructorCache.set(prop, wrapped);\n return wrapped;\n }\n\n // 3. Pass through everything else (static methods, constants)\n return value;\n },\n }) as unknown as WrappedIntl;\n};\n\nexport const CachedIntl = createCachedIntl();\n\n// new CachedIntl.DisplayNames(Locales.FRENCH, { type: 'language' });\n// new CachedIntl.DisplayNames('fr', { type: 'language' });\n// new CachedIntl.DateTimeFormat('fr', {\n// year: 'numeric',\n// month: 'long',\n// day: 'numeric',\n// });\n// new CachedIntl.NumberFormat('fr', {\n// style: 'currency',\n// currency: 'EUR',\n// });\n// new CachedIntl.Collator('fr', { sensitivity: 'base' });\n// new CachedIntl.PluralRules('fr');\n// new CachedIntl.RelativeTimeFormat('fr', { numeric: 'auto' });\n// new CachedIntl.ListFormat('fr', { type: 'conjunction' });\nexport { CachedIntl as Intl };\n"],"mappings":";;;;;;;;;AAoEA,MAAM,eACJ,SACA,YACW;CACX,MAAM,YAAY,UAAU,OAAO,QAAQ,GAAGA,wBAAQ;AAEtD,KAAI,CAAC,QAAS,QAAO;AAIrB,QAAO,GAAG,UAAU,GAAG,KAAK,UAAU,QAAQ;;;;;AAMhD,MAAM,2BACJ,SACG;CAEH,MAAM,wBAAQ,IAAI,KAA8B;CAChD,MAAM,iBAAiB;CAEvB,SAAS,QAAQ,SAAyB,SAAe;AAEvD,MACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,WAGvC,QAAO;EAIT,MAAM,MAAM,YAAY,SAAS,QAAQ;EAGzC,IAAI,WAAW,MAAM,IAAI,IAAI;AAC7B,MAAI,SAAU,QAAO;AAGrB,aAAW,IAAI,KAAK,SAAkB,QAAiB;AAIvD,MAAI,MAAM,QAAQ,gBAAgB;GAChC,MAAM,YAAY,MAAM,MAAM,CAAC,MAAM,CAAC;AACtC,OAAI,UAAW,OAAM,OAAO,UAAU;;AAGxC,QAAM,IAAI,KAAK,SAA4B;AAC3C,SAAO;;AAIT,CAAC,QAAgB,YAAa,KAAa;AAE3C,QAAO;;;;;AAMT,MAAa,yBAAsC;CAKjD,MAAM,mCAAmB,IAAI,KAA2B;AAExD,QAAO,IAAI,MAAM,MAA0B,EACzC,MAAM,QAAQ,MAAM,aAAa;AAE/B,MAAI,iBAAiB,IAAI,KAAK,CAC5B,QAAO,iBAAiB,IAAI,KAAK;EAGnC,MAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAIjD,MACE,OAAO,UAAU,cACjB,OAAO,SAAS,YAChB,SAAS,KAAK,KAAK,EACnB;GACA,MAAM,UAAU,wBAAwB,MAAM;AAC9C,oBAAiB,IAAI,MAAM,QAAQ;AACnC,UAAO;;AAIT,SAAO;IAEV,CAAC;;AAGJ,MAAa,aAAa,kBAAkB"}
|
|
1
|
+
{"version":3,"file":"intl.cjs","names":["Locales"],"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { Locales, type LocalesValues } from '@intlayer/types';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (\n ...args: any\n ) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? {\n new (locales?: LocalesValues, options?: Options): Instance;\n new (options?: Options & { locale?: LocalesValues }): Instance;\n }\n : T extends new (\n locales: any\n ) => infer Instance\n ? {\n new (locales?: LocalesValues): Instance;\n new (options?: { locale?: LocalesValues }): Instance;\n }\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// ... (Keep your Type Helper definitions here: IntlConstructors, ReplaceLocaleWithLocalesValues, WrappedIntl) ...\n\n/**\n * Optimized Cache Key Generator\n * 1. Fast path: If no options, just use the locale string.\n * 2. Normal path: JSON.stringify for deterministic object comparison.\n */\nconst getCacheKey = (\n locales: LocalesValues | undefined,\n options: unknown\n): string => {\n const localeKey = locales ? String(locales) : Locales.ENGLISH;\n\n if (!options) return localeKey;\n\n // JSON.stringify is the most robust way to handle nested options objects\n // without a heavy custom hashing function.\n return `${localeKey}|${JSON.stringify(options)}`;\n};\n\n/**\n * Generic wrapper for any `new Intl.*()` constructor.\n */\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n // The cache lives here, inside the closure of the wrapped constructor.\n const cache = new Map<string, InstanceType<T>>();\n const MAX_CACHE_SIZE = 50;\n\n function Wrapped(locales?: LocalesValues | any, options?: any) {\n let resolvedLocales = locales;\n let resolvedOptions = options;\n\n // Handle case where first argument is an options object instead of locales\n if (\n typeof locales === 'object' &&\n !Array.isArray(locales) &&\n locales !== null\n ) {\n resolvedOptions = locales;\n resolvedLocales = locales.locale;\n }\n\n // Handle DisplayNames Polyfill warning\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n // ... (Existing polyfill logic would go here if needed, but let's keep it simple for now as it was empty in the read output)\n // Actually the read output had \"// ... (Your existing polyfill warning logic) ...\"\n // I should check what was there before or just preserve it.\n }\n\n // Generate Key\n const key = getCacheKey(resolvedLocales, resolvedOptions);\n\n // Check Cache\n let instance = cache.get(key);\n if (instance) return instance;\n\n // Create New Instance\n instance = new Ctor(resolvedLocales as never, resolvedOptions as never);\n\n // Smart Eviction (LRU-ish)\n // Map iterates in insertion order. Deleting the first key removes the \"oldest\".\n if (cache.size >= MAX_CACHE_SIZE) {\n const oldestKey = cache.keys().next().value;\n if (oldestKey) cache.delete(oldestKey);\n }\n\n cache.set(key, instance as InstanceType<T>);\n return instance as InstanceType<T>;\n }\n\n // Preserve prototype for `instanceof` checks\n (Wrapped as any).prototype = (Ctor as any).prototype;\n\n return Wrapped as unknown as ReplaceLocaleWithLocalesValues<T>;\n};\n\n/**\n * Factory that turns the global `Intl` into a cached clone.\n */\nexport const createCachedIntl = (): WrappedIntl => {\n // We must cache the *wrapped constructors* themselves.\n // Otherwise, the Proxy creates a new `Wrapped` function (and a new empty Map)\n // on every single property access.\n const constructorCache = new Map<string | symbol, any>();\n\n return new Proxy(Intl as IntlConstructors, {\n get: (target, prop, receiver) => {\n // Fast return if we already wrapped this constructor\n if (constructorCache.has(prop)) {\n return constructorCache.get(prop);\n }\n\n const value = Reflect.get(target, prop, receiver);\n\n // Wrap only Constructors (Heuristic: Function + starts with Uppercase)\n // This prevents wrapping static methods like `Intl.getCanonicalLocales`\n if (\n typeof value === 'function' &&\n typeof prop === 'string' &&\n /^[A-Z]/.test(prop)\n ) {\n const wrapped = createCachedConstructor(value);\n constructorCache.set(prop, wrapped);\n return wrapped;\n }\n\n // Pass through everything else (static methods, constants)\n return value;\n },\n }) as unknown as WrappedIntl;\n};\n\nexport const CachedIntl = createCachedIntl();\n\n/**\n * Creates a proxied Intl object with a preset locale.\n *\n * @example\n * const intl = bindIntl(Locales.FRENCH);\n * new intl.NumberFormat(undefined, { style: 'currency', currency: 'EUR' }).format(10);\n * // Uses 'fr' automatically\n */\nexport const bindIntl = (locale: LocalesValues): WrappedIntl => {\n return new Proxy(CachedIntl, {\n get: (target, prop) => {\n const value = Reflect.get(target, prop);\n\n // We only want to intercept Constructors (e.g., NumberFormat, DateTimeFormat)\n // to inject the locale into their arguments.\n if (\n typeof value === 'function' &&\n typeof prop === 'string' &&\n /^[A-Z]/.test(prop)\n ) {\n return new Proxy(value, {\n construct: (Ctor, args) => {\n let [locales, options] = args;\n\n // If the user provided a locale (args[0]), respect it.\n // If args[0] is undefined, inject the bound locale.\n // If args[0] is an object (not array), it's the options object.\n if (\n typeof locales === 'object' &&\n !Array.isArray(locales) &&\n locales !== null\n ) {\n options = locales;\n locales = options.locale ?? locale;\n } else if (locales === undefined) {\n locales = locale;\n }\n\n // We pass it to `CachedIntl` which handles caching logic.\n return new Ctor(locales, options);\n },\n // Ensure static methods (like supportedLocalesOf) still work\n get: (Ctor, key) => Reflect.get(Ctor, key),\n });\n }\n\n // Return constants or static methods as-is\n return value;\n },\n }) as unknown as WrappedIntl;\n};\n\n// new CachedIntl.DisplayNames(Locales.FRENCH, { type: 'language' });\n// new CachedIntl.DisplayNames('fr', { type: 'language' });\n// new CachedIntl.DateTimeFormat('fr', {\n// year: 'numeric',\n// month: 'long',\n// day: 'numeric',\n// });\n// new CachedIntl.NumberFormat('fr', {\n// style: 'currency',\n// currency: 'EUR',\n// });\n// new CachedIntl.Collator('fr', { sensitivity: 'base' });\n// new CachedIntl.PluralRules('fr');\n// new CachedIntl.RelativeTimeFormat('fr', { numeric: 'auto' });\n// new CachedIntl.ListFormat('fr', { type: 'conjunction' });\nexport { CachedIntl as Intl };\n"],"mappings":";;;;;;;;;AAqEA,MAAM,eACJ,SACA,YACW;CACX,MAAM,YAAY,UAAU,OAAO,QAAQ,GAAGA,wBAAQ;AAEtD,KAAI,CAAC,QAAS,QAAO;AAIrB,QAAO,GAAG,UAAU,GAAG,KAAK,UAAU,QAAQ;;;;;AAMhD,MAAM,2BACJ,SACG;CAEH,MAAM,wBAAQ,IAAI,KAA8B;CAChD,MAAM,iBAAiB;CAEvB,SAAS,QAAQ,SAA+B,SAAe;EAC7D,IAAI,kBAAkB;EACtB,IAAI,kBAAkB;AAGtB,MACE,OAAO,YAAY,YACnB,CAAC,MAAM,QAAQ,QAAQ,IACvB,YAAY,MACZ;AACA,qBAAkB;AAClB,qBAAkB,QAAQ;;AAI5B,MACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,YACvC;EAOF,MAAM,MAAM,YAAY,iBAAiB,gBAAgB;EAGzD,IAAI,WAAW,MAAM,IAAI,IAAI;AAC7B,MAAI,SAAU,QAAO;AAGrB,aAAW,IAAI,KAAK,iBAA0B,gBAAyB;AAIvE,MAAI,MAAM,QAAQ,gBAAgB;GAChC,MAAM,YAAY,MAAM,MAAM,CAAC,MAAM,CAAC;AACtC,OAAI,UAAW,OAAM,OAAO,UAAU;;AAGxC,QAAM,IAAI,KAAK,SAA4B;AAC3C,SAAO;;AAIT,CAAC,QAAgB,YAAa,KAAa;AAE3C,QAAO;;;;;AAMT,MAAa,yBAAsC;CAIjD,MAAM,mCAAmB,IAAI,KAA2B;AAExD,QAAO,IAAI,MAAM,MAA0B,EACzC,MAAM,QAAQ,MAAM,aAAa;AAE/B,MAAI,iBAAiB,IAAI,KAAK,CAC5B,QAAO,iBAAiB,IAAI,KAAK;EAGnC,MAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAIjD,MACE,OAAO,UAAU,cACjB,OAAO,SAAS,YAChB,SAAS,KAAK,KAAK,EACnB;GACA,MAAM,UAAU,wBAAwB,MAAM;AAC9C,oBAAiB,IAAI,MAAM,QAAQ;AACnC,UAAO;;AAIT,SAAO;IAEV,CAAC;;AAGJ,MAAa,aAAa,kBAAkB;;;;;;;;;AAU5C,MAAa,YAAY,WAAuC;AAC9D,QAAO,IAAI,MAAM,YAAY,EAC3B,MAAM,QAAQ,SAAS;EACrB,MAAM,QAAQ,QAAQ,IAAI,QAAQ,KAAK;AAIvC,MACE,OAAO,UAAU,cACjB,OAAO,SAAS,YAChB,SAAS,KAAK,KAAK,CAEnB,QAAO,IAAI,MAAM,OAAO;GACtB,YAAY,MAAM,SAAS;IACzB,IAAI,CAAC,SAAS,WAAW;AAKzB,QACE,OAAO,YAAY,YACnB,CAAC,MAAM,QAAQ,QAAQ,IACvB,YAAY,MACZ;AACA,eAAU;AACV,eAAU,QAAQ,UAAU;eACnB,YAAY,OACrB,WAAU;AAIZ,WAAO,IAAI,KAAK,SAAS,QAAQ;;GAGnC,MAAM,MAAM,QAAQ,QAAQ,IAAI,MAAM,IAAI;GAC3C,CAAC;AAIJ,SAAO;IAEV,CAAC"}
|
|
@@ -27,7 +27,7 @@ const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
|
|
|
27
27
|
currentValue = currentValue[keyObj.type][keyObj.key];
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.Insertion) {
|
|
30
|
+
if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.HTML || keyObj.type === NodeType.Insertion) {
|
|
31
31
|
lastKeys = [keyObj.type];
|
|
32
32
|
if (!currentValue[keyObj.type] || typeof currentValue[keyObj.type] !== "object") currentValue[keyObj.type] = "";
|
|
33
33
|
currentValue = currentValue[keyObj.type];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editDictionaryByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n if (keyPath.length === 0) {\n return newValue;\n }\n\n try {\n for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n // Note: Logic above already handles Enumeration, ensure no duplication in your actual file\n // or keep the specific block if your logic differs.\n // The important part is below in the final update block.\n\n // Assuming this block runs for Condition/Gender/etc:\n if (keyObj.type !== NodeType.Enumeration) {\n lastKeys = [keyObj.type, keyObj.key];\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion\n ) {\n lastKeys = [keyObj.type];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type === NodeType.File) {\n lastKeys = ['content'];\n currentValue = currentValue.content;\n }\n\n // Only update the value when processing the last key in the keyPath.\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n\n // Drill down to the container holding the value to be changed\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n\n const finalKey = lastKeys[lastKeys.length - 1];\n\n if (typeof newValue === 'undefined') {\n // Use splice for arrays to re-index the list, use delete for objects\n if (Array.isArray(target)) {\n const index = Number(finalKey);\n if (!isNaN(index) && index >= 0 && index < target.length) {\n target.splice(index, 1);\n }\n } else {\n delete target[finalKey];\n }\n } else {\n target[finalKey] = newValue;\n }\n }\n }\n\n return dictionaryContent;\n } catch (error) {\n console.error(\n 'Cannot edit dictionary by key path',\n { dictionaryContent, keyPath, newValue },\n error\n );\n return dictionaryContent;\n }\n};\n"],"mappings":";;;AAIA,MAAa,2BACX,mBACA,SACA,aACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,WAA0B,EAAE;AAEhC,KAAI,QAAQ,WAAW,EACrB,QAAO;AAGT,KAAI;AACF,OAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;GACvC,MAAM,SAAS,QAAQ;AACvB,iBAAc;AAEd,OAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,eAAW,CAAC,OAAO,IAAI;AACvB,QACE,CAAC,aAAa,OAAO,QACrB,OAAO,aAAa,OAAO,SAAS,SAEpC,cAAa,OAAO,OAAO,EAAE;AAE/B,mBAAe,aAAa,OAAO;;AAGrC,OACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,aACzB;AACA,eAAW,CAAC,OAAO,MAAM,OAAO,IAAI;AACpC,QACE,CAAC,aAAa,OAAO,SACrB,OAAO,aAAa,OAAO,UAAU,SAErC,cAAa,OAAO,QAAQ,EAAE;AAEhC,QACE,CAAC,aAAa,OAAO,MAAM,OAAO,QAClC,OAAO,aAAa,OAAO,MAAM,OAAO,SAAS,SAEjD,cAAa,OAAO,MAAM,OAAO,OAAO,EAAE;AAE5C,mBAAe,aAAa,OAAO,MAAM,OAAO;;AAGlD,OACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,WAOzB;QAAI,OAAO,SAAS,SAAS,aAAa;AACxC,gBAAW,CAAC,OAAO,MAAM,OAAO,IAAI;AACpC,oBAAe,aAAa,OAAO,MAAM,OAAO;;;AAIpD,OACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,WACzB;AACA,eAAW,CAAC,OAAO,KAAK;AACxB,QACE,CAAC,aAAa,OAAO,SACrB,OAAO,aAAa,OAAO,UAAU,SAErC,cAAa,OAAO,QAAQ;AAE9B,mBAAe,aAAa,OAAO;;AAGrC,OAAI,OAAO,SAAS,SAAS,MAAM;AACjC,eAAW,CAAC,UAAU;AACtB,mBAAe,aAAa;;AAI9B,OAAI,MAAM,QAAQ,SAAS,KAAK,eAAe,SAAS,SAAS,GAAG;IAClE,IAAI,SAAS;AAGb,SAAK,MAAM,OAAO,SAAS,MAAM,GAAG,GAAG,CACrC,UAAS,OAAO;IAGlB,MAAM,WAAW,SAAS,SAAS,SAAS;AAE5C,QAAI,OAAO,aAAa,YAEtB,KAAI,MAAM,QAAQ,OAAO,EAAE;KACzB,MAAM,QAAQ,OAAO,SAAS;AAC9B,SAAI,CAAC,MAAM,MAAM,IAAI,SAAS,KAAK,QAAQ,OAAO,OAChD,QAAO,OAAO,OAAO,EAAE;UAGzB,QAAO,OAAO;QAGhB,QAAO,YAAY;;;AAKzB,SAAO;UACA,OAAO;AACd,UAAQ,MACN,sCACA;GAAE;GAAmB;GAAS;GAAU,EACxC,MACD;AACD,SAAO"}
|
|
1
|
+
{"version":3,"file":"editDictionaryByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n if (keyPath.length === 0) {\n return newValue;\n }\n\n try {\n for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n // Note: Logic above already handles Enumeration, ensure no duplication in your actual file\n // or keep the specific block if your logic differs.\n // The important part is below in the final update block.\n\n // Assuming this block runs for Condition/Gender/etc:\n if (keyObj.type !== NodeType.Enumeration) {\n lastKeys = [keyObj.type, keyObj.key];\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.HTML ||\n keyObj.type === NodeType.Insertion\n ) {\n lastKeys = [keyObj.type];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type === NodeType.File) {\n lastKeys = ['content'];\n currentValue = currentValue.content;\n }\n\n // Only update the value when processing the last key in the keyPath.\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n\n // Drill down to the container holding the value to be changed\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n\n const finalKey = lastKeys[lastKeys.length - 1];\n\n if (typeof newValue === 'undefined') {\n // Use splice for arrays to re-index the list, use delete for objects\n if (Array.isArray(target)) {\n const index = Number(finalKey);\n if (!isNaN(index) && index >= 0 && index < target.length) {\n target.splice(index, 1);\n }\n } else {\n delete target[finalKey];\n }\n } else {\n target[finalKey] = newValue;\n }\n }\n }\n\n return dictionaryContent;\n } catch (error) {\n console.error(\n 'Cannot edit dictionary by key path',\n { dictionaryContent, keyPath, newValue },\n error\n );\n return dictionaryContent;\n }\n};\n"],"mappings":";;;AAIA,MAAa,2BACX,mBACA,SACA,aACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,WAA0B,EAAE;AAEhC,KAAI,QAAQ,WAAW,EACrB,QAAO;AAGT,KAAI;AACF,OAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;GACvC,MAAM,SAAS,QAAQ;AACvB,iBAAc;AAEd,OAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,eAAW,CAAC,OAAO,IAAI;AACvB,QACE,CAAC,aAAa,OAAO,QACrB,OAAO,aAAa,OAAO,SAAS,SAEpC,cAAa,OAAO,OAAO,EAAE;AAE/B,mBAAe,aAAa,OAAO;;AAGrC,OACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,aACzB;AACA,eAAW,CAAC,OAAO,MAAM,OAAO,IAAI;AACpC,QACE,CAAC,aAAa,OAAO,SACrB,OAAO,aAAa,OAAO,UAAU,SAErC,cAAa,OAAO,QAAQ,EAAE;AAEhC,QACE,CAAC,aAAa,OAAO,MAAM,OAAO,QAClC,OAAO,aAAa,OAAO,MAAM,OAAO,SAAS,SAEjD,cAAa,OAAO,MAAM,OAAO,OAAO,EAAE;AAE5C,mBAAe,aAAa,OAAO,MAAM,OAAO;;AAGlD,OACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,WAOzB;QAAI,OAAO,SAAS,SAAS,aAAa;AACxC,gBAAW,CAAC,OAAO,MAAM,OAAO,IAAI;AACpC,oBAAe,aAAa,OAAO,MAAM,OAAO;;;AAIpD,OACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,QACzB,OAAO,SAAS,SAAS,WACzB;AACA,eAAW,CAAC,OAAO,KAAK;AACxB,QACE,CAAC,aAAa,OAAO,SACrB,OAAO,aAAa,OAAO,UAAU,SAErC,cAAa,OAAO,QAAQ;AAE9B,mBAAe,aAAa,OAAO;;AAGrC,OAAI,OAAO,SAAS,SAAS,MAAM;AACjC,eAAW,CAAC,UAAU;AACtB,mBAAe,aAAa;;AAI9B,OAAI,MAAM,QAAQ,SAAS,KAAK,eAAe,SAAS,SAAS,GAAG;IAClE,IAAI,SAAS;AAGb,SAAK,MAAM,OAAO,SAAS,MAAM,GAAG,GAAG,CACrC,UAAS,OAAO;IAGlB,MAAM,WAAW,SAAS,SAAS,SAAS;AAE5C,QAAI,OAAO,aAAa,YAEtB,KAAI,MAAM,QAAQ,OAAO,EAAE;KACzB,MAAM,QAAQ,OAAO,SAAS;AAC9B,SAAI,CAAC,MAAM,MAAM,IAAI,SAAS,KAAK,QAAQ,OAAO,OAChD,QAAO,OAAO,OAAO,EAAE;UAGzB,QAAO,OAAO;QAGhB,QAAO,YAAY;;;AAKzB,SAAO;UACA,OAAO;AACd,UAAQ,MACN,sCACA;GAAE;GAAmB;GAAS;GAAU,EACxC,MACD;AACD,SAAO"}
|
|
@@ -7,7 +7,7 @@ const getContentNodeByKeyPath = (dictionaryContent, keyPath, fallbackLocale) =>
|
|
|
7
7
|
if (fallbackLocale && currentValue?.nodeType === NodeType.Translation) currentValue = currentValue?.[NodeType.Translation]?.[fallbackLocale];
|
|
8
8
|
if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) currentValue = currentValue?.[keyObj.key];
|
|
9
9
|
if (keyObj.type === NodeType.Translation || keyObj.type === NodeType.Condition || keyObj.type === NodeType.Enumeration) currentValue = currentValue?.[keyObj.type]?.[keyObj.key];
|
|
10
|
-
if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) currentValue = currentValue?.[keyObj.type];
|
|
10
|
+
if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.HTML || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) currentValue = currentValue?.[keyObj.type];
|
|
11
11
|
}
|
|
12
12
|
return currentValue;
|
|
13
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import {\n type ContentNode,\n type KeyPath,\n type Locale,\n NodeType,\n} from '@intlayer/types';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n fallbackLocale?: Locale\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n // Auto-resolve translation nodes when fallbackLocale is provided\n if (fallbackLocale && currentValue?.nodeType === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation]?.[fallbackLocale];\n }\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Condition ||\n keyObj.type === NodeType.Enumeration\n ) {\n currentValue = currentValue?.[keyObj.type]?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n currentValue = currentValue?.[keyObj.type];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":";;;AAOA,MAAa,2BACX,mBACA,SACA,mBACgB;CAChB,IAAI,eAAoB,gBAAgB,kBAAkB;AAE1D,MAAK,MAAM,UAAU,SAAS;AAE5B,MAAI,kBAAkB,cAAc,aAAa,SAAS,YACxD,gBAAe,eAAe,SAAS,eAAe;AAGxD,MAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,MAC9D,gBAAe,eAAe,OAAO;AAGvC,MACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,YAEzB,gBAAe,eAAe,OAAO,QAAQ,OAAO;AAGtD,MACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,KAEzB,gBAAe,eAAe,OAAO;;AAIzC,QAAO"}
|
|
1
|
+
{"version":3,"file":"getContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import {\n type ContentNode,\n type KeyPath,\n type Locale,\n NodeType,\n} from '@intlayer/types';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n fallbackLocale?: Locale\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n // Auto-resolve translation nodes when fallbackLocale is provided\n if (fallbackLocale && currentValue?.nodeType === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation]?.[fallbackLocale];\n }\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Condition ||\n keyObj.type === NodeType.Enumeration\n ) {\n currentValue = currentValue?.[keyObj.type]?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.HTML ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n currentValue = currentValue?.[keyObj.type];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":";;;AAOA,MAAa,2BACX,mBACA,SACA,mBACgB;CAChB,IAAI,eAAoB,gBAAgB,kBAAkB;AAE1D,MAAK,MAAM,UAAU,SAAS;AAE5B,MAAI,kBAAkB,cAAc,aAAa,SAAS,YACxD,gBAAe,eAAe,SAAS,eAAe;AAGxD,MAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,MAC9D,gBAAe,eAAe,OAAO;AAGvC,MACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,YAEzB,gBAAe,eAAe,OAAO,QAAQ,OAAO;AAGtD,MACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,QACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,KAEzB,gBAAe,eAAe,OAAO;;AAIzC,QAAO"}
|
|
@@ -31,6 +31,11 @@ const getDefaultNode = (nodeType, locales, content) => {
|
|
|
31
31
|
nodeType: NodeType.Markdown,
|
|
32
32
|
[NodeType.Markdown]: clonedContent ?? ""
|
|
33
33
|
};
|
|
34
|
+
case NodeType.HTML: return {
|
|
35
|
+
nodeType: NodeType.HTML,
|
|
36
|
+
[NodeType.HTML]: clonedContent ?? "",
|
|
37
|
+
customComponents: []
|
|
38
|
+
};
|
|
34
39
|
case NodeType.File: return {
|
|
35
40
|
nodeType: NodeType.File,
|
|
36
41
|
[NodeType.File]: clonedContent ?? ""
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDefaultNode.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import {\n type ContentNode,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n): ContentNode => {\n const clonedContent = structuredClone(content);\n switch (nodeType) {\n case NodeType.Translation:\n return {\n nodeType: NodeType.Translation,\n [NodeType.Translation]: Object.assign(\n {},\n ...locales.map((locale) => ({\n [locale]: structuredClone(clonedContent) ?? '',\n }))\n ),\n } as ContentNode;\n\n case NodeType.Enumeration:\n return {\n nodeType: NodeType.Enumeration,\n [NodeType.Enumeration]: {\n '1': clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeType.Condition:\n return {\n nodeType: NodeType.Condition,\n [NodeType.Condition]: {\n true: clonedContent ?? '',\n false: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeType.Insertion:\n return {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: {\n insertion: clonedContent ?? '',\n },\n } as unknown as ContentNode;\n\n case NodeType.Nested:\n return {\n nodeType: NodeType.Nested,\n [NodeType.Nested]: {\n dictionaryKey: '',\n },\n } as ContentNode;\n\n case NodeType.Markdown:\n return {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeType.File:\n return {\n nodeType: NodeType.File,\n [NodeType.File]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeType.Object:\n return {\n newKey: clonedContent ?? '',\n } as unknown as ContentNode;\n\n case NodeType.Array:\n return [clonedContent ?? ''] as unknown as ContentNode;\n\n case NodeType.Text:\n return clonedContent ?? '';\n\n case NodeType.Number:\n return clonedContent ?? 0;\n\n case NodeType.Boolean:\n return clonedContent ?? true;\n\n default:\n return clonedContent ?? '';\n }\n};\n"],"mappings":";;;AAMA,MAAa,kBACX,UACA,SACA,YACgB;CAChB,MAAM,gBAAgB,gBAAgB,QAAQ;AAC9C,SAAQ,UAAR;EACE,KAAK,SAAS,YACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,cAAc,OAAO,OAC7B,EAAE,EACF,GAAG,QAAQ,KAAK,YAAY,GACzB,SAAS,gBAAgB,cAAc,IAAI,IAC7C,EAAE,CACJ;GACF;EAEH,KAAK,SAAS,YACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,cAAc,EACtB,KAAK,iBAAiB,IACvB;GACF;EAEH,KAAK,SAAS,UACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,YAAY;IACpB,MAAM,iBAAiB;IACvB,OAAO,iBAAiB;IACzB;GACF;EAEH,KAAK,SAAS,UACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,YAAY,EACpB,WAAW,iBAAiB,IAC7B;GACF;EAEH,KAAK,SAAS,OACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,SAAS,EACjB,eAAe,IAChB;GACF;EAEH,KAAK,SAAS,SACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,WAAW,iBAAiB;GACvC;EAEH,KAAK,SAAS,KACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,OAAO,iBAAiB;GACnC;EAEH,KAAK,SAAS,OACZ,QAAO,EACL,QAAQ,iBAAiB,IAC1B;EAEH,KAAK,SAAS,MACZ,QAAO,CAAC,iBAAiB,GAAG;EAE9B,KAAK,SAAS,KACZ,QAAO,iBAAiB;EAE1B,KAAK,SAAS,OACZ,QAAO,iBAAiB;EAE1B,KAAK,SAAS,QACZ,QAAO,iBAAiB;EAE1B,QACE,QAAO,iBAAiB"}
|
|
1
|
+
{"version":3,"file":"getDefaultNode.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import {\n type ContentNode,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n): ContentNode => {\n const clonedContent = structuredClone(content);\n switch (nodeType) {\n case NodeType.Translation:\n return {\n nodeType: NodeType.Translation,\n [NodeType.Translation]: Object.assign(\n {},\n ...locales.map((locale) => ({\n [locale]: structuredClone(clonedContent) ?? '',\n }))\n ),\n } as ContentNode;\n\n case NodeType.Enumeration:\n return {\n nodeType: NodeType.Enumeration,\n [NodeType.Enumeration]: {\n '1': clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeType.Condition:\n return {\n nodeType: NodeType.Condition,\n [NodeType.Condition]: {\n true: clonedContent ?? '',\n false: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeType.Insertion:\n return {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: {\n insertion: clonedContent ?? '',\n },\n } as unknown as ContentNode;\n\n case NodeType.Nested:\n return {\n nodeType: NodeType.Nested,\n [NodeType.Nested]: {\n dictionaryKey: '',\n },\n } as ContentNode;\n\n case NodeType.Markdown:\n return {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeType.HTML:\n return {\n nodeType: NodeType.HTML,\n [NodeType.HTML]: clonedContent ?? '',\n customComponents: [],\n } as ContentNode;\n\n case NodeType.File:\n return {\n nodeType: NodeType.File,\n [NodeType.File]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeType.Object:\n return {\n newKey: clonedContent ?? '',\n } as unknown as ContentNode;\n\n case NodeType.Array:\n return [clonedContent ?? ''] as unknown as ContentNode;\n\n case NodeType.Text:\n return clonedContent ?? '';\n\n case NodeType.Number:\n return clonedContent ?? 0;\n\n case NodeType.Boolean:\n return clonedContent ?? true;\n\n default:\n return clonedContent ?? '';\n }\n};\n"],"mappings":";;;AAMA,MAAa,kBACX,UACA,SACA,YACgB;CAChB,MAAM,gBAAgB,gBAAgB,QAAQ;AAC9C,SAAQ,UAAR;EACE,KAAK,SAAS,YACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,cAAc,OAAO,OAC7B,EAAE,EACF,GAAG,QAAQ,KAAK,YAAY,GACzB,SAAS,gBAAgB,cAAc,IAAI,IAC7C,EAAE,CACJ;GACF;EAEH,KAAK,SAAS,YACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,cAAc,EACtB,KAAK,iBAAiB,IACvB;GACF;EAEH,KAAK,SAAS,UACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,YAAY;IACpB,MAAM,iBAAiB;IACvB,OAAO,iBAAiB;IACzB;GACF;EAEH,KAAK,SAAS,UACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,YAAY,EACpB,WAAW,iBAAiB,IAC7B;GACF;EAEH,KAAK,SAAS,OACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,SAAS,EACjB,eAAe,IAChB;GACF;EAEH,KAAK,SAAS,SACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,WAAW,iBAAiB;GACvC;EAEH,KAAK,SAAS,KACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,OAAO,iBAAiB;GAClC,kBAAkB,EAAE;GACrB;EAEH,KAAK,SAAS,KACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,OAAO,iBAAiB;GACnC;EAEH,KAAK,SAAS,OACZ,QAAO,EACL,QAAQ,iBAAiB,IAC1B;EAEH,KAAK,SAAS,MACZ,QAAO,CAAC,iBAAiB,GAAG;EAE9B,KAAK,SAAS,KACZ,QAAO,iBAAiB;EAE1B,KAAK,SAAS,OACZ,QAAO,iBAAiB;EAE1B,KAAK,SAAS,QACZ,QAAO,iBAAiB;EAE1B,QACE,QAAO,iBAAiB"}
|
|
@@ -8,7 +8,7 @@ const getEmptyNode = (section) => {
|
|
|
8
8
|
if (typeof section?.nodeType === "string") {
|
|
9
9
|
const typedNode = section;
|
|
10
10
|
const content = typedNode[typedNode.nodeType];
|
|
11
|
-
if (typedNode.nodeType === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition || typedNode.nodeType === NodeType.Insertion) return getEmptyNode(content);
|
|
11
|
+
if (typedNode.nodeType === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition || typedNode.nodeType === NodeType.Insertion || typedNode.nodeType === NodeType.HTML) return getEmptyNode(content);
|
|
12
12
|
if (typedNode.nodeType === NodeType.Nested) return "dictionary-key";
|
|
13
13
|
if (typedNode.nodeType === NodeType.File) return "file/path";
|
|
14
14
|
if (typedNode.nodeType === NodeType.Markdown) return getEmptyNode(typedNode);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEmptyNode.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getEmptyNode.ts"],"sourcesContent":["import { type ContentNode, NodeType, type TypedNode } from '@intlayer/types';\n\nexport const getEmptyNode = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return '';\n }\n if (typeof section === 'number') {\n return 0;\n }\n if (typeof section === 'boolean') {\n return true;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion\n ) {\n return getEmptyNode(content as ContentNode);\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return 'dictionary-key';\n }\n\n if (typedNode.nodeType === NodeType.File) {\n return 'file/path';\n }\n\n if (typedNode.nodeType === NodeType.Markdown) {\n return getEmptyNode(typedNode);\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[]).map(\n getEmptyNode\n ) as unknown as ContentNode;\n }\n\n const mappedSectionObject = Object.entries(section).map(([key, value]) => [\n key,\n getEmptyNode(value as ContentNode),\n ]);\n\n const mappedSectionArray = Object.fromEntries(mappedSectionObject);\n\n return mappedSectionArray;\n};\n"],"mappings":";;;AAEA,MAAa,gBAAgB,YAAsC;AACjE,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,UACrB,QAAO;AAET,KAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;AAEtB,MACE,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,
|
|
1
|
+
{"version":3,"file":"getEmptyNode.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getEmptyNode.ts"],"sourcesContent":["import { type ContentNode, NodeType, type TypedNode } from '@intlayer/types';\n\nexport const getEmptyNode = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return '';\n }\n if (typeof section === 'number') {\n return 0;\n }\n if (typeof section === 'boolean') {\n return true;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion ||\n typedNode.nodeType === NodeType.HTML\n ) {\n return getEmptyNode(content as ContentNode);\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return 'dictionary-key';\n }\n\n if (typedNode.nodeType === NodeType.File) {\n return 'file/path';\n }\n\n if (typedNode.nodeType === NodeType.Markdown) {\n return getEmptyNode(typedNode);\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[]).map(\n getEmptyNode\n ) as unknown as ContentNode;\n }\n\n const mappedSectionObject = Object.entries(section).map(([key, value]) => [\n key,\n getEmptyNode(value as ContentNode),\n ]);\n\n const mappedSectionArray = Object.fromEntries(mappedSectionObject);\n\n return mappedSectionArray;\n};\n"],"mappings":";;;AAEA,MAAa,gBAAgB,YAAsC;AACjE,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,UACrB,QAAO;AAET,KAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;AAEtB,MACE,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,KAEhC,QAAO,aAAa,QAAuB;AAG7C,MAAI,UAAU,aAAa,SAAS,OAClC,QAAO;AAGT,MAAI,UAAU,aAAa,SAAS,KAClC,QAAO;AAGT,MAAI,UAAU,aAAa,SAAS,SAClC,QAAO,aAAa,UAAU;AAGhC,SAAO;;AAGT,KAAI,CAAC,WAAW,OAAO,YAAY,SACjC,QAAO;AAGT,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAQ,QAA0B,IAChC,aACD;CAGH,MAAM,sBAAsB,OAAO,QAAQ,QAAQ,CAAC,KAAK,CAAC,KAAK,WAAW,CACxE,KACA,aAAa,MAAqB,CACnC,CAAC;AAIF,QAF2B,OAAO,YAAY,oBAAoB"}
|
|
@@ -8,7 +8,7 @@ const getNodeChildren = (section) => {
|
|
|
8
8
|
if (typeof section?.nodeType === "string") {
|
|
9
9
|
const typedNode = section;
|
|
10
10
|
const content = typedNode[typedNode.nodeType];
|
|
11
|
-
if (typedNode.nodeType === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition || typedNode.nodeType === NodeType.Insertion || typedNode.nodeType === NodeType.Gender || typedNode.nodeType === NodeType.File || typedNode.nodeType === NodeType.Markdown) return content[Object.keys(content)[0]];
|
|
11
|
+
if (typedNode.nodeType === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition || typedNode.nodeType === NodeType.Insertion || typedNode.nodeType === NodeType.Gender || typedNode.nodeType === NodeType.File || typedNode.nodeType === NodeType.Markdown || typedNode.nodeType === NodeType.HTML) return content[Object.keys(content)[0]];
|
|
12
12
|
if (typedNode.nodeType === NodeType.Nested) return;
|
|
13
13
|
return content;
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNodeChildren.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import { type ContentNode, NodeType, type TypedNode } from '@intlayer/types';\n\nexport const getNodeChildren = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return section;\n }\n if (typeof section === 'number') {\n return section;\n }\n if (typeof section === 'boolean') {\n return section;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion ||\n typedNode.nodeType === NodeType.Gender ||\n typedNode.nodeType === NodeType.File ||\n typedNode.nodeType === NodeType.Markdown\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return undefined;\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[])[0];\n }\n\n return section;\n};\n"],"mappings":";;;AAEA,MAAa,mBAAmB,YAAsC;AACpE,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,UACrB,QAAO;AAET,KAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;AAEtB,MACE,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,UAChC,UAAU,aAAa,SAAS,QAChC,UAAU,aAAa,SAAS,
|
|
1
|
+
{"version":3,"file":"getNodeChildren.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import { type ContentNode, NodeType, type TypedNode } from '@intlayer/types';\n\nexport const getNodeChildren = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return section;\n }\n if (typeof section === 'number') {\n return section;\n }\n if (typeof section === 'boolean') {\n return section;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion ||\n typedNode.nodeType === NodeType.Gender ||\n typedNode.nodeType === NodeType.File ||\n typedNode.nodeType === NodeType.Markdown ||\n typedNode.nodeType === NodeType.HTML\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return undefined;\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[])[0];\n }\n\n return section;\n};\n"],"mappings":";;;AAEA,MAAa,mBAAmB,YAAsC;AACpE,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,OAAO,YAAY,UACrB,QAAO;AAET,KAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;AAEtB,MACE,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,UAChC,UAAU,aAAa,SAAS,QAChC,UAAU,aAAa,SAAS,YAChC,UAAU,aAAa,SAAS,KAGhC,QAAO,QADU,OAAO,KAAK,QAAQ,CAAC;AAIxC,MAAI,UAAU,aAAa,SAAS,OAClC;AAGF,SAAO;;AAGT,KAAI,CAAC,WAAW,OAAO,YAAY,SACjC,QAAO;AAGT,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAQ,QAA0B;AAGpC,QAAO"}
|
|
@@ -15,7 +15,7 @@ const removeContentNodeByKeyPath = (dictionaryContent, keyPath) => {
|
|
|
15
15
|
lastKey = keyObj.type;
|
|
16
16
|
currentValue = currentValue[keyObj.type][keyObj.key];
|
|
17
17
|
}
|
|
18
|
-
if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.ReactNode || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) {
|
|
18
|
+
if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.ReactNode || keyObj.type === NodeType.HTML || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) {
|
|
19
19
|
lastKey = keyObj.type;
|
|
20
20
|
currentValue = currentValue[keyObj.type];
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/removeContentNodeByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\nexport const removeContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.ReactNode ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;AAEA,MAAa,8BACX,mBACA,YACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,UAAkC;AAEtC,MAAK,MAAM,UAAU,SAAS;AAC5B,gBAAc;AAEd,MAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO;;AAGrC,MACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,WACzB;AACA,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO,MAAM,OAAO;;AAGlD,MACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,MACzB;AACA,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO;;;AAIvC,KAAI,eAAe,YAAY,KAC7B,KAAI,MAAM,QAAQ,YAAY,CAC5B,aAAY,OAAO,SAA8B,EAAE;KAEnD,QAAO,YAAY;AAIvB,QAAO"}
|
|
1
|
+
{"version":3,"file":"removeContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/removeContentNodeByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\nexport const removeContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.ReactNode ||\n keyObj.type === NodeType.HTML ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;AAEA,MAAa,8BACX,mBACA,YACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,UAAkC;AAEtC,MAAK,MAAM,UAAU,SAAS;AAC5B,gBAAc;AAEd,MAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO;;AAGrC,MACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,WACzB;AACA,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO,MAAM,OAAO;;AAGlD,MACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,QACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,MACzB;AACA,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO;;;AAIvC,KAAI,eAAe,YAAY,KAC7B,KAAI,MAAM,QAAQ,YAAY,CAC5B,aAAY,OAAO,SAA8B,EAAE;KAEnD,QAAO,YAAY;AAIvB,QAAO"}
|
|
@@ -15,7 +15,7 @@ const renameContentNodeByKeyPath = (dictionaryContent, newKey, keyPath) => {
|
|
|
15
15
|
lastKey = keyObj.type;
|
|
16
16
|
currentValue = currentValue[keyObj.type][keyObj.key];
|
|
17
17
|
}
|
|
18
|
-
if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.ReactNode || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) {
|
|
18
|
+
if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.ReactNode || keyObj.type === NodeType.HTML || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) {
|
|
19
19
|
lastKey = keyObj.type;
|
|
20
20
|
currentValue = currentValue[keyObj.type];
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renameContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/renameContentNodeByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\nexport const renameContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n newKey: KeyPath['key'],\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.ReactNode ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n // Assign the new value to the last key of the parent while preserving the order\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue[lastKey as number] = currentValue;\n } else {\n const newParentValue: any = {};\n for (const key of Object.keys(parentValue)) {\n if (key === lastKey && typeof newKey !== 'undefined') {\n newParentValue[newKey] = currentValue;\n } else {\n newParentValue[key] = parentValue[key];\n }\n }\n // Replace the contents of parentValue with newParentValue\n Object.keys(parentValue).forEach((key) => {\n delete parentValue[key];\n });\n Object.assign(parentValue, newParentValue);\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;AAEA,MAAa,8BACX,mBACA,QACA,YACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,UAAkC;AAEtC,MAAK,MAAM,UAAU,SAAS;AAC5B,gBAAc;AAEd,MAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO;;AAGrC,MACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,WACzB;AACA,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO,MAAM,OAAO;;AAGlD,MACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,MACzB;AACA,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO;;;AAKvC,KAAI,eAAe,YAAY,KAC7B,KAAI,MAAM,QAAQ,YAAY,CAC5B,aAAY,WAAqB;MAC5B;EACL,MAAM,iBAAsB,EAAE;AAC9B,OAAK,MAAM,OAAO,OAAO,KAAK,YAAY,CACxC,KAAI,QAAQ,WAAW,OAAO,WAAW,YACvC,gBAAe,UAAU;MAEzB,gBAAe,OAAO,YAAY;AAItC,SAAO,KAAK,YAAY,CAAC,SAAS,QAAQ;AACxC,UAAO,YAAY;IACnB;AACF,SAAO,OAAO,aAAa,eAAe;;AAI9C,QAAO"}
|
|
1
|
+
{"version":3,"file":"renameContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/renameContentNodeByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\nexport const renameContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n newKey: KeyPath['key'],\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.ReactNode ||\n keyObj.type === NodeType.HTML ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n // Assign the new value to the last key of the parent while preserving the order\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue[lastKey as number] = currentValue;\n } else {\n const newParentValue: any = {};\n for (const key of Object.keys(parentValue)) {\n if (key === lastKey && typeof newKey !== 'undefined') {\n newParentValue[newKey] = currentValue;\n } else {\n newParentValue[key] = parentValue[key];\n }\n }\n // Replace the contents of parentValue with newParentValue\n Object.keys(parentValue).forEach((key) => {\n delete parentValue[key];\n });\n Object.assign(parentValue, newParentValue);\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;AAEA,MAAa,8BACX,mBACA,QACA,YACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,UAAkC;AAEtC,MAAK,MAAM,UAAU,SAAS;AAC5B,gBAAc;AAEd,MAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO;;AAGrC,MACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,WACzB;AACA,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO,MAAM,OAAO;;AAGlD,MACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,QACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,MACzB;AACA,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO;;;AAKvC,KAAI,eAAe,YAAY,KAC7B,KAAI,MAAM,QAAQ,YAAY,CAC5B,aAAY,WAAqB;MAC5B;EACL,MAAM,iBAAsB,EAAE;AAC9B,OAAK,MAAM,OAAO,OAAO,KAAK,YAAY,CACxC,KAAI,QAAQ,WAAW,OAAO,WAAW,YACvC,gBAAe,UAAU;MAEzB,gBAAe,OAAO,YAAY;AAItC,SAAO,KAAK,YAAY,CAAC,SAAS,QAAQ;AACxC,UAAO,YAAY;IACnB;AACF,SAAO,OAAO,aAAa,eAAe;;AAI9C,QAAO"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -8,10 +8,12 @@ import { getNesting } from "./interpreter/getNesting.mjs";
|
|
|
8
8
|
import { getTranslation } from "./interpreter/getTranslation.mjs";
|
|
9
9
|
import { conditionPlugin, enumerationPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, translationPlugin } from "./interpreter/getContent/plugins.mjs";
|
|
10
10
|
import { getContent } from "./interpreter/getContent/getContent.mjs";
|
|
11
|
+
import { getHTML } from "./interpreter/getHTML.mjs";
|
|
11
12
|
import { getFilteredLocalesContent, getFilteredLocalesDictionary } from "./deepTransformPlugins/getFilteredLocalesContent.mjs";
|
|
12
13
|
import { cond as condition } from "./transpiler/condition/condition.mjs";
|
|
13
14
|
import { enu as enumeration } from "./transpiler/enumeration/enumeration.mjs";
|
|
14
15
|
import { gender } from "./transpiler/gender/gender.mjs";
|
|
16
|
+
import { HTML_TAGS, html } from "./transpiler/html/index.mjs";
|
|
15
17
|
import { getInsertionValues } from "./transpiler/insertion/getInsertionValues.mjs";
|
|
16
18
|
import { insert as insertion } from "./transpiler/insertion/insertion.mjs";
|
|
17
19
|
import { parseYaml } from "./utils/parseYaml.mjs";
|
|
@@ -41,7 +43,7 @@ import { normalizeDictionaries, normalizeDictionary } from "./dictionaryManipula
|
|
|
41
43
|
import { removeContentNodeByKeyPath } from "./dictionaryManipulator/removeContentNodeByKeyPath.mjs";
|
|
42
44
|
import { renameContentNodeByKeyPath } from "./dictionaryManipulator/renameContentNodeByKeyPath.mjs";
|
|
43
45
|
import { updateNodeChildren } from "./dictionaryManipulator/updateNodeChildren.mjs";
|
|
44
|
-
import { CachedIntl, createCachedIntl } from "./utils/intl.mjs";
|
|
46
|
+
import { CachedIntl, bindIntl, createCachedIntl } from "./utils/intl.mjs";
|
|
45
47
|
import { compact } from "./formatters/compact.mjs";
|
|
46
48
|
import { currency } from "./formatters/currency.mjs";
|
|
47
49
|
import { date } from "./formatters/date.mjs";
|
|
@@ -50,11 +52,11 @@ import { number } from "./formatters/number.mjs";
|
|
|
50
52
|
import { percentage } from "./formatters/percentage.mjs";
|
|
51
53
|
import { relativeTime } from "./formatters/relativeTime.mjs";
|
|
52
54
|
import { units } from "./formatters/units.mjs";
|
|
55
|
+
import { getCookie } from "./utils/getCookie.mjs";
|
|
56
|
+
import { LocaleStorage, getLocaleFromStorage, setLocaleInStorage } from "./utils/localeStorage.mjs";
|
|
53
57
|
import { localeResolver } from "./localization/localeResolver.mjs";
|
|
54
58
|
import { localeDetector } from "./localization/localeDetector.mjs";
|
|
55
59
|
import { getLocale } from "./localization/getLocale.mjs";
|
|
56
|
-
import { getCookie } from "./utils/getCookie.mjs";
|
|
57
|
-
import { LocaleStorage, getLocaleFromStorage, setLocaleInStorage } from "./utils/localeStorage.mjs";
|
|
58
60
|
import { getBrowserLocale, localeStorageOptions } from "./localization/getBrowserLocale.mjs";
|
|
59
61
|
import { getHTMLTextDir } from "./localization/getHTMLTextDir.mjs";
|
|
60
62
|
import { checkIsURLAbsolute } from "./utils/checkIsURLAbsolute.mjs";
|
|
@@ -67,6 +69,11 @@ import { getLocalizedUrl } from "./localization/getLocalizedUrl.mjs";
|
|
|
67
69
|
import { getMultilingualUrls } from "./localization/getMultilingualUrls.mjs";
|
|
68
70
|
import { localeFlatMap, localeMap, localeRecord } from "./localization/localeMapper.mjs";
|
|
69
71
|
import { validatePrefix } from "./localization/validatePrefix.mjs";
|
|
72
|
+
import { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, NAMED_CODES_TO_UNICODE, ORDERED, Priority, RuleType, UNORDERED } from "./markdown/constants.mjs";
|
|
73
|
+
import { allowInline, anyScopeRegex, attributeValueToNodePropValue, blockRegex, captureNothing, cx, get, inlineRegex, normalizeAttributeKey, normalizeWhitespace, parseBlock, parseCaptureInline, parseInline, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableCells, parseTableRow, qualifies, renderNothing, sanitizer, simpleInlineRegex, slugify, some, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, unquote } from "./markdown/utils.mjs";
|
|
74
|
+
import { parserFor } from "./markdown/parser.mjs";
|
|
75
|
+
import { createRenderer, renderFor } from "./markdown/renderer.mjs";
|
|
76
|
+
import { compile, compileWithOptions, createCompiler } from "./markdown/compiler.mjs";
|
|
70
77
|
import { isSameKeyPath } from "./utils/isSameKeyPath.mjs";
|
|
71
78
|
|
|
72
|
-
export { CachedIntl, CachedIntl as Intl, LocaleStorage, buildMaskPlugin, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, condition as cond, conditionPlugin, createCachedIntl, currency, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, gender, genderPlugin, getBrowserLocale, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getHTMLTextDir, getInsertionValues, getIntlayer, getLocale, getLocaleFromPath, getLocaleFromStorage, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPrefix, getReplacedValuesContent, getSplittedContent, getSplittedDictionaryContent, getStorageAttributes, getTranslation, insertion as insert, insertContentInDictionary, insertionPlugin, isSameKeyPath, isValidElement, list, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, markdown as md, mergeDictionaries, nesting as nest, nestedPlugin, normalizeDictionaries, normalizeDictionary, number, orderDictionaries, parseYaml, percentage, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, setLocaleInStorage, translation as t, translationPlugin, units, updateNodeChildren, validatePrefix };
|
|
79
|
+
export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, CachedIntl, CachedIntl as Intl, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, HTML_TAGS, LocaleStorage, NAMED_CODES_TO_UNICODE, ORDERED, Priority, RuleType, UNORDERED, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, compile, compileWithOptions, condition as cond, conditionPlugin, createCachedIntl, createCompiler, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, gender, genderPlugin, get, getBrowserLocale, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getHTML, getHTMLTextDir, getInsertionValues, getIntlayer, getLocale, getLocaleFromPath, getLocaleFromStorage, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPrefix, getReplacedValuesContent, getSplittedContent, getSplittedDictionaryContent, getStorageAttributes, getTranslation, html, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, isSameKeyPath, isValidElement, list, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, markdown as md, mergeDictionaries, nesting as nest, nestedPlugin, normalizeAttributeKey, normalizeDictionaries, normalizeDictionary, normalizeWhitespace, number, orderDictionaries, parseBlock, parseCaptureInline, parseInline, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableCells, parseTableRow, parseYaml, parserFor, percentage, qualifies, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderNothing, sanitizer, setLocaleInStorage, simpleInlineRegex, slugify, some, translation as t, translationPlugin, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, units, unquote, updateNodeChildren, validatePrefix };
|
|
@@ -9,6 +9,7 @@ import { NodeType } from "@intlayer/types";
|
|
|
9
9
|
const deepTransformNode = (node, props) => {
|
|
10
10
|
for (const plugin of props.plugins ?? []) if (plugin.canHandle(node)) return plugin.transform(node, props, (node$1, props$1) => deepTransformNode(node$1, props$1));
|
|
11
11
|
if (node === null || typeof node !== "object") return node;
|
|
12
|
+
if (node.$$typeof !== void 0 || node.__v_isVNode !== void 0 || node._isVNode !== void 0 || node.isJSX !== void 0 || typeof node === "function") return node;
|
|
12
13
|
if (Array.isArray(node)) return node.map((child, index) => {
|
|
13
14
|
return deepTransformNode(child, {
|
|
14
15
|
...props,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deepTransform.mjs","names":["node","props"],"sources":["../../../../src/interpreter/getContent/deepTransform.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '@intlayer/types';\nimport type { NodeProps } from './plugins';\n\n/**\n * Recursively traverses a node (object/array/primitive).\n * Applies the *first* plugin that can transform a node, then stops descending further.\n * If no plugin transforms it, it recurses into its children.\n */\nexport const deepTransformNode = (node: any, props: NodeProps): any => {\n // Otherwise, if it's an object, check if any plugin can handle it:\n for (const plugin of props.plugins ?? []) {\n if (plugin.canHandle(node)) {\n // Return the transformed node => do NOT recurse further\n return plugin.transform(node, props, (node: any, props: any) =>\n deepTransformNode(node, props)\n );\n }\n }\n\n // If it's null/undefined or not an object, just return it directly:\n if (node === null || typeof node !== 'object') {\n return node;\n }\n\n // If it's an array, transform each element:\n if (Array.isArray(node)) {\n return node.map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n });\n }\n\n // If no plugin transforms it, we keep traversing its properties.\n const result: Record<string, any> = {};\n for (const key in node) {\n const childProps = {\n ...props,\n children: node[key],\n keyPath: [...props.keyPath, { type: NodeType.Object, key } as KeyPath],\n };\n result[key] = deepTransformNode(node[key], childProps);\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;AAQA,MAAa,qBAAqB,MAAW,UAA0B;AAErE,MAAK,MAAM,UAAU,MAAM,WAAW,EAAE,CACtC,KAAI,OAAO,UAAU,KAAK,CAExB,QAAO,OAAO,UAAU,MAAM,QAAQ,QAAW,YAC/C,kBAAkBA,QAAMC,QAAM,CAC/B;AAKL,KAAI,SAAS,QAAQ,OAAO,SAAS,SACnC,QAAO;AAIT,KAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,KAAK,KAAK,OAAO,UAAU;AAShC,SAAO,kBAAkB,OARN;GACjB,GAAG;GACH,UAAU;GACV,SAAS,CACP,GAAG,MAAM,SACT;IAAE,MAAM,SAAS;IAAO,KAAK;IAAO,CACrC;GACF,CAC0C;GAC3C;CAIJ,MAAM,SAA8B,EAAE;AACtC,MAAK,MAAM,OAAO,MAAM;EACtB,MAAM,aAAa;GACjB,GAAG;GACH,UAAU,KAAK;GACf,SAAS,CAAC,GAAG,MAAM,SAAS;IAAE,MAAM,SAAS;IAAQ;IAAK,CAAY;GACvE;AACD,SAAO,OAAO,kBAAkB,KAAK,MAAM,WAAW;;AAGxD,QAAO"}
|
|
1
|
+
{"version":3,"file":"deepTransform.mjs","names":["node","props"],"sources":["../../../../src/interpreter/getContent/deepTransform.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '@intlayer/types';\nimport type { NodeProps } from './plugins';\n\n/**\n * Recursively traverses a node (object/array/primitive).\n * Applies the *first* plugin that can transform a node, then stops descending further.\n * If no plugin transforms it, it recurses into its children.\n */\nexport const deepTransformNode = (node: any, props: NodeProps): any => {\n // Otherwise, if it's an object, check if any plugin can handle it:\n for (const plugin of props.plugins ?? []) {\n if (plugin.canHandle(node)) {\n // Return the transformed node => do NOT recurse further\n return plugin.transform(node, props, (node: any, props: any) =>\n deepTransformNode(node, props)\n );\n }\n }\n\n // If it's null/undefined or not an object, just return it directly:\n if (node === null || typeof node !== 'object') {\n return node;\n }\n\n // If it's a framework-specific virtual node or already a transformed Proxy,\n // return it directly to avoid re-transforming its internal properties.\n if (\n (node as any).$$typeof !== undefined ||\n (node as any).__v_isVNode !== undefined ||\n (node as any)._isVNode !== undefined ||\n (node as any).isJSX !== undefined ||\n typeof node === 'function' // Proxies for html/markdown are functions\n ) {\n return node;\n }\n\n // If it's an array, transform each element:\n if (Array.isArray(node)) {\n return node.map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n });\n }\n\n // If no plugin transforms it, we keep traversing its properties.\n const result: Record<string, any> = {};\n for (const key in node) {\n const childProps = {\n ...props,\n children: node[key],\n keyPath: [...props.keyPath, { type: NodeType.Object, key } as KeyPath],\n };\n result[key] = deepTransformNode(node[key], childProps);\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;AAQA,MAAa,qBAAqB,MAAW,UAA0B;AAErE,MAAK,MAAM,UAAU,MAAM,WAAW,EAAE,CACtC,KAAI,OAAO,UAAU,KAAK,CAExB,QAAO,OAAO,UAAU,MAAM,QAAQ,QAAW,YAC/C,kBAAkBA,QAAMC,QAAM,CAC/B;AAKL,KAAI,SAAS,QAAQ,OAAO,SAAS,SACnC,QAAO;AAKT,KACG,KAAa,aAAa,UAC1B,KAAa,gBAAgB,UAC7B,KAAa,aAAa,UAC1B,KAAa,UAAU,UACxB,OAAO,SAAS,WAEhB,QAAO;AAIT,KAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,KAAK,KAAK,OAAO,UAAU;AAShC,SAAO,kBAAkB,OARN;GACjB,GAAG;GACH,UAAU;GACV,SAAS,CACP,GAAG,MAAM,SACT;IAAE,MAAM,SAAS;IAAO,KAAK;IAAO,CACrC;GACF,CAC0C;GAC3C;CAIJ,MAAM,SAA8B,EAAE;AACtC,MAAK,MAAM,OAAO,MAAM;EACtB,MAAM,aAAa;GACjB,GAAG;GACH,UAAU,KAAK;GACf,SAAS,CAAC,GAAG,MAAM,SAAS;IAAE,MAAM,SAAS;IAAQ;IAAK,CAAY;GACvE;AACD,SAAO,OAAO,kBAAkB,KAAK,MAAM,WAAW;;AAGxD,QAAO"}
|
|
@@ -9,11 +9,11 @@ import configuration from "@intlayer/config/built";
|
|
|
9
9
|
* @param node The node to transform.
|
|
10
10
|
* @param locale The locale to use if your transformers need it (e.g. for translations).
|
|
11
11
|
*/
|
|
12
|
-
const getContent = (node, nodeProps, locale) => {
|
|
12
|
+
const getContent = (node, nodeProps, locale, fallback) => {
|
|
13
13
|
const defaultLocale = configuration?.internationalization?.defaultLocale;
|
|
14
14
|
const plugins = [
|
|
15
15
|
insertionPlugin,
|
|
16
|
-
translationPlugin(locale ?? defaultLocale, defaultLocale),
|
|
16
|
+
translationPlugin(locale ?? defaultLocale, fallback ? defaultLocale : void 0),
|
|
17
17
|
enumerationPlugin,
|
|
18
18
|
conditionPlugin,
|
|
19
19
|
nestedPlugin(locale ?? defaultLocale),
|