@intlayer/core 9.0.1 → 9.1.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 +5 -5
- 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 +15 -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/getNodeType.cjs +30 -22
- package/dist/cjs/dictionaryManipulator/getNodeType.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/dictionaryManipulator/updateNodeChildren.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -1
- package/dist/cjs/index.cjs +7 -0
- package/dist/cjs/interpreter/getContent/getContent.cjs +2 -1
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/index.cjs +1 -0
- package/dist/cjs/interpreter/getContent/plugins.cjs +28 -0
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getSelect.cjs +36 -0
- package/dist/cjs/interpreter/getSelect.cjs.map +1 -0
- package/dist/cjs/interpreter/index.cjs +5 -0
- package/dist/cjs/messageFormat/ICU.cjs +23 -6
- package/dist/cjs/messageFormat/ICU.cjs.map +1 -1
- package/dist/cjs/messageFormat/i18next.cjs +24 -6
- package/dist/cjs/messageFormat/i18next.cjs.map +1 -1
- package/dist/cjs/messageFormat/resolveMessage.cjs +8 -0
- package/dist/cjs/messageFormat/resolveMessage.cjs.map +1 -1
- package/dist/cjs/messageFormat/vue-i18n.cjs +11 -2
- package/dist/cjs/messageFormat/vue-i18n.cjs.map +1 -1
- package/dist/cjs/transpiler/index.cjs +2 -0
- package/dist/cjs/transpiler/select/index.cjs +4 -0
- package/dist/cjs/transpiler/select/select.cjs +42 -0
- package/dist/cjs/transpiler/select/select.cjs.map +1 -0
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +5 -5
- 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 +15 -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/getNodeType.mjs +30 -22
- package/dist/esm/dictionaryManipulator/getNodeType.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/dictionaryManipulator/updateNodeChildren.mjs +1 -1
- package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs.map +1 -1
- package/dist/esm/index.mjs +5 -2
- package/dist/esm/interpreter/getContent/getContent.mjs +3 -2
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/index.mjs +2 -2
- package/dist/esm/interpreter/getContent/plugins.mjs +28 -1
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getSelect.mjs +34 -0
- package/dist/esm/interpreter/getSelect.mjs.map +1 -0
- package/dist/esm/interpreter/index.mjs +4 -2
- package/dist/esm/messageFormat/ICU.mjs +23 -6
- package/dist/esm/messageFormat/ICU.mjs.map +1 -1
- package/dist/esm/messageFormat/i18next.mjs +24 -6
- package/dist/esm/messageFormat/i18next.mjs.map +1 -1
- package/dist/esm/messageFormat/resolveMessage.mjs +8 -0
- package/dist/esm/messageFormat/resolveMessage.mjs.map +1 -1
- package/dist/esm/messageFormat/vue-i18n.mjs +11 -2
- package/dist/esm/messageFormat/vue-i18n.mjs.map +1 -1
- package/dist/esm/transpiler/index.mjs +2 -1
- package/dist/esm/transpiler/select/index.mjs +3 -0
- package/dist/esm/transpiler/select/select.mjs +41 -0
- package/dist/esm/transpiler/select/select.mjs.map +1 -0
- package/dist/types/dictionaryManipulator/getNodeType.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -2
- 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 +22 -1
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/interpreter/getSelect.d.ts +31 -0
- package/dist/types/interpreter/getSelect.d.ts.map +1 -0
- package/dist/types/interpreter/index.d.ts +4 -2
- package/dist/types/messageFormat/ICU.d.ts.map +1 -1
- package/dist/types/messageFormat/i18next.d.ts.map +1 -1
- package/dist/types/messageFormat/resolveMessage.d.ts.map +1 -1
- package/dist/types/messageFormat/vue-i18n.d.ts.map +1 -1
- package/dist/types/transpiler/index.d.ts +3 -1
- package/dist/types/transpiler/select/index.d.ts +2 -0
- package/dist/types/transpiler/select/select.d.ts +62 -0
- package/dist/types/transpiler/select/select.d.ts.map +1 -0
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEmptyNode.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getEmptyNode.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\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 === NodeTypes.TRANSLATION ||\n typedNode.nodeType === NodeTypes.ENUMERATION ||\n typedNode.nodeType === NodeTypes.PLURAL ||\n typedNode.nodeType === NodeTypes.CONDITION ||\n typedNode.nodeType === NodeTypes.INSERTION ||\n typedNode.nodeType === NodeTypes.HTML\n ) {\n return getEmptyNode(content as ContentNode);\n }\n\n if (typedNode.nodeType === NodeTypes.NESTED) {\n return 'dictionary-key';\n }\n\n if (typedNode.nodeType === NodeTypes.FILE) {\n return 'file/path';\n }\n\n if (typedNode.nodeType === NodeTypes.MARKDOWN) {\n return getEmptyNode(content as ContentNode);\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":";;;AAIA,MAAa,gBAAgB,YAAsC;CACjE,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,WACrB,OAAO;CAET,IAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;EAEtB,IACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,MAEjC,OAAO,aAAa,OAAsB;EAG5C,IAAI,UAAU,aAAa,UAAU,QACnC,OAAO;EAGT,IAAI,UAAU,aAAa,UAAU,MACnC,OAAO;EAGT,IAAI,UAAU,aAAa,UAAU,UACnC,OAAO,aAAa,OAAsB;EAG5C,OAAO;CACT;CAEA,IAAI,CAAC,WAAW,OAAO,YAAY,UACjC,OAAO;CAGT,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAQ,QAA0B,IAChC,YACF;CAGF,MAAM,sBAAsB,OAAO,QAAQ,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CACxE,KACA,aAAa,KAAoB,CACnC,CAAC;CAID,OAF2B,OAAO,YAAY,mBAEtB;AAC1B"}
|
|
1
|
+
{"version":3,"file":"getEmptyNode.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getEmptyNode.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\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 === NodeTypes.TRANSLATION ||\n typedNode.nodeType === NodeTypes.ENUMERATION ||\n typedNode.nodeType === NodeTypes.PLURAL ||\n typedNode.nodeType === NodeTypes.CONDITION ||\n typedNode.nodeType === NodeTypes.INSERTION ||\n typedNode.nodeType === NodeTypes.GENDER ||\n typedNode.nodeType === NodeTypes.SELECT ||\n typedNode.nodeType === NodeTypes.HTML\n ) {\n return getEmptyNode(content as ContentNode);\n }\n\n if (typedNode.nodeType === NodeTypes.NESTED) {\n return 'dictionary-key';\n }\n\n if (typedNode.nodeType === NodeTypes.FILE) {\n return 'file/path';\n }\n\n if (typedNode.nodeType === NodeTypes.MARKDOWN) {\n return getEmptyNode(content as ContentNode);\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":";;;AAIA,MAAa,gBAAgB,YAAsC;CACjE,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,WACrB,OAAO;CAET,IAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;EAEtB,IACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,MAEjC,OAAO,aAAa,OAAsB;EAG5C,IAAI,UAAU,aAAa,UAAU,QACnC,OAAO;EAGT,IAAI,UAAU,aAAa,UAAU,MACnC,OAAO;EAGT,IAAI,UAAU,aAAa,UAAU,UACnC,OAAO,aAAa,OAAsB;EAG5C,OAAO;CACT;CAEA,IAAI,CAAC,WAAW,OAAO,YAAY,UACjC,OAAO;CAGT,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAQ,QAA0B,IAChC,YACF;CAGF,MAAM,sBAAsB,OAAO,QAAQ,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CACxE,KACA,aAAa,KAAoB,CACnC,CAAC;CAID,OAF2B,OAAO,YAAY,mBAEtB;AAC1B"}
|
|
@@ -9,7 +9,7 @@ const getNodeChildren = (section) => {
|
|
|
9
9
|
const typedNode = section;
|
|
10
10
|
const content = typedNode[typedNode.nodeType];
|
|
11
11
|
if (typedNode.nodeType === NodeTypes.MARKDOWN || typedNode.nodeType === NodeTypes.HTML) return content;
|
|
12
|
-
if (typedNode.nodeType === NodeTypes.TRANSLATION || typedNode.nodeType === NodeTypes.ENUMERATION || typedNode.nodeType === NodeTypes.PLURAL || typedNode.nodeType === NodeTypes.CONDITION || typedNode.nodeType === NodeTypes.INSERTION || typedNode.nodeType === NodeTypes.GENDER || typedNode.nodeType === NodeTypes.FILE) return content[Object.keys(content)[0]];
|
|
12
|
+
if (typedNode.nodeType === NodeTypes.TRANSLATION || typedNode.nodeType === NodeTypes.ENUMERATION || typedNode.nodeType === NodeTypes.PLURAL || typedNode.nodeType === NodeTypes.CONDITION || typedNode.nodeType === NodeTypes.INSERTION || typedNode.nodeType === NodeTypes.GENDER || typedNode.nodeType === NodeTypes.SELECT || typedNode.nodeType === NodeTypes.FILE) return content[Object.keys(content)[0]];
|
|
13
13
|
if (typedNode.nodeType === NodeTypes.NESTED) return;
|
|
14
14
|
return content;
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNodeChildren.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\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 === NodeTypes.MARKDOWN ||\n typedNode.nodeType === NodeTypes.HTML\n ) {\n return content as ContentNode;\n }\n\n if (\n typedNode.nodeType === NodeTypes.TRANSLATION ||\n typedNode.nodeType === NodeTypes.ENUMERATION ||\n typedNode.nodeType === NodeTypes.PLURAL ||\n typedNode.nodeType === NodeTypes.CONDITION ||\n typedNode.nodeType === NodeTypes.INSERTION ||\n typedNode.nodeType === NodeTypes.GENDER ||\n typedNode.nodeType === NodeTypes.FILE\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeTypes.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":";;;AAIA,MAAa,mBAAmB,YAAsC;CACpE,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,WACrB,OAAO;CAET,IAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;EAEtB,IACE,UAAU,aAAa,UAAU,YACjC,UAAU,aAAa,UAAU,MAEjC,OAAO;EAGT,IACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,MAGjC,OAAO,QADU,OAAO,KAAK,OAAO,CAAC,CAAC;EAIxC,IAAI,UAAU,aAAa,UAAU,QACnC;EAGF,OAAO;CACT;CAEA,IAAI,CAAC,WAAW,OAAO,YAAY,UACjC,OAAO;CAGT,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAQ,QAA0B;CAGpC,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"getNodeChildren.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\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 === NodeTypes.MARKDOWN ||\n typedNode.nodeType === NodeTypes.HTML\n ) {\n return content as ContentNode;\n }\n\n if (\n typedNode.nodeType === NodeTypes.TRANSLATION ||\n typedNode.nodeType === NodeTypes.ENUMERATION ||\n typedNode.nodeType === NodeTypes.PLURAL ||\n typedNode.nodeType === NodeTypes.CONDITION ||\n typedNode.nodeType === NodeTypes.INSERTION ||\n typedNode.nodeType === NodeTypes.GENDER ||\n typedNode.nodeType === NodeTypes.SELECT ||\n typedNode.nodeType === NodeTypes.FILE\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeTypes.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":";;;AAIA,MAAa,mBAAmB,YAAsC;CACpE,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,WACrB,OAAO;CAET,IAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;EAEtB,IACE,UAAU,aAAa,UAAU,YACjC,UAAU,aAAa,UAAU,MAEjC,OAAO;EAGT,IACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,MAGjC,OAAO,QADU,OAAO,KAAK,OAAO,CAAC,CAAC;EAIxC,IAAI,UAAU,aAAa,UAAU,QACnC;EAGF,OAAO;CACT;CAEA,IAAI,CAAC,WAAW,OAAO,YAAY,UACjC,OAAO;CAGT,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAQ,QAA0B;CAGpC,OAAO;AACT"}
|
|
@@ -9,30 +9,38 @@ const isTypedNode = (content) => {
|
|
|
9
9
|
return typeof content === "object" && content !== null && "nodeType" in content && typeof content.nodeType === "string";
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Every known {@link NodeType}, as a lookup record.
|
|
13
|
+
*
|
|
14
|
+
* Typed as `Record<NodeType, true>` so that adding a node type to
|
|
15
|
+
* `@intlayer/types` without registering it here becomes a compile-time error.
|
|
13
16
|
*/
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
]
|
|
17
|
+
const validNodeTypes = {
|
|
18
|
+
[NodeTypes.TRANSLATION]: true,
|
|
19
|
+
[NodeTypes.ENUMERATION]: true,
|
|
20
|
+
[NodeTypes.PLURAL]: true,
|
|
21
|
+
[NodeTypes.CONDITION]: true,
|
|
22
|
+
[NodeTypes.INSERTION]: true,
|
|
23
|
+
[NodeTypes.FILE]: true,
|
|
24
|
+
[NodeTypes.OBJECT]: true,
|
|
25
|
+
[NodeTypes.ARRAY]: true,
|
|
26
|
+
[NodeTypes.NESTED]: true,
|
|
27
|
+
[NodeTypes.REACT_NODE]: true,
|
|
28
|
+
[NodeTypes.PREACT_NODE]: true,
|
|
29
|
+
[NodeTypes.SOLID_NODE]: true,
|
|
30
|
+
[NodeTypes.MARKDOWN]: true,
|
|
31
|
+
[NodeTypes.HTML]: true,
|
|
32
|
+
[NodeTypes.TEXT]: true,
|
|
33
|
+
[NodeTypes.NUMBER]: true,
|
|
34
|
+
[NodeTypes.BOOLEAN]: true,
|
|
35
|
+
[NodeTypes.GENDER]: true,
|
|
36
|
+
[NodeTypes.SELECT]: true,
|
|
37
|
+
[NodeTypes.NULL]: true,
|
|
38
|
+
[NodeTypes.UNKNOWN]: true
|
|
35
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Type guard to check if a raw string is a valid {@link NodeType}
|
|
42
|
+
*/
|
|
43
|
+
const isValidNodeType = (nodeType) => Object.hasOwn(validNodeTypes, nodeType);
|
|
36
44
|
const getNodeType = (content) => {
|
|
37
45
|
if (typeof content === "string") return NodeTypes.TEXT;
|
|
38
46
|
if (isTypedNode(content)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNodeType.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { isValidElement } from '../utils/isValidReactElement';\n\n/**\n * Type guard to check if content is a TypedNode\n */\nconst isTypedNode = (content: unknown): content is TypedNode => {\n return (\n typeof content === 'object' &&\n content !== null &&\n 'nodeType' in content &&\n typeof (content as TypedNode).nodeType === 'string'\n );\n};\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"getNodeType.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { isValidElement } from '../utils/isValidReactElement';\n\n/**\n * Type guard to check if content is a TypedNode\n */\nconst isTypedNode = (content: unknown): content is TypedNode => {\n return (\n typeof content === 'object' &&\n content !== null &&\n 'nodeType' in content &&\n typeof (content as TypedNode).nodeType === 'string'\n );\n};\n\n/**\n * Every known {@link NodeType}, as a lookup record.\n *\n * Typed as `Record<NodeType, true>` so that adding a node type to\n * `@intlayer/types` without registering it here becomes a compile-time error.\n */\nconst validNodeTypes: Record<NodeType, true> = {\n [NodeTypes.TRANSLATION]: true,\n [NodeTypes.ENUMERATION]: true,\n [NodeTypes.PLURAL]: true,\n [NodeTypes.CONDITION]: true,\n [NodeTypes.INSERTION]: true,\n [NodeTypes.FILE]: true,\n [NodeTypes.OBJECT]: true,\n [NodeTypes.ARRAY]: true,\n [NodeTypes.NESTED]: true,\n [NodeTypes.REACT_NODE]: true,\n [NodeTypes.PREACT_NODE]: true,\n [NodeTypes.SOLID_NODE]: true,\n [NodeTypes.MARKDOWN]: true,\n [NodeTypes.HTML]: true,\n [NodeTypes.TEXT]: true,\n [NodeTypes.NUMBER]: true,\n [NodeTypes.BOOLEAN]: true,\n [NodeTypes.GENDER]: true,\n [NodeTypes.SELECT]: true,\n [NodeTypes.NULL]: true,\n [NodeTypes.UNKNOWN]: true,\n};\n\n/**\n * Type guard to check if a raw string is a valid {@link NodeType}\n */\nconst isValidNodeType = (nodeType: string): nodeType is NodeType =>\n Object.hasOwn(validNodeTypes, nodeType);\n\nexport const getNodeType = (content: ContentNode): NodeType => {\n if (typeof content === 'string') {\n return NodeTypes.TEXT;\n }\n\n if (isTypedNode(content)) {\n const nodeType = content.nodeType;\n if (isValidNodeType(nodeType)) {\n return nodeType;\n }\n // Fallback for unknown node types\n return NodeTypes.UNKNOWN;\n }\n\n if (Array.isArray(content)) {\n return NodeTypes.ARRAY;\n }\n\n if (isValidElement(content)) {\n return NodeTypes.REACT_NODE;\n }\n\n if (typeof content === 'number') {\n return NodeTypes.NUMBER;\n }\n\n if (typeof content === 'boolean') {\n return NodeTypes.BOOLEAN;\n }\n\n if (content && typeof content === 'object') {\n return NodeTypes.OBJECT;\n }\n\n if (content === null) {\n return NodeTypes.NULL;\n }\n\n return NodeTypes.UNKNOWN;\n};\n"],"mappings":";;;;;;;AASA,MAAM,eAAe,YAA2C;CAC9D,OACE,OAAO,YAAY,YACnB,YAAY,QACZ,cAAc,WACd,OAAQ,QAAsB,aAAa;AAE/C;;;;;;;AAQA,MAAM,iBAAyC;EAC5C,UAAU,cAAc;EACxB,UAAU,cAAc;EACxB,UAAU,SAAS;EACnB,UAAU,YAAY;EACtB,UAAU,YAAY;EACtB,UAAU,OAAO;EACjB,UAAU,SAAS;EACnB,UAAU,QAAQ;EAClB,UAAU,SAAS;EACnB,UAAU,aAAa;EACvB,UAAU,cAAc;EACxB,UAAU,aAAa;EACvB,UAAU,WAAW;EACrB,UAAU,OAAO;EACjB,UAAU,OAAO;EACjB,UAAU,SAAS;EACnB,UAAU,UAAU;EACpB,UAAU,SAAS;EACnB,UAAU,SAAS;EACnB,UAAU,OAAO;EACjB,UAAU,UAAU;AACvB;;;;AAKA,MAAM,mBAAmB,aACvB,OAAO,OAAO,gBAAgB,QAAQ;AAExC,MAAa,eAAe,YAAmC;CAC7D,IAAI,OAAO,YAAY,UACrB,OAAO,UAAU;CAGnB,IAAI,YAAY,OAAO,GAAG;EACxB,MAAM,WAAW,QAAQ;EACzB,IAAI,gBAAgB,QAAQ,GAC1B,OAAO;EAGT,OAAO,UAAU;CACnB;CAEA,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAO,UAAU;CAGnB,IAAI,eAAe,OAAO,GACxB,OAAO,UAAU;CAGnB,IAAI,OAAO,YAAY,UACrB,OAAO,UAAU;CAGnB,IAAI,OAAO,YAAY,WACrB,OAAO,UAAU;CAGnB,IAAI,WAAW,OAAO,YAAY,UAChC,OAAO,UAAU;CAGnB,IAAI,YAAY,MACd,OAAO,UAAU;CAGnB,OAAO,UAAU;AACnB"}
|
|
@@ -11,7 +11,7 @@ const removeContentNodeByKeyPath = (dictionaryContent, keyPath) => {
|
|
|
11
11
|
lastKey = keyObj.key;
|
|
12
12
|
currentValue = currentValue[keyObj.key];
|
|
13
13
|
}
|
|
14
|
-
if (keyObj.type === NodeTypes.TRANSLATION || keyObj.type === NodeTypes.ENUMERATION || keyObj.type === NodeTypes.PLURAL || keyObj.type === NodeTypes.CONDITION) {
|
|
14
|
+
if (keyObj.type === NodeTypes.TRANSLATION || keyObj.type === NodeTypes.ENUMERATION || keyObj.type === NodeTypes.PLURAL || keyObj.type === NodeTypes.CONDITION || keyObj.type === NodeTypes.GENDER || keyObj.type === NodeTypes.SELECT) {
|
|
15
15
|
lastKey = keyObj.type;
|
|
16
16
|
currentValue = currentValue[keyObj.type][keyObj.key];
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/removeContentNodeByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\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 === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL ||\n keyObj.type === NodeTypes.CONDITION\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.REACT_NODE ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION ||\n keyObj.type === NodeTypes.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":";;;AAKA,MAAa,8BACX,mBACA,YACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,UAAkC;CAEtC,KAAK,MAAM,UAAU,SAAS;EAC5B,cAAc;EAEd,IAAI,OAAO,SAAS,UAAU,UAAU,OAAO,SAAS,UAAU,OAAO;GACvE,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO;EACrC;EAEA,IACE,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,UAC1B,OAAO,SAAS,UAAU,
|
|
1
|
+
{"version":3,"file":"removeContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/removeContentNodeByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\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 === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL ||\n keyObj.type === NodeTypes.CONDITION ||\n keyObj.type === NodeTypes.GENDER ||\n keyObj.type === NodeTypes.SELECT\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.REACT_NODE ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION ||\n keyObj.type === NodeTypes.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":";;;AAKA,MAAa,8BACX,mBACA,YACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,UAAkC;CAEtC,KAAK,MAAM,UAAU,SAAS;EAC5B,cAAc;EAEd,IAAI,OAAO,SAAS,UAAU,UAAU,OAAO,SAAS,UAAU,OAAO;GACvE,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO;EACrC;EAEA,IACE,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,UAC1B,OAAO,SAAS,UAAU,aAC1B,OAAO,SAAS,UAAU,UAC1B,OAAO,SAAS,UAAU,QAC1B;GACA,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO,KAAK,CAAC,OAAO;EAClD;EAEA,IACE,OAAO,SAAS,UAAU,YAC1B,OAAO,SAAS,UAAU,cAC1B,OAAO,SAAS,UAAU,QAC1B,OAAO,SAAS,UAAU,aAC1B,OAAO,SAAS,UAAU,MAC1B;GACA,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO;EACrC;CACF;CAEA,IAAI,eAAe,YAAY,MAC7B,IAAI,MAAM,QAAQ,WAAW,GAC3B,YAAY,OAAO,SAA8B,CAAC;MAElD,OAAO,YAAY;CAIvB,OAAO;AACT"}
|
|
@@ -11,7 +11,7 @@ const renameContentNodeByKeyPath = (dictionaryContent, newKey, keyPath) => {
|
|
|
11
11
|
lastKey = keyObj.key;
|
|
12
12
|
currentValue = currentValue[keyObj.key];
|
|
13
13
|
}
|
|
14
|
-
if (keyObj.type === NodeTypes.TRANSLATION || keyObj.type === NodeTypes.ENUMERATION || keyObj.type === NodeTypes.PLURAL || keyObj.type === NodeTypes.CONDITION) {
|
|
14
|
+
if (keyObj.type === NodeTypes.TRANSLATION || keyObj.type === NodeTypes.ENUMERATION || keyObj.type === NodeTypes.PLURAL || keyObj.type === NodeTypes.CONDITION || keyObj.type === NodeTypes.GENDER || keyObj.type === NodeTypes.SELECT) {
|
|
15
15
|
lastKey = keyObj.type;
|
|
16
16
|
currentValue = currentValue[keyObj.type][keyObj.key];
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renameContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/renameContentNodeByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\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 === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL ||\n keyObj.type === NodeTypes.CONDITION\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.REACT_NODE ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION ||\n keyObj.type === NodeTypes.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":";;;AAKA,MAAa,8BACX,mBACA,QACA,YACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,UAAkC;CAEtC,KAAK,MAAM,UAAU,SAAS;EAC5B,cAAc;EAEd,IAAI,OAAO,SAAS,UAAU,UAAU,OAAO,SAAS,UAAU,OAAO;GACvE,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO;EACrC;EAEA,IACE,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,UAC1B,OAAO,SAAS,UAAU,
|
|
1
|
+
{"version":3,"file":"renameContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/renameContentNodeByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\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 === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL ||\n keyObj.type === NodeTypes.CONDITION ||\n keyObj.type === NodeTypes.GENDER ||\n keyObj.type === NodeTypes.SELECT\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.REACT_NODE ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION ||\n keyObj.type === NodeTypes.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":";;;AAKA,MAAa,8BACX,mBACA,QACA,YACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,UAAkC;CAEtC,KAAK,MAAM,UAAU,SAAS;EAC5B,cAAc;EAEd,IAAI,OAAO,SAAS,UAAU,UAAU,OAAO,SAAS,UAAU,OAAO;GACvE,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO;EACrC;EAEA,IACE,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,UAC1B,OAAO,SAAS,UAAU,aAC1B,OAAO,SAAS,UAAU,UAC1B,OAAO,SAAS,UAAU,QAC1B;GACA,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO,KAAK,CAAC,OAAO;EAClD;EAEA,IACE,OAAO,SAAS,UAAU,YAC1B,OAAO,SAAS,UAAU,cAC1B,OAAO,SAAS,UAAU,QAC1B,OAAO,SAAS,UAAU,aAC1B,OAAO,SAAS,UAAU,MAC1B;GACA,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO;EACrC;CACF;CAGA,IAAI,eAAe,YAAY,MAC7B,IAAI,MAAM,QAAQ,WAAW,GAC3B,YAAY,WAAqB;MAC5B;EACL,MAAM,iBAAsB,CAAC;EAC7B,KAAK,MAAM,OAAO,OAAO,KAAK,WAAW,GACvC,IAAI,QAAQ,WAAW,OAAO,WAAW,aACvC,eAAe,UAAU;OAEzB,eAAe,OAAO,YAAY;EAItC,OAAO,KAAK,WAAW,CAAC,CAAC,SAAS,QAAQ;GACxC,OAAO,YAAY;EACrB,CAAC;EACD,OAAO,OAAO,aAAa,cAAc;CAC3C;CAGF,OAAO;AACT"}
|
|
@@ -8,7 +8,7 @@ const updateNodeChildren = (section, newChildren) => {
|
|
|
8
8
|
if (typeof section?.nodeType === "string") {
|
|
9
9
|
const typedNode = section;
|
|
10
10
|
const content = typedNode[typedNode.nodeType];
|
|
11
|
-
if (typedNode.nodeType === NodeTypes.TRANSLATION || typedNode.nodeType === NodeTypes.ENUMERATION || typedNode.nodeType === NodeTypes.PLURAL || typedNode.nodeType === NodeTypes.CONDITION) {
|
|
11
|
+
if (typedNode.nodeType === NodeTypes.TRANSLATION || typedNode.nodeType === NodeTypes.ENUMERATION || typedNode.nodeType === NodeTypes.PLURAL || typedNode.nodeType === NodeTypes.CONDITION || typedNode.nodeType === NodeTypes.GENDER || typedNode.nodeType === NodeTypes.SELECT) {
|
|
12
12
|
const newContent = Object.entries(content).reduce((acc, [key]) => {
|
|
13
13
|
acc[key] = newChildren;
|
|
14
14
|
return acc;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateNodeChildren.mjs","names":[],"sources":["../../../src/dictionaryManipulator/updateNodeChildren.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const updateNodeChildren = <\n T extends ContentNode,\n U extends ContentNode,\n>(\n section: T,\n newChildren: U\n): ContentNode => {\n if (typeof section === 'string') {\n return newChildren;\n }\n if (typeof section === 'number') {\n return newChildren;\n }\n if (typeof section === 'boolean') {\n return newChildren;\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 === NodeTypes.TRANSLATION ||\n typedNode.nodeType === NodeTypes.ENUMERATION ||\n typedNode.nodeType === NodeTypes.PLURAL ||\n typedNode.nodeType === NodeTypes.CONDITION\n ) {\n const newContent = Object.entries(content).reduce(\n (acc, [key]) => {\n acc[key] = newChildren;\n return acc;\n },\n {} as Record<string, ContentNode>\n );\n\n return {\n ...typedNode,\n [typedNode.nodeType]: newContent,\n };\n }\n\n if (typedNode.nodeType === NodeTypes.NESTED) {\n return typedNode;\n }\n\n return {\n ...typedNode,\n [typedNode.nodeType]: newChildren,\n };\n }\n\n if (!section || typeof section !== 'object') {\n return newChildren;\n }\n\n if (Array.isArray(section)) {\n return section.map(() => newChildren) as unknown as ContentNode;\n }\n\n return Object.entries(\n section as unknown as Record<string, ContentNode>\n ).reduce(\n (acc, [key]) => ({\n ...acc,\n [key]: newChildren,\n }),\n {} as Record<string, ContentNode>\n ) as unknown as ContentNode;\n};\n"],"mappings":";;;AAIA,MAAa,sBAIX,SACA,gBACgB;CAChB,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,WACrB,OAAO;CAET,IAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;EAEtB,IACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,
|
|
1
|
+
{"version":3,"file":"updateNodeChildren.mjs","names":[],"sources":["../../../src/dictionaryManipulator/updateNodeChildren.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const updateNodeChildren = <\n T extends ContentNode,\n U extends ContentNode,\n>(\n section: T,\n newChildren: U\n): ContentNode => {\n if (typeof section === 'string') {\n return newChildren;\n }\n if (typeof section === 'number') {\n return newChildren;\n }\n if (typeof section === 'boolean') {\n return newChildren;\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 === NodeTypes.TRANSLATION ||\n typedNode.nodeType === NodeTypes.ENUMERATION ||\n typedNode.nodeType === NodeTypes.PLURAL ||\n typedNode.nodeType === NodeTypes.CONDITION ||\n typedNode.nodeType === NodeTypes.GENDER ||\n typedNode.nodeType === NodeTypes.SELECT\n ) {\n const newContent = Object.entries(content).reduce(\n (acc, [key]) => {\n acc[key] = newChildren;\n return acc;\n },\n {} as Record<string, ContentNode>\n );\n\n return {\n ...typedNode,\n [typedNode.nodeType]: newContent,\n };\n }\n\n if (typedNode.nodeType === NodeTypes.NESTED) {\n return typedNode;\n }\n\n return {\n ...typedNode,\n [typedNode.nodeType]: newChildren,\n };\n }\n\n if (!section || typeof section !== 'object') {\n return newChildren;\n }\n\n if (Array.isArray(section)) {\n return section.map(() => newChildren) as unknown as ContentNode;\n }\n\n return Object.entries(\n section as unknown as Record<string, ContentNode>\n ).reduce(\n (acc, [key]) => ({\n ...acc,\n [key]: newChildren,\n }),\n {} as Record<string, ContentNode>\n ) as unknown as ContentNode;\n};\n"],"mappings":";;;AAIA,MAAa,sBAIX,SACA,gBACgB;CAChB,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,WACrB,OAAO;CAET,IAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;EAEtB,IACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,QACjC;GACA,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC,CAAC,QACxC,KAAK,CAAC,SAAS;IACd,IAAI,OAAO;IACX,OAAO;GACT,GACA,CAAC,CACH;GAEA,OAAO;IACL,GAAG;KACF,UAAU,WAAW;GACxB;EACF;EAEA,IAAI,UAAU,aAAa,UAAU,QACnC,OAAO;EAGT,OAAO;GACL,GAAG;IACF,UAAU,WAAW;EACxB;CACF;CAEA,IAAI,CAAC,WAAW,OAAO,YAAY,UACjC,OAAO;CAGT,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAO,QAAQ,UAAU,WAAW;CAGtC,OAAO,OAAO,QACZ,OACF,CAAC,CAAC,QACC,KAAK,CAAC,UAAU;EACf,GAAG;GACF,MAAM;CACT,IACA,CAAC,CACH;AACF"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { getEditedContent, getEditedDictionary } from "./deepTransformPlugins/ge
|
|
|
2
2
|
import { getCondition } from "./interpreter/getCondition.mjs";
|
|
3
3
|
import { deepTransformNode } from "./interpreter/getContent/deepTransform.mjs";
|
|
4
4
|
import { findMatchingCondition, getEnumeration } from "./interpreter/getEnumeration.mjs";
|
|
5
|
+
import { getGender } from "./interpreter/getGender.mjs";
|
|
5
6
|
import { getInsertion } from "./interpreter/getInsertion.mjs";
|
|
6
7
|
import { COMPOSITE_ID_SEPARATOR, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getVariantIds, isQualifiedDictionaryGroup, isQualifiedDynamicLoaderMap, parseDictionarySelector, reconstructQualifiedEntry, resolveQualifiedDictionary, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync, serializeVariant } from "./dictionaryManipulator/qualifiedDictionary.mjs";
|
|
7
8
|
import { getDictionary } from "./interpreter/getDictionary.mjs";
|
|
@@ -17,9 +18,10 @@ import { percentage } from "./formatters/percentage.mjs";
|
|
|
17
18
|
import { relativeTime } from "./formatters/relativeTime.mjs";
|
|
18
19
|
import { units } from "./formatters/units.mjs";
|
|
19
20
|
import { getPlural } from "./interpreter/getPlural.mjs";
|
|
21
|
+
import { getSelect } from "./interpreter/getSelect.mjs";
|
|
20
22
|
import { getTranslation } from "./interpreter/getTranslation.mjs";
|
|
21
23
|
import { getInterpolableContent, isInterpolableWrapperNode, rebuildInterpolableContent, transformInterpolableNode } from "./interpreter/interpolableNode.mjs";
|
|
22
|
-
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, translationPlugin } from "./interpreter/getContent/plugins.mjs";
|
|
24
|
+
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin } from "./interpreter/getContent/plugins.mjs";
|
|
23
25
|
import { getBasePlugins, getContent } from "./interpreter/getContent/getContent.mjs";
|
|
24
26
|
import { getHTML } from "./interpreter/getHTML.mjs";
|
|
25
27
|
import { splitInsertionTemplate } from "./interpreter/splitAndJoinInsertion.mjs";
|
|
@@ -38,6 +40,7 @@ import { validateMarkdown } from "./transpiler/markdown/validateMarkdown.mjs";
|
|
|
38
40
|
import { md as markdown } from "./transpiler/markdown/markdown.mjs";
|
|
39
41
|
import { nest as nesting } from "./transpiler/nesting/nesting.mjs";
|
|
40
42
|
import { plural } from "./transpiler/plural/plural.mjs";
|
|
43
|
+
import { select } from "./transpiler/select/select.mjs";
|
|
41
44
|
import { t as translation } from "./transpiler/translation/translation.mjs";
|
|
42
45
|
import { filterMissingTranslationsOnlyPlugin, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary } from "./deepTransformPlugins/getFilterMissingTranslationsContent.mjs";
|
|
43
46
|
import { filterTranslationsOnlyPlugin, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary } from "./deepTransformPlugins/getFilterTranslationsOnlyContent.mjs";
|
|
@@ -97,4 +100,4 @@ import { interpolateMessage, parseTaggedMessage, resolveMessage, resolveMessageN
|
|
|
97
100
|
import { isSameKeyPath } from "./utils/isSameKeyPath.mjs";
|
|
98
101
|
import { stringifyYaml } from "./utils/stringifyYaml.mjs";
|
|
99
102
|
|
|
100
|
-
export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, COMPOSITE_ID_SEPARATOR, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CUSTOM_COMPONENT_R, CachedIntl, CachedIntl as Intl, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, GFM_TASK_R, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, HTML_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, HTML_TAGS, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LIST_LOOKBEHIND_R, LOOKAHEAD, LocaleStorage, LocaleStorageClient, LocaleStorageServer, NAMED_CODES_TO_UNICODE, NP_TABLE_R, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, PARAGRAPH_R, Priority, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, RuleType, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_PLAIN_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, VOID_HTML_ELEMENTS, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, comparePaths, compile, compileWithOptions, condition as cond, conditionPlugin, createCompiler, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPlural, getPrefix, getReplacedValuesContent, getRewritePath, getRewriteRules, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, isInterpolableWrapperNode, isLocaleExclusiveOnDomain, isQualifiedDictionaryGroup, isQualifiedDynamicLoaderMap, isSameKeyPath, isValidElement, list, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, markdown as md, mergeDictionaries, mergeQualifiedDictionaries, navigatePath, nesting as nest, nestedPlugin, normalizeAttributeKey, normalizeDictionaries, normalizeDictionary, normalizePath, normalizeWhitespace, number, orderDictionaries, parseBlock, parseCaptureInline, parseDictionarySelector, parseInline, parseMarkdown, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableAlignCapture, parseTableCells, parseTableRow, parseTaggedMessage, parseYaml, parserFor, percentage, plural, pluralPlugin, portableObjectToIntlayerFormatter, presets, qualifies, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveMessage, resolveMessageNode, resolveQualifiedDictionary, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync, sanitizer, serializeVariant, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer, simpleInlineRegex, slugify, some, splitInsertionTemplate, startsWith, stringifyYaml, translation as t, transformInterpolableNode, translationPlugin, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, units, unquote, updateNodeChildren, validateHTML, validateMarkdown, validatePrefix, vueI18nToIntlayerFormatter };
|
|
103
|
+
export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, COMPOSITE_ID_SEPARATOR, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CUSTOM_COMPONENT_R, CachedIntl, CachedIntl as Intl, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, GFM_TASK_R, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, HTML_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, HTML_TAGS, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LIST_LOOKBEHIND_R, LOOKAHEAD, LocaleStorage, LocaleStorageClient, LocaleStorageServer, NAMED_CODES_TO_UNICODE, NP_TABLE_R, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, PARAGRAPH_R, Priority, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, RuleType, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_PLAIN_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, VOID_HTML_ELEMENTS, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, comparePaths, compile, compileWithOptions, condition as cond, conditionPlugin, createCompiler, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getGender, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPlural, getPrefix, getReplacedValuesContent, getRewritePath, getRewriteRules, getSelect, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, isInterpolableWrapperNode, isLocaleExclusiveOnDomain, isQualifiedDictionaryGroup, isQualifiedDynamicLoaderMap, isSameKeyPath, isValidElement, list, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, markdown as md, mergeDictionaries, mergeQualifiedDictionaries, navigatePath, nesting as nest, nestedPlugin, normalizeAttributeKey, normalizeDictionaries, normalizeDictionary, normalizePath, normalizeWhitespace, number, orderDictionaries, parseBlock, parseCaptureInline, parseDictionarySelector, parseInline, parseMarkdown, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableAlignCapture, parseTableCells, parseTableRow, parseTaggedMessage, parseYaml, parserFor, percentage, plural, pluralPlugin, portableObjectToIntlayerFormatter, presets, qualifies, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveMessage, resolveMessageNode, resolveQualifiedDictionary, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync, sanitizer, select, selectPlugin, serializeVariant, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer, simpleInlineRegex, slugify, some, splitInsertionTemplate, startsWith, stringifyYaml, translation as t, transformInterpolableNode, translationPlugin, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, units, unquote, updateNodeChildren, validateHTML, validateMarkdown, validatePrefix, vueI18nToIntlayerFormatter };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deepTransformNode } from "./deepTransform.mjs";
|
|
2
|
-
import { conditionPlugin, enumerationPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, translationPlugin } from "./plugins.mjs";
|
|
2
|
+
import { conditionPlugin, enumerationPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, selectPlugin, translationPlugin } from "./plugins.mjs";
|
|
3
3
|
import { internationalization } from "@intlayer/config/built";
|
|
4
4
|
|
|
5
5
|
//#region src/interpreter/getContent/getContent.ts
|
|
@@ -10,7 +10,8 @@ const getBasePlugins = (locale, fallback = true) => [
|
|
|
10
10
|
insertionPlugin,
|
|
11
11
|
nestedPlugin(locale ?? internationalization.defaultLocale),
|
|
12
12
|
filePlugin,
|
|
13
|
-
genderPlugin
|
|
13
|
+
genderPlugin,
|
|
14
|
+
selectPlugin
|
|
14
15
|
];
|
|
15
16
|
/**
|
|
16
17
|
* Transforms a node in a single pass, applying each plugin as needed.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContent.mjs","names":[],"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { deepTransformNode } from './deepTransform';\nimport {\n conditionPlugin,\n type DeepTransformContent,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState,\n insertionPlugin,\n type NodeProps,\n nestedPlugin,\n type Plugins,\n translationPlugin,\n} from './plugins';\n\nexport const getBasePlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] =>\n [\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n conditionPlugin,\n insertionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n ] as Plugins[];\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getContent = <\n const T extends ContentNode,\n const L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n nodeProps: NodeProps,\n plugins: Plugins[] = []\n) =>\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T, IInterpreterPluginState, L>;\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"getContent.mjs","names":[],"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { deepTransformNode } from './deepTransform';\nimport {\n conditionPlugin,\n type DeepTransformContent,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState,\n insertionPlugin,\n type NodeProps,\n nestedPlugin,\n type Plugins,\n selectPlugin,\n translationPlugin,\n} from './plugins';\n\nexport const getBasePlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] =>\n [\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n conditionPlugin,\n insertionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n selectPlugin,\n ] as Plugins[];\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getContent = <\n const T extends ContentNode,\n const L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n nodeProps: NodeProps,\n plugins: Plugins[] = []\n) =>\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T, IInterpreterPluginState, L>;\n"],"mappings":";;;;;AAsBA,MAAa,kBACX,QACA,WAAoB,SAEpB;CACE,kBACE,UAAU,qBAAqB,eAC/B,WAAW,qBAAqB,gBAAgB,MAClD;CACA;CACA;CACA;CACA,aAAa,UAAU,qBAAqB,aAAa;CACzD;CACA;CACA;AACF;;;;;;;AAQF,MAAa,cAIX,MACA,WACA,UAAqB,CAAC,MAEtB,kBAAkB,MAAM;CACtB,GAAG;CACH;AACF,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deepTransformNode } from "./deepTransform.mjs";
|
|
2
|
-
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, translationPlugin } from "./plugins.mjs";
|
|
2
|
+
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin } from "./plugins.mjs";
|
|
3
3
|
import { getBasePlugins, getContent } from "./getContent.mjs";
|
|
4
4
|
|
|
5
|
-
export { conditionPlugin, deepTransformNode, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, getBasePlugins, getContent, insertionPlugin, nestedPlugin, pluralPlugin, translationPlugin };
|
|
5
|
+
export { conditionPlugin, deepTransformNode, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, getBasePlugins, getContent, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin };
|
|
@@ -4,6 +4,7 @@ import { getGender } from "../getGender.mjs";
|
|
|
4
4
|
import { getInsertion } from "../getInsertion.mjs";
|
|
5
5
|
import { getNesting } from "../getNesting.mjs";
|
|
6
6
|
import { getPlural } from "../getPlural.mjs";
|
|
7
|
+
import { getSelect } from "../getSelect.mjs";
|
|
7
8
|
import { getTranslation } from "../getTranslation.mjs";
|
|
8
9
|
import { isInterpolableWrapperNode, transformInterpolableNode } from "../interpolableNode.mjs";
|
|
9
10
|
import * as NodeTypes from "@intlayer/types/nodeType";
|
|
@@ -203,6 +204,32 @@ const genderPlugin = process.env.INTLAYER_NODE_TYPE_GENDER === "false" ? fallbac
|
|
|
203
204
|
return (value) => getGender(result, value);
|
|
204
205
|
}
|
|
205
206
|
};
|
|
207
|
+
/** Select plugin. Replaces node with a function that takes a string => content. */
|
|
208
|
+
const selectPlugin = process.env.INTLAYER_NODE_TYPE_SELECT === "false" ? fallbackPlugin : {
|
|
209
|
+
id: "select-plugin",
|
|
210
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.SELECT,
|
|
211
|
+
transform: (node, props, deepTransformNode) => {
|
|
212
|
+
const original = node[NodeTypes.SELECT];
|
|
213
|
+
const result = {};
|
|
214
|
+
for (const key in original) {
|
|
215
|
+
const child = original[key];
|
|
216
|
+
result[key] = deepTransformNode(child, {
|
|
217
|
+
...props,
|
|
218
|
+
children: child,
|
|
219
|
+
keyPath: [...props.keyPath, {
|
|
220
|
+
type: NodeTypes.SELECT,
|
|
221
|
+
key
|
|
222
|
+
}]
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return (arg) => {
|
|
226
|
+
const value = typeof arg === "string" ? arg : arg?.value;
|
|
227
|
+
const subResult = getSelect(result, value);
|
|
228
|
+
if (typeof subResult === "function" && typeof arg === "object") return subResult(arg);
|
|
229
|
+
return subResult;
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
};
|
|
206
233
|
/** Nested plugin. Replaces node with the result of `getNesting`. */
|
|
207
234
|
const nestedPlugin = (locale) => process.env.INTLAYER_NODE_TYPE_NESTED === "false" ? fallbackPlugin : {
|
|
208
235
|
id: "nested-plugin",
|
|
@@ -223,5 +250,5 @@ const filePlugin = process.env.INTLAYER_NODE_TYPE_FILE === "false" ? fallbackPlu
|
|
|
223
250
|
};
|
|
224
251
|
|
|
225
252
|
//#endregion
|
|
226
|
-
export { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, translationPlugin };
|
|
253
|
+
export { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin };
|
|
227
254
|
//# sourceMappingURL=plugins.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.mjs","names":[],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n PluralContent,\n PluralContentState,\n TranslationContent,\n} from '../../transpiler';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getPlural } from '../getPlural';\nimport { getTranslation } from '../getTranslation';\nimport {\n isInterpolableWrapperNode,\n transformInterpolableNode,\n} from '../interpolableNode';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * FALLBACK PLUGIN\n *\n * Used to fallback a tree-shaken plugin\n * --------------------------------------------- */\n\nexport const fallbackPlugin: Plugins = {\n id: 'fallback-plugin',\n canHandle: () => false,\n transform: (node) => node,\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type UnionKeys<T> = T extends unknown ? keyof T : never;\nexport type ValueAtKey<T, K> = T extends unknown\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\nexport type TranslationCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.TRANSLATION]: infer U;\n}\n ? U extends Record<PropertyKey, unknown>\n ? U[keyof U] extends Record<PropertyKey, unknown>\n ? {\n [K in UnionKeys<U[keyof U]>]: L extends keyof U\n ? K extends keyof U[L]\n ? U[L][K]\n : ValueAtKey<U[keyof U], K>\n : ValueAtKey<U[keyof U], K>;\n } extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : (L extends keyof U ? U[L] : U[keyof U]) extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : never\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins =>\n process.env.INTLAYER_NODE_TYPE_TRANSLATION === 'false'\n ? fallbackPlugin\n : {\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.TRANSLATION,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const original = node[NodeTypes.TRANSLATION] ?? {};\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const childProps = {\n ...props,\n children: original[key as keyof typeof original],\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.TRANSLATION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(\n original[key as keyof typeof original],\n childProps\n );\n }\n\n return getTranslation(result, locale, fallback);\n },\n };\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.ENUMERATION]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[typeof NodeTypes.ENUMERATION][keyof T[typeof NodeTypes.ENUMERATION]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_ENUMERATION === 'false'\n ? fallbackPlugin\n : {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.ENUMERATION,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const original = node[NodeTypes.ENUMERATION];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as unknown as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.ENUMERATION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: number | { count: number }) => {\n const quantity = typeof arg === 'number' ? arg : arg.count;\n const subResult = getEnumeration(result, quantity);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * PLURAL PLUGIN\n * --------------------------------------------- */\n\nexport type PluralCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.PLURAL]: object;\n}\n ? (\n arg: number | { count: number; [key: string]: unknown }\n ) => DeepTransformContent<\n T[typeof NodeTypes.PLURAL][keyof T[typeof NodeTypes.PLURAL]],\n S\n >\n : never;\n\ntype SubResultFunction = (values: Record<string, string | number>) => string;\n\n/**\n * Plural plugin. Replaces node with a function that takes a count (or\n * `{ count, ...values }`) => string, picking the matching CLDR plural form\n * for the active locale and interpolating `{{count}}` (and other values).\n */\nexport const pluralPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_PLURAL === 'false'\n ? fallbackPlugin\n : {\n id: 'plural-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.PLURAL,\n transform: (node: PluralContent, props, deepTransformNode) => {\n const original = node[NodeTypes.PLURAL];\n const result: Record<string, any> = {};\n\n /** String plugin for plural. Replaces string node with a component that renders the insertion. */\n const pluralStringPlugin: Plugins = {\n id: 'plural-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{count}}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n if (isInterpolableWrapperNode(node)) {\n return (values: { [k: string]: string | number }) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (values: { [k: string]: string | number }) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.PLURAL, key } as KeyPath,\n ],\n plugins: [pluralStringPlugin, ...(props.plugins ?? [])],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n const effectiveLocale = String(locale ?? props.locale ?? 'en');\n\n return (arg: number | { count: number; [key: string]: unknown }) => {\n const count = typeof arg === 'number' ? arg : arg.count;\n const values =\n typeof arg === 'number'\n ? { count: arg }\n : (arg as { count: number; [key: string]: unknown });\n\n const subResult: string | SubResultFunction = getPlural(\n result as PluralContent['plural'] as PluralContentState<string>,\n count,\n effectiveLocale\n );\n\n if (typeof subResult === 'function') {\n return (subResult as SubResultFunction)(values);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.CONDITION]: object;\n}\n ? (\n value: boolean | { value: boolean }\n ) => DeepTransformContent<\n T[typeof NodeTypes.CONDITION][keyof T[typeof NodeTypes.CONDITION]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_CONDITION === 'false'\n ? fallbackPlugin\n : {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.CONDITION,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const original = node[NodeTypes.CONDITION];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.CONDITION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: boolean | { value: boolean }) => {\n const value = typeof arg === 'boolean' ? arg : arg.value;\n const subResult = getCondition(result as any, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? (\n values: {\n [K in T['fields'][number]]: string | number;\n }\n ) => I extends string\n ? DeepTransformContent<string, S>\n : DeepTransformContent<I, S>\n : never;\n\n/** Insertion plugin. Replaces node with a function that takes quantity => string. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n if (isInterpolableWrapperNode(node)) {\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.GENDER]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<\n T[typeof NodeTypes.GENDER][keyof T[typeof NodeTypes.GENDER]],\n S\n >\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_GENDER === 'false'\n ? fallbackPlugin\n : {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.GENDER,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const original = node[NodeTypes.GENDER];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.GENDER, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (value: Gender) => getGender(result as any, value);\n },\n };\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.NESTED]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_NESTED === 'false'\n ? fallbackPlugin\n : {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n (node?.nodeType === NodeTypes.NESTED || node?.nodeType === 'n'),\n transform: (node: NestedContent, props) =>\n getNesting(\n node[NodeTypes.NESTED].dictionaryKey,\n node[NodeTypes.NESTED].path,\n {\n ...props,\n locale: (locale ?? props.locale) as Locale,\n }\n ),\n };\n\n/** ---------------------------------------------\n * FILE PLUGIN\n * --------------------------------------------- */\n\nexport type FileCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.FILE]: string;\n content?: string;\n}\n ? DeepTransformContent<string, S>\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_FILE === 'false'\n ? fallbackPlugin\n : {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.FILE,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n };\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locale;\n dictionaryPath?: string;\n children?: any;\n /**\n * Forces eager traversal of plain objects in `deepTransformNode`. By default\n * traversal is lazy (property getters), so callers that discard the returned\n * value never trigger plugins on nested nodes. Set this when running plugins\n * for their side effects only (e.g. missing-locale detection).\n */\n eager?: boolean;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S, L extends LocalesValues> {\n translation: TranslationCond<T, S, L>;\n enumeration: EnumerationCond<T, S, L>;\n plural: PluralCond<T, S, L>;\n condition: ConditionCond<T, S, L>;\n insertion: InsertionCond<T, S, L>;\n gender: GenderCond<T, S, L>;\n nested: NestedCond<T, S, L>;\n file: FileCond<T, S, L>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n plural: true;\n condition: true;\n insertion: true;\n gender: true;\n nested: true;\n file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<\n T,\n K extends keyof IInterpreterPlugin<T, S, L>,\n S,\n L extends LocalesValues = DeclaredLocales,\n> = K extends keyof S // Test if the key is a key of S.\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S, L>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S, L>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S, L extends LocalesValues = DeclaredLocales> =\n T extends ReadonlyArray<infer U> // Turn any read-only array into a plain mutable array\n ? Array<DeepTransformContent<U, S, L>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S, L> }\n : T;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<\n T,\n S = IInterpreterPluginState,\n L extends LocalesValues = DeclaredLocales,\n> =\n IsAny<T> extends true\n ? T\n : CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L> extends never // Check if there is a plugin for T:\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S, L>\n : // A plugin was found – use the plugin's transformation.\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L>;\n"],"mappings":";;;;;;;;;;;;;;;;AAgEA,MAAa,iBAA0B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ins.mjs","names":[],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n PluralContent,\n PluralContentState,\n SelectContent,\n TranslationContent,\n} from '../../transpiler';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getPlural } from '../getPlural';\nimport { getSelect } from '../getSelect';\nimport { getTranslation } from '../getTranslation';\nimport {\n isInterpolableWrapperNode,\n transformInterpolableNode,\n} from '../interpolableNode';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * FALLBACK PLUGIN\n *\n * Used to fallback a tree-shaken plugin\n * --------------------------------------------- */\n\nexport const fallbackPlugin: Plugins = {\n id: 'fallback-plugin',\n canHandle: () => false,\n transform: (node) => node,\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type UnionKeys<T> = T extends unknown ? keyof T : never;\nexport type ValueAtKey<T, K> = T extends unknown\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\nexport type TranslationCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.TRANSLATION]: infer U;\n}\n ? U extends Record<PropertyKey, unknown>\n ? U[keyof U] extends Record<PropertyKey, unknown>\n ? {\n [K in UnionKeys<U[keyof U]>]: L extends keyof U\n ? K extends keyof U[L]\n ? U[L][K]\n : ValueAtKey<U[keyof U], K>\n : ValueAtKey<U[keyof U], K>;\n } extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : (L extends keyof U ? U[L] : U[keyof U]) extends infer Content\n ? DeepTransformContent<Content, S>\n : never\n : never\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins =>\n process.env.INTLAYER_NODE_TYPE_TRANSLATION === 'false'\n ? fallbackPlugin\n : {\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.TRANSLATION,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const original = node[NodeTypes.TRANSLATION] ?? {};\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const childProps = {\n ...props,\n children: original[key as keyof typeof original],\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.TRANSLATION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(\n original[key as keyof typeof original],\n childProps\n );\n }\n\n return getTranslation(result, locale, fallback);\n },\n };\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.ENUMERATION]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[typeof NodeTypes.ENUMERATION][keyof T[typeof NodeTypes.ENUMERATION]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_ENUMERATION === 'false'\n ? fallbackPlugin\n : {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.ENUMERATION,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const original = node[NodeTypes.ENUMERATION];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as unknown as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.ENUMERATION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: number | { count: number }) => {\n const quantity = typeof arg === 'number' ? arg : arg.count;\n const subResult = getEnumeration(result, quantity);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * PLURAL PLUGIN\n * --------------------------------------------- */\n\nexport type PluralCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.PLURAL]: object;\n}\n ? (\n arg: number | { count: number; [key: string]: unknown }\n ) => DeepTransformContent<\n T[typeof NodeTypes.PLURAL][keyof T[typeof NodeTypes.PLURAL]],\n S\n >\n : never;\n\ntype SubResultFunction = (values: Record<string, string | number>) => string;\n\n/**\n * Plural plugin. Replaces node with a function that takes a count (or\n * `{ count, ...values }`) => string, picking the matching CLDR plural form\n * for the active locale and interpolating `{{count}}` (and other values).\n */\nexport const pluralPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_PLURAL === 'false'\n ? fallbackPlugin\n : {\n id: 'plural-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.PLURAL,\n transform: (node: PluralContent, props, deepTransformNode) => {\n const original = node[NodeTypes.PLURAL];\n const result: Record<string, any> = {};\n\n /** String plugin for plural. Replaces string node with a component that renders the insertion. */\n const pluralStringPlugin: Plugins = {\n id: 'plural-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{count}}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n if (isInterpolableWrapperNode(node)) {\n return (values: { [k: string]: string | number }) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (values: { [k: string]: string | number }) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.PLURAL, key } as KeyPath,\n ],\n plugins: [pluralStringPlugin, ...(props.plugins ?? [])],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n const effectiveLocale = String(locale ?? props.locale ?? 'en');\n\n return (arg: number | { count: number; [key: string]: unknown }) => {\n const count = typeof arg === 'number' ? arg : arg.count;\n const values =\n typeof arg === 'number'\n ? { count: arg }\n : (arg as { count: number; [key: string]: unknown });\n\n const subResult: string | SubResultFunction = getPlural(\n result as PluralContent['plural'] as PluralContentState<string>,\n count,\n effectiveLocale\n );\n\n if (typeof subResult === 'function') {\n return (subResult as SubResultFunction)(values);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.CONDITION]: object;\n}\n ? (\n value: boolean | { value: boolean }\n ) => DeepTransformContent<\n T[typeof NodeTypes.CONDITION][keyof T[typeof NodeTypes.CONDITION]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_CONDITION === 'false'\n ? fallbackPlugin\n : {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.CONDITION,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const original = node[NodeTypes.CONDITION];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.CONDITION, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: boolean | { value: boolean }) => {\n const value = typeof arg === 'boolean' ? arg : arg.value;\n const subResult = getCondition(result as any, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? (\n values: {\n [K in T['fields'][number]]: string | number;\n }\n ) => I extends string\n ? DeepTransformContent<string, S>\n : DeepTransformContent<I, S>\n : never;\n\n/** Insertion plugin. Replaces node with a function that takes quantity => string. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n if (isInterpolableWrapperNode(node)) {\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.GENDER]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<\n T[typeof NodeTypes.GENDER][keyof T[typeof NodeTypes.GENDER]],\n S\n >\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_GENDER === 'false'\n ? fallbackPlugin\n : {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.GENDER,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const original = node[NodeTypes.GENDER];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.GENDER, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (value: Gender) => getGender(result as any, value);\n },\n };\n\n/** ---------------------------------------------\n * SELECT PLUGIN\n * --------------------------------------------- */\n\n/**\n * Accepted selector for a select node.\n *\n * When the node declares a `fallback` case, any string is accepted (the\n * fallback covers the unmatched values) while the declared cases still\n * autocomplete. Without a `fallback`, only the declared cases are accepted.\n */\nexport type SelectSelector<States> = 'fallback' extends keyof States\n ? Exclude<keyof States & string, 'fallback'> | (string & {})\n : keyof States & string;\n\nexport type SelectCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.SELECT]: object;\n}\n ? (\n value:\n | SelectSelector<T[typeof NodeTypes.SELECT]>\n | { value: SelectSelector<T[typeof NodeTypes.SELECT]> }\n ) => DeepTransformContent<\n T[typeof NodeTypes.SELECT][keyof T[typeof NodeTypes.SELECT]],\n S\n >\n : never;\n\n/** Select plugin. Replaces node with a function that takes a string => content. */\nexport const selectPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_SELECT === 'false'\n ? fallbackPlugin\n : {\n id: 'select-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.SELECT,\n transform: (node: SelectContent, props, deepTransformNode) => {\n const original = node[NodeTypes.SELECT];\n const result: Record<string, any> = {};\n\n for (const key in original) {\n const child = original[key as keyof typeof original];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeTypes.SELECT, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(child, childProps);\n }\n\n return (arg: string | { value: string }) => {\n const value = typeof arg === 'string' ? arg : arg?.value;\n const subResult = getSelect(result, value);\n\n if (typeof subResult === 'function' && typeof arg === 'object') {\n return subResult(arg);\n }\n\n return subResult;\n };\n },\n };\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.NESTED]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin = (locale?: LocalesValues): Plugins =>\n process.env.INTLAYER_NODE_TYPE_NESTED === 'false'\n ? fallbackPlugin\n : {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n (node?.nodeType === NodeTypes.NESTED || node?.nodeType === 'n'),\n transform: (node: NestedContent, props) =>\n getNesting(\n node[NodeTypes.NESTED].dictionaryKey,\n node[NodeTypes.NESTED].path,\n {\n ...props,\n locale: (locale ?? props.locale) as Locale,\n }\n ),\n };\n\n/** ---------------------------------------------\n * FILE PLUGIN\n * --------------------------------------------- */\n\nexport type FileCond<T, S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.FILE]: string;\n content?: string;\n}\n ? DeepTransformContent<string, S>\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_FILE === 'false'\n ? fallbackPlugin\n : {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.FILE,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n };\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locale;\n dictionaryPath?: string;\n children?: any;\n /**\n * Forces eager traversal of plain objects in `deepTransformNode`. By default\n * traversal is lazy (property getters), so callers that discard the returned\n * value never trigger plugins on nested nodes. Set this when running plugins\n * for their side effects only (e.g. missing-locale detection).\n */\n eager?: boolean;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S, L extends LocalesValues> {\n translation: TranslationCond<T, S, L>;\n enumeration: EnumerationCond<T, S, L>;\n plural: PluralCond<T, S, L>;\n condition: ConditionCond<T, S, L>;\n insertion: InsertionCond<T, S, L>;\n gender: GenderCond<T, S, L>;\n select: SelectCond<T, S, L>;\n nested: NestedCond<T, S, L>;\n file: FileCond<T, S, L>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n plural: true;\n condition: true;\n insertion: true;\n gender: true;\n select: true;\n nested: true;\n file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<\n T,\n K extends keyof IInterpreterPlugin<T, S, L>,\n S,\n L extends LocalesValues = DeclaredLocales,\n> = K extends keyof S // Test if the key is a key of S.\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S, L>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S, L>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S, L extends LocalesValues = DeclaredLocales> =\n T extends ReadonlyArray<infer U> // Turn any read-only array into a plain mutable array\n ? Array<DeepTransformContent<U, S, L>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S, L> }\n : T;\n\nexport type IsAny<T> = 0 extends 1 & T ? true : false;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<\n T,\n S = IInterpreterPluginState,\n L extends LocalesValues = DeclaredLocales,\n> =\n IsAny<T> extends true\n ? T\n : CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L> extends never // Check if there is a plugin for T:\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S, L>\n : // A plugin was found – use the plugin's transformation.\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L>;\n"],"mappings":";;;;;;;;;;;;;;;;;AAkEA,MAAa,iBAA0B;CACrC,IAAI;CACJ,iBAAiB;CACjB,YAAY,SAAS;AACvB;;AAmCA,MAAa,qBACX,QACA,aAEA,QAAQ,IAAI,mCAAmC,UAC3C,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,UAAU;CAC3D,YAAY,MAA0B,OAAO,sBAAsB;EACjE,MAAM,WAAW,KAAK,UAAU,gBAAgB,CAAC;EACjD,MAAM,SAA8B,CAAC;EAErC,KAAK,MAAM,OAAO,UAAU;GAC1B,MAAM,aAAa;IACjB,GAAG;IACH,UAAU,SAAS;IACnB,SAAS,CACP,GAAG,MAAM,SACT;KAAE,MAAM,UAAU;KAAa;IAAI,CACrC;GACF;GACA,OAAO,OAAO,kBACZ,SAAS,MACT,UACF;EACF;EAEA,OAAO,eAAe,QAAQ,QAAQ,QAAQ;CAChD;AACF;;AAmBN,MAAa,oBACX,QAAQ,IAAI,mCAAmC,UAC3C,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,UAAU;CAC3D,YAAY,MAA0B,OAAO,sBAAsB;EACjE,MAAM,WAAW,KAAK,UAAU;EAChC,MAAM,SAA8B,CAAC;EAErC,KAAK,MAAM,OAAO,UAAU;GAC1B,MAAM,QAAQ,SAAS;GASvB,OAAO,OAAO,kBAAkB,OAAO;IAPrC,GAAG;IACH,UAAU;IACV,SAAS,CACP,GAAG,MAAM,SACT;KAAE,MAAM,UAAU;KAAa;IAAI,CACrC;GAE8C,CAAC;EACnD;EAEA,QAAQ,QAAoC;GAC1C,MAAM,WAAW,OAAO,QAAQ,WAAW,MAAM,IAAI;GACrD,MAAM,YAAY,eAAe,QAAQ,QAAQ;GAEjD,IAAI,OAAO,cAAc,cAAc,OAAO,QAA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8C,CAAC;EACnD;EAEA,QAAQ,QAAoC;GAC1C,MAAM,QAAQ,OAAO,QAAQ,WAAW,MAAM,KAAK;GACnD,MAAM,YAAY,UAAU,QAAQ,KAAK;GAEzC,IAAI,OAAO,cAAc,cAAc,OAAO,QAAQ,UACpD,OAAO,UAAU,GAAG;GAGtB,OAAO;EACT;CACF;AACF;;AAmBN,MAAa,gBAAgB,WAC3B,QAAQ,IAAI,8BAA8B,UACtC,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,aACf,MAAM,aAAa,UAAU,UAAU,MAAM,aAAa;CAC7D,YAAY,MAAqB,UAC/B,WACE,KAAK,UAAU,OAAO,CAAC,eACvB,KAAK,UAAU,OAAO,CAAC,MACvB;EACE,GAAG;EACH,QAAS,UAAU,MAAM;CAC3B,CACF;AACJ;;AAeN,MAAa,aACX,QAAQ,IAAI,4BAA4B,UACpC,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,UAAU;CAC3D,YAAY,MAAmB,OAAO,kBACpC,cAAc,KAAK,SAAS;EAC1B,GAAG;EACH,UAAU,KAAK;CACjB,CAAC;AACL"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/interpreter/getSelect.ts
|
|
2
|
+
/**
|
|
3
|
+
* Picks content from a select map based on an arbitrary string value.
|
|
4
|
+
*
|
|
5
|
+
* Resolution order:
|
|
6
|
+
* 1. Exact match on the provided value.
|
|
7
|
+
* 2. The `fallback` key.
|
|
8
|
+
* 3. The `other` key — kept for content imported from an ICU `select` message,
|
|
9
|
+
* where the catch-all case is named `other`.
|
|
10
|
+
* 4. The last declared key, so a select node never resolves to `undefined`.
|
|
11
|
+
*
|
|
12
|
+
* @param selectContent - A map of string cases to content.
|
|
13
|
+
* @param value - The value to match against the declared cases.
|
|
14
|
+
* @returns The matching content.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const content = getSelect({
|
|
19
|
+
* draft: 'This post is a draft',
|
|
20
|
+
* published: 'This post is live',
|
|
21
|
+
* fallback: 'Unknown status',
|
|
22
|
+
* }, 'published');
|
|
23
|
+
* // 'This post is live'
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
const getSelect = (selectContent, value) => {
|
|
27
|
+
const caseList = Object.keys(selectContent);
|
|
28
|
+
const lastCase = caseList[caseList.length - 1];
|
|
29
|
+
return selectContent[value] ?? selectContent.fallback ?? selectContent.other ?? selectContent[lastCase];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { getSelect };
|
|
34
|
+
//# sourceMappingURL=getSelect.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSelect.mjs","names":[],"sources":["../../../src/interpreter/getSelect.ts"],"sourcesContent":["import type { SelectContentStates } from '../transpiler';\n\n/**\n * Picks content from a select map based on an arbitrary string value.\n *\n * Resolution order:\n * 1. Exact match on the provided value.\n * 2. The `fallback` key.\n * 3. The `other` key — kept for content imported from an ICU `select` message,\n * where the catch-all case is named `other`.\n * 4. The last declared key, so a select node never resolves to `undefined`.\n *\n * @param selectContent - A map of string cases to content.\n * @param value - The value to match against the declared cases.\n * @returns The matching content.\n *\n * @example\n * ```ts\n * const content = getSelect({\n * draft: 'This post is a draft',\n * published: 'This post is live',\n * fallback: 'Unknown status',\n * }, 'published');\n * // 'This post is live'\n * ```\n */\nexport const getSelect = <const Content>(\n selectContent: SelectContentStates<Content>,\n value?: string\n): Content => {\n const caseList = Object.keys(selectContent);\n const lastCase = caseList[caseList.length - 1] as keyof typeof selectContent;\n\n return (selectContent[value as keyof typeof selectContent] ??\n selectContent.fallback ??\n selectContent.other ??\n selectContent[lastCase]) as Content;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,aACX,eACA,UACY;CACZ,MAAM,WAAW,OAAO,KAAK,aAAa;CAC1C,MAAM,WAAW,SAAS,SAAS,SAAS;CAE5C,OAAQ,cAAc,UACpB,cAAc,YACd,cAAc,SACd,cAAc;AAClB"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { getCondition } from "./getCondition.mjs";
|
|
2
2
|
import { deepTransformNode } from "./getContent/deepTransform.mjs";
|
|
3
3
|
import { findMatchingCondition, getEnumeration } from "./getEnumeration.mjs";
|
|
4
|
+
import { getGender } from "./getGender.mjs";
|
|
4
5
|
import { getInsertion } from "./getInsertion.mjs";
|
|
5
6
|
import { getDictionary } from "./getDictionary.mjs";
|
|
6
7
|
import { getIntlayer } from "./getIntlayer.mjs";
|
|
7
8
|
import { getNesting } from "./getNesting.mjs";
|
|
8
9
|
import { getPlural } from "./getPlural.mjs";
|
|
10
|
+
import { getSelect } from "./getSelect.mjs";
|
|
9
11
|
import { getTranslation } from "./getTranslation.mjs";
|
|
10
12
|
import { getInterpolableContent, isInterpolableWrapperNode, rebuildInterpolableContent, transformInterpolableNode } from "./interpolableNode.mjs";
|
|
11
|
-
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, translationPlugin } from "./getContent/plugins.mjs";
|
|
13
|
+
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin } from "./getContent/plugins.mjs";
|
|
12
14
|
import { getBasePlugins, getContent } from "./getContent/getContent.mjs";
|
|
13
15
|
import { getHTML } from "./getHTML.mjs";
|
|
14
16
|
import { splitInsertionTemplate } from "./splitAndJoinInsertion.mjs";
|
|
15
17
|
|
|
16
|
-
export { conditionPlugin, deepTransformNode, enumerationPlugin, fallbackPlugin, filePlugin, findMatchingCondition, genderPlugin, getBasePlugins, getCondition, getContent, getDictionary, getEnumeration, getHTML, getInsertion, getInterpolableContent, getIntlayer, getNesting, getPlural, getTranslation, insertionPlugin, isInterpolableWrapperNode, nestedPlugin, pluralPlugin, rebuildInterpolableContent, splitInsertionTemplate, transformInterpolableNode, translationPlugin };
|
|
18
|
+
export { conditionPlugin, deepTransformNode, enumerationPlugin, fallbackPlugin, filePlugin, findMatchingCondition, genderPlugin, getBasePlugins, getCondition, getContent, getDictionary, getEnumeration, getGender, getHTML, getInsertion, getInterpolableContent, getIntlayer, getNesting, getPlural, getSelect, getTranslation, insertionPlugin, isInterpolableWrapperNode, nestedPlugin, pluralPlugin, rebuildInterpolableContent, selectPlugin, splitInsertionTemplate, transformInterpolableNode, translationPlugin };
|