@intlayer/core 5.3.2 → 5.3.4

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.
Files changed (83) hide show
  1. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +26 -41
  2. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
  3. package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +4 -8
  4. package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
  5. package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +12 -0
  6. package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
  7. package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs +5 -2
  8. package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
  9. package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs +8 -15
  10. package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
  11. package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs +8 -15
  12. package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
  13. package/dist/cjs/interpreter/getContent/getContent.cjs +1 -1
  14. package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
  15. package/dist/cjs/interpreter/getContent/plugins.cjs +10 -0
  16. package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
  17. package/dist/cjs/interpreter/getInsertion.cjs +1 -1
  18. package/dist/cjs/interpreter/getInsertion.cjs.map +1 -1
  19. package/dist/cjs/transpiler/file/file.cjs +5 -2
  20. package/dist/cjs/transpiler/file/file.cjs.map +1 -1
  21. package/dist/cjs/transpiler/file/fileBrowser.cjs +36 -0
  22. package/dist/cjs/transpiler/file/fileBrowser.cjs.map +1 -0
  23. package/dist/cjs/transpiler/index.cjs.map +1 -1
  24. package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -1
  25. package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
  26. package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
  27. package/dist/cjs/types/dictionary.cjs.map +1 -1
  28. package/dist/cjs/types/keyPath.cjs.map +1 -1
  29. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +26 -41
  30. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
  31. package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs +4 -8
  32. package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
  33. package/dist/esm/dictionaryManipulator/getDefaultNode.mjs +12 -0
  34. package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -1
  35. package/dist/esm/dictionaryManipulator/getEmptyNode.mjs +5 -2
  36. package/dist/esm/dictionaryManipulator/getEmptyNode.mjs.map +1 -1
  37. package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs +8 -15
  38. package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs.map +1 -1
  39. package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs +8 -15
  40. package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs.map +1 -1
  41. package/dist/esm/interpreter/getContent/getContent.mjs +3 -2
  42. package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
  43. package/dist/esm/interpreter/getContent/plugins.mjs +9 -0
  44. package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
  45. package/dist/esm/interpreter/getInsertion.mjs +1 -1
  46. package/dist/esm/interpreter/getInsertion.mjs.map +1 -1
  47. package/dist/esm/transpiler/file/file.mjs +1 -2
  48. package/dist/esm/transpiler/file/file.mjs.map +1 -1
  49. package/dist/esm/transpiler/file/fileBrowser.mjs +12 -0
  50. package/dist/esm/transpiler/file/fileBrowser.mjs.map +1 -0
  51. package/dist/esm/transpiler/index.mjs.map +1 -1
  52. package/dist/esm/transpiler/insertion/insertion.mjs.map +1 -1
  53. package/dist/esm/transpiler/markdown/markdown.mjs.map +1 -1
  54. package/dist/esm/transpiler/translation/translation.mjs +4 -1
  55. package/dist/esm/transpiler/translation/translation.mjs.map +1 -1
  56. package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts.map +1 -1
  57. package/dist/types/dictionaryManipulator/getContentNodeByKeyPath.d.ts.map +1 -1
  58. package/dist/types/dictionaryManipulator/getDefaultNode.d.ts +2 -2
  59. package/dist/types/dictionaryManipulator/getDefaultNode.d.ts.map +1 -1
  60. package/dist/types/dictionaryManipulator/getEmptyNode.d.ts.map +1 -1
  61. package/dist/types/dictionaryManipulator/removeContentNodeByKeyPath.d.ts.map +1 -1
  62. package/dist/types/dictionaryManipulator/renameContentNodeByKeyPath.d.ts.map +1 -1
  63. package/dist/types/interpreter/getContent/plugins.d.ts +8 -1
  64. package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
  65. package/dist/types/interpreter/getInsertion.d.ts +1 -1
  66. package/dist/types/interpreter/getInsertion.d.ts.map +1 -1
  67. package/dist/types/transpiler/file/file.d.ts +3 -3
  68. package/dist/types/transpiler/file/file.d.ts.map +1 -1
  69. package/dist/types/transpiler/file/fileBrowser.d.ts +18 -0
  70. package/dist/types/transpiler/file/fileBrowser.d.ts.map +1 -0
  71. package/dist/types/transpiler/index.d.ts +1 -0
  72. package/dist/types/transpiler/index.d.ts.map +1 -1
  73. package/dist/types/transpiler/insertion/insertion.d.ts +2 -1
  74. package/dist/types/transpiler/insertion/insertion.d.ts.map +1 -1
  75. package/dist/types/transpiler/markdown/markdown.d.ts +4 -2
  76. package/dist/types/transpiler/markdown/markdown.d.ts.map +1 -1
  77. package/dist/types/transpiler/translation/translation.d.ts +1 -2
  78. package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
  79. package/dist/types/types/dictionary.d.ts +1 -1
  80. package/dist/types/types/dictionary.d.ts.map +1 -1
  81. package/dist/types/types/keyPath.d.ts +1 -1
  82. package/dist/types/types/keyPath.d.ts.map +1 -1
  83. package/package.json +19 -8
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/translation/translation.ts"],"sourcesContent":["import type { LanguageContent } from 'intlayer';\nimport { formatNodeType, NodeType, TypedNodeModel } from '../../types/index';\n\nexport type TranslationContent<\n Content = unknown,\n RecordContent extends LanguageContent<Content> = LanguageContent<Content>,\n> = TypedNodeModel<NodeType.Translation, RecordContent>;\n\n/**\n *\n * Function intended to be used to build intlayer dictionaries.\n *\n * Get the content of a translation based on the locale.\n *\n * Usage:\n *\n * ```ts\n * translation<string>({\n * \"en\": \"Hello\",\n * \"fr\": \"Bonjour\",\n * // ... any other available locale\n * })\n * ```\n *\n * Using TypeScript:\n * - this function require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nconst translation = <\n Content = unknown,\n ContentRecord extends LanguageContent<Content> = LanguageContent<Content>,\n>(\n content: ContentRecord\n) =>\n formatNodeType(NodeType.Translation, content) satisfies TranslationContent<\n Content,\n ContentRecord\n >;\n\nexport { translation as t };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAyD;AA2BzD,MAAM,cAAc,CAIlB,gBAEA,6BAAe,sBAAS,aAAa,OAAO;","names":[]}
1
+ {"version":3,"sources":["../../../../src/transpiler/translation/translation.ts"],"sourcesContent":["import {\n formatNodeType,\n NodeType,\n type LanguageContent,\n type TypedNodeModel,\n} from '../../types/index';\n\nexport type TranslationContent<\n Content = unknown,\n RecordContent extends LanguageContent<Content> = LanguageContent<Content>,\n> = TypedNodeModel<NodeType.Translation, RecordContent>;\n\n/**\n *\n * Function intended to be used to build intlayer dictionaries.\n *\n * Get the content of a translation based on the locale.\n *\n * Usage:\n *\n * ```ts\n * translation<string>({\n * \"en\": \"Hello\",\n * \"fr\": \"Bonjour\",\n * // ... any other available locale\n * })\n * ```\n *\n * Using TypeScript:\n * - this function require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nconst translation = <\n Content = unknown,\n ContentRecord extends LanguageContent<Content> = LanguageContent<Content>,\n>(\n content: ContentRecord\n) =>\n formatNodeType(NodeType.Translation, content) satisfies TranslationContent<\n Content,\n ContentRecord\n >;\n\nexport { translation as t };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAKO;AA2BP,MAAM,cAAc,CAIlB,gBAEA,6BAAe,sBAAS,aAAa,OAAO;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/dictionary.ts"],"sourcesContent":["// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { ConditionContent } from '../transpiler/condition';\nimport type { EnumerationContent } from '../transpiler/enumeration';\nimport type { FileContent } from '../transpiler/file';\nimport type { InsertionContent } from '../transpiler/insertion';\nimport type { MarkdownContent } from '../transpiler/markdown';\nimport type { NestedContent } from '../transpiler/nesting';\nimport type { TranslationContent } from '../transpiler/translation';\n\n/**\n * Provides a fallback to string type if the generic type T is undefined,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<undefined> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends undefined ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\ntype BaseNode = number | string | boolean | null | undefined;\n\nexport type TypedNode<NodeType = undefined> =\n | TranslationContent<NodeType>\n | EnumerationContent<NodeType>\n | ConditionContent<NodeType>\n | InsertionContent<NodeType>\n | MarkdownContent\n | NestedContent<DictionaryKeys>\n | FileContent;\n\ntype FetchableContentNode<NodeType> = (\n args?: any\n) => ContentNode<NodeType> | Promise<ContentNode<NodeType>>;\n\nexport type ContentNode<\n T = undefined,\n FetchableNode = false,\n NodeType = T extends undefined ? BaseNode : T,\n> =\n | NodeType\n | TypedNode<NodeType>\n | ((args?: any) => ContentNode<NodeType>)\n | (FetchableNode extends true ? FetchableContentNode<NodeType> : undefined);\n\n// Utility types (unchanged)\ntype IsArray<T> = T extends any[] ? true : false;\n\ntype ReplaceContentValueArray<T, FetchableNode> = T extends (infer U)[]\n ? // Allow either a *single* typed node returning the entire array\n // or an array of typed nodes (or scalar nodes).\n ContentNode<T, FetchableNode> | ReplaceContentValue<U, FetchableNode>[]\n : never;\n\ntype ReplaceContentValueObject<T, FetchableNode> = {\n [K in keyof T]: ReplaceContentValue<T[K], FetchableNode>;\n};\n\n// Modified: allow a full ContentNode wrapper OR an object shape when T is an object\ntype ReplaceContentValue<\n NodeType,\n FetchableNode = true,\n> = NodeType extends object\n ? IsArray<NodeType> extends true\n ? ReplaceContentValueArray<NodeType, FetchableNode>\n :\n | ContentNode<NodeType, FetchableNode>\n | ReplaceContentValueObject<NodeType, FetchableNode>\n : ContentNode<NodeType, FetchableNode>;\n\nexport type Dictionary<ContentType = undefined, FetchableNode = false> = {\n $schema?: string;\n key: string;\n title?: string;\n description?: string;\n availableVersions?: string[];\n version?: string;\n filePath?: string;\n tags?: string[];\n content: ContentType extends undefined // Applying the generic to replace ContentValue with Replacement\n ? any\n : ReplaceContentValue<ContentType, FetchableNode> | ContentType;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/types/dictionary.ts"],"sourcesContent":["// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { ConditionContent } from '../transpiler/condition';\nimport type { EnumerationContent } from '../transpiler/enumeration';\nimport type { FileContent } from '../transpiler/file';\nimport type { InsertionContent } from '../transpiler/insertion';\nimport type { MarkdownContent } from '../transpiler/markdown';\nimport type { NestedContent } from '../transpiler/nesting';\nimport type { TranslationContent } from '../transpiler/translation';\n\n/**\n * Provides a fallback to string type if the generic type T is undefined,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<undefined> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends undefined ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\ntype BaseNode = number | string | boolean | null | undefined;\n\nexport type TypedNode<NodeType = undefined> =\n | TranslationContent<NodeType>\n | EnumerationContent<NodeType>\n | ConditionContent<NodeType>\n | InsertionContent<NodeType>\n | MarkdownContent<NodeType>\n | NestedContent<DictionaryKeys>\n | FileContent;\n\ntype FetchableContentNode<NodeType> = (\n args?: any\n) => ContentNode<NodeType> | Promise<ContentNode<NodeType>>;\n\nexport type ContentNode<\n T = undefined,\n FetchableNode = false,\n NodeType = T extends undefined ? BaseNode : T,\n> =\n | NodeType\n | TypedNode<NodeType>\n | ((args?: any) => ContentNode<NodeType>)\n | (FetchableNode extends true ? FetchableContentNode<NodeType> : undefined);\n\n// Utility types (unchanged)\ntype IsArray<T> = T extends any[] ? true : false;\n\ntype ReplaceContentValueArray<T, FetchableNode> = T extends (infer U)[]\n ? // Allow either a *single* typed node returning the entire array\n // or an array of typed nodes (or scalar nodes).\n ContentNode<T, FetchableNode> | ReplaceContentValue<U, FetchableNode>[]\n : never;\n\ntype ReplaceContentValueObject<T, FetchableNode> = {\n [K in keyof T]: ReplaceContentValue<T[K], FetchableNode>;\n};\n\n// Modified: allow a full ContentNode wrapper OR an object shape when T is an object\ntype ReplaceContentValue<\n NodeType,\n FetchableNode = true,\n> = NodeType extends object\n ? IsArray<NodeType> extends true\n ? ReplaceContentValueArray<NodeType, FetchableNode>\n :\n | ContentNode<NodeType, FetchableNode>\n | ReplaceContentValueObject<NodeType, FetchableNode>\n : ContentNode<NodeType, FetchableNode>;\n\nexport type Dictionary<ContentType = undefined, FetchableNode = false> = {\n $schema?: string;\n key: string;\n title?: string;\n description?: string;\n availableVersions?: string[];\n version?: string;\n filePath?: string;\n tags?: string[];\n content: ContentType extends undefined // Applying the generic to replace ContentValue with Replacement\n ? any\n : ReplaceContentValue<ContentType, FetchableNode> | ContentType;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/keyPath.ts"],"sourcesContent":["import type { NodeType } from './nodeType';\n\nexport type ObjectNode = {\n type: NodeType.Object;\n key: string;\n};\n\nexport type ArrayNode = {\n type: NodeType.Array;\n key: number;\n};\n\nexport type EnumerationNode = {\n type: NodeType.Enumeration;\n key: string;\n};\n\nexport type TranslationNode = {\n type: NodeType.Translation;\n key: string;\n};\n\nexport type ConditionNode = {\n type: NodeType.Condition;\n key: string;\n};\n\nexport type InsertionNode = {\n type: NodeType.Insertion;\n key?: undefined;\n};\n\nexport type MarkdownNode = {\n type: NodeType.Markdown;\n key?: undefined;\n};\n\nexport type ReactNode = {\n type: NodeType.ReactNode;\n key?: undefined;\n};\n\nexport type NestedNode = {\n type: NodeType.Nested;\n key?: undefined;\n};\n\nexport type FileNode = {\n type: NodeType.File;\n key?: undefined;\n};\n\nexport type KeyPath =\n | ObjectNode\n | ArrayNode\n | TranslationNode\n | EnumerationNode\n | InsertionNode\n | MarkdownNode\n | ReactNode\n | ConditionNode\n | NestedNode;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/types/keyPath.ts"],"sourcesContent":["import type { NodeType } from './nodeType';\n\nexport type ObjectNode = {\n type: NodeType.Object;\n key: string;\n};\n\nexport type ArrayNode = {\n type: NodeType.Array;\n key: number;\n};\n\nexport type EnumerationNode = {\n type: NodeType.Enumeration;\n key: string;\n};\n\nexport type TranslationNode = {\n type: NodeType.Translation;\n key: string;\n};\n\nexport type ConditionNode = {\n type: NodeType.Condition;\n key: string;\n};\n\nexport type InsertionNode = {\n type: NodeType.Insertion;\n key?: undefined;\n};\n\nexport type MarkdownNode = {\n type: NodeType.Markdown;\n key?: undefined;\n};\n\nexport type ReactNode = {\n type: NodeType.ReactNode;\n key?: undefined;\n};\n\nexport type NestedNode = {\n type: NodeType.Nested;\n key?: undefined;\n};\n\nexport type FileNode = {\n type: NodeType.File;\n key?: undefined;\n};\n\nexport type KeyPath =\n | ObjectNode\n | ArrayNode\n | TranslationNode\n | EnumerationNode\n | InsertionNode\n | MarkdownNode\n | ReactNode\n | ConditionNode\n | NestedNode\n | FileNode;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -9,57 +9,42 @@ const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
9
9
  for (let i = 0; i < keyPath.length; i++) {
10
10
  const keyObj = keyPath[i];
11
11
  parentValue = currentValue;
12
- if (keyObj.type === NodeType.Object) {
12
+ if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
13
13
  lastKeys = [keyObj.key];
14
14
  if (!currentValue[keyObj.key] || typeof currentValue[keyObj.key] !== "object") {
15
15
  currentValue[keyObj.key] = {};
16
16
  }
17
17
  currentValue = currentValue[keyObj.key];
18
- } else if (keyObj.type === NodeType.Array) {
19
- lastKeys = [keyObj.key];
20
- if (!currentValue[keyObj.key] || typeof currentValue[keyObj.key] !== "object") {
21
- currentValue[keyObj.key] = {};
22
- }
23
- currentValue = currentValue[keyObj.key];
24
- } else if (keyObj.type === NodeType.Translation) {
25
- lastKeys = [NodeType.Translation, keyObj.key];
26
- if (!currentValue[NodeType.Translation] || typeof currentValue[NodeType.Translation] !== "object") {
27
- currentValue[NodeType.Translation] = {};
28
- }
29
- if (!currentValue[NodeType.Translation][keyObj.key] || typeof currentValue[NodeType.Translation][keyObj.key] !== "object") {
30
- currentValue[NodeType.Translation][keyObj.key] = {};
31
- }
32
- currentValue = currentValue[NodeType.Translation][keyObj.key];
33
- } else if (keyObj.type === NodeType.Enumeration) {
34
- lastKeys = [NodeType.Enumeration, keyObj.key];
35
- if (!currentValue[NodeType.Enumeration] || typeof currentValue[NodeType.Enumeration] !== "object") {
36
- currentValue[NodeType.Enumeration] = {};
37
- }
38
- if (!currentValue[NodeType.Enumeration][keyObj.key] || typeof currentValue[NodeType.Enumeration][keyObj.key] !== "object") {
39
- currentValue[NodeType.Enumeration][keyObj.key] = {};
18
+ }
19
+ if (keyObj.type === NodeType.Translation || keyObj.type === NodeType.Enumeration) {
20
+ lastKeys = [keyObj.type, keyObj.key];
21
+ if (!currentValue[keyObj.type] || typeof currentValue[keyObj.type] !== "object") {
22
+ currentValue[keyObj.type] = {};
40
23
  }
41
- currentValue = currentValue[NodeType.Enumeration][keyObj.key];
42
- } else if (keyObj.type === NodeType.Condition) {
43
- lastKeys = [NodeType.Condition, keyObj.key];
44
- if (!currentValue[NodeType.Condition] || typeof currentValue[NodeType.Condition] !== "object") {
45
- currentValue[NodeType.Condition] = {};
24
+ if (!currentValue[keyObj.type][keyObj.key] || typeof currentValue[keyObj.type][keyObj.key] !== "object") {
25
+ currentValue[keyObj.type][keyObj.key] = {};
46
26
  }
47
- if (!currentValue[NodeType.Condition][keyObj.key] || typeof currentValue[NodeType.Condition][keyObj.key] !== "object") {
48
- currentValue[NodeType.Condition][keyObj.key] = {};
27
+ currentValue = currentValue[keyObj.type][keyObj.key];
28
+ }
29
+ if (keyObj.type === NodeType.Enumeration || keyObj.type === NodeType.Condition) {
30
+ lastKeys = [keyObj.type, keyObj.key];
31
+ if (!currentValue[keyObj.type] || typeof currentValue[keyObj.type] !== "object") {
32
+ currentValue[keyObj.type] = {};
49
33
  }
50
- currentValue = currentValue[NodeType.Condition][keyObj.key];
51
- } else if (keyObj.type === NodeType.Markdown) {
52
- lastKeys = [NodeType.Markdown];
53
- if (!currentValue[NodeType.Markdown] || typeof currentValue[NodeType.Markdown] !== "object") {
54
- currentValue[NodeType.Markdown] = "";
34
+ if (!currentValue[keyObj.type][keyObj.key] || typeof currentValue[keyObj.type][keyObj.key] !== "object") {
35
+ currentValue[keyObj.type][keyObj.key] = {};
55
36
  }
56
- currentValue = currentValue[NodeType.Markdown];
57
- } else if (keyObj.type === NodeType.Nested) {
58
- lastKeys = [NodeType.Nested];
59
- if (!currentValue[NodeType.Nested] || typeof currentValue[NodeType.Nested] !== "object") {
60
- currentValue[NodeType.Nested] = {};
37
+ currentValue = currentValue[keyObj.type][keyObj.key];
38
+ }
39
+ if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) {
40
+ lastKeys = [keyObj.type];
41
+ if (!currentValue[keyObj.type] || typeof currentValue[keyObj.type] !== "object") {
42
+ currentValue[keyObj.type] = "";
61
43
  }
62
- currentValue = currentValue[NodeType.Nested];
44
+ currentValue = currentValue[keyObj.type];
45
+ }
46
+ if (keyObj.type) {
47
+ currentValue = currentValue;
63
48
  }
64
49
  if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {
65
50
  let target = parentValue;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\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 for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKeys = [NodeType.Translation, keyObj.key];\n if (\n !currentValue[NodeType.Translation] ||\n typeof currentValue[NodeType.Translation] !== 'object'\n ) {\n currentValue[NodeType.Translation] = {};\n }\n if (\n !currentValue[NodeType.Translation][keyObj.key] ||\n typeof currentValue[NodeType.Translation][keyObj.key] !== 'object'\n ) {\n currentValue[NodeType.Translation][keyObj.key] = {};\n }\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKeys = [NodeType.Enumeration, keyObj.key];\n if (\n !currentValue[NodeType.Enumeration] ||\n typeof currentValue[NodeType.Enumeration] !== 'object'\n ) {\n currentValue[NodeType.Enumeration] = {};\n }\n if (\n !currentValue[NodeType.Enumeration][keyObj.key] ||\n typeof currentValue[NodeType.Enumeration][keyObj.key] !== 'object'\n ) {\n currentValue[NodeType.Enumeration][keyObj.key] = {};\n }\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n } else if (keyObj.type === NodeType.Condition) {\n lastKeys = [NodeType.Condition, keyObj.key];\n if (\n !currentValue[NodeType.Condition] ||\n typeof currentValue[NodeType.Condition] !== 'object'\n ) {\n currentValue[NodeType.Condition] = {};\n }\n if (\n !currentValue[NodeType.Condition][keyObj.key] ||\n typeof currentValue[NodeType.Condition][keyObj.key] !== 'object'\n ) {\n currentValue[NodeType.Condition][keyObj.key] = {};\n }\n currentValue = currentValue[NodeType.Condition][keyObj.key];\n } else if (keyObj.type === NodeType.Markdown) {\n lastKeys = [NodeType.Markdown];\n if (\n !currentValue[NodeType.Markdown] ||\n typeof currentValue[NodeType.Markdown] !== 'object'\n ) {\n currentValue[NodeType.Markdown] = '';\n }\n currentValue = currentValue[NodeType.Markdown];\n } else if (keyObj.type === NodeType.Nested) {\n lastKeys = [NodeType.Nested];\n if (\n !currentValue[NodeType.Nested] ||\n typeof currentValue[NodeType.Nested] !== 'object'\n ) {\n currentValue[NodeType.Nested] = {};\n }\n currentValue = currentValue[NodeType.Nested];\n }\n\n // Only update the value when processing the last key in the keyPath.\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n // Drill down if lastKeys contains more than one key.\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n if (typeof newValue === 'undefined') {\n delete target[lastKeys[lastKeys.length - 1]];\n } else {\n target[lastKeys[lastKeys.length - 1]] = newValue;\n }\n }\n }\n return dictionaryContent;\n};\n"],"mappings":"AAAA,SAAuB,gBAAgB;AAKhC,MAAM,0BAA0B,CACrC,mBACA,SACA,aACgB;AAChB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,WAA0B,CAAC;AAE/B,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,SAAS,QAAQ,CAAC;AACxB,kBAAc;AAEd,QAAI,OAAO,SAAS,SAAS,QAAQ;AACnC,iBAAW,CAAC,OAAO,GAAG;AACtB,UACE,CAAC,aAAa,OAAO,GAAG,KACxB,OAAO,aAAa,OAAO,GAAG,MAAM,UACpC;AACA,qBAAa,OAAO,GAAG,IAAI,CAAC;AAAA,MAC9B;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,SAAS,OAAO;AACzC,iBAAW,CAAC,OAAO,GAAG;AACtB,UACE,CAAC,aA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,MACtC;AACA,UACE,CAAC,aAAa,SAAS,SAAS,EAAE,OAAO,GAAG,KAC5C,OAAO,aAAa,SAAS,SAAS,EAAE,OAAO,GAAG,MAAM,UACxD;AACA,qBAAa,SAAS,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;AAAA,MAClD;AACA,qBAAe,aAAa,SAAS,SAAS,EAAE,OAAO,GAAG;AAAA,IAC5D,WAAW,OAAO,SAAS,SAAS,UAAU;AAC5C,iBAAW,CAAC,SAAS,QAAQ;AAC7B,UACE,CAAC,aAAa,SAAS,QAAQ,KAC/B,OAAO,aAAa,SAAS,QAAQ,MAAM,UAC3C;AACA,qBAAa,SAAS,QAAQ,IAAI;AAAA,MACpC;AACA,qBAAe,aAAa,SAAS,QAAQ;AAAA,IAC/C,WAAW,OAAO,SAAS,SAAS,QAAQ;AAC1C,iBAAW,CAAC,SAAS,MAAM;AAC3B,UACE,CAAC,aAAa,SAAS,MAAM,KAC7B,OAAO,aAAa,SAAS,MAAM,MAAM,UACzC;AACA,qBAAa,SAAS,MAAM,IAAI,CAAC;AAAA,MACnC;AACA,qBAAe,aAAa,SAAS,MAAM;AAAA,IAC7C;AAGA,QAAI,MAAM,QAAQ,SAAS,KAAK,eAAe,SAAS,SAAS,GAAG;AAClE,UAAI,SAAS;AAEb,iBAAW,OAAO,SAAS,MAAM,GAAG,EAAE,GAAG;AACvC,iBAAS,OAAO,GAAG;AAAA,MACrB;AACA,UAAI,OAAO,aAAa,aAAa;AACnC,eAAO,OAAO,SAAS,SAAS,SAAS,CAAC,CAAC;AAAA,MAC7C,OAAO;AACL,eAAO,SAAS,SAAS,SAAS,CAAC,CAAC,IAAI;AAAA,MAC1C;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\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 for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n lastKeys = [keyObj.type];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type) {\n // No treated TypedNode\n\n currentValue = currentValue;\n }\n\n // Only update the value when processing the last key in the keyPath.\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n // Drill down if lastKeys contains more than one key.\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n if (typeof newValue === 'undefined') {\n delete target[lastKeys[lastKeys.length - 1]];\n } else {\n target[lastKeys[lastKeys.length - 1]] = newValue;\n }\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":"AAAA,SAAuB,gBAAgB;AAKhC,MAAM,0BAA0B,CACrC,mBACA,SACA,aACgB;AAChB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,WAA0B,CAAC;AAE/B,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,SAAS,QAAQ,CAAC;AACxB,kBAAc;AAEd,QAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,iBAAW,CAAC,OAAO,GAAG;AACtB,UACE,CAAC,aAAa,OAAO,GAAG,KACxB,OAAO,aAAa,OAAO,GAAG,MAAM,UACpC;AACA,qBAAa,OAAO,GAAG,IAAI,CAAC;AAAA,MAC9B;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC;AAEA,QACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,aACzB;AACA,iBAAW,CAAC,OAAO,MAAM,OAAO,GAAG;AACnC,UACE,CAAC,aAAa,OAAO,IAAI,KACzB,OAAO,aAAa,OAAO,IAAI,MAAM,UACrC;AACA,qBAAa,OAAO,IAAI,IAAI,CAAC;AAAA,MAC/B;AACA,UACE,CAAC,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG,KACrC,OAAO,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG,MAAM,UACjD;AACA,qBAAa,OAAO,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F;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -4,14 +4,10 @@ const getContentNodeByKeyPath = (dictionaryContent, keyPath) => {
4
4
  for (const keyObj of keyPath) {
5
5
  if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
6
6
  currentValue = currentValue?.[keyObj.key];
7
- } else if (keyObj.type === NodeType.Translation) {
8
- currentValue = currentValue?.[NodeType.Translation][keyObj.key];
9
- } else if (keyObj.type === NodeType.Enumeration) {
10
- currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];
11
- } else if (keyObj.type === NodeType.Condition) {
12
- currentValue = currentValue?.[NodeType.Condition];
13
- } else if (keyObj.type === NodeType.Markdown) {
14
- currentValue = currentValue?.[NodeType.Markdown];
7
+ } else if (keyObj.type === NodeType.Translation || keyObj.type === NodeType.Condition || keyObj.type === NodeType.Enumeration) {
8
+ currentValue = currentValue?.[keyObj.type][keyObj.key];
9
+ } else if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) {
10
+ currentValue = currentValue?.[keyObj.type];
15
11
  }
16
12
  }
17
13
  return currentValue;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];\n } else if (keyObj.type === NodeType.Condition) {\n currentValue = currentValue?.[NodeType.Condition];\n } else if (keyObj.type === NodeType.Markdown) {\n currentValue = currentValue?.[NodeType.Markdown];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":"AAAA,SAAuB,gBAAgB;AAGhC,MAAM,0BAA0B,CACrC,mBACA,YACgB;AAChB,MAAI,eAAoB,gBAAgB,iBAAiB;AAEzD,aAAW,UAAU,SAAS;AAC5B,QAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,qBAAe,eAAe,OAAO,GAAG;AAAA,IAC1C,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,qBAAe,eAAe,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,qBAAe,eAAe,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE,WAAW,OAAO,SAAS,SAAS,WAAW;AAC7C,qBAAe,eAAe,SAAS,SAAS;AAAA,IAClD,WAAW,OAAO,SAAS,SAAS,UAAU;AAC5C,qBAAe,eAAe,SAAS,QAAQ;AAAA,IACjD;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n } else if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Condition ||\n keyObj.type === NodeType.Enumeration\n ) {\n currentValue = currentValue?.[keyObj.type][keyObj.key];\n } else if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n currentValue = currentValue?.[keyObj.type];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":"AAAA,SAAuB,gBAAgB;AAGhC,MAAM,0BAA0B,CACrC,mBACA,YACgB;AAChB,MAAI,eAAoB,gBAAgB,iBAAiB;AAEzD,aAAW,UAAU,SAAS;AAC5B,QAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,qBAAe,eAAe,OAAO,GAAG;AAAA,IAC1C,WACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,aACzB;AACA,qBAAe,eAAe,OAAO,IAAI,EAAE,OAAO,GAAG;AAAA,IACvD,WACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,MACzB;AACA,qBAAe,eAAe,OAAO,IAAI;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -26,6 +26,13 @@ const getDefaultNode = (nodeType, locales, content) => {
26
26
  false: content ?? ""
27
27
  }
28
28
  };
29
+ case NodeType.Insertion:
30
+ return {
31
+ nodeType: NodeType.Insertion,
32
+ [NodeType.Insertion]: {
33
+ insertion: content ?? ""
34
+ }
35
+ };
29
36
  case NodeType.Nested:
30
37
  return {
31
38
  nodeType: NodeType.Nested,
@@ -38,6 +45,11 @@ const getDefaultNode = (nodeType, locales, content) => {
38
45
  nodeType: NodeType.Markdown,
39
46
  [NodeType.Markdown]: content ?? ""
40
47
  };
48
+ case NodeType.File:
49
+ return {
50
+ nodeType: NodeType.File,
51
+ [NodeType.File]: content ?? ""
52
+ };
41
53
  case NodeType.Object:
42
54
  return {
43
55
  newKey: content ?? ""
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport type {\n TranslationContent,\n EnumerationContent,\n ConditionContent,\n NestedContent,\n MarkdownContent,\n} from '../transpiler';\nimport { type ContentNode, NodeType } from '../types';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n) => {\n switch (nodeType) {\n case NodeType.Translation:\n return {\n nodeType: NodeType.Translation,\n [NodeType.Translation]: Object.assign(\n {},\n ...locales.map((locale) => ({\n [locale]: content ?? '',\n }))\n ),\n } as TranslationContent<ContentNode>;\n\n case NodeType.Enumeration:\n return {\n nodeType: NodeType.Enumeration,\n [NodeType.Enumeration]: {\n '1': content ?? '',\n },\n } as EnumerationContent<ContentNode>;\n\n case NodeType.Condition:\n return {\n nodeType: NodeType.Condition,\n [NodeType.Condition]: {\n true: content ?? '',\n false: content ?? '',\n },\n } as ConditionContent<ContentNode>;\n\n case NodeType.Nested:\n return {\n nodeType: NodeType.Nested,\n [NodeType.Nested]: {\n dictionaryKey: '',\n },\n } as NestedContent;\n\n case NodeType.Markdown:\n return {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: content ?? '',\n } as MarkdownContent;\n\n case NodeType.Object:\n return {\n newKey: content ?? '',\n } as Record<string, ContentNode>;\n\n case NodeType.Array:\n return [content ?? ''] as Record<number, ContentNode>;\n\n case NodeType.Text:\n return content ?? '';\n\n case NodeType.Number:\n return content ?? 0;\n\n case NodeType.Boolean:\n return content ?? true;\n\n default:\n return content ?? '';\n }\n};\n"],"mappings":"AAQA,SAA2B,gBAAgB;AAEpC,MAAM,iBAAiB,CAC5B,UACA,SACA,YACG;AACH,UAAQ,UAAU;AAAA,IAChB,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,WAAW,GAAG,OAAO;AAAA,UAC7B,CAAC;AAAA,UACD,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,YAC1B,CAAC,MAAM,GAAG,WAAW;AAAA,UACvB,EAAE;AAAA,QACJ;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,WAAW,GAAG;AAAA,UACtB,KAAK,WAAW;AAAA,QAClB;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,SAAS,GAAG;AAAA,UACpB,MAAM,WAAW;AAAA,UACjB,OAAO,WAAW;AAAA,QACpB;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,MAAM,GAAG;AAAA,UACjB,eAAe;AAAA,QACjB;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,QAAQ,GAAG,WAAW;AAAA,MAClC;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,QAAQ,WAAW;AAAA,MACrB;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO,CAAC,WAAW,EAAE;AAAA,IAEvB,KAAK,SAAS;AACZ,aAAO,WAAW;AAAA,IAEpB,KAAK,SAAS;AACZ,aAAO,WAAW;AAAA,IAEpB,KAAK,SAAS;AACZ,aAAO,WAAW;AAAA,IAEpB;AACE,aAAO,WAAW;AAAA,EACtB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport type {\n TranslationContent,\n EnumerationContent,\n ConditionContent,\n NestedContent,\n MarkdownContent,\n InsertionContent,\n FileContent,\n} from '../transpiler';\nimport { type ContentNode, NodeType } from '../types';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n) => {\n switch (nodeType) {\n case NodeType.Translation:\n return {\n nodeType: NodeType.Translation,\n [NodeType.Translation]: Object.assign(\n {},\n ...locales.map((locale) => ({\n [locale]: content ?? '',\n }))\n ),\n } as TranslationContent<ContentNode>;\n\n case NodeType.Enumeration:\n return {\n nodeType: NodeType.Enumeration,\n [NodeType.Enumeration]: {\n '1': content ?? '',\n },\n } as EnumerationContent<ContentNode>;\n\n case NodeType.Condition:\n return {\n nodeType: NodeType.Condition,\n [NodeType.Condition]: {\n true: content ?? '',\n false: content ?? '',\n },\n } as ConditionContent<ContentNode>;\n\n case NodeType.Insertion:\n return {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: {\n insertion: content ?? '',\n },\n } as InsertionContent<ContentNode>;\n\n case NodeType.Nested:\n return {\n nodeType: NodeType.Nested,\n [NodeType.Nested]: {\n dictionaryKey: '',\n },\n } as NestedContent;\n\n case NodeType.Markdown:\n return {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: content ?? '',\n } as MarkdownContent;\n\n case NodeType.File:\n return {\n nodeType: NodeType.File,\n [NodeType.File]: content ?? '',\n } as FileContent;\n\n case NodeType.Object:\n return {\n newKey: content ?? '',\n } as Record<string, ContentNode>;\n\n case NodeType.Array:\n return [content ?? ''] as Record<number, ContentNode>;\n\n case NodeType.Text:\n return content ?? '';\n\n case NodeType.Number:\n return content ?? 0;\n\n case NodeType.Boolean:\n return content ?? true;\n\n default:\n return content ?? '';\n }\n};\n"],"mappings":"AAUA,SAA2B,gBAAgB;AAEpC,MAAM,iBAAiB,CAC5B,UACA,SACA,YACG;AACH,UAAQ,UAAU;AAAA,IAChB,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,WAAW,GAAG,OAAO;AAAA,UAC7B,CAAC;AAAA,UACD,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,YAC1B,CAAC,MAAM,GAAG,WAAW;AAAA,UACvB,EAAE;AAAA,QACJ;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,WAAW,GAAG;AAAA,UACtB,KAAK,WAAW;AAAA,QAClB;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,SAAS,GAAG;AAAA,UACpB,MAAM,WAAW;AAAA,UACjB,OAAO,WAAW;AAAA,QACpB;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,SAAS,GAAG;AAAA,UACpB,WAAW,WAAW;AAAA,QACxB;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,MAAM,GAAG;AAAA,UACjB,eAAe;AAAA,QACjB;AAAA,MACF;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,QAAQ,GAAG,WAAW;AAAA,MAClC;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,UAAU,SAAS;AAAA,QACnB,CAAC,SAAS,IAAI,GAAG,WAAW;AAAA,MAC9B;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO;AAAA,QACL,QAAQ,WAAW;AAAA,MACrB;AAAA,IAEF,KAAK,SAAS;AACZ,aAAO,CAAC,WAAW,EAAE;AAAA,IAEvB,KAAK,SAAS;AACZ,aAAO,WAAW;AAAA,IAEpB,KAAK,SAAS;AACZ,aAAO,WAAW;AAAA,IAEpB,KAAK,SAAS;AACZ,aAAO,WAAW;AAAA,IAEpB;AACE,aAAO,WAAW;AAAA,EACtB;AACF;","names":[]}
@@ -12,11 +12,14 @@ const getEmptyNode = (section) => {
12
12
  if (typeof section?.nodeType === "string") {
13
13
  const typedNode = section;
14
14
  const content = typedNode[typedNode.nodeType];
15
- if (typedNode.nodeType === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition) {
15
+ if (typedNode.nodeType === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition || typedNode.nodeType === NodeType.Insertion) {
16
16
  return getEmptyNode(content);
17
17
  }
18
18
  if (typedNode.nodeType === NodeType.Nested) {
19
- return typedNode;
19
+ return "dictionary-key";
20
+ }
21
+ if (typedNode.nodeType === NodeType.File) {
22
+ return "file/path";
20
23
  }
21
24
  if (typedNode.nodeType === NodeType.Markdown) {
22
25
  return getEmptyNode(typedNode);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/getEmptyNode.ts"],"sourcesContent":["import { type ContentNode, type TypedNode, NodeType } from '../types';\n\nexport const getEmptyNode = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return '';\n }\n if (typeof section === 'number') {\n return 0;\n }\n if (typeof section === 'boolean') {\n return true;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content = typedNode[typedNode.nodeType as keyof TypedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition\n ) {\n return getEmptyNode(content as ContentNode);\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return typedNode;\n }\n\n if (typedNode.nodeType === NodeType.Markdown) {\n return getEmptyNode(typedNode);\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[]).map(\n getEmptyNode\n ) as unknown as ContentNode;\n }\n\n const mappedSectionObject = Object.entries(section).map(([key, value]) => [\n key,\n getEmptyNode(value),\n ]);\n\n const mappedSectionArray = Object.fromEntries(mappedSectionObject);\n\n return mappedSectionArray;\n};\n"],"mappings":"AAAA,SAA2C,gBAAgB;AAEpD,MAAM,eAAe,CAAC,YAAsC;AACjE,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,WAAW;AAChC,WAAO;AAAA,EACT;AACA,MAAI,OAAQ,SAAuB,aAAa,UAAU;AACxD,UAAM,YAAY;AAClB,UAAM,UAAU,UAAU,UAAU,QAA2B;AAE/D,QACE,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,WAChC;AACA,aAAO,aAAa,OAAsB;AAAA,IAC5C;AAEA,QAAI,UAAU,aAAa,SAAS,QAAQ;AAC1C,aAAO;AAAA,IACT;AAEA,QAAI,UAAU,aAAa,SAAS,UAAU;AAC5C,aAAO,aAAa,SAAS;AAAA,IAC/B;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,WAAW,OAAO,YAAY,UAAU;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAQ,QAA0B;AAAA,MAChC;AAAA,IACF;AAAA,EACF;AAEA,QAAM,sBAAsB,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,IACxE;AAAA,IACA,aAAa,KAAK;AAAA,EACpB,CAAC;AAED,QAAM,qBAAqB,OAAO,YAAY,mBAAmB;AAEjE,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/dictionaryManipulator/getEmptyNode.ts"],"sourcesContent":["import { type ContentNode, type TypedNode, NodeType } from '../types';\n\nexport const getEmptyNode = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return '';\n }\n if (typeof section === 'number') {\n return 0;\n }\n if (typeof section === 'boolean') {\n return true;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content = typedNode[typedNode.nodeType as keyof TypedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion\n ) {\n return getEmptyNode(content as ContentNode);\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return 'dictionary-key';\n }\n\n if (typedNode.nodeType === NodeType.File) {\n return 'file/path';\n }\n\n if (typedNode.nodeType === NodeType.Markdown) {\n return getEmptyNode(typedNode);\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[]).map(\n getEmptyNode\n ) as unknown as ContentNode;\n }\n\n const mappedSectionObject = Object.entries(section).map(([key, value]) => [\n key,\n getEmptyNode(value as ContentNode),\n ]);\n\n const mappedSectionArray = Object.fromEntries(mappedSectionObject);\n\n return mappedSectionArray;\n};\n"],"mappings":"AAAA,SAA2C,gBAAgB;AAEpD,MAAM,eAAe,CAAC,YAAsC;AACjE,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,WAAW;AAChC,WAAO;AAAA,EACT;AACA,MAAI,OAAQ,SAAuB,aAAa,UAAU;AACxD,UAAM,YAAY;AAClB,UAAM,UAAU,UAAU,UAAU,QAA2B;AAE/D,QACE,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,WAChC;AACA,aAAO,aAAa,OAAsB;AAAA,IAC5C;AAEA,QAAI,UAAU,aAAa,SAAS,QAAQ;AAC1C,aAAO;AAAA,IACT;AAEA,QAAI,UAAU,aAAa,SAAS,MAAM;AACxC,aAAO;AAAA,IACT;AAEA,QAAI,UAAU,aAAa,SAAS,UAAU;AAC5C,aAAO,aAAa,SAAS;AAAA,IAC/B;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,WAAW,OAAO,YAAY,UAAU;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAQ,QAA0B;AAAA,MAChC;AAAA,IACF;AAAA,EACF;AAEA,QAAM,sBAAsB,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,IACxE;AAAA,IACA,aAAa,KAAoB;AAAA,EACnC,CAAC;AAED,QAAM,qBAAqB,OAAO,YAAY,mBAAmB;AAEjE,SAAO;AACT;","names":[]}
@@ -8,21 +8,14 @@ const removeContentNodeByKeyPath = (dictionaryContent, keyPath) => {
8
8
  if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
9
9
  lastKey = keyObj.key;
10
10
  currentValue = currentValue[keyObj.key];
11
- } else if (keyObj.type === NodeType.Translation) {
12
- lastKey = NodeType.Translation;
13
- currentValue = currentValue[NodeType.Translation][keyObj.key];
14
- } else if (keyObj.type === NodeType.Enumeration) {
15
- lastKey = NodeType.Enumeration;
16
- currentValue = currentValue[NodeType.Enumeration][keyObj.key];
17
- } else if (keyObj.type === NodeType.Condition) {
18
- lastKey = NodeType.Condition;
19
- currentValue = currentValue[NodeType.Condition];
20
- } else if (keyObj.type === NodeType.Markdown) {
21
- lastKey = NodeType.Markdown;
22
- currentValue = currentValue[NodeType.Markdown];
23
- } else if (keyObj.type === NodeType.ReactNode) {
24
- lastKey = NodeType.ReactNode;
25
- currentValue = currentValue[NodeType.ReactNode];
11
+ }
12
+ if (keyObj.type === NodeType.Translation || keyObj.type === NodeType.Enumeration || keyObj.type === NodeType.Condition) {
13
+ lastKey = keyObj.type;
14
+ currentValue = currentValue[keyObj.type][keyObj.key];
15
+ }
16
+ if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.ReactNode || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) {
17
+ lastKey = keyObj.type;
18
+ currentValue = currentValue[keyObj.type];
26
19
  }
27
20
  }
28
21
  if (parentValue && lastKey !== null) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/removeContentNodeByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\n\nexport const removeContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKey = NodeType.Translation;\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKey = NodeType.Enumeration;\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n } else if (keyObj.type === NodeType.Condition) {\n lastKey = NodeType.Condition;\n currentValue = currentValue[NodeType.Condition];\n } else if (keyObj.type === NodeType.Markdown) {\n lastKey = NodeType.Markdown;\n currentValue = currentValue[NodeType.Markdown];\n } else if (keyObj.type === NodeType.ReactNode) {\n lastKey = NodeType.ReactNode;\n currentValue = currentValue[NodeType.ReactNode];\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":"AAAA,SAAuB,gBAAgB;AAGhC,MAAM,6BAA6B,CACxC,mBACA,YACgB;AAChB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,UAAkC;AAEtC,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,SAAS,WAAW;AAC7C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,SAAS;AAAA,IAChD,WAAW,OAAO,SAAS,SAAS,UAAU;AAC5C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,QAAQ;AAAA,IAC/C,WAAW,OAAO,SAAS,SAAS,WAAW;AAC7C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,SAAS;AAAA,IAChD;AAAA,EACF;AAEA,MAAI,eAAe,YAAY,MAAM;AACnC,QAAI,MAAM,QAAQ,WAAW,GAAG;AAC9B,kBAAY,OAAO,SAA8B,CAAC;AAAA,IACpD,OAAO;AACL,aAAO,YAAY,OAAO;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/dictionaryManipulator/removeContentNodeByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\n\nexport const removeContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.ReactNode ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":"AAAA,SAAuB,gBAAgB;AAGhC,MAAM,6BAA6B,CACxC,mBACA,YACgB;AAChB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,UAAkC;AAEtC,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC;AAEA,QACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,WACzB;AACA,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG;AAAA,IACrD;AAEA,QACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,MACzB;AACA,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,IAAI;AAAA,IACzC;AAAA,EACF;AAEA,MAAI,eAAe,YAAY,MAAM;AACnC,QAAI,MAAM,QAAQ,WAAW,GAAG;AAC9B,kBAAY,OAAO,SAA8B,CAAC;AAAA,IACpD,OAAO;AACL,aAAO,YAAY,OAAO;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -8,21 +8,14 @@ const renameContentNodeByKeyPath = (dictionaryContent, newKey, keyPath) => {
8
8
  if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
9
9
  lastKey = keyObj.key;
10
10
  currentValue = currentValue[keyObj.key];
11
- } else if (keyObj.type === NodeType.Translation) {
12
- lastKey = NodeType.Translation;
13
- currentValue = currentValue[NodeType.Translation][keyObj.key];
14
- } else if (keyObj.type === NodeType.Enumeration) {
15
- lastKey = NodeType.Enumeration;
16
- currentValue = currentValue[NodeType.Enumeration][keyObj.key];
17
- } else if (keyObj.type === NodeType.Condition) {
18
- lastKey = NodeType.Condition;
19
- currentValue = currentValue[NodeType.Condition];
20
- } else if (keyObj.type === NodeType.Markdown) {
21
- lastKey = NodeType.Markdown;
22
- currentValue = currentValue[NodeType.Markdown];
23
- } else if (keyObj.type === NodeType.ReactNode) {
24
- lastKey = NodeType.ReactNode;
25
- currentValue = currentValue[NodeType.ReactNode];
11
+ }
12
+ if (keyObj.type === NodeType.Translation || keyObj.type === NodeType.Enumeration || keyObj.type === NodeType.Condition) {
13
+ lastKey = keyObj.type;
14
+ currentValue = currentValue[keyObj.type][keyObj.key];
15
+ }
16
+ if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.ReactNode || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) {
17
+ lastKey = keyObj.type;
18
+ currentValue = currentValue[keyObj.type];
26
19
  }
27
20
  }
28
21
  if (parentValue && lastKey !== null) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/renameContentNodeByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\n\nexport const renameContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n newKey: KeyPath['key'],\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKey = NodeType.Translation;\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKey = NodeType.Enumeration;\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n } else if (keyObj.type === NodeType.Condition) {\n lastKey = NodeType.Condition;\n currentValue = currentValue[NodeType.Condition];\n } else if (keyObj.type === NodeType.Markdown) {\n lastKey = NodeType.Markdown;\n currentValue = currentValue[NodeType.Markdown];\n } else if (keyObj.type === NodeType.ReactNode) {\n lastKey = NodeType.ReactNode;\n currentValue = currentValue[NodeType.ReactNode];\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) => delete parentValue[key]);\n Object.assign(parentValue, newParentValue);\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":"AAAA,SAAuB,gBAAgB;AAGhC,MAAM,6BAA6B,CACxC,mBACA,QACA,YACgB;AAChB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,UAAkC;AAEtC,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,SAAS,WAAW;AAC7C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,SAAS;AAAA,IAChD,WAAW,OAAO,SAAS,SAAS,UAAU;AAC5C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,QAAQ;AAAA,IAC/C,WAAW,OAAO,SAAS,SAAS,WAAW;AAC7C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,SAAS;AAAA,IAChD;AAAA,EACF;AAGA,MAAI,eAAe,YAAY,MAAM;AACnC,QAAI,MAAM,QAAQ,WAAW,GAAG;AAC9B,kBAAY,OAAiB,IAAI;AAAA,IACnC,OAAO;AACL,YAAM,iBAAsB,CAAC;AAC7B,iBAAW,OAAO,OAAO,KAAK,WAAW,GAAG;AAC1C,YAAI,QAAQ,WAAW,OAAO,WAAW,aAAa;AACpD,yBAAe,MAAM,IAAI;AAAA,QAC3B,OAAO;AACL,yBAAe,GAAG,IAAI,YAAY,GAAG;AAAA,QACvC;AAAA,MACF;AAEA,aAAO,KAAK,WAAW,EAAE,QAAQ,CAAC,QAAQ,OAAO,YAAY,GAAG,CAAC;AACjE,aAAO,OAAO,aAAa,cAAc;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/dictionaryManipulator/renameContentNodeByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\n\nexport const renameContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n newKey: KeyPath['key'],\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.ReactNode ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n // Assign the new value to the last key of the parent while preserving the order\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue[lastKey as number] = currentValue;\n } else {\n const newParentValue: any = {};\n for (const key of Object.keys(parentValue)) {\n if (key === lastKey && typeof newKey !== 'undefined') {\n newParentValue[newKey] = currentValue;\n } else {\n newParentValue[key] = parentValue[key];\n }\n }\n // Replace the contents of parentValue with newParentValue\n Object.keys(parentValue).forEach((key) => delete parentValue[key]);\n Object.assign(parentValue, newParentValue);\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":"AAAA,SAAuB,gBAAgB;AAGhC,MAAM,6BAA6B,CACxC,mBACA,QACA,YACgB;AAChB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,UAAkC;AAEtC,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC;AAEA,QACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,WACzB;AACA,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG;AAAA,IACrD;AAEA,QACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,MACzB;AACA,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,IAAI;AAAA,IACzC;AAAA,EACF;AAGA,MAAI,eAAe,YAAY,MAAM;AACnC,QAAI,MAAM,QAAQ,WAAW,GAAG;AAC9B,kBAAY,OAAiB,IAAI;AAAA,IACnC,OAAO;AACL,YAAM,iBAAsB,CAAC;AAC7B,iBAAW,OAAO,OAAO,KAAK,WAAW,GAAG;AAC1C,YAAI,QAAQ,WAAW,OAAO,WAAW,aAAa;AACpD,yBAAe,MAAM,IAAI;AAAA,QAC3B,OAAO;AACL,yBAAe,GAAG,IAAI,YAAY,GAAG;AAAA,QACvC;AAAA,MACF;AAEA,aAAO,KAAK,WAAW,EAAE,QAAQ,CAAC,QAAQ,OAAO,YAAY,GAAG,CAAC;AACjE,aAAO,OAAO,aAAa,cAAc;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -5,7 +5,8 @@ import {
5
5
  enumerationPlugin,
6
6
  conditionPlugin,
7
7
  nestedPlugin,
8
- insertionPlugin
8
+ insertionPlugin,
9
+ filePlugin
9
10
  } from "./plugins.mjs";
10
11
  const getContent = (node, nodeProps, locale = configuration.internationalization.defaultLocale) => {
11
12
  const plugins = [
@@ -14,7 +15,7 @@ const getContent = (node, nodeProps, locale = configuration.internationalization
14
15
  enumerationPlugin,
15
16
  conditionPlugin,
16
17
  nestedPlugin,
17
- // filePlugin,
18
+ filePlugin,
18
19
  ...nodeProps.plugins ?? []
19
20
  ];
20
21
  return deepTransformNode(node, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import { type Locales, type LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport type { ContentNode } from '../../types';\nimport { deepTransformNode } from './deepTransform';\nimport {\n translationPlugin,\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n insertionPlugin,\n // filePlugin,\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n} from './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 T extends ContentNode,\n L extends LocalesValues = Locales,\n>(\n node: T,\n nodeProps: NodeProps,\n locale: L = configuration.internationalization.defaultLocale as L\n) => {\n const plugins: Plugins[] = [\n insertionPlugin,\n translationPlugin(locale),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n // filePlugin,\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n"],"mappings":"AACA,OAAO,mBAAmB;AAG1B,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAQA,MAAM,aAAa,CAIxB,MACA,WACA,SAAY,cAAc,qBAAqB,kBAC5C;AACH,QAAM,UAAqB;AAAA,IACzB;AAAA,IACA,kBAAkB,MAAM;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IAEA,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,SAAO,kBAAkB,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import { type Locales, type LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport type { ContentNode } from '../../types';\nimport { deepTransformNode } from './deepTransform';\nimport {\n translationPlugin,\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n insertionPlugin,\n filePlugin,\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n} from './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 T extends ContentNode,\n L extends LocalesValues = Locales,\n>(\n node: T,\n nodeProps: NodeProps,\n locale: L = configuration.internationalization.defaultLocale as L\n) => {\n const plugins: Plugins[] = [\n insertionPlugin,\n translationPlugin(locale),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n filePlugin,\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n"],"mappings":"AACA,OAAO,mBAAmB;AAG1B,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAQA,MAAM,aAAa,CAIxB,MACA,WACA,SAAY,cAAc,qBAAqB,kBAC5C;AACH,QAAM,UAAqB;AAAA,IACzB;AAAA,IACA,kBAAkB,MAAM;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,SAAO,kBAAkB,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -119,9 +119,18 @@ const nestedPlugin = {
119
119
  canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Nested,
120
120
  transform: (node, props) => getNesting(node.nested.dictionaryKey, node.nested.path, props)
121
121
  };
122
+ const filePlugin = {
123
+ id: "file-plugin",
124
+ canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.File,
125
+ transform: (node, props, deepTransform) => deepTransform(node.content, {
126
+ ...props,
127
+ children: node.content
128
+ })
129
+ };
122
130
  export {
123
131
  conditionPlugin,
124
132
  enumerationPlugin,
133
+ filePlugin,
125
134
  insertionPlugin,
126
135
  nestedPlugin,
127
136
  translationPlugin
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport type {\n ConditionContent,\n EnumerationContent,\n NestedContent,\n TranslationContent,\n InsertionContent,\n} from '../../transpiler';\nimport { type DictionaryKeys, type KeyPath, NodeType } from '../../types/index';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\nimport { getInsertion } from '../getInsertion';\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 * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type TranslationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Translation]: object;\n}\n ? DeepTransformContent<\n T[NodeType.Translation][keyof T[NodeType.Translation]],\n S\n >\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (locale: LocalesValues): Plugins => ({\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Translation]);\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n return getTranslation(result, locale);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Enumeration]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[NodeType.Enumeration][keyof T[NodeType.Enumeration]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Enumeration]);\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Enumeration, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (quantity: number) => getEnumeration(result, quantity);\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Condition]: object;\n}\n ? (\n value: boolean\n ) => DeepTransformContent<\n T[NodeType.Condition][keyof T[NodeType.Condition]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Condition]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Condition, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: boolean) => getCondition(result, value);\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Insertion]: infer I;\n fields?: infer U;\n}\n ? U extends readonly string[]\n ? (data: Record<U[number], string>) => DeepTransformContent<I, S>\n : (data: Record<string, string>) => DeepTransformContent<I, S>\n : never;\n\nexport const insertionPlugin: Plugins = {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Insertion,\n },\n ];\n\n const children = node[NodeType.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) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\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: {\n [K in InsertionContent['fields'][number]]: string;\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 * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.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: Plugins = {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Nested,\n transform: (node: NestedContent, props) =>\n getNesting(node.nested.dictionaryKey, node.nested.path, props),\n};\n\n// /** ---------------------------------------------\n// * FILE PLUGIN\n// * --------------------------------------------- */\n\n// export type FileCond<T> = T extends {\n// nodeType: NodeType | string;\n// [NodeType.File]: string;\n// content?: string;\n// }\n// ? string\n// : never;\n\n// /** File plugin. Replaces node with the result of `getNesting`. */\n// export const filePlugin: Plugins = {\n// id: 'file-plugin',\n// canHandle: (node) =>\n// typeof node === 'object' && node?.nodeType === NodeType.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?: Locales;\n dictionaryPath?: string;\n children?: any;\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> {\n translation: TranslationCond<T, S>;\n insertion: InsertionCond<T, S>;\n enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\n // file: FileCond<T>;\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 condition: true;\n insertion: 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<T, K extends keyof IInterpreterPlugin<T, S>, S> =\n // Test if the key is a key of S.\n K extends keyof 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>[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>[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> =\n // Turn any read-only array into a plain mutable array\n T extends ReadonlyArray<infer U>\n ? Array<DeepTransformContent<U, S>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S> }\n : T;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<T, S = IInterpreterPluginState> =\n // Check if there is a plugin for T:\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S>, S> extends never\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S>\n : // A plugin was found – use the plugin’s transformation.\n IInterpreterPlugin<T, S>[keyof IInterpreterPlugin<T, S>];\n"],"mappings":"AAQA,SAA4C,gBAAgB;AAC5D,SAAS,oBAAoB;AAC7B,SAAS,sBA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,YACH,SAAS,MAAM;AAAA,YACf,UAAAA;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,WAAO,kBAAkB,UAAU;AAAA,MACjC,GAAG;AAAA,MACH;AAAA,MACA,SAAS;AAAA,MACT,SAAS,CAAC,uBAAuB,GAAI,MAAM,WAAW,CAAC,CAAE;AAAA,IAC3D,CAAC;AAAA,EACH;AACF;AAmBO,MAAM,eAAwB;AAAA,EACnC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAqB,UAC/B,WAAW,KAAK,OAAO,eAAe,KAAK,OAAO,MAAM,KAAK;AACjE;","names":["node","deepTransformNode","children"]}
1
+ {"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport type {\n ConditionContent,\n EnumerationContent,\n NestedContent,\n TranslationContent,\n InsertionContent,\n FileContent,\n} from '../../transpiler';\nimport { type DictionaryKeys, type KeyPath, NodeType } from '../../types/index';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\nimport { getInsertion } from '../getInsertion';\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 * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type TranslationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Translation]: object;\n}\n ? DeepTransformContent<\n T[NodeType.Translation][keyof T[NodeType.Translation]],\n S\n >\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (locale: LocalesValues): Plugins => ({\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Translation]);\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n return getTranslation(result, locale);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Enumeration]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[NodeType.Enumeration][keyof T[NodeType.Enumeration]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Enumeration]);\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Enumeration, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (quantity: number) => getEnumeration(result, quantity);\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Condition]: object;\n}\n ? (\n value: boolean\n ) => DeepTransformContent<\n T[NodeType.Condition][keyof T[NodeType.Condition]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Condition]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Condition, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: boolean) => getCondition(result, value);\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Insertion]: infer I;\n fields?: infer U;\n}\n ? U extends readonly string[]\n ? (data: Record<U[number], string | number>) => DeepTransformContent<I, S>\n : (data: Record<string, string | number>) => DeepTransformContent<I, S>\n : never;\n\nexport const insertionPlugin: Plugins = {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Insertion,\n },\n ];\n\n const children = node[NodeType.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) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\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: {\n [K in InsertionContent['fields'][number]]: string | number;\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 * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.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: Plugins = {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Nested,\n transform: (node: NestedContent, props) =>\n getNesting(node.nested.dictionaryKey, node.nested.path, props),\n};\n\n// /** ---------------------------------------------\n// * FILE PLUGIN\n// * --------------------------------------------- */\n\nexport type FileCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.File]: string;\n content?: string;\n}\n ? string\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins = {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.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?: Locales;\n dictionaryPath?: string;\n children?: any;\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> {\n translation: TranslationCond<T, S>;\n insertion: InsertionCond<T, S>;\n enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\n // file: FileCond<T>;\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 condition: true;\n insertion: 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<T, K extends keyof IInterpreterPlugin<T, S>, S> =\n // Test if the key is a key of S.\n K extends keyof 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>[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>[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> =\n // Turn any read-only array into a plain mutable array\n T extends ReadonlyArray<infer U>\n ? Array<DeepTransformContent<U, S>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S> }\n : T;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<T, S = IInterpreterPluginState> =\n // Check if there is a plugin for T:\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S>, S> extends never\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S>\n : // A plugin was found – use the plugin’s transformation.\n IInterpreterPlugin<T, S>[keyof IInterpreterPlugin<T, S>];\n"],"mappings":"AASA,SAA4C,gBAAgB;AAC5D,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAgC,kBAAkB;AAClD,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAsCtB,MAAM,oBAAoB,CAAC,YAAoC;AAAA,EACpE,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gB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mBO,MAAM,eAAwB;AAAA,EACnC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAqB,UAC/B,WAAW,KAAK,OAAO,eAAe,KAAK,OAAO,MAAM,KAAK;AACjE;AAeO,MAAM,aAAsB;AAAA,EACjC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAmB,OAAO,kBACpC,cAAc,KAAK,SAAS;AAAA,IAC1B,GAAG;AAAA,IACH,UAAU,KAAK;AAAA,EACjB,CAAC;AACL;","names":["node","deepTransformNode","children"]}
@@ -1,4 +1,4 @@
1
- const getInsertion = (content, values) => content.replace(/\{\{(.*?)\}\}/g, (_, key) => values[key] ?? "");
1
+ const getInsertion = (content, values) => content.replace(/\{\{(.*?)\}\}/g, (_, key) => (values[key] ?? "").toString());
2
2
  export {
3
3
  getInsertion
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/interpreter/getInsertion.ts"],"sourcesContent":["import type { InsertionContent } from '../transpiler';\n\n/**\n * Allow to insert values in a string.\n *\n * Usage:\n *\n * ```ts\n * const content = getInsertion('Hello {{name}}!', {\n * name: 'John',\n * });\n * // 'Hello John!'\n * ```\n *\n */\nexport const getInsertion = (\n content: string,\n values: { [K in InsertionContent['fields'][number]]: string }\n) => content.replace(/\\{\\{(.*?)\\}\\}/g, (_, key) => values[key] ?? '');\n"],"mappings":"AAeO,MAAM,eAAe,CAC1B,SACA,WACG,QAAQ,QAAQ,kBAAkB,CAAC,GAAG,QAAQ,OAAO,GAAG,KAAK,EAAE;","names":[]}
1
+ {"version":3,"sources":["../../../src/interpreter/getInsertion.ts"],"sourcesContent":["import type { InsertionContent } from '../transpiler';\n\n/**\n * Allow to insert values in a string.\n *\n * Usage:\n *\n * ```ts\n * const content = getInsertion('Hello {{name}}!', {\n * name: 'John',\n * });\n * // 'Hello John!'\n * ```\n *\n */\nexport const getInsertion = (\n content: string,\n values: { [K in InsertionContent['fields'][number]]: string | number }\n) =>\n content.replace(/\\{\\{(.*?)\\}\\}/g, (_, key) => (values[key] ?? '').toString());\n"],"mappings":"AAeO,MAAM,eAAe,CAC1B,SACA,WAEA,QAAQ,QAAQ,kBAAkB,CAAC,GAAG,SAAS,OAAO,GAAG,KAAK,IAAI,SAAS,CAAC;","names":[]}
@@ -33,8 +33,7 @@ const file = (path) => {
33
33
  fixedPath: relative(process.cwd(), filePath)
34
34
  });
