intlayer-editor 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +51 -135
  2. package/dist/cjs/client/ContentEditionLayout.cjs +21 -13
  3. package/dist/cjs/client/ContentEditionLayout.cjs.map +1 -1
  4. package/dist/cjs/client/ContentEditionLayout.d.ts +1 -0
  5. package/dist/cjs/client/ContentEditorProvider.cjs +47 -0
  6. package/dist/cjs/client/ContentEditorProvider.cjs.map +1 -0
  7. package/dist/cjs/client/ContentEditorProvider.d.ts +23 -0
  8. package/dist/cjs/client/ContentSelectorWrapper.cjs +27 -10
  9. package/dist/cjs/client/ContentSelectorWrapper.cjs.map +1 -1
  10. package/dist/cjs/client/ContentSelectorWrapper.d.ts +2 -2
  11. package/dist/cjs/client/DictionaryEditionDrawer/DictionaryEditionDrawer.cjs +135 -0
  12. package/dist/cjs/client/DictionaryEditionDrawer/DictionaryEditionDrawer.cjs.map +1 -0
  13. package/dist/cjs/client/DictionaryEditionDrawer/DictionaryEditionDrawer.d.ts +28 -0
  14. package/dist/cjs/client/DictionaryEditionDrawer/index.cjs +27 -0
  15. package/dist/cjs/client/DictionaryEditionDrawer/index.cjs.map +1 -0
  16. package/dist/cjs/client/DictionaryEditionDrawer/index.d.ts +9 -0
  17. package/dist/cjs/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.cjs +103 -0
  18. package/dist/cjs/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.cjs.map +1 -0
  19. package/dist/cjs/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.d.ts +32 -0
  20. package/dist/cjs/client/{EditionPanel → DictionaryEditionDrawer}/useEditedContentStore.cjs +19 -11
  21. package/dist/cjs/client/DictionaryEditionDrawer/useEditedContentStore.cjs.map +1 -0
  22. package/dist/cjs/client/{EditionPanel → DictionaryEditionDrawer}/useEditedContentStore.d.ts +1 -1
  23. package/dist/cjs/client/{EditionPanel/useEditionPanelStore.cjs → DictionaryEditionDrawer/useFocusContentStore.cjs} +4 -4
  24. package/dist/cjs/client/DictionaryEditionDrawer/useFocusContentStore.cjs.map +1 -0
  25. package/dist/cjs/client/{EditionPanel/useEditionPanelStore.d.ts → DictionaryEditionDrawer/useFocusContentStore.d.ts} +1 -1
  26. package/dist/cjs/client/DictionaryListDrawer/DictionaryListDrawer.cjs +74 -0
  27. package/dist/cjs/client/DictionaryListDrawer/DictionaryListDrawer.cjs.map +1 -0
  28. package/dist/cjs/client/DictionaryListDrawer/DictionaryListDrawer.d.ts +5 -0
  29. package/dist/cjs/client/{EditionPanel → DictionaryListDrawer}/index.cjs +6 -8
  30. package/dist/cjs/client/DictionaryListDrawer/index.cjs.map +1 -0
  31. package/dist/cjs/client/DictionaryListDrawer/index.d.ts +3 -0
  32. package/dist/cjs/client/{renderContentSelector.cjs → DictionaryListDrawer/useDictionaryListDrawer.cjs} +11 -17
  33. package/dist/cjs/client/DictionaryListDrawer/useDictionaryListDrawer.cjs.map +1 -0
  34. package/dist/cjs/client/DictionaryListDrawer/useDictionaryListDrawer.d.ts +8 -0
  35. package/dist/cjs/client/index.cjs +9 -5
  36. package/dist/cjs/client/index.cjs.map +1 -1
  37. package/dist/cjs/client/index.d.ts +9 -7
  38. package/dist/cjs/client/renderContentEditor.cjs +48 -0
  39. package/dist/cjs/client/renderContentEditor.cjs.map +1 -0
  40. package/dist/cjs/client/renderContentEditor.d.ts +15 -0
  41. package/dist/cjs/client/useEditorServer.cjs +5 -2
  42. package/dist/cjs/client/useEditorServer.cjs.map +1 -1
  43. package/dist/cjs/server/formatPrettier.cjs +51 -0
  44. package/dist/cjs/server/formatPrettier.cjs.map +1 -0
  45. package/dist/cjs/server/formatPrettier.d.ts +6 -0
  46. package/dist/cjs/server/index.cjs +2 -2
  47. package/dist/cjs/server/index.cjs.map +1 -1
  48. package/dist/cjs/server/{content-editor.cjs → processEdition.cjs} +69 -68
  49. package/dist/cjs/server/processEdition.cjs.map +1 -0
  50. package/dist/cjs/server/processEdition.d.ts +12 -0
  51. package/dist/esm/client/ContentEditionLayout.d.mts +1 -0
  52. package/dist/esm/client/ContentEditionLayout.mjs +21 -13
  53. package/dist/esm/client/ContentEditionLayout.mjs.map +1 -1
  54. package/dist/esm/client/ContentEditorProvider.d.mts +23 -0
  55. package/dist/esm/client/ContentEditorProvider.mjs +24 -0
  56. package/dist/esm/client/ContentEditorProvider.mjs.map +1 -0
  57. package/dist/esm/client/ContentSelectorWrapper.d.mts +2 -2
  58. package/dist/esm/client/ContentSelectorWrapper.mjs +27 -10
  59. package/dist/esm/client/ContentSelectorWrapper.mjs.map +1 -1
  60. package/dist/esm/client/DictionaryEditionDrawer/DictionaryEditionDrawer.d.mts +28 -0
  61. package/dist/esm/client/DictionaryEditionDrawer/DictionaryEditionDrawer.mjs +104 -0
  62. package/dist/esm/client/DictionaryEditionDrawer/DictionaryEditionDrawer.mjs.map +1 -0
  63. package/dist/esm/client/DictionaryEditionDrawer/index.d.mts +9 -0
  64. package/dist/esm/client/DictionaryEditionDrawer/index.mjs +4 -0
  65. package/dist/esm/client/DictionaryEditionDrawer/index.mjs.map +1 -0
  66. package/dist/esm/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.d.mts +32 -0
  67. package/dist/esm/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.mjs +80 -0
  68. package/dist/esm/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.mjs.map +1 -0
  69. package/dist/esm/client/{EditionPanel → DictionaryEditionDrawer}/useEditedContentStore.d.mts +1 -1
  70. package/dist/esm/client/{EditionPanel → DictionaryEditionDrawer}/useEditedContentStore.mjs +17 -9
  71. package/dist/esm/client/DictionaryEditionDrawer/useEditedContentStore.mjs.map +1 -0
  72. package/dist/esm/client/{EditionPanel/useEditionPanelStore.d.mts → DictionaryEditionDrawer/useFocusContentStore.d.mts} +1 -1
  73. package/dist/esm/client/{EditionPanel/useEditionPanelStore.mjs → DictionaryEditionDrawer/useFocusContentStore.mjs} +1 -1
  74. package/dist/esm/client/DictionaryEditionDrawer/useFocusContentStore.mjs.map +1 -0
  75. package/dist/esm/client/DictionaryListDrawer/DictionaryListDrawer.d.mts +5 -0
  76. package/dist/esm/client/DictionaryListDrawer/DictionaryListDrawer.mjs +46 -0
  77. package/dist/esm/client/DictionaryListDrawer/DictionaryListDrawer.mjs.map +1 -0
  78. package/dist/esm/client/DictionaryListDrawer/index.d.mts +3 -0
  79. package/dist/esm/client/DictionaryListDrawer/index.mjs +3 -0
  80. package/dist/esm/client/DictionaryListDrawer/index.mjs.map +1 -0
  81. package/dist/esm/client/DictionaryListDrawer/useDictionaryListDrawer.d.mts +8 -0
  82. package/dist/esm/client/DictionaryListDrawer/useDictionaryListDrawer.mjs +8 -0
  83. package/dist/esm/client/DictionaryListDrawer/useDictionaryListDrawer.mjs.map +1 -0
  84. package/dist/esm/client/index.d.mts +9 -7
  85. package/dist/esm/client/index.mjs +4 -2
  86. package/dist/esm/client/index.mjs.map +1 -1
  87. package/dist/esm/client/renderContentEditor.d.mts +15 -0
  88. package/dist/esm/client/renderContentEditor.mjs +24 -0
  89. package/dist/esm/client/renderContentEditor.mjs.map +1 -0
  90. package/dist/esm/client/useEditorServer.mjs +5 -2
  91. package/dist/esm/client/useEditorServer.mjs.map +1 -1
  92. package/dist/esm/server/formatPrettier.d.mts +6 -0
  93. package/dist/esm/server/formatPrettier.mjs +17 -0
  94. package/dist/esm/server/formatPrettier.mjs.map +1 -0
  95. package/dist/esm/server/index.mjs +2 -2
  96. package/dist/esm/server/index.mjs.map +1 -1
  97. package/dist/esm/server/processEdition.d.mts +12 -0
  98. package/dist/esm/server/processEdition.mjs +134 -0
  99. package/dist/esm/server/processEdition.mjs.map +1 -0
  100. package/package.json +17 -18
  101. package/dist/cjs/client/EditionPanel/EditionPanel.cjs +0 -101
  102. package/dist/cjs/client/EditionPanel/EditionPanel.cjs.map +0 -1
  103. package/dist/cjs/client/EditionPanel/EditionPanel.d.ts +0 -11
  104. package/dist/cjs/client/EditionPanel/index.cjs.map +0 -1
  105. package/dist/cjs/client/EditionPanel/index.d.ts +0 -9
  106. package/dist/cjs/client/EditionPanel/useEditedContentStore.cjs.map +0 -1
  107. package/dist/cjs/client/EditionPanel/useEditionPanelStore.cjs.map +0 -1
  108. package/dist/cjs/client/renderContentSelector.cjs.map +0 -1
  109. package/dist/cjs/client/renderContentSelector.d.ts +0 -6
  110. package/dist/cjs/server/content-editor.cjs.map +0 -1
  111. package/dist/cjs/server/content-editor.d.ts +0 -12
  112. package/dist/esm/client/EditionPanel/EditionPanel.d.mts +0 -11
  113. package/dist/esm/client/EditionPanel/EditionPanel.mjs +0 -72
  114. package/dist/esm/client/EditionPanel/EditionPanel.mjs.map +0 -1
  115. package/dist/esm/client/EditionPanel/index.d.mts +0 -9
  116. package/dist/esm/client/EditionPanel/index.mjs +0 -4
  117. package/dist/esm/client/EditionPanel/index.mjs.map +0 -1
  118. package/dist/esm/client/EditionPanel/useEditedContentStore.mjs.map +0 -1
  119. package/dist/esm/client/EditionPanel/useEditionPanelStore.mjs.map +0 -1
  120. package/dist/esm/client/renderContentSelector.d.mts +0 -6
  121. package/dist/esm/client/renderContentSelector.mjs +0 -15
  122. package/dist/esm/client/renderContentSelector.mjs.map +0 -1
  123. package/dist/esm/server/content-editor.d.mts +0 -12
  124. package/dist/esm/server/content-editor.mjs +0 -123
  125. package/dist/esm/server/content-editor.mjs.map +0 -1
  126. package/src/client/ContentEditionLayout.tsx +0 -26
  127. package/src/client/ContentSelectorWrapper.tsx +0 -38
  128. package/src/client/EditionPanel/EditionPanel.tsx +0 -90
  129. package/src/client/EditionPanel/index.ts +0 -3
  130. package/src/client/EditionPanel/useEditedContentStore.ts +0 -98
  131. package/src/client/EditionPanel/useEditionPanelStore.ts +0 -19
  132. package/src/client/index.ts +0 -4
  133. package/src/client/renderContentSelector.tsx +0 -17
  134. package/src/client/useEditorServer.ts +0 -31
  135. package/src/server/content-editor.ts +0 -209
  136. package/src/server/index.ts +0 -40
