Page MenuHomeSealhub

index.ts
No OneTemporary

index.ts

import { tempstream } from "tempstream";
import { JDDContext } from "./jdd-context";
import { Registry } from "./registry";
export * from "./component";
export * from "./component-arguments/component-argument";
export * from "./component-arguments/component-arguments"; // exporting this also as root elements to make it easier to auto-import those
export * as ComponentArguments from "./component-arguments/component-arguments";
export * from "./jdd-context";
export * from "./registry";
export { insert_nbsp } from "./utils/insert_nbsp";
export type JDDocument = Array<{
component_name: string;
args: Record<string, unknown>;
}>;
export function countWords(registry: Registry, document: JDDocument): number {
return document.reduce((acc, { component_name, args }) => {
const component = registry.get(component_name);
if (!component) {
console.warn(
"Component not found in the registry: " + component_name
);
return acc + 0;
}
return acc + component.countWords(args);
}, 0);
}
export function render(
registry: Registry,
document: JDDocument,
context: JDDContext
) {
return tempstream`${document.map(({ component_name, args }) => {
const component = registry.get(component_name);
if (!component) {
console.warn(
"Component not found in the registry: " + component_name
);
return "";
}
for (const arg_name in component?.getArguments()) {
if (!Object.prototype.hasOwnProperty.call(args, arg_name)) {
args[arg_name] = component
?.getArguments()
[arg_name]?.getEmptyValue();
}
}
return component.toHTML(args, context);
})}`;
}

File Metadata

Mime Type
text/x-java
Expires
Fri, Jan 24, 15:15 (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
600500
Default Alt Text
index.ts (1 KB)

Event Timeline