tsondb 0.5.16 → 0.5.18
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/src/node/schema/Schema.js +7 -0
- package/dist/src/node/schema/declarations/Declaration.d.ts +1 -0
- package/dist/src/node/schema/types/references/IncludeIdentifierType.d.ts +3 -2
- package/dist/src/node/schema/types/references/IncludeIdentifierType.js +3 -2
- package/dist/src/node/schema/types/references/NestedEntityMapType.d.ts +7 -4
- package/dist/src/node/schema/types/references/NestedEntityMapType.js +20 -10
- package/dist/src/shared/utils/markdown.d.ts +11 -0
- package/dist/src/shared/utils/markdown.js +75 -5
- package/dist/src/web/utils/BlockMarkdown.js +3 -1
- package/dist/src/web/utils/BlockMarkdownHighlighting.js +2 -0
- package/dist/src/web/utils/InlineMarkdown.js +2 -0
- package/package.json +3 -2
- package/public/css/styles.css +28 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import Debug from "debug";
|
|
1
2
|
import { getNestedDeclarations, getParameterNames, walkNodeTree, } from "./declarations/Declaration.js";
|
|
2
3
|
import { isEntityDecl } from "./declarations/EntityDecl.js";
|
|
3
4
|
import { isStringType } from "./types/primitives/StringType.js";
|
|
4
5
|
import { isIncludeIdentifierType } from "./types/references/IncludeIdentifierType.js";
|
|
5
6
|
import { isNestedEntityMapType } from "./types/references/NestedEntityMapType.js";
|
|
6
7
|
import { findTypeAtPath } from "./types/Type.js";
|
|
8
|
+
const debug = Debug("tsondb:schema");
|
|
7
9
|
const checkDuplicateIdentifier = (existingDecls, decl) => {
|
|
8
10
|
const existingDeclWithSameName = existingDecls
|
|
9
11
|
.values()
|
|
@@ -66,9 +68,14 @@ const addDeclarations = (existingDecls, declsToAdd, nested) => declsToAdd.reduce
|
|
|
66
68
|
return accDecls;
|
|
67
69
|
}, existingDecls);
|
|
68
70
|
export const Schema = (declarations, localeEntity) => {
|
|
71
|
+
debug("creating schema from %d declarations", declarations.length);
|
|
72
|
+
debug("collecting nested declarations ...");
|
|
69
73
|
const allDecls = addDeclarations([], localeEntity ? declarations.concat(localeEntity) : declarations, true);
|
|
74
|
+
debug("checking name shadowing ...");
|
|
70
75
|
checkParameterNamesShadowing(allDecls);
|
|
76
|
+
debug("checking entity display name paths ...");
|
|
71
77
|
checkEntityDisplayNamePaths(allDecls, localeEntity);
|
|
78
|
+
debug("created schema, no integrity violations found");
|
|
72
79
|
return {
|
|
73
80
|
declarations: allDecls,
|
|
74
81
|
localeEntity,
|
|
@@ -17,6 +17,7 @@ export declare const getTypeArgumentsRecord: <Params extends TypeParameter[]>(de
|
|
|
17
17
|
export type Decl = EntityDecl | EnumDecl | TypeAliasDecl;
|
|
18
18
|
export type SerializedDecl = SerializedEntityDecl | SerializedEnumDecl | SerializedTypeAliasDecl;
|
|
19
19
|
export type DeclP<Params extends TypeParameter[] = TypeParameter[]> = EntityDecl | EnumDecl<string, Record<string, EnumCaseDecl>, Params> | TypeAliasDecl<string, Type, Params>;
|
|
20
|
+
export type IncludableDeclP<Params extends TypeParameter[] = TypeParameter[]> = EnumDecl<string, Record<string, EnumCaseDecl>, Params> | TypeAliasDecl<string, Type, Params>;
|
|
20
21
|
export type SerializedDeclP<Params extends SerializedTypeParameter[] = SerializedTypeParameter[]> = SerializedEntityDecl | SerializedEnumDecl<string, Record<string, SerializedEnumCaseDecl>, Params> | SerializedTypeAliasDecl<string, SerializedType, Params>;
|
|
21
22
|
export type SecondaryDecl = EnumDecl | TypeAliasDecl;
|
|
22
23
|
export type SerializedSecondaryDecl = SerializedEnumDecl | SerializedTypeAliasDecl;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GetNestedDeclarations, SerializedTypeArguments, TypeArguments } from "../../declarations/Declaration.ts";
|
|
1
|
+
import type { GetNestedDeclarations, IncludableDeclP, SerializedTypeArguments, TypeArguments } from "../../declarations/Declaration.ts";
|
|
2
2
|
import type { EnumDecl } from "../../declarations/EnumDecl.ts";
|
|
3
3
|
import type { TypeAliasDecl } from "../../declarations/TypeAliasDecl.ts";
|
|
4
4
|
import type { GetReferences, Node, Serializer } from "../../Node.ts";
|
|
@@ -23,9 +23,10 @@ export { GenIncludeIdentifierType as GenIncludeIdentifier };
|
|
|
23
23
|
export declare const IncludeIdentifierType: <T extends TConstraint<[]>>(reference: T) => IncludeIdentifierType<[], T>;
|
|
24
24
|
export { IncludeIdentifierType as IncludeIdentifier };
|
|
25
25
|
export declare const isIncludeIdentifierType: (node: Node) => node is IncludeIdentifierType;
|
|
26
|
+
export declare const isNoGenericIncludeIdentifierType: (node: IncludeIdentifierType) => node is IncludeIdentifierType<[], IncludableDeclP<[]>>;
|
|
26
27
|
export declare const getNestedDeclarationsInIncludeIdentifierType: GetNestedDeclarations<IncludeIdentifierType>;
|
|
27
28
|
export declare const validateIncludeIdentifierType: Validator<IncludeIdentifierType>;
|
|
28
|
-
export declare const resolveTypeArgumentsInIncludeIdentifierType: (args: Record<string, Type>, type:
|
|
29
|
+
export declare const resolveTypeArgumentsInIncludeIdentifierType: <T extends IncludeIdentifierType>(args: Record<string, Type>, type: T) => T extends IncludeIdentifierType<[], IncludableDeclP<[]>> ? T : Type;
|
|
29
30
|
export declare const serializeIncludeIdentifierType: Serializer<IncludeIdentifierType, SerializedIncludeIdentifierType>;
|
|
30
31
|
export declare const getReferencesForIncludeIdentifierType: GetReferences<IncludeIdentifierType>;
|
|
31
32
|
export declare const formatIncludeIdentifierValue: StructureFormatter<IncludeIdentifierType>;
|
|
@@ -15,13 +15,14 @@ export const IncludeIdentifierType = (reference) => ({
|
|
|
15
15
|
});
|
|
16
16
|
export { IncludeIdentifierType as IncludeIdentifier };
|
|
17
17
|
export const isIncludeIdentifierType = (node) => node.kind === NodeKind.IncludeIdentifierType;
|
|
18
|
+
export const isNoGenericIncludeIdentifierType = (node) => node.args.length === 0 && node.reference.parameters.length === 0;
|
|
18
19
|
export const getNestedDeclarationsInIncludeIdentifierType = (addedDecls, type) => type.args.reduce((accAddedDecls, arg) => getNestedDeclarations(accAddedDecls, arg), addedDecls.includes(type.reference)
|
|
19
20
|
? addedDecls
|
|
20
21
|
: getNestedDeclarations([type.reference, ...addedDecls], type.reference));
|
|
21
22
|
export const validateIncludeIdentifierType = (helpers, type, value) => validateDecl(helpers, type.reference, type.args, value);
|
|
22
|
-
export const resolveTypeArgumentsInIncludeIdentifierType = (args, type) => type
|
|
23
|
+
export const resolveTypeArgumentsInIncludeIdentifierType = (args, type) => (isNoGenericIncludeIdentifierType(type)
|
|
23
24
|
? type
|
|
24
|
-
: resolveTypeArgumentsInDecl(type.reference, type.args.map(arg => resolveTypeArgumentsInType(args, arg))).type.value;
|
|
25
|
+
: resolveTypeArgumentsInDecl(type.reference, type.args.map(arg => resolveTypeArgumentsInType(args, arg))).type.value);
|
|
25
26
|
export const serializeIncludeIdentifierType = type => ({
|
|
26
27
|
...removeParentKey(type),
|
|
27
28
|
reference: type.reference.name,
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { Lazy } from "../../../../shared/utils/lazy.ts";
|
|
2
|
-
import type
|
|
2
|
+
import { type GetNestedDeclarations } from "../../declarations/Declaration.ts";
|
|
3
3
|
import type { EntityDecl } from "../../declarations/EntityDecl.ts";
|
|
4
|
+
import type { TypeAliasDecl } from "../../declarations/TypeAliasDecl.ts";
|
|
4
5
|
import type { GetReferences, Node, Serializer } from "../../Node.ts";
|
|
5
6
|
import { NodeKind } from "../../Node.ts";
|
|
6
7
|
import type { Validator } from "../../validation/type.ts";
|
|
7
8
|
import type { MemberDecl, ObjectType, SerializedMemberDecl, SerializedObjectType } from "../generic/ObjectType.ts";
|
|
8
9
|
import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.ts";
|
|
10
|
+
import { type IncludeIdentifier, type SerializedIncludeIdentifierType } from "./IncludeIdentifierType.ts";
|
|
9
11
|
type TConstraint = Record<string, MemberDecl>;
|
|
12
|
+
type PossibleType<T extends TConstraint> = ObjectType<T> | IncludeIdentifier<[], TypeAliasDecl<string, ObjectType<T>, []>>;
|
|
10
13
|
export interface NestedEntityMapType<Name extends string = string, T extends TConstraint = TConstraint> extends BaseType {
|
|
11
14
|
kind: NodeKind["NestedEntityMapType"];
|
|
12
15
|
name: Name;
|
|
13
16
|
comment?: string;
|
|
14
17
|
secondaryEntity: EntityDecl;
|
|
15
|
-
type: Lazy<
|
|
18
|
+
type: Lazy<PossibleType<T>>;
|
|
16
19
|
}
|
|
17
20
|
type TSerializedConstraint = Record<string, SerializedMemberDecl>;
|
|
18
21
|
export interface SerializedNestedEntityMapType<Name extends string = string, T extends TSerializedConstraint = TSerializedConstraint> extends SerializedBaseType {
|
|
@@ -20,13 +23,13 @@ export interface SerializedNestedEntityMapType<Name extends string = string, T e
|
|
|
20
23
|
name: Name;
|
|
21
24
|
comment?: string;
|
|
22
25
|
secondaryEntity: string;
|
|
23
|
-
type: SerializedObjectType<T
|
|
26
|
+
type: SerializedObjectType<T> | SerializedIncludeIdentifierType;
|
|
24
27
|
}
|
|
25
28
|
export declare const NestedEntityMapType: <Name extends string, T extends TConstraint>(options: {
|
|
26
29
|
name: Name;
|
|
27
30
|
comment?: string;
|
|
28
31
|
secondaryEntity: EntityDecl;
|
|
29
|
-
type:
|
|
32
|
+
type: PossibleType<T>;
|
|
30
33
|
}) => NestedEntityMapType<Name, T>;
|
|
31
34
|
export { NestedEntityMapType as NestedEntityMap };
|
|
32
35
|
export declare const isNestedEntityMapType: (node: Node) => node is NestedEntityMapType;
|
|
@@ -3,9 +3,11 @@ import { sortObjectKeysAlphabetically } from "../../../../shared/utils/object.js
|
|
|
3
3
|
import { parallelizeErrors } from "../../../../shared/utils/validation.js";
|
|
4
4
|
import { wrapErrorsIfAny } from "../../../utils/error.js";
|
|
5
5
|
import { entity, json, key as keyColor } from "../../../utils/errorFormatting.js";
|
|
6
|
+
import { getNestedDeclarations, } from "../../declarations/Declaration.js";
|
|
6
7
|
import { NodeKind } from "../../Node.js";
|
|
7
|
-
import {
|
|
8
|
-
import { formatValue, removeParentKey, setParent } from "../Type.js";
|
|
8
|
+
import { getReferencesForObjectType, isObjectType, resolveTypeArgumentsInObjectType, serializeObjectType, } from "../generic/ObjectType.js";
|
|
9
|
+
import { formatValue, removeParentKey, setParent, validate } from "../Type.js";
|
|
10
|
+
import { formatIncludeIdentifierValue, getReferencesForIncludeIdentifierType, resolveTypeArgumentsInIncludeIdentifierType, serializeIncludeIdentifierType, } from "./IncludeIdentifierType.js";
|
|
9
11
|
export const NestedEntityMapType = (options) => {
|
|
10
12
|
const nestedEntityMapType = {
|
|
11
13
|
...options,
|
|
@@ -24,30 +26,38 @@ const _NestedEntityMapType = (options) => {
|
|
|
24
26
|
return nestedEntityMapType;
|
|
25
27
|
};
|
|
26
28
|
export const isNestedEntityMapType = (node) => node.kind === NodeKind.NestedEntityMapType;
|
|
27
|
-
export const getNestedDeclarationsInNestedEntityMapType = (addedDecls, type) =>
|
|
29
|
+
export const getNestedDeclarationsInNestedEntityMapType = (addedDecls, type) => getNestedDeclarations(addedDecls.includes(type.secondaryEntity) ? addedDecls : [type.secondaryEntity, ...addedDecls], type.type.value);
|
|
28
30
|
export const validateNestedEntityMapType = (helpers, type, value) => {
|
|
29
31
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
30
32
|
return [TypeError(`expected an object, but got ${json(value, helpers.useStyling)}`)];
|
|
31
33
|
}
|
|
32
|
-
return parallelizeErrors(Object.keys(value).map(key => wrapErrorsIfAny(`at nested entity map ${entity(`"${type.name}"`, helpers.useStyling)} at key ${keyColor(`"${key}"`, helpers.useStyling)}`,
|
|
34
|
+
return parallelizeErrors(Object.keys(value).map(key => wrapErrorsIfAny(`at nested entity map ${entity(`"${type.name}"`, helpers.useStyling)} at key ${keyColor(`"${key}"`, helpers.useStyling)}`, validate(helpers, type.type.value, value[key]).concat(helpers.checkReferentialIntegrity({
|
|
33
35
|
name: type.secondaryEntity.name,
|
|
34
36
|
value: key,
|
|
35
37
|
})))));
|
|
36
38
|
};
|
|
37
39
|
export const resolveTypeArgumentsInNestedEntityMapType = (args, type) => _NestedEntityMapType({
|
|
38
40
|
...type,
|
|
39
|
-
type: () =>
|
|
41
|
+
type: () => isObjectType(type.type.value)
|
|
42
|
+
? resolveTypeArgumentsInObjectType(args, type.type.value)
|
|
43
|
+
: resolveTypeArgumentsInIncludeIdentifierType(args, type.type.value),
|
|
40
44
|
});
|
|
41
45
|
export const serializeNestedEntityMapType = type => ({
|
|
42
46
|
...removeParentKey(type),
|
|
43
47
|
secondaryEntity: type.secondaryEntity.name,
|
|
44
|
-
type:
|
|
48
|
+
type: isObjectType(type.type.value)
|
|
49
|
+
? serializeObjectType(type.type.value)
|
|
50
|
+
: serializeIncludeIdentifierType(type.type.value),
|
|
45
51
|
});
|
|
46
52
|
export const getReferencesForNestedEntityMapType = (type, value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
47
53
|
? Object.values(value)
|
|
48
|
-
.flatMap(item =>
|
|
54
|
+
.flatMap(item => isObjectType(type.type.value)
|
|
55
|
+
? getReferencesForObjectType(type.type.value, item)
|
|
56
|
+
: getReferencesForIncludeIdentifierType(type.type.value, item))
|
|
49
57
|
.concat(Object.keys(value))
|
|
50
58
|
: [];
|
|
51
|
-
export const formatNestedEntityMapValue = (type, value) =>
|
|
52
|
-
?
|
|
53
|
-
|
|
59
|
+
export const formatNestedEntityMapValue = (type, value) => isObjectType(type.type.value)
|
|
60
|
+
? typeof value === "object" && value !== null && !Array.isArray(value)
|
|
61
|
+
? sortObjectKeysAlphabetically(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, formatValue(type.type.value, item)])))
|
|
62
|
+
: value
|
|
63
|
+
: formatIncludeIdentifierValue(type.type.value, value);
|
|
@@ -8,6 +8,10 @@ export type InlineMarkdownNode = {
|
|
|
8
8
|
} | {
|
|
9
9
|
kind: "code";
|
|
10
10
|
content: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "link";
|
|
13
|
+
href: string;
|
|
14
|
+
content: InlineMarkdownNode[];
|
|
11
15
|
} | TextNode;
|
|
12
16
|
export type BlockMarkdownNode = {
|
|
13
17
|
kind: "paragraph";
|
|
@@ -19,10 +23,17 @@ export type BlockMarkdownNode = {
|
|
|
19
23
|
kind: "listitem";
|
|
20
24
|
content: InlineMarkdownNode[];
|
|
21
25
|
}[];
|
|
26
|
+
} | {
|
|
27
|
+
kind: "table";
|
|
28
|
+
header: InlineMarkdownNode[][];
|
|
29
|
+
rows: InlineMarkdownNode[][][];
|
|
22
30
|
};
|
|
23
31
|
export type BlockSyntaxMarkdownNode = InlineMarkdownNode | {
|
|
24
32
|
kind: "listitemmarker";
|
|
25
33
|
content: string;
|
|
34
|
+
} | {
|
|
35
|
+
kind: "tablemarker";
|
|
36
|
+
content: string;
|
|
26
37
|
};
|
|
27
38
|
export declare const parseBlockMarkdown: (text: string) => BlockMarkdownNode[];
|
|
28
39
|
export declare const parseBlockMarkdownForSyntaxHighlighting: (text: string) => BlockSyntaxMarkdownNode[];
|
|
@@ -6,7 +6,7 @@ const codeRule = {
|
|
|
6
6
|
}),
|
|
7
7
|
};
|
|
8
8
|
const boldWithItalicRule = {
|
|
9
|
-
pattern:
|
|
9
|
+
pattern: /(?<!\\)\*\*((.*?[^\\*])?\*(?!\*).*?[^\\*]\*.*?)(?<!\\)\*\*/,
|
|
10
10
|
map: (result, parseInside, forSyntaxHighlighting) => ({
|
|
11
11
|
kind: "bold",
|
|
12
12
|
content: forSyntaxHighlighting
|
|
@@ -19,7 +19,7 @@ const boldWithItalicRule = {
|
|
|
19
19
|
}),
|
|
20
20
|
};
|
|
21
21
|
const italicWithBoldRule = {
|
|
22
|
-
pattern:
|
|
22
|
+
pattern: /(?<![\\*])\*(?=\*\*|[^*])(.*?\*\*.*?\*\*.*?)(?<=[^\\*]|[^\\]\*\*)\*(?!\*)/,
|
|
23
23
|
map: (result, parseInside, forSyntaxHighlighting) => ({
|
|
24
24
|
kind: "italic",
|
|
25
25
|
content: forSyntaxHighlighting
|
|
@@ -32,7 +32,7 @@ const italicWithBoldRule = {
|
|
|
32
32
|
}),
|
|
33
33
|
};
|
|
34
34
|
const boldRule = {
|
|
35
|
-
pattern:
|
|
35
|
+
pattern: /(?<!\\)\*\*(.*?[^\\*])\*\*/,
|
|
36
36
|
map: (result, parseInside, forSyntaxHighlighting) => ({
|
|
37
37
|
kind: "bold",
|
|
38
38
|
content: forSyntaxHighlighting
|
|
@@ -45,7 +45,7 @@ const boldRule = {
|
|
|
45
45
|
}),
|
|
46
46
|
};
|
|
47
47
|
const italicRule = {
|
|
48
|
-
pattern:
|
|
48
|
+
pattern: /(?<!\\)\*(.*?[^\\*])\*/,
|
|
49
49
|
map: (result, parseInside, forSyntaxHighlighting) => ({
|
|
50
50
|
kind: "italic",
|
|
51
51
|
content: forSyntaxHighlighting
|
|
@@ -57,8 +57,23 @@ const italicRule = {
|
|
|
57
57
|
: parseInside(result[1] ?? ""),
|
|
58
58
|
}),
|
|
59
59
|
};
|
|
60
|
+
const linkRule = {
|
|
61
|
+
pattern: /(?<!\\)\[(.*?[^\\])\]\((.*?[^\\])\)/,
|
|
62
|
+
map: (result, parseInside, forSyntaxHighlighting) => ({
|
|
63
|
+
kind: "link",
|
|
64
|
+
href: result[2] ?? "",
|
|
65
|
+
content: forSyntaxHighlighting
|
|
66
|
+
? [
|
|
67
|
+
{ kind: "text", content: "[" },
|
|
68
|
+
...parseInside(result[1] ?? ""),
|
|
69
|
+
{ kind: "text", content: `](${result[2] ?? ""})` },
|
|
70
|
+
]
|
|
71
|
+
: parseInside(result[1] ?? ""),
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
60
74
|
const inlineRules = [
|
|
61
75
|
codeRule,
|
|
76
|
+
linkRule,
|
|
62
77
|
boldWithItalicRule,
|
|
63
78
|
italicWithBoldRule,
|
|
64
79
|
boldRule,
|
|
@@ -123,7 +138,62 @@ const paragraphRule = {
|
|
|
123
138
|
{ kind: "text", content: result[2] ?? "" },
|
|
124
139
|
],
|
|
125
140
|
};
|
|
126
|
-
const
|
|
141
|
+
const removeSurroundingPipes = (text) => text.replace(/^\|/, "").replace(/\|$/, "");
|
|
142
|
+
const tableRule = {
|
|
143
|
+
pattern: /^(\| *)?(.+?(?: *(?<!\\)\| *.+?)+)( *\|)?\n((?:\| *)?(?:-{3,}|:-{2,}|-{2,}:|:-+:)(?: *\| *(?:-{3,}|:-{2,}|-{2,}:|:-+:))*(?: *\|)?)((?:\n\|? *.+?(?: *(?<!\\)\| *.+?)* *(?<!\\)\|?)+)(\n{2,}|$)/,
|
|
144
|
+
map: result => ({
|
|
145
|
+
kind: "table",
|
|
146
|
+
header: result[2]?.split("|").map(th => parseInlineMarkdown(th.trim(), false)) ?? [],
|
|
147
|
+
rows: result[5]
|
|
148
|
+
?.split("\n")
|
|
149
|
+
.slice(1)
|
|
150
|
+
.map(tr => removeSurroundingPipes(tr)
|
|
151
|
+
.split("|")
|
|
152
|
+
.map(tc => parseInlineMarkdown(tc.trim(), false))) ?? [],
|
|
153
|
+
}),
|
|
154
|
+
mapHighlighting: result => [
|
|
155
|
+
{
|
|
156
|
+
kind: "tablemarker",
|
|
157
|
+
content: result[1] ?? "",
|
|
158
|
+
},
|
|
159
|
+
...(result[2]?.split("|").flatMap((th, i) => i === 0
|
|
160
|
+
? parseInlineMarkdown(th, true)
|
|
161
|
+
: [
|
|
162
|
+
{
|
|
163
|
+
kind: "tablemarker",
|
|
164
|
+
content: "|",
|
|
165
|
+
},
|
|
166
|
+
...parseInlineMarkdown(th, true),
|
|
167
|
+
]) ?? []),
|
|
168
|
+
{
|
|
169
|
+
kind: "tablemarker",
|
|
170
|
+
content: (result[3] ?? "") + "\n" + (result[4] ?? ""),
|
|
171
|
+
},
|
|
172
|
+
...(result[5]
|
|
173
|
+
?.split("\n")
|
|
174
|
+
.slice(1)
|
|
175
|
+
.flatMap((tr) => [
|
|
176
|
+
{
|
|
177
|
+
kind: "text",
|
|
178
|
+
content: "\n",
|
|
179
|
+
},
|
|
180
|
+
...tr.split("|").flatMap((tc, i) => i === 0
|
|
181
|
+
? parseInlineMarkdown(tc, true)
|
|
182
|
+
: [
|
|
183
|
+
{
|
|
184
|
+
kind: "tablemarker",
|
|
185
|
+
content: "|",
|
|
186
|
+
},
|
|
187
|
+
...parseInlineMarkdown(tc, true),
|
|
188
|
+
]),
|
|
189
|
+
]) ?? []),
|
|
190
|
+
{
|
|
191
|
+
kind: "text",
|
|
192
|
+
content: result[6] ?? "",
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
};
|
|
196
|
+
const blockRules = [tableRule, listRule, paragraphRule];
|
|
127
197
|
const parseForBlockRules = (rules, text, remainingRules = rules) => {
|
|
128
198
|
if (text.length === 0) {
|
|
129
199
|
return [];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
2
|
import { InlineMarkdown } from "./InlineMarkdown.js";
|
|
3
3
|
export const BlockMarkdown = ({ node }) => {
|
|
4
4
|
switch (node.kind) {
|
|
@@ -11,6 +11,8 @@ export const BlockMarkdown = ({ node }) => {
|
|
|
11
11
|
else {
|
|
12
12
|
return (_jsx("ul", { children: node.content.map((item, ii) => (_jsx("li", { children: item.content.map((inline, iii) => (_jsx(InlineMarkdown, { node: inline }, iii))) }, ii))) }));
|
|
13
13
|
}
|
|
14
|
+
case "table":
|
|
15
|
+
return (_jsxs("table", { children: [_jsx("thead", { children: _jsx("tr", { children: node.header.map((th, hi) => (_jsx("th", { children: th.map((inline, hii) => (_jsx(InlineMarkdown, { node: inline }, hii))) }, hi))) }) }), _jsx("tbody", { children: node.rows.map((tr, ri) => (_jsx("tr", { children: tr.map((tc, ci) => (_jsx("td", { children: tc.map((inline, cii) => (_jsx(InlineMarkdown, { node: inline }, cii))) }, ci))) }, ri))) })] }));
|
|
14
16
|
default:
|
|
15
17
|
return null;
|
|
16
18
|
}
|
|
@@ -4,6 +4,8 @@ export const BlockMarkdownHighlighting = ({ node }) => {
|
|
|
4
4
|
switch (node.kind) {
|
|
5
5
|
case "listitemmarker":
|
|
6
6
|
return _jsx("span", { class: "list-item-marker", children: node.content });
|
|
7
|
+
case "tablemarker":
|
|
8
|
+
return _jsx("span", { class: "table-marker", children: node.content });
|
|
7
9
|
default:
|
|
8
10
|
return _jsx(InlineMarkdown, { node: node });
|
|
9
11
|
}
|
|
@@ -7,6 +7,8 @@ export const InlineMarkdown = ({ node }) => {
|
|
|
7
7
|
return (_jsx("strong", { children: node.content.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))) }));
|
|
8
8
|
case "italic":
|
|
9
9
|
return (_jsx("em", { children: node.content.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))) }));
|
|
10
|
+
case "link":
|
|
11
|
+
return (_jsx("a", { href: node.href, children: node.content.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))) }));
|
|
10
12
|
case "text":
|
|
11
13
|
return node.content;
|
|
12
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsondb",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.18",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Lukas Obermann",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "tsc -b",
|
|
25
25
|
"watch": "tsc -b -w",
|
|
26
|
-
"test": "node --test",
|
|
26
|
+
"test": "node --import tsx --test",
|
|
27
27
|
"lint": "eslint",
|
|
28
28
|
"format": "prettier \"{src,test}/**/*.{ts,tsx}\" --write",
|
|
29
29
|
"format:check": "prettier \"{src,test}/**/*.{ts,tsx}\" --check",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
42
42
|
"globals": "^16.3.0",
|
|
43
43
|
"prettier": "^3.6.2",
|
|
44
|
+
"tsx": "^4.20.5",
|
|
44
45
|
"typescript": "^5.9.2",
|
|
45
46
|
"typescript-eslint": "^8.43.0"
|
|
46
47
|
},
|
package/public/css/styles.css
CHANGED
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
--highlight-color-bold: rgb(205, 123, 43);
|
|
52
52
|
--highlight-color-italic: rgb(41, 155, 96);
|
|
53
53
|
--highlight-color-list-item-marker: rgb(195, 58, 237);
|
|
54
|
+
--highlight-color-table-marker: rgb(237, 58, 118);
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
@media (prefers-color-scheme: dark) {
|
|
@@ -82,6 +83,7 @@
|
|
|
82
83
|
--highlight-color-bold: rgb(236, 170, 105);
|
|
83
84
|
--highlight-color-italic: rgb(130, 230, 178);
|
|
84
85
|
--highlight-color-list-item-marker: rgb(220, 133, 245);
|
|
86
|
+
--highlight-color-table-marker: rgb(244, 135, 171);
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
|
|
@@ -584,6 +586,10 @@ form > .field--container {
|
|
|
584
586
|
color: var(--highlight-color-list-item-marker);
|
|
585
587
|
}
|
|
586
588
|
|
|
589
|
+
.editor-highlighting .table-marker {
|
|
590
|
+
color: var(--highlight-color-table-marker);
|
|
591
|
+
}
|
|
592
|
+
|
|
587
593
|
.help {
|
|
588
594
|
font-size: 0.8rem;
|
|
589
595
|
color: var(--secondary-color);
|
|
@@ -608,6 +614,28 @@ form > .field--container {
|
|
|
608
614
|
margin-bottom: 0;
|
|
609
615
|
}
|
|
610
616
|
|
|
617
|
+
.field--string .preview table {
|
|
618
|
+
border-collapse: collapse;
|
|
619
|
+
margin: 0.5rem 0;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
.field--string .preview table :is(th, td) {
|
|
623
|
+
vertical-align: top;
|
|
624
|
+
padding: 0.25rem 0.5rem;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
.field--string .preview table :is(th, td):first-child {
|
|
628
|
+
padding-left: 0;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
.field--string .preview table :is(th, td):last-child {
|
|
632
|
+
padding-right: 0;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
.field--string .preview table tbody tr {
|
|
636
|
+
border-top: 1px solid var(--tertiary-color);
|
|
637
|
+
}
|
|
638
|
+
|
|
611
639
|
.container-item {
|
|
612
640
|
container-type: inline-size;
|
|
613
641
|
}
|