@@ -0,0 +1,12 @@
1
+ import { EditedContent } from '../client/DictionaryEditionDrawer/useEditedContentStore.mjs';
2
+ import 'zustand/middleware';
3
+ import 'zustand';
4
+ import '@intlayer/core';
5
+ import '@intlayer/design-system';
6
+
7
+ /**
8
+ * Edit the content of a file based on the key path and new value
9
+ */
10
+ declare const processEdition: (editedContent: EditedContent) => Promise<void>;
11
+
12
+ export { processEdition };
@@ -0,0 +1,134 @@
1
+ import { readFileSync, writeFileSync } from "fs";
2
+ import { createRequire } from "module";
3
+ import { parse } from "@babel/parser";
4
+ import {
5
+ NodeType
6
+ } from "@intlayer/core";
7
+ import { format } from './formatPrettier.mjs';
8
+ const requireFunction = typeof import.meta.url === "undefined" ? require : createRequire(import.meta.url);
9
+ const { default: generate } = requireFunction("@babel/generator");
10
+ const findNestedProperty = (obj, keyPath) => {
11
+ let currentObj = obj;
12
+ for (const key of keyPath) {
13
+ const nextProperty = getNextProperty(currentObj, key);
14
+ if (!nextProperty)
15
+ throw new Error("Could not find the specified key path.");
16
+ currentObj = nextProperty;
17
+ }
18
+ return currentObj;
19
+ };
20
+ const getNextProperty = (obj, key) => {
21
+ if (key.type === "ObjectExpression") {
22
+ return findInObjectExpression(
23
+ obj,
24
+ key
25
+ );
26
+ }
27
+ if (key.type === "ArrayExpression") {
28
+ return obj.elements[key.key];
29
+ }
30
+ if (Object.values(NodeType).includes(key.type)) {
31
+ return findInTranslationOrEnumerationNode(
32
+ obj,
33
+ key
34
+ );
35
+ }
36
+ return void 0;
37
+ };
38
+ const findInObjectExpression = (obj, key) => {
39
+ const result = obj.properties.find(
40
+ (prop) => "key" in prop && prop.key.name === key.key
41
+ );
42
+ return result && "value" in result ? result.value : void 0;
43
+ };
44
+ const findInTranslationOrEnumerationNode = (obj, key) => {
45
+ const argument = obj.arguments[0];
46
+ const identifierResult = argument.properties.find(
47
+ (prop) => "key" in prop && prop.key.name === key.key
48
+ );
49
+ const stringResult = identifierResult.value;
50
+ return stringResult ? identifierResult : identifierResult && "name" in identifierResult ? identifierResult.name : void 0;
51
+ };
52
+ const findAndUpdate = (objExpr, keyPath, newValue) => {
53
+ const lastKey = keyPath[keyPath.length - 1];
54
+ if (lastKey) {
55
+ const propertyToUpdate = findNestedProperty(objExpr, keyPath);
56
+ if (!propertyToUpdate) {
57
+ throw new Error("Could not find the specified key path.");
58
+ }
59
+ if ("value" in propertyToUpdate) {
60
+ propertyToUpdate.value.value = newValue;
61
+ }
62
+ }
63
+ };
64
+ const traverseNode = (node, keyPath, newValue) => {
65
+ if (Array.isArray(node.body)) {
66
+ node.body.forEach(
67
+ (subNode) => traverseNode(subNode, keyPath, newValue)
68
+ );
69
+ } else if (node.body) {
70
+ traverseNode(node.body, keyPath, newValue);
71
+ }
72
+ if (
73
+ // For ES Module (e.g., `const variable = ...; export default variable`)
74
+ "declarations" in node
75
+ ) {
76
+ node.declarations.forEach((declaration) => {
77
+ if (declaration.init?.type === "ObjectExpression") {
78
+ findAndUpdate(declaration.init, keyPath, newValue);
79
+ }
80
+ });
81
+ }
82
+ if (
83
+ // For ES Module (e.g., `export default { ... }`)
84
+ "declaration" in node && node.declaration.type === "ObjectExpression"
85
+ ) {
86
+ return findAndUpdate(
87
+ node.declaration,
88
+ keyPath,
89
+ newValue
90
+ );
91
+ }
92
+ if (
93
+ // For CommonJS (e.g., `module.exports = ...`)
94
+ "expression" in node && node.expression.right.type === "ObjectExpression"
95
+ ) {
96
+ return findAndUpdate(
97
+ node.expression.right,
98
+ keyPath,
99
+ newValue
100
+ );
101
+ }
102
+ };
103
+ const processEdition = async (editedContent) => {
104
+ for (const dictionaryPath of Object.keys(editedContent)) {
105
+ const fileContent = readFileSync(dictionaryPath, "utf-8");
106
+ const parsedBase = parseFileContent(fileContent);
107
+ const parsed = parseFileContent(fileContent);
108
+ for (const { keyPath, newValue } of editedContent[dictionaryPath]) {
109
+ traverseNode(parsed.program, keyPath, newValue);
110
+ }
111
+ await writeUpdatedContent(dictionaryPath, parsedBase, parsed);
112
+ }
113
+ };
114
+ const parseFileContent = (fileContent) => parse(fileContent, {
115
+ sourceType: "module",
116
+ plugins: ["jsx", "typescript"]
117
+ });
118
+ const writeUpdatedContent = async (dictionaryPath, parsedBase, parsed) => {
119
+ const baseContent = generate(parsedBase).code;
120
+ const updatedContent = generate(parsed).code;
121
+ if (baseContent === updatedContent) {
122
+ console.info(
123
+ `No change made on the dictionary - dictionaryPath: ${dictionaryPath}.`
124
+ );
125
+ } else {
126
+ const formattedContent = await format(updatedContent);
127
+ writeFileSync(dictionaryPath, formattedContent, "utf-8");
128
+ console.info("Updated the file successfully.");
129
+ }
130
+ };
131
+ export {
132
+ processEdition
133
+ };
134
+ //# sourceMappingURL=processEdition.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/server/processEdition.ts"],"sourcesContent":["/* eslint-disable sonarjs/cognitive-complexity */\nimport { readFileSync, writeFileSync } from 'fs';\nimport { createRequire } from 'module';\nimport { parse } from '@babel/parser';\nimport type {\n ObjectExpression,\n VariableDeclarator,\n Program,\n Identifier,\n StringLiteral,\n AssignmentExpression,\n ObjectProperty,\n CallExpression,\n ArrayExpression,\n} from '@babel/types';\nimport {\n NodeType,\n type KeyPath,\n type ArrayExpressionNode,\n type ObjectExpressionNode,\n type TranslationOrEnumerationNode,\n} from '@intlayer/core';\nimport type { EditedContent } from '../client/index';\nimport { format } from './formatPrettier';\n\nconst requireFunction =\n typeof import.meta.url === 'undefined'\n ? require\n : createRequire(import.meta.url);\n\nconst { default: generate } = requireFunction('@babel/generator');\n\ntype ObjectOrArrayExpression = ObjectExpression | ArrayExpression;\n\n/**\n * Helper function to find a nested property in an ObjectExpression based on a key path\n */\nconst findNestedProperty = (\n obj: ObjectOrArrayExpression,\n keyPath: KeyPath[]\n): ObjectOrArrayExpression | undefined => {\n let currentObj: ObjectOrArrayExpression = obj;\n\n for (const key of keyPath) {\n const nextProperty = getNextProperty(currentObj, key);\n\n if (!nextProperty)\n throw new Error('Could not find the specified key path.');\n\n currentObj = nextProperty;\n }\n\n return currentObj;\n};\n\nconst getNextProperty = (\n obj: ObjectOrArrayExpression,\n key: KeyPath\n): ObjectOrArrayExpression | undefined => {\n if ((key as ObjectExpressionNode).type === 'ObjectExpression') {\n return findInObjectExpression(\n obj as ObjectExpression,\n key as ObjectExpressionNode\n );\n }\n\n if ((key as ArrayExpressionNode).type === 'ArrayExpression') {\n return (obj as ArrayExpression).elements[\n (key as ArrayExpressionNode).key\n ] as ObjectOrArrayExpression;\n }\n\n if (\n Object.values(NodeType).includes((key as TranslationOrEnumerationNode).type)\n ) {\n return findInTranslationOrEnumerationNode(\n obj as unknown as CallExpression,\n key as TranslationOrEnumerationNode\n );\n }\n\n return undefined;\n};\n\nconst findInObjectExpression = (\n obj: ObjectExpression,\n key: ObjectExpressionNode\n): ObjectOrArrayExpression | undefined => {\n const result = obj.properties.find(\n (prop) => 'key' in prop && (prop.key as Identifier).name === key.key\n );\n\n return result && 'value' in result\n ? (result.value as ObjectOrArrayExpression)\n : undefined;\n};\n\nconst findInTranslationOrEnumerationNode = (\n obj: CallExpression,\n key: TranslationOrEnumerationNode\n): ObjectOrArrayExpression | undefined => {\n const argument = obj.arguments[0] as ObjectExpression;\n const identifierResult = argument.properties.find(\n (prop) => 'key' in prop && (prop.key as Identifier).name === key.key\n ) as ObjectProperty;\n\n const stringResult = identifierResult.value as StringLiteral;\n\n return stringResult\n ? (identifierResult as unknown as ObjectOrArrayExpression)\n : identifierResult && 'name' in identifierResult\n ? (identifierResult.name as ObjectOrArrayExpression)\n : undefined;\n};\n\n/**\n * Find and update specific content based on key path\n */\nconst findAndUpdate = (\n objExpr: ObjectExpression,\n keyPath: KeyPath[],\n newValue: string\n) => {\n const lastKey = keyPath[keyPath.length - 1]; // Get the last key in the path\n\n if (lastKey) {\n const propertyToUpdate = findNestedProperty(objExpr, keyPath); // Traverse the key path\n\n if (!propertyToUpdate) {\n throw new Error('Could not find the specified key path.');\n }\n\n if ('value' in propertyToUpdate) {\n (propertyToUpdate.value as StringLiteral).value = newValue; // Update the value of the specified key\n }\n }\n};\n\n/**\n * Traverse the AST and update based on key path and new value\n */\nconst traverseNode = (node: Program, keyPath: KeyPath[], newValue: string) => {\n if (Array.isArray(node.body)) {\n node.body.forEach((subNode) =>\n traverseNode(subNode as unknown as Program, keyPath, newValue)\n );\n } else if (node.body) {\n traverseNode(node.body as Program, keyPath, newValue);\n }\n\n if (\n // For ES Module (e.g., `const variable = ...; export default variable`)\n 'declarations' in node\n ) {\n (node.declarations as VariableDeclarator[]).forEach((declaration) => {\n if (declaration.init?.type === 'ObjectExpression') {\n findAndUpdate(declaration.init, keyPath, newValue);\n }\n });\n }\n\n if (\n // For ES Module (e.g., `export default { ... }`)\n 'declaration' in node &&\n (node.declaration as ObjectExpression).type === 'ObjectExpression'\n ) {\n return findAndUpdate(\n node.declaration as ObjectExpression,\n keyPath,\n newValue\n );\n }\n\n if (\n // For CommonJS (e.g., `module.exports = ...`)\n 'expression' in node &&\n (node.expression as AssignmentExpression).right.type === 'ObjectExpression'\n ) {\n return findAndUpdate(\n (node.expression as AssignmentExpression).right as ObjectExpression,\n keyPath,\n newValue\n );\n }\n};\n\n/**\n * Edit the content of a file based on the key path and new value\n */\nexport const processEdition = async (editedContent: EditedContent) => {\n for (const dictionaryPath of Object.keys(editedContent)) {\n const fileContent = readFileSync(dictionaryPath, 'utf-8');\n const parsedBase = parseFileContent(fileContent);\n const parsed = parseFileContent(fileContent);\n\n for (const { keyPath, newValue } of editedContent[dictionaryPath]) {\n traverseNode(parsed.program, keyPath, newValue);\n }\n\n await writeUpdatedContent(dictionaryPath, parsedBase, parsed);\n }\n};\n\nconst parseFileContent = (fileContent: string) =>\n parse(fileContent, {\n sourceType: 'module',\n plugins: ['jsx', 'typescript'],\n });\n\nconst writeUpdatedContent = async (\n dictionaryPath: string,\n parsedBase: ReturnType<typeof parseFileContent>,\n parsed: ReturnType<typeof parseFileContent>\n) => {\n const baseContent = generate(parsedBase).code;\n const updatedContent = generate(parsed).code;\n\n if (baseContent === updatedContent) {\n console.info(\n `No change made on the dictionary - dictionaryPath: ${dictionaryPath}.`\n );\n } else {\n const formattedContent = await format(updatedContent);\n writeFileSync(dictionaryPath, formattedContent, 'utf-8');\n console.info('Updated the file successfully.');\n }\n};\n"],"mappings":"AACA,SAAS,cAAc,qBAAqB;AAC5C,SAAS,qBAAqB;AAC9B,SAAS,aAAa;AAYtB;AAAA,EACE;AAAA,OAKK;AAEP,SAAS,cAAc;AAEvB,MAAM,kBACJ,OAAO,YAAY,QAAQ,cACvB,UACA,cAAc,YAAY,GAAG;AAEnC,MAAM,EAAE,SAAS,SAAS,IAAI,gBAAgB,kBAAkB;AAOhE,MAAM,qBAAqB,CACzB,KACA,YACwC;AACxC,MAAI,aAAsC;AAE1C,aAAW,OAAO,SAAS;AACzB,UAAM,eAAe,gBAAgB,YAAY,GAAG;AAEpD,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,wCAAwC;AAE1D,iBAAa;AAAA,EACf;AAEA,SAAO;AACT;AAEA,MAAM,kBAAkB,CACtB,KACA,QACwC;AACxC,MAAK,IAA6B,SAAS,oBAAoB;AAC7D,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,MAAK,IAA4B,SAAS,mBAAmB;AAC3D,WAAQ,IAAwB,SAC7B,IAA4B,GAC/B;AAAA,EACF;AAEA,MACE,OAAO,OAAO,QAAQ,EAAE,SAAU,IAAqC,IAAI,GAC3E;AACA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,yBAAyB,CAC7B,KACA,QACwC;AACxC,QAAM,SAAS,IAAI,WAAW;AAAA,IAC5B,CAAC,SAAS,SAAS,QAAS,KAAK,IAAmB,SAAS,IAAI;AAAA,EACnE;AAEA,SAAO,UAAU,WAAW,SACvB,OAAO,QACR;AACN;AAEA,MAAM,qCAAqC,CACzC,KACA,QACwC;AACxC,QAAM,WAAW,IAAI,UAAU,CA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1C;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAKO,MAAM,iBAAiB,OAAO,kBAAiC;AACpE,aAAW,kBAAkB,OAAO,KAAK,aAAa,GAAG;AACvD,UAAM,cAAc,aAAa,gBAAgB,OAAO;AACxD,UAAM,aAAa,iBAAiB,WAAW;AAC/C,UAAM,SAAS,iBAAiB,WAAW;AAE3C,eAAW,EAAE,SAAS,SAAS,KAAK,cAAc,cAAc,GAAG;AACjE,mBAAa,OAAO,SAAS,SAAS,QAAQ;AAAA,IAChD;AAEA,UAAM,oBAAoB,gBAAgB,YAAY,MAAM;AAAA,EAC9D;AACF;AAEA,MAAM,mBAAmB,CAAC,gBACxB,MAAM,aAAa;AAAA,EACjB,YAAY;AAAA,EACZ,SAAS,CAAC,OAAO,YAAY;AAC/B,CAAC;AAEH,MAAM,sBAAsB,OAC1B,gBACA,YACA,WACG;AACH,QAAM,cAAc,SAAS,UAAU,EAAE;AACzC,QAAM,iBAAiB,SAAS,MAAM,EAAE;AAExC,MAAI,gBAAgB,gBAAgB;AAClC,YAAQ;AAAA,MACN,sDAAsD,cAAc;AAAA,IACtE;AAAA,EACF,OAAO;AACL,UAAM,mBAAmB,MAAM,OAAO,cAAc;AACpD,kBAAc,gBAAgB,kBAAkB,OAAO;AACvD,YAAQ,KAAK,gCAAgC;AAAA,EAC/C;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intlayer-editor",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "private": false,
5
5
  "description": "IntLayer Editor is a tool that allow you to edit your IntLayer declaration files using a graphical interface.",