35
35
  };
36
- var file_default = file;
37
36
  export {
38
- file_default as default
37
+ file
39
38
  };
40
39
  //# sourceMappingURL=file.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/file/file.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'fs';\nimport {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\nimport { relative, resolve } from 'path';\nimport { appLogger } from '@intlayer/config';\n\nexport type FileContent = TypedNodeModel<\n NodeType.File,\n string,\n {\n content: string;\n fixedPath?: string;\n }\n>;\n\ndeclare const intlayer_file_path: string; // Injected by esbuild to track the file content\ndeclare const intlayer_file_dir: string; // Injected by esbuild to track the file path\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow identify the usage of an external resource.\n *\n * Usage:\n *\n * ```ts\n * file('/path/to/file.md') // absolute path\n *\n * // or\n *\n * file('path/to/file.md') // relative path\n * ```\n */\nconst file = (path: string): FileContent => {\n const callerDir = intlayer_file_dir ?? process.cwd();\n\n const isAbsolutePath = path.startsWith('/');\n const isRelativePath = path.startsWith('./') || path.startsWith('../');\n\n let filePath: string;\n if (isAbsolutePath) {\n appLogger(\n `Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${intlayer_file_path}`,\n { level: 'warn' }\n );\n filePath = path;\n } else if (isRelativePath) {\n filePath = resolve(callerDir, path);\n } else {\n filePath = resolve(process.cwd(), path);\n }\n\n let content: string;\n\n if (existsSync(filePath)) {\n content = readFileSync(filePath, 'utf8');\n } else {\n appLogger(`File not found: ${filePath}`, { level: 'warn' });\n\n content = `File not found`;\n }\n\n return formatNodeType(NodeType.File, path, {\n content,\n fixedPath: relative(process.cwd(), filePath),\n });\n};\n\nexport default file;\n"],"mappings":"AAAA,SAAS,YAAY,oBAAoB;AACzC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,UAAU,eAAe;AAClC,SAAS,iBAAiB;AA6B1B,MAAM,OAAO,CAAC,SAA8B;AAC1C,QAAM,YAAY,qBAAqB,QAAQ,IAAI;AAEnD,QAAM,iBAAiB,KAAK,WAAW,GAAG;AAC1C,QAAM,iBAAiB,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK;AAErE,MAAI;AACJ,MAAI,gBAAgB;AAClB;AAAA,MACE,sFAAsF,IAAI,oBAAoB,kBAAkB;AAAA,MAChI,EAAE,OAAO,OAAO;AAAA,IAClB;AACA,eAAW;AAAA,EACb,WAAW,gBAAgB;AACzB,eAAW,QAAQ,WAAW,IAAI;AAAA,EACpC,OAAO;AACL,eAAW,QAAQ,QAAQ,IAAI,GAAG,IAAI;AAAA,EACxC;AAEA,MAAI;AAEJ,MAAI,WAAW,QAAQ,GAAG;AACxB,cAAU,aAAa,UAAU,MAAM;AAAA,EACzC,OAAO;AACL,cAAU,mBAAmB,QAAQ,IAAI,EAAE,OAAO,OAAO,CAAC;AAE1D,cAAU;AAAA,EACZ;AAEA,SAAO,eAAe,SAAS,MAAM,MAAM;AAAA,IACzC;AAAA,IACA,WAAW,SAAS,QAAQ,IAAI,GAAG,QAAQ;AAAA,EAC7C,CAAC;AACH;AAEA,IAAO,eAAQ;","names":[]}
