@sealcode/jdd 0.5.5 → 0.6.0-alpha
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/@types/component-arguments/markdown.d.ts +2 -0
- package/@types/component.d.ts +6 -0
- package/@types/components/markdown.d.ts +9 -0
- package/@types/index.d.ts +1 -8
- package/@types/jdd.d.ts +18 -0
- package/@types/jdd.test.d.ts +1 -0
- package/@types/test-utils/simplest-context.d.ts +1 -0
- package/lib/component-arguments/markdown.js +12 -0
- package/lib/component-arguments/markdown.js.map +1 -1
- package/lib/component.js +10 -0
- package/lib/component.js.map +1 -1
- package/lib/components/markdown.js +3 -0
- package/lib/components/markdown.js.map +1 -1
- package/lib/components/markdown.test.js +31 -3
- package/lib/components/markdown.test.js.map +1 -1
- package/lib/index.js +1 -109
- package/lib/index.js.map +1 -1
- package/lib/jdd-context.js +14 -1
- package/lib/jdd-context.js.map +1 -1
- package/lib/jdd.js +133 -0
- package/lib/jdd.js.map +1 -0
- package/lib/jdd.test.js +39 -0
- package/lib/jdd.test.js.map +1 -0
- package/lib/render.test.js +11 -5
- package/lib/render.test.js.map +1 -1
- package/lib/test-utils/simplest-context.js +6 -0
- package/lib/test-utils/simplest-context.js.map +1 -0
- package/package.json +3 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { JDDContext } from "../jdd-context.js";
|
|
2
2
|
import { MaybePromise } from "../utils/util-types.js";
|
|
3
3
|
import { StringBasedArgument } from "./string-based-argument.js";
|
|
4
|
+
import { JDDHeading } from "../component.js";
|
|
4
5
|
export declare class MarkdownArgument extends StringBasedArgument<string> {
|
|
5
6
|
getTypeName(): string;
|
|
6
7
|
getEmptyValue(): string;
|
|
7
8
|
countWords(value: string): number;
|
|
8
9
|
example_values: string[];
|
|
9
10
|
parseFormInput(_: JDDContext, input: unknown): MaybePromise<string | string[] | null>;
|
|
11
|
+
extractHeadings(value: string): JDDHeading[];
|
|
10
12
|
}
|
package/@types/component.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ export type EarlyAsset = ({
|
|
|
13
13
|
}) & {
|
|
14
14
|
identity: string;
|
|
15
15
|
};
|
|
16
|
+
export type JDDHeading = {
|
|
17
|
+
text: string;
|
|
18
|
+
level: number;
|
|
19
|
+
id?: string;
|
|
20
|
+
};
|
|
16
21
|
export type ComponentToHTMLArgs<T extends Record<string, ComponentArgument<unknown>>> = {
|
|
17
22
|
args: ExtractStructuredComponentArgumentsParsed<T>;
|
|
18
23
|
classes: string[];
|
|
@@ -23,6 +28,7 @@ export declare abstract class Component<ArgumentsT extends Record<string, Compon
|
|
|
23
28
|
abstract getArguments(): ArgumentsT;
|
|
24
29
|
abstract toHTML(params: ComponentToHTMLArgs<ArgumentsT>): FlatTemplatable | Promise<FlatTemplatable>;
|
|
25
30
|
getTitle(context: JDDContext, args: ExtractStructuredComponentArgumentsParsed<ArgumentsT>): string | null;
|
|
31
|
+
getHeadings(context: JDDContext, args: ExtractStructuredComponentArgumentsParsed<ArgumentsT>): JDDHeading[];
|
|
26
32
|
getEarlyAssets(_args: ExtractStructuredComponentArgumentsParsed<ArgumentsT>, _context: JDDContext): Promise<EarlyAsset[]>;
|
|
27
33
|
countWords(args: Record<string, unknown>): number;
|
|
28
34
|
getExampleValues(context: JDDContext): Promise<ExtractStructuredComponentArgumentsParsed<ArgumentsT>>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FlatTemplatable } from "tempstream";
|
|
2
2
|
import { Component, ComponentToHTMLArgs } from "../component.js";
|
|
3
3
|
import { MarkdownArgument } from "../component-arguments/markdown.js";
|
|
4
|
+
import { ExtractStructuredComponentArgumentsParsed } from "../index.js";
|
|
5
|
+
import { JDDContext } from "../jdd-context.js";
|
|
4
6
|
declare const component_arguments: {
|
|
5
7
|
readonly markdown: MarkdownArgument;
|
|
6
8
|
};
|
|
@@ -9,5 +11,12 @@ export declare class Markdown extends Component<typeof component_arguments> {
|
|
|
9
11
|
readonly markdown: MarkdownArgument;
|
|
10
12
|
};
|
|
11
13
|
toHTML({ args: { markdown }, classes, jdd_context: { render_markdown, language }, }: ComponentToHTMLArgs<typeof component_arguments>): FlatTemplatable;
|
|
14
|
+
getHeadings(context: JDDContext, args: ExtractStructuredComponentArgumentsParsed<{
|
|
15
|
+
readonly markdown: MarkdownArgument;
|
|
16
|
+
}>): {
|
|
17
|
+
text: string;
|
|
18
|
+
level: number;
|
|
19
|
+
id?: string | undefined;
|
|
20
|
+
}[];
|
|
12
21
|
}
|
|
13
22
|
export {};
|
package/@types/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { JDDContext } from "./jdd-context.js";
|
|
2
|
-
import { Registry } from "./registry.js";
|
|
3
|
-
import { JDDocumentContainer, RawJDDocument } from "./document.js";
|
|
4
1
|
export * from "./component.js";
|
|
5
2
|
export * from "./component-arguments/component-argument.js";
|
|
6
3
|
export * as ComponentArguments from "./component-arguments/component-arguments.js";
|
|
@@ -9,8 +6,4 @@ export * from "./jdd-context.js";
|
|
|
9
6
|
export * from "./registry.js";
|
|
10
7
|
export { insert_nbsp } from "./utils/insert_nbsp.js";
|
|
11
8
|
export * from "./document.js";
|
|
12
|
-
export
|
|
13
|
-
export declare function renderEarlyAssets(registry: Registry, document_container: JDDocumentContainer<"parsed">, context: JDDContext): Promise<string>;
|
|
14
|
-
export declare function renderEarlyAssetsFromStorage(registry: Registry, document: RawJDDocument, jdd_context: JDDContext): Promise<string>;
|
|
15
|
-
export declare function render(registry: Registry, document: JDDocumentContainer<"parsed">, context: JDDContext, make_component_classes?: (index: number) => string[]): Promise<string>;
|
|
16
|
-
export declare function renderFromStorage(registry: Registry, document: RawJDDocument, jdd_context: JDDContext): Promise<string>;
|
|
9
|
+
export * from "./jdd.js";
|
package/@types/jdd.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { JDDContext } from "./jdd-context.js";
|
|
2
|
+
import { Registry } from "./registry.js";
|
|
3
|
+
import { EarlyAsset, JDDHeading } from "./component.js";
|
|
4
|
+
import { JDDocumentContainer, RawJDDocument } from "./document.js";
|
|
5
|
+
export declare class JDD {
|
|
6
|
+
registry: Registry;
|
|
7
|
+
jdd_context: JDDContext;
|
|
8
|
+
parsed: JDDocumentContainer<"parsed">;
|
|
9
|
+
constructor(registry: Registry, jdd_context: JDDContext, parsed: JDDocumentContainer<"parsed">);
|
|
10
|
+
static fromStorage(registry: Registry, jdd_context: JDDContext, document: RawJDDocument): Promise<JDD>;
|
|
11
|
+
static fromParsed(registry: Registry, jdd_context: JDDContext, parsed: RawJDDocument): JDD;
|
|
12
|
+
render(make_component_classes?: (index: number) => string[]): Promise<string>;
|
|
13
|
+
renderEarlyScript(asset: EarlyAsset): string;
|
|
14
|
+
renderEarlyStyle(asset: EarlyAsset): string;
|
|
15
|
+
renderEarlyAssets(registry: Registry, document_container: JDDocumentContainer<"parsed">, context: JDDContext): Promise<string>;
|
|
16
|
+
countWords(registry: Registry): number;
|
|
17
|
+
getHeadings(): JDDHeading[];
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function simplestContext(): import("../jdd-context.js").JDDContext;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { is, predicates } from "@sealcode/ts-predicates";
|
|
2
2
|
import { StringBasedArgument } from "./string-based-argument.js";
|
|
3
|
+
import { marked } from "marked";
|
|
4
|
+
import slug from "slug";
|
|
3
5
|
export class MarkdownArgument extends StringBasedArgument {
|
|
4
6
|
constructor() {
|
|
5
7
|
super(...arguments);
|
|
@@ -31,5 +33,15 @@ Pulvinar neque laoreet suspendisse interdum consectetur. Orci phasellus egestas
|
|
|
31
33
|
return null;
|
|
32
34
|
}
|
|
33
35
|
}
|
|
36
|
+
extractHeadings(value) {
|
|
37
|
+
return marked
|
|
38
|
+
.lexer(value)
|
|
39
|
+
.filter((t) => t.type == "heading")
|
|
40
|
+
.map((t) => ({
|
|
41
|
+
text: t.text,
|
|
42
|
+
level: t.depth,
|
|
43
|
+
slug: slug(t.text),
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
34
46
|
}
|
|
35
47
|
//# sourceMappingURL=markdown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/component-arguments/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,MAAM,OAAO,gBAAiB,SAAQ,mBAA2B;IAAjE;;QAaC,mBAAc,GAAG;YAChB;;oaAEka;YACla;;;;sGAIoG;SACpG,CAAC;
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/component-arguments/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,OAAO,gBAAiB,SAAQ,mBAA2B;IAAjE;;QAaC,mBAAc,GAAG;YAChB;;oaAEka;YACla;;;;sGAIoG;SACpG,CAAC;IAuBH,CAAC;IA5CA,WAAW;QACV,OAAO,UAAU,CAAC;IACnB,CAAC;IAED,aAAa;QACZ,OAAO,EAAE,CAAC;IACX,CAAC;IAED,UAAU,CAAC,KAAa;QACvB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,CAAC;IAaD,cAAc,CACb,CAAa,EACb,KAAc;QAEd,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE;YACjC,OAAO,KAAK,CAAC;SACb;aAAM;YACN,OAAO,IAAI,CAAC;SACZ;IACF,CAAC;IAED,eAAe,CAAC,KAAa;QAC5B,OAAO,MAAM;aACX,KAAK,CAAC,KAAK,CAAC;aACZ,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,SAAS,CAAC;aAClC,GAAG,CAAC,CAAC,CAAiB,EAAE,EAAE,CAAC,CAAC;YAC5B,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;SAClB,CAAC,CAAC,CAAC;IACN,CAAC;CACD"}
|
package/lib/component.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
import slug from "slug";
|
|
1
2
|
export class Component {
|
|
2
3
|
getTitle(context, args) {
|
|
3
4
|
return null;
|
|
4
5
|
}
|
|
6
|
+
getHeadings(context, args) {
|
|
7
|
+
const title = this.getTitle(context, args);
|
|
8
|
+
if (title) {
|
|
9
|
+
return [{ text: title, level: 1, id: slug(title) }];
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
5
15
|
async getEarlyAssets(_args, _context) {
|
|
6
16
|
return [];
|
|
7
17
|
}
|
package/lib/component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAQA,OAAO,IAAI,MAAM,MAAM,CAAC;AA2BxB,MAAM,OAAgB,SAAS;IAW9B,QAAQ,CACP,OAAmB,EACnB,IAA2D;QAE3D,OAAO,IAAI,CAAC;IACb,CAAC;IAED,WAAW,CACV,OAAmB,EACnB,IAA2D;QAE3D,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,OA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":"markdown.js","sourceRoot":"","sources":["../../src/components/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,UAAU,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,SAAS,EAAuB,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAItE,MAAM,mBAAmB,GAAG,EAAE,QAAQ,EAAE,IAAI,gBAAgB,EAAE,EAAW,CAAC;AAE1E,MAAM,OAAO,QAAS,SAAQ,SAAqC;IAClE,YAAY;QACX,OAAO,mBAAmB,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,EACN,IAAI,EAAE,EAAE,QAAQ,EAAE,EAClB,OAAO,EACP,WAAW,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAE,GACO;QACjD,OAAO,UAAU,CAAA,mBAAmB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;MACjD,eAAe,CAAC,QAAQ,EAAE,QAAQ,CAAC;cAC3B,CAAC;IACd,CAAC;IAED,WAAW,CACV,OAAmB,EACnB,IAEE;QAEF,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpE,CAAC;CACD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { JDD } from "../jdd.js";
|
|
1
2
|
import { Registry } from "../registry.js";
|
|
2
3
|
import { Markdown } from "./markdown.js";
|
|
3
|
-
import { documentContainerFromParsed, makeSimpleEnglishJDDContext,
|
|
4
|
+
import { documentContainerFromParsed, makeSimpleEnglishJDDContext, } from "../index.js";
|
|
4
5
|
import assert from "assert";
|
|
5
6
|
import { FileManager } from "@sealcode/file-manager";
|
|
6
7
|
import { formatWithPrettier } from "../test-utils/prettier.js";
|
|
@@ -15,16 +16,43 @@ describe("markdown component", () => {
|
|
|
15
16
|
]);
|
|
16
17
|
const registry = new Registry();
|
|
17
18
|
registry.add("markdown", Markdown);
|
|
18
|
-
const result = await
|
|
19
|
+
const result = await new JDD(registry, makeSimpleEnglishJDDContext(new FileManager("/tmp", "/uploaded_files")), document).render();
|
|
19
20
|
assert.strictEqual(await formatWithPrettier(result, "html"),
|
|
20
21
|
// note the soft hyphens
|
|
21
22
|
await formatWithPrettier(
|
|
22
23
|
/* HTML */ `<section class="jdd-component component-number-0">
|
|
23
|
-
<h1
|
|
24
|
+
<h1 id="hello-world">
|
|
25
|
+
<a class="anchor" href="#hello-world">
|
|
26
|
+
<span class="markdown-header-link"></span>
|
|
27
|
+
</a>
|
|
28
|
+
Hello World
|
|
29
|
+
</h1>
|
|
24
30
|
</section>
|
|
25
31
|
<section class="jdd-component component-number-1">
|
|
26
32
|
<p>Multiple components ftw</p>
|
|
27
33
|
</section>`, "html"));
|
|
28
34
|
});
|
|
35
|
+
it("properly returns the headings", () => {
|
|
36
|
+
const headings = new Markdown().getHeadings(makeSimpleEnglishJDDContext(new FileManager("/tmp", "/uploaded_files")), {
|
|
37
|
+
markdown: `# Heading level 1
|
|
38
|
+
|
|
39
|
+
some content
|
|
40
|
+
|
|
41
|
+
## Heading level 2
|
|
42
|
+
|
|
43
|
+
some content as well
|
|
44
|
+
|
|
45
|
+
# Another heading level 1`,
|
|
46
|
+
});
|
|
47
|
+
assert.deepStrictEqual(headings, [
|
|
48
|
+
{ text: "Heading level 1", level: 1, slug: "heading-level-1" },
|
|
49
|
+
{ text: "Heading level 2", level: 2, slug: "heading-level-2" },
|
|
50
|
+
{
|
|
51
|
+
text: "Another heading level 1",
|
|
52
|
+
level: 1,
|
|
53
|
+
slug: "another-heading-level-1",
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
56
|
+
});
|
|
29
57
|
});
|
|
30
58
|
//# sourceMappingURL=markdown.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.test.js","sourceRoot":"","sources":["../../src/components/markdown.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,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AAC;QACxC,wBAAwB;QACxB,MAAM,kBAAkB;QACvB,UAAU,CAAC;;;;;;;;;;gBAUC,EACZ,MAAM,CACN,CACD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACxC,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC,WAAW,CAC1C,2BAA2B,CAC1B,IAAI,WAAW,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAC1C,EACD;YACC,QAAQ,EAAE;;;;;;;;0BAQY;SACtB,CACD,CAAC;QACF,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE;YAChC,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE;YAC9D,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE;YAC9D;gBACC,IAAI,EAAE,yBAAyB;gBAC/B,KAAK,EAAE,CAAC;gBACR,IAAI,EAAE,yBAAyB;aAC/B;SACD,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { tempstream } from "tempstream";
|
|
2
|
-
import { hasField } from "@sealcode/ts-predicates";
|
|
3
|
-
import { documentContainerFromStorage, } from "./document.js";
|
|
4
|
-
import { documentToParsed } from "./document.js";
|
|
5
1
|
export * from "./component.js";
|
|
6
2
|
export * from "./component-arguments/component-argument.js";
|
|
7
3
|
export * as ComponentArguments from "./component-arguments/component-arguments.js";
|
|
@@ -10,109 +6,5 @@ export * from "./jdd-context.js";
|
|
|
10
6
|
export * from "./registry.js";
|
|
11
7
|
export { insert_nbsp } from "./utils/insert_nbsp.js";
|
|
12
8
|
export * from "./document.js";
|
|
13
|
-
export
|
|
14
|
-
return document_container.value.reduce((acc, { component_name, args }) => {
|
|
15
|
-
const component = registry.get(component_name);
|
|
16
|
-
if (!component) {
|
|
17
|
-
console.warn("Component not found in the registry: " + component_name);
|
|
18
|
-
return acc + 0;
|
|
19
|
-
}
|
|
20
|
-
return acc + component.countWords(args);
|
|
21
|
-
}, 0);
|
|
22
|
-
}
|
|
23
|
-
export async function renderEarlyAssets(registry, document_container, context) {
|
|
24
|
-
const early_assets = (await Promise.all(document_container.value.map(async ({ component_name, args }) => {
|
|
25
|
-
const component = registry.get(component_name);
|
|
26
|
-
if (!component) {
|
|
27
|
-
console.warn("Component not found in the registry: " + component_name);
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
for (const arg_name in component?.getArguments()) {
|
|
31
|
-
if (!Object.prototype.hasOwnProperty.call(args, arg_name)) {
|
|
32
|
-
args[arg_name] = component
|
|
33
|
-
?.getArguments()[arg_name]?.getEmptyValue(context);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return await component.getEarlyAssets(args, context);
|
|
37
|
-
}))).flat();
|
|
38
|
-
const deduplicated_assets = {};
|
|
39
|
-
for (const asset of early_assets) {
|
|
40
|
-
deduplicated_assets[asset.identity] = asset;
|
|
41
|
-
}
|
|
42
|
-
return Object.values(deduplicated_assets)
|
|
43
|
-
.map((asset) => {
|
|
44
|
-
if (asset.type == "script") {
|
|
45
|
-
if (hasField("url", asset)) {
|
|
46
|
-
return /* HTML */ `<script
|
|
47
|
-
async
|
|
48
|
-
src="${asset.url}"
|
|
49
|
-
onLoad="document.dispatchEvent(new Event('loaded-${asset.identity}'))"
|
|
50
|
-
${(asset.integrity &&
|
|
51
|
-
`integrity="${asset.integrity}" crossorigin="anonymous"`) ||
|
|
52
|
-
""}
|
|
53
|
-
></script>`;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
return /* HTML */ `<script><${asset.content}/script>`;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else if (asset.type == "style") {
|
|
60
|
-
if (hasField("url", asset)) {
|
|
61
|
-
const integrity = (asset.integrity &&
|
|
62
|
-
`integrity="${asset.integrity}" crossorigin="anonymous"`) ||
|
|
63
|
-
"";
|
|
64
|
-
// see https://web.dev/articles/defer-non-critical-css
|
|
65
|
-
return /* HTML */ `<link
|
|
66
|
-
rel="preload"
|
|
67
|
-
href="${asset.url}"
|
|
68
|
-
as="style"
|
|
69
|
-
onload="this.onload=null;this.rel='stylesheet'"
|
|
70
|
-
${integrity}
|
|
71
|
-
/>
|
|
72
|
-
<noscript
|
|
73
|
-
><link
|
|
74
|
-
rel="stylesheet"
|
|
75
|
-
href="${asset.url}"
|
|
76
|
-
${integrity}
|
|
77
|
-
/></noscript>`;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
return /* HTML */ `<style>
|
|
81
|
-
${asset.content}
|
|
82
|
-
</style>`;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
.join(" ");
|
|
87
|
-
}
|
|
88
|
-
export async function renderEarlyAssetsFromStorage(registry, document, jdd_context) {
|
|
89
|
-
return renderEarlyAssets(registry, await documentToParsed(registry, jdd_context, documentContainerFromStorage(document)), jdd_context);
|
|
90
|
-
}
|
|
91
|
-
export function render(registry, document, context, make_component_classes = (index) => [
|
|
92
|
-
"jdd-component",
|
|
93
|
-
`component-number-${index}`,
|
|
94
|
-
]) {
|
|
95
|
-
return tempstream `${document.value.map(({ component_name, args }, index) => {
|
|
96
|
-
const component = registry.get(component_name);
|
|
97
|
-
if (!component) {
|
|
98
|
-
console.warn("Component not found in the registry: " + component_name);
|
|
99
|
-
return "";
|
|
100
|
-
}
|
|
101
|
-
for (const arg_name in component?.getArguments()) {
|
|
102
|
-
if (!Object.prototype.hasOwnProperty.call(args, arg_name)) {
|
|
103
|
-
args[arg_name] = component
|
|
104
|
-
?.getArguments()[arg_name]?.getEmptyValue(context);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return component.toHTML({
|
|
108
|
-
args,
|
|
109
|
-
classes: make_component_classes(index),
|
|
110
|
-
jdd_context: context,
|
|
111
|
-
index,
|
|
112
|
-
});
|
|
113
|
-
})}`;
|
|
114
|
-
}
|
|
115
|
-
export async function renderFromStorage(registry, document, jdd_context) {
|
|
116
|
-
return render(registry, await documentToParsed(registry, jdd_context, documentContainerFromStorage(document)), jdd_context);
|
|
117
|
-
}
|
|
9
|
+
export * from "./jdd.js";
|
|
118
10
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6CAA6C,CAAC;AAC5D,OAAO,KAAK,kBAAkB,MAAM,8CAA8C,CAAC;AACnF,cAAc,8CAA8C,CAAC,CAAC,8EAA8E;AAC5I,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC"}
|
package/lib/jdd-context.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import { marked } from "marked";
|
|
1
|
+
import { Renderer, marked } from "marked";
|
|
2
2
|
import { insert_nbsp } from "./utils/insert_nbsp.js";
|
|
3
3
|
import { get_hyphenator } from "./hyphenation.js";
|
|
4
|
+
import slug from "slug";
|
|
5
|
+
class RendererWithHeadings extends Renderer {
|
|
6
|
+
heading(text, depth) {
|
|
7
|
+
const id = slug(text);
|
|
8
|
+
return /* HTML */ ` <h${depth} id="${id}">
|
|
9
|
+
<a class="anchor" href="#${id}">
|
|
10
|
+
<span class="markdown-header-link"></span>
|
|
11
|
+
</a>
|
|
12
|
+
${text}
|
|
13
|
+
</h${depth}>`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
4
16
|
export const makeSimpleJDDContext = (file_manager) => ({
|
|
5
17
|
render_image: async (file) => {
|
|
6
18
|
if (typeof file == "string") {
|
|
@@ -22,6 +34,7 @@ export const makeSimpleJDDContext = (file_manager) => ({
|
|
|
22
34
|
token.text = hyphenator(token.text);
|
|
23
35
|
}
|
|
24
36
|
},
|
|
37
|
+
renderer: new RendererWithHeadings(),
|
|
25
38
|
})
|
|
26
39
|
: "";
|
|
27
40
|
},
|
package/lib/jdd-context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jdd-context.js","sourceRoot":"","sources":["../src/jdd-context.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"jdd-context.js","sourceRoot":"","sources":["../src/jdd-context.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,IAAI,MAAM,MAAM,CAAC;AAexB,MAAM,oBAAqB,SAAQ,QAAQ;IAC1C,OAAO,CAAC,IAAY,EAAE,KAAa;QAClC,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,OAAO,UAAU,CAAC,MAAM,KAAK,QAAQ,EAAE;+BACV,EAAE;;;MAG3B,IAAI;QACF,KAAK,GAAG,CAAC;IAChB,CAAC;CACD;AAED,MAAM,CAAC,MAAM,oBAAoB,GAEG,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IACtD,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAC5B,IAAI,OAAO,IAAI,IAAI,QAAQ,EAAE;YAC5B,IAAI,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;SAC1C;QACD,MA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ACrC,QAAQ,EAAE,OAAO;CACjB,CAAC,CAAC"}
|
package/lib/jdd.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { tempstream } from "tempstream";
|
|
2
|
+
import { hasField } from "@sealcode/ts-predicates";
|
|
3
|
+
import { documentContainerFromParsed, documentContainerFromStorage, } from "./document.js";
|
|
4
|
+
import { documentToParsed } from "./document.js";
|
|
5
|
+
export class JDD {
|
|
6
|
+
constructor(registry, jdd_context, parsed) {
|
|
7
|
+
this.registry = registry;
|
|
8
|
+
this.jdd_context = jdd_context;
|
|
9
|
+
this.parsed = parsed;
|
|
10
|
+
}
|
|
11
|
+
static async fromStorage(registry, jdd_context, document) {
|
|
12
|
+
const parsed = await documentToParsed(registry, jdd_context, documentContainerFromStorage(document));
|
|
13
|
+
return new JDD(registry, jdd_context, parsed);
|
|
14
|
+
}
|
|
15
|
+
static fromParsed(registry, jdd_context, parsed) {
|
|
16
|
+
return new JDD(registry, jdd_context, documentContainerFromParsed(parsed));
|
|
17
|
+
}
|
|
18
|
+
render(make_component_classes = (index) => [
|
|
19
|
+
"jdd-component",
|
|
20
|
+
`component-number-${index}`,
|
|
21
|
+
]) {
|
|
22
|
+
return tempstream `${this.parsed.value.map(({ component_name, args }, index) => {
|
|
23
|
+
const component = this.registry.get(component_name);
|
|
24
|
+
if (!component) {
|
|
25
|
+
console.warn("Component not found in the registry: " + component_name);
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
for (const arg_name in component?.getArguments()) {
|
|
29
|
+
if (!Object.prototype.hasOwnProperty.call(args, arg_name)) {
|
|
30
|
+
args[arg_name] = component
|
|
31
|
+
?.getArguments()[arg_name]?.getEmptyValue(this.jdd_context);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return component.toHTML({
|
|
35
|
+
args,
|
|
36
|
+
classes: make_component_classes(index),
|
|
37
|
+
jdd_context: this.jdd_context,
|
|
38
|
+
index,
|
|
39
|
+
});
|
|
40
|
+
})}`;
|
|
41
|
+
}
|
|
42
|
+
renderEarlyScript(asset) {
|
|
43
|
+
if (hasField("url", asset)) {
|
|
44
|
+
return /* HTML */ `<script
|
|
45
|
+
async
|
|
46
|
+
src="${asset.url}"
|
|
47
|
+
onLoad="document.dispatchEvent(new Event('loaded-${asset.identity}'))"
|
|
48
|
+
${(asset.integrity &&
|
|
49
|
+
`integrity="${asset.integrity}" crossorigin="anonymous"`) ||
|
|
50
|
+
""}
|
|
51
|
+
></script>`;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return /* HTML */ `<script><${asset.content}/script>`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
renderEarlyStyle(asset) {
|
|
58
|
+
if (hasField("url", asset)) {
|
|
59
|
+
const integrity = (asset.integrity &&
|
|
60
|
+
`integrity="${asset.integrity}" crossorigin="anonymous"`) ||
|
|
61
|
+
"";
|
|
62
|
+
// see https://web.dev/articles/defer-non-critical-css
|
|
63
|
+
return /* HTML */ `<link
|
|
64
|
+
rel="preload"
|
|
65
|
+
href="${asset.url}"
|
|
66
|
+
as="style"
|
|
67
|
+
onload="this.onload=null;this.rel='stylesheet'"
|
|
68
|
+
${integrity}
|
|
69
|
+
/>
|
|
70
|
+
<noscript
|
|
71
|
+
><link rel="stylesheet" href="${asset.url}" ${integrity}
|
|
72
|
+
/></noscript>`;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return /* HTML */ `<style>
|
|
76
|
+
${asset.content}
|
|
77
|
+
</style>`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async renderEarlyAssets(registry, document_container, context) {
|
|
81
|
+
const early_assets = (await Promise.all(document_container.value.map(async ({ component_name, args }) => {
|
|
82
|
+
const component = registry.get(component_name);
|
|
83
|
+
if (!component) {
|
|
84
|
+
console.warn("Component not found in the registry: " +
|
|
85
|
+
component_name);
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
for (const arg_name in component?.getArguments()) {
|
|
89
|
+
if (!Object.prototype.hasOwnProperty.call(args, arg_name)) {
|
|
90
|
+
args[arg_name] = component
|
|
91
|
+
?.getArguments()[arg_name]?.getEmptyValue(context);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return await component.getEarlyAssets(args, context);
|
|
95
|
+
}))).flat();
|
|
96
|
+
const deduplicated_assets = {};
|
|
97
|
+
for (const asset of early_assets) {
|
|
98
|
+
deduplicated_assets[asset.identity] = asset;
|
|
99
|
+
}
|
|
100
|
+
return Object.values(deduplicated_assets)
|
|
101
|
+
.map((asset) => {
|
|
102
|
+
if (asset.type == "script") {
|
|
103
|
+
return this.renderEarlyScript(asset);
|
|
104
|
+
}
|
|
105
|
+
else if (asset.type == "style") {
|
|
106
|
+
this.renderEarlyStyle(asset);
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
.join(" ");
|
|
110
|
+
}
|
|
111
|
+
countWords(registry) {
|
|
112
|
+
return this.parsed.value.reduce((acc, { component_name, args }) => {
|
|
113
|
+
const component = registry.get(component_name);
|
|
114
|
+
if (!component) {
|
|
115
|
+
console.warn("Component not found in the registry: " + component_name);
|
|
116
|
+
return acc + 0;
|
|
117
|
+
}
|
|
118
|
+
return acc + component.countWords(args);
|
|
119
|
+
}, 0);
|
|
120
|
+
}
|
|
121
|
+
getHeadings() {
|
|
122
|
+
return this.parsed.value
|
|
123
|
+
.map(({ component_name, args }) => {
|
|
124
|
+
const component = this.registry.get(component_name);
|
|
125
|
+
if (!component) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
return component.getHeadings(this.jdd_context, args);
|
|
129
|
+
})
|
|
130
|
+
.flat();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=jdd.js.map
|
package/lib/jdd.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jdd.js","sourceRoot":"","sources":["../src/jdd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE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AM,IAAI,KAAK,CAAC,IAAI,IAAI,OAAO,EAAE;gBACjC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;aAC7B;QACF,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED,UAAU,CAAC,QAAkB;QAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,EAAE;YACjE,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAC/C,IAAI,CAAC,SAAS,EAAE;gBACf,OAAO,CAAC,IAAI,CACX,uCAAuC,GAAG,cAAc,CACxD,CAAC;gBACF,OAAO,GAAG,GAAG,CAAC,CAAC;aACf;YAED,OAAO,GAAG,GAAG,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC,EAAE,CAAC,CAAC,CAAC;IACP,CAAC;IAED,WAAW;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK;aACtB,GAAG,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,EAAE;YACjC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YACpD,IAAI,CAAC,SAAS,EAAE;gBACf,OAAO,EAAE,CAAC;aACV;YACD,OAAO,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QACtD,CAAC,CAAC;aACD,IAAI,EAAE,CAAC;IACV,CAAC;CACD"}
|
package/lib/jdd.test.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { Markdown } from "./components/markdown.js";
|
|
3
|
+
import { JDD } from "./jdd.js";
|
|
4
|
+
import { Registry } from "./registry.js";
|
|
5
|
+
import { simplestContext } from "./test-utils/simplest-context.js";
|
|
6
|
+
describe("jdd", () => {
|
|
7
|
+
it("properly extracts headings from multiple components", () => {
|
|
8
|
+
const registry = new Registry();
|
|
9
|
+
registry.add("markdown", Markdown);
|
|
10
|
+
const jdd = JDD.fromParsed(registry, simplestContext(), [
|
|
11
|
+
{
|
|
12
|
+
component_name: "markdown",
|
|
13
|
+
args: {
|
|
14
|
+
markdown: `
|
|
15
|
+
# heading one
|
|
16
|
+
|
|
17
|
+
## heading two
|
|
18
|
+
|
|
19
|
+
### heading three`,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
component_name: "markdown",
|
|
24
|
+
args: {
|
|
25
|
+
markdown: `
|
|
26
|
+
# heading four
|
|
27
|
+
`,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
]);
|
|
31
|
+
assert.deepEqual(jdd.getHeadings(), [
|
|
32
|
+
{ text: "heading one", level: 1, slug: "heading-one" },
|
|
33
|
+
{ text: "heading two", level: 2, slug: "heading-two" },
|
|
34
|
+
{ text: "heading three", level: 3, slug: "heading-three" },
|
|
35
|
+
{ text: "heading four", level: 1, slug: "heading-four" },
|
|
36
|
+
]);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=jdd.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jdd.test.js","sourceRoot":"","sources":["../src/jdd.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE;IACpB,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC9D,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;QAChC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QACnC,MAAM,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE;YACvD;gBACC,cAAc,EAAE,UAAU;gBAC1B,IAAI,EAAE;oBACL,QAAQ,EAAE;;;;;kBAKG;iBACb;aACD;YACD;gBACC,cAAc,EAAE,UAAU;gBAC1B,IAAI,EAAE;oBACL,QAAQ,EAAE;;CAEd;iBACI;aACD;SACD,CAAC,CAAC;QACH,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE;YACnC,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE;YACtD,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE;YACtD,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE;YAC1D,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE;SACxD,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/lib/render.test.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JDD } from "./jdd.js";
|
|
2
|
+
import { makeSimpleEnglishJDDContext } from "./index.js";
|
|
2
3
|
import { Registry } from "./registry.js";
|
|
3
4
|
import { Markdown } from "./components/markdown.js";
|
|
4
5
|
import { FileManager } from "@sealcode/file-manager";
|
|
@@ -9,16 +10,21 @@ describe("render method", () => {
|
|
|
9
10
|
it("renders from a raw document", async () => {
|
|
10
11
|
const registry = new Registry();
|
|
11
12
|
registry.add("markdown", Markdown);
|
|
12
|
-
const
|
|
13
|
+
const jdd = await JDD.fromStorage(registry, makeSimpleEnglishJDDContext(new FileManager("/tmp", "/uploaded_files")), [
|
|
13
14
|
{
|
|
14
15
|
component_name: "markdown",
|
|
15
16
|
args: { markdown: "# Hello" },
|
|
16
17
|
},
|
|
17
|
-
]
|
|
18
|
-
assert.strictEqual(await formatWithPrettier(
|
|
18
|
+
]);
|
|
19
|
+
assert.strictEqual(await formatWithPrettier(await jdd.render()), await formatWithPrettier(/* HTML */ `<section
|
|
19
20
|
class="jdd-component component-number-0"
|
|
20
21
|
>
|
|
21
|
-
<h1>
|
|
22
|
+
<h1 id="hello">
|
|
23
|
+
<a class="anchor" href="#hello">
|
|
24
|
+
<span class="markdown-header-link"></span>
|
|
25
|
+
</a>
|
|
26
|
+
Hello
|
|
27
|
+
</h1>
|
|
22
28
|
</section>`));
|
|
23
29
|
});
|
|
24
30
|
});
|
package/lib/render.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.test.js","sourceRoot":"","sources":["../src/render.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"render.test.js","sourceRoot":"","sources":["../src/render.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC9B,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;QAClC,EAAE,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE;YAC5C,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;YAChC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YACnC,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,WAAW,CAChC,QAAQ,EACR,2BAA2B,CAC1B,IAAI,WAAW,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAC1C,EACD;gBACC;oBACC,cAAc,EAAE,UAAU;oBAC1B,IAAI,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE;iBAC7B;aACD,CACD,CAAC;YACF,MAAM,CAAC,WAAW,CACjB,MAAM,kBAAkB,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC,EAC5C,MAAM,kBAAkB,CAAC,UAAU,CAAC;;;;;;;;;eASzB,CAAC,CACZ,CAAC;QACH,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FileManager } from "@sealcode/file-manager";
|
|
2
|
+
import { makeSimpleEnglishJDDContext } from "../jdd-context.js";
|
|
3
|
+
export function simplestContext() {
|
|
4
|
+
return makeSimpleEnglishJDDContext(new FileManager("/tmp", "/uploaded_files"));
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=simplest-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simplest-context.js","sourceRoot":"","sources":["../../src/test-utils/simplest-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAEhE,MAAM,UAAU,eAAe;IAC9B,OAAO,2BAA2B,CACjC,IAAI,WAAW,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAC1C,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealcode/jdd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-alpha",
|
|
4
4
|
"description": "JSON-Driven Documents",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/mocha": "^10.0.1",
|
|
26
26
|
"@types/prettier": "^2.7.0",
|
|
27
|
+
"@types/slug": "^5.0.9",
|
|
27
28
|
"@types/uuid": "^9.0.8",
|
|
28
29
|
"@typescript-eslint/eslint-plugin": "^5.58.0",
|
|
29
30
|
"@typescript-eslint/parser": "^5.58.0",
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"marked": "^12.0.0",
|
|
50
51
|
"mri": "^1.2.0",
|
|
51
52
|
"prettier": "^2.7.1",
|
|
53
|
+
"slug": "^9.1.0",
|
|
52
54
|
"tempstream": "^0.4.1",
|
|
53
55
|
"uuid": "^9.0.1"
|
|
54
56
|
},
|