6
6
  "keywords": [
@@ -47,26 +47,25 @@
47
47
  },
48
48
  "files": [
49
49
  "./dist",
50
- "./src",
51
50
  "./bin",
52
51
  "./package.json"
53
52
  ],
54
53
  "dependencies": {
55
54
  "@types/body-parser": "^1.19.5",
56
55
  "body-parser": "^1.20.2",
57
- "commander": "^12.0.0",
56
+ "commander": "^12.1.0",
58
57
  "express": "^4.19.2",
59
58
  "lucide-react": "^0.376.0",
60
59
  "magic-regexp": "^0.8.0",
61
- "react": "^18.2.0",
62
- "react-dom": "^18.2.0",
63
- "webpack": "^5.91.0",
60
+ "react": "^18.3.1",
61
+ "react-dom": "^18.3.1",
62
+ "webpack": "^5.92.1",
64
63
  "zustand": "^4.5.2",
65
- "@intlayer/config": "^2.0.0",
66
- "@intlayer/core": "^2.0.0",
67
- "@intlayer/design-system": "^2.0.0",
68
- "@intlayer/dictionaries-entry": "^2.0.0",
69
- "intlayer": "^2.0.0"
64
+ "@intlayer/config": "^2.0.2",
65
+ "@intlayer/core": "^2.0.2",
66
+ "@intlayer/design-system": "^2.0.2",
67
+ "@intlayer/dictionaries-entry": "^2.0.2",
68
+ "intlayer": "^2.0.2"
70
69
  },