1
+ {"version":3,"sources":["../../../../src/transpiler/file/file.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'fs';\nimport {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\nimport { relative, resolve } from 'path';\nimport { appLogger } from '@intlayer/config';\n\nexport type FileContentConstructer<T extends Record<string, any> = {}> =\n TypedNodeModel<NodeType.File, string, T>;\n\nexport type FileContent = FileContentConstructer<{\n content: string;\n fixedPath?: string;\n}>;\n\ndeclare const intlayer_file_path: string; // Injected by esbuild to track the file content\ndeclare const intlayer_file_dir: string; // Injected by esbuild to track the file path\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow identify the usage of an external resource.\n *\n * Usage:\n *\n * ```ts\n * file('/path/to/file.md') // absolute path\n *\n * // or\n *\n * file('path/to/file.md') // relative path\n * ```\n */\nexport const file = (path: string): FileContent => {\n const callerDir = intlayer_file_dir ?? process.cwd();\n\n const isAbsolutePath = path.startsWith('/');\n const isRelativePath = path.startsWith('./') || path.startsWith('../');\n\n let filePath: string;\n if (isAbsolutePath) {\n appLogger(\n `Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${intlayer_file_path}`,\n { level: 'warn' }\n );\n filePath = path;\n } else if (isRelativePath) {\n filePath = resolve(callerDir, path);\n } else {\n filePath = resolve(process.cwd(), path);\n }\n\n let content: string;\n\n if (existsSync(filePath)) {\n content = readFileSync(filePath, 'utf8');\n } else {\n appLogger(`File not found: ${filePath}`, { level: 'warn' });\n\n content = `File not found`;\n }\n\n return formatNodeType(NodeType.File, path, {\n content,\n fixedPath: relative(process.cwd(), filePath),\n });\n};\n"],"mappings":"AAAA,SAAS,YAAY,oBAAoB;AACzC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,UAAU,eAAe;AAClC,SAAS,iBAAiB;AA4BnB,MAAM,OAAO,CAAC,SAA8B;AACjD,QAAM,YAAY,qBAAqB,QAAQ,IAAI;AAEnD,QAAM,iBAAiB,KAAK,WAAW,GAAG;AAC1C,QAAM,iBAAiB,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK;AAErE,MAAI;AACJ,MAAI,gBAAgB;AAClB;AAAA,MACE,sFAAsF,IAAI,oBAAoB,kBAAkB;AAAA,MAChI,EAAE,OAAO,OAAO;AAAA,IAClB;AACA,eAAW;AAAA,EACb,WAAW,gBAAgB;AACzB,eAAW,QAAQ,WAAW,IAAI;AAAA,EACpC,OAAO;AACL,eAAW,QAAQ,QAAQ,IAAI,GAAG,IAAI;AAAA,EACxC;AAEA,MAAI;AAEJ,MAAI,WAAW,QAAQ,GAAG;AACxB,cAAU,aAAa,UAAU,MAAM;AAAA,EACzC,OAAO;AACL,cAAU,mBAAmB,QAAQ,IAAI,EAAE,OAAO,OAAO,CAAC;AAE1D,cAAU;AAAA,EACZ;AAEA,SAAO,eAAe,SAAS,MAAM,MAAM;AAAA,IACzC;AAAA,IACA,WAAW,SAAS,QAAQ,IAAI,GAAG,QAAQ;AAAA,EAC7C,CAAC;AACH;","names":[]}
@@ -0,0 +1,12 @@
1
+ import { formatNodeType, NodeType } from "../../types/index.mjs";
2
+ const file = (path) => {
3
+ throw new Error("file is not available in browser");
4
+ return formatNodeType(NodeType.File, path, {
5
+ content: "",
6
+ fixedPath: ""
7
+ });
8
+ };
9
+ export {
10
+ file
11
+ };
12
+ //# sourceMappingURL=fileBrowser.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/transpiler/file/fileBrowser.ts"],"sourcesContent":["import { formatNodeType, NodeType } from '../../types';\nimport type { FileContent } from './file';\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow identify the usage of an external resource.\n *\n * Usage:\n *\n * ```ts\n * file('/path/to/file.md') // absolute path\n *\n * // or\n *\n * file('path/to/file.md') // relative path\n * ```\n */\nexport const file = (path: string): FileContent => {\n throw new Error('file is not available in browser');\n\n return formatNodeType(NodeType.File, path, {\n content: '',\n fixedPath: '',\n });\n};\n"],"mappings":"AAAA,SAAS,gBAAgB,gBAAgB;AAkBlC,MAAM,OAAO,CAAC,SAA8B;AACjD,QAAM,IAAI,MAAM,kCAAkC;AAElD,SAAO,eAAe,SAAS,MAAM,MAAM;AAAA,IACzC,SAAS;AAAA,IACT,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/transpiler/index.ts"],"sourcesContent":["export * from './translation/index';\nexport * from './enumeration/index';\nexport * from './condition/index';\nexport * from './insertion/index';\nexport * from './markdown/index';\nexport * from './nesting/index';\n// export * from './file/index';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/transpiler/index.ts"],"sourcesContent":["export * from './translation/index';\nexport * from './enumeration/index';\nexport * from './condition/index';\nexport * from './insertion/index';\nexport * from './markdown/index';\nexport * from './nesting/index';\nexport type * from './file/index'; // Export type only because of file transpiler is based on node js function and block build\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/insertion/insertion.ts"],"sourcesContent":["import {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\nimport { getInsertionValues } from './getInsertionValues';\n\nexport type InsertionContent<Content = unknown> = TypedNodeModel<\n NodeType.Insertion,\n Content,\n { fields: string[] }\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to identify insertions inside a content.\n *\n * Usage:\n *\n * ```ts\n * insertion('Hi, my name is {{name}} and I am {{age}} years old.')\n * ```\n *\n */\nconst insertion = <Content = unknown>(\n content: Content\n): InsertionContent<Content> => {\n const getInsertions = () => {\n if (typeof content === 'string') {\n return getInsertionValues(content);\n }\n\n let stringContent = undefined;\n\n if (typeof content === 'function') {\n stringContent = content();\n } else if (typeof (content as Promise<string>).then === 'function') {\n stringContent = async () =>\n getInsertionValues(await (content as Promise<string>));\n }\n\n if (typeof stringContent === 'string') {\n return getInsertionValues(stringContent);\n }\n\n try {\n return getInsertionValues(JSON.stringify(content));\n } catch (e) {\n return [];\n }\n };\n\n return formatNodeType(NodeType.Insertion, content, {\n fields: getInsertions(),\n });\n};\n\nexport { insertion as insert };\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,0BAA0B;AAoBnC,MAAM,YAAY,CAChB,YAC8B;AAC9B,QAAM,gBAAgB,MAAM;AAC1B,QAAI,OAAO,YAAY,UAAU;AAC/B,aAAO,mBAAmB,OAAO;AAAA,IACnC;AAEA,QAAI,gBAAgB;AAEpB,QAAI,OAAO,YAAY,YAAY;AACjC,sBAAgB,QAAQ;AAAA,IAC1B,WAAW,OAAQ,QAA4B,SAAS,YAAY;AAClE,sBAAgB,YACd,mBAAmB,MAAO,OAA2B;AAAA,IACzD;AAEA,QAAI,OAAO,kBAAkB,UAAU;AACrC,aAAO,mBAAmB,aAAa;AAAA,IACzC;AAEA,QAAI;AACF,aAAO,mBAAmB,KAAK,UAAU,OAAO,CAAC;AAAA,IACnD,SAAS,GAAG;AACV,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AAEA,SAAO,eAAe,SAAS,WAAW,SAAS;AAAA,IACjD,QAAQ,cAAc;AAAA,EACxB,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/transpiler/insertion/insertion.ts"],"sourcesContent":["import {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\nimport { getInsertionValues } from './getInsertionValues';\n\nexport type InsertionContentConstructer<\n Content = unknown,\n T extends Record<string, any> = {},\n> = TypedNodeModel<NodeType.Insertion, Content, T>;\n\nexport type InsertionContent<Content = unknown> = InsertionContentConstructer<\n Content,\n {\n fields: string[];\n }\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to identify insertions inside a content.\n *\n * Usage:\n *\n * ```ts\n * insertion('Hi, my name is {{name}} and I am {{age}} years old.')\n * ```\n *\n */\nconst insertion = <Content = unknown>(\n content: Content\n): InsertionContent<Content> => {\n const getInsertions = () => {\n if (typeof content === 'string') {\n return getInsertionValues(content);\n }\n\n let stringContent = undefined;\n\n if (typeof content === 'function') {\n stringContent = content();\n } else if (typeof (content as Promise<string>).then === 'function') {\n stringContent = async () =>\n getInsertionValues(await (content as Promise<string>));\n }\n\n if (typeof stringContent === 'string') {\n return getInsertionValues(stringContent);\n }\n\n try {\n return getInsertionValues(JSON.stringify(content));\n } catch (e) {\n return [];\n }\n };\n\n return formatNodeType(NodeType.Insertion, content, {\n fields: getInsertions(),\n });\n};\n\nexport { insertion as insert };\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,0BAA0B;AA0BnC,MAAM,YAAY,CAChB,YAC8B;AAC9B,QAAM,gBAAgB,MAAM;AAC1B,QAAI,OAAO,YAAY,UAAU;AAC/B,aAAO,mBAAmB,OAAO;AAAA,IACnC;AAEA,QAAI,gBAAgB;AAEpB,QAAI,OAAO,YAAY,YAAY;AACjC,sBAAgB,QAAQ;AAAA,IAC1B,WAAW,OAAQ,QAA4B,SAAS,YAAY;AAClE,sBAAgB,YACd,mBAAmB,MAAO,OAA2B;AAAA,IACzD;AAEA,QAAI,OAAO,kBAAkB,UAAU;AACrC,aAAO,mBAAmB,aAAa;AAAA,IACzC;AAEA,QAAI;AACF,aAAO,mBAAmB,KAAK,UAAU,OAAO,CAAC;AAAA,IACnD,SAAS,GAAG;AACV,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AAEA,SAAO,eAAe,SAAS,WAAW,SAAS;AAAA,IACjD,QAAQ,cAAc;AAAA,EACxB,CAAC;AACH;","names":[]}