tsondb 0.5.17 → 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/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,
|
|
@@ -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
|
}
|