71
70
  "devDependencies": {
72
71
  "@babel/generator": "7.24.4",
@@ -76,15 +75,15 @@
76
75
  "@changesets/cli": "2.27.1",
77
76
  "@types/babel__generator": "^7.6.8",
78
77
  "@types/express": "^4.17.21",
79
- "@types/node": "^20.12.7",
80
- "@types/react": "^18.2.79",
81
- "@types/react-dom": "^18.2.25",
78
+ "@types/node": "^20.14.9",
79
+ "@types/react": "^18.3.3",
80
+ "@types/react-dom": "^18.3.0",
82
81
  "rimraf": "5.0.5",
83
82
  "ts-node": "^10.9.2",
84
- "tsup": "^8.0.2",
85
- "typescript": "^5.4.5",
86
- "@utils/eslint-config": "^1.0.1",
87
- "@utils/ts-config": "^1.0.1"
83
+ "tsup": "^8.1.0",
84
+ "typescript": "^5.5.2",
85
+ "@utils/eslint-config": "^1.0.2",
86
+ "@utils/ts-config": "^1.0.2"
88
87
  },
89
88
  "engines": {
90
89
  "node": ">=14.18"
@@ -1,101 +0,0 @@
1
- "use strict";
2
- "use client";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var EditionPanel_exports = {};
31
- __export(EditionPanel_exports, {
32
- EditionPanel: () => EditionPanel
33
- });
34
- module.exports = __toCommonJS(EditionPanel_exports);
35
- var import_jsx_runtime = require("react/jsx-runtime");
36
- var import_design_system = require("@intlayer/design-system");
37
- var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
38
- var import_react = require("react");
39
- var import_useEditorServer = require('../useEditorServer.cjs');
40
- var import_useEditedContentStore = require('./useEditedContentStore.cjs');
41
- var import_useEditionPanelStore = require('./useEditionPanelStore.cjs');
42
- const EditionPanel = ({
43
- locale,
44
- localeList,
45
- setLocale
46
- }) => {
47
- const { open } = (0, import_design_system.useRightDrawerStore)();
48
- const { focusedContent, setFocusedContent } = (0, import_useEditionPanelStore.useEditionPanelStore)();
49
- const { editedContent, addEditedContent, clearEditedDictionaryContent } = (0, import_useEditedContentStore.useEditedContentStore)();
50
- const { editContentRequest } = (0, import_useEditorServer.useEditorServer)();
51
- (0, import_react.useEffect)(() => {
52
- if (focusedContent !== null) {
53
- open();
54
- }
55
- }, [focusedContent, open]);
56
- if (!focusedContent) {
57
- return null;
58
- }
59
- const dictionary = import_dictionaries_entry.default[focusedContent.dictionaryId];
60
- if (!dictionary?.filePath) {
61
- return null;
62
- }
63
- const dictionaryPath = dictionary.filePath;
64
- const editedDictionaryContent = editedContent[dictionaryPath] ?? [];
65
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
66
- import_design_system.RightDrawer,
67
- {
68
- title: dictionary.id,
69
- label: `Edit dictionary ${dictionary.id}`,
70
- header: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
71
- import_design_system.LocaleSwitcher,
72
- {
73
- setLocale,
74
- locale,
75
- localeList
76
- }
77
- ),
78
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
79
- import_design_system.DictionaryEditor,
80
- {
81
- dictionary,
82
- locale,
83
- focusedKeyPath: focusedContent.keyPath,
84
- editedContent: editedDictionaryContent,
85
- onFocusKeyPath: (keyPath) => setFocusedContent({ ...focusedContent, keyPath }),
86
- onContentChange: (keyPath, newValue) => addEditedContent(dictionaryPath, keyPath, newValue),
87
- onValidEdition: editContentRequest,
88
- onCancelEdition: () => {
89
- clearEditedDictionaryContent(dictionaryPath);
90
- setFocusedContent(null);
91
- }
92
- }
93
- )
94
- }
95
- );
96
- };
97
- // Annotate the CommonJS export names for ESM import in node:
98
- 0 && (module.exports = {
99
- EditionPanel
100
- });
101
- //# sourceMappingURL=EditionPanel.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/client/EditionPanel/EditionPanel.tsx"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { ContentModule } from '@intlayer/core';\nimport {\n useRightDrawerStore,\n RightDrawer,\n DictionaryEditor,\n LocaleSwitcher,\n} from '@intlayer/design-system';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport { type FC, useEffect } from 'react';\nimport { useEditorServer } from '../useEditorServer';\nimport { useEditedContentStore } from './useEditedContentStore';\nimport { useEditionPanelStore } from './useEditionPanelStore';\n\ntype EditionPanelProps = {\n locale: Locales;\n localeList: Locales[];\n setLocale: (locale: Locales) => void;\n};\n\nexport const EditionPanel: FC<EditionPanelProps> = ({\n locale,\n localeList,\n setLocale,\n}) => {\n const { open } = useRightDrawerStore();\n const { focusedContent, setFocusedContent } = useEditionPanelStore();\n const { editedContent, addEditedContent, clearEditedDictionaryContent } =\n useEditedContentStore();\n const { editContentRequest } = useEditorServer();\n\n // Use effect to react to changes in focusedContent\n useEffect(() => {\n if (focusedContent !== null) {\n open(); // Call the open function from useRightDrawerStore\n }\n }, [focusedContent, open]); // Depend on focusedContent and open to trigger the effect\n\n if (!focusedContent) {\n return null;\n }\n\n const dictionary: ContentModule = dictionaries[focusedContent.dictionaryId];\n\n if (!dictionary?.filePath) {\n return null;\n }\n\n const dictionaryPath = dictionary.filePath;\n const editedDictionaryContent = editedContent[dictionaryPath] ?? [];\n\n return (\n <RightDrawer\n title={dictionary.id}\n label={`Edit dictionary ${dictionary.id}`}\n header={\n <LocaleSwitcher\n setLocale={setLocale}\n locale={locale}\n localeList={localeList}\n />\n }\n >\n <DictionaryEditor\n dictionary={dictionary}\n locale={locale}\n focusedKeyPath={focusedContent.keyPath}\n editedContent={editedDictionaryContent}\n onFocusKeyPath={(keyPath) =>\n setFocusedContent({ ...focusedContent, keyPath })\n }\n onContentChange={(keyPath, newValue) =>\n addEditedContent(dictionaryPath, keyPath, newValue)\n }\n onValidEdition={editContentRequest}\n onCancelEdition={() => {\n clearEditedDictionaryContent(dictionaryPath);\n setFocusedContent(null);\n }}\n />\n </RightDrawer>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;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;AAAA;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;","names":["dictionaries"]}
@@ -1,11 +0,0 @@
1
- import { Locales } from '@intlayer/config/client';
2
- import { FC } from 'react';
3
-
4
- type EditionPanelProps = {
5
- locale: Locales;
6
- localeList: Locales[];
7
- setLocale: (locale: Locales) => void;
8
- };
9
- declare const EditionPanel: FC<EditionPanelProps>;
10
-
11
- export { EditionPanel };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/client/EditionPanel/index.ts"],"sourcesContent":["export * from './EditionPanel';\nexport * from './useEditionPanelStore';\nexport * from './useEditedContentStore';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,iCAAc,2BAAd;AACA,iCAAc,mCADd;AAEA,iCAAc,oCAFd;","names":[]}
@@ -1,9 +0,0 @@
1
- export { EditionPanel } from './EditionPanel.js';
2
- export { useEditionPanelStore } from './useEditionPanelStore.js';
3
- export { EditedContent, useEditedContentStore } from './useEditedContentStore.js';
4
- import '@intlayer/config/client';
5
- import 'react';
6
- import 'zustand';
7
- import '@intlayer/core';
8
- import 'zustand/middleware';
9
- import '@intlayer/design-system';
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/client/EditionPanel/useEditedContentStore.ts"],"sourcesContent":["import type { KeyPath } from '@intlayer/core';\nimport type { FileContent } from '@intlayer/design-system';\nimport { create } from 'zustand';\nimport { persist, createJSONStorage } from 'zustand/middleware';\n\ntype DictionaryPath = string;\n\nexport type EditedContent = Record<DictionaryPath, FileContent[]>;\n\ntype EditedContentStore = {\n editedContent: EditedContent;\n addEditedContent: (\n dictionaryPath: DictionaryPath,\n keyPath: KeyPath[],\n newValue: string\n ) => void;\n removeEditedContent: (\n dictionaryPath: DictionaryPath,\n keyPath: KeyPath[]\n ) => void;\n clearEditedDictionaryContent: (dictionaryPath: DictionaryPath) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n dictionaryPath: DictionaryPath,\n keyPath: KeyPath[]\n ) => string | undefined;\n};\n\nconst isSameKeyPath = (keyPath1: KeyPath[], keyPath2: KeyPath[]) =>\n keyPath1.every(\n (element, index) =>\n keyPath2[index] &&\n keyPath2[index].key === element.key &&\n keyPath2[index].type === element.type\n );\n\nexport const useEditedContentStore = create(\n persist<EditedContentStore>(\n (set, get) => ({\n editedContent: {},\n addEditedContent: (dictionaryPath, keyPath, newValue) => {\n set((state) => {\n const editedContent = state.editedContent[dictionaryPath] ?? [];\n return {\n editedContent: {\n ...state.editedContent,\n [dictionaryPath]: [\n ...editedContent.filter(\n (content) => !isSameKeyPath(content.keyPath, keyPath)\n ),\n {\n keyPath,\n newValue,\n },\n ],\n },\n };\n });\n },\n\n removeEditedContent: (dictionaryPath, keyPath) => {\n set((state) => {\n const editedContent = state.editedContent[dictionaryPath] ?? [];\n return {\n editedContent: {\n ...state.editedContent,\n [dictionaryPath]: editedContent.filter(\n (content) => content.keyPath !== keyPath\n ),\n },\n };\n });\n },\n\n clearEditedDictionaryContent: (dictionaryPath) => {\n set((state) => ({\n editedContent: {\n ...state.editedContent,\n [dictionaryPath]: [],\n },\n }));\n },\n\n clearEditedContent: () => {\n set({ editedContent: {} });\n },\n\n getEditedContentValue: (dictionaryPath, keyPath): string | undefined =>\n get().editedContent[dictionaryPath]?.find((content) =>\n isSameKeyPath(content.keyPath, keyPath)\n )?.newValue,\n }),\n {\n name: 'edited-content-store',\n storage: createJSONStorage(() => sessionStorage),\n }\n )\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAAuB;AACvB,wBAA2C;AAyB3C,MAAM,gBAAgB,CAAC,UAAqB,aAC1C,SAAS;AAAA,EACP,CAAC,SAAS,UACR,SAAS,KAAK,KACd,SAAS,KAAK,EAAE,QAAQ,QAAQ,OAChC,SAAS,KAAK,EAAE,SAAS,QAAQ;AACrC;AAEK,MAAM,4BAAwB;AAAA,MACnC;AAAA,IACE,CAAC,KAAK,SAAS;AAAA,MACb,eAAe,CAAC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 @@
1
- {"version":3,"sources":["../../../../src/client/EditionPanel/useEditionPanelStore.ts"],"sourcesContent":["import type { KeyPath } from '@intlayer/core';\nimport { create } from 'zustand';\n\ntype DictionaryPath = string;\ntype FileContent = {\n dictionaryPath: DictionaryPath;\n dictionaryId: string;\n keyPath: KeyPath[];\n};\n\ntype EditionPanelStore = {\n focusedContent: FileContent | null;\n setFocusedContent: (content: FileContent | null) => void;\n};\n\nexport const useEditionPanelStore = create<EditionPanelStore>((set) => ({\n focusedContent: null,\n setFocusedContent: (content) => set({ focusedContent: content }),\n}));\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAuB;AAchB,MAAM,2BAAuB,uBAA0B,CAAC,SAAS;AAAA,EACtE,gBAAgB;AAAA,EAChB,mBAAmB,CAAC,YAAY,IAAI,EAAE,gBAAgB,QAAQ,CAAC;AACjE,EAAE;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/client/renderContentSelector.tsx"],"sourcesContent":["import type { KeyPath } from '@intlayer/core';\nimport { ContentSelectorWrapper } from './ContentSelectorWrapper';\n\nexport const renderContentEditor = (\n content: string,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[]\n) => (\n <ContentSelectorWrapper\n dictionaryId={dictionaryId}\n dictionaryPath={dictionaryPath}\n keyPath={keyPath}\n >\n {content}\n </ContentSelectorWrapper>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASE;AARF,oCAAuC;AAEhC,MAAM,sBAAsB,CACjC,SACA,cACA,gBACA,YAEA;AAAA,EAAC;AAAA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IAEC;AAAA;AACH;","names":[]}
@@ -1,6 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { KeyPath } from '@intlayer/core';
3
-
4
- declare const renderContentEditor: (content: string, dictionaryId: string, dictionaryPath: string, keyPath: KeyPath[]) => react_jsx_runtime.JSX.Element;
5
-
6
- export { renderContentEditor };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/server/content-editor.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'fs';\nimport { createRequire } from 'module';\nimport { parse } from '@babel/parser';\nimport type {\n ObjectExpression,\n VariableDeclarator,\n Program,\n Identifier,\n StringLiteral,\n AssignmentExpression,\n ObjectProperty,\n CallExpression,\n ObjectMethod,\n SpreadElement,\n} from '@babel/types';\nimport {\n NodeType,\n type KeyPath,\n type ObjectExpressionNode,\n type TranslationOrEnumerationNode,\n} from '@intlayer/core';\nimport prettier from 'prettier';\nimport type { EditedContent } from '../client/index';\n\nconst requireFunction =\n typeof import.meta.url === 'undefined'\n ? require\n : createRequire(import.meta.url);\n\nconst { default: generate } = requireFunction('@babel/generator');\n\n/**\n * Helper function to find a nested property in an ObjectExpression based on a key path\n */\nconst findNestedProperty = (\n obj: ObjectExpression,\n keyPath: KeyPath[]\n): ObjectExpression | undefined => {\n let currentObj = obj;\n for (const key of keyPath) {\n let foundProperty:\n | ObjectProperty\n | ObjectMethod\n | SpreadElement\n | undefined;\n\n if (\n // if the keyPath is an object, select the related node\n (key as ObjectExpressionNode).type === 'ObjectExpression'\n ) {\n foundProperty = currentObj.properties.find(\n (prop) =>\n 'key' in prop &&\n (prop.key as Identifier).name === (key as ObjectExpressionNode).key\n );\n }\n\n if (\n // if the keypath is a translation or enumeration node, go across the function and select the related node\n Object.values(NodeType).includes(\n (key as TranslationOrEnumerationNode).type\n )\n ) {\n foundProperty = (\n (currentObj as unknown as CallExpression)\n .arguments[0] as ObjectExpression\n ).properties.find(\n (prop) => 'key' in prop && (prop.key as Identifier).name === key.key\n );\n }\n\n if (foundProperty && 'value' in foundProperty) {\n currentObj = foundProperty.value as ObjectExpression;\n } else {\n return undefined;\n }\n }\n\n return currentObj;\n};\n\n/**\n * Find and update specific content based on key path\n */\nconst findAndUpdate = (\n objExpr: ObjectExpression,\n keyPath: KeyPath[],\n newValue: string\n) => {\n const lastKey = keyPath[keyPath.length - 1]; // Get the last key in the path\n\n if (lastKey) {\n const propertyToUpdate = findNestedProperty(objExpr, keyPath); // Traverse the key path\n\n if (propertyToUpdate && 'value' in propertyToUpdate) {\n (propertyToUpdate as unknown as StringLiteral).value = newValue; // Update the value of the specified key\n }\n }\n};\n\n/**\n * Traverse the AST and update based on key path and new value\n */\nconst traverseNode = (node: Program, keyPath: KeyPath[], newValue: string) => {\n if (Array.isArray(node.body)) {\n (node.body as unknown as Program[]).forEach((subNode) =>\n traverseNode(subNode, keyPath, newValue)\n );\n } else if (node.body) {\n traverseNode(node.body, keyPath, newValue);\n }\n\n if (\n // For ES Module (e.g., `const variable = ...; export default variable`)\n 'declarations' in node\n ) {\n (node.declarations as VariableDeclarator[]).forEach((declaration) => {\n if (declaration.init?.type === 'ObjectExpression') {\n findAndUpdate(declaration.init, keyPath, newValue);\n }\n });\n }\n\n if (\n // For ES Module (e.g., `export default { ... }`)\n 'declaration' in node &&\n (node.declaration as ObjectExpression).type === 'ObjectExpression'\n ) {\n return findAndUpdate(\n node.declaration as ObjectExpression,\n keyPath,\n newValue\n );\n }\n\n if (\n // For CommonJS (e.g., `module.exports = ...`)\n 'expression' in node &&\n (node.expression as AssignmentExpression).right.type === 'ObjectExpression'\n ) {\n return findAndUpdate(\n (node.expression as AssignmentExpression).right as ObjectExpression,\n keyPath,\n newValue\n );\n }\n\n // throw new Error('Could not find the specified key path in the AST.');\n};\n\n/**\n * Format the content with Prettier\n */\nconst format = async (content: string) => {\n // Resolve the configuration from the project\n let options: prettier.Options = {};\n\n try {\n // Resolve the prettier configuration from the project\n options =\n (await prettier.resolveConfig(content, {\n editorconfig: true,\n })) ?? {};\n } catch (error) {\n console.error('Failed to resolve Prettier configuration:', error);\n }\n\n // Add the parser option to the resolved config\n const config: prettier.Options = { ...options, parser: 'typescript' };\n\n return prettier.format(content, config);\n};\n\n/**\n * Edit the content of a file based on the key path and new value\n */\nexport const editContent = async (editedContent: EditedContent) => {\n // Loop into each dictionary path\n for (const dictionaryPath of Object.keys(editedContent)) {\n // Read the file\n const fileContent = readFileSync(dictionaryPath, 'utf-8');\n\n // Parse the content with TypeScript support\n const parsed = parse(fileContent, {\n sourceType: 'module',\n plugins: ['jsx', 'typescript'],\n });\n\n // Loop into each key path and new value\n for (const { keyPath, newValue } of editedContent[dictionaryPath]) {\n // Update values based on key paths\n traverseNode(parsed.program, keyPath, newValue);\n }\n\n // Generate the updated code\n const updatedContent = generate(parsed).code;\n\n if (fileContent === updatedContent) {\n console.info(`Could not find specified key path in ${dictionaryPath}.`);\n } else {\n const formattedContent = await format(updatedContent);\n\n // Write back to the file\n writeFileSync(dictionaryPath, formattedContent, 'utf-8');\n\n console.info('Updated the file successfully.');\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA4C;AAC5C,oBAA8B;AAC9B,oBAAsB;AAatB,kBAKO;AACP,sBAAqB;AArBrB;AAwBA,MAAM,kBACJ,OAAO,YAAY,QAAQ,cACvB,cACA,6BAAc,YAAY,GAAG;AAEnC,MAAM,EAAE,SAAS,SAAS,IAAI,gBAAgB,kBAAkB;AAKhE,MAAM,qBAAqB,CACzB,KACA,YACiC;AACjC,MAAI,aAAa;AACjB,aAAW,OAAO,SAAS;AACzB,QAAI;AAMJ;AAAA;AAAA,MAEG,IAA6B,SAAS;AAAA,MACvC;AACA,sBAAgB,WAAW,WAAW;AAAA,QACpC,CAAC,SACC,SAAS,QACR,KAAK,IAAmB,SAAU,IAA6B;AAAA,MACpE;AAAA,IACF;AAEA;AAAA;AAAA,MAEE,OAAO,OAAO,oBAAQ,EAAE;AAAA,QACrB,IAAqC;AAAA,MACxC;AAAA,MACA;AACA,sBACG,WACE,UAAU,CAAC,EACd,WAAW;AAAA,QACX,CAAC,SAAS,SAAS,QAAS,KAAK,IAAmB,SAAS,IAAI;AAAA,MACnE;AAAA,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cAAc,SAAS;AAAA,MACrC,cAAc;AAAA,IAChB,CAAC,KAAM,CAAC;AAAA,EACZ,SAAS,OAAO;AACd,YAAQ,MAAM,6CAA6C,KAAK;AAAA,EAClE;AAGA,QAAM,SAA2B,EAAE,GAAG,SAAS,QAAQ,aAAa;AAEpE,SAAO,gBAAAA,QAAS,OAAO,SAAS,MAAM;AACxC;AAKO,MAAM,cAAc,OAAO,kBAAiC;AAEjE,aAAW,kBAAkB,OAAO,KAAK,aAAa,GAAG;AAEvD,UAAM,kBAAc,wBAAa,gBAAgB,OAAO;AAGxD,UAAM,aAAS,qBAAM,aAAa;AAAA,MAChC,YAAY;AAAA,MACZ,SAAS,CAAC,OAAO,YAAY;AAAA,IAC/B,CAAC;AAGD,eAAW,EAAE,SAAS,SAAS,KAAK,cAAc,cAAc,GAAG;AAEjE,mBAAa,OAAO,SAAS,SAAS,QAAQ;AAAA,IAChD;AAGA,UAAM,iBAAiB,SAAS,MAAM,EAAE;AAExC,QAAI,gBAAgB,gBAAgB;AAClC,cAAQ,KAAK,wCAAwC,cAAc,GAAG;AAAA,IACxE,OAAO;AACL,YAAM,mBAAmB,MAAM,OAAO,cAAc;AAGpD,mCAAc,gBAAgB,kBAAkB,OAAO;AAEvD,cAAQ,KAAK,gCAAgC;AAAA,IAC/C;AAAA,EACF;AACF;","names":["prettier"]}
@@ -1,12 +0,0 @@
1
- import { EditedContent } from '../client/EditionPanel/useEditedContentStore.js';
2
- import 'zustand/middleware';
3
- import 'zustand';
4
- import '@intlayer/core';
5
- import '@intlayer/design-system';
6
-
7
- /**
8
- * Edit the content of a file based on the key path and new value
9
- */
10
- declare const editContent: (editedContent: EditedContent) => Promise<void>;
11
-
12
- export { editContent };
@@ -1,11 +0,0 @@
1
- import { Locales } from '@intlayer/config/client';
2
- import { FC } from 'react';
3
-
4
- type EditionPanelProps = {
5
- locale: Locales;
6
- localeList: Locales[];
7
- setLocale: (locale: Locales) => void;
8
- };
9
- declare const EditionPanel: FC<EditionPanelProps>;
10
-
11
- export { EditionPanel };
@@ -1,72 +0,0 @@
1
- "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import {
4
- useRightDrawerStore,
5
- RightDrawer,
6
- DictionaryEditor,
7
- LocaleSwitcher
8
- } from "@intlayer/design-system";
9
- import dictionaries from "@intlayer/dictionaries-entry";
10
- import { useEffect } from "react";
11
- import { useEditorServer } from '../useEditorServer.mjs';
12
- import { useEditedContentStore } from './useEditedContentStore.mjs';
13
- import { useEditionPanelStore } from './useEditionPanelStore.mjs';
14
- const EditionPanel = ({
15
- locale,
16
- localeList,
17
- setLocale
18
- }) => {
19
- const { open } = useRightDrawerStore();
20
- const { focusedContent, setFocusedContent } = useEditionPanelStore();
21
- const { editedContent, addEditedContent, clearEditedDictionaryContent } = useEditedContentStore();
22
- const { editContentRequest } = useEditorServer();
23
- useEffect(() => {
24
- if (focusedContent !== null) {
25
- open();
26
- }
27
- }, [focusedContent, open]);
28
- if (!focusedContent) {
29
- return null;
30
- }
31
- const dictionary = dictionaries[focusedContent.dictionaryId];
32
- if (!dictionary?.filePath) {
33
- return null;
34
- }
35
- const dictionaryPath = dictionary.filePath;
36
- const editedDictionaryContent = editedContent[dictionaryPath] ?? [];
37
- return /* @__PURE__ */ jsx(
38
- RightDrawer,
39
- {
40
- title: dictionary.id,
41
- label: `Edit dictionary ${dictionary.id}`,
42
- header: /* @__PURE__ */ jsx(
43
- LocaleSwitcher,
44
- {
45
- setLocale,
46
- locale,
47
- localeList
48
- }
49
- ),
50
- children: /* @__PURE__ */ jsx(
51
- DictionaryEditor,
52
- {
53
- dictionary,
54
- locale,
55
- focusedKeyPath: focusedContent.keyPath,
56
- editedContent: editedDictionaryContent,
57
- onFocusKeyPath: (keyPath) => setFocusedContent({ ...focusedContent, keyPath }),
58
- onContentChange: (keyPath, newValue) => addEditedContent(dictionaryPath, keyPath, newValue),
59
- onValidEdition: editContentRequest,
60
- onCancelEdition: () => {
61
- clearEditedDictionaryContent(dictionaryPath);
62
- setFocusedContent(null);
63
- }
64
- }
65
- )
66
- }
67
- );
68
- };
69
- export {
70
- EditionPanel
71
- };
72
- //# sourceMappingURL=EditionPanel.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/client/EditionPanel/EditionPanel.tsx"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { ContentModule } from '@intlayer/core';\nimport {\n useRightDrawerStore,\n RightDrawer,\n DictionaryEditor,\n LocaleSwitcher,\n} from '@intlayer/design-system';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport { type FC, useEffect } from 'react';\nimport { useEditorServer } from '../useEditorServer';\nimport { useEditedContentStore } from './useEditedContentStore';\nimport { useEditionPanelStore } from './useEditionPanelStore';\n\ntype EditionPanelProps = {\n locale: Locales;\n localeList: Locales[];\n setLocale: (locale: Locales) => void;\n};\n\nexport const EditionPanel: FC<EditionPanelProps> = ({\n locale,\n localeList,\n setLocale,\n}) => {\n const { open } = useRightDrawerStore();\n const { focusedContent, setFocusedContent } = useEditionPanelStore();\n const { editedContent, addEditedContent, clearEditedDictionaryContent } =\n useEditedContentStore();\n const { editContentRequest } = useEditorServer();\n\n // Use effect to react to changes in focusedContent\n useEffect(() => {\n if (focusedContent !== null) {\n open(); // Call the open function from useRightDrawerStore\n }\n }, [focusedContent, open]); // Depend on focusedContent and open to trigger the effect\n\n if (!focusedContent) {\n return null;\n }\n\n const dictionary: ContentModule = dictionaries[focusedContent.dictionaryId];\n\n if (!dictionary?.filePath) {\n return null;\n }\n\n const dictionaryPath = dictionary.filePath;\n const editedDictionaryContent = editedContent[dictionaryPath] ?? [];\n\n return (\n <RightDrawer\n title={dictionary.id}\n label={`Edit dictionary ${dictionary.id}`}\n header={\n <LocaleSwitcher\n setLocale={setLocale}\n locale={locale}\n localeList={localeList}\n />\n }\n >\n <DictionaryEditor\n dictionary={dictionary}\n locale={locale}\n focusedKeyPath={focusedContent.keyPath}\n editedContent={editedDictionaryContent}\n onFocusKeyPath={(keyPath) =>\n setFocusedContent({ ...focusedContent, keyPath })\n }\n onContentChange={(keyPath, newValue) =>\n addEditedContent(dictionaryPath, keyPath, newValue)\n }\n onValidEdition={editContentRequest}\n onCancelEdition={() => {\n clearEditedDictionaryContent(dictionaryPath);\n setFocusedContent(null);\n }}\n />\n </RightDrawer>\n );\n};\n"],"mappings":";AA+DQ;AA3DR;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMP,OAAO,kBAAkB;AACzB,SAAkB,iBAAiB;AACnC,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,4BAA4B;AAQ9B,MAAM,eAAsC,CAAC;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,KAAK,IAAI,oBAAoB;AACrC,QAAM,EAAE,gBAAgB,kBAAkB,IAAI,qBAAqB;AACnE,QAAM,EAAE,eAAe,kBAAkB,6BAA6B,IACpE,sBAAsB;AACxB,QAAM,EAAE,mBAAmB,IAAI,gBAAgB;AAG/C,YAAU,MAAM;AACd,QAAI,mBAAmB,MAAM;AAC3B,WAAK;AAAA,IACP;AAAA,EACF,GAAG,CAAC,gBAAgB,IAAI,CAAC;AAEzB,MAAI,CAAC,gBAAgB;AACnB,WAAO;AAAA,EACT;AAEA,QAAM,aAA4B,aAAa,eAAe,YAAY;AAE1E,MAAI,CAAC,YAAY,UAAU;AACzB,WAAO;AAAA,EACT;AAEA,QAAM,iBAAiB,WAAW;AAClC,QAAM,0BAA0B,cAAc,cAAc,KAAK,CAAC;AAElE,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,WAAW;AAAA,MAClB,OAAO,mBAAmB,WAAW,EAAE;AAAA,MACvC,QACE;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA;AAAA,MACF;AAAA,MAGF;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA,gBAAgB,eAAe;AAAA,UAC/B,eAAe;AAAA,UACf,gBAAgB,CAAC,YACf,kBAAkB,EAAE,GAAG,gBAAgB,QAAQ,CAAC;AAAA,UAElD,iBAAiB,CAAC,SAAS,aACzB,iBAAiB,gBAAgB,SAAS,QAAQ;AAAA,UAEpD,gBAAgB;AAAA,UAChB,iBAAiB,MAAM;AACrB,yCAA6B,cAAc;AAC3C,8BAAkB,IAAI;AAAA,UACxB;AAAA;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;","names":[]}
@@ -1,9 +0,0 @@
1
- export { EditionPanel } from './EditionPanel.mjs';
2
- export { useEditionPanelStore } from './useEditionPanelStore.mjs';
3
- export { EditedContent, useEditedContentStore } from './useEditedContentStore.mjs';
4
- import '@intlayer/config/client';
5
- import 'react';
6
- import 'zustand';
7
- import '@intlayer/core';
8
- import 'zustand/middleware';
9
- import '@intlayer/design-system';
@@ -1,4 +0,0 @@
1
- export * from './EditionPanel.mjs';
2
- export * from './useEditionPanelStore.mjs';
3
- export * from './useEditedContentStore.mjs';
4
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/client/EditionPanel/index.ts"],"sourcesContent":["export * from './EditionPanel';\nexport * from './useEditionPanelStore';\nexport * from './useEditedContentStore';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/client/EditionPanel/useEditedContentStore.ts"],"sourcesContent":["import type { KeyPath } from '@intlayer/core';\nimport type { FileContent } from '@intlayer/design-system';\nimport { create } from 'zustand';\nimport { persist, createJSONStorage } from 'zustand/middleware';\n\ntype DictionaryPath = string;\n\nexport type EditedContent = Record<DictionaryPath, FileContent[]>;\n\ntype EditedContentStore = {\n editedContent: EditedContent;\n addEditedContent: (\n dictionaryPath: DictionaryPath,\n keyPath: KeyPath[],\n newValue: string\n ) => void;\n removeEditedContent: (\n dictionaryPath: DictionaryPath,\n keyPath: KeyPath[]\n ) => void;\n clearEditedDictionaryContent: (dictionaryPath: DictionaryPath) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n dictionaryPath: DictionaryPath,\n keyPath: KeyPath[]\n ) => string | undefined;\n};\n\nconst isSameKeyPath = (keyPath1: KeyPath[], keyPath2: KeyPath[]) =>\n keyPath1.every(\n (element, index) =>\n keyPath2[index] &&\n keyPath2[index].key === element.key &&\n keyPath2[index].type === element.type\n );\n\nexport const useEditedContentStore = create(\n persist<EditedContentStore>(\n (set, get) => ({\n editedContent: {},\n addEditedContent: (dictionaryPath, keyPath, newValue) => {\n set((state) => {\n const editedContent = state.editedContent[dictionaryPath] ?? [];\n return {\n editedContent: {\n ...state.editedContent,\n [dictionaryPath]: [\n ...editedContent.filter(\n (content) => !isSameKeyPath(content.keyPath, keyPath)\n ),\n {\n keyPath,\n newValue,\n },\n ],\n },\n };\n });\n },\n\n removeEditedContent: (dictionaryPath, keyPath) => {\n set((state) => {\n const editedContent = state.editedContent[dictionaryPath] ?? [];\n return {\n editedContent: {\n ...state.editedContent,\n [dictionaryPath]: editedContent.filter(\n (content) => content.keyPath !== keyPath\n ),\n },\n };\n });\n },\n\n clearEditedDictionaryContent: (dictionaryPath) => {\n set((state) => ({\n editedContent: {\n ...state.editedContent,\n [dictionaryPath]: [],\n },\n }));\n },\n\n clearEditedContent: () => {\n set({ editedContent: {} });\n },\n\n getEditedContentValue: (dictionaryPath, keyPath): string | undefined =>\n get().editedContent[dictionaryPath]?.find((content) =>\n isSameKeyPath(content.keyPath, keyPath)\n )?.newValue,\n }),\n {\n name: 'edited-content-store',\n storage: createJSONStorage(() => sessionStorage),\n }\n )\n);\n"],"mappings":"AAEA,SAAS,cAAc;AACvB,SAAS,SAAS,yBAAyB;AAyB3C,MAAM,gBAAgB,CAAC,UAAqB,aAC1C,SAAS;A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AAc,GAAG;AAAA,QAAK,CAAC,YACzC,cAAc,QAAQ,SAAS,OAAO;AAAA,MACxC,GAAG;AAAA,IACP;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,SAAS,kBAAkB,MAAM,cAAc;AAAA,IACjD;AAAA,EACF;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/client/EditionPanel/useEditionPanelStore.ts"],"sourcesContent":["import type { KeyPath } from '@intlayer/core';\nimport { create } from 'zustand';\n\ntype DictionaryPath = string;\ntype FileContent = {\n dictionaryPath: DictionaryPath;\n dictionaryId: string;\n keyPath: KeyPath[];\n};\n\ntype EditionPanelStore = {\n focusedContent: FileContent | null;\n setFocusedContent: (content: FileContent | null) => void;\n};\n\nexport const useEditionPanelStore = create<EditionPanelStore>((set) => ({\n focusedContent: null,\n setFocusedContent: (content) => set({ focusedContent: content }),\n}));\n"],"mappings":"AACA,SAAS,cAAc;AAchB,MAAM,uBAAuB,OAA0B,CAAC,SAAS;AAAA,EACtE,gBAAgB;AAAA,EAChB,mBAAmB,CAAC,YAAY,IAAI,EAAE,gBAAgB,QAAQ,CAAC;AACjE,EAAE;","names":[]}
@@ -1,6 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { KeyPath } from '@intlayer/core';
3
-
4
- declare const renderContentEditor: (content: string, dictionaryId: string, dictionaryPath: string, keyPath: KeyPath[]) => react_jsx_runtime.JSX.Element;
5
-
6
- export { renderContentEditor };
@@ -1,15 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { ContentSelectorWrapper } from './ContentSelectorWrapper.mjs';
3
- const renderContentEditor = (content, dictionaryId, dictionaryPath, keyPath) => /* @__PURE__ */ jsx(
4
- ContentSelectorWrapper,
5
- {
6
- dictionaryId,
7
- dictionaryPath,
8
- keyPath,
9
- children: content
10
- }
11
- );
12
- export {
13
- renderContentEditor
14
- };
15
- //# sourceMappingURL=renderContentSelector.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/client/renderContentSelector.tsx"],"sourcesContent":["import type { KeyPath } from '@intlayer/core';\nimport { ContentSelectorWrapper } from './ContentSelectorWrapper';\n\nexport const renderContentEditor = (\n content: string,\n dictionaryId: string,\n dictionaryPath: string,\n keyPath: KeyPath[]\n) => (\n <ContentSelectorWrapper\n dictionaryId={dictionaryId}\n dictionaryPath={dictionaryPath}\n keyPath={keyPath}\n >\n {content}\n </ContentSelectorWrapper>\n);\n"],"mappings":"AASE;AARF,SAAS,8BAA8B;AAEhC,MAAM,sBAAsB,CACjC,SACA,cACA,gBACA,YAEA;AAAA,EAAC;AAAA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IAEC;AAAA;AACH;","names":[]}
@@ -1,12 +0,0 @@
1
- import { EditedContent } from '../client/EditionPanel/useEditedContentStore.mjs';
2
- import 'zustand/middleware';
3
- import 'zustand';
4
- import '@intlayer/core';
5
- import '@intlayer/design-system';
6
-
7
- /**
8
- * Edit the content of a file based on the key path and new value
9
- */
10
- declare const editContent: (editedContent: EditedContent) => Promise<void>;
11
-
12
- export { editContent };