@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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { NodeType } from "@intlayer/core";
|
|
2
|
+
const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
|
|
3
|
+
let currentValue = dictionaryContent;
|
|
4
|
+
let parentValue = null;
|
|
5
|
+
let lastKeys = [];
|
|
6
|
+
for (const keyObj of keyPath) {
|
|
7
|
+
parentValue = currentValue;
|
|
8
|
+
if (keyObj.type === NodeType.Object) {
|
|
9
|
+
lastKeys = [keyObj.key];
|
|
10
|
+
if (!currentValue[keyObj.key]) {
|
|
11
|
+
currentValue = {
|
|
12
|
+
...currentValue,
|
|
13
|
+
[keyObj.key]: {}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
currentValue = currentValue[keyObj.key];
|
|
17
|
+
} else if (keyObj.type === NodeType.Array) {
|
|
18
|
+
lastKeys = [keyObj.key];
|
|
19
|
+
if (!currentValue[keyObj.key]) {
|
|
20
|
+
currentValue[keyObj.key] = {};
|
|
21
|
+
}
|
|
22
|
+
currentValue = currentValue[keyObj.key];
|
|
23
|
+
} else if (keyObj.type === NodeType.Translation) {
|
|
24
|
+
lastKeys = [NodeType.Translation, keyObj.key];
|
|
25
|
+
if (!currentValue[NodeType.Translation]) {
|
|
26
|
+
currentValue[NodeType.Translation] = {
|
|
27
|
+
...currentValue[NodeType.Translation],
|
|
28
|
+
[keyObj.key]: newValue
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
currentValue = currentValue[NodeType.Translation][keyObj.key];
|
|
32
|
+
} else if (keyObj.type === NodeType.Enumeration) {
|
|
33
|
+
lastKeys = [NodeType.Enumeration, keyObj.key];
|
|
34
|
+
if (!currentValue[NodeType.Enumeration]) {
|
|
35
|
+
currentValue[NodeType.Enumeration] = {
|
|
36
|
+
...currentValue[NodeType.Enumeration],
|
|
37
|
+
[keyObj.key]: newValue
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
currentValue = currentValue[NodeType.Enumeration][keyObj.key];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (parentValue && lastKeys.length > 0) {
|
|
44
|
+
for (const key of lastKeys.slice(0, -1)) {
|
|
45
|
+
parentValue = parentValue[key];
|
|
46
|
+
}
|
|
47
|
+
if (
|
|
48
|
+
// Remove the field if the new value is undefined
|
|
49
|
+
typeof newValue === "undefined"
|
|
50
|
+
) {
|
|
51
|
+
delete parentValue[lastKeys[lastKeys.length - 1]];
|
|
52
|
+
} else {
|
|
53
|
+
parentValue[lastKeys[lastKeys.length - 1]] = newValue;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return dictionaryContent;
|
|
57
|
+
};
|
|
58
|
+
export {
|
|
59
|
+
editDictionaryByKeyPath
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=editDictionaryByKeyPath.mjs.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":"AACA,SAA6C,gBAAgB;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,SAAS,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,SAAS,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,SAAS,aAAa;AAC/C,iBAAW,CAAC,SAAS,aAAa,OAAO,GAAG;AAE5C,UAAI,CAAC,aAAa,SAAS,WAAW,GAAG;AACvC,qBAAa,SAAS,WAAW,IAAI;AAAA,UACnC,GAAG,aAAa,SAAS,WAAW;AAAA,UACpC,CAAC,OAAO,GAAG,GAAG;AAAA,QAChB;AAAA,MACF;AACA,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,iBAAW,CAAC,SAAS,aAAa,OAAO,GAAG;AAE5C,UAAI,CAAC,aAAa,SAAS,WAAW,GAAG;AACvC,qBAAa,SAAS,WAAW,IAAI;AAAA,UACnC,GAAG,aAAa,SAAS,WAAW;AAAA,UACpC,CAAC,OAAO,GAAG,GAAG;AAAA,QAChB;AAAA,MACF;AACA,qBAAe,aAAa,SAAS,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,18 @@
|
|
|
1
|
+
import { NodeType } from "@intlayer/core";
|
|
2
|
+
const getDictionaryValueByKeyPath = (dictionaryContent, keyPath) => {
|
|
3
|
+
let currentValue = JSON.parse(JSON.stringify(dictionaryContent ?? {}));
|
|
4
|
+
for (const keyObj of keyPath) {
|
|
5
|
+
if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
|
|
6
|
+
currentValue = currentValue?.[keyObj.key];
|
|
7
|
+
} else if (keyObj.type === NodeType.Translation) {
|
|
8
|
+
currentValue = currentValue?.[NodeType.Translation][keyObj.key];
|
|
9
|
+
} else if (keyObj.type === NodeType.Enumeration) {
|
|
10
|
+
currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return currentValue;
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
getDictionaryValueByKeyPath
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=getDictionaryValueByKeyPath.mjs.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":"AACA,SAA6C,gBAAgB;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,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,qBAAe,eAAe,OAAO,GAAG;AAAA,IAC1C,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,qBAAe,eAAe,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,qBAAe,eAAe,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NodeType
|
|
3
|
+
} from "@intlayer/core";
|
|
4
|
+
import { isValidElement } from "./isValidReactElement.mjs";
|
|
5
|
+
const getSectionType = (section) => {
|
|
6
|
+
if (typeof section === "string") {
|
|
7
|
+
return NodeType.Text;
|
|
8
|
+
}
|
|
9
|
+
if (section?.nodeType === NodeType.Translation) {
|
|
10
|
+
return NodeType.Translation;
|
|
11
|
+
}
|
|
12
|
+
if (section?.nodeType === NodeType.Enumeration) {
|
|
13
|
+
return NodeType.Enumeration;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(section)) {
|
|
16
|
+
return NodeType.Array;
|
|
17
|
+
}
|
|
18
|
+
if (isValidElement(section)) {
|
|
19
|
+
return NodeType.ReactNode;
|
|
20
|
+
}
|
|
21
|
+
return NodeType.Object;
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
getSectionType
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=getSectionType.mjs.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,EAIE;AAAA,OACK;AACP,SAAS,sBAAsB;AAExB,MAAM,iBAAiB,CAAC,YAAuC;AACpE,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO,SAAS;AAAA,EAClB;AAEA,MACG,SAAyC,aAAa,SAAS,aAChE;AACA,WAAO,SAAS;AAAA,EAClB;AAEA,MACG,SAAyC,aAAa,SAAS,aAChE;AACA,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,eAAe,OAAO,GAAG;AAC3B,WAAO,SAAS;AAAA,EAClB;AAEA,SAAO,SAAS;AAClB;","names":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./editDictionaryByKeyPath.mjs";
|
|
2
|
+
export * from "./getDictionaryValueByKeyPath.mjs";
|
|
3
|
+
export * from "./getSectionType.mjs";
|
|
4
|
+
export * from "./removeDictionaryValueByKeyPath.mjs";
|
|
5
|
+
export * from "./renameDictionaryValueByKeyPath.mjs";
|
|
6
|
+
//# sourceMappingURL=index.mjs.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,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -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":"AACA,MAAM,qBAAqB,OAAO,IAAI,eAAe;AAU9C,MAAM,iBAAiB,CAAC,WAC7B,OAAO,WAAW,YAClB,WAAW,QACX,OAAO,aAAa;","names":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { NodeType } from "@intlayer/core";
|
|
2
|
+
const removeDictionaryValueByKeyPath = (dictionaryContent, keyPath) => {
|
|
3
|
+
let currentValue = dictionaryContent;
|
|
4
|
+
let parentValue = null;
|
|
5
|
+
let lastKey = null;
|
|
6
|
+
for (const keyObj of keyPath) {
|
|
7
|
+
parentValue = currentValue;
|
|
8
|
+
if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
|
|
9
|
+
lastKey = keyObj.key;
|
|
10
|
+
currentValue = currentValue[keyObj.key];
|
|
11
|
+
} else if (keyObj.type === NodeType.Translation) {
|
|
12
|
+
lastKey = NodeType.Translation;
|
|
13
|
+
currentValue = currentValue[NodeType.Translation][keyObj.key];
|
|
14
|
+
} else if (keyObj.type === NodeType.Enumeration) {
|
|
15
|
+
lastKey = NodeType.Enumeration;
|
|
16
|
+
currentValue = currentValue[NodeType.Enumeration][keyObj.key];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (parentValue && lastKey !== null) {
|
|
20
|
+
if (Array.isArray(parentValue)) {
|
|
21
|
+
parentValue.splice(lastKey, 1);
|
|
22
|
+
} else {
|
|
23
|
+
delete parentValue[lastKey];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return dictionaryContent;
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
removeDictionaryValueByKeyPath
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=removeDictionaryValueByKeyPath.mjs.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":"AAEA,SAAmC,gBAAgB;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,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D;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,40 @@
|
|
|
1
|
+
import { NodeType } from "@intlayer/core";
|
|
2
|
+
const renameDictionaryValueByKeyPath = (dictionaryContent, newKey, keyPath) => {
|
|
3
|
+
let currentValue = dictionaryContent;
|
|
4
|
+
let parentValue = null;
|
|
5
|
+
let lastKey = null;
|
|
6
|
+
for (const keyObj of keyPath) {
|
|
7
|
+
parentValue = currentValue;
|
|
8
|
+
if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
|
|
9
|
+
lastKey = keyObj.key;
|
|
10
|
+
currentValue = currentValue[keyObj.key];
|
|
11
|
+
} else if (keyObj.type === NodeType.Translation) {
|
|
12
|
+
lastKey = NodeType.Translation;
|
|
13
|
+
currentValue = currentValue[NodeType.Translation][keyObj.key];
|
|
14
|
+
} else if (keyObj.type === NodeType.Enumeration) {
|
|
15
|
+
lastKey = NodeType.Enumeration;
|
|
16
|
+
currentValue = currentValue[NodeType.Enumeration][keyObj.key];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (parentValue && lastKey !== null) {
|
|
20
|
+
if (Array.isArray(parentValue)) {
|
|
21
|
+
parentValue[lastKey] = currentValue;
|
|
22
|
+
} else {
|
|
23
|
+
const newParentValue = {};
|
|
24
|
+
for (const key of Object.keys(parentValue)) {
|
|
25
|
+
if (key === lastKey) {
|
|
26
|
+
newParentValue[newKey] = currentValue;
|
|
27
|
+
} else {
|
|
28
|
+
newParentValue[key] = parentValue[key];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
Object.keys(parentValue).forEach((key) => delete parentValue[key]);
|
|
32
|
+
Object.assign(parentValue, newParentValue);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return dictionaryContent;
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
renameDictionaryValueByKeyPath
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=renameDictionaryValueByKeyPath.mjs.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":"AAEA,SAAmC,gBAAgB;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,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,gBAAU,OAAO;AACjB,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,SAAS,aAAa;AAC/C,gBAAU,SAAS;AACnB,qBAAe,aAAa,SAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D;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 @@
|
|
|
1
|
+
//# sourceMappingURL=dictionaryStatus.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/esm/index.mjs
CHANGED
package/dist/esm/index.mjs.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,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export * from './writeContentDeclaration';\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import * as fsPromises from "fs/promises";
|
|
3
|
+
import { basename, dirname, extname } from "path";
|
|
4
|
+
import { getConfiguration } from "@intlayer/config/client";
|
|
5
|
+
import dictionariesRecord from "@intlayer/dictionaries-entry";
|
|
6
|
+
import deepEqual from "deep-equal";
|
|
7
|
+
const DEFAULT_NEW_DICTIONARY_PATH = "intlayer-dictionaries";
|
|
8
|
+
const writeContentDeclaration = async (distantDictionary, config, newDictionariesPath) => {
|
|
9
|
+
const {
|
|
10
|
+
content: { baseDir }
|
|
11
|
+
} = config ?? getConfiguration();
|
|
12
|
+
const newDictionaryRelativeLocationPath = newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
|
|
13
|
+
const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
|
|
14
|
+
const existingDictionary = dictionariesRecord[distantDictionary.key];
|
|
15
|
+
if (existingDictionary) {
|
|
16
|
+
const { filePath } = existingDictionary;
|
|
17
|
+
if (deepEqual(existingDictionary, distantDictionary)) {
|
|
18
|
+
return {
|
|
19
|
+
status: "up-to-date",
|
|
20
|
+
path: filePath
|
|
21
|
+
};
|
|
22
|
+
} else {
|
|
23
|
+
if (filePath) {
|
|
24
|
+
const isDictionaryJSON = filePath.endsWith(".json");
|
|
25
|
+
if (isDictionaryJSON) {
|
|
26
|
+
const contentDeclarationPath = `${baseDir}/${filePath}`;
|
|
27
|
+
await fsPromises.writeFile(
|
|
28
|
+
contentDeclarationPath,
|
|
29
|
+
JSON.stringify(distantDictionary, null, 2)
|
|
30
|
+
);
|
|
31
|
+
return { status: "updated", path: contentDeclarationPath };
|
|
32
|
+
} else {
|
|
33
|
+
const dictionariesDirPath = dirname(filePath);
|
|
34
|
+
const dictionariesFileName = basename(filePath, extname(filePath));
|
|
35
|
+
const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;
|
|
36
|
+
await writeFileWithDirectories(
|
|
37
|
+
newFilePath,
|
|
38
|
+
JSON.stringify(distantDictionary, null, 2)
|
|
39
|
+
);
|
|
40
|
+
return {
|
|
41
|
+
status: "updated",
|
|
42
|
+
path: newFilePath
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
|
|
47
|
+
await writeFileWithDirectories(
|
|
48
|
+
contentDeclarationPath,
|
|
49
|
+
JSON.stringify(distantDictionary, null, 2)
|
|
50
|
+
);
|
|
51
|
+
return {
|
|
52
|
+
status: "reimported in new location",
|
|
53
|
+
path: contentDeclarationPath
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
const contentDeclarationPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
|
|
59
|
+
await writeFileWithDirectories(
|
|
60
|
+
contentDeclarationPath,
|
|
61
|
+
JSON.stringify(distantDictionary, null, 2)
|
|
62
|
+
);
|
|
63
|
+
return {
|
|
64
|
+
status: "imported",
|
|
65
|
+
path: contentDeclarationPath
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const writeFileWithDirectories = async (filePath, data) => {
|
|
70
|
+
try {
|
|
71
|
+
const dir = dirname(filePath);
|
|
72
|
+
const directoryExists = existsSync(dir);
|
|
73
|
+
if (!directoryExists) {
|
|
74
|
+
await fsPromises.mkdir(dir, { recursive: true });
|
|
75
|
+
}
|
|
76
|
+
await fsPromises.writeFile(filePath, data);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
throw new Error(`Error writing file to ${filePath}: ${error}`);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
writeContentDeclaration
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=writeContentDeclaration.mjs.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,SAAS,kBAAkB;AAC3B,YAAY,gBAAgB;AAC5B,SAAS,UAAU,SAAS,eAAe;AAC3C,SAAS,wBAAwC;AAEjD,OAAO,wBAAwB;AAC/B,OAAO,eAAe;AAGtB,MAAM,8BAA8B;AAE7B,MAAM,0BAA0B,OACrC,mBACA,QACA,wBACwD;AACxD,QAAM;AAAA,IACJ,SAAS,EAAE,QAAQ;AAAA,EACrB,IAAI,UAAU,iBAAiB;AAE/B,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBAAqB,mBAAmB,kBAAkB,GAAG;AAEnE,MAAI,oBAAoB;AACtB,UAAM,EAAE,SAAS,IAAI;AAGrB,QAAI,UAAU,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,sBAAsB,QAAQ,QAAQ;AAC5C,gBAAM,uBAAuB,SAAS,UAAU,QAAQ,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,MAAM,QAAQ,QAAQ;AAG5B,UAAM,kBAAkB,WAAW,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":[]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type DictionaryValue, type KeyPath } from '@intlayer/core';
|
|
2
|
+
export declare const editDictionaryByKeyPath: (dictionaryContent: DictionaryValue, keyPath: KeyPath[], newValue: DictionaryValue) => DictionaryValue;
|
|
3
|
+
//# sourceMappingURL=editDictionaryByKeyPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editDictionaryByKeyPath.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,OAAO,EAAY,MAAM,gBAAgB,CAAC;AAI9E,eAAO,MAAM,uBAAuB,sBACf,eAAe,WACzB,OAAO,EAAE,YACR,eAAe,KACxB,eAgEF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDictionaryValueByKeyPath.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/getDictionaryValueByKeyPath.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,OAAO,EAAY,MAAM,gBAAgB,CAAC;AAE9E,eAAO,MAAM,2BAA2B,sBACnB,eAAe,WACzB,OAAO,EAAE,KACjB,eAcF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSectionType.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/getSectionType.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EACpB,QAAQ,EACT,MAAM,gBAAgB,CAAC;AAGxB,eAAO,MAAM,cAAc,YAAa,eAAe,KAAG,QA0BzD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifies the object is a ReactElement.
|
|
3
|
+
* See https://reactjs.org/docs/react-api.html#isvalidelement
|
|
4
|
+
* @param object
|
|
5
|
+
* @return True if `object` is a ReactElement.
|
|
6
|
+
* @final
|
|
7
|
+
*/
|
|
8
|
+
export declare const isValidElement: (object: any) => boolean;
|
|
9
|
+
//# sourceMappingURL=isValidReactElement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidReactElement.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/isValidReactElement.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AAEH,eAAO,MAAM,cAAc,WAAY,GAAG,KAAG,OAGL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeDictionaryValueByKeyPath.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/removeDictionaryValueByKeyPath.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAY,MAAM,gBAAgB,CAAC;AAEpE,eAAO,MAAM,8BAA8B,sBACtB,eAAe,WACzB,OAAO,EAAE,KACjB,eA6BF,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DictionaryValue, KeyPath } from '@intlayer/core';
|
|
2
|
+
export declare const renameDictionaryValueByKeyPath: (dictionaryContent: DictionaryValue, newKey: string | number, keyPath: KeyPath[]) => DictionaryValue;
|
|
3
|
+
//# sourceMappingURL=renameDictionaryValueByKeyPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameDictionaryValueByKeyPath.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/renameDictionaryValueByKeyPath.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAY,MAAM,gBAAgB,CAAC;AAEpE,eAAO,MAAM,8BAA8B,sBACtB,eAAe,UAC1B,MAAM,GAAG,MAAM,WACd,OAAO,EAAE,KACjB,eAwCF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionaryStatus.d.ts","sourceRoot":"","sources":["../../src/dictionaryStatus.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,UAAU,GACV,YAAY,GACZ,SAAS,GACT,SAAS,GACT,SAAS,GACT,OAAO,GACP,UAAU,GACV,oBAAoB,GACpB,4BAA4B,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IntlayerConfig } from '@intlayer/config/client';
|
|
2
|
+
import { Dictionary } from '@intlayer/core';
|
|
3
|
+
import { DictionaryStatus } from '../dictionaryStatus';
|
|
4
|
+
export declare const writeContentDeclaration: (distantDictionary: Dictionary, config?: IntlayerConfig, newDictionariesPath?: string) => Promise<{
|
|
5
|
+
status: DictionaryStatus;
|
|
6
|
+
path: string;
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=writeContentDeclaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeContentDeclaration.d.ts","sourceRoot":"","sources":["../../../src/server/writeContentDeclaration.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAIvD,eAAO,MAAM,uBAAuB,sBACf,UAAU,WACpB,cAAc,wBACD,MAAM,KAC3B,OAAO,CAAC;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA6EpD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/editor",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "Provides the
|
|
5
|
+
"description": "Provides the utilities to interface the application with the Intlayer editor and manipulate dictionaries",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"intlayer",
|
|
8
8
|
"editor",
|
|
@@ -34,6 +34,11 @@
|
|
|
34
34
|
"require": "./dist/cjs/index.cjs",
|
|
35
35
|
"import": "./dist/esm/index.mjs"
|
|
36
36
|
},
|
|
37
|
+
"./server": {
|
|
38
|
+
"types": "./dist/types/server/index.d.ts",
|
|
39
|
+
"require": "./dist/cjs/server/index.cjs",
|
|
40
|
+
"import": "./dist/esm/server/index.mjs"
|
|
41
|
+
},
|
|
37
42
|
"./package.json": "./package.json"
|
|
38
43
|
},
|
|
39
44
|
"main": "dist/cjs/index.cjs",
|
|
@@ -50,7 +55,14 @@
|
|
|
50
55
|
"./dist",
|
|
51
56
|
"./package.json"
|
|
52
57
|
],
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"deep-equal": "^2.2.3",
|
|
60
|
+
"@intlayer/config": "4.0.5",
|
|
61
|
+
"@intlayer/dictionaries-entry": "4.0.5",
|
|
62
|
+
"@intlayer/core": "4.0.5"
|
|
63
|
+
},
|
|
53
64
|
"devDependencies": {
|
|
65
|
+
"@types/deep-equal": "^1.0.4",
|
|
54
66
|
"@types/node": "^22.10.6",
|
|
55
67
|
"@typescript-eslint/parser": "^8.20.0",
|
|
56
68
|
"concurrently": "^9.1.2",
|
|
@@ -60,10 +72,15 @@
|
|
|
60
72
|
"tsc-alias": "^1.8.10",
|
|
61
73
|
"tsup": "^8.3.5",
|
|
62
74
|
"typescript": "^5.7.3",
|
|
63
|
-
"@utils/ts-config": "1.0.4",
|
|
64
|
-
"@utils/ts-config-types": "1.0.4",
|
|
65
75
|
"@utils/eslint-config": "1.0.4",
|
|
66
|
-
"@utils/tsup-config": "1.0.4"
|
|
76
|
+
"@utils/tsup-config": "1.0.4",
|
|
77
|
+
"@utils/ts-config-types": "1.0.4",
|
|
78
|
+
"@utils/ts-config": "1.0.4"
|
|
79
|
+
},
|
|
80
|
+
"peerDependencies": {
|
|
81
|
+
"@intlayer/config": "4.0.5",
|
|
82
|
+
"@intlayer/core": "4.0.5",
|
|
83
|
+
"@intlayer/dictionaries-entry": "4.0.5"
|
|
67
84
|
},
|
|
68
85
|
"engines": {
|
|
69
86
|
"node": ">=14.18"
|
|
@@ -1,89 +0,0 @@
|
|
|
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 CrossFrameCommunicator_exports = {};
|
|
20
|
-
__export(CrossFrameCommunicator_exports, {
|
|
21
|
-
CrossFrameCommunicator: () => CrossFrameCommunicator
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(CrossFrameCommunicator_exports);
|
|
24
|
-
class CrossFrameCommunicator {
|
|
25
|
-
targetWindow;
|
|
26
|
-
targetOrigin;
|
|
27
|
-
allowedOrigins;
|
|
28
|
-
handlers;
|
|
29
|
-
constructor(options) {
|
|
30
|
-
this.targetWindow = options.targetWindow;
|
|
31
|
-
this.targetOrigin = options.targetOrigin ?? "*";
|
|
32
|
-
this.allowedOrigins = options.allowedOrigins ?? ["*"];
|
|
33
|
-
this.handlers = {};
|
|
34
|
-
window.addEventListener("message", this.handleIncomingMessage);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Clean up the event listener if needed (for single-page apps, unmounting, etc.).
|
|
38
|
-
*/
|
|
39
|
-
destroy() {
|
|
40
|
-
window.removeEventListener("message", this.handleIncomingMessage);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Register a handler for a specific message type.
|
|
44
|
-
*/
|
|
45
|
-
on(type, handler) {
|
|
46
|
-
if (!this.handlers[type]) {
|
|
47
|
-
this.handlers[type] = [];
|
|
48
|
-
}
|
|
49
|
-
this.handlers[type].push(handler);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Post a message to the target window.
|
|
53
|
-
* @param type A string identifying the message
|
|
54
|
-
* @param data The payload (any serializable data)
|
|
55
|
-
*/
|
|
56
|
-
sendMessage(type, data) {
|
|
57
|
-
this.targetWindow.postMessage({ type, data }, this.targetOrigin);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Internal method to dispatch incoming messages to registered handlers.
|
|
61
|
-
*/
|
|
62
|
-
handleIncomingMessage = (event) => {
|
|
63
|
-
const { data, origin, source } = event;
|
|
64
|
-
if (!data || typeof data !== "object" || !data.type) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (!this.isAllowedOrigin(origin)) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (source !== this.targetWindow) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const messageType = data.type;
|
|
74
|
-
if (this.handlers[messageType]) {
|
|
75
|
-
this.handlers[messageType].forEach((handler) => {
|
|
76
|
-
handler(data.data, event);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
isAllowedOrigin(origin) {
|
|
81
|
-
if (this.allowedOrigins.includes("*")) return true;
|
|
82
|
-
return this.allowedOrigins.includes(origin);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
-
0 && (module.exports = {
|
|
87
|
-
CrossFrameCommunicator
|
|
88
|
-
});
|
|
89
|
-
//# sourceMappingURL=CrossFrameCommunicator.cjs.map
|