nodoku-core 0.2.2 → 0.2.4
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/esm/bin/generate-component-resolver.js +1 -5
- package/esm/bin/generate-skin-schema.js +1 -4
- package/esm/bin/manifest-loader.js +13 -3
- package/esm/bin/manifest.js +1 -24
- package/esm/core/dummy-comp.jsx +13 -15
- package/esm/core/rendering-page-props.js +4 -1
- package/esm/core/rendering-page.jsx +69 -17
- package/esm/index.js +27 -0
- package/esm/skin/nd-skin.js +3 -3
- package/package.json +1 -1
- package/types/bin/manifest.d.ts +5 -7
- package/types/core/providers.d.ts +10 -2
- package/types/core/rendering-page-props.d.ts +8 -4
- package/types/index.d.ts +5 -3
- package/types/skin/nd-skin.d.ts +5 -4
|
@@ -12,16 +12,12 @@ register('./import-load-hooks.js', import.meta.url);
|
|
|
12
12
|
*/
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
const template = (await import("./mustache/component-resolver.ts.hbs")).default;
|
|
15
|
-
class TemplateView {
|
|
16
|
-
modules = [];
|
|
17
|
-
comps = [];
|
|
18
|
-
}
|
|
19
15
|
function calculateTemplateView(dirNodeModules = undefined) {
|
|
20
16
|
if (!dirNodeModules) {
|
|
21
17
|
dirNodeModules = `${path.resolve()}/node_modules`;
|
|
22
18
|
}
|
|
23
19
|
const manifests = loadManifestsFromFolder(dirNodeModules);
|
|
24
|
-
const view =
|
|
20
|
+
const view = { modules: [], comps: [] };
|
|
25
21
|
manifests.forEach((m, k) => {
|
|
26
22
|
let prefix = "";
|
|
27
23
|
if (m.namespace) {
|
|
@@ -12,15 +12,12 @@ register('./import-load-hooks.js', import.meta.url);
|
|
|
12
12
|
*/
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
const template = (await import("./mustache/visual-schema.json.hbs")).default;
|
|
15
|
-
class TemplateView {
|
|
16
|
-
components = new Map();
|
|
17
|
-
}
|
|
18
15
|
function calculateTemplateView(schemaDestinationDir, dirNodeModules = undefined) {
|
|
19
16
|
if (!dirNodeModules) {
|
|
20
17
|
dirNodeModules = path.resolve("./node_modules");
|
|
21
18
|
}
|
|
22
19
|
const components = loadManifestsFromFolder(dirNodeModules);
|
|
23
|
-
const tv = new
|
|
20
|
+
const tv = { components: new Map() };
|
|
24
21
|
components.forEach((m) => {
|
|
25
22
|
m.components.forEach((cd, cn) => {
|
|
26
23
|
const moduleDir = `${dirNodeModules}/${m.moduleName}`;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ComponentDef, Manifest } from "./manifest.js";
|
|
2
1
|
import fs from "node:fs";
|
|
3
2
|
import path from "path";
|
|
4
3
|
export function loadManifestsFromFolder(dir) {
|
|
@@ -23,7 +22,11 @@ function loadComponentsByManifest(dir, moduleName) {
|
|
|
23
22
|
const stat = fs.statSync(moduleDir);
|
|
24
23
|
if (stat.isFile()) {
|
|
25
24
|
if (f == "nodoku.manifest.json") {
|
|
26
|
-
const manifest =
|
|
25
|
+
const manifest = {
|
|
26
|
+
moduleName: moduleName,
|
|
27
|
+
moduleDir: moduleDir,
|
|
28
|
+
components: new Map()
|
|
29
|
+
};
|
|
27
30
|
console.log("found manifest ", `${dir}/${f}`, "reading...");
|
|
28
31
|
let json;
|
|
29
32
|
if (stat.isSymbolicLink()) {
|
|
@@ -39,7 +42,14 @@ function loadComponentsByManifest(dir, moduleName) {
|
|
|
39
42
|
const v = json.components[k];
|
|
40
43
|
console.log("adding ", k, v);
|
|
41
44
|
// comps.set(k, Manifest.from(k, moduleName, v));
|
|
42
|
-
manifest.components.set(k, new ComponentDef(v.implementation, v.schemaFile, v.optionsFile, v.defaultThemeFile, v.numBlocks))
|
|
45
|
+
// manifest.components.set(k, new ComponentDef(v.implementation, v.schemaFile, v.optionsFile, v.defaultThemeFile, v.numBlocks))
|
|
46
|
+
manifest.components.set(k, {
|
|
47
|
+
implementation: v.implementation,
|
|
48
|
+
themeSchema: v.schemaFile,
|
|
49
|
+
optionsSchema: v.optionsFile,
|
|
50
|
+
defaultThemeFile: v.defaultThemeFile,
|
|
51
|
+
numBlocks: v.numBlocks
|
|
52
|
+
});
|
|
43
53
|
});
|
|
44
54
|
return manifest;
|
|
45
55
|
}
|
package/esm/bin/manifest.js
CHANGED
|
@@ -1,24 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
implementation;
|
|
3
|
-
themeSchema;
|
|
4
|
-
optionsSchema;
|
|
5
|
-
defaultThemeFile;
|
|
6
|
-
numBlocks;
|
|
7
|
-
constructor(componentImplementation, componentSchema, optionsSchema, defaultThemeFile, numBlocks) {
|
|
8
|
-
this.implementation = componentImplementation;
|
|
9
|
-
this.themeSchema = componentSchema;
|
|
10
|
-
this.optionsSchema = optionsSchema;
|
|
11
|
-
this.defaultThemeFile = defaultThemeFile;
|
|
12
|
-
this.numBlocks = numBlocks;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export class Manifest {
|
|
16
|
-
moduleName;
|
|
17
|
-
moduleDir;
|
|
18
|
-
namespace = undefined;
|
|
19
|
-
components = new Map();
|
|
20
|
-
constructor(moduleName, moduleDir) {
|
|
21
|
-
this.moduleName = moduleName;
|
|
22
|
-
this.moduleDir = moduleDir;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
export {};
|
package/esm/core/dummy-comp.jsx
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
import { NdCode, NdTranslatableText } from "../content/nd-content";
|
|
2
2
|
export async function DummyComp(props) {
|
|
3
3
|
// console.log("content dummy comp", props.theme)
|
|
4
|
-
const { content,
|
|
5
|
-
const { t } = await
|
|
4
|
+
const { content, i18nextTrustedHtmlProvider, lng, rowIndex, componentIndex } = props;
|
|
5
|
+
const { t } = await i18nextTrustedHtmlProvider(lng);
|
|
6
6
|
return <div>{await render(rowIndex, componentIndex, content[0], t)}</div>;
|
|
7
7
|
}
|
|
8
8
|
async function render(rowIndex, componentIndex, block, t) {
|
|
9
9
|
console.log("this is my block", block.callToActions.map(cta => `${cta.ctaUrl.key}`));
|
|
10
10
|
return (<div className={"w-full w-full flex flex-col items-left justify-left border border-4 border-red-200 relative pb-10"}>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<div className={"top-0 bottom-0 left-0 right-0 absolute bg-white "} style={{ zIndex: -5, opacity: 0.7 }}>
|
|
11
|
+
<div className={"top-0 bottom-0 left-0 right-0 absolute bg-white "} style={{ zIndex: -5, opacity: 0.7 }}></div>
|
|
12
|
+
<div className={"p-5 w-full bg-red-400 text-center"}>
|
|
13
|
+
dummy component<h3><b>{`ns-${block.namespace}-row-${rowIndex}-i-${componentIndex}`}</b></h3>
|
|
15
14
|
</div>
|
|
16
|
-
<div className={"p-5 w-full bg-red-400 text-center"}>dummy component<h3><b>{`ns-${block.namespace}-row-${rowIndex}-i-${componentIndex}`}</b></h3></div>
|
|
17
15
|
|
|
18
16
|
|
|
19
17
|
<div className="p-5">
|
|
20
18
|
{block.title && <a href="#">
|
|
21
19
|
{block.title && block.title.key}
|
|
22
20
|
<h5 className={"mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white"}>
|
|
23
|
-
{block.title && t(block.title)}
|
|
21
|
+
{block.title && t(block.title).__html}
|
|
24
22
|
</h5>
|
|
25
23
|
</a>}
|
|
26
24
|
{block.subTitle && block.subTitle.key}
|
|
27
25
|
{block.subTitle && <h6 className={"mb-2 text-xl tracking-tight text-gray-900 dark:text-white"}>
|
|
28
|
-
{block.subTitle && t(block.subTitle)}
|
|
26
|
+
{block.subTitle && t(block.subTitle).__html}
|
|
29
27
|
</h6>}
|
|
30
28
|
|
|
31
29
|
paragraphs:
|
|
@@ -34,7 +32,7 @@ async function render(rowIndex, componentIndex, block, t) {
|
|
|
34
32
|
return (<div>
|
|
35
33
|
{p && p.key}
|
|
36
34
|
<p key={ip} className={"mb-3 font-normal text-gray-700 dark:text-gray-400"}>
|
|
37
|
-
{p && t(p)}
|
|
35
|
+
{p && t(p).__html}
|
|
38
36
|
</p>
|
|
39
37
|
</div>);
|
|
40
38
|
}
|
|
@@ -50,12 +48,12 @@ async function render(rowIndex, componentIndex, block, t) {
|
|
|
50
48
|
const list = p;
|
|
51
49
|
if (list.ordered) {
|
|
52
50
|
return (<ol className={"list-disc list-outside"}>
|
|
53
|
-
{list.items.map(i => <li className={"ml-4"}>{t(i)} <small>(<i>{i.key}</i>)</small></li>)}
|
|
51
|
+
{list.items.map(i => <li className={"ml-4"}>{t(i).__html} <small>(<i>{i.key}</i>)</small></li>)}
|
|
54
52
|
</ol>);
|
|
55
53
|
}
|
|
56
54
|
else {
|
|
57
55
|
return (<ul className={"list-disc list-outside"}>
|
|
58
|
-
{list.items.map(i => <li className={"ml-4"}>{t(i)} <small>(<i>{i.key}</i>)</small></li>)}
|
|
56
|
+
{list.items.map(i => <li className={"ml-4"}>{t(i).__html} <small>(<i>{i.key}</i>)</small></li>)}
|
|
59
57
|
</ul>);
|
|
60
58
|
}
|
|
61
59
|
}
|
|
@@ -64,7 +62,7 @@ async function render(rowIndex, componentIndex, block, t) {
|
|
|
64
62
|
{block.images.map((img, ii) => {
|
|
65
63
|
return (<div>
|
|
66
64
|
<p key={"url" + ii} className={"mb-3 font-normal text-gray-700 dark:text-gray-400"}>
|
|
67
|
-
url: {img && img.url && t(img.url)}
|
|
65
|
+
url: {img && img.url && t(img.url).__html}
|
|
68
66
|
{img.url && <span className={"bg-cover bg-no-repeat"} style={{
|
|
69
67
|
display: "block",
|
|
70
68
|
width: "200px",
|
|
@@ -73,10 +71,10 @@ async function render(rowIndex, componentIndex, block, t) {
|
|
|
73
71
|
}}></span>}
|
|
74
72
|
</p>
|
|
75
73
|
<p key={"alt" + ii} className={"mb-3 font-normal text-gray-700 dark:text-gray-400"}>
|
|
76
|
-
alt: {img && img.alt && t(img.alt)}
|
|
74
|
+
alt: {img && img.alt && t(img.alt).__html}
|
|
77
75
|
</p>
|
|
78
76
|
<p key={"title" + ii} className={"mb-3 font-normal text-gray-700 dark:text-gray-400"}>
|
|
79
|
-
title: {img && img.title && t(img.title)}
|
|
77
|
+
title: {img && img.title && t(img.title).__html}
|
|
80
78
|
</p>
|
|
81
79
|
</div>);
|
|
82
80
|
})}
|
|
@@ -23,7 +23,9 @@ export class RenderingPageProps {
|
|
|
23
23
|
componentResolver = undefined;
|
|
24
24
|
imageProvider = undefined;
|
|
25
25
|
i18nextProvider = undefined;
|
|
26
|
-
|
|
26
|
+
i18nextPostProcessor;
|
|
27
|
+
htmlSanitizer;
|
|
28
|
+
constructor(lng, content, componentResolver, skin = undefined, renderingPriority = RenderingPriority.content_first, imageProvider = undefined, i18nextProvider = undefined, htmlSanitizer = undefined) {
|
|
27
29
|
this.lng = lng;
|
|
28
30
|
this.renderingPriority = renderingPriority;
|
|
29
31
|
this.content = content;
|
|
@@ -31,5 +33,6 @@ export class RenderingPageProps {
|
|
|
31
33
|
this.skin = skin;
|
|
32
34
|
this.imageProvider = imageProvider;
|
|
33
35
|
this.i18nextProvider = i18nextProvider;
|
|
36
|
+
this.htmlSanitizer = htmlSanitizer;
|
|
34
37
|
}
|
|
35
38
|
}
|
|
@@ -16,7 +16,7 @@ async function defaultImageProvider(imageProps) {
|
|
|
16
16
|
return <img className={`${imageStyle?.base} ${imageStyle?.decoration}`} src={url} alt={alt}/>;
|
|
17
17
|
}
|
|
18
18
|
async function RenderingPage(props) {
|
|
19
|
-
const { lng, renderingPriority, content, componentResolver, skin, imageProvider, i18nextProvider } = props;
|
|
19
|
+
const { lng, renderingPriority, content, componentResolver, skin, imageProvider, i18nextProvider, i18nextPostProcessor, htmlSanitizer } = props;
|
|
20
20
|
const actualComponentResolver = componentResolver ? componentResolver : defaultComponentResolver;
|
|
21
21
|
let l;
|
|
22
22
|
if (skin) {
|
|
@@ -26,12 +26,13 @@ async function RenderingPage(props) {
|
|
|
26
26
|
}
|
|
27
27
|
// console.log(" >>> this is my content <<< ", content)
|
|
28
28
|
// console.log(" >>> this is my skin <<< ", JSON.stringify(blockSkin))
|
|
29
|
-
l = await Promise.all(blockSkin.rows.map(async (row, iRow) => await createRow(row, iRow, content, lng, imageProvider, i18nextProvider, actualComponentResolver)));
|
|
29
|
+
l = await Promise.all(blockSkin.rows.map(async (row, iRow) => await createRow(row, iRow, content, lng, imageProvider, i18nextProvider, i18nextPostProcessor, actualComponentResolver, htmlSanitizer)));
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
|
-
l = [await createRow(undefined, 0, content, lng, imageProvider, i18nextProvider, actualComponentResolver)];
|
|
32
|
+
l = [await createRow(undefined, 0, content, lng, imageProvider, i18nextProvider, i18nextPostProcessor, actualComponentResolver, htmlSanitizer)];
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
const actualSkin = mergeTheme(skin, { renderingPage: { base: "", decoration: "" }, rows: [] });
|
|
35
|
+
return <div className={`rows-container ${ts(actualSkin, "renderingPage")}`}>{l}</div>;
|
|
35
36
|
}
|
|
36
37
|
function generateSkinByContentBlocks(blocks, skin) {
|
|
37
38
|
const rendered = new Set();
|
|
@@ -65,17 +66,17 @@ function generateSkinByContentBlocks(blocks, skin) {
|
|
|
65
66
|
// console.log("generated skin", JSON.stringify(res))
|
|
66
67
|
return res;
|
|
67
68
|
}
|
|
68
|
-
async function createRow(row, iRow, blocks, lng, imageProvider, i18nProvider, componentResolver) {
|
|
69
|
+
async function createRow(row, iRow, blocks, lng, imageProvider, i18nProvider, i18nextPostProcessor, componentResolver, htmlSanitizer) {
|
|
69
70
|
let l;
|
|
70
71
|
if (row) {
|
|
71
|
-
l = await Promise.all(row.components.map(async (visualSection, iComp) => await createRowComponents(iRow, iComp, visualSection, blocks, lng, imageProvider, i18nProvider, componentResolver)));
|
|
72
|
+
l = await Promise.all(row.components.map(async (visualSection, iComp) => await createRowComponents(iRow, iComp, visualSection, blocks, lng, imageProvider, i18nProvider, i18nextPostProcessor, componentResolver, htmlSanitizer)));
|
|
72
73
|
}
|
|
73
74
|
else {
|
|
74
|
-
l = await Promise.all(blocks.map(async (block, iComp) => await createRowComponents(iRow, iComp, undefined, [block], lng, imageProvider, i18nProvider, componentResolver)));
|
|
75
|
+
l = await Promise.all(blocks.map(async (block, iComp) => await createRowComponents(iRow, iComp, undefined, [block], lng, imageProvider, i18nProvider, i18nextPostProcessor, componentResolver, htmlSanitizer)));
|
|
75
76
|
}
|
|
76
77
|
const rowComponents = l.flatMap((p) => p);
|
|
77
78
|
if (rowComponents.length == 0) {
|
|
78
|
-
return
|
|
79
|
+
return <div key={`row-${iRow}`}></div>;
|
|
79
80
|
}
|
|
80
81
|
const numComponents = rowComponents.length;
|
|
81
82
|
const rowEffectiveTheme = mergeTheme(row?.theme, defaultRowThemeImpl);
|
|
@@ -137,13 +138,13 @@ async function createRow(row, iRow, blocks, lng, imageProvider, i18nProvider, co
|
|
|
137
138
|
if (rowEffectiveTheme.rowDisplay == "flex") {
|
|
138
139
|
rowDisplay = "flex flex-row justify-center flex-wrap flex-1";
|
|
139
140
|
}
|
|
140
|
-
return (<div key={`row-${iRow}`} className={
|
|
141
|
-
{rowComponents.map((c) => <div className={`nd-component-holder ${flexBasis} ${ts(rowEffectiveTheme, "componentHolder")}
|
|
141
|
+
return (<div key={`row-${iRow}`} className={`row-${iRow} ${rowDisplay} ${rowEffectiveTheme?.base} ${rowEffectiveTheme?.decoration} class-row-${iRow}`}>
|
|
142
|
+
{rowComponents.map((c, i) => <div key={`row-${iRow}-component-${i}`} className={`row-${iRow}-component-${i} nd-component-holder ${flexBasis} ${ts(rowEffectiveTheme, "componentHolder")}`}>
|
|
142
143
|
{c}
|
|
143
144
|
</div>)}
|
|
144
145
|
</div>);
|
|
145
146
|
}
|
|
146
|
-
async function createRowComponents(rowIndex, blockIndex, skinComponent, pageContent, lng, imageProvider, i18nProvider, componentResolver) {
|
|
147
|
+
async function createRowComponents(rowIndex, blockIndex, skinComponent, pageContent, lng, imageProvider, i18nProvider, i18nextPostProcessor, componentResolver, htmlSanitizer) {
|
|
147
148
|
// console.log("before component", skinComponent)
|
|
148
149
|
const filteredBlocks = skinComponent ? skinComponent.selector.filterBlocks(pageContent) : pageContent;
|
|
149
150
|
if (filteredBlocks.length == 0) {
|
|
@@ -169,17 +170,67 @@ async function createRowComponents(rowIndex, blockIndex, skinComponent, pageCont
|
|
|
169
170
|
const blocks = filteredBlocks.slice(start, end);
|
|
170
171
|
const compIndex = blockIndex * filteredBlocks.length + i;
|
|
171
172
|
// console.log("calculated compo index ", compIndex, "filteredBlocks.length", filteredBlocks.length, "blockIndex", blockIndex)
|
|
172
|
-
res.push(await renderSingleComponent(rowIndex, compIndex, compo, blocks, skinComponent?.defaultThemeName || "light", compoDef.defaultTheme, skinComponent?.themeHierarchy, lng, imageProvider, i18nProvider));
|
|
173
|
+
res.push(await renderSingleComponent(rowIndex, compIndex, compo, blocks, skinComponent?.defaultThemeName || "light", compoDef.defaultTheme, skinComponent?.themeHierarchy, lng, imageProvider, i18nProvider, i18nextPostProcessor, htmlSanitizer));
|
|
173
174
|
}
|
|
174
175
|
start = end;
|
|
175
176
|
++i;
|
|
176
177
|
} while (end < filteredBlocks.length);
|
|
177
178
|
return res;
|
|
178
179
|
}
|
|
179
|
-
|
|
180
|
-
|
|
180
|
+
function wrapInPostProcessor(provider, postProcessor) {
|
|
181
|
+
// if (postProcessor) {
|
|
182
|
+
//
|
|
183
|
+
// return async (lng: string): Promise<{t: (text: NdTranslatableText) => NdTrustedHtml}> => {
|
|
184
|
+
//
|
|
185
|
+
// const {t} = await provider(lng)
|
|
186
|
+
// const tt = (txt: NdTranslatableText): NdTrustedHtml => {
|
|
187
|
+
// // const translated: NdTrustedHtml = t(txt);
|
|
188
|
+
// // let res = translated;
|
|
189
|
+
// // if (typeof translated === "string") {
|
|
190
|
+
// // res = postProcessor(translated)
|
|
191
|
+
// // }
|
|
192
|
+
// // return res;
|
|
193
|
+
// return postProcessor(t(txt))
|
|
194
|
+
// }
|
|
195
|
+
//
|
|
196
|
+
// return {t: tt}
|
|
197
|
+
// }
|
|
198
|
+
// } else {
|
|
199
|
+
// return provider;
|
|
200
|
+
// }
|
|
201
|
+
return async (lng) => {
|
|
202
|
+
const { t } = await provider(lng);
|
|
203
|
+
const tt = (txt) => {
|
|
204
|
+
// const translated: NdTrustedHtml = t(txt);
|
|
205
|
+
// let res = translated;
|
|
206
|
+
// if (typeof translated === "string") {
|
|
207
|
+
// res = postProcessor(translated)
|
|
208
|
+
// }
|
|
209
|
+
// return res;
|
|
210
|
+
return postProcessor ? postProcessor(t(txt)) : t(txt);
|
|
211
|
+
};
|
|
212
|
+
return { t: tt };
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function makeTrusted(provider, sanitizer) {
|
|
216
|
+
return async (lng) => {
|
|
217
|
+
const { t } = await provider(lng);
|
|
218
|
+
const tt = (txt) => {
|
|
219
|
+
// const translated: NdTrustedHtml = t(txt);
|
|
220
|
+
// let res = translated;
|
|
221
|
+
// if (typeof translated === "string") {
|
|
222
|
+
// res = postProcessor(translated)
|
|
223
|
+
// }
|
|
224
|
+
// return res;
|
|
225
|
+
return sanitizer(t(txt));
|
|
226
|
+
};
|
|
227
|
+
return { t: tt };
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
async function renderSingleComponent(rowIndex, componentIndex, component, blocks, defaultThemeName, defaultTheme, themeHierarchy, lng, imageProvider, i18nextProvider, i18nextPostProcessor, htmlSanitizer) {
|
|
231
|
+
let actualI18nextProvider_;
|
|
181
232
|
if (lng == blocks[0].lng || !i18nextProvider) {
|
|
182
|
-
|
|
233
|
+
actualI18nextProvider_ = async (lng) => {
|
|
183
234
|
return { t: (text) => {
|
|
184
235
|
const b = blocks.map((b) => b.getByKey(text.key, text.ns)).find((s) => s);
|
|
185
236
|
return b ? b : `key not found: ${text.ns}:${text.key}`;
|
|
@@ -187,8 +238,9 @@ async function renderSingleComponent(rowIndex, componentIndex, component, blocks
|
|
|
187
238
|
};
|
|
188
239
|
}
|
|
189
240
|
else {
|
|
190
|
-
|
|
241
|
+
actualI18nextProvider_ = i18nextProvider;
|
|
191
242
|
}
|
|
243
|
+
const actualI18nextProvider = makeTrusted(wrapInPostProcessor(actualI18nextProvider_, i18nextPostProcessor), htmlSanitizer || ((text) => ({ __html: text })));
|
|
192
244
|
const actualImageProvider = imageProvider ? imageProvider : defaultImageProvider;
|
|
193
245
|
// if (themeHierarchy) {
|
|
194
246
|
// console.log("themeHierarchy", themeHierarchy)
|
|
@@ -205,7 +257,7 @@ async function renderSingleComponent(rowIndex, componentIndex, component, blocks
|
|
|
205
257
|
options: effectiveOptions,
|
|
206
258
|
lng: lng,
|
|
207
259
|
imageProvider: actualImageProvider,
|
|
208
|
-
|
|
260
|
+
i18nextTrustedHtmlProvider: actualI18nextProvider
|
|
209
261
|
};
|
|
210
262
|
// console.log("start rendering page with props", props);
|
|
211
263
|
const res = await component(props);
|
package/esm/index.js
CHANGED
|
@@ -15,4 +15,31 @@ export const ts = function (t, key) {
|
|
|
15
15
|
const k = key;
|
|
16
16
|
return k + " " + themeStyle?.base + " " + themeStyle?.decoration;
|
|
17
17
|
};
|
|
18
|
+
export const tsi = function (t, key, i) {
|
|
19
|
+
// console.log("in tsi ", key, t[key], Array.isArray(t[key]), [1, 2, 3], Array.isArray([1, 2, 3]))
|
|
20
|
+
if (typeof t[key] === 'object') {
|
|
21
|
+
// console.log("this is tsi object", key)
|
|
22
|
+
const len = Object.keys(t[key]).length;
|
|
23
|
+
const obj = t[key];
|
|
24
|
+
const themeStyle = obj[i % len];
|
|
25
|
+
const k = key;
|
|
26
|
+
return k + `[${i}]` + themeStyle?.base + " " + themeStyle?.decoration;
|
|
27
|
+
}
|
|
28
|
+
else if (Array.isArray(t[key])) {
|
|
29
|
+
// console.log("this is tsi array", key)
|
|
30
|
+
const len = t[key].length;
|
|
31
|
+
const themeStyle = t[key][i % len];
|
|
32
|
+
const k = key;
|
|
33
|
+
return k + `[${i}]` + themeStyle?.base + " " + themeStyle?.decoration;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return ts(t, key);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export const extractValueFromText = (text, attrName) => {
|
|
40
|
+
if (text && text.__html.startsWith(`{${attrName}}`)) {
|
|
41
|
+
return { __html: text.__html.substring(`{${attrName}}`.length) };
|
|
42
|
+
}
|
|
43
|
+
return text;
|
|
44
|
+
};
|
|
18
45
|
export const defaultRowTheme = defaultRowThemeImpl;
|
package/esm/skin/nd-skin.js
CHANGED
|
@@ -118,8 +118,8 @@ export class NdSkinComponentProps {
|
|
|
118
118
|
options;
|
|
119
119
|
lng;
|
|
120
120
|
imageProvider;
|
|
121
|
-
|
|
122
|
-
constructor(rowIndex, componentIndex, content, defaultThemeName, theme, themes, options, lng, imageProvider,
|
|
121
|
+
i18nextTrustedHtmlProvider;
|
|
122
|
+
constructor(rowIndex, componentIndex, content, defaultThemeName, theme, themes, options, lng, imageProvider, i18nextTrustedHtmlProvider) {
|
|
123
123
|
this.rowIndex = rowIndex;
|
|
124
124
|
this.componentIndex = componentIndex;
|
|
125
125
|
this.content = content;
|
|
@@ -129,6 +129,6 @@ export class NdSkinComponentProps {
|
|
|
129
129
|
this.options = options;
|
|
130
130
|
this.lng = lng;
|
|
131
131
|
this.imageProvider = imageProvider;
|
|
132
|
-
this.
|
|
132
|
+
this.i18nextTrustedHtmlProvider = i18nextTrustedHtmlProvider;
|
|
133
133
|
}
|
|
134
134
|
}
|
package/package.json
CHANGED
package/types/bin/manifest.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type ComponentDef = {
|
|
2
2
|
implementation: string;
|
|
3
3
|
themeSchema: string;
|
|
4
4
|
optionsSchema: string;
|
|
5
5
|
defaultThemeFile: string;
|
|
6
6
|
numBlocks: string | number;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export declare class Manifest {
|
|
7
|
+
};
|
|
8
|
+
export type Manifest = {
|
|
10
9
|
moduleName: string;
|
|
11
10
|
moduleDir: string;
|
|
12
|
-
namespace
|
|
11
|
+
namespace?: string;
|
|
13
12
|
components: Map<string, ComponentDef>;
|
|
14
|
-
|
|
15
|
-
}
|
|
13
|
+
};
|
|
@@ -8,12 +8,20 @@ export type NdImageProps = {
|
|
|
8
8
|
title?: string;
|
|
9
9
|
imageStyle?: ImageStyle;
|
|
10
10
|
};
|
|
11
|
+
export type NdTrustedHtml = {
|
|
12
|
+
__html: TrustedHTML;
|
|
13
|
+
};
|
|
11
14
|
export type AsyncFunctionComponent = (props: NdSkinComponentProps) => Promise<JSX.Element>;
|
|
12
15
|
export type ComponentResolver = (componentName: string) => Promise<{
|
|
13
16
|
compo: AsyncFunctionComponent;
|
|
14
17
|
compoDef: NdComponentDefinition;
|
|
15
18
|
}>;
|
|
16
|
-
export type
|
|
19
|
+
export type NdI18nextProvider = (lng: string) => Promise<{
|
|
17
20
|
t: (text: NdTranslatableText) => string;
|
|
18
21
|
}>;
|
|
19
|
-
export type
|
|
22
|
+
export type NdI18nextTrustedHtmlProvider = (lng: string) => Promise<{
|
|
23
|
+
t: (text: NdTranslatableText) => NdTrustedHtml;
|
|
24
|
+
}>;
|
|
25
|
+
export type NdImageProvider = (imageProps: NdImageProps) => Promise<JSX.Element>;
|
|
26
|
+
export type NdI18NextPostProcessor = (text: string) => string;
|
|
27
|
+
export type NdHtmlSanitizer = (text: string) => NdTrustedHtml;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { ComponentResolver,
|
|
1
|
+
import { ComponentResolver, NdI18nextProvider, NdImageProvider } from "./providers";
|
|
2
2
|
import { NdContentBlock } from "../content/nd-content";
|
|
3
3
|
import { NdPageSkin } from "../skin/nd-skin";
|
|
4
|
+
import { NdI18NextPostProcessor } from "./providers";
|
|
5
|
+
import { NdHtmlSanitizer } from "./providers";
|
|
4
6
|
export declare enum RenderingPriority {
|
|
5
7
|
content_first = 0,
|
|
6
8
|
skin_first = 1
|
|
@@ -11,7 +13,9 @@ export declare class RenderingPageProps {
|
|
|
11
13
|
skin: NdPageSkin | undefined;
|
|
12
14
|
renderingPriority: RenderingPriority;
|
|
13
15
|
componentResolver: ComponentResolver | undefined;
|
|
14
|
-
imageProvider:
|
|
15
|
-
i18nextProvider:
|
|
16
|
-
|
|
16
|
+
imageProvider: NdImageProvider | undefined;
|
|
17
|
+
i18nextProvider: NdI18nextProvider | undefined;
|
|
18
|
+
i18nextPostProcessor: NdI18NextPostProcessor | undefined;
|
|
19
|
+
htmlSanitizer: NdHtmlSanitizer | undefined;
|
|
20
|
+
constructor(lng: string, content: NdContentBlock[], componentResolver: ComponentResolver | undefined, skin?: NdPageSkin | undefined, renderingPriority?: RenderingPriority, imageProvider?: NdImageProvider | undefined, i18nextProvider?: NdI18nextProvider | undefined, htmlSanitizer?: NdHtmlSanitizer | undefined);
|
|
17
21
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -2,18 +2,20 @@ import { NdContentImage, NdTranslatableText, NdList, NdCode, NdCallToAction, NdC
|
|
|
2
2
|
import { NdSkinComponent, NdRow, NdPageSkin, NdSkinComponentProps, NdContentSelector, NdComponentDefinition, NdThemeHierarchy, NdDefaultThemeName } from "./skin/nd-skin";
|
|
3
3
|
import { RenderingPageProps, RenderingPriority } from "./core/rendering-page-props";
|
|
4
4
|
import { RenderingPage } from "./core/rendering-page";
|
|
5
|
-
import {
|
|
5
|
+
import { NdI18nextProvider, AsyncFunctionComponent, NdImageProvider, NdImageProps, NdI18nextTrustedHtmlProvider, NdHtmlSanitizer, NdTrustedHtml, NdI18NextPostProcessor } from "./core/providers";
|
|
6
6
|
import { mergeTheme } from "./theme-utils/theme-merger";
|
|
7
7
|
import { ThemeStyle } from "./theme-utils/theme-style";
|
|
8
8
|
import { ExtendedThemeStyle } from "./theme-utils/extended-theme-style";
|
|
9
9
|
import { ImageStyle } from "./theme-utils/image-style";
|
|
10
10
|
import { RowStyle } from "./theme-utils/row-style";
|
|
11
|
-
export { NdContentImage, NdTranslatableText, NdList, NdCode, NdCallToAction, NdContentBlock, NdSkinComponent, NdRow, NdPageSkin, NdSkinComponentProps, NdContentSelector, NdComponentDefinition, NdThemeHierarchy, type NdDefaultThemeName, type NdImageProps };
|
|
11
|
+
export { NdContentImage, NdTranslatableText, NdList, NdCode, NdCallToAction, NdContentBlock, NdSkinComponent, NdRow, NdPageSkin, NdSkinComponentProps, NdContentSelector, NdComponentDefinition, NdThemeHierarchy, type NdDefaultThemeName, type NdImageProps, type NdI18nextTrustedHtmlProvider, type NdHtmlSanitizer, type NdTrustedHtml, type NdI18NextPostProcessor };
|
|
12
12
|
export { RenderingPageProps, RenderingPriority, RenderingPage };
|
|
13
13
|
export { mergeTheme, type ThemeStyle, type ExtendedThemeStyle, type ImageStyle };
|
|
14
|
-
export type {
|
|
14
|
+
export type { NdI18nextProvider, AsyncFunctionComponent, NdImageProvider };
|
|
15
15
|
export { DummyComp } from "./core/dummy-comp";
|
|
16
16
|
export { contentMarkdownProvider, parseMarkdownAsContent } from "./providers/content/content-markdown-provider";
|
|
17
17
|
export { skinYamlProvider, parseYamlContentAsSkin } from "./providers/skin/skin-yaml-provider";
|
|
18
18
|
export declare const ts: <T>(t: T, key: keyof T) => string;
|
|
19
|
+
export declare const tsi: <T>(t: T, key: keyof T, i: number) => string;
|
|
20
|
+
export declare const extractValueFromText: (text: NdTrustedHtml | undefined, attrName: string) => NdTrustedHtml | undefined;
|
|
19
21
|
export declare const defaultRowTheme: RowStyle;
|
package/types/skin/nd-skin.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NdImageProvider } from "../core/providers";
|
|
2
2
|
import { NdContentBlock } from "../content/nd-content";
|
|
3
3
|
import { ThemeStyle } from "../theme-utils/theme-style";
|
|
4
4
|
import { RowStyle } from "../theme-utils/row-style";
|
|
5
|
+
import { NdI18nextTrustedHtmlProvider } from "../core/providers";
|
|
5
6
|
export type NdDefaultThemeName = "light" | "dark";
|
|
6
7
|
export declare class NdThemeHierarchy {
|
|
7
8
|
defaultThemeName: NdDefaultThemeName;
|
|
@@ -69,7 +70,7 @@ export declare class NdSkinComponentProps<TComponentTheme = any, TComponentOptio
|
|
|
69
70
|
themes: TComponentTheme[];
|
|
70
71
|
options: TComponentOptions | undefined;
|
|
71
72
|
lng: string;
|
|
72
|
-
imageProvider:
|
|
73
|
-
|
|
74
|
-
constructor(rowIndex: number, componentIndex: number, content: NdContentBlock[], defaultThemeName: NdDefaultThemeName, theme: TComponentTheme, themes: TComponentTheme[], options: TComponentOptions, lng: string, imageProvider:
|
|
73
|
+
imageProvider: NdImageProvider;
|
|
74
|
+
i18nextTrustedHtmlProvider: NdI18nextTrustedHtmlProvider;
|
|
75
|
+
constructor(rowIndex: number, componentIndex: number, content: NdContentBlock[], defaultThemeName: NdDefaultThemeName, theme: TComponentTheme, themes: TComponentTheme[], options: TComponentOptions, lng: string, imageProvider: NdImageProvider, i18nextTrustedHtmlProvider: NdI18nextTrustedHtmlProvider);
|
|
75
76
|
}
|