intlayer-editor 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -135
- package/dist/cjs/client/ContentEditionLayout.cjs +5 -3
- package/dist/cjs/client/ContentEditionLayout.cjs.map +1 -1
- package/dist/cjs/client/ContentSelectorWrapper.cjs +14 -10
- package/dist/cjs/client/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/client/ContentSelectorWrapper.d.ts +2 -2
- package/dist/cjs/client/DictionaryEditionDrawer/DictionaryEditionDrawer.cjs +135 -0
- package/dist/cjs/client/DictionaryEditionDrawer/DictionaryEditionDrawer.cjs.map +1 -0
- package/dist/cjs/client/DictionaryEditionDrawer/DictionaryEditionDrawer.d.ts +28 -0
- package/dist/cjs/client/DictionaryEditionDrawer/index.cjs +27 -0
- package/dist/cjs/client/DictionaryEditionDrawer/index.cjs.map +1 -0
- package/dist/cjs/client/DictionaryEditionDrawer/index.d.ts +9 -0
- package/dist/cjs/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.cjs +103 -0
- package/dist/cjs/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.cjs.map +1 -0
- package/dist/cjs/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.d.ts +32 -0
- package/dist/cjs/client/{EditionPanel → DictionaryEditionDrawer}/useEditedContentStore.cjs +19 -11
- package/dist/cjs/client/DictionaryEditionDrawer/useEditedContentStore.cjs.map +1 -0
- package/dist/cjs/client/{EditionPanel/useEditionPanelStore.cjs → DictionaryEditionDrawer/useFocusContentStore.cjs} +4 -4
- package/dist/cjs/client/DictionaryEditionDrawer/useFocusContentStore.cjs.map +1 -0
- package/dist/cjs/client/{EditionPanel/useEditionPanelStore.d.ts → DictionaryEditionDrawer/useFocusContentStore.d.ts} +1 -1
- package/dist/cjs/client/DictionaryListDrawer/DictionaryListDrawer.cjs +74 -0
- package/dist/cjs/client/DictionaryListDrawer/DictionaryListDrawer.cjs.map +1 -0
- package/dist/cjs/client/DictionaryListDrawer/DictionaryListDrawer.d.ts +5 -0
- package/dist/cjs/client/{EditionPanel → DictionaryListDrawer}/index.cjs +6 -8
- package/dist/cjs/client/DictionaryListDrawer/index.cjs.map +1 -0
- package/dist/cjs/client/DictionaryListDrawer/index.d.ts +3 -0
- package/dist/cjs/client/{renderContentSelector.cjs → DictionaryListDrawer/useDictionaryListDrawer.cjs} +11 -17
- package/dist/cjs/client/DictionaryListDrawer/useDictionaryListDrawer.cjs.map +1 -0
- package/dist/cjs/client/DictionaryListDrawer/useDictionaryListDrawer.d.ts +8 -0
- package/dist/cjs/client/index.cjs +7 -5
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/client/index.d.ts +8 -7
- package/dist/cjs/client/renderContentEditor.cjs +48 -0
- package/dist/cjs/client/renderContentEditor.cjs.map +1 -0
- package/dist/cjs/client/renderContentEditor.d.ts +15 -0
- package/dist/cjs/client/useEditorServer.cjs +5 -2
- package/dist/cjs/client/useEditorServer.cjs.map +1 -1
- package/dist/cjs/server/formatPrettier.cjs +51 -0
- package/dist/cjs/server/formatPrettier.cjs.map +1 -0
- package/dist/cjs/server/formatPrettier.d.ts +6 -0
- package/dist/cjs/server/index.cjs +2 -2
- package/dist/cjs/server/index.cjs.map +1 -1
- package/dist/cjs/server/{content-editor.cjs → processEdition.cjs} +41 -38
- package/dist/cjs/server/processEdition.cjs.map +1 -0
- package/dist/cjs/server/processEdition.d.ts +12 -0
- package/dist/esm/client/ContentEditionLayout.mjs +5 -3
- package/dist/esm/client/ContentEditionLayout.mjs.map +1 -1
- package/dist/esm/client/ContentSelectorWrapper.d.mts +2 -2
- package/dist/esm/client/ContentSelectorWrapper.mjs +14 -10
- package/dist/esm/client/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/client/DictionaryEditionDrawer/DictionaryEditionDrawer.d.mts +28 -0
- package/dist/esm/client/DictionaryEditionDrawer/DictionaryEditionDrawer.mjs +104 -0
- package/dist/esm/client/DictionaryEditionDrawer/DictionaryEditionDrawer.mjs.map +1 -0
- package/dist/esm/client/DictionaryEditionDrawer/index.d.mts +9 -0
- package/dist/esm/client/DictionaryEditionDrawer/index.mjs +4 -0
- package/dist/esm/client/DictionaryEditionDrawer/index.mjs.map +1 -0
- package/dist/esm/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.d.mts +32 -0
- package/dist/esm/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.mjs +80 -0
- package/dist/esm/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.mjs.map +1 -0
- package/dist/esm/client/{EditionPanel → DictionaryEditionDrawer}/useEditedContentStore.mjs +17 -9
- package/dist/esm/client/DictionaryEditionDrawer/useEditedContentStore.mjs.map +1 -0
- package/dist/esm/client/{EditionPanel/useEditionPanelStore.d.mts → DictionaryEditionDrawer/useFocusContentStore.d.mts} +1 -1
- package/dist/esm/client/{EditionPanel/useEditionPanelStore.mjs → DictionaryEditionDrawer/useFocusContentStore.mjs} +1 -1
- package/dist/esm/client/DictionaryEditionDrawer/useFocusContentStore.mjs.map +1 -0
- package/dist/esm/client/DictionaryListDrawer/DictionaryListDrawer.d.mts +5 -0
- package/dist/esm/client/DictionaryListDrawer/DictionaryListDrawer.mjs +46 -0
- package/dist/esm/client/DictionaryListDrawer/DictionaryListDrawer.mjs.map +1 -0
- package/dist/esm/client/DictionaryListDrawer/index.d.mts +3 -0
- package/dist/esm/client/DictionaryListDrawer/index.mjs +3 -0
- package/dist/esm/client/DictionaryListDrawer/index.mjs.map +1 -0
- package/dist/esm/client/DictionaryListDrawer/useDictionaryListDrawer.d.mts +8 -0
- package/dist/esm/client/DictionaryListDrawer/useDictionaryListDrawer.mjs +8 -0
- package/dist/esm/client/DictionaryListDrawer/useDictionaryListDrawer.mjs.map +1 -0
- package/dist/esm/client/index.d.mts +8 -7
- package/dist/esm/client/index.mjs +3 -2
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/renderContentEditor.d.mts +15 -0
- package/dist/esm/client/renderContentEditor.mjs +24 -0
- package/dist/esm/client/renderContentEditor.mjs.map +1 -0
- package/dist/esm/client/useEditorServer.mjs +5 -2
- package/dist/esm/client/useEditorServer.mjs.map +1 -1
- package/dist/esm/server/formatPrettier.d.mts +6 -0
- package/dist/esm/server/formatPrettier.mjs +17 -0
- package/dist/esm/server/formatPrettier.mjs.map +1 -0
- package/dist/esm/server/index.mjs +2 -2
- package/dist/esm/server/index.mjs.map +1 -1
- package/dist/esm/server/processEdition.d.mts +12 -0
- package/dist/esm/server/{content-editor.mjs → processEdition.mjs} +36 -23
- package/dist/esm/server/processEdition.mjs.map +1 -0
- package/package.json +6 -7
- package/dist/cjs/client/EditionPanel/EditionPanel.cjs +0 -101
- package/dist/cjs/client/EditionPanel/EditionPanel.cjs.map +0 -1
- package/dist/cjs/client/EditionPanel/EditionPanel.d.ts +0 -11
- package/dist/cjs/client/EditionPanel/index.cjs.map +0 -1
- package/dist/cjs/client/EditionPanel/index.d.ts +0 -9
- package/dist/cjs/client/EditionPanel/useEditedContentStore.cjs.map +0 -1
- package/dist/cjs/client/EditionPanel/useEditionPanelStore.cjs.map +0 -1
- package/dist/cjs/client/renderContentSelector.cjs.map +0 -1
- package/dist/cjs/client/renderContentSelector.d.ts +0 -6
- package/dist/cjs/server/content-editor.cjs.map +0 -1
- package/dist/cjs/server/content-editor.d.ts +0 -12
- package/dist/esm/client/EditionPanel/EditionPanel.d.mts +0 -11
- package/dist/esm/client/EditionPanel/EditionPanel.mjs +0 -72
- package/dist/esm/client/EditionPanel/EditionPanel.mjs.map +0 -1
- package/dist/esm/client/EditionPanel/index.d.mts +0 -9
- package/dist/esm/client/EditionPanel/index.mjs +0 -4
- package/dist/esm/client/EditionPanel/index.mjs.map +0 -1
- package/dist/esm/client/EditionPanel/useEditedContentStore.mjs.map +0 -1
- package/dist/esm/client/EditionPanel/useEditionPanelStore.mjs.map +0 -1
- package/dist/esm/client/renderContentSelector.d.mts +0 -6
- package/dist/esm/client/renderContentSelector.mjs +0 -15
- package/dist/esm/client/renderContentSelector.mjs.map +0 -1
- package/dist/esm/server/content-editor.d.mts +0 -12
- package/dist/esm/server/content-editor.mjs.map +0 -1
- package/src/client/ContentEditionLayout.tsx +0 -26
- package/src/client/ContentSelectorWrapper.tsx +0 -38
- package/src/client/EditionPanel/EditionPanel.tsx +0 -90
- package/src/client/EditionPanel/index.ts +0 -3
- package/src/client/EditionPanel/useEditedContentStore.ts +0 -98
- package/src/client/EditionPanel/useEditionPanelStore.ts +0 -19
- package/src/client/index.ts +0 -4
- package/src/client/renderContentSelector.tsx +0 -17
- package/src/client/useEditorServer.ts +0 -31
- package/src/server/content-editor.ts +0 -209
- package/src/server/index.ts +0 -40
- /package/dist/cjs/client/{EditionPanel → DictionaryEditionDrawer}/useEditedContentStore.d.ts +0 -0
- /package/dist/esm/client/{EditionPanel → DictionaryEditionDrawer}/useEditedContentStore.d.mts +0 -0
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,25 +15,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
|
|
19
|
+
var processEdition_exports = {};
|
|
20
|
+
__export(processEdition_exports, {
|
|
21
|
+
processEdition: () => processEdition
|
|
32
22
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(processEdition_exports);
|
|
34
24
|
var import_fs = require("fs");
|
|
35
25
|
var import_module = require("module");
|
|
36
26
|
var import_parser = require("@babel/parser");
|
|
37
27
|
var import_core = require("@intlayer/core");
|
|
38
|
-
var
|
|
28
|
+
var import_formatPrettier = require('./formatPrettier.cjs');
|
|
39
29
|
const import_meta = {};
|
|
40
30
|
const requireFunction = typeof import_meta.url === "undefined" ? require : (0, import_module.createRequire)(import_meta.url);
|
|
41
31
|
const { default: generate } = requireFunction("@babel/generator");
|
|
@@ -47,9 +37,22 @@ const findNestedProperty = (obj, keyPath) => {
|
|
|
47
37
|
// if the keyPath is an object, select the related node
|
|
48
38
|
key.type === "ObjectExpression"
|
|
49
39
|
) {
|
|
50
|
-
|
|
40
|
+
const result = currentObj.properties.find(
|
|
51
41
|
(prop) => "key" in prop && prop.key.name === key.key
|
|
52
42
|
);
|
|
43
|
+
if (result && "value" in result) {
|
|
44
|
+
currentObj = result.value;
|
|
45
|
+
foundProperty = result;
|
|
46
|
+
} else {
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (
|
|
51
|
+
// if the keyPath is an array, select the related node
|
|
52
|
+
key.type === "ArrayExpression"
|
|
53
|
+
) {
|
|
54
|
+
const result = currentObj.elements[key.key];
|
|
55
|
+
currentObj = result;
|
|
53
56
|
}
|
|
54
57
|
if (
|
|
55
58
|
// if the keypath is a translation or enumeration node, go across the function and select the related node
|
|
@@ -57,14 +60,26 @@ const findNestedProperty = (obj, keyPath) => {
|
|
|
57
60
|
key.type
|
|
58
61
|
)
|
|
59
62
|
) {
|
|
60
|
-
|
|
63
|
+
const argument = currentObj.arguments[0];
|
|
64
|
+
const identifierResult = argument.properties.find(
|
|
61
65
|
(prop) => "key" in prop && prop.key.name === key.key
|
|
62
66
|
);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
const stringResult = argument.properties.find(
|
|
68
|
+
(prop) => "key" in prop && prop.key.value === key.key
|
|
69
|
+
);
|
|
70
|
+
if (stringResult) {
|
|
71
|
+
if ("value" in stringResult) {
|
|
72
|
+
currentObj = stringResult.value;
|
|
73
|
+
}
|
|
74
|
+
foundProperty = stringResult;
|
|
75
|
+
} else if (identifierResult) {
|
|
76
|
+
if ("name" in identifierResult) {
|
|
77
|
+
currentObj = identifierResult.name;
|
|
78
|
+
}
|
|
79
|
+
foundProperty = identifierResult;
|
|
80
|
+
} else {
|
|
81
|
+
return void 0;
|
|
82
|
+
}
|
|
68
83
|
}
|
|
69
84
|
}
|
|
70
85
|
return currentObj;
|
|
@@ -117,19 +132,7 @@ const traverseNode = (node, keyPath, newValue) => {
|
|
|
117
132
|
);
|
|
118
133
|
}
|
|
119
134
|
};
|
|
120
|
-
const
|
|
121
|
-
let options = {};
|
|
122
|
-
try {
|
|
123
|
-
options = await import_prettier.default.resolveConfig(content, {
|
|
124
|
-
editorconfig: true
|
|
125
|
-
}) ?? {};
|
|
126
|
-
} catch (error) {
|
|
127
|
-
console.error("Failed to resolve Prettier configuration:", error);
|
|
128
|
-
}
|
|
129
|
-
const config = { ...options, parser: "typescript" };
|
|
130
|
-
return import_prettier.default.format(content, config);
|
|
131
|
-
};
|
|
132
|
-
const editContent = async (editedContent) => {
|
|
135
|
+
const processEdition = async (editedContent) => {
|
|
133
136
|
for (const dictionaryPath of Object.keys(editedContent)) {
|
|
134
137
|
const fileContent = (0, import_fs.readFileSync)(dictionaryPath, "utf-8");
|
|
135
138
|
const parsed = (0, import_parser.parse)(fileContent, {
|
|
@@ -143,7 +146,7 @@ const editContent = async (editedContent) => {
|
|
|
143
146
|
if (fileContent === updatedContent) {
|
|
144
147
|
console.info(`Could not find specified key path in ${dictionaryPath}.`);
|
|
145
148
|
} else {
|
|
146
|
-
const formattedContent = await format(updatedContent);
|
|
149
|
+
const formattedContent = await (0, import_formatPrettier.format)(updatedContent);
|
|
147
150
|
(0, import_fs.writeFileSync)(dictionaryPath, formattedContent, "utf-8");
|
|
148
151
|
console.info("Updated the file successfully.");
|
|
149
152
|
}
|
|
@@ -151,6 +154,6 @@ const editContent = async (editedContent) => {
|
|
|
151
154
|
};
|
|
152
155
|
// Annotate the CommonJS export names for ESM import in node:
|
|
153
156
|
0 && (module.exports = {
|
|
154
|
-
|
|
157
|
+
processEdition
|
|
155
158
|
});
|
|
156
|
-
//# sourceMappingURL=
|
|
159
|
+
//# sourceMappingURL=processEdition.cjs.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 ObjectMethod,\n SpreadElement,\n ArrayExpression,\n PrivateName,\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 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 const result = (currentObj as ObjectExpression).properties.find(\n (prop) =>\n 'key' in prop &&\n (prop.key as Identifier).name === (key as ObjectExpressionNode).key\n );\n\n if (result && 'value' in result) {\n currentObj = result.value as ObjectExpression;\n foundProperty = result;\n } else {\n return undefined;\n }\n }\n\n if (\n // if the keyPath is an array, select the related node\n (key as ArrayExpressionNode).type === 'ArrayExpression'\n ) {\n const result = (currentObj as ArrayExpression).elements[\n (key as ArrayExpressionNode).key\n ] as unknown as ObjectProperty;\n\n currentObj = result as unknown as ObjectExpression;\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 const argument = (currentObj as unknown as CallExpression)\n .arguments[0] as ObjectExpression;\n\n const identifierResult = argument.properties.find(\n (prop) => 'key' in prop && (prop.key as Identifier).name === key.key\n );\n\n const stringResult = argument.properties.find(\n (prop) => 'key' in prop && (prop.key as StringLiteral).value === key.key\n );\n\n if (stringResult) {\n // Correspond to StringLiteral oject property (e.g., { 'key': 'value' })\n if ('value' in stringResult) {\n currentObj = stringResult.value as ObjectExpression;\n }\n foundProperty = stringResult;\n } else if (identifierResult) {\n // Correspond to Identifier object property (e.g., { key: 'value' })\n if ('name' in identifierResult) {\n currentObj = identifierResult.name as ObjectExpression;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n foundProperty = identifierResult;\n } else {\n return undefined;\n }\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\n/**\n * Edit the content of a file based on the key path and new value\n */\nexport const processEdition = 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":"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","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EditedContent } from '../client/DictionaryEditionDrawer/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 processEdition: (editedContent: EditedContent) => Promise<void>;
|
|
11
|
+
|
|
12
|
+
export { processEdition };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { DictionaryEditionDrawerController } from './DictionaryEditionDrawer/index.mjs';
|
|
3
|
+
import { DictionaryListDrawer } from './DictionaryListDrawer/index.mjs';
|
|
3
4
|
const ContentEditionLayout = ({
|
|
4
5
|
children,
|
|
5
6
|
locale,
|
|
@@ -8,13 +9,14 @@ const ContentEditionLayout = ({
|
|
|
8
9
|
}) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
9
10
|
children,
|
|
10
11
|
/* @__PURE__ */ jsx(
|
|
11
|
-
|
|
12
|
+
DictionaryEditionDrawerController,
|
|
12
13
|
{
|
|
13
14
|
locale,
|
|
14
15
|
localeList,
|
|
15
16
|
setLocale
|
|
16
17
|
}
|
|
17
|
-
)
|
|
18
|
+
),
|
|
19
|
+
/* @__PURE__ */ jsx(DictionaryListDrawer, {})
|
|
18
20
|
] });
|
|
19
21
|
export {
|
|
20
22
|
ContentEditionLayout
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/ContentEditionLayout.tsx"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { FC, ReactNode } from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/ContentEditionLayout.tsx"],"sourcesContent":["import type { Locales } from '@intlayer/config/client';\nimport type { FC, ReactNode } from 'react';\nimport { DictionaryEditionDrawerController } from './DictionaryEditionDrawer/index';\nimport { DictionaryListDrawer } from './DictionaryListDrawer/index';\n\nexport type ContentEditionLayoutProps = {\n children?: ReactNode;\n locale: Locales;\n localeList: Locales[];\n setLocale: (locale: Locales) => void;\n};\n\nexport const ContentEditionLayout: FC<ContentEditionLayoutProps> = ({\n children,\n locale,\n setLocale,\n localeList,\n}) => (\n <>\n {children}\n <DictionaryEditionDrawerController\n locale={locale}\n localeList={localeList}\n setLocale={setLocale}\n />\n <DictionaryListDrawer />\n </>\n);\n"],"mappings":"AAkBE,mBAEE,KAFF;AAhBF,SAAS,yCAAyC;AAClD,SAAS,4BAA4B;AAS9B,MAAM,uBAAsD,CAAC;AAAA,EAClE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MACE,iCACG;AAAA;AAAA,EACD;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACF;AAAA,EACA,oBAAC,wBAAqB;AAAA,GACxB;","names":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { KeyPath } from '@intlayer/core';
|
|
2
|
-
import { FC } from 'react';
|
|
2
|
+
import { FC, ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
type ContentSelectorWrapperProps = {
|
|
5
|
-
children:
|
|
5
|
+
children: ReactNode;
|
|
6
6
|
dictionaryId: string;
|
|
7
7
|
dictionaryPath: string;
|
|
8
8
|
keyPath: KeyPath[];
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { isSameKeyPath } from "@intlayer/core";
|
|
3
4
|
import { ContentSelector } from "@intlayer/design-system";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { useCallback } from "react";
|
|
6
|
+
import { useDictionaryEditionDrawer } from './DictionaryEditionDrawer/useDictionaryEditionDrawer.mjs';
|
|
6
7
|
const ContentSelectorWrapper = ({
|
|
7
8
|
children,
|
|
8
9
|
dictionaryId,
|
|
9
10
|
dictionaryPath,
|
|
10
11
|
keyPath
|
|
11
12
|
}) => {
|
|
12
|
-
const {
|
|
13
|
-
const handleSelect = () => setFocusedContent({
|
|
14
|
-
dictionaryId,
|
|
15
|
-
dictionaryPath,
|
|
16
|
-
keyPath
|
|
17
|
-
});
|
|
18
|
-
const { getEditedContentValue } = useEditedContentStore();
|
|
13
|
+
const { open, getEditedContentValue, focusedContent, isOpen } = useDictionaryEditionDrawer(dictionaryId);
|
|
19
14
|
const editedValue = getEditedContentValue(dictionaryPath, keyPath);
|
|
20
|
-
|
|
15
|
+
const handleSelect = useCallback(
|
|
16
|
+
() => open({
|
|
17
|
+
dictionaryId,
|
|
18
|
+
dictionaryPath,
|
|
19
|
+
keyPath
|
|
20
|
+
}),
|
|
21
|
+
[dictionaryId, dictionaryPath, keyPath, open]
|
|
22
|
+
);
|
|
23
|
+
const isSelected = (isOpen && (focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ?? false;
|
|
24
|
+
return /* @__PURE__ */ jsx(ContentSelector, { onSelect: handleSelect, isSelecting: isSelected, children: editedValue ?? children });
|
|
21
25
|
};
|
|
22
26
|
export {
|
|
23
27
|
ContentSelectorWrapper
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport type
|
|
1
|
+
{"version":3,"sources":["../../../src/client/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { isSameKeyPath, type KeyPath } from '@intlayer/core';\nimport { ContentSelector } from '@intlayer/design-system';\nimport { useCallback, type FC, type ReactNode } from 'react';\nimport { useDictionaryEditionDrawer } from './DictionaryEditionDrawer/useDictionaryEditionDrawer';\n\ntype ContentSelectorWrapperProps = {\n children: ReactNode;\n dictionaryId: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n};\n\nexport const ContentSelectorWrapper: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryId,\n dictionaryPath,\n keyPath,\n}) => {\n const { open, getEditedContentValue, focusedContent, isOpen } =\n useDictionaryEditionDrawer(dictionaryId);\n const editedValue = getEditedContentValue(dictionaryPath, keyPath);\n\n const handleSelect = useCallback(\n () =>\n open({\n dictionaryId,\n dictionaryPath,\n keyPath,\n }),\n [dictionaryId, dictionaryPath, keyPath, open]\n );\n\n const isSelected =\n (isOpen &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ??\n false;\n\n return (\n <ContentSelector onSelect={handleSelect} isSelecting={isSelected}>\n {editedValue ?? children}\n </ContentSelector>\n );\n};\n"],"mappings":";AAyCI;AAvCJ,SAAS,qBAAmC;AAC5C,SAAS,uBAAuB;AAChC,SAAS,mBAA4C;AACrD,SAAS,kCAAkC;AASpC,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,MAAM,uBAAuB,gBAAgB,OAAO,IAC1D,2BAA2B,YAAY;AACzC,QAAM,cAAc,sBAAsB,gBAAgB,OAAO;AAEjE,QAAM,eAAe;AAAA,IACnB,MACE,KAAK;AAAA,MACH;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,cAAc,gBAAgB,SAAS,IAAI;AAAA,EAC9C;AAEA,QAAM,cACH,WACE,gBAAgB,SAAS,UAAU,KAAK,KACzC,cAAc,gBAAgB,WAAW,CAAC,GAAG,OAAO,MACtD;AAEF,SACE,oBAAC,mBAAgB,UAAU,cAAc,aAAa,YACnD,yBAAe,UAClB;AAEJ;","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Locales } from '@intlayer/config/client';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
import { FileContent } from './useDictionaryEditionDrawer.mjs';
|
|
4
|
+
import './useEditedContentStore.mjs';
|
|
5
|
+
import '@intlayer/core';
|
|
6
|
+
import 'zustand/middleware';
|
|
7
|
+
import 'zustand';
|
|
8
|
+
import '@intlayer/design-system';
|
|
9
|
+
|
|
10
|
+
type DictionaryEditionDrawerContentProps = {
|
|
11
|
+
focusedContent: FileContent;
|
|
12
|
+
locale: Locales;
|
|
13
|
+
identifier: string;
|
|
14
|
+
};
|
|
15
|
+
declare const DictionaryEditionDrawerContent: FC<DictionaryEditionDrawerContentProps>;
|
|
16
|
+
type DictionaryEditionDrawerProps = DictionaryEditionDrawerControllerProps & {
|
|
17
|
+
dictionaryId: string;
|
|
18
|
+
};
|
|
19
|
+
declare const getDrawerIdentifier: (dictionaryId: string) => string;
|
|
20
|
+
declare const DictionaryEditionDrawer: FC<DictionaryEditionDrawerProps>;
|
|
21
|
+
type DictionaryEditionDrawerControllerProps = {
|
|
22
|
+
locale: Locales;
|
|
23
|
+
localeList: Locales[];
|
|
24
|
+
setLocale: (locale: Locales) => void;
|
|
25
|
+
};
|
|
26
|
+
declare const DictionaryEditionDrawerController: FC<DictionaryEditionDrawerControllerProps>;
|
|
27
|
+
|
|
28
|
+
export { DictionaryEditionDrawer, DictionaryEditionDrawerContent, DictionaryEditionDrawerController, getDrawerIdentifier };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
RightDrawer,
|
|
5
|
+
DictionaryEditor,
|
|
6
|
+
LocaleSwitcher
|
|
7
|
+
} from "@intlayer/design-system";
|
|
8
|
+
import dictionaries from "@intlayer/dictionaries-entry";
|
|
9
|
+
import { useDictionaryListDrawer } from '../DictionaryListDrawer/index.mjs';
|
|
10
|
+
import {
|
|
11
|
+
useDictionaryEditionDrawer
|
|
12
|
+
} from './useDictionaryEditionDrawer.mjs';
|
|
13
|
+
import { useEditionPanelStore } from './useFocusContentStore.mjs';
|
|
14
|
+
const DictionaryEditionDrawerContent = ({ focusedContent, locale, identifier }) => {
|
|
15
|
+
const {
|
|
16
|
+
setFocusedContent,
|
|
17
|
+
editContentRequest,
|
|
18
|
+
editedContent,
|
|
19
|
+
addEditedContent,
|
|
20
|
+
clearEditedDictionaryContent
|
|
21
|
+
} = useDictionaryEditionDrawer(identifier);
|
|
22
|
+
const dictionaryId = focusedContent.dictionaryId;
|
|
23
|
+
const dictionary = dictionaries[dictionaryId];
|
|
24
|
+
const dictionaryPath = dictionary.filePath;
|
|
25
|
+
const editedDictionaryContent = editedContent[dictionaryPath];
|
|
26
|
+
return /* @__PURE__ */ jsx(
|
|
27
|
+
DictionaryEditor,
|
|
28
|
+
{
|
|
29
|
+
dictionary,
|
|
30
|
+
locale,
|
|
31
|
+
focusedKeyPath: focusedContent.keyPath,
|
|
32
|
+
editedContent: editedDictionaryContent,
|
|
33
|
+
onFocusKeyPath: (keyPath) => setFocusedContent({ ...focusedContent, keyPath }),
|
|
34
|
+
onContentChange: (keyPath, newValue) => addEditedContent(dictionaryPath, keyPath, newValue),
|
|
35
|
+
onValidEdition: editContentRequest,
|
|
36
|
+
onCancelEdition: () => clearEditedDictionaryContent(dictionaryPath)
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
const getDrawerIdentifier = (dictionaryId) => `dictionary_edition_${dictionaryId}`;
|
|
41
|
+
const DictionaryEditionDrawer = ({
|
|
42
|
+
locale,
|
|
43
|
+
localeList,
|
|
44
|
+
setLocale,
|
|
45
|
+
dictionaryId
|
|
46
|
+
}) => {
|
|
47
|
+
const id = getDrawerIdentifier(dictionaryId);
|
|
48
|
+
const { focusedContent, close } = useDictionaryEditionDrawer(dictionaryId);
|
|
49
|
+
const { open: openDictionaryListDrawer } = useDictionaryListDrawer();
|
|
50
|
+
const handleOnBack = () => {
|
|
51
|
+
close();
|
|
52
|
+
openDictionaryListDrawer();
|
|
53
|
+
};
|
|
54
|
+
return /* @__PURE__ */ jsx(
|
|
55
|
+
RightDrawer,
|
|
56
|
+
{
|
|
57
|
+
title: dictionaryId,
|
|
58
|
+
identifier: id,
|
|
59
|
+
header: /* @__PURE__ */ jsx(
|
|
60
|
+
LocaleSwitcher,
|
|
61
|
+
{
|
|
62
|
+
setLocale,
|
|
63
|
+
locale,
|
|
64
|
+
localeList
|
|
65
|
+
}
|
|
66
|
+
),
|
|
67
|
+
backButton: {
|
|
68
|
+
onBack: handleOnBack,
|
|
69
|
+
text: "Dictionary list"
|
|
70
|
+
},
|
|
71
|
+
children: focusedContent && /* @__PURE__ */ jsx(
|
|
72
|
+
DictionaryEditionDrawerContent,
|
|
73
|
+
{
|
|
74
|
+
focusedContent,
|
|
75
|
+
locale,
|
|
76
|
+
identifier: id
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
const DictionaryEditionDrawerController = ({ locale, localeList, setLocale }) => {
|
|
83
|
+
const focusedContent = useEditionPanelStore((s) => s.focusedContent);
|
|
84
|
+
const dictionaryId = focusedContent?.dictionaryId;
|
|
85
|
+
if (!dictionaryId) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
return /* @__PURE__ */ jsx(
|
|
89
|
+
DictionaryEditionDrawer,
|
|
90
|
+
{
|
|
91
|
+
locale,
|
|
92
|
+
localeList,
|
|
93
|
+
setLocale,
|
|
94
|
+
dictionaryId
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
export {
|
|
99
|
+
DictionaryEditionDrawer,
|
|
100
|
+
DictionaryEditionDrawerContent,
|
|
101
|
+
DictionaryEditionDrawerController,
|
|
102
|
+
getDrawerIdentifier
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=DictionaryEditionDrawer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/client/DictionaryEditionDrawer/DictionaryEditionDrawer.tsx"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport {\n RightDrawer,\n DictionaryEditor,\n LocaleSwitcher,\n type FileContent,\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 } from 'react';\nimport { useDictionaryListDrawer } from '../DictionaryListDrawer/index';\nimport {\n type FileContent as FileContentWithDictionaryPath,\n useDictionaryEditionDrawer,\n} from './useDictionaryEditionDrawer';\nimport { useEditionPanelStore } from './useFocusContentStore';\n\ntype DictionaryEditionDrawerContentProps = {\n focusedContent: FileContentWithDictionaryPath;\n locale: Locales;\n identifier: string;\n};\n\nexport const DictionaryEditionDrawerContent: FC<\n DictionaryEditionDrawerContentProps\n> = ({ focusedContent, locale, identifier }) => {\n const {\n setFocusedContent,\n editContentRequest,\n editedContent,\n addEditedContent,\n clearEditedDictionaryContent,\n } = useDictionaryEditionDrawer(identifier);\n\n const dictionaryId: string = focusedContent.dictionaryId;\n const dictionary: Dictionary = dictionaries[dictionaryId];\n const dictionaryPath: string = dictionary.filePath;\n const editedDictionaryContent: FileContent[] = editedContent[dictionaryPath];\n\n return (\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={() => clearEditedDictionaryContent(dictionaryPath)}\n />\n );\n};\n\ntype DictionaryEditionDrawerProps = DictionaryEditionDrawerControllerProps & {\n dictionaryId: string;\n};\n\nexport const getDrawerIdentifier = (dictionaryId: string) =>\n `dictionary_edition_${dictionaryId}`;\n\nexport const DictionaryEditionDrawer: FC<DictionaryEditionDrawerProps> = ({\n locale,\n localeList,\n setLocale,\n dictionaryId,\n}) => {\n const id = getDrawerIdentifier(dictionaryId);\n\n const { focusedContent, close } = useDictionaryEditionDrawer(dictionaryId);\n const { open: openDictionaryListDrawer } = useDictionaryListDrawer();\n\n const handleOnBack = () => {\n close();\n openDictionaryListDrawer();\n };\n\n return (\n <RightDrawer\n title={dictionaryId}\n identifier={id}\n header={\n <LocaleSwitcher\n setLocale={setLocale}\n locale={locale}\n localeList={localeList}\n />\n }\n backButton={{\n onBack: handleOnBack,\n text: 'Dictionary list',\n }}\n >\n {focusedContent && (\n <DictionaryEditionDrawerContent\n focusedContent={focusedContent}\n locale={locale}\n identifier={id}\n />\n )}\n </RightDrawer>\n );\n};\n\ntype DictionaryEditionDrawerControllerProps = {\n locale: Locales;\n localeList: Locales[];\n setLocale: (locale: Locales) => void;\n};\n\nexport const DictionaryEditionDrawerController: FC<\n DictionaryEditionDrawerControllerProps\n> = ({ locale, localeList, setLocale }) => {\n const focusedContent = useEditionPanelStore((s) => s.focusedContent);\n const dictionaryId: string | undefined = focusedContent?.dictionaryId;\n\n if (!dictionaryId) {\n return null;\n }\n\n return (\n <DictionaryEditionDrawer\n locale={locale}\n localeList={localeList}\n setLocale={setLocale}\n dictionaryId={dictionaryId}\n />\n );\n};\n"],"mappings":";AA+CI;AA3CJ;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAMP,OAAO,kBAAkB;AAEzB,SAAS,+BAA+B;AACxC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,4BAA4B;AAQ9B,MAAM,iCAET,CAAC,EAAE,gBAAgB,QAAQ,WAAW,MAAM;AAC9C,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,2BAA2B,UAAU;AAEzC,QAAM,eAAuB,eAAe;AAC5C,QAAM,aAAyB,aAAa,YAAY;AACxD,QAAM,iBAAyB,WAAW;AAC1C,QAAM,0BAAyC,cAAc,cAAc;AAE3E,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,gBAAgB,eAAe;AAAA,MAC/B,eAAe;AAAA,MACf,gBAAgB,CAAC,YACf,kBAAkB,EAAE,GAAG,gBAAgB,QAAQ,CAAC;AAAA,MAElD,iBAAiB,CAAC,SAAS,aACzB,iBAAiB,gBAAgB,SAAS,QAAQ;AAAA,MAEpD,gBAAgB;AAAA,MAChB,iBAAiB,MAAM,6BAA6B,cAAc;AAAA;AAAA,EACpE;AAEJ;AAMO,MAAM,sBAAsB,CAAC,iBAClC,sBAAsB,YAAY;AAE7B,MAAM,0BAA4D,CAAC;AAAA,EACxE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,KAAK,oBAAoB,YAAY;AAE3C,QAAM,EAAE,gBAAgB,MAAM,IAAI,2BAA2B,YAAY;AACzE,QAAM,EAAE,MAAM,yBAAyB,IAAI,wBAAwB;AAEnE,QAAM,eAAe,MAAM;AACzB,UAAM;AACN,6BAAyB;AAAA,EAC3B;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,QACE;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA;AAAA,MACF;AAAA,MAEF,YAAY;AAAA,QACV,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,MAEC,4BACC;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA,YAAY;AAAA;AAAA,MACd;AAAA;AAAA,EAEJ;AAEJ;AAQO,MAAM,oCAET,CAAC,EAAE,QAAQ,YAAY,UAAU,MAAM;AACzC,QAAM,iBAAiB,qBAAqB,CAAC,MAAM,EAAE,cAAc;AACnE,QAAM,eAAmC,gBAAgB;AAEzD,MAAI,CAAC,cAAc;AACjB,WAAO;AAAA,EACT;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DictionaryEditionDrawer, DictionaryEditionDrawerContent, DictionaryEditionDrawerController, getDrawerIdentifier } from './DictionaryEditionDrawer.mjs';
|
|
2
|
+
export { FileContent, useDictionaryEditionDrawer, useDictionaryEditionDrawerControl } from './useDictionaryEditionDrawer.mjs';
|
|
3
|
+
export { EditedContent, useEditedContentStore } from './useEditedContentStore.mjs';
|
|
4
|
+
import '@intlayer/config/client';
|
|
5
|
+
import 'react';
|
|
6
|
+
import '@intlayer/core';
|
|
7
|
+
import 'zustand/middleware';
|
|
8
|
+
import 'zustand';
|
|
9
|
+
import '@intlayer/design-system';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/client/DictionaryEditionDrawer/index.ts"],"sourcesContent":["export * from './DictionaryEditionDrawer';\nexport * from './useDictionaryEditionDrawer';\nexport * from './useEditedContentStore';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { KeyPath } from '@intlayer/core';
|
|
2
|
+
import { EditedContent } from './useEditedContentStore.mjs';
|
|
3
|
+
import 'zustand/middleware';
|
|
4
|
+
import 'zustand';
|
|
5
|
+
import '@intlayer/design-system';
|
|
6
|
+
|
|
7
|
+
type DictionaryPath = string;
|
|
8
|
+
type FileContent = {
|
|
9
|
+
dictionaryPath: DictionaryPath;
|
|
10
|
+
dictionaryId: string;
|
|
11
|
+
keyPath?: KeyPath[];
|
|
12
|
+
};
|
|
13
|
+
type DictionaryEditionDrawer = {
|
|
14
|
+
focusedContent: FileContent | null;
|
|
15
|
+
setFocusedContent: (content: FileContent | null) => void;
|
|
16
|
+
isOpen: boolean;
|
|
17
|
+
open: (content: FileContent) => void;
|
|
18
|
+
close: () => void;
|
|
19
|
+
editContentRequest: () => Promise<void>;
|
|
20
|
+
editedContent: EditedContent;
|
|
21
|
+
addEditedContent: (dictionaryPath: DictionaryPath, keyPath: KeyPath[], newValue: string) => void;
|
|
22
|
+
getEditedContentValue: (dictionaryPath: DictionaryPath, keyPath: KeyPath[]) => string | undefined;
|
|
23
|
+
clearEditedDictionaryContent: (dictionaryPath: DictionaryPath) => void;
|
|
24
|
+
};
|
|
25
|
+
declare const useDictionaryEditionDrawer: (dictionaryId: string) => DictionaryEditionDrawer;
|
|
26
|
+
type DictionaryEditionDrawerControl = {
|
|
27
|
+
open: (content: FileContent) => void;
|
|
28
|
+
close: (dictionaryId: string) => void;
|
|
29
|
+
};
|
|
30
|
+
declare const useDictionaryEditionDrawerControl: () => DictionaryEditionDrawerControl;
|
|
31
|
+
|
|
32
|
+
export { type FileContent, useDictionaryEditionDrawer, useDictionaryEditionDrawerControl };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useRightDrawerStore } from "@intlayer/design-system";
|
|
2
|
+
import { useEditorServer } from '../useEditorServer.mjs';
|
|
3
|
+
import { getDrawerIdentifier } from './DictionaryEditionDrawer.mjs';
|
|
4
|
+
import {
|
|
5
|
+
useEditedContentStore
|
|
6
|
+
} from './useEditedContentStore.mjs';
|
|
7
|
+
import { useEditionPanelStore } from './useFocusContentStore.mjs';
|
|
8
|
+
const useDictionaryEditionDrawer = (dictionaryId) => {
|
|
9
|
+
const id = getDrawerIdentifier(dictionaryId);
|
|
10
|
+
const { isOpen, open, close } = useRightDrawerStore(id)();
|
|
11
|
+
const {
|
|
12
|
+
editedContent,
|
|
13
|
+
getEditedContentValue,
|
|
14
|
+
addEditedContent,
|
|
15
|
+
clearEditedDictionaryContent
|
|
16
|
+
} = useEditedContentStore((s) => ({
|
|
17
|
+
editedContent: s.editedContent,
|
|
18
|
+
addEditedContent: s.addEditedContent,
|
|
19
|
+
getEditedContentValue: s.getEditedContentValue,
|
|
20
|
+
clearEditedDictionaryContent: s.clearEditedDictionaryContent
|
|
21
|
+
}));
|
|
22
|
+
const { setFocusedContent, focusedContent } = useEditionPanelStore((s) => ({
|
|
23
|
+
focusedContent: s.focusedContent,
|
|
24
|
+
setFocusedContent: s.setFocusedContent
|
|
25
|
+
}));
|
|
26
|
+
const { editContentRequest } = useEditorServer();
|
|
27
|
+
const openDictionaryEditionDrawer = ({
|
|
28
|
+
dictionaryId: dictionaryId2,
|
|
29
|
+
dictionaryPath,
|
|
30
|
+
keyPath = []
|
|
31
|
+
}) => {
|
|
32
|
+
setFocusedContent({
|
|
33
|
+
dictionaryId: dictionaryId2,
|
|
34
|
+
dictionaryPath,
|
|
35
|
+
keyPath
|
|
36
|
+
});
|
|
37
|
+
open();
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
isOpen,
|
|
41
|
+
focusedContent,
|
|
42
|
+
setFocusedContent,
|
|
43
|
+
open: openDictionaryEditionDrawer,
|
|
44
|
+
close,
|
|
45
|
+
getEditedContentValue,
|
|
46
|
+
editContentRequest,
|
|
47
|
+
editedContent,
|
|
48
|
+
addEditedContent,
|
|
49
|
+
clearEditedDictionaryContent
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const useDictionaryEditionDrawerControl = () => {
|
|
53
|
+
const setFocusedContent = useEditionPanelStore((s) => s.setFocusedContent);
|
|
54
|
+
const open = ({
|
|
55
|
+
dictionaryId,
|
|
56
|
+
dictionaryPath,
|
|
57
|
+
keyPath = []
|
|
58
|
+
}) => {
|
|
59
|
+
setFocusedContent({
|
|
60
|
+
dictionaryId,
|
|
61
|
+
dictionaryPath,
|
|
62
|
+
keyPath
|
|
63
|
+
});
|
|
64
|
+
const id = getDrawerIdentifier(dictionaryId);
|
|
65
|
+
useRightDrawerStore(id).getState().open();
|
|
66
|
+
};
|
|
67
|
+
const close = (dictionaryId) => {
|
|
68
|
+
const id = getDrawerIdentifier(dictionaryId);
|
|
69
|
+
useRightDrawerStore(id).getState().close();
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
open,
|
|
73
|
+
close
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
export {
|
|
77
|
+
useDictionaryEditionDrawer,
|
|
78
|
+
useDictionaryEditionDrawerControl
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=useDictionaryEditionDrawer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/client/DictionaryEditionDrawer/useDictionaryEditionDrawer.ts"],"sourcesContent":["import type { KeyPath } from '@intlayer/core';\nimport { useRightDrawerStore } from '@intlayer/design-system';\nimport { useEditorServer } from '../useEditorServer';\nimport { getDrawerIdentifier } from './DictionaryEditionDrawer';\nimport {\n type EditedContent,\n useEditedContentStore,\n} from './useEditedContentStore';\nimport { useEditionPanelStore } from './useFocusContentStore';\n\ntype DictionaryPath = string;\nexport type FileContent = {\n dictionaryPath: DictionaryPath;\n dictionaryId: string;\n keyPath?: KeyPath[];\n};\n\ntype DictionaryEditionDrawer = {\n focusedContent: FileContent | null;\n setFocusedContent: (content: FileContent | null) => void;\n isOpen: boolean;\n open: (content: FileContent) => void;\n close: () => void;\n editContentRequest: () => Promise<void>;\n editedContent: EditedContent;\n addEditedContent: (\n dictionaryPath: DictionaryPath,\n keyPath: KeyPath[],\n newValue: string\n ) => void;\n getEditedContentValue: (\n dictionaryPath: DictionaryPath,\n keyPath: KeyPath[]\n ) => string | undefined;\n clearEditedDictionaryContent: (dictionaryPath: DictionaryPath) => void;\n};\n\ntype OpenDictionaryEditionDrawerProps = {\n dictionaryId: string;\n dictionaryPath: string;\n keyPath?: KeyPath[];\n};\n\nexport const useDictionaryEditionDrawer = (\n dictionaryId: string\n): DictionaryEditionDrawer => {\n const id = getDrawerIdentifier(dictionaryId);\n const { isOpen, open, close } = useRightDrawerStore(id)();\n const {\n editedContent,\n getEditedContentValue,\n addEditedContent,\n clearEditedDictionaryContent,\n } = useEditedContentStore((s) => ({\n editedContent: s.editedContent,\n addEditedContent: s.addEditedContent,\n getEditedContentValue: s.getEditedContentValue,\n clearEditedDictionaryContent: s.clearEditedDictionaryContent,\n }));\n const { setFocusedContent, focusedContent } = useEditionPanelStore((s) => ({\n focusedContent: s.focusedContent,\n setFocusedContent: s.setFocusedContent,\n }));\n const { editContentRequest } = useEditorServer();\n\n const openDictionaryEditionDrawer = ({\n dictionaryId,\n dictionaryPath,\n keyPath = [],\n }: OpenDictionaryEditionDrawerProps) => {\n setFocusedContent({\n dictionaryId,\n dictionaryPath,\n keyPath,\n });\n\n open();\n };\n\n return {\n isOpen,\n focusedContent,\n setFocusedContent,\n open: openDictionaryEditionDrawer,\n close,\n getEditedContentValue,\n editContentRequest,\n editedContent,\n addEditedContent,\n clearEditedDictionaryContent,\n };\n};\n\ntype DictionaryEditionDrawerControl = {\n open: (content: FileContent) => void;\n close: (dictionaryId: string) => void;\n};\n\nexport const useDictionaryEditionDrawerControl =\n (): DictionaryEditionDrawerControl => {\n const setFocusedContent = useEditionPanelStore((s) => s.setFocusedContent);\n\n const open = ({\n dictionaryId,\n dictionaryPath,\n keyPath = [],\n }: OpenDictionaryEditionDrawerProps) => {\n setFocusedContent({\n dictionaryId,\n dictionaryPath,\n keyPath,\n });\n\n const id = getDrawerIdentifier(dictionaryId);\n\n useRightDrawerStore(id).getState().open();\n };\n\n const close = (dictionaryId: string) => {\n const id = getDrawerIdentifier(dictionaryId);\n\n useRightDrawerStore(id).getState().close();\n };\n\n return {\n open,\n close,\n };\n };\n"],"mappings":"AACA,SAAS,2BAA2B;AACpC,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;AACpC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,4BAA4B;AAmC9B,MAAM,6BAA6B,CACxC,iBAC4B;AAC5B,QAAM,KAAK,oBAAoB,YAAY;AAC3C,QAAM,EAAE,QAAQ,MAAM,MAAM,IAAI,oBAAoB,EAAE,EAAE;AACxD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,sBAAsB,CAAC,OAAO;AAAA,IAChC,eAAe,EAAE;AAAA,IACjB,kBAAkB,EAAE;AAAA,IACpB,uBAAuB,EAAE;AAAA,IACzB,8BAA8B,EAAE;AAAA,EAClC,EAAE;AACF,QAAM,EAAE,mBAAmB,eAAe,IAAI,qBAAqB,CAAC,OAAO;AAAA,IACzE,gBAAgB,EAAE;AAAA,IAClB,mBAAmB,EAAE;AAAA,EACvB,EAAE;AACF,QAAM,EAAE,mBAAmB,IAAI,gBAAgB;AAE/C,QAAM,8BAA8B,CAAC;AAAA,IACnC,cAAAA;AAAA,IACA;AAAA,IACA,UAAU,CAAC;AAAA,EACb,MAAwC;AACtC,sBAAkB;AAAA,MAChB,cAAAA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,SAAK;AAAA,EACP;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAOO,MAAM,oCACX,MAAsC;AACpC,QAAM,oBAAoB,qBAAqB,CAAC,MAAM,EAAE,iBAAiB;AAEzE,QAAM,OAAO,CAAC;AAAA,IACZ;AAAA,IACA;AAAA,IACA,UAAU,CAAC;AAAA,EACb,MAAwC;AACtC,sBAAkB;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,UAAM,KAAK,oBAAoB,YAAY;AAE3C,wBAAoB,EAAE,EAAE,SAAS,EAAE,KAAK;AAAA,EAC1C;AAEA,QAAM,QAAQ,CAAC,iBAAyB;AACtC,UAAM,KAAK,oBAAoB,YAAY;AAE3C,wBAAoB,EAAE,EAAE,SAAS,EAAE,MAAM;AAAA,EAC3C;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["dictionaryId"]}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
import { isSameKeyPath } from "@intlayer/core";
|
|
1
2
|
import { create } from "zustand";
|
|
2
3
|
import { persist, createJSONStorage } from "zustand/middleware";
|
|
3
|
-
const isSameKeyPath = (keyPath1, keyPath2) => keyPath1.every(
|
|
4
|
-
(element, index) => keyPath2[index] && keyPath2[index].key === element.key && keyPath2[index].type === element.type
|
|
5
|
-
);
|
|
6
4
|
const useEditedContentStore = create(
|
|
7
5
|
persist(
|
|
8
6
|
(set, get) => ({
|
|
@@ -40,12 +38,22 @@ const useEditedContentStore = create(
|
|
|
40
38
|
});
|
|
41
39
|
},
|
|
42
40
|
clearEditedDictionaryContent: (dictionaryPath) => {
|
|
43
|
-
set((state) =>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
set((state) => {
|
|
42
|
+
const filteredEditedContent = Object.entries(
|
|
43
|
+
state.editedContent
|
|
44
|
+
).reduce((acc, [path, content]) => {
|
|
45
|
+
if (path === dictionaryPath) {
|
|
46
|
+
return acc;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
...acc,
|
|
50
|
+
[path]: content
|
|
51
|
+
};
|
|
52
|
+
}, {});
|
|
53
|
+
return {
|
|
54
|
+
editedContent: filteredEditedContent
|
|
55
|
+
};
|
|
56
|
+
});
|
|
49
57
|
},
|
|
50
58
|
clearEditedContent: () => {
|
|
51
59
|
set({ editedContent: {} });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/client/DictionaryEditionDrawer/useEditedContentStore.ts"],"sourcesContent":["import { type KeyPath, isSameKeyPath } 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\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 const filteredEditedContent = Object.entries(\n state.editedContent\n ).reduce((acc, [path, content]) => {\n if (path === dictionaryPath) {\n return acc;\n }\n\n return {\n ...acc,\n [path]: content,\n };\n }, {});\n\n return {\n editedContent: filteredEditedContent,\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,SAAuB,qBAAqB;AAE5C,SAAS,cAAc;AACvB,SAAS,SAAS,yBAAyB;AAyBpC,MAAM,wBAAwB;AAAA,EACnC;AAAA,IACE,CAAC,KAAK,SAAS;AAAA,MACb,eAAe,CAAC;AAAA,MAChB,kBAAkB,CAAC,gBAAgB,SAAS,aAAa;AACvD,YAAI,CAAC,UAAU;AACb,gBAAM,gBAAgB,MAAM,cAAc,cAAc,KAAK,CAAC;AAC9D,iBAAO;AAAA,YACL,eAAe;AAAA,cACb,GAAG,MAAM;AAAA,cACT,CAAC,cAAc,GAAG;AAAA,gBAChB,GAAG,cAAc;AAAA,kBACf,CAAC,YAAY,CAAC,cAAc,QAAQ,SAAS,OAAO;AAAA,gBACtD;AAAA,gBACA;AAAA,kBACE;AAAA,kBACA;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAAA,MAEA,qBAAqB,CAAC,gBAAgB,YAAY;AAChD,YAAI,CAAC,UAAU;AACb,gBAAM,gBAAgB,MAAM,cAAc,cAAc,KAAK,CAAC;AAC9D,iBAAO;AAAA,YACL,eAAe;AAAA,cACb,GAAG,MAAM;AAAA,cACT,CAAC,cAAc,GAAG,cAAc;AAAA,gBAC9B,CAAC,YAAY,QAAQ,YAAY;AAAA,cACnC;AAAA,YACF;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAAA,MAEA,8BAA8B,CAAC,mBAAmB;AAChD,YAAI,CAAC,UAAU;AACb,gBAAM,wBAAwB,OAAO;AAAA,YACnC,MAAM;AAAA,UACR,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,OAAO,MAAM;AACjC,gBAAI,SAAS,gBAAgB;AAC3B,qBAAO;AAAA,YACT;AAEA,mBAAO;AAAA,cACL,GAAG;AAAA,cACH,CAAC,IAAI,GAAG;AAAA,YACV;AAAA,UACF,GAAG,CAAC,CAAC;AAEL,iBAAO;AAAA,YACL,eAAe;AAAA,UACjB;AAAA,QACF,CAAC;AAAA,MACH;AAAA,MAEA,oBAAoB,MAAM;AACxB,YAAI,EAAE,eAAe,CAAC,EAAE,CAAC;AAAA,MAC3B;AAAA,MAEA,uBAAuB,CAAC,gBAAgB,YACtC,IAAI,EAAE,cAAc,cAAc,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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/client/DictionaryEditionDrawer/useFocusContentStore.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":[]}
|