@intlayer/editor 4.0.3 → 4.0.5
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 +22 -0
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +85 -0
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/getDictionaryValueByKeyPath.cjs +42 -0
- package/dist/cjs/dictionaryManipulator/getDictionaryValueByKeyPath.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/getSectionType.cjs +48 -0
- package/dist/cjs/dictionaryManipulator/getSectionType.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/index.cjs +31 -0
- package/dist/cjs/dictionaryManipulator/index.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/isValidReactElement.cjs +30 -0
- package/dist/cjs/dictionaryManipulator/isValidReactElement.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/removeDictionaryValueByKeyPath.cjs +55 -0
- package/dist/cjs/dictionaryManipulator/removeDictionaryValueByKeyPath.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/renameDictionaryValueByKeyPath.cjs +64 -0
- package/dist/cjs/dictionaryManipulator/renameDictionaryValueByKeyPath.cjs.map +1 -0
- package/dist/cjs/dictionaryStatus.cjs +17 -0
- package/dist/cjs/dictionaryStatus.cjs.map +1 -0
- package/dist/cjs/index.cjs +4 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +23 -0
- package/dist/cjs/server/index.cjs.map +1 -0
- package/dist/cjs/server/writeContentDeclaration.cjs +118 -0
- package/dist/cjs/server/writeContentDeclaration.cjs.map +1 -0
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +61 -0
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/getDictionaryValueByKeyPath.mjs +18 -0
- package/dist/esm/dictionaryManipulator/getDictionaryValueByKeyPath.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/getSectionType.mjs +26 -0
- package/dist/esm/dictionaryManipulator/getSectionType.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/index.mjs +6 -0
- package/dist/esm/dictionaryManipulator/index.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/isValidReactElement.mjs +6 -0
- package/dist/esm/dictionaryManipulator/isValidReactElement.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/removeDictionaryValueByKeyPath.mjs +31 -0
- package/dist/esm/dictionaryManipulator/removeDictionaryValueByKeyPath.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/renameDictionaryValueByKeyPath.mjs +40 -0
- package/dist/esm/dictionaryManipulator/renameDictionaryValueByKeyPath.mjs.map +1 -0
- package/dist/esm/dictionaryStatus.mjs +1 -0
- package/dist/esm/dictionaryStatus.mjs.map +1 -0
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/server/index.mjs +2 -0
- package/dist/esm/server/index.mjs.map +1 -0
- package/dist/esm/server/writeContentDeclaration.mjs +84 -0
- package/dist/esm/server/writeContentDeclaration.mjs.map +1 -0
- package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts +3 -0
- package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/getDictionaryValueByKeyPath.d.ts +3 -0
- package/dist/types/dictionaryManipulator/getDictionaryValueByKeyPath.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/getSectionType.d.ts +3 -0
- package/dist/types/dictionaryManipulator/getSectionType.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/index.d.ts +6 -0
- package/dist/types/dictionaryManipulator/index.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/isValidReactElement.d.ts +9 -0
- package/dist/types/dictionaryManipulator/isValidReactElement.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/removeDictionaryValueByKeyPath.d.ts +3 -0
- package/dist/types/dictionaryManipulator/removeDictionaryValueByKeyPath.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/renameDictionaryValueByKeyPath.d.ts +3 -0
- package/dist/types/dictionaryManipulator/renameDictionaryValueByKeyPath.d.ts.map +1 -0
- package/dist/types/dictionaryStatus.d.ts +2 -0
- package/dist/types/dictionaryStatus.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/server/index.d.ts +2 -0
- package/dist/types/server/index.d.ts.map +1 -0
- package/dist/types/server/writeContentDeclaration.d.ts +8 -0
- package/dist/types/server/writeContentDeclaration.d.ts.map +1 -0
- package/package.json +22 -5
- package/dist/cjs/CrossFrameCommunicator.cjs +0 -89
- package/dist/cjs/CrossFrameCommunicator.cjs.map +0 -1
- package/dist/esm/CrossFrameCommunicator.mjs +0 -65
- package/dist/esm/CrossFrameCommunicator.mjs.map +0 -1
- package/dist/types/CrossFrameCommunicator.d.ts +0 -52
- package/dist/types/CrossFrameCommunicator.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -16,3 +16,25 @@
|
|
|
16
16
|
/>
|
|
17
17
|
</a>
|
|
18
18
|
</div>
|
|
19
|
+
|
|
20
|
+
# @intlayer/editor: Utilities to interface the application with the Intlayer editor and manipulate dictionaries
|
|
21
|
+
|
|
22
|
+
**Intlayer** is a suite of packages designed specifically for JavaScript developers. It is compatible with frameworks like React, Next.js, and Express.js.
|
|
23
|
+
|
|
24
|
+
The **`intlayer-editor`** package provides utilities to interface the application with the Intlayer editor. It includes the API to interact with the editor, and utilities to manipulate dictionaries. This package is cross-platform.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
Install the necessary package using your preferred package manager:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install @intlayer/editor
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
yarn add @intlayer/editor
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pnpm add @intlayer/editor
|
|
40
|
+
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var editDictionaryByKeyPath_exports = {};
|
|
20
|
+
__export(editDictionaryByKeyPath_exports, {
|
|
21
|
+
editDictionaryByKeyPath: () => editDictionaryByKeyPath
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(editDictionaryByKeyPath_exports);
|
|
24
|
+
var import_core = require("@intlayer/core");
|
|
25
|
+
const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
|
|
26
|
+
let currentValue = dictionaryContent;
|
|
27
|
+
let parentValue = null;
|
|
28
|
+
let lastKeys = [];
|
|
29
|
+
for (const keyObj of keyPath) {
|
|
30
|
+
parentValue = currentValue;
|
|
31
|
+
if (keyObj.type === import_core.NodeType.Object) {
|
|
32
|
+
lastKeys = [keyObj.key];
|
|
33
|
+
if (!currentValue[keyObj.key]) {
|
|
34
|
+
currentValue = {
|
|
35
|
+
...currentValue,
|
|
36
|
+
[keyObj.key]: {}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
currentValue = currentValue[keyObj.key];
|
|
40
|
+
} else if (keyObj.type === import_core.NodeType.Array) {
|
|
41
|
+
lastKeys = [keyObj.key];
|
|
42
|
+
if (!currentValue[keyObj.key]) {
|
|
43
|
+
currentValue[keyObj.key] = {};
|
|
44
|
+
}
|
|
45
|
+
currentValue = currentValue[keyObj.key];
|
|
46
|
+
} else if (keyObj.type === import_core.NodeType.Translation) {
|
|
47
|
+
lastKeys = [import_core.NodeType.Translation, keyObj.key];
|
|
48
|
+
if (!currentValue[import_core.NodeType.Translation]) {
|
|
49
|
+
currentValue[import_core.NodeType.Translation] = {
|
|
50
|
+
...currentValue[import_core.NodeType.Translation],
|
|
51
|
+
[keyObj.key]: newValue
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
currentValue = currentValue[import_core.NodeType.Translation][keyObj.key];
|
|
55
|
+
} else if (keyObj.type === import_core.NodeType.Enumeration) {
|
|
56
|
+
lastKeys = [import_core.NodeType.Enumeration, keyObj.key];
|
|
57
|
+
if (!currentValue[import_core.NodeType.Enumeration]) {
|
|
58
|
+
currentValue[import_core.NodeType.Enumeration] = {
|
|
59
|
+
...currentValue[import_core.NodeType.Enumeration],
|
|
60
|
+
[keyObj.key]: newValue
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
currentValue = currentValue[import_core.NodeType.Enumeration][keyObj.key];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (parentValue && lastKeys.length > 0) {
|
|
67
|
+
for (const key of lastKeys.slice(0, -1)) {
|
|
68
|
+
parentValue = parentValue[key];
|
|
69
|
+
}
|
|
70
|
+
if (
|
|
71
|
+
// Remove the field if the new value is undefined
|
|
72
|
+
typeof newValue === "undefined"
|
|
73
|
+
) {
|
|
74
|
+
delete parentValue[lastKeys[lastKeys.length - 1]];
|
|
75
|
+
} else {
|
|
76
|
+
parentValue[lastKeys[lastKeys.length - 1]] = newValue;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return dictionaryContent;
|
|
80
|
+
};
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
editDictionaryByKeyPath
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=editDictionaryByKeyPath.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type DictionaryValue, type KeyPath, NodeType } from '@intlayer/core';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[],\n newValue: DictionaryValue\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object) {\n lastKeys = [keyObj.key];\n\n if (!currentValue[keyObj.key]) {\n currentValue = {\n ...currentValue,\n [keyObj.key]: {},\n };\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n\n if (!currentValue[keyObj.key]) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKeys = [NodeType.Translation, keyObj.key];\n\n if (!currentValue[NodeType.Translation]) {\n currentValue[NodeType.Translation] = {\n ...currentValue[NodeType.Translation],\n [keyObj.key]: newValue,\n };\n }\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKeys = [NodeType.Enumeration, keyObj.key];\n\n if (!currentValue[NodeType.Enumeration]) {\n currentValue[NodeType.Enumeration] = {\n ...currentValue[NodeType.Enumeration],\n [keyObj.key]: newValue,\n };\n }\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n // Assign the new value to the last key of the parent\n if (parentValue && lastKeys.length > 0) {\n for (const key of lastKeys.slice(0, -1)) {\n parentValue = parentValue[key];\n }\n if (\n // Remove the field if the new value is undefined\n typeof newValue === 'undefined'\n ) {\n delete parentValue[lastKeys[lastKeys.length - 1]];\n } else {\n parentValue[lastKeys[lastKeys.length - 1]] = newValue;\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAA6D;AAItD,MAAM,0BAA0B,CACrC,mBACA,SACA,aACoB;AACpB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,WAA0B,CAAC;AAE/B,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,qBAAS,QAAQ;AACnC,iBAAW,CAAC,OAAO,GAAG;AAEtB,UAAI,CAAC,aAAa,OAAO,GAAG,GAAG;AAC7B,uBAAe;AAAA,UACb,GAAG;AAAA,UACH,CAAC,OAAO,GAAG,GAAG,CAAC;AAAA,QACjB;AAAA,MACF;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,qBAAS,OAAO;AACzC,iBAAW,CAAC,OAAO,GAAG;AAEtB,UAAI,CAAC,aAAa,OAAO,GAAG,GAAG;AAC7B,qBAAa,OAAO,GAAG,IAAI,CAAC;AAAA,MAC9B;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,iBAAW,CAAC,qBAAS,aAAa,OAAO,GAAG;AAE5C,UAAI,CAAC,aAAa,qBAAS,WAAW,GAAG;AACvC,qBAAa,qBAAS,WAAW,IAAI;AAAA,UACnC,GAAG,aAAa,qBAAS,WAAW;AAAA,UACpC,CAAC,OAAO,GAAG,GAAG;AAAA,QAChB;AAAA,MACF;AACA,qBAAe,aAAa,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,iBAAW,CAAC,qBAAS,aAAa,OAAO,GAAG;AAE5C,UAAI,CAAC,aAAa,qBAAS,WAAW,GAAG;AACvC,qBAAa,qBAAS,WAAW,IAAI;AAAA,UACnC,GAAG,aAAa,qBAAS,WAAW;AAAA,UACpC,CAAC,OAAO,GAAG,GAAG;AAAA,QAChB;AAAA,MACF;AACA,qBAAe,aAAa,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D;AAAA,EACF;AAGA,MAAI,eAAe,SAAS,SAAS,GAAG;AACtC,eAAW,OAAO,SAAS,MAAM,GAAG,EAAE,GAAG;AACvC,oBAAc,YAAY,GAAG;AAAA,IAC/B;AACA;AAAA;AAAA,MAEE,OAAO,aAAa;AAAA,MACpB;AACA,aAAO,YAAY,SAAS,SAAS,SAAS,CAAC,CAAC;AAAA,IAClD,OAAO;AACL,kBAAY,SAAS,SAAS,SAAS,CAAC,CAAC,IAAI;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var getDictionaryValueByKeyPath_exports = {};
|
|
20
|
+
__export(getDictionaryValueByKeyPath_exports, {
|
|
21
|
+
getDictionaryValueByKeyPath: () => getDictionaryValueByKeyPath
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(getDictionaryValueByKeyPath_exports);
|
|
24
|
+
var import_core = require("@intlayer/core");
|
|
25
|
+
const getDictionaryValueByKeyPath = (dictionaryContent, keyPath) => {
|
|
26
|
+
let currentValue = JSON.parse(JSON.stringify(dictionaryContent ?? {}));
|
|
27
|
+
for (const keyObj of keyPath) {
|
|
28
|
+
if (keyObj.type === import_core.NodeType.Object || keyObj.type === import_core.NodeType.Array) {
|
|
29
|
+
currentValue = currentValue?.[keyObj.key];
|
|
30
|
+
} else if (keyObj.type === import_core.NodeType.Translation) {
|
|
31
|
+
currentValue = currentValue?.[import_core.NodeType.Translation][keyObj.key];
|
|
32
|
+
} else if (keyObj.type === import_core.NodeType.Enumeration) {
|
|
33
|
+
currentValue = currentValue?.[import_core.NodeType.Enumeration][keyObj.key];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return currentValue;
|
|
37
|
+
};
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
getDictionaryValueByKeyPath
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=getDictionaryValueByKeyPath.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/getDictionaryValueByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type DictionaryValue, type KeyPath, NodeType } from '@intlayer/core';\n\nexport const getDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = JSON.parse(JSON.stringify(dictionaryContent ?? {}));\n\n for (const keyObj of keyPath) {\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];\n }\n }\n\n return currentValue as DictionaryValue;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAA6D;AAEtD,MAAM,8BAA8B,CACzC,mBACA,YACoB;AACpB,MAAI,eAAoB,KAAK,MAAM,KAAK,UAAU,qBAAqB,CAAC,CAAC,CAAC;AAE1E,aAAW,UAAU,SAAS;AAC5B,QAAI,OAAO,SAAS,qBAAS,UAAU,OAAO,SAAS,qBAAS,OAAO;AACrE,qBAAe,eAAe,OAAO,GAAG;AAAA,IAC1C,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,qBAAe,eAAe,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,qBAAe,eAAe,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var getSectionType_exports = {};
|
|
20
|
+
__export(getSectionType_exports, {
|
|
21
|
+
getSectionType: () => getSectionType
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(getSectionType_exports);
|
|
24
|
+
var import_core = require("@intlayer/core");
|
|
25
|
+
var import_isValidReactElement = require('./isValidReactElement.cjs');
|
|
26
|
+
const getSectionType = (section) => {
|
|
27
|
+
if (typeof section === "string") {
|
|
28
|
+
return import_core.NodeType.Text;
|
|
29
|
+
}
|
|
30
|
+
if (section?.nodeType === import_core.NodeType.Translation) {
|
|
31
|
+
return import_core.NodeType.Translation;
|
|
32
|
+
}
|
|
33
|
+
if (section?.nodeType === import_core.NodeType.Enumeration) {
|
|
34
|
+
return import_core.NodeType.Enumeration;
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(section)) {
|
|
37
|
+
return import_core.NodeType.Array;
|
|
38
|
+
}
|
|
39
|
+
if ((0, import_isValidReactElement.isValidElement)(section)) {
|
|
40
|
+
return import_core.NodeType.ReactNode;
|
|
41
|
+
}
|
|
42
|
+
return import_core.NodeType.Object;
|
|
43
|
+
};
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
getSectionType
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=getSectionType.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/getSectionType.ts"],"sourcesContent":["import {\n type TranslationContent,\n type EnumerationContent,\n type DictionaryValue,\n NodeType,\n} from '@intlayer/core';\nimport { isValidElement } from './isValidReactElement';\n\nexport const getSectionType = (section: DictionaryValue): NodeType => {\n if (typeof section === 'string') {\n return NodeType.Text;\n }\n\n if (\n (section as TranslationContent<unknown>)?.nodeType === NodeType.Translation\n ) {\n return NodeType.Translation;\n }\n\n if (\n (section as EnumerationContent<unknown>)?.nodeType === NodeType.Enumeration\n ) {\n return NodeType.Enumeration;\n }\n\n if (Array.isArray(section)) {\n return NodeType.Array;\n }\n\n if (isValidElement(section)) {\n return NodeType.ReactNode;\n }\n\n return NodeType.Object;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAKO;AACP,iCAA+B;AAExB,MAAM,iBAAiB,CAAC,YAAuC;AACpE,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO,qBAAS;AAAA,EAClB;AAEA,MACG,SAAyC,aAAa,qBAAS,aAChE;AACA,WAAO,qBAAS;AAAA,EAClB;AAEA,MACG,SAAyC,aAAa,qBAAS,aAChE;AACA,WAAO,qBAAS;AAAA,EAClB;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAO,qBAAS;AAAA,EAClB;AAEA,UAAI,2CAAe,OAAO,GAAG;AAC3B,WAAO,qBAAS;AAAA,EAClB;AAEA,SAAO,qBAAS;AAClB;","names":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var dictionaryManipulator_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(dictionaryManipulator_exports);
|
|
18
|
+
__reExport(dictionaryManipulator_exports, require('./editDictionaryByKeyPath.cjs'), module.exports);
|
|
19
|
+
__reExport(dictionaryManipulator_exports, require('./getDictionaryValueByKeyPath.cjs'), module.exports);
|
|
20
|
+
__reExport(dictionaryManipulator_exports, require('./getSectionType.cjs'), module.exports);
|
|
21
|
+
__reExport(dictionaryManipulator_exports, require('./removeDictionaryValueByKeyPath.cjs'), module.exports);
|
|
22
|
+
__reExport(dictionaryManipulator_exports, require('./renameDictionaryValueByKeyPath.cjs'), module.exports);
|
|
23
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
24
|
+
0 && (module.exports = {
|
|
25
|
+
...require('./editDictionaryByKeyPath.cjs'),
|
|
26
|
+
...require('./getDictionaryValueByKeyPath.cjs'),
|
|
27
|
+
...require('./getSectionType.cjs'),
|
|
28
|
+
...require('./removeDictionaryValueByKeyPath.cjs'),
|
|
29
|
+
...require('./renameDictionaryValueByKeyPath.cjs')
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/index.ts"],"sourcesContent":["export * from './editDictionaryByKeyPath';\nexport * from './getDictionaryValueByKeyPath';\nexport * from './getSectionType';\nexport * from './removeDictionaryValueByKeyPath';\nexport * from './renameDictionaryValueByKeyPath';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0CAAc,sCAAd;AACA,0CAAc,0CADd;AAEA,0CAAc,6BAFd;AAGA,0CAAc,6CAHd;AAIA,0CAAc,6CAJd;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var isValidReactElement_exports = {};
|
|
20
|
+
__export(isValidReactElement_exports, {
|
|
21
|
+
isValidElement: () => isValidElement
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(isValidReactElement_exports);
|
|
24
|
+
const REACT_ELEMENT_TYPE = Symbol.for("react.element");
|
|
25
|
+
const isValidElement = (object) => typeof object === "object" && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
isValidElement
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=isValidReactElement.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/isValidReactElement.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nconst REACT_ELEMENT_TYPE = Symbol.for('react.element');\n\n/**\n * Verifies the object is a ReactElement.\n * See https://reactjs.org/docs/react-api.html#isvalidelement\n * @param object\n * @return True if `object` is a ReactElement.\n * @final\n */\n\nexport const isValidElement = (object: any): boolean =>\n typeof object === 'object' &&\n object !== null &&\n object.$$typeof === REACT_ELEMENT_TYPE;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,MAAM,qBAAqB,OAAO,IAAI,eAAe;AAU9C,MAAM,iBAAiB,CAAC,WAC7B,OAAO,WAAW,YAClB,WAAW,QACX,OAAO,aAAa;","names":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var removeDictionaryValueByKeyPath_exports = {};
|
|
20
|
+
__export(removeDictionaryValueByKeyPath_exports, {
|
|
21
|
+
removeDictionaryValueByKeyPath: () => removeDictionaryValueByKeyPath
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(removeDictionaryValueByKeyPath_exports);
|
|
24
|
+
var import_core = require("@intlayer/core");
|
|
25
|
+
const removeDictionaryValueByKeyPath = (dictionaryContent, keyPath) => {
|
|
26
|
+
let currentValue = dictionaryContent;
|
|
27
|
+
let parentValue = null;
|
|
28
|
+
let lastKey = null;
|
|
29
|
+
for (const keyObj of keyPath) {
|
|
30
|
+
parentValue = currentValue;
|
|
31
|
+
if (keyObj.type === import_core.NodeType.Object || keyObj.type === import_core.NodeType.Array) {
|
|
32
|
+
lastKey = keyObj.key;
|
|
33
|
+
currentValue = currentValue[keyObj.key];
|
|
34
|
+
} else if (keyObj.type === import_core.NodeType.Translation) {
|
|
35
|
+
lastKey = import_core.NodeType.Translation;
|
|
36
|
+
currentValue = currentValue[import_core.NodeType.Translation][keyObj.key];
|
|
37
|
+
} else if (keyObj.type === import_core.NodeType.Enumeration) {
|
|
38
|
+
lastKey = import_core.NodeType.Enumeration;
|
|
39
|
+
currentValue = currentValue[import_core.NodeType.Enumeration][keyObj.key];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (parentValue && lastKey !== null) {
|
|
43
|
+
if (Array.isArray(parentValue)) {
|
|
44
|
+
parentValue.splice(lastKey, 1);
|
|
45
|
+
} else {
|
|
46
|
+
delete parentValue[lastKey];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return dictionaryContent;
|
|
50
|
+
};
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
removeDictionaryValueByKeyPath
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=removeDictionaryValueByKeyPath.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/removeDictionaryValueByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { DictionaryValue, KeyPath, NodeType } from '@intlayer/core';\n\nexport const removeDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKey = NodeType.Translation;\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKey = NodeType.Enumeration;\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAmD;AAE5C,MAAM,iCAAiC,CAC5C,mBACA,YACoB;AACpB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,UAAkC;AAEtC,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,qBAAS,UAAU,OAAO,SAAS,qBAAS,OAAO;AACrE,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,gBAAU,qBAAS;AACnB,qBAAe,aAAa,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,gBAAU,qBAAS;AACnB,qBAAe,aAAa,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D;AAAA,EACF;AAEA,MAAI,eAAe,YAAY,MAAM;AACnC,QAAI,MAAM,QAAQ,WAAW,GAAG;AAC9B,kBAAY,OAAO,SAA8B,CAAC;AAAA,IACpD,OAAO;AACL,aAAO,YAAY,OAAO;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var renameDictionaryValueByKeyPath_exports = {};
|
|
20
|
+
__export(renameDictionaryValueByKeyPath_exports, {
|
|
21
|
+
renameDictionaryValueByKeyPath: () => renameDictionaryValueByKeyPath
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(renameDictionaryValueByKeyPath_exports);
|
|
24
|
+
var import_core = require("@intlayer/core");
|
|
25
|
+
const renameDictionaryValueByKeyPath = (dictionaryContent, newKey, keyPath) => {
|
|
26
|
+
let currentValue = dictionaryContent;
|
|
27
|
+
let parentValue = null;
|
|
28
|
+
let lastKey = null;
|
|
29
|
+
for (const keyObj of keyPath) {
|
|
30
|
+
parentValue = currentValue;
|
|
31
|
+
if (keyObj.type === import_core.NodeType.Object || keyObj.type === import_core.NodeType.Array) {
|
|
32
|
+
lastKey = keyObj.key;
|
|
33
|
+
currentValue = currentValue[keyObj.key];
|
|
34
|
+
} else if (keyObj.type === import_core.NodeType.Translation) {
|
|
35
|
+
lastKey = import_core.NodeType.Translation;
|
|
36
|
+
currentValue = currentValue[import_core.NodeType.Translation][keyObj.key];
|
|
37
|
+
} else if (keyObj.type === import_core.NodeType.Enumeration) {
|
|
38
|
+
lastKey = import_core.NodeType.Enumeration;
|
|
39
|
+
currentValue = currentValue[import_core.NodeType.Enumeration][keyObj.key];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (parentValue && lastKey !== null) {
|
|
43
|
+
if (Array.isArray(parentValue)) {
|
|
44
|
+
parentValue[lastKey] = currentValue;
|
|
45
|
+
} else {
|
|
46
|
+
const newParentValue = {};
|
|
47
|
+
for (const key of Object.keys(parentValue)) {
|
|
48
|
+
if (key === lastKey) {
|
|
49
|
+
newParentValue[newKey] = currentValue;
|
|
50
|
+
} else {
|
|
51
|
+
newParentValue[key] = parentValue[key];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
Object.keys(parentValue).forEach((key) => delete parentValue[key]);
|
|
55
|
+
Object.assign(parentValue, newParentValue);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return dictionaryContent;
|
|
59
|
+
};
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
renameDictionaryValueByKeyPath
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=renameDictionaryValueByKeyPath.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/renameDictionaryValueByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { DictionaryValue, KeyPath, NodeType } from '@intlayer/core';\n\nexport const renameDictionaryValueByKeyPath = (\n dictionaryContent: DictionaryValue,\n newKey: string | number,\n keyPath: KeyPath[]\n): DictionaryValue => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKey = NodeType.Translation;\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKey = NodeType.Enumeration;\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n }\n }\n\n // Assign the new value to the last key of the parent while preserving the order\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue[lastKey as number] = currentValue;\n } else {\n const newParentValue: any = {};\n for (const key of Object.keys(parentValue)) {\n if (key === lastKey) {\n newParentValue[newKey] = currentValue;\n } else {\n newParentValue[key] = parentValue[key];\n }\n }\n // Replace the contents of parentValue with newParentValue\n Object.keys(parentValue).forEach((key) => delete parentValue[key]);\n Object.assign(parentValue, newParentValue);\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAmD;AAE5C,MAAM,iCAAiC,CAC5C,mBACA,QACA,YACoB;AACpB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,UAAkC;AAEtC,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,qBAAS,UAAU,OAAO,SAAS,qBAAS,OAAO;AACrE,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,gBAAU,qBAAS;AACnB,qBAAe,aAAa,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,qBAAS,aAAa;AAC/C,gBAAU,qBAAS;AACnB,qBAAe,aAAa,qBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D;AAAA,EACF;AAGA,MAAI,eAAe,YAAY,MAAM;AACnC,QAAI,MAAM,QAAQ,WAAW,GAAG;AAC9B,kBAAY,OAAiB,IAAI;AAAA,IACnC,OAAO;AACL,YAAM,iBAAsB,CAAC;AAC7B,iBAAW,OAAO,OAAO,KAAK,WAAW,GAAG;AAC1C,YAAI,QAAQ,SAAS;AACnB,yBAAe,MAAM,IAAI;AAAA,QAC3B,OAAO;AACL,yBAAe,GAAG,IAAI,YAAY,GAAG;AAAA,QACvC;AAAA,MACF;AAEA,aAAO,KAAK,WAAW,EAAE,QAAQ,CAAC,QAAQ,OAAO,YAAY,GAAG,CAAC;AACjE,aAAO,OAAO,aAAa,cAAc;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var dictionaryStatus_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(dictionaryStatus_exports);
|
|
17
|
+
//# sourceMappingURL=dictionaryStatus.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/dictionaryStatus.ts"],"sourcesContent":["export type DictionaryStatus =\n | 'pending'\n | 'fetching'\n | 'up-to-date'\n | 'updated'\n | 'fetched'\n | 'unknown'\n | 'error'\n | 'imported'\n | 'reimported in JSON'\n | 'reimported in new location';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -15,9 +15,11 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
16
|
var index_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(index_exports);
|
|
18
|
-
__reExport(index_exports, require('./
|
|
18
|
+
__reExport(index_exports, require('./dictionaryManipulator/index.cjs'), module.exports);
|
|
19
|
+
__reExport(index_exports, require('./dictionaryStatus.cjs'), module.exports);
|
|
19
20
|
// Annotate the CommonJS export names for ESM import in node:
|
|
20
21
|
0 && (module.exports = {
|
|
21
|
-
...require('./
|
|
22
|
+
...require('./dictionaryManipulator/index.cjs'),
|
|
23
|
+
...require('./dictionaryStatus.cjs')
|
|
22
24
|
});
|
|
23
25
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\nexport * from './dictionaryStatus';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,0CAAd;AACA,0BAAc,+BADd;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var server_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(server_exports);
|
|
18
|
+
__reExport(server_exports, require('./writeContentDeclaration.cjs'), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require('./writeContentDeclaration.cjs')
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export * from './writeContentDeclaration';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,2BAAc,sCAAd;","names":[]}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var writeContentDeclaration_exports = {};
|
|
30
|
+
__export(writeContentDeclaration_exports, {
|
|
31
|
+
writeContentDeclaration: () => writeContentDeclaration
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(writeContentDeclaration_exports);
|
|
34
|
+
var import_fs = require("fs");
|
|
35
|
+
var fsPromises = __toESM(require("fs/promises"));
|
|
36
|
+
var import_path = require("path");
|
|
37
|
+
var import_client = require("@intlayer/config/client");
|
|
38
|
+
var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
|
|
39
|
+
var import_deep_equal = __toESM(require("deep-equal"));
|
|
40
|
+
const DEFAULT_NEW_DICTIONARY_PATH = "intlayer-dictionaries";
|
|
41
|
+
const writeContentDeclaration = async (distantDictionary, config, newDictionariesPath) => {
|
|
42
|
+
const {
|
|
43
|
+
content: { baseDir }
|
|
44
|
+
} = config ?? (0, import_client.getConfiguration)();
|
|
45
|
+
const newDictionaryRelativeLocationPath = newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
|
|
46
|
+
const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
|
|
47
|
+
const existingDictionary = import_dictionaries_entry.default[distantDictionary.key];
|
|
48
|
+
if (existingDictionary) {
|
|
49
|
+
const { filePath } = existingDictionary;
|
|
50
|
+
if ((0, import_deep_equal.default)(existingDictionary, distantDictionary)) {
|
|
51
|
+
return {
|
|
52
|
+
status: "up-to-date",
|
|
53
|
+
path: filePath
|
|
54
|
+
};
|
|
55
|
+
} else {
|
|
56
|
+
if (filePath) {
|
|
57
|
+
const isDictionaryJSON = filePath.endsWith(".json");
|
|
58
|
+
if (isDictionaryJSON) {
|
|
59
|
+
const contentDeclarationPath = `${baseDir}/${filePath}`;
|
|
60
|
+
await fsPromises.writeFile(
|
|
61
|
+
contentDeclarationPath,
|
|
62
|
+
JSON.stringify(distantDictionary, null, 2)
|
|
63
|
+
);
|
|
64
|
+
return { status: "updated", path: contentDeclarationPath };
|
|
65
|
+
} else {
|
|
66
|
+
const dictionariesDirPath = (0, import_path.dirname)(filePath);
|
|
67
|
+
const dictionariesFileName = (0, import_path.basename)(filePath, (0, import_path.extname)(filePath));
|
|
68
|
+
const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;
|
|
69
|
+
await writeFileWithDirectories(
|
|
70
|
+
newFilePath,
|
|
71
|
+
JSON.stringify(distantDictionary, null, 2)
|
|
72
|
+
);
|
|
73
|
+
return {
|
|
74
|
+
status: "updated",
|
|
75
|
+
path: newFilePath
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
|
|
80
|
+
await writeFileWithDirectories(
|
|
81
|
+
contentDeclarationPath,
|
|
82
|
+
JSON.stringify(distantDictionary, null, 2)
|
|
83
|
+
);
|
|
84
|
+
return {
|
|
85
|
+
status: "reimported in new location",
|
|
86
|
+
path: contentDeclarationPath
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
|
|
92
|
+
await writeFileWithDirectories(
|
|
93
|
+
contentDeclarationPath,
|
|
94
|
+
JSON.stringify(distantDictionary, null, 2)
|
|
95
|
+
);
|
|
96
|
+
return {
|
|
97
|
+
status: "imported",
|
|
98
|
+
path: contentDeclarationPath
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const writeFileWithDirectories = async (filePath, data) => {
|
|
103
|
+
try {
|
|
104
|
+
const dir = (0, import_path.dirname)(filePath);
|
|
105
|
+
const directoryExists = (0, import_fs.existsSync)(dir);
|
|
106
|
+
if (!directoryExists) {
|
|
107
|
+
await fsPromises.mkdir(dir, { recursive: true });
|
|
108
|
+
}
|
|
109
|
+
await fsPromises.writeFile(filePath, data);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
throw new Error(`Error writing file to ${filePath}: ${error}`);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
115
|
+
0 && (module.exports = {
|
|
116
|
+
writeContentDeclaration
|
|
117
|
+
});
|
|
118
|
+
//# sourceMappingURL=writeContentDeclaration.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport * as fsPromises from 'fs/promises';\nimport { basename, dirname, extname } from 'path';\nimport { getConfiguration, IntlayerConfig } from '@intlayer/config/client';\nimport { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { DictionaryStatus } from '../dictionaryStatus';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nexport const writeContentDeclaration = async (\n distantDictionary: Dictionary,\n config?: IntlayerConfig,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const {\n content: { baseDir },\n } = config ?? getConfiguration();\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = dictionariesRecord[distantDictionary.key];\n\n if (existingDictionary) {\n const { filePath } = existingDictionary;\n\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, distantDictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n const isDictionaryJSON = filePath.endsWith('.json');\n\n if (isDictionaryJSON) {\n const contentDeclarationPath = `${baseDir}/${filePath}`;\n // Write the dictionary to the same location of the existing dictionary file\n await fsPromises.writeFile(\n contentDeclarationPath,\n JSON.stringify(distantDictionary, null, 2)\n );\n return { status: 'updated', path: contentDeclarationPath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const dictionariesDirPath = dirname(filePath);\n const dictionariesFileName = basename(filePath, extname(filePath));\n\n const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;\n\n await writeFileWithDirectories(\n newFilePath,\n JSON.stringify(distantDictionary, null, 2)\n );\n\n return {\n status: 'updated',\n path: newFilePath,\n };\n }\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(distantDictionary, null, 2)\n );\n return {\n status: 'reimported in new location',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n JSON.stringify(distantDictionary, null, 2)\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await fsPromises.mkdir(dir, { recursive: true });\n }\n\n // Write the file\n await fsPromises.writeFile(filePath, data);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;AAC3B,iBAA4B;AAC5B,kBAA2C;AAC3C,oBAAiD;AAEjD,gCAA+B;AAC/B,wBAAsB;AAGtB,MAAM,8BAA8B;AAE7B,MAAM,0BAA0B,OACrC,mBACA,QACA,wBACwD;AACxD,QAAM;AAAA,IACJ,SAAS,EAAE,QAAQ;AAAA,EACrB,IAAI,cAAU,gCAAiB;AAE/B,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBAAqB,0BAAAA,QAAmB,kBAAkB,GAAG;AAEnE,MAAI,oBAAoB;AACtB,UAAM,EAAE,SAAS,IAAI;AAGrB,YAAI,kBAAAC,SAAU,oBAAoB,iBAAiB,GAAG;AAEpD,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,IACF,OAAO;AACL,UAAI,UAAU;AACZ,cAAM,mBAAmB,SAAS,SAAS,OAAO;AAElD,YAAI,kBAAkB;AACpB,gBAAM,yBAAyB,GAAG,OAAO,IAAI,QAAQ;AAErD,gBAAM,WAAW;AAAA,YACf;AAAA,YACA,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,UAC3C;AACA,iBAAO,EAAE,QAAQ,WAAW,MAAM,uBAAuB;AAAA,QAC3D,OAAO;AAEL,gBAAM,0BAAsB,qBAAQ,QAAQ;AAC5C,gBAAM,2BAAuB,sBAAS,cAAU,qBAAQ,QAAQ,CAAC;AAEjE,gBAAM,cAAc,GAAG,mBAAmB,IAAI,oBAAoB;AAElE,gBAAM;AAAA,YACJ;AAAA,YACA,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,UAC3C;AAEA,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM;AAAA,UACR;AAAA,QACF;AAAA,MACF,OAAO;AAEL,cAAM,yBAAyB,GAAG,yBAAyB,IAAI,kBAAkB,GAAG;AACpF,cAAM;AAAA,UACJ;AAAA,UACA,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,QAC3C;AACA,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,yBAAyB,GAAG,yBAAyB,IAAI,kBAAkB,GAAG;AAEpF,UAAM;AAAA,MACJ;AAAA,MACA,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,IAC3C;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,UAAM,qBAAQ,QAAQ;AAG5B,UAAM,sBAAkB,sBAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,YAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACjD;AAGA,UAAM,WAAW,UAAU,UAAU,IAAI;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":["dictionariesRecord","deepEqual"]}
|