@intlayer/core 5.3.1 → 5.3.3
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/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs +2 -14
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/getContent.cjs +2 -0
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs +62 -3
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getInsertion.cjs +29 -0
- package/dist/cjs/interpreter/getInsertion.cjs.map +1 -0
- package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
- package/dist/cjs/transpiler/file/file.cjs +60 -0
- package/dist/cjs/transpiler/file/file.cjs.map +1 -0
- package/dist/cjs/transpiler/file/fileBrowser.cjs +36 -0
- package/dist/cjs/transpiler/file/fileBrowser.cjs.map +1 -0
- package/dist/cjs/transpiler/file/index.cjs +23 -0
- package/dist/cjs/transpiler/file/index.cjs.map +1 -0
- package/dist/cjs/transpiler/index.cjs +2 -0
- package/dist/cjs/transpiler/index.cjs.map +1 -1
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs +34 -0
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs.map +1 -0
- package/dist/cjs/transpiler/insertion/index.cjs +25 -0
- package/dist/cjs/transpiler/insertion/index.cjs.map +1 -0
- package/dist/cjs/transpiler/insertion/insertion.cjs +54 -0
- package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -0
- package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs +30 -26
- package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/markdown.cjs +1 -1
- package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
- package/dist/cjs/transpiler/translation/index.cjs +1 -3
- package/dist/cjs/transpiler/translation/index.cjs.map +1 -1
- package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
- package/dist/cjs/types/dictionary.cjs.map +1 -1
- package/dist/cjs/types/index.cjs +3 -1
- package/dist/cjs/types/index.cjs.map +1 -1
- package/dist/cjs/types/keyPath.cjs.map +1 -1
- package/dist/cjs/types/nodeType.cjs +2 -0
- package/dist/cjs/types/nodeType.cjs.map +1 -1
- package/dist/cjs/{transpiler/translation/types.cjs → types/translation.cjs} +3 -3
- package/dist/cjs/types/translation.cjs.map +1 -0
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +1 -1
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeType.mjs +2 -14
- package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/getContent.mjs +5 -1
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/plugins.mjs +60 -3
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getInsertion.mjs +5 -0
- package/dist/esm/interpreter/getInsertion.mjs.map +1 -0
- package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
- package/dist/esm/transpiler/file/file.mjs +39 -0
- package/dist/esm/transpiler/file/file.mjs.map +1 -0
- package/dist/esm/transpiler/file/fileBrowser.mjs +12 -0
- package/dist/esm/transpiler/file/fileBrowser.mjs.map +1 -0
- package/dist/esm/transpiler/file/index.mjs +2 -0
- package/dist/esm/transpiler/file/index.mjs.map +1 -0
- package/dist/esm/transpiler/index.mjs +1 -0
- package/dist/esm/transpiler/index.mjs.map +1 -1
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs +10 -0
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs.map +1 -0
- package/dist/esm/transpiler/insertion/index.mjs +3 -0
- package/dist/esm/transpiler/insertion/index.mjs.map +1 -0
- package/dist/esm/transpiler/insertion/insertion.mjs +33 -0
- package/dist/esm/transpiler/insertion/insertion.mjs.map +1 -0
- package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs +30 -26
- package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs.map +1 -1
- package/dist/esm/transpiler/markdown/markdown.mjs +1 -1
- package/dist/esm/transpiler/markdown/markdown.mjs.map +1 -1
- package/dist/esm/transpiler/translation/index.mjs +0 -1
- package/dist/esm/transpiler/translation/index.mjs.map +1 -1
- package/dist/esm/transpiler/translation/translation.mjs +4 -1
- package/dist/esm/transpiler/translation/translation.mjs.map +1 -1
- package/dist/esm/types/index.mjs +1 -0
- package/dist/esm/types/index.mjs.map +1 -1
- package/dist/esm/types/nodeType.mjs +2 -0
- package/dist/esm/types/nodeType.mjs.map +1 -1
- package/dist/esm/types/translation.mjs +1 -0
- package/dist/types/dictionaryManipulator/getDefaultNode.d.ts +1 -1
- package/dist/types/dictionaryManipulator/getDefaultNode.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getNodeChildren.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getNodeType.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/plugins.d.ts +19 -0
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/interpreter/getInsertion.d.ts +16 -0
- package/dist/types/interpreter/getInsertion.d.ts.map +1 -0
- package/dist/types/interpreter/getTranslation.d.ts +1 -1
- package/dist/types/interpreter/getTranslation.d.ts.map +1 -1
- package/dist/types/transpiler/condition/condition.d.ts +1 -1
- package/dist/types/transpiler/condition/condition.d.ts.map +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
- package/dist/types/transpiler/file/file.d.ts +22 -0
- package/dist/types/transpiler/file/file.d.ts.map +1 -0
- package/dist/types/transpiler/file/fileBrowser.d.ts +18 -0
- package/dist/types/transpiler/file/fileBrowser.d.ts.map +1 -0
- package/dist/types/transpiler/file/index.d.ts +2 -0
- package/dist/types/transpiler/file/index.d.ts.map +1 -0
- package/dist/types/transpiler/index.d.ts +2 -0
- package/dist/types/transpiler/index.d.ts.map +1 -1
- package/dist/types/transpiler/insertion/getInsertionValues.d.ts +2 -0
- package/dist/types/transpiler/insertion/getInsertionValues.d.ts.map +1 -0
- package/dist/types/transpiler/insertion/index.d.ts +3 -0
- package/dist/types/transpiler/insertion/index.d.ts.map +1 -0
- package/dist/types/transpiler/insertion/insertion.d.ts +19 -0
- package/dist/types/transpiler/insertion/insertion.d.ts.map +1 -0
- package/dist/types/transpiler/markdown/getMarkdownMetadata.d.ts +1 -1
- package/dist/types/transpiler/markdown/getMarkdownMetadata.d.ts.map +1 -1
- package/dist/types/transpiler/markdown/markdown.d.ts +1 -1
- package/dist/types/transpiler/markdown/markdown.d.ts.map +1 -1
- package/dist/types/transpiler/translation/index.d.ts +0 -1
- package/dist/types/transpiler/translation/index.d.ts.map +1 -1
- package/dist/types/transpiler/translation/translation.d.ts +7 -3
- package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
- package/dist/types/types/dictionary.d.ts +8 -2
- package/dist/types/types/dictionary.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/types/keyPath.d.ts +9 -1
- package/dist/types/types/keyPath.d.ts.map +1 -1
- package/dist/types/types/nodeType.d.ts +10 -4
- package/dist/types/types/nodeType.d.ts.map +1 -1
- package/dist/types/{transpiler/translation/types.d.ts → types/translation.d.ts} +1 -3
- package/dist/types/types/translation.d.ts.map +1 -0
- package/package.json +20 -9
- package/dist/cjs/transpiler/translation/types.cjs.map +0 -1
- package/dist/esm/transpiler/translation/types.mjs +0 -1
- package/dist/types/transpiler/translation/types.d.ts.map +0 -1
- /package/dist/esm/{transpiler/translation/types.mjs.map → types/translation.mjs.map} +0 -0
|
@@ -35,7 +35,7 @@ const getNodeChildren = (section) => {
|
|
|
35
35
|
if (typeof section?.nodeType === "string") {
|
|
36
36
|
const typedNode = section;
|
|
37
37
|
const content = typedNode[typedNode.nodeType];
|
|
38
|
-
if (typedNode.nodeType === import_types.NodeType.Translation || typedNode.nodeType === import_types.NodeType.Enumeration || typedNode.nodeType === import_types.NodeType.Condition) {
|
|
38
|
+
if (typedNode.nodeType === import_types.NodeType.Translation || typedNode.nodeType === import_types.NodeType.Enumeration || typedNode.nodeType === import_types.NodeType.Condition || typedNode.nodeType === import_types.NodeType.Insertion || typedNode.nodeType === import_types.NodeType.File) {
|
|
39
39
|
const firstKey = Object.keys(content)[0];
|
|
40
40
|
return content[firstKey];
|
|
41
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import { type ContentNode, type TypedNode, NodeType } from '../types';\n\nexport const getNodeChildren = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return section;\n }\n if (typeof section === 'number') {\n return section;\n }\n if (typeof section === 'boolean') {\n return section;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content = typedNode[typedNode.nodeType as keyof TypedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return undefined;\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[])[0];\n }\n\n return section;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2D;AAEpD,MAAM,kBAAkB,CAAC,YAAsC;AACpE,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,WAAW;AAChC,WAAO;AAAA,EACT;AACA,MAAI,OAAQ,SAAuB,aAAa,UAAU;AACxD,UAAM,YAAY;AAClB,UAAM,UAAU,UAAU,UAAU,QAA2B;AAE/D,QACE,UAAU,aAAa,sBAAS,eAChC,UAAU,aAAa,sBAAS,eAChC,UAAU,aAAa,sBAAS,
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import { type ContentNode, type TypedNode, NodeType } from '../types';\n\nexport const getNodeChildren = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return section;\n }\n if (typeof section === 'number') {\n return section;\n }\n if (typeof section === 'boolean') {\n return section;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content = typedNode[typedNode.nodeType as keyof TypedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion ||\n typedNode.nodeType === NodeType.File\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return undefined;\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[])[0];\n }\n\n return section;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2D;AAEpD,MAAM,kBAAkB,CAAC,YAAsC;AACpE,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,WAAW;AAChC,WAAO;AAAA,EACT;AACA,MAAI,OAAQ,SAAuB,aAAa,UAAU;AACxD,UAAM,YAAY;AAClB,UAAM,UAAU,UAAU,UAAU,QAA2B;AAE/D,QACE,UAAU,aAAa,sBAAS,eAChC,UAAU,aAAa,sBAAS,eAChC,UAAU,aAAa,sBAAS,aAChC,UAAU,aAAa,sBAAS,aAChC,UAAU,aAAa,sBAAS,MAChC;AACA,YAAM,WAAW,OAAO,KAAK,OAAO,EAAE,CAAC;AACvC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAEA,QAAI,UAAU,aAAa,sBAAS,QAAQ;AAC1C,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,WAAW,OAAO,YAAY,UAAU;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAQ,QAA0B,CAAC;AAAA,EACrC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -27,20 +27,8 @@ const getNodeType = (content) => {
|
|
|
27
27
|
if (typeof content === "string") {
|
|
28
28
|
return import_types.NodeType.Text;
|
|
29
29
|
}
|
|
30
|
-
if (content?.nodeType ===
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
if (content?.nodeType === import_types.NodeType.Enumeration) {
|
|
34
|
-
return import_types.NodeType.Enumeration;
|
|
35
|
-
}
|
|
36
|
-
if (content?.nodeType === import_types.NodeType.Condition) {
|
|
37
|
-
return import_types.NodeType.Condition;
|
|
38
|
-
}
|
|
39
|
-
if (content?.nodeType === import_types.NodeType.Markdown) {
|
|
40
|
-
return import_types.NodeType.Markdown;
|
|
41
|
-
}
|
|
42
|
-
if (content?.nodeType === import_types.NodeType.Nested) {
|
|
43
|
-
return import_types.NodeType.Nested;
|
|
30
|
+
if (typeof content?.nodeType === "string") {
|
|
31
|
+
return content.nodeType;
|
|
44
32
|
}
|
|
45
33
|
if (Array.isArray(content)) {
|
|
46
34
|
return import_types.NodeType.Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"sourcesContent":["import { NodeType, type TypedNode } from '../types';\nimport type { ContentNode } from '../types/dictionary';\nimport { isValidElement } from '../utils/isValidReactElement';\n\nexport const getNodeType = (content: ContentNode): NodeType => {\n if (typeof content === 'string') {\n return NodeType.Text;\n }\n\n if (typeof (content as TypedNode)?.nodeType === 'string') {\n return (content as TypedNode).nodeType as NodeType;\n }\n\n if (Array.isArray(content)) {\n return NodeType.Array;\n }\n\n if (isValidElement(content)) {\n return NodeType.ReactNode;\n }\n\n if (typeof content === 'number') {\n return NodeType.Number;\n }\n\n if (typeof content === 'boolean') {\n return NodeType.Boolean;\n }\n\n if (content && typeof content === 'object') {\n return NodeType.Object;\n }\n\n return NodeType.Unknown;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyC;AAEzC,iCAA+B;AAExB,MAAM,cAAc,CAAC,YAAmC;AAC7D,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO,sBAAS;AAAA,EAClB;AAEA,MAAI,OAAQ,SAAuB,aAAa,UAAU;AACxD,WAAQ,QAAsB;AAAA,EAChC;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAO,sBAAS;AAAA,EAClB;AAEA,UAAI,2CAAe,OAAO,GAAG;AAC3B,WAAO,sBAAS;AAAA,EAClB;AAEA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO,sBAAS;AAAA,EAClB;AAEA,MAAI,OAAO,YAAY,WAAW;AAChC,WAAO,sBAAS;AAAA,EAClB;AAEA,MAAI,WAAW,OAAO,YAAY,UAAU;AAC1C,WAAO,sBAAS;AAAA,EAClB;AAEA,SAAO,sBAAS;AAClB;","names":[]}
|
|
@@ -36,10 +36,12 @@ var import_deepTransform = require('./deepTransform.cjs');
|
|
|
36
36
|
var import_plugins = require('./plugins.cjs');
|
|
37
37
|
const getContent = (node, nodeProps, locale = import_built.default.internationalization.defaultLocale) => {
|
|
38
38
|
const plugins = [
|
|
39
|
+
import_plugins.insertionPlugin,
|
|
39
40
|
(0, import_plugins.translationPlugin)(locale),
|
|
40
41
|
import_plugins.enumerationPlugin,
|
|
41
42
|
import_plugins.conditionPlugin,
|
|
42
43
|
import_plugins.nestedPlugin,
|
|
44
|
+
import_plugins.filePlugin,
|
|
43
45
|
...nodeProps.plugins ?? []
|
|
44
46
|
];
|
|
45
47
|
return (0, import_deepTransform.deepTransformNode)(node, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import { type Locales, type LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport type { ContentNode } from '../../types';\nimport { deepTransformNode } from './deepTransform';\nimport {\n translationPlugin,\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n} from './plugins';\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getContent = <\n T extends ContentNode,\n L extends LocalesValues = Locales,\n>(\n node: T,\n nodeProps: NodeProps,\n locale: L = configuration.internationalization.defaultLocale as L\n) => {\n const plugins: Plugins[] = [\n translationPlugin(locale),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA0B;AAG1B,2BAAkC;AAClC,
|
|
1
|
+
{"version":3,"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import { type Locales, type LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport type { ContentNode } from '../../types';\nimport { deepTransformNode } from './deepTransform';\nimport {\n translationPlugin,\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n insertionPlugin,\n filePlugin,\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n} from './plugins';\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getContent = <\n T extends ContentNode,\n L extends LocalesValues = Locales,\n>(\n node: T,\n nodeProps: NodeProps,\n locale: L = configuration.internationalization.defaultLocale as L\n) => {\n const plugins: Plugins[] = [\n insertionPlugin,\n translationPlugin(locale),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n filePlugin,\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA0B;AAG1B,2BAAkC;AAClC,qBAUO;AAQA,MAAM,aAAa,CAIxB,MACA,WACA,SAAY,aAAAA,QAAc,qBAAqB,kBAC5C;AACH,QAAM,UAAqB;AAAA,IACzB;AAAA,QACA,kCAAkB,MAAM;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,aAAO,wCAAkB,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":["configuration"]}
|
|
@@ -20,6 +20,8 @@ var plugins_exports = {};
|
|
|
20
20
|
__export(plugins_exports, {
|
|
21
21
|
conditionPlugin: () => conditionPlugin,
|
|
22
22
|
enumerationPlugin: () => enumerationPlugin,
|
|
23
|
+
filePlugin: () => filePlugin,
|
|
24
|
+
insertionPlugin: () => insertionPlugin,
|
|
23
25
|
nestedPlugin: () => nestedPlugin,
|
|
24
26
|
translationPlugin: () => translationPlugin
|
|
25
27
|
});
|
|
@@ -29,10 +31,12 @@ var import_getCondition = require('../getCondition.cjs');
|
|
|
29
31
|
var import_getEnumeration = require('../getEnumeration.cjs');
|
|
30
32
|
var import_getNesting = require('../getNesting.cjs');
|
|
31
33
|
var import_getTranslation = require('../getTranslation.cjs');
|
|
34
|
+
var import_getInsertion = require('../getInsertion.cjs');
|
|
32
35
|
const translationPlugin = (locale) => ({
|
|
36
|
+
id: "translation-plugin",
|
|
33
37
|
canHandle: (node) => typeof node === "object" && node?.nodeType === import_types.NodeType.Translation,
|
|
34
38
|
transform: (node, props, deepTransformNode) => {
|
|
35
|
-
const result = structuredClone(node.
|
|
39
|
+
const result = structuredClone(node[import_types.NodeType.Translation]);
|
|
36
40
|
for (const key in result) {
|
|
37
41
|
const childProps = {
|
|
38
42
|
...props,
|
|
@@ -51,9 +55,10 @@ const translationPlugin = (locale) => ({
|
|
|
51
55
|
}
|
|
52
56
|
});
|
|
53
57
|
const enumerationPlugin = {
|
|
58
|
+
id: "enumeration-plugin",
|
|
54
59
|
canHandle: (node) => typeof node === "object" && node?.nodeType === import_types.NodeType.Enumeration,
|
|
55
60
|
transform: (node, props, deepTransformNode) => {
|
|
56
|
-
const result = structuredClone(node.
|
|
61
|
+
const result = structuredClone(node[import_types.NodeType.Enumeration]);
|
|
57
62
|
for (const key in result) {
|
|
58
63
|
const child = result[key];
|
|
59
64
|
const childProps = {
|
|
@@ -73,9 +78,10 @@ const enumerationPlugin = {
|
|
|
73
78
|
}
|
|
74
79
|
};
|
|
75
80
|
const conditionPlugin = {
|
|
81
|
+
id: "condition-plugin",
|
|
76
82
|
canHandle: (node) => typeof node === "object" && node?.nodeType === import_types.NodeType.Condition,
|
|
77
83
|
transform: (node, props, deepTransformNode) => {
|
|
78
|
-
const result = structuredClone(node.
|
|
84
|
+
const result = structuredClone(node[import_types.NodeType.Condition]);
|
|
79
85
|
for (const key in result) {
|
|
80
86
|
const child = result[key];
|
|
81
87
|
const childProps = {
|
|
@@ -94,14 +100,67 @@ const conditionPlugin = {
|
|
|
94
100
|
return (value) => (0, import_getCondition.getCondition)(result, value);
|
|
95
101
|
}
|
|
96
102
|
};
|
|
103
|
+
const insertionPlugin = {
|
|
104
|
+
id: "insertion-plugin",
|
|
105
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === import_types.NodeType.Insertion,
|
|
106
|
+
transform: (node, props, deepTransformNode) => {
|
|
107
|
+
const newKeyPath = [
|
|
108
|
+
...props.keyPath,
|
|
109
|
+
{
|
|
110
|
+
type: import_types.NodeType.Insertion
|
|
111
|
+
}
|
|
112
|
+
];
|
|
113
|
+
const children = node[import_types.NodeType.Insertion];
|
|
114
|
+
const insertionStringPlugin = {
|
|
115
|
+
id: "insertion-string-plugin",
|
|
116
|
+
canHandle: (node2) => typeof node2 === "string",
|
|
117
|
+
transform: (node2, subProps, deepTransformNode2) => {
|
|
118
|
+
const transformedResult = deepTransformNode2(node2, {
|
|
119
|
+
...subProps,
|
|
120
|
+
children: node2,
|
|
121
|
+
plugins: [
|
|
122
|
+
...(props.plugins ?? []).filter(
|
|
123
|
+
(plugin) => plugin.id !== "intlayer-node-plugin"
|
|
124
|
+
)
|
|
125
|
+
]
|
|
126
|
+
});
|
|
127
|
+
return (values) => {
|
|
128
|
+
const children2 = (0, import_getInsertion.getInsertion)(transformedResult, values);
|
|
129
|
+
return deepTransformNode2(children2, {
|
|
130
|
+
...subProps,
|
|
131
|
+
plugins: props.plugins,
|
|
132
|
+
children: children2
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
return deepTransformNode(children, {
|
|
138
|
+
...props,
|
|
139
|
+
children,
|
|
140
|
+
keyPath: newKeyPath,
|
|
141
|
+
plugins: [insertionStringPlugin, ...props.plugins ?? []]
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
97
145
|
const nestedPlugin = {
|
|
146
|
+
id: "nested-plugin",
|
|
98
147
|
canHandle: (node) => typeof node === "object" && node?.nodeType === import_types.NodeType.Nested,
|
|
99
148
|
transform: (node, props) => (0, import_getNesting.getNesting)(node.nested.dictionaryKey, node.nested.path, props)
|
|
100
149
|
};
|
|
150
|
+
const filePlugin = {
|
|
151
|
+
id: "file-plugin",
|
|
152
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === import_types.NodeType.File,
|
|
153
|
+
transform: (node, props, deepTransform) => deepTransform(node.content, {
|
|
154
|
+
...props,
|
|
155
|
+
children: node.content
|
|
156
|
+
})
|
|
157
|
+
};
|
|
101
158
|
// Annotate the CommonJS export names for ESM import in node:
|
|
102
159
|
0 && (module.exports = {
|
|
103
160
|
conditionPlugin,
|
|
104
161
|
enumerationPlugin,
|
|
162
|
+
filePlugin,
|
|
163
|
+
insertionPlugin,
|
|
105
164
|
nestedPlugin,
|
|
106
165
|
translationPlugin
|
|
107
166
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport type {\n ConditionContent,\n EnumerationContent,\n NestedContent,\n TranslationContent,\n} from '../../transpiler';\nimport { type DictionaryKeys, type KeyPath, NodeType } from '../../types/index';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type TranslationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Translation]: object;\n}\n ? DeepTransformContent<\n T[NodeType.Translation][keyof T[NodeType.Translation]],\n S\n >\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (locale: LocalesValues): Plugins => ({\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node.translation);\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n return getTranslation(result, locale);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Enumeration]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[NodeType.Enumeration][keyof T[NodeType.Enumeration]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node.enumeration);\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Enumeration, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (quantity: number) => getEnumeration(result, quantity);\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Condition]: object;\n}\n ? (\n value: boolean\n ) => DeepTransformContent<\n T[NodeType.Condition][keyof T[NodeType.Condition]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node.condition);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Condition, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: boolean) => getCondition(result, value);\n },\n};\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Nested]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin: Plugins = {\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Nested,\n transform: (node: NestedContent, props) =>\n getNesting(node.nested.dictionaryKey, node.nested.path, props),\n};\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locales;\n dictionaryPath?: string;\n children?: any;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S> {\n translation: TranslationCond<T, S>;\n enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n condition: true;\n nested: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<T, K extends keyof IInterpreterPlugin<T, S>, S> =\n // Test if the key is a key of S.\n K extends keyof S\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S> =\n // Turn any read-only array into a plain mutable array\n T extends ReadonlyArray<infer U>\n ? Array<DeepTransformContent<U, S>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S> }\n : T;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<T, S = IInterpreterPluginState> =\n // Check if there is a plugin for T:\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S>, S> extends never\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S>\n : // A plugin was found – use the plugin’s transformation.\n IInterpreterPlugin<T, S>[keyof IInterpreterPlugin<T, S>];\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,mBAA4D;AAC5D,0BAA6B;AAC7B,4BAA+B;AAC/B,wBAAkD;AAClD,4BAA+B;AAqCxB,MAAM,oBAAoB,CAAC,YAAoC;AAAA,EACpE,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,WAAW;AAE/C,eAAW,OAAO,QAAQ;AACxB,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU,OAAO,GAAqC;AAAA,QACtD,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C,OAAO,GAAqC;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AACA,eAAO,sCAAe,QAAQ,MAAM;AAAA,EACtC;AACF;AAmBO,MAAM,oBAA6B;AAAA,EACxC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,WAAW;AAE/C,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAAqC;AAC1D,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU;AAAA,QACV,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,iBAAqB,sCAAe,QAAQ,QAAQ;AAAA,EAC9D;AACF;AAmBO,MAAM,kBAA2B;AAAA,EACtC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAO,sBAAsB;AAC/D,UAAM,SAAS,gBAAgB,KAAK,SAAS;AAE7C,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAA0B;AAC/C,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU;AAAA,QACV,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,WAAW,IAAI;AAAA,QAClC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,cAAmB,kCAAa,QAAQ,KAAK;AAAA,EACvD;AACF;AAmBO,MAAM,eAAwB;AAAA,EACnC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAqB,cAC/B,8BAAW,KAAK,OAAO,eAAe,KAAK,OAAO,MAAM,KAAK;AACjE;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport type {\n ConditionContent,\n EnumerationContent,\n NestedContent,\n TranslationContent,\n InsertionContent,\n FileContent,\n} from '../../transpiler';\nimport { type DictionaryKeys, type KeyPath, NodeType } from '../../types/index';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\nimport { getInsertion } from '../getInsertion';\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type TranslationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Translation]: object;\n}\n ? DeepTransformContent<\n T[NodeType.Translation][keyof T[NodeType.Translation]],\n S\n >\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (locale: LocalesValues): Plugins => ({\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Translation]);\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n return getTranslation(result, locale);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Enumeration]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[NodeType.Enumeration][keyof T[NodeType.Enumeration]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Enumeration]);\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Enumeration, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (quantity: number) => getEnumeration(result, quantity);\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Condition]: object;\n}\n ? (\n value: boolean\n ) => DeepTransformContent<\n T[NodeType.Condition][keyof T[NodeType.Condition]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Condition]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Condition, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: boolean) => getCondition(result, value);\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Insertion]: infer I;\n fields?: infer U;\n}\n ? U extends readonly string[]\n ? (data: Record<U[number], string>) => DeepTransformContent<I, S>\n : (data: Record<string, string>) => DeepTransformContent<I, S>\n : never;\n\nexport const insertionPlugin: Plugins = {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Insertion,\n },\n ];\n\n const children = node[NodeType.Insertion];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (values: {\n [K in InsertionContent['fields'][number]]: string;\n }) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Nested]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin: Plugins = {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Nested,\n transform: (node: NestedContent, props) =>\n getNesting(node.nested.dictionaryKey, node.nested.path, props),\n};\n\n// /** ---------------------------------------------\n// * FILE PLUGIN\n// * --------------------------------------------- */\n\nexport type FileCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.File]: string;\n content?: string;\n}\n ? string\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins = {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.File,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n};\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locales;\n dictionaryPath?: string;\n children?: any;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S> {\n translation: TranslationCond<T, S>;\n insertion: InsertionCond<T, S>;\n enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\n // file: FileCond<T>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n condition: true;\n insertion: true;\n nested: true;\n // file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<T, K extends keyof IInterpreterPlugin<T, S>, S> =\n // Test if the key is a key of S.\n K extends keyof S\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S> =\n // Turn any read-only array into a plain mutable array\n T extends ReadonlyArray<infer U>\n ? Array<DeepTransformContent<U, S>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S> }\n : T;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<T, S = IInterpreterPluginState> =\n // Check if there is a plugin for T:\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S>, S> extends never\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S>\n : // A plugin was found – use the plugin’s transformation.\n IInterpreterPlugin<T, S>[keyof IInterpreterPlugin<T, S>];\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,mBAA4D;AAC5D,0BAA6B;AAC7B,4BAA+B;AAC/B,wBAAkD;AAClD,4BAA+B;AAC/B,0BAA6B;AAsCtB,MAAM,oBAAoB,CAAC,YAAoC;AAAA,EACpE,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,sBAAS,WAAW,CAAC;AAEzD,eAAW,OAAO,QAAQ;AACxB,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU,OAAO,GAAqC;AAAA,QACtD,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C,OAAO,GAAqC;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AACA,eAAO,sCAAe,QAAQ,MAAM;AAAA,EACtC;AACF;AAmBO,MAAM,oBAA6B;AAAA,EACxC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,sBAAS,WAAW,CAAC;AAEzD,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAAqC;AAC1D,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU;AAAA,QACV,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,iBAAqB,sCAAe,QAAQ,QAAQ;AAAA,EAC9D;AACF;AAmBO,MAAM,kBAA2B;AAAA,EACtC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAO,sBAAsB;AAC/D,UAAM,SAAS,gBAAgB,KAAK,sBAAS,SAAS,CAAC;AAEvD,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAA0B;AAC/C,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU;AAAA,QACV,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,WAAW,IAAI;AAAA,QAClC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,cAAmB,kCAAa,QAAQ,KAAK;AAAA,EACvD;AACF;AAgBO,MAAM,kBAA2B;AAAA,EACtC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAO,sBAAsB;AAC/D,UAAM,aAAwB;AAAA,MAC5B,GAAG,MAAM;AAAA,MACT;AAAA,QACE,MAAM,sBAAS;AAAA,MACjB;AAAA,IACF;AAEA,UAAM,WAAW,KAAK,sBAAS,SAAS;AAGxC,UAAM,wBAAiC;AAAA,MACrC,IAAI;AAAA,MACJ,WAAW,CAACA,UAAS,OAAOA,UAAS;AAAA,MACrC,WAAW,CAACA,OAAc,UAAUC,uBAAsB;AACxD,cAAM,oBAAoBA,mBAAkBD,OAAM;AAAA,UAChD,GAAG;AAAA,UACH,UAAUA;AAAA,UACV,SAAS;AAAA,YACP,IAAI,MAAM,WAAY,CAAC,GAAiB;AAAA,cACtC,CAAC,WAAW,OAAO,OAAO;AAAA,YAC5B;AAAA,UACF;AAAA,QACF,CAAC;AAED,eAAO,CAAC,WAEF;AACJ,gBAAME,gBAAW,kCAAa,mBAAmB,MAAM;AAEvD,iBAAOD,mBAAkBC,WAAU;AAAA,YACjC,GAAG;AAAA,YACH,SAAS,MAAM;AAAA,YACf,UAAAA;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,WAAO,kBAAkB,UAAU;AAAA,MACjC,GAAG;AAAA,MACH;AAAA,MACA,SAAS;AAAA,MACT,SAAS,CAAC,uBAAuB,GAAI,MAAM,WAAW,CAAC,CAAE;AAAA,IAC3D,CAAC;AAAA,EACH;AACF;AAmBO,MAAM,eAAwB;AAAA,EACnC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAqB,cAC/B,8BAAW,KAAK,OAAO,eAAe,KAAK,OAAO,MAAM,KAAK;AACjE;AAeO,MAAM,aAAsB;AAAA,EACjC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAmB,OAAO,kBACpC,cAAc,KAAK,SAAS;AAAA,IAC1B,GAAG;AAAA,IACH,UAAU,KAAK;AAAA,EACjB,CAAC;AACL;","names":["node","deepTransformNode","children"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
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 getInsertion_exports = {};
|
|
20
|
+
__export(getInsertion_exports, {
|
|
21
|
+
getInsertion: () => getInsertion
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(getInsertion_exports);
|
|
24
|
+
const getInsertion = (content, values) => content.replace(/\{\{(.*?)\}\}/g, (_, key) => values[key] ?? "");
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
getInsertion
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=getInsertion.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/getInsertion.ts"],"sourcesContent":["import type { InsertionContent } from '../transpiler';\n\n/**\n * Allow to insert values in a string.\n *\n * Usage:\n *\n * ```ts\n * const content = getInsertion('Hello {{name}}!', {\n * name: 'John',\n * });\n * // 'Hello John!'\n * ```\n *\n */\nexport const getInsertion = (\n content: string,\n values: { [K in InsertionContent['fields'][number]]: string }\n) => content.replace(/\\{\\{(.*?)\\}\\}/g, (_, key) => values[key] ?? '');\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeO,MAAM,eAAe,CAC1B,SACA,WACG,QAAQ,QAAQ,kBAAkB,CAAC,GAAG,QAAQ,OAAO,GAAG,KAAK,EAAE;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\nimport { LanguageContent } from '../types';\n\n/**\n *\n * Allow to pick a content based on a locale.\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = getTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const getTranslation = <Content = string>(\n languageContent: LanguageContent<Content>,\n locale?: LocalesValues\n): Content => {\n const { defaultLocale } = configuration?.internationalization;\n\n const result =\n languageContent[\n (locale ?? defaultLocale) as unknown as keyof typeof languageContent\n ] ??\n (languageContent[\n defaultLocale as unknown as keyof typeof languageContent\n ] as Content);\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA0B;AAwBnB,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,IAAI,aAAAA,SAAe;AAEzC,QAAM,SACJ,gBACG,UAAU,aACb,KACC,gBACC,aACF;AAEF,SAAO;AACT;","names":["configuration"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 file_exports = {};
|
|
20
|
+
__export(file_exports, {
|
|
21
|
+
file: () => file
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(file_exports);
|
|
24
|
+
var import_fs = require("fs");
|
|
25
|
+
var import_types = require('../../types/index.cjs');
|
|
26
|
+
var import_path = require("path");
|
|
27
|
+
var import_config = require("@intlayer/config");
|
|
28
|
+
const file = (path) => {
|
|
29
|
+
const callerDir = intlayer_file_dir ?? process.cwd();
|
|
30
|
+
const isAbsolutePath = path.startsWith("/");
|
|
31
|
+
const isRelativePath = path.startsWith("./") || path.startsWith("../");
|
|
32
|
+
let filePath;
|
|
33
|
+
if (isAbsolutePath) {
|
|
34
|
+
(0, import_config.appLogger)(
|
|
35
|
+
`Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${intlayer_file_path}`,
|
|
36
|
+
{ level: "warn" }
|
|
37
|
+
);
|
|
38
|
+
filePath = path;
|
|
39
|
+
} else if (isRelativePath) {
|
|
40
|
+
filePath = (0, import_path.resolve)(callerDir, path);
|
|
41
|
+
} else {
|
|
42
|
+
filePath = (0, import_path.resolve)(process.cwd(), path);
|
|
43
|
+
}
|
|
44
|
+
let content;
|
|
45
|
+
if ((0, import_fs.existsSync)(filePath)) {
|
|
46
|
+
content = (0, import_fs.readFileSync)(filePath, "utf8");
|
|
47
|
+
} else {
|
|
48
|
+
(0, import_config.appLogger)(`File not found: ${filePath}`, { level: "warn" });
|
|
49
|
+
content = `File not found`;
|
|
50
|
+
}
|
|
51
|
+
return (0, import_types.formatNodeType)(import_types.NodeType.File, path, {
|
|
52
|
+
content,
|
|
53
|
+
fixedPath: (0, import_path.relative)(process.cwd(), filePath)
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
file
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=file.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/file/file.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'fs';\nimport {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\nimport { relative, resolve } from 'path';\nimport { appLogger } from '@intlayer/config';\n\nexport type FileContent = TypedNodeModel<\n NodeType.File,\n string,\n {\n content: string;\n fixedPath?: string;\n }\n>;\n\ndeclare const intlayer_file_path: string; // Injected by esbuild to track the file content\ndeclare const intlayer_file_dir: string; // Injected by esbuild to track the file path\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow identify the usage of an external resource.\n *\n * Usage:\n *\n * ```ts\n * file('/path/to/file.md') // absolute path\n *\n * // or\n *\n * file('path/to/file.md') // relative path\n * ```\n */\nexport const file = (path: string): FileContent => {\n const callerDir = intlayer_file_dir ?? process.cwd();\n\n const isAbsolutePath = path.startsWith('/');\n const isRelativePath = path.startsWith('./') || path.startsWith('../');\n\n let filePath: string;\n if (isAbsolutePath) {\n appLogger(\n `Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${intlayer_file_path}`,\n { level: 'warn' }\n );\n filePath = path;\n } else if (isRelativePath) {\n filePath = resolve(callerDir, path);\n } else {\n filePath = resolve(process.cwd(), path);\n }\n\n let content: string;\n\n if (existsSync(filePath)) {\n content = readFileSync(filePath, 'utf8');\n } else {\n appLogger(`File not found: ${filePath}`, { level: 'warn' });\n\n content = `File not found`;\n }\n\n return formatNodeType(NodeType.File, path, {\n content,\n fixedPath: relative(process.cwd(), filePath),\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAyC;AACzC,mBAIO;AACP,kBAAkC;AAClC,oBAA0B;AA6BnB,MAAM,OAAO,CAAC,SAA8B;AACjD,QAAM,YAAY,qBAAqB,QAAQ,IAAI;AAEnD,QAAM,iBAAiB,KAAK,WAAW,GAAG;AAC1C,QAAM,iBAAiB,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK;AAErE,MAAI;AACJ,MAAI,gBAAgB;AAClB;AAAA,MACE,sFAAsF,IAAI,oBAAoB,kBAAkB;AAAA,MAChI,EAAE,OAAO,OAAO;AAAA,IAClB;AACA,eAAW;AAAA,EACb,WAAW,gBAAgB;AACzB,mBAAW,qBAAQ,WAAW,IAAI;AAAA,EACpC,OAAO;AACL,mBAAW,qBAAQ,QAAQ,IAAI,GAAG,IAAI;AAAA,EACxC;AAEA,MAAI;AAEJ,UAAI,sBAAW,QAAQ,GAAG;AACxB,kBAAU,wBAAa,UAAU,MAAM;AAAA,EACzC,OAAO;AACL,iCAAU,mBAAmB,QAAQ,IAAI,EAAE,OAAO,OAAO,CAAC;AAE1D,cAAU;AAAA,EACZ;AAEA,aAAO,6BAAe,sBAAS,MAAM,MAAM;AAAA,IACzC;AAAA,IACA,eAAW,sBAAS,QAAQ,IAAI,GAAG,QAAQ;AAAA,EAC7C,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 fileBrowser_exports = {};
|
|
20
|
+
__export(fileBrowser_exports, {
|
|
21
|
+
file: () => file
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(fileBrowser_exports);
|
|
24
|
+
var import_types = require('../../types/index.cjs');
|
|
25
|
+
const file = (path) => {
|
|
26
|
+
throw new Error("file is not available in browser");
|
|
27
|
+
return (0, import_types.formatNodeType)(import_types.NodeType.File, path, {
|
|
28
|
+
content: "",
|
|
29
|
+
fixedPath: ""
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
file
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=fileBrowser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/file/fileBrowser.ts"],"sourcesContent":["import { formatNodeType, NodeType } from '../../types';\nimport type { FileContent } from './file';\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow identify the usage of an external resource.\n *\n * Usage:\n *\n * ```ts\n * file('/path/to/file.md') // absolute path\n *\n * // or\n *\n * file('path/to/file.md') // relative path\n * ```\n */\nexport const file = (path: string): FileContent => {\n throw new Error('file is not available in browser');\n\n return formatNodeType(NodeType.File, path, {\n content: '',\n fixedPath: '',\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyC;AAkBlC,MAAM,OAAO,CAAC,SAA8B;AACjD,QAAM,IAAI,MAAM,kCAAkC;AAElD,aAAO,6BAAe,sBAAS,MAAM,MAAM;AAAA,IACzC,SAAS;AAAA,IACT,WAAW;AAAA,EACb,CAAC;AACH;","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 file_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(file_exports);
|
|
18
|
+
__reExport(file_exports, require('./file.cjs'), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require('./file.cjs')
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/file/index.ts"],"sourcesContent":["export * from './file';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,yBAAc,mBAAd;","names":[]}
|
|
@@ -18,6 +18,7 @@ module.exports = __toCommonJS(transpiler_exports);
|
|
|
18
18
|
__reExport(transpiler_exports, require('./translation/index.cjs'), module.exports);
|
|
19
19
|
__reExport(transpiler_exports, require('./enumeration/index.cjs'), module.exports);
|
|
20
20
|
__reExport(transpiler_exports, require('./condition/index.cjs'), module.exports);
|
|
21
|
+
__reExport(transpiler_exports, require('./insertion/index.cjs'), module.exports);
|
|
21
22
|
__reExport(transpiler_exports, require('./markdown/index.cjs'), module.exports);
|
|
22
23
|
__reExport(transpiler_exports, require('./nesting/index.cjs'), module.exports);
|
|
23
24
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -25,6 +26,7 @@ __reExport(transpiler_exports, require('./nesting/index.cjs'), module.exports);
|
|
|
25
26
|
...require('./translation/index.cjs'),
|
|
26
27
|
...require('./enumeration/index.cjs'),
|
|
27
28
|
...require('./condition/index.cjs'),
|
|
29
|
+
...require('./insertion/index.cjs'),
|
|
28
30
|
...require('./markdown/index.cjs'),
|
|
29
31
|
...require('./nesting/index.cjs')
|
|
30
32
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/transpiler/index.ts"],"sourcesContent":["export * from './translation/index';\nexport * from './enumeration/index';\nexport * from './condition/index';\nexport * from './markdown/index';\nexport * from './nesting/index';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,gCAAd;AACA,+BAAc,gCADd;AAEA,+BAAc,8BAFd;AAGA,+BAAc,
|
|
1
|
+
{"version":3,"sources":["../../../src/transpiler/index.ts"],"sourcesContent":["export * from './translation/index';\nexport * from './enumeration/index';\nexport * from './condition/index';\nexport * from './insertion/index';\nexport * from './markdown/index';\nexport * from './nesting/index';\nexport type * from './file/index'; // Export type only because of file transpiler is based on node js function and block build\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,gCAAd;AACA,+BAAc,gCADd;AAEA,+BAAc,8BAFd;AAGA,+BAAc,8BAHd;AAIA,+BAAc,6BAJd;AAKA,+BAAc,4BALd;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 getInsertionValues_exports = {};
|
|
20
|
+
__export(getInsertionValues_exports, {
|
|
21
|
+
getInsertionValues: () => getInsertionValues
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(getInsertionValues_exports);
|
|
24
|
+
const getInsertionValues = (content) => {
|
|
25
|
+
const regex = /{{\s*(\w+)\s*}}/g;
|
|
26
|
+
const matches = [...content.matchAll(regex)];
|
|
27
|
+
if (matches.length === 0) return [];
|
|
28
|
+
return matches.map((match) => match[1]);
|
|
29
|
+
};
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
getInsertionValues
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=getInsertionValues.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/insertion/getInsertionValues.ts"],"sourcesContent":["export const getInsertionValues = (content: string): string[] => {\n // Regular expression to match {{field}} patterns\n const regex = /{{\\s*(\\w+)\\s*}}/g;\n const matches = [...content.matchAll(regex)];\n\n // If no matches are found, return undefined\n if (matches.length === 0) return [];\n\n // Extract field names from matches and return as an object with the field names\n return matches.map((match) => match[1]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,qBAAqB,CAAC,YAA8B;AAE/D,QAAM,QAAQ;AACd,QAAM,UAAU,CAAC,GAAG,QAAQ,SAAS,KAAK,CAAC;AAG3C,MAAI,QAAQ,WAAW,EAAG,QAAO,CAAC;AAGlC,SAAO,QAAQ,IAAI,CAAC,UAAU,MAAM,CAAC,CAAC;AACxC;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 insertion_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(insertion_exports);
|
|
18
|
+
__reExport(insertion_exports, require('./insertion.cjs'), module.exports);
|
|
19
|
+
__reExport(insertion_exports, require('./getInsertionValues.cjs'), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require('./insertion.cjs'),
|
|
23
|
+
...require('./getInsertionValues.cjs')
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/insertion/index.ts"],"sourcesContent":["export * from './insertion';\nexport * from './getInsertionValues';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,8BAAc,wBAAd;AACA,8BAAc,iCADd;","names":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
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 insertion_exports = {};
|
|
20
|
+
__export(insertion_exports, {
|
|
21
|
+
insert: () => insertion
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(insertion_exports);
|
|
24
|
+
var import_types = require('../../types/index.cjs');
|
|
25
|
+
var import_getInsertionValues = require('./getInsertionValues.cjs');
|
|
26
|
+
const insertion = (content) => {
|
|
27
|
+
const getInsertions = () => {
|
|
28
|
+
if (typeof content === "string") {
|
|
29
|
+
return (0, import_getInsertionValues.getInsertionValues)(content);
|
|
30
|
+
}
|
|
31
|
+
let stringContent = void 0;
|
|
32
|
+
if (typeof content === "function") {
|
|
33
|
+
stringContent = content();
|
|
34
|
+
} else if (typeof content.then === "function") {
|
|
35
|
+
stringContent = async () => (0, import_getInsertionValues.getInsertionValues)(await content);
|
|
36
|
+
}
|
|
37
|
+
if (typeof stringContent === "string") {
|
|
38
|
+
return (0, import_getInsertionValues.getInsertionValues)(stringContent);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
return (0, import_getInsertionValues.getInsertionValues)(JSON.stringify(content));
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return (0, import_types.formatNodeType)(import_types.NodeType.Insertion, content, {
|
|
47
|
+
fields: getInsertions()
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
insert
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=insertion.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/insertion/insertion.ts"],"sourcesContent":["import {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\nimport { getInsertionValues } from './getInsertionValues';\n\nexport type InsertionContent<Content = unknown> = TypedNodeModel<\n NodeType.Insertion,\n Content,\n { fields: string[] }\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to identify insertions inside a content.\n *\n * Usage:\n *\n * ```ts\n * insertion('Hi, my name is {{name}} and I am {{age}} years old.')\n * ```\n *\n */\nconst insertion = <Content = unknown>(\n content: Content\n): InsertionContent<Content> => {\n const getInsertions = () => {\n if (typeof content === 'string') {\n return getInsertionValues(content);\n }\n\n let stringContent = undefined;\n\n if (typeof content === 'function') {\n stringContent = content();\n } else if (typeof (content as Promise<string>).then === 'function') {\n stringContent = async () =>\n getInsertionValues(await (content as Promise<string>));\n }\n\n if (typeof stringContent === 'string') {\n return getInsertionValues(stringContent);\n }\n\n try {\n return getInsertionValues(JSON.stringify(content));\n } catch (e) {\n return [];\n }\n };\n\n return formatNodeType(NodeType.Insertion, content, {\n fields: getInsertions(),\n });\n};\n\nexport { insertion as insert };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAIO;AACP,gCAAmC;AAoBnC,MAAM,YAAY,CAChB,YAC8B;AAC9B,QAAM,gBAAgB,MAAM;AAC1B,QAAI,OAAO,YAAY,UAAU;AAC/B,iBAAO,8CAAmB,OAAO;AAAA,IACnC;AAEA,QAAI,gBAAgB;AAEpB,QAAI,OAAO,YAAY,YAAY;AACjC,sBAAgB,QAAQ;AAAA,IAC1B,WAAW,OAAQ,QAA4B,SAAS,YAAY;AAClE,sBAAgB,gBACd,8CAAmB,MAAO,OAA2B;AAAA,IACzD;AAEA,QAAI,OAAO,kBAAkB,UAAU;AACrC,iBAAO,8CAAmB,aAAa;AAAA,IACzC;AAEA,QAAI;AACF,iBAAO,8CAAmB,KAAK,UAAU,OAAO,CAAC;AAAA,IACnD,SAAS,GAAG;AACV,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AAEA,aAAO,6BAAe,sBAAS,WAAW,SAAS;AAAA,IACjD,QAAQ,cAAc;AAAA,EACxB,CAAC;AACH;","names":[]}
|