@intlayer/core 9.0.2 → 9.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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/index.cjs +1 -0
- package/dist/cjs/dictionaryManipulator/mergeQualifiedDictionaries.cjs +25 -2
- package/dist/cjs/dictionaryManipulator/mergeQualifiedDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/qualifiedDictionary.cjs +42 -13
- package/dist/cjs/dictionaryManipulator/qualifiedDictionary.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/qualifiedDictionary.test-d.cjs +92 -0
- package/dist/cjs/dictionaryManipulator/qualifiedDictionary.test-d.cjs.map +1 -0
- 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 +8 -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/getDictionary.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayer.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/index.mjs +2 -2
- package/dist/esm/dictionaryManipulator/mergeQualifiedDictionaries.mjs +26 -3
- package/dist/esm/dictionaryManipulator/mergeQualifiedDictionaries.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/qualifiedDictionary.mjs +42 -14
- package/dist/esm/dictionaryManipulator/qualifiedDictionary.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/qualifiedDictionary.test-d.mjs +92 -0
- package/dist/esm/dictionaryManipulator/qualifiedDictionary.test-d.mjs.map +1 -0
- 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 +6 -3
- 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/getDictionary.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayer.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/dictionaryManipulator/index.d.ts +2 -2
- package/dist/types/dictionaryManipulator/mergeQualifiedDictionaries.d.ts +4 -1
- package/dist/types/dictionaryManipulator/mergeQualifiedDictionaries.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/qualifiedDictionary.d.ts +16 -8
- package/dist/types/dictionaryManipulator/qualifiedDictionary.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/qualifiedDictionary.test-d.d.ts +1 -0
- package/dist/types/index.d.ts +6 -3
- 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/getDictionary.d.ts +2 -2
- package/dist/types/interpreter/getDictionary.d.ts.map +1 -1
- package/dist/types/interpreter/getIntlayer.d.ts +2 -2
- package/dist/types/interpreter/getIntlayer.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 +7 -7
|
@@ -13,29 +13,29 @@ const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
|
|
|
13
13
|
for (let i = 0; i < keyPath.length; i++) {
|
|
14
14
|
const keyObj = keyPath[i];
|
|
15
15
|
parentValue = currentValue;
|
|
16
|
-
if (keyObj
|
|
16
|
+
if (keyObj?.type === _intlayer_types_nodeType.OBJECT || keyObj?.type === _intlayer_types_nodeType.ARRAY) {
|
|
17
17
|
lastKeys = [keyObj.key];
|
|
18
18
|
if (!currentValue[keyObj.key] || typeof currentValue[keyObj.key] !== "object") currentValue[keyObj.key] = {};
|
|
19
19
|
currentValue = currentValue[keyObj.key];
|
|
20
20
|
}
|
|
21
|
-
if (keyObj
|
|
21
|
+
if (keyObj?.type === _intlayer_types_nodeType.TRANSLATION || keyObj?.type === _intlayer_types_nodeType.ENUMERATION || keyObj?.type === _intlayer_types_nodeType.PLURAL || keyObj?.type === _intlayer_types_nodeType.GENDER || keyObj?.type === _intlayer_types_nodeType.SELECT) {
|
|
22
22
|
lastKeys = [keyObj.type, keyObj.key];
|
|
23
23
|
if (!currentValue[keyObj.type] || typeof currentValue[keyObj.type] !== "object") currentValue[keyObj.type] = {};
|
|
24
24
|
if (!currentValue[keyObj.type][keyObj.key] || typeof currentValue[keyObj.type][keyObj.key] !== "object") currentValue[keyObj.type][keyObj.key] = {};
|
|
25
25
|
currentValue = currentValue[keyObj.type][keyObj.key];
|
|
26
26
|
}
|
|
27
|
-
if (keyObj
|
|
27
|
+
if (keyObj?.type === _intlayer_types_nodeType.ENUMERATION || keyObj?.type === _intlayer_types_nodeType.PLURAL || keyObj?.type === _intlayer_types_nodeType.CONDITION) {
|
|
28
28
|
if (keyObj.type !== _intlayer_types_nodeType.ENUMERATION && keyObj.type !== _intlayer_types_nodeType.PLURAL) {
|
|
29
29
|
lastKeys = [keyObj.type, keyObj.key];
|
|
30
30
|
currentValue = currentValue[keyObj.type][keyObj.key];
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
if (keyObj
|
|
33
|
+
if (keyObj?.type === _intlayer_types_nodeType.MARKDOWN || keyObj?.type === _intlayer_types_nodeType.HTML || keyObj?.type === _intlayer_types_nodeType.INSERTION) {
|
|
34
34
|
lastKeys = [keyObj.type];
|
|
35
35
|
if (currentValue[keyObj.type] == null) currentValue[keyObj.type] = "";
|
|
36
36
|
currentValue = currentValue[keyObj.type];
|
|
37
37
|
}
|
|
38
|
-
if (keyObj
|
|
38
|
+
if (keyObj?.type === _intlayer_types_nodeType.FILE) {
|
|
39
39
|
lastKeys = ["content"];
|
|
40
40
|
currentValue = currentValue.content;
|
|
41
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editDictionaryByKeyPath.cjs","names":["NodeTypes"],"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n if (keyPath.length === 0) {\n return newValue;\n }\n\n try {\n for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj
|
|
1
|
+
{"version":3,"file":"editDictionaryByKeyPath.cjs","names":["NodeTypes"],"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n if (keyPath.length === 0) {\n return newValue;\n }\n\n try {\n for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (\n keyObj?.type === NodeTypes.OBJECT ||\n keyObj?.type === NodeTypes.ARRAY\n ) {\n lastKeys = [keyObj.key];\n\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj?.type === NodeTypes.TRANSLATION ||\n keyObj?.type === NodeTypes.ENUMERATION ||\n keyObj?.type === NodeTypes.PLURAL ||\n keyObj?.type === NodeTypes.GENDER ||\n keyObj?.type === NodeTypes.SELECT\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj?.type === NodeTypes.ENUMERATION ||\n keyObj?.type === NodeTypes.PLURAL ||\n keyObj?.type === NodeTypes.CONDITION\n ) {\n // Note: Logic above already handles Enumeration/Plural, ensure no duplication in your actual file\n // or keep the specific block if your logic differs.\n // The important part is below in the final update block.\n\n // Assuming this block runs for Condition/Gender/etc:\n\n if (\n keyObj.type !== NodeTypes.ENUMERATION &&\n keyObj.type !== NodeTypes.PLURAL\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n }\n\n if (\n keyObj?.type === NodeTypes.MARKDOWN ||\n keyObj?.type === NodeTypes.HTML ||\n keyObj?.type === NodeTypes.INSERTION\n ) {\n lastKeys = [keyObj.type];\n\n if (currentValue[keyObj.type] == null) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj?.type === NodeTypes.FILE) {\n lastKeys = ['content'];\n currentValue = currentValue.content;\n }\n\n // Only update the value when processing the last key in the keyPath.\n\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n\n // Drill down to the container holding the value to be changed\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n\n const finalKey = lastKeys[lastKeys.length - 1];\n\n if (typeof newValue === 'undefined') {\n // Use splice for arrays to re-index the list, use delete for objects\n\n if (Array.isArray(target)) {\n const index = Number(finalKey);\n\n if (!Number.isNaN(index) && index >= 0 && index < target.length) {\n target.splice(index, 1);\n }\n } else {\n delete target[finalKey];\n }\n } else {\n target[finalKey] = newValue;\n }\n }\n }\n\n return dictionaryContent;\n } catch (error) {\n console.error(\n 'Cannot edit dictionary by key path',\n { dictionaryContent, keyPath, newValue },\n error\n );\n return dictionaryContent;\n }\n};\n"],"mappings":";;;;;;AAMA,MAAa,2BACX,mBACA,SACA,aACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,WAA0B,CAAC;CAE/B,IAAI,QAAQ,WAAW,GACrB,OAAO;CAGT,IAAI;EACF,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;GACvC,MAAM,SAAS,QAAQ;GACvB,cAAc;GAEd,IACE,QAAQ,SAASA,yBAAU,UAC3B,QAAQ,SAASA,yBAAU,OAC3B;IACA,WAAW,CAAC,OAAO,GAAG;IAEtB,IACE,CAAC,aAAa,OAAO,QACrB,OAAO,aAAa,OAAO,SAAS,UAEpC,aAAa,OAAO,OAAO,CAAC;IAE9B,eAAe,aAAa,OAAO;GACrC;GAEA,IACE,QAAQ,SAASA,yBAAU,eAC3B,QAAQ,SAASA,yBAAU,eAC3B,QAAQ,SAASA,yBAAU,UAC3B,QAAQ,SAASA,yBAAU,UAC3B,QAAQ,SAASA,yBAAU,QAC3B;IACA,WAAW,CAAC,OAAO,MAAM,OAAO,GAAG;IAEnC,IACE,CAAC,aAAa,OAAO,SACrB,OAAO,aAAa,OAAO,UAAU,UAErC,aAAa,OAAO,QAAQ,CAAC;IAG/B,IACE,CAAC,aAAa,OAAO,KAAK,CAAC,OAAO,QAClC,OAAO,aAAa,OAAO,KAAK,CAAC,OAAO,SAAS,UAEjD,aAAa,OAAO,KAAK,CAAC,OAAO,OAAO,CAAC;IAE3C,eAAe,aAAa,OAAO,KAAK,CAAC,OAAO;GAClD;GAEA,IACE,QAAQ,SAASA,yBAAU,eAC3B,QAAQ,SAASA,yBAAU,UAC3B,QAAQ,SAASA,yBAAU,WAQ3B;QACE,OAAO,SAASA,yBAAU,eAC1B,OAAO,SAASA,yBAAU,QAC1B;KACA,WAAW,CAAC,OAAO,MAAM,OAAO,GAAG;KACnC,eAAe,aAAa,OAAO,KAAK,CAAC,OAAO;IAClD;;GAGF,IACE,QAAQ,SAASA,yBAAU,YAC3B,QAAQ,SAASA,yBAAU,QAC3B,QAAQ,SAASA,yBAAU,WAC3B;IACA,WAAW,CAAC,OAAO,IAAI;IAEvB,IAAI,aAAa,OAAO,SAAS,MAC/B,aAAa,OAAO,QAAQ;IAE9B,eAAe,aAAa,OAAO;GACrC;GAEA,IAAI,QAAQ,SAASA,yBAAU,MAAM;IACnC,WAAW,CAAC,SAAS;IACrB,eAAe,aAAa;GAC9B;GAIA,IAAI,MAAM,QAAQ,SAAS,KAAK,eAAe,SAAS,SAAS,GAAG;IAClE,IAAI,SAAS;IAGb,KAAK,MAAM,OAAO,SAAS,MAAM,GAAG,EAAE,GACpC,SAAS,OAAO;IAGlB,MAAM,WAAW,SAAS,SAAS,SAAS;IAE5C,IAAI,OAAO,aAAa,aAGtB,IAAI,MAAM,QAAQ,MAAM,GAAG;KACzB,MAAM,QAAQ,OAAO,QAAQ;KAE7B,IAAI,CAAC,OAAO,MAAM,KAAK,KAAK,SAAS,KAAK,QAAQ,OAAO,QACvD,OAAO,OAAO,OAAO,CAAC;IAE1B,OACE,OAAO,OAAO;SAGhB,OAAO,YAAY;GAEvB;EACF;EAEA,OAAO;CACT,SAAS,OAAO;EACd,QAAQ,MACN,sCACA;GAAE;GAAmB;GAAS;EAAS,GACvC,KACF;EACA,OAAO;CACT;AACF"}
|
|
@@ -9,7 +9,7 @@ const getContentNodeByKeyPath = (dictionaryContent, keyPath, fallbackLocale) =>
|
|
|
9
9
|
for (const keyObj of keyPath) {
|
|
10
10
|
if (fallbackLocale && currentValue?.nodeType === _intlayer_types_nodeType.TRANSLATION) currentValue = currentValue?.[_intlayer_types_nodeType.TRANSLATION]?.[fallbackLocale];
|
|
11
11
|
if (keyObj.type === _intlayer_types_nodeType.OBJECT || keyObj.type === _intlayer_types_nodeType.ARRAY) currentValue = currentValue?.[keyObj.key];
|
|
12
|
-
if (keyObj.type === _intlayer_types_nodeType.TRANSLATION || keyObj.type === _intlayer_types_nodeType.CONDITION || keyObj.type === _intlayer_types_nodeType.ENUMERATION || keyObj.type === _intlayer_types_nodeType.PLURAL) currentValue = currentValue?.[keyObj.type]?.[keyObj.key];
|
|
12
|
+
if (keyObj.type === _intlayer_types_nodeType.TRANSLATION || keyObj.type === _intlayer_types_nodeType.CONDITION || keyObj.type === _intlayer_types_nodeType.ENUMERATION || keyObj.type === _intlayer_types_nodeType.PLURAL || keyObj.type === _intlayer_types_nodeType.GENDER || keyObj.type === _intlayer_types_nodeType.SELECT) currentValue = currentValue?.[keyObj.type]?.[keyObj.key];
|
|
13
13
|
if (keyObj.type === _intlayer_types_nodeType.MARKDOWN || keyObj.type === _intlayer_types_nodeType.HTML || keyObj.type === _intlayer_types_nodeType.INSERTION || keyObj.type === _intlayer_types_nodeType.FILE) currentValue = currentValue?.[keyObj.type];
|
|
14
14
|
}
|
|
15
15
|
return currentValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContentNodeByKeyPath.cjs","names":["NodeTypes"],"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n fallbackLocale?: LocalesValues\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n // Auto-resolve translation nodes when fallbackLocale is provided\n if (fallbackLocale && currentValue?.nodeType === NodeTypes.TRANSLATION) {\n currentValue = currentValue?.[NodeTypes.TRANSLATION]?.[fallbackLocale];\n }\n\n if (keyObj.type === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n currentValue = currentValue?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.CONDITION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL\n ) {\n currentValue = currentValue?.[keyObj.type]?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION ||\n keyObj.type === NodeTypes.FILE\n ) {\n currentValue = currentValue?.[keyObj.type];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":";;;;;;AAKA,MAAa,2BACX,mBACA,SACA,mBACgB;CAChB,IAAI,eAAoB,gBAAgB,iBAAiB;CAEzD,KAAK,MAAM,UAAU,SAAS;EAE5B,IAAI,kBAAkB,cAAc,aAAaA,yBAAU,aACzD,eAAe,eAAeA,yBAAU,YAAY,GAAG;EAGzD,IAAI,OAAO,SAASA,yBAAU,UAAU,OAAO,SAASA,yBAAU,OAChE,eAAe,eAAe,OAAO;EAGvC,IACE,OAAO,SAASA,yBAAU,eAC1B,OAAO,SAASA,yBAAU,aAC1B,OAAO,SAASA,yBAAU,eAC1B,OAAO,SAASA,yBAAU,QAE1B,eAAe,eAAe,OAAO,KAAK,GAAG,OAAO;EAGtD,IACE,OAAO,SAASA,yBAAU,YAC1B,OAAO,SAASA,yBAAU,QAC1B,OAAO,SAASA,yBAAU,aAC1B,OAAO,SAASA,yBAAU,MAE1B,eAAe,eAAe,OAAO;CAEzC;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"getContentNodeByKeyPath.cjs","names":["NodeTypes"],"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n fallbackLocale?: LocalesValues\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n // Auto-resolve translation nodes when fallbackLocale is provided\n if (fallbackLocale && currentValue?.nodeType === NodeTypes.TRANSLATION) {\n currentValue = currentValue?.[NodeTypes.TRANSLATION]?.[fallbackLocale];\n }\n\n if (keyObj.type === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n currentValue = currentValue?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.CONDITION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL ||\n keyObj.type === NodeTypes.GENDER ||\n keyObj.type === NodeTypes.SELECT\n ) {\n currentValue = currentValue?.[keyObj.type]?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION ||\n keyObj.type === NodeTypes.FILE\n ) {\n currentValue = currentValue?.[keyObj.type];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":";;;;;;AAKA,MAAa,2BACX,mBACA,SACA,mBACgB;CAChB,IAAI,eAAoB,gBAAgB,iBAAiB;CAEzD,KAAK,MAAM,UAAU,SAAS;EAE5B,IAAI,kBAAkB,cAAc,aAAaA,yBAAU,aACzD,eAAe,eAAeA,yBAAU,YAAY,GAAG;EAGzD,IAAI,OAAO,SAASA,yBAAU,UAAU,OAAO,SAASA,yBAAU,OAChE,eAAe,eAAe,OAAO;EAGvC,IACE,OAAO,SAASA,yBAAU,eAC1B,OAAO,SAASA,yBAAU,aAC1B,OAAO,SAASA,yBAAU,eAC1B,OAAO,SAASA,yBAAU,UAC1B,OAAO,SAASA,yBAAU,UAC1B,OAAO,SAASA,yBAAU,QAE1B,eAAe,eAAe,OAAO,KAAK,GAAG,OAAO;EAGtD,IACE,OAAO,SAASA,yBAAU,YAC1B,OAAO,SAASA,yBAAU,QAC1B,OAAO,SAASA,yBAAU,aAC1B,OAAO,SAASA,yBAAU,MAE1B,eAAe,eAAe,OAAO;CAEzC;CAEA,OAAO;AACT"}
|
|
@@ -29,6 +29,21 @@ const getDefaultNode = (nodeType, locales, content) => {
|
|
|
29
29
|
false: clonedContent ?? ""
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
+
case _intlayer_types_nodeType.GENDER: return {
|
|
33
|
+
nodeType: _intlayer_types_nodeType.GENDER,
|
|
34
|
+
[_intlayer_types_nodeType.GENDER]: {
|
|
35
|
+
male: clonedContent ?? "",
|
|
36
|
+
female: clonedContent ?? "",
|
|
37
|
+
fallback: clonedContent ?? ""
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
case _intlayer_types_nodeType.SELECT: return {
|
|
41
|
+
nodeType: _intlayer_types_nodeType.SELECT,
|
|
42
|
+
[_intlayer_types_nodeType.SELECT]: {
|
|
43
|
+
case1: clonedContent ?? "",
|
|
44
|
+
fallback: clonedContent ?? ""
|
|
45
|
+
}
|
|
46
|
+
};
|
|
32
47
|
case _intlayer_types_nodeType.INSERTION: return {
|
|
33
48
|
nodeType: _intlayer_types_nodeType.INSERTION,
|
|
34
49
|
[_intlayer_types_nodeType.INSERTION]: { insertion: clonedContent ?? "" }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDefaultNode.cjs","names":["NodeTypes"],"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n): ContentNode => {\n const clonedContent = structuredClone(content);\n switch (nodeType) {\n case NodeTypes.TRANSLATION:\n return {\n nodeType: NodeTypes.TRANSLATION,\n [NodeTypes.TRANSLATION]: Object.assign(\n {},\n ...locales.map((locale) => ({\n [locale]: structuredClone(clonedContent) ?? '',\n }))\n ),\n } as ContentNode;\n\n case NodeTypes.ENUMERATION:\n return {\n nodeType: NodeTypes.ENUMERATION,\n [NodeTypes.ENUMERATION]: {\n '1': clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.PLURAL:\n return {\n nodeType: NodeTypes.PLURAL,\n [NodeTypes.PLURAL]: {\n one: clonedContent ?? '',\n other: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.CONDITION:\n return {\n nodeType: NodeTypes.CONDITION,\n [NodeTypes.CONDITION]: {\n true: clonedContent ?? '',\n false: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.INSERTION:\n return {\n nodeType: NodeTypes.INSERTION,\n [NodeTypes.INSERTION]: {\n insertion: clonedContent ?? '',\n },\n } as unknown as ContentNode;\n\n case NodeTypes.NESTED:\n return {\n nodeType: NodeTypes.NESTED,\n [NodeTypes.NESTED]: {\n dictionaryKey: '',\n },\n } as ContentNode;\n\n case NodeTypes.MARKDOWN:\n return {\n nodeType: NodeTypes.MARKDOWN,\n [NodeTypes.MARKDOWN]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeTypes.HTML:\n return {\n nodeType: NodeTypes.HTML,\n [NodeTypes.HTML]: clonedContent ?? '',\n customComponents: [],\n } as ContentNode;\n\n case NodeTypes.FILE:\n return {\n nodeType: NodeTypes.FILE,\n [NodeTypes.FILE]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeTypes.OBJECT:\n return {\n newKey: clonedContent ?? '',\n } as unknown as ContentNode;\n\n case NodeTypes.ARRAY:\n return [clonedContent ?? ''] as unknown as ContentNode;\n\n case NodeTypes.TEXT:\n return clonedContent ?? '';\n\n case NodeTypes.NUMBER:\n return clonedContent ?? 0;\n\n case NodeTypes.BOOLEAN:\n return clonedContent ?? true;\n\n default:\n return clonedContent ?? '';\n }\n};\n"],"mappings":";;;;;;AAMA,MAAa,kBACX,UACA,SACA,YACgB;CAChB,MAAM,gBAAgB,gBAAgB,OAAO;CAC7C,QAAQ,UAAR;EACE,KAAKA,yBAAU,aACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,cAAc,OAAO,OAC9B,CAAC,GACD,GAAG,QAAQ,KAAK,YAAY,GACzB,SAAS,gBAAgB,aAAa,KAAK,GAC9C,EAAE,CACJ;EACF;EAEF,KAAKA,yBAAU,aACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,cAAc,EACvB,KAAK,iBAAiB,GACxB;EACF;EAEF,KAAKA,yBAAU,QACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,SAAS;IAClB,KAAK,iBAAiB;IACtB,OAAO,iBAAiB;GAC1B;EACF;EAEF,KAAKA,yBAAU,WACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,YAAY;IACrB,MAAM,iBAAiB;IACvB,OAAO,iBAAiB;GAC1B;EACF;EAEF,KAAKA,yBAAU,WACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,YAAY,EACrB,WAAW,iBAAiB,GAC9B;EACF;EAEF,KAAKA,yBAAU,QACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,SAAS,EAClB,eAAe,GACjB;EACF;EAEF,KAAKA,yBAAU,UACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,WAAW,iBAAiB;EACzC;EAEF,KAAKA,yBAAU,MACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,OAAO,iBAAiB;GACnC,kBAAkB,CAAC;EACrB;EAEF,KAAKA,yBAAU,MACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,OAAO,iBAAiB;EACrC;EAEF,KAAKA,yBAAU,QACb,OAAO,EACL,QAAQ,iBAAiB,GAC3B;EAEF,KAAKA,yBAAU,OACb,OAAO,CAAC,iBAAiB,EAAE;EAE7B,KAAKA,yBAAU,MACb,OAAO,iBAAiB;EAE1B,KAAKA,yBAAU,QACb,OAAO,iBAAiB;EAE1B,KAAKA,yBAAU,SACb,OAAO,iBAAiB;EAE1B,SACE,OAAO,iBAAiB;CAC5B;AACF"}
|
|
1
|
+
{"version":3,"file":"getDefaultNode.cjs","names":["NodeTypes"],"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n): ContentNode => {\n const clonedContent = structuredClone(content);\n switch (nodeType) {\n case NodeTypes.TRANSLATION:\n return {\n nodeType: NodeTypes.TRANSLATION,\n [NodeTypes.TRANSLATION]: Object.assign(\n {},\n ...locales.map((locale) => ({\n [locale]: structuredClone(clonedContent) ?? '',\n }))\n ),\n } as ContentNode;\n\n case NodeTypes.ENUMERATION:\n return {\n nodeType: NodeTypes.ENUMERATION,\n [NodeTypes.ENUMERATION]: {\n '1': clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.PLURAL:\n return {\n nodeType: NodeTypes.PLURAL,\n [NodeTypes.PLURAL]: {\n one: clonedContent ?? '',\n other: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.CONDITION:\n return {\n nodeType: NodeTypes.CONDITION,\n [NodeTypes.CONDITION]: {\n true: clonedContent ?? '',\n false: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.GENDER:\n return {\n nodeType: NodeTypes.GENDER,\n [NodeTypes.GENDER]: {\n male: clonedContent ?? '',\n female: clonedContent ?? '',\n fallback: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.SELECT:\n return {\n nodeType: NodeTypes.SELECT,\n [NodeTypes.SELECT]: {\n case1: clonedContent ?? '',\n fallback: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.INSERTION:\n return {\n nodeType: NodeTypes.INSERTION,\n [NodeTypes.INSERTION]: {\n insertion: clonedContent ?? '',\n },\n } as unknown as ContentNode;\n\n case NodeTypes.NESTED:\n return {\n nodeType: NodeTypes.NESTED,\n [NodeTypes.NESTED]: {\n dictionaryKey: '',\n },\n } as ContentNode;\n\n case NodeTypes.MARKDOWN:\n return {\n nodeType: NodeTypes.MARKDOWN,\n [NodeTypes.MARKDOWN]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeTypes.HTML:\n return {\n nodeType: NodeTypes.HTML,\n [NodeTypes.HTML]: clonedContent ?? '',\n customComponents: [],\n } as ContentNode;\n\n case NodeTypes.FILE:\n return {\n nodeType: NodeTypes.FILE,\n [NodeTypes.FILE]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeTypes.OBJECT:\n return {\n newKey: clonedContent ?? '',\n } as unknown as ContentNode;\n\n case NodeTypes.ARRAY:\n return [clonedContent ?? ''] as unknown as ContentNode;\n\n case NodeTypes.TEXT:\n return clonedContent ?? '';\n\n case NodeTypes.NUMBER:\n return clonedContent ?? 0;\n\n case NodeTypes.BOOLEAN:\n return clonedContent ?? true;\n\n default:\n return clonedContent ?? '';\n }\n};\n"],"mappings":";;;;;;AAMA,MAAa,kBACX,UACA,SACA,YACgB;CAChB,MAAM,gBAAgB,gBAAgB,OAAO;CAC7C,QAAQ,UAAR;EACE,KAAKA,yBAAU,aACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,cAAc,OAAO,OAC9B,CAAC,GACD,GAAG,QAAQ,KAAK,YAAY,GACzB,SAAS,gBAAgB,aAAa,KAAK,GAC9C,EAAE,CACJ;EACF;EAEF,KAAKA,yBAAU,aACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,cAAc,EACvB,KAAK,iBAAiB,GACxB;EACF;EAEF,KAAKA,yBAAU,QACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,SAAS;IAClB,KAAK,iBAAiB;IACtB,OAAO,iBAAiB;GAC1B;EACF;EAEF,KAAKA,yBAAU,WACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,YAAY;IACrB,MAAM,iBAAiB;IACvB,OAAO,iBAAiB;GAC1B;EACF;EAEF,KAAKA,yBAAU,QACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,SAAS;IAClB,MAAM,iBAAiB;IACvB,QAAQ,iBAAiB;IACzB,UAAU,iBAAiB;GAC7B;EACF;EAEF,KAAKA,yBAAU,QACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,SAAS;IAClB,OAAO,iBAAiB;IACxB,UAAU,iBAAiB;GAC7B;EACF;EAEF,KAAKA,yBAAU,WACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,YAAY,EACrB,WAAW,iBAAiB,GAC9B;EACF;EAEF,KAAKA,yBAAU,QACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,SAAS,EAClB,eAAe,GACjB;EACF;EAEF,KAAKA,yBAAU,UACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,WAAW,iBAAiB;EACzC;EAEF,KAAKA,yBAAU,MACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,OAAO,iBAAiB;GACnC,kBAAkB,CAAC;EACrB;EAEF,KAAKA,yBAAU,MACb,OAAO;GACL,UAAUA,yBAAU;IACnBA,yBAAU,OAAO,iBAAiB;EACrC;EAEF,KAAKA,yBAAU,QACb,OAAO,EACL,QAAQ,iBAAiB,GAC3B;EAEF,KAAKA,yBAAU,OACb,OAAO,CAAC,iBAAiB,EAAE;EAE7B,KAAKA,yBAAU,MACb,OAAO,iBAAiB;EAE1B,KAAKA,yBAAU,QACb,OAAO,iBAAiB;EAE1B,KAAKA,yBAAU,SACb,OAAO,iBAAiB;EAE1B,SACE,OAAO,iBAAiB;CAC5B;AACF"}
|
|
@@ -11,7 +11,7 @@ const getEmptyNode = (section) => {
|
|
|
11
11
|
if (typeof section?.nodeType === "string") {
|
|
12
12
|
const typedNode = section;
|
|
13
13
|
const content = typedNode[typedNode.nodeType];
|
|
14
|
-
if (typedNode.nodeType === _intlayer_types_nodeType.TRANSLATION || typedNode.nodeType === _intlayer_types_nodeType.ENUMERATION || typedNode.nodeType === _intlayer_types_nodeType.PLURAL || typedNode.nodeType === _intlayer_types_nodeType.CONDITION || typedNode.nodeType === _intlayer_types_nodeType.INSERTION || typedNode.nodeType === _intlayer_types_nodeType.HTML) return getEmptyNode(content);
|
|
14
|
+
if (typedNode.nodeType === _intlayer_types_nodeType.TRANSLATION || typedNode.nodeType === _intlayer_types_nodeType.ENUMERATION || typedNode.nodeType === _intlayer_types_nodeType.PLURAL || typedNode.nodeType === _intlayer_types_nodeType.CONDITION || typedNode.nodeType === _intlayer_types_nodeType.INSERTION || typedNode.nodeType === _intlayer_types_nodeType.GENDER || typedNode.nodeType === _intlayer_types_nodeType.SELECT || typedNode.nodeType === _intlayer_types_nodeType.HTML) return getEmptyNode(content);
|
|
15
15
|
if (typedNode.nodeType === _intlayer_types_nodeType.NESTED) return "dictionary-key";
|
|
16
16
|
if (typedNode.nodeType === _intlayer_types_nodeType.FILE) return "file/path";
|
|
17
17
|
if (typedNode.nodeType === _intlayer_types_nodeType.MARKDOWN) return getEmptyNode(content);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEmptyNode.cjs","names":["NodeTypes"],"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,aAAaA,yBAAU,eACjC,UAAU,aAAaA,yBAAU,eACjC,UAAU,aAAaA,yBAAU,UACjC,UAAU,aAAaA,yBAAU,aACjC,UAAU,aAAaA,yBAAU,aACjC,UAAU,aAAaA,yBAAU,MAEjC,OAAO,aAAa,OAAsB;EAG5C,IAAI,UAAU,aAAaA,yBAAU,QACnC,OAAO;EAGT,IAAI,UAAU,aAAaA,yBAAU,MACnC,OAAO;EAGT,IAAI,UAAU,aAAaA,yBAAU,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.cjs","names":["NodeTypes"],"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,aAAaA,yBAAU,eACjC,UAAU,aAAaA,yBAAU,eACjC,UAAU,aAAaA,yBAAU,UACjC,UAAU,aAAaA,yBAAU,aACjC,UAAU,aAAaA,yBAAU,aACjC,UAAU,aAAaA,yBAAU,UACjC,UAAU,aAAaA,yBAAU,UACjC,UAAU,aAAaA,yBAAU,MAEjC,OAAO,aAAa,OAAsB;EAG5C,IAAI,UAAU,aAAaA,yBAAU,QACnC,OAAO;EAGT,IAAI,UAAU,aAAaA,yBAAU,MACnC,OAAO;EAGT,IAAI,UAAU,aAAaA,yBAAU,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"}
|
|
@@ -12,7 +12,7 @@ const getNodeChildren = (section) => {
|
|
|
12
12
|
const typedNode = section;
|
|
13
13
|
const content = typedNode[typedNode.nodeType];
|
|
14
14
|
if (typedNode.nodeType === _intlayer_types_nodeType.MARKDOWN || typedNode.nodeType === _intlayer_types_nodeType.HTML) return content;
|
|
15
|
-
if (typedNode.nodeType === _intlayer_types_nodeType.TRANSLATION || typedNode.nodeType === _intlayer_types_nodeType.ENUMERATION || typedNode.nodeType === _intlayer_types_nodeType.PLURAL || typedNode.nodeType === _intlayer_types_nodeType.CONDITION || typedNode.nodeType === _intlayer_types_nodeType.INSERTION || typedNode.nodeType === _intlayer_types_nodeType.GENDER || typedNode.nodeType === _intlayer_types_nodeType.FILE) return content[Object.keys(content)[0]];
|
|
15
|
+
if (typedNode.nodeType === _intlayer_types_nodeType.TRANSLATION || typedNode.nodeType === _intlayer_types_nodeType.ENUMERATION || typedNode.nodeType === _intlayer_types_nodeType.PLURAL || typedNode.nodeType === _intlayer_types_nodeType.CONDITION || typedNode.nodeType === _intlayer_types_nodeType.INSERTION || typedNode.nodeType === _intlayer_types_nodeType.GENDER || typedNode.nodeType === _intlayer_types_nodeType.SELECT || typedNode.nodeType === _intlayer_types_nodeType.FILE) return content[Object.keys(content)[0]];
|
|
16
16
|
if (typedNode.nodeType === _intlayer_types_nodeType.NESTED) return;
|
|
17
17
|
return content;
|
|
18
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNodeChildren.cjs","names":["NodeTypes"],"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,aAAaA,yBAAU,YACjC,UAAU,aAAaA,yBAAU,MAEjC,OAAO;EAGT,IACE,UAAU,aAAaA,yBAAU,eACjC,UAAU,aAAaA,yBAAU,eACjC,UAAU,aAAaA,yBAAU,UACjC,UAAU,aAAaA,yBAAU,aACjC,UAAU,aAAaA,yBAAU,aACjC,UAAU,aAAaA,yBAAU,UACjC,UAAU,aAAaA,yBAAU,MAGjC,OAAO,QADU,OAAO,KAAK,OAAO,CAAC,CAAC;EAIxC,IAAI,UAAU,aAAaA,yBAAU,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.cjs","names":["NodeTypes"],"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,aAAaA,yBAAU,YACjC,UAAU,aAAaA,yBAAU,MAEjC,OAAO;EAGT,IACE,UAAU,aAAaA,yBAAU,eACjC,UAAU,aAAaA,yBAAU,eACjC,UAAU,aAAaA,yBAAU,UACjC,UAAU,aAAaA,yBAAU,aACjC,UAAU,aAAaA,yBAAU,aACjC,UAAU,aAAaA,yBAAU,UACjC,UAAU,aAAaA,yBAAU,UACjC,UAAU,aAAaA,yBAAU,MAGjC,OAAO,QADU,OAAO,KAAK,OAAO,CAAC,CAAC;EAIxC,IAAI,UAAU,aAAaA,yBAAU,QACnC;EAGF,OAAO;CACT;CAEA,IAAI,CAAC,WAAW,OAAO,YAAY,UACjC,OAAO;CAGT,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAQ,QAA0B;CAGpC,OAAO;AACT"}
|
|
@@ -12,30 +12,38 @@ const isTypedNode = (content) => {
|
|
|
12
12
|
return typeof content === "object" && content !== null && "nodeType" in content && typeof content.nodeType === "string";
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Every known {@link NodeType}, as a lookup record.
|
|
16
|
+
*
|
|
17
|
+
* Typed as `Record<NodeType, true>` so that adding a node type to
|
|
18
|
+
* `@intlayer/types` without registering it here becomes a compile-time error.
|
|
16
19
|
*/
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
]
|
|
20
|
+
const validNodeTypes = {
|
|
21
|
+
[_intlayer_types_nodeType.TRANSLATION]: true,
|
|
22
|
+
[_intlayer_types_nodeType.ENUMERATION]: true,
|
|
23
|
+
[_intlayer_types_nodeType.PLURAL]: true,
|
|
24
|
+
[_intlayer_types_nodeType.CONDITION]: true,
|
|
25
|
+
[_intlayer_types_nodeType.INSERTION]: true,
|
|
26
|
+
[_intlayer_types_nodeType.FILE]: true,
|
|
27
|
+
[_intlayer_types_nodeType.OBJECT]: true,
|
|
28
|
+
[_intlayer_types_nodeType.ARRAY]: true,
|
|
29
|
+
[_intlayer_types_nodeType.NESTED]: true,
|
|
30
|
+
[_intlayer_types_nodeType.REACT_NODE]: true,
|
|
31
|
+
[_intlayer_types_nodeType.PREACT_NODE]: true,
|
|
32
|
+
[_intlayer_types_nodeType.SOLID_NODE]: true,
|
|
33
|
+
[_intlayer_types_nodeType.MARKDOWN]: true,
|
|
34
|
+
[_intlayer_types_nodeType.HTML]: true,
|
|
35
|
+
[_intlayer_types_nodeType.TEXT]: true,
|
|
36
|
+
[_intlayer_types_nodeType.NUMBER]: true,
|
|
37
|
+
[_intlayer_types_nodeType.BOOLEAN]: true,
|
|
38
|
+
[_intlayer_types_nodeType.GENDER]: true,
|
|
39
|
+
[_intlayer_types_nodeType.SELECT]: true,
|
|
40
|
+
[_intlayer_types_nodeType.NULL]: true,
|
|
41
|
+
[_intlayer_types_nodeType.UNKNOWN]: true
|
|
38
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Type guard to check if a raw string is a valid {@link NodeType}
|
|
45
|
+
*/
|
|
46
|
+
const isValidNodeType = (nodeType) => Object.hasOwn(validNodeTypes, nodeType);
|
|
39
47
|
const getNodeType = (content) => {
|
|
40
48
|
if (typeof content === "string") return _intlayer_types_nodeType.TEXT;
|
|
41
49
|
if (isTypedNode(content)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNodeType.cjs","names":["NodeTypes","isValidElement"],"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.cjs","names":["NodeTypes","isValidElement"],"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;EAC5CA,yBAAU,cAAc;EACxBA,yBAAU,cAAc;EACxBA,yBAAU,SAAS;EACnBA,yBAAU,YAAY;EACtBA,yBAAU,YAAY;EACtBA,yBAAU,OAAO;EACjBA,yBAAU,SAAS;EACnBA,yBAAU,QAAQ;EAClBA,yBAAU,SAAS;EACnBA,yBAAU,aAAa;EACvBA,yBAAU,cAAc;EACxBA,yBAAU,aAAa;EACvBA,yBAAU,WAAW;EACrBA,yBAAU,OAAO;EACjBA,yBAAU,OAAO;EACjBA,yBAAU,SAAS;EACnBA,yBAAU,UAAU;EACpBA,yBAAU,SAAS;EACnBA,yBAAU,SAAS;EACnBA,yBAAU,OAAO;EACjBA,yBAAU,UAAU;AACvB;;;;AAKA,MAAM,mBAAmB,aACvB,OAAO,OAAO,gBAAgB,QAAQ;AAExC,MAAa,eAAe,YAAmC;CAC7D,IAAI,OAAO,YAAY,UACrB,OAAOA,yBAAU;CAGnB,IAAI,YAAY,OAAO,GAAG;EACxB,MAAM,WAAW,QAAQ;EACzB,IAAI,gBAAgB,QAAQ,GAC1B,OAAO;EAGT,OAAOA,yBAAU;CACnB;CAEA,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAOA,yBAAU;CAGnB,IAAIC,iDAAe,OAAO,GACxB,OAAOD,yBAAU;CAGnB,IAAI,OAAO,YAAY,UACrB,OAAOA,yBAAU;CAGnB,IAAI,OAAO,YAAY,WACrB,OAAOA,yBAAU;CAGnB,IAAI,WAAW,OAAO,YAAY,UAChC,OAAOA,yBAAU;CAGnB,IAAI,YAAY,MACd,OAAOA,yBAAU;CAGnB,OAAOA,yBAAU;AACnB"}
|
|
@@ -15,6 +15,7 @@ const require_dictionaryManipulator_renameContentNodeByKeyPath = require('./rena
|
|
|
15
15
|
const require_dictionaryManipulator_updateNodeChildren = require('./updateNodeChildren.cjs');
|
|
16
16
|
|
|
17
17
|
exports.COMPOSITE_ID_SEPARATOR = require_dictionaryManipulator_qualifiedDictionary.COMPOSITE_ID_SEPARATOR;
|
|
18
|
+
exports.DEFAULT_VARIANT_ID = require_dictionaryManipulator_qualifiedDictionary.DEFAULT_VARIANT_ID;
|
|
18
19
|
exports.QUALIFIER_DYNAMIC_TYPES_KEY = require_dictionaryManipulator_qualifiedDictionary.QUALIFIER_DYNAMIC_TYPES_KEY;
|
|
19
20
|
exports.QUALIFIER_ORDER = require_dictionaryManipulator_qualifiedDictionary.QUALIFIER_ORDER;
|
|
20
21
|
exports.editDictionaryByKeyPath = require_dictionaryManipulator_editDictionaryByKeyPath.editDictionaryByKeyPath;
|
|
@@ -15,7 +15,10 @@ let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
|
15
15
|
* `variant → item`). Dictionaries are grouped by their composite id
|
|
16
16
|
* (one segment per dimension), merged within each group (locale completion /
|
|
17
17
|
* priority overrides preserved), and a `QualifiedDictionaryGroup` is returned.
|
|
18
|
-
* Unqualified siblings act as shared base content merged into every entry
|
|
18
|
+
* Unqualified siblings act as shared base content merged into every entry —
|
|
19
|
+
* and, on a variant-only key, also materialize the `default` entry when no
|
|
20
|
+
* declaration claims it. Every other variant entry then inherits from that
|
|
21
|
+
* `default` entry, so a variant only declares the fields it overrides.
|
|
19
22
|
*
|
|
20
23
|
* Every qualified entry must declare ALL dimensions of the group; an entry that
|
|
21
24
|
* declares only a subset is ambiguous and is rejected with an error log.
|
|
@@ -45,10 +48,30 @@ const mergeQualifiedDictionaries = (dictionaries) => {
|
|
|
45
48
|
entriesDictionaries.set(compositeId, existingEntries);
|
|
46
49
|
}
|
|
47
50
|
});
|
|
51
|
+
if (groupQualifierTypes.length === 1 && groupQualifierTypes[0] === "variant" && baseDictionaries.length > 0 && !entriesDictionaries.has("default")) entriesDictionaries.set(require_dictionaryManipulator_qualifiedDictionary.DEFAULT_VARIANT_ID, []);
|
|
48
52
|
const content = {};
|
|
49
53
|
let importMode;
|
|
54
|
+
const variantIndex = groupQualifierTypes.indexOf("variant");
|
|
55
|
+
/**
|
|
56
|
+
* The id of the entry a composite id inherits from — itself with its variant
|
|
57
|
+
* segment swapped for `default` (`'promo/2'` → `'default/2'`). `undefined`
|
|
58
|
+
* for the default entries themselves and for keys with no variant dimension.
|
|
59
|
+
*/
|
|
60
|
+
const getInheritedEntryId = (compositeId) => {
|
|
61
|
+
if (variantIndex === -1) return void 0;
|
|
62
|
+
const segments = compositeId.split("/");
|
|
63
|
+
if (segments[variantIndex] === "default") return void 0;
|
|
64
|
+
segments[variantIndex] = require_dictionaryManipulator_qualifiedDictionary.DEFAULT_VARIANT_ID;
|
|
65
|
+
return segments.join("/");
|
|
66
|
+
};
|
|
50
67
|
for (const [compositeId, qualifiedDictionaries] of entriesDictionaries) {
|
|
51
|
-
|
|
68
|
+
const inheritedEntryId = getInheritedEntryId(compositeId);
|
|
69
|
+
const inheritedDictionaries = inheritedEntryId ? entriesDictionaries.get(inheritedEntryId) ?? [] : [];
|
|
70
|
+
content[compositeId] = require_dictionaryManipulator_mergeDictionaries.mergeDictionaries([
|
|
71
|
+
...qualifiedDictionaries,
|
|
72
|
+
...inheritedDictionaries,
|
|
73
|
+
...baseDictionaries
|
|
74
|
+
]).content;
|
|
52
75
|
const [firstQualified] = qualifiedDictionaries;
|
|
53
76
|
importMode ??= firstQualified?.importMode;
|
|
54
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeQualifiedDictionaries.cjs","names":["getDictionaryQualifierTypes","QUALIFIER_ORDER","mergeDictionaries","getDictionaryCompositeIds"],"sources":["../../../src/dictionaryManipulator/mergeQualifiedDictionaries.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport type {\n Dictionary,\n DictionaryQualifierType,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport { mergeDictionaries } from './mergeDictionaries';\nimport {\n getDictionaryCompositeIds,\n getDictionaryQualifierTypes,\n QUALIFIER_ORDER,\n} from './qualifiedDictionary';\n\n/**\n * Merges sibling dictionaries sharing the same key, honouring qualifiers.\n *\n * - No dictionary declares a qualifier → behaves exactly like\n * `mergeDictionaries` (single merged dictionary).\n * - At least one dictionary declares a qualifier → the group's dimension set is\n * the union of every declared dimension (in canonical order\n * `variant → item`). Dictionaries are grouped by their composite id\n * (one segment per dimension), merged within each group (locale completion /\n * priority overrides preserved), and a `QualifiedDictionaryGroup` is returned.\n * Unqualified siblings act as shared base content merged into every entry.\n *\n * Every qualified entry must declare ALL dimensions of the group; an entry that\n * declares only a subset is ambiguous and is rejected with an error log.\n */\nexport const mergeQualifiedDictionaries = (\n dictionaries: Dictionary[]\n): Dictionary | QualifiedDictionaryGroup => {\n const perDictionaryTypes = dictionaries.map(getDictionaryQualifierTypes);\n\n const declaredDimensions = new Set<DictionaryQualifierType>();\n for (const types of perDictionaryTypes) {\n for (const type of types) declaredDimensions.add(type);\n }\n\n // Canonical order, restricted to the dimensions actually declared.\n const groupQualifierTypes = QUALIFIER_ORDER.filter((qualifierType) =>\n declaredDimensions.has(qualifierType)\n );\n\n if (groupQualifierTypes.length === 0) {\n return mergeDictionaries(dictionaries);\n }\n\n const appLogger = getAppLogger({ log });\n\n const baseDictionaries: Dictionary[] = [];\n const entriesDictionaries = new Map<string, Dictionary[]>();\n\n dictionaries.forEach((dictionary, index) => {\n if (perDictionaryTypes[index]?.length === 0) {\n baseDictionaries.push(dictionary);\n return;\n }\n\n // A dictionary may map to several composite ids (array variant fan-out):\n // its content is registered under every id it lists.\n const compositeIds = getDictionaryCompositeIds(\n dictionary,\n groupQualifierTypes\n );\n\n if (compositeIds === undefined) {\n appLogger(\n `Dictionary ${colorizeKey(dictionary.key)} declares (${perDictionaryTypes[index].join(', ')}) but the key's dimensions are (${groupQualifierTypes.join(', ')}); every entry must declare all of them. Entry ignored${dictionary.filePath ? ` - ${dictionary.filePath}` : ''}.`,\n { level: 'error' }\n );\n return;\n }\n\n for (const compositeId of compositeIds) {\n const existingEntries = entriesDictionaries.get(compositeId) ?? [];\n existingEntries.push(dictionary);\n entriesDictionaries.set(compositeId, existingEntries);\n }\n });\n\n // `content` maps each composite id to its resolved content node directly; the\n // qualifier coordinates live in the key, not in a per-entry wrapper. For an\n // object variant the variant segment is the canonical serialization of the\n // object, so it fully identifies the entry — no side-map is needed.\n const content: Record<string, unknown> = {};\n\n let importMode: Dictionary['importMode'];\n\n for (const [compositeId, qualifiedDictionaries] of entriesDictionaries) {\n //
|
|
1
|
+
{"version":3,"file":"mergeQualifiedDictionaries.cjs","names":["getDictionaryQualifierTypes","QUALIFIER_ORDER","mergeDictionaries","getDictionaryCompositeIds","DEFAULT_VARIANT_ID"],"sources":["../../../src/dictionaryManipulator/mergeQualifiedDictionaries.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport type {\n Dictionary,\n DictionaryQualifierType,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport { mergeDictionaries } from './mergeDictionaries';\nimport {\n COMPOSITE_ID_SEPARATOR,\n DEFAULT_VARIANT_ID,\n getDictionaryCompositeIds,\n getDictionaryQualifierTypes,\n QUALIFIER_ORDER,\n} from './qualifiedDictionary';\n\n/**\n * Merges sibling dictionaries sharing the same key, honouring qualifiers.\n *\n * - No dictionary declares a qualifier → behaves exactly like\n * `mergeDictionaries` (single merged dictionary).\n * - At least one dictionary declares a qualifier → the group's dimension set is\n * the union of every declared dimension (in canonical order\n * `variant → item`). Dictionaries are grouped by their composite id\n * (one segment per dimension), merged within each group (locale completion /\n * priority overrides preserved), and a `QualifiedDictionaryGroup` is returned.\n * Unqualified siblings act as shared base content merged into every entry —\n * and, on a variant-only key, also materialize the `default` entry when no\n * declaration claims it. Every other variant entry then inherits from that\n * `default` entry, so a variant only declares the fields it overrides.\n *\n * Every qualified entry must declare ALL dimensions of the group; an entry that\n * declares only a subset is ambiguous and is rejected with an error log.\n */\nexport const mergeQualifiedDictionaries = (\n dictionaries: Dictionary[]\n): Dictionary | QualifiedDictionaryGroup => {\n const perDictionaryTypes = dictionaries.map(getDictionaryQualifierTypes);\n\n const declaredDimensions = new Set<DictionaryQualifierType>();\n for (const types of perDictionaryTypes) {\n for (const type of types) declaredDimensions.add(type);\n }\n\n // Canonical order, restricted to the dimensions actually declared.\n const groupQualifierTypes = QUALIFIER_ORDER.filter((qualifierType) =>\n declaredDimensions.has(qualifierType)\n );\n\n if (groupQualifierTypes.length === 0) {\n return mergeDictionaries(dictionaries);\n }\n\n const appLogger = getAppLogger({ log });\n\n const baseDictionaries: Dictionary[] = [];\n const entriesDictionaries = new Map<string, Dictionary[]>();\n\n dictionaries.forEach((dictionary, index) => {\n if (perDictionaryTypes[index]?.length === 0) {\n baseDictionaries.push(dictionary);\n return;\n }\n\n // A dictionary may map to several composite ids (array variant fan-out):\n // its content is registered under every id it lists.\n const compositeIds = getDictionaryCompositeIds(\n dictionary,\n groupQualifierTypes\n );\n\n if (compositeIds === undefined) {\n appLogger(\n `Dictionary ${colorizeKey(dictionary.key)} declares (${perDictionaryTypes[index].join(', ')}) but the key's dimensions are (${groupQualifierTypes.join(', ')}); every entry must declare all of them. Entry ignored${dictionary.filePath ? ` - ${dictionary.filePath}` : ''}.`,\n { level: 'error' }\n );\n return;\n }\n\n for (const compositeId of compositeIds) {\n const existingEntries = entriesDictionaries.get(compositeId) ?? [];\n existingEntries.push(dictionary);\n entriesDictionaries.set(compositeId, existingEntries);\n }\n });\n\n // Unqualified siblings are the key's base content. On a variant key they also\n // materialize the `default` entry when no declaration claims it, so the key\n // still resolves when no variant is selected — and so variants that declare\n // no entry of their own can fall back to it. Registering an empty entry list\n // is enough: the merge loop below appends the base dictionaries to it.\n //\n // Composite (variant × item) keys are excluded: base content carries no item\n // index, so it cannot be placed on the collection axis.\n const isVariantOnlyGroup =\n groupQualifierTypes.length === 1 && groupQualifierTypes[0] === 'variant';\n\n if (\n isVariantOnlyGroup &&\n baseDictionaries.length > 0 &&\n !entriesDictionaries.has(DEFAULT_VARIANT_ID)\n ) {\n entriesDictionaries.set(DEFAULT_VARIANT_ID, []);\n }\n\n // `content` maps each composite id to its resolved content node directly; the\n // qualifier coordinates live in the key, not in a per-entry wrapper. For an\n // object variant the variant segment is the canonical serialization of the\n // object, so it fully identifies the entry — no side-map is needed.\n const content: Record<string, unknown> = {};\n\n let importMode: Dictionary['importMode'];\n\n const variantIndex = groupQualifierTypes.indexOf('variant');\n\n /**\n * The id of the entry a composite id inherits from — itself with its variant\n * segment swapped for `default` (`'promo/2'` → `'default/2'`). `undefined`\n * for the default entries themselves and for keys with no variant dimension.\n */\n const getInheritedEntryId = (compositeId: string): string | undefined => {\n if (variantIndex === -1) return undefined;\n\n const segments = compositeId.split(COMPOSITE_ID_SEPARATOR);\n if (segments[variantIndex] === DEFAULT_VARIANT_ID) return undefined;\n\n segments[variantIndex] = DEFAULT_VARIANT_ID;\n return segments.join(COMPOSITE_ID_SEPARATOR);\n };\n\n for (const [compositeId, qualifiedDictionaries] of entriesDictionaries) {\n // Precedence, highest first: the entry's own declarations, then the\n // `default` variant it inherits from, then the unqualified siblings shared\n // by the whole key (mergeDictionaries prefers the first occurrence).\n //\n // Inheriting from `default` is what makes a variant declaration partial: it\n // only has to declare the fields whose wording actually differs, and every\n // other field is completed from the default entry.\n const inheritedEntryId = getInheritedEntryId(compositeId);\n const inheritedDictionaries = inheritedEntryId\n ? (entriesDictionaries.get(inheritedEntryId) ?? [])\n : [];\n\n const mergedEntry = mergeDictionaries([\n ...qualifiedDictionaries,\n ...inheritedDictionaries,\n ...baseDictionaries,\n ]);\n\n content[compositeId] = mergedEntry.content;\n\n const [firstQualified] = qualifiedDictionaries;\n\n importMode ??= firstQualified?.importMode;\n }\n\n const localIds = Array.from(\n new Set(\n dictionaries\n .filter((dictionary) => dictionary.localId)\n .map((dictionary) => dictionary.localId!)\n )\n );\n\n return {\n key: dictionaries[0]!.key,\n qualifierTypes: groupQualifierTypes,\n content,\n ...(importMode !== undefined && { importMode }),\n localIds,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,8BACX,iBAC0C;CAC1C,MAAM,qBAAqB,aAAa,IAAIA,6EAA2B;CAEvE,MAAM,qCAAqB,IAAI,IAA6B;CAC5D,KAAK,MAAM,SAAS,oBAClB,KAAK,MAAM,QAAQ,OAAO,mBAAmB,IAAI,IAAI;CAIvD,MAAM,sBAAsBC,kEAAgB,QAAQ,kBAClD,mBAAmB,IAAI,aAAa,CACtC;CAEA,IAAI,oBAAoB,WAAW,GACjC,OAAOC,kEAAkB,YAAY;CAGvC,MAAM,sDAAyB,EAAE,gCAAI,CAAC;CAEtC,MAAM,mBAAiC,CAAC;CACxC,MAAM,sCAAsB,IAAI,IAA0B;CAE1D,aAAa,SAAS,YAAY,UAAU;EAC1C,IAAI,mBAAmB,MAAM,EAAE,WAAW,GAAG;GAC3C,iBAAiB,KAAK,UAAU;GAChC;EACF;EAIA,MAAM,eAAeC,4EACnB,YACA,mBACF;EAEA,IAAI,iBAAiB,QAAW;GAC9B,UACE,uDAA0B,WAAW,GAAG,EAAE,aAAa,mBAAmB,MAAM,CAAC,KAAK,IAAI,EAAE,kCAAkC,oBAAoB,KAAK,IAAI,EAAE,wDAAwD,WAAW,WAAW,MAAM,WAAW,aAAa,GAAG,IAC5Q,EAAE,OAAO,QAAQ,CACnB;GACA;EACF;EAEA,KAAK,MAAM,eAAe,cAAc;GACtC,MAAM,kBAAkB,oBAAoB,IAAI,WAAW,KAAK,CAAC;GACjE,gBAAgB,KAAK,UAAU;GAC/B,oBAAoB,IAAI,aAAa,eAAe;EACtD;CACF,CAAC;CAaD,IAFE,oBAAoB,WAAW,KAAK,oBAAoB,OAAO,aAI/D,iBAAiB,SAAS,KAC1B,CAAC,oBAAoB,aAAsB,GAE3C,oBAAoB,IAAIC,sEAAoB,CAAC,CAAC;CAOhD,MAAM,UAAmC,CAAC;CAE1C,IAAI;CAEJ,MAAM,eAAe,oBAAoB,QAAQ,SAAS;;;;;;CAO1D,MAAM,uBAAuB,gBAA4C;EACvE,IAAI,iBAAiB,IAAI,OAAO;EAEhC,MAAM,WAAW,YAAY,SAA4B;EACzD,IAAI,SAAS,6BAAsC,OAAO;EAE1D,SAAS,gBAAgBA;EACzB,OAAO,SAAS,QAA2B;CAC7C;CAEA,KAAK,MAAM,CAAC,aAAa,0BAA0B,qBAAqB;EAQtE,MAAM,mBAAmB,oBAAoB,WAAW;EACxD,MAAM,wBAAwB,mBACzB,oBAAoB,IAAI,gBAAgB,KAAK,CAAC,IAC/C,CAAC;EAQL,QAAQ,eANYF,kEAAkB;GACpC,GAAG;GACH,GAAG;GACH,GAAG;EACL,CAEiC,CAAC,CAAC;EAEnC,MAAM,CAAC,kBAAkB;EAEzB,eAAe,gBAAgB;CACjC;CAEA,MAAM,WAAW,MAAM,KACrB,IAAI,IACF,aACG,QAAQ,eAAe,WAAW,OAAO,CAAC,CAC1C,KAAK,eAAe,WAAW,OAAQ,CAC5C,CACF;CAEA,OAAO;EACL,KAAK,aAAa,EAAE,CAAE;EACtB,gBAAgB;EAChB;EACA,GAAI,eAAe,UAAa,EAAE,WAAW;EAC7C;CACF;AACF"}
|
|
@@ -13,6 +13,12 @@ const QUALIFIER_ORDER = ["variant", "item"];
|
|
|
13
13
|
*/
|
|
14
14
|
const COMPOSITE_ID_SEPARATOR = "/";
|
|
15
15
|
/**
|
|
16
|
+
* Identity of the implicit fallback variant. A selector that pins no variant
|
|
17
|
+
* resolves to it, and a variant that declares no entry of its own falls back to
|
|
18
|
+
* it — so a key only has to ship the entries that actually differ.
|
|
19
|
+
*/
|
|
20
|
+
const DEFAULT_VARIANT_ID = "default";
|
|
21
|
+
/**
|
|
16
22
|
* Characters kept verbatim in an encoded qualifier segment. Everything else is
|
|
17
23
|
* percent-encoded so a segment can never contain the composite-id separator
|
|
18
24
|
* (`/`), path-hostile characters (`\` `:` `*` `?` `"` `<` `>` `|`, control
|
|
@@ -51,7 +57,7 @@ const encodeSegmentText = (raw, unsafeChars) => {
|
|
|
51
57
|
* an object variant in a selector must equal the one declared on the dictionary.
|
|
52
58
|
*/
|
|
53
59
|
const serializeVariant = (variant) => {
|
|
54
|
-
if (variant === void 0) return
|
|
60
|
+
if (variant === void 0) return DEFAULT_VARIANT_ID;
|
|
55
61
|
if (typeof variant === "string") return encodeSegmentText(variant, SEGMENT_UNSAFE_CHARS);
|
|
56
62
|
return Object.keys(variant).sort().map((field) => `${encodeSegmentText(field, COMPONENT_UNSAFE_CHARS)}=${encodeSegmentText(String(variant[field]), COMPONENT_UNSAFE_CHARS)}`).join("&");
|
|
57
63
|
};
|
|
@@ -107,16 +113,33 @@ const getDictionaryCompositeIds = (dictionary, qualifierTypes) => {
|
|
|
107
113
|
return compositeIds;
|
|
108
114
|
};
|
|
109
115
|
/**
|
|
116
|
+
* Resolves the variant id a selector actually targets among the ids a key
|
|
117
|
+
* declares — the sparse-override fallback.
|
|
118
|
+
*
|
|
119
|
+
* The requested id wins when the key declares it. Otherwise the key falls back
|
|
120
|
+
* to its `default` entry, so a variant only has to be declared where its
|
|
121
|
+
* wording differs. When the key declares no `default` either, the requested id
|
|
122
|
+
* is returned unchanged and the caller resolves to `null` / `[]`.
|
|
123
|
+
*
|
|
124
|
+
* @param requestedVariantId - The serialized variant id the selector asks for.
|
|
125
|
+
* @param isVariantIdDeclared - Whether the key declares an entry for an id.
|
|
126
|
+
*/
|
|
127
|
+
const resolveEffectiveVariantId = (requestedVariantId, isVariantIdDeclared) => {
|
|
128
|
+
if (isVariantIdDeclared(requestedVariantId)) return requestedVariantId;
|
|
129
|
+
return isVariantIdDeclared("default") ? DEFAULT_VARIANT_ID : requestedVariantId;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
110
132
|
* Tests whether a composite entry id matches a selector across every declared
|
|
111
133
|
* dimension. Segments are compared in their encoded form (both the stored id
|
|
112
134
|
* and the selector go through {@link serializeVariant}). The `item` dimension
|
|
113
135
|
* matches any value when the selector does not provide one (open collection
|
|
114
|
-
* axis)
|
|
136
|
+
* axis); the `variant` dimension is compared against the already-resolved
|
|
137
|
+
* effective id, so the fallback is applied consistently across dimensions.
|
|
115
138
|
*/
|
|
116
|
-
const compositeIdMatchesSelector = (compositeId, qualifierTypes, selector) => {
|
|
139
|
+
const compositeIdMatchesSelector = (compositeId, qualifierTypes, selector, effectiveVariantId) => {
|
|
117
140
|
const segments = compositeId.split("/");
|
|
118
141
|
return qualifierTypes.every((qualifierType, index) => {
|
|
119
|
-
if (qualifierType === "variant") return segments[index] ===
|
|
142
|
+
if (qualifierType === "variant") return segments[index] === effectiveVariantId;
|
|
120
143
|
return selector?.item === void 0 || segments[index] === String(selector.item);
|
|
121
144
|
});
|
|
122
145
|
};
|
|
@@ -156,8 +179,10 @@ const reconstructQualifiedEntry = (group, compositeId) => {
|
|
|
156
179
|
* - Plain dictionary → returned as-is (selector ignored)
|
|
157
180
|
* - `item` declared but not selected → every matching entry ordered by index
|
|
158
181
|
* - `item` selected → the matching entry or null
|
|
159
|
-
* - `variant` defaults to the `default` entry when not selected
|
|
160
|
-
*
|
|
182
|
+
* - `variant` defaults to the `default` entry when not selected, and falls back
|
|
183
|
+
* to it when the selected variant declares no entry of its own; an object
|
|
184
|
+
* variant resolves only when the selector provides an equal object (or, again,
|
|
185
|
+
* through the `default` fallback)
|
|
161
186
|
*
|
|
162
187
|
* Dimensions compose: e.g. a variant × item key with `{ variant: 'promo' }`
|
|
163
188
|
* returns every promo item as an array; adding `{ item: 2 }` narrows to one.
|
|
@@ -166,7 +191,10 @@ const resolveQualifiedDictionary = (dictionaryOrGroup, selector) => {
|
|
|
166
191
|
if (!isQualifiedDictionaryGroup(dictionaryOrGroup)) return dictionaryOrGroup;
|
|
167
192
|
const { qualifierTypes, content } = dictionaryOrGroup;
|
|
168
193
|
const itemAxisOpen = qualifierTypes.includes("item") && selector?.item === void 0;
|
|
169
|
-
const
|
|
194
|
+
const compositeIds = Object.keys(content);
|
|
195
|
+
const variantIndex = qualifierTypes.indexOf("variant");
|
|
196
|
+
const effectiveVariantId = variantIndex === -1 ? DEFAULT_VARIANT_ID : resolveEffectiveVariantId(serializeVariant(selector?.variant), (variantId) => compositeIds.some((compositeId) => compositeId.split("/")[variantIndex] === variantId));
|
|
197
|
+
const matchedEntries = compositeIds.filter((compositeId) => compositeIdMatchesSelector(compositeId, qualifierTypes, selector, effectiveVariantId)).map((compositeId) => reconstructQualifiedEntry(dictionaryOrGroup, compositeId));
|
|
170
198
|
if (itemAxisOpen) return matchedEntries.sort((left, right) => (left.item ?? 0) - (right.item ?? 0));
|
|
171
199
|
return matchedEntries[0] ?? null;
|
|
172
200
|
};
|
|
@@ -233,7 +261,7 @@ const collectQualifiedChunks = (loaderMap, key, locale, selector) => {
|
|
|
233
261
|
for (const segment of Object.keys(tree).sort((left, right) => Number(left) - Number(right))) walk(tree[segment], rest, [...segments, segment]);
|
|
234
262
|
return true;
|
|
235
263
|
}
|
|
236
|
-
const segment = dimension === "variant" ? serializeVariant(selector?.variant) : String(selector?.item);
|
|
264
|
+
const segment = dimension === "variant" ? resolveEffectiveVariantId(serializeVariant(selector?.variant), (variantId) => tree[variantId] !== void 0) : String(selector?.item);
|
|
237
265
|
const child = tree[segment];
|
|
238
266
|
if (!child) return false;
|
|
239
267
|
return walk(child, rest, [...segments, segment]);
|
|
@@ -249,11 +277,11 @@ const collectQualifiedChunks = (loaderMap, key, locale, selector) => {
|
|
|
249
277
|
* loading only the chunk(s) the selector actually targets.
|
|
250
278
|
*
|
|
251
279
|
* Walks the nested loader tree one dimension at a time (canonical order
|
|
252
|
-
* `variant → item`): `variant`
|
|
253
|
-
*
|
|
254
|
-
* or — when no item is given — expands
|
|
255
|
-
* axis). Semantics mirror
|
|
256
|
-
* static modes behave alike.
|
|
280
|
+
* `variant → item`): `variant` descends by the serialized id, falling back to
|
|
281
|
+
* `default` when the selected variant has no chunk of its own, and `item`
|
|
282
|
+
* either narrows to the selected index or — when no item is given — expands
|
|
283
|
+
* into every sibling chunk (the collection axis). Semantics mirror
|
|
284
|
+
* {@link resolveQualifiedDictionary} so dynamic and static modes behave alike.
|
|
257
285
|
*
|
|
258
286
|
* The Suspense mechanism is injected through `loadChunk` so the same logic
|
|
259
287
|
* serves both the client (suspender cache) and the server (`react.use`). Every
|
|
@@ -299,6 +327,7 @@ const resolveQualifiedDynamicContentAsync = async (params) => {
|
|
|
299
327
|
|
|
300
328
|
//#endregion
|
|
301
329
|
exports.COMPOSITE_ID_SEPARATOR = COMPOSITE_ID_SEPARATOR;
|
|
330
|
+
exports.DEFAULT_VARIANT_ID = DEFAULT_VARIANT_ID;
|
|
302
331
|
exports.QUALIFIER_DYNAMIC_TYPES_KEY = QUALIFIER_DYNAMIC_TYPES_KEY;
|
|
303
332
|
exports.QUALIFIER_ORDER = QUALIFIER_ORDER;
|
|
304
333
|
exports.getDictionaryCompositeIds = getDictionaryCompositeIds